Skip to content
Permalink
Browse files

Ignore session reset if player doesn't move a block.

So technically we do this block check in Session#testMoveTo, but the
/wg flushstates command can force a session re-initialization even if
the player hasn't moved a full block yet.
The amount of logic going on between the event call and the point where
we test that force boolean is rather lengthy though, so ignoring it for
the time being may be worth it.
TL;DR: Don't want WG in timings for PlayerMoveEvent needlessly.
  • Loading branch information
wizjany committed Jan 7, 2020
1 parent d37f015 commit 789405d116f2c3fff7650572b5ccb39272118bf4
@@ -77,6 +77,14 @@ public void onVehicleEnter(VehicleEnterEvent event) {

@EventHandler(priority = EventPriority.HIGH)
public void onPlayerMove(PlayerMoveEvent event) {
Location from = event.getFrom();
Location to = event.getTo();
if (from.getBlockX() == to.getBlockX()
&& from.getBlockY() == to.getBlockY()
&& from.getBlockZ() == to.getBlockZ()) {
return;
}

final Player player = event.getPlayer();
LocalPlayer localPlayer = plugin.wrapPlayer(player);

@@ -89,15 +97,15 @@ public void onPlayerMove(PlayerMoveEvent event) {
} else if (event.getPlayer().getVehicle() != null && event.getPlayer().getVehicle() instanceof Horse) {
moveType = MoveType.RIDE;
}
com.sk89q.worldedit.util.Location weLocation = session.testMoveTo(localPlayer, BukkitAdapter.adapt(event.getTo()), moveType);
com.sk89q.worldedit.util.Location weLocation = session.testMoveTo(localPlayer, BukkitAdapter.adapt(to), moveType);

if (weLocation != null) {
final Location override = BukkitAdapter.adapt(weLocation);
override.setX(override.getBlockX() + 0.5);
override.setY(override.getBlockY());
override.setZ(override.getBlockZ() + 0.5);
override.setPitch(event.getTo().getPitch());
override.setYaw(event.getTo().getYaw());
override.setPitch(to.getPitch());
override.setYaw(to.getYaw());

event.setTo(override.clone());

0 comments on commit 789405d

Please sign in to comment.
You can’t perform that action at this time.