276 Commits

Author SHA1 Message Date
Dylan K. Taylor
7804172846
Player: added API documentation for some functions 2022-09-21 14:46:04 +01:00
Dylan K. Taylor
d1c75da14b
Player: lock flight state in spectator mode
players should not be able to stop flying in spectator mode
2022-09-20 21:53:51 +01:00
NoClip
2f4a9469b6
Player: spectator shouldn't able to pick blocks they don't have (#5111)
Jury is out on whether they should be able to pick blocks at all, or be considered to have infinite resources, but this solution has been used in a few other places already anyway, so it can be cleaned up another time.
2022-08-15 16:48:37 +01:00
Dylan K. Taylor
608c6ed6db
Improved suboptimal code in Player::handleMovement() 2022-07-24 20:51:28 +01:00
Dylan K. Taylor
06655bee78
Updated to 1.19.10 2022-07-13 00:59:49 +01:00
Dylan K. Taylor
bb5b52d998
Player: fix terrain getting redrawn when moving in noclip mode 2022-06-09 13:48:29 +01:00
Dylan K. Taylor
38d6284671
Use PHP-CS-Fixer to enforce file header presence 2022-06-04 17:34:49 +01:00
Dylan K. Taylor
812d5c3f58
Merge branch 'stable' into next-minor 2022-05-24 14:17:53 +01:00
Dylan K. Taylor
38d75f3aab
Player: Be more explicit about not parsing chat messages when messageCounter is zero
the length check technically accounts for this, but future readers might not realize this
2022-05-22 16:46:53 +01:00
Dylan K. Taylor
179cac45f5
Merge branch 'stable' into next-minor 2022-05-22 16:21:05 +01:00
Dylan K. Taylor
c82dfef9b0
Player: fix weird behaviour when teleporting sleeping players
closes #4672
2022-05-21 20:08:12 +01:00
Dylan K. Taylor
1181b13b5d
Player: call InventoryCloseEvent after doing the necessary business
closes #4626

this does change the behaviour of getCurrentWindow() during InventoryCloseEvent, but no one should be using that anyway, since InventoryCloseEvent->getInventory() exists.
2022-05-21 19:23:59 +01:00
TheNewHEROBRINEX
02cf6ae46c
Added PlayerDeathEvent->setKeepXp(), closes #4002 (#4015) 2022-05-21 16:41:14 +01:00
Dylan K. Taylor
86efa0aae6
Merge remote-tracking branch 'origin/stable' into next-minor 2022-05-20 17:49:04 +01:00
Dylan K. Taylor
554f96bc24
InventoryManager: Defer opening new windows to the client until the window close handshake has been completed
fixes #5021 and probably a bunch of other inventory related glitches

When the server initiates a window close, it does so by sending a ContainerClose to the client, which causes the
client to behave as if it initiated the close itself. It responds by sending a ContainerClose back to the server,
which the server is then expected to respond to.

Sending the client a new window before sending this final response creates buggy behaviour on the client, which
is problematic when switching windows. Therefore, we defer sending any new windows until after the client
responds to our window close instruction, so that we can complete the window handshake correctly.

This is a pile of complicated garbage that only exists because Mojang overengineered the process of opening and
closing inventory windows.
2022-05-20 16:54:15 +01:00
Dylan K. Taylor
7bc3dcdefd
Modernize private property declarations in src/player 2022-05-17 21:36:51 +01:00
Duo Incure
89cc449808
Update exhaustion values for 1.18.30 (#5034) 2022-05-17 18:28:19 +01:00
Dylan T
8b8560a701
Added PlayerPostChunkSendEvent (#4937)
this is primarily useful for debugging plugins, but could also be useful for other things, such as spawning fake blocks, particles, etc.
2022-05-17 15:40:01 +01:00
Dylan K. Taylor
937bb4c6ce
Merge branch 'stable' into next-minor 2022-04-28 21:00:23 +01:00
ねらひかだ
27056b6c37
Player: creative players should not be damaged by the void (#4978) 2022-04-21 16:39:36 +01:00
Dylan K. Taylor
df33e179e5
Player: fixed chat newlines denial-of-service vulnerability
irresponsibly reported in #4974

closes #4974
2022-04-20 13:01:05 +01:00
Dylan K. Taylor
7d1464f0a1
Merge branch 'stable' into next-minor 2022-03-28 17:18:54 +01:00
Dylan K. Taylor
901449b0b1
Player: simplify PlayerItemHeldEvent calling on content change
the second parameter to this callback is the OLD slots, not the changed slots. This means that ALL slots are included, including empty and unchanged slots.
2022-03-23 13:47:01 +00:00
Dylan K. Taylor
a9f2766a8b
Merge branch 'stable' into next-minor 2022-03-23 13:39:41 +00:00
Dylan K. Taylor
ea33a04d00
Player: ensure that PlayerItemHeldEvent is called when the contents of the held slot changes
in PM3, this was done by implicitly relying on the client to send a MobEquipmentPacket selecting the same hotbar slot when the slot contents changes.
In PM4, we avoid relying on this, and fire the event directly when the listener detects a held slot change.
This ensures that the behaviour remains consistent regardless of what the client starts doing in the future.

closes #4905
2022-03-22 16:53:02 +00:00
Dylan K. Taylor
ab93135b84
Merge branch 'stable' into next-minor 2022-03-22 15:49:58 +00:00
Dylan K. Taylor
856fd2a33b
fix PHPStan failures 2022-03-09 17:26:05 +00:00
IvanCraft623
90a369f0b6
Humans can now do emotes (#4610)
added the following API methods:
- Human::emote()
2022-03-03 18:19:30 +00:00
ShockedPlot7560
b9f1bcf0e4
Implement PlayerViewDistanceChangeEvent (#4749)
closes #4550
2022-01-25 18:00:26 +00:00
Dylan K. Taylor
419bb9eba6
Player: fixed parameter name inconsistency 2022-01-22 01:33:31 +00:00
Dylan K. Taylor
373880e582
Replace disallowed operators in src/player/ 2022-01-20 19:16:00 +00:00
Dylan K. Taylor
e04dfe96af
Merge branch 'stable' into next-minor 2022-01-01 17:55:17 +00:00
Dylan K. Taylor
c8247786d7
Player: check chat length check with strlen() before mb_strlen()
mb_strlen() is O(n), whereas strlen() is O(1). If we receive very large chat messages (e.g. 2 MB), mb_strlen() will take a very long time to return a result (around 8ms on my machine).
Since the max size of a UTF-8 character is 4 bytes (according to standard), we can use strlen() with 4x the char limit to gate it and prevent this from happening.
2022-01-01 16:46:00 +00:00
Dylan T
f486b5f4a7
Player: fixed fall damage when sprinting down stairs (#4685)
Due to the way positions are updated over the network, we only see the end result of a movement and not its preceding actions. In addition, we don't know for sure whether the MCPE collision checks work the same exact way as PM.

TL;DR: It's possible for the client to capture and send a movement frame after they collided with a step and then already moved forward from it some distance, resulting in a weird arc pattern.

This PR checks the range between the old and new positions for collision boxes to ensure that all possible areas are checked for detecting fall damage.

This has been tested and successfully resolves various issues involving running down stairs:
- missing sounds
- random fall damage
2022-01-01 15:41:19 +00:00
Dylan K. Taylor
207f7ec309
Player: avoid unnecessary network updates on repeated calls to setAllowFLight(), setHasBlockCollision() and setAutoJump() 2021-12-29 20:22:16 +00:00
Dylan K. Taylor
5c994e4a24
Player: removed an old hack for setFlying() feedback loop
this is no longer a concern, since we now check if the sent state matches the current state before doing anything, at multiple layers.
2021-12-29 18:41:11 +00:00
Dylan K. Taylor
d94578a420
Player: remove dead TODO comment 2021-12-29 18:32:53 +00:00
Dylan K. Taylor
7124d44b92
Player: prevent PlayerToggle(Sprint|Sneak|Fly|Glide|Swim)Events from firing multiple times with the same value
this happens with swimming due to bugs in the client.
2021-12-29 17:24:49 +00:00
Dylan K. Taylor
87170ab067
Player: move reach distances to constants 2021-12-27 17:32:04 +00:00
Dylan K. Taylor
74ac0f5862
Player: move max chat length to constant 2021-12-27 17:06:19 +00:00
Dylan K. Taylor
f5144d49b1
Merge branch 'stable' into next-minor 2021-12-27 16:52:22 +00:00
Dylan K. Taylor
8943d8a2a7
Player: fixed maximum message size limits to match vanilla bugrock 2021-12-27 16:51:47 +00:00
XenialDan
d41f933e7b
Implement swimming/gliding including AABB recalculation (#4446)
- The following events have been added:
  - PlayerToggleGlideEvent
  - PlayerToggleSwimEvent
- The following API methods have been added:
  - Entity->getSize()
  - Living->isSwimming()
  - Living->setSwimming()
  - Living->isGliding()
  - Living->setSwimming()
  - Player->toggleSwim()
  - Player->toggleGlide()
2021-12-19 17:10:41 +00:00
Dylan K. Taylor
4b06fe73f2
Merge branch 'stable' into next-minor 2021-12-14 22:54:39 +00:00
Dylan K. Taylor
45c4a9673d
Player: fixed arm swing animation not showing during attack cooldown of victim
closes #4650
2021-12-14 19:03:42 +00:00
Drew B
ce54d268f2
Player: allow controlling client-sided block collisions irrespective of Spectator Mode (#4563)
- Added the following API methods:
  - `Player::hasBlockCollision()`
  - `Player::setHasBlockCollision()`

This enables spectator-like noclip behaviour in other gamemodes (could be useful for builders).
2021-12-06 21:14:22 +00:00
Dylan K. Taylor
c7beb0a702
Clean up inventory auto close mess from PM3
on PM3 there was no concept of 'current window', we had no idea which window the player was actually looking at.
2021-11-08 23:51:25 +00:00
Dylan K. Taylor
5be429a8c4
Ensure inventories get evacuated on server-side window close 2021-11-08 23:48:05 +00:00
Dylan K. Taylor
ab002ca06d
Improved handling of temporary inventory windows
evacuation behaviour is now consistent regardless of who is doing it
2021-11-08 23:36:58 +00:00
Dylan K. Taylor
45edb94607
Crafting tables now work the same way as anvils and enchanting tables
Removing almost all special-case logic for crafting tables.
2021-11-07 16:20:07 +00:00