From 9d5211cff1f286af25bd3d7a80fbc32f6f2fd3d2 Mon Sep 17 00:00:00 2001 From: DelayedGaming <72163224+DelayedGaming@users.noreply.github.com> Date: Tue, 26 Sep 2023 00:45:10 +0800 Subject: [PATCH] Fix EvtPlayerChunkEnter Comparison & Cleanup (#5965) Initial (cherry picked from commit 389c0022ed177c3124cfd1884165c5c697becaac) Co-authored-by: Moderocky --- .../classes/data/BukkitEventValues.java | 39 ++++++++++++------- .../skript/events/EvtPlayerChunkEnter.java | 7 ++-- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java b/src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java index c47d5ab2885..2b3fa65af5b 100644 --- a/src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java +++ b/src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java @@ -845,6 +845,30 @@ public Block get(PlayerMoveEvent event) { return event.getTo().clone().subtract(0, 0.5, 0).getBlock(); } }, EventValues.TIME_NOW); + EventValues.registerEventValue(PlayerMoveEvent.class, Location.class, new Getter() { + @Override + public Location get(PlayerMoveEvent event) { + return event.getFrom(); + } + }, EventValues.TIME_PAST); + EventValues.registerEventValue(PlayerMoveEvent.class, Location.class, new Getter() { + @Override + public Location get(PlayerMoveEvent event) { + return event.getTo(); + } + }, EventValues.TIME_NOW); + EventValues.registerEventValue(PlayerMoveEvent.class, Chunk.class, new Getter() { + @Override + public Chunk get(PlayerMoveEvent event) { + return event.getFrom().getChunk(); + } + }, EventValues.TIME_PAST); + EventValues.registerEventValue(PlayerMoveEvent.class, Chunk.class, new Getter() { + @Override + public Chunk get(PlayerMoveEvent event) { + return event.getTo().getChunk(); + } + }, EventValues.TIME_NOW); // PlayerItemDamageEvent EventValues.registerEventValue(PlayerItemDamageEvent.class, ItemStack.class, new Getter() { @Override @@ -1425,21 +1449,6 @@ public TeleportCause get(final PlayerTeleportEvent e) { return e.getCause(); } }, 0); - //PlayerMoveEvent - EventValues.registerEventValue(PlayerMoveEvent.class, Location.class, new Getter() { - @Override - @Nullable - public Location get(PlayerMoveEvent e) { - return e.getFrom(); - } - }, EventValues.TIME_PAST); - EventValues.registerEventValue(PlayerMoveEvent.class, Location.class, new Getter() { - @Override - @Nullable - public Location get(PlayerMoveEvent e) { - return e.getTo(); - } - }, EventValues.TIME_NOW); //EntityMoveEvent if (Skript.classExists("io.papermc.paper.event.entity.EntityMoveEvent")) { EventValues.registerEventValue(EntityMoveEvent.class, Location.class, new Getter() { diff --git a/src/main/java/ch/njol/skript/events/EvtPlayerChunkEnter.java b/src/main/java/ch/njol/skript/events/EvtPlayerChunkEnter.java index e79030c1553..d3caf6d325b 100644 --- a/src/main/java/ch/njol/skript/events/EvtPlayerChunkEnter.java +++ b/src/main/java/ch/njol/skript/events/EvtPlayerChunkEnter.java @@ -22,11 +22,9 @@ import ch.njol.skript.lang.Literal; import ch.njol.skript.lang.SkriptEvent; import ch.njol.skript.lang.SkriptParser.ParseResult; - import org.bukkit.event.Event; import org.bukkit.event.player.PlayerMoveEvent; - -import org.eclipse.jdt.annotation.Nullable; +import org.jetbrains.annotations.Nullable; public class EvtPlayerChunkEnter extends SkriptEvent { @@ -46,7 +44,8 @@ public boolean init(Literal[] args, int matchedPattern, ParseResult parseResu @Override public boolean check(Event event) { - return ((PlayerMoveEvent) event).getFrom().getChunk() != ((PlayerMoveEvent) event).getTo().getChunk(); + PlayerMoveEvent moveEvent = ((PlayerMoveEvent) event); + return !moveEvent.getFrom().getChunk().equals(moveEvent.getTo().getChunk()); } @Override