Skip to content

Commit

Permalink
Patch item frame modification while in chunk editor (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
WasabiThumb authored Dec 7, 2024
1 parent e65b093 commit 1174f76
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions src/main/java/codes/wasabi/xclaim/gui/ChunkEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
import org.bukkit.entity.Entity;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.*;
import org.bukkit.event.block.Action;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
Expand All @@ -52,6 +50,24 @@ private Events() {
listener.register();
}

void tryRegisterPaperEvents() {
// PAPER ONLY: Item frame change event
Class<? extends PlayerEvent> itemFrameEventClass;
try {
itemFrameEventClass = Class.forName("io.papermc.paper.event.player.PlayerItemFrameChangeEvent")
.asSubclass(PlayerEvent.class);
} catch (ClassNotFoundException | ClassCastException ignored) {
return;
}
Bukkit.getPluginManager().registerEvent(
itemFrameEventClass,
this,
EventPriority.NORMAL,
(Listener ignored, Event event) -> this.onItemFrameChange((PlayerEvent) event),
XClaim.instance
);
}

@EventHandler
public void onDrop(@NotNull PlayerDropItemEvent event) {
Player ply = event.getPlayer();
Expand Down Expand Up @@ -403,6 +419,14 @@ public void onMove(@NotNull PlayerMoveEvent event) {
}
}

// PAPER ONLY
public void onItemFrameChange(@NotNull PlayerEvent event) {
Player ply = event.getPlayer();
if (getEditing(ply) != null && event instanceof Cancellable) {
((Cancellable) event).setCancelled(true);
}
}

}

private static ItemStack CLAIM_STACK;
Expand Down Expand Up @@ -430,6 +454,7 @@ public static void initialize() {
KEY_INVENTORY = Objects.requireNonNull(Platform.get().createNamespacedKey(XClaim.instance, "ce_inventory"));
EVENTS = new Events();
Bukkit.getPluginManager().registerEvents(EVENTS, XClaim.instance);
EVENTS.tryRegisterPaperEvents();
}

private static final Map<UUID, Claim> editingMap = new HashMap<>();
Expand Down

0 comments on commit 1174f76

Please sign in to comment.