Skip to content

Commit

Permalink
Fix EvtPlayerChunkEnter Comparison & Cleanup (#5965)
Browse files Browse the repository at this point in the history
Initial

(cherry picked from commit 389c002)

Co-authored-by: Moderocky <[email protected]>
  • Loading branch information
NotSoDelayed and Moderocky authored Sep 25, 2023
1 parent 78116e7 commit 9d5211c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
39 changes: 24 additions & 15 deletions src/main/java/ch/njol/skript/classes/data/BukkitEventValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Location, PlayerMoveEvent>() {
@Override
public Location get(PlayerMoveEvent event) {
return event.getFrom();
}
}, EventValues.TIME_PAST);
EventValues.registerEventValue(PlayerMoveEvent.class, Location.class, new Getter<Location, PlayerMoveEvent>() {
@Override
public Location get(PlayerMoveEvent event) {
return event.getTo();
}
}, EventValues.TIME_NOW);
EventValues.registerEventValue(PlayerMoveEvent.class, Chunk.class, new Getter<Chunk, PlayerMoveEvent>() {
@Override
public Chunk get(PlayerMoveEvent event) {
return event.getFrom().getChunk();
}
}, EventValues.TIME_PAST);
EventValues.registerEventValue(PlayerMoveEvent.class, Chunk.class, new Getter<Chunk, PlayerMoveEvent>() {
@Override
public Chunk get(PlayerMoveEvent event) {
return event.getTo().getChunk();
}
}, EventValues.TIME_NOW);
// PlayerItemDamageEvent
EventValues.registerEventValue(PlayerItemDamageEvent.class, ItemStack.class, new Getter<ItemStack, PlayerItemDamageEvent>() {
@Override
Expand Down Expand Up @@ -1425,21 +1449,6 @@ public TeleportCause get(final PlayerTeleportEvent e) {
return e.getCause();
}
}, 0);
//PlayerMoveEvent
EventValues.registerEventValue(PlayerMoveEvent.class, Location.class, new Getter<Location, PlayerMoveEvent>() {
@Override
@Nullable
public Location get(PlayerMoveEvent e) {
return e.getFrom();
}
}, EventValues.TIME_PAST);
EventValues.registerEventValue(PlayerMoveEvent.class, Location.class, new Getter<Location, PlayerMoveEvent>() {
@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<Location, EntityMoveEvent>() {
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/ch/njol/skript/events/EvtPlayerChunkEnter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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
Expand Down

0 comments on commit 9d5211c

Please sign in to comment.