diff --git a/bukkit/src/main/java/net/william278/husksync/listener/BukkitEventListener.java b/bukkit/src/main/java/net/william278/husksync/listener/BukkitEventListener.java index 94654d35..84b3d43b 100644 --- a/bukkit/src/main/java/net/william278/husksync/listener/BukkitEventListener.java +++ b/bukkit/src/main/java/net/william278/husksync/listener/BukkitEventListener.java @@ -17,6 +17,7 @@ import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityPickupItemEvent; import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryOpenEvent; import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.event.player.PlayerInteractEvent; @@ -55,7 +56,7 @@ public class BukkitEventListener extends EventListener implements BukkitJoinEven final OnlineUser user = BukkitPlayer.adapt(event.getEntity()); // If the player is locked or the plugin disabling, clear their drops - if (cancelPlayerEvent(user)) { + if (cancelPlayerEvent(user.uuid)) { event.getDrops().clear(); return; } @@ -89,43 +90,47 @@ public class BukkitEventListener extends EventListener implements BukkitJoinEven @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onDropItem(@NotNull PlayerDropItemEvent event) { - event.setCancelled(cancelPlayerEvent(BukkitPlayer.adapt(event.getPlayer()))); + event.setCancelled(cancelPlayerEvent(event.getPlayer().getUniqueId())); } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onPickupItem(@NotNull EntityPickupItemEvent event) { if (event.getEntity() instanceof Player player) { - event.setCancelled(cancelPlayerEvent(BukkitPlayer.adapt(player))); + event.setCancelled(cancelPlayerEvent(player.getUniqueId())); } - } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onPlayerInteract(@NotNull PlayerInteractEvent event) { - event.setCancelled(cancelPlayerEvent(BukkitPlayer.adapt(event.getPlayer()))); + event.setCancelled(cancelPlayerEvent(event.getPlayer().getUniqueId())); } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onBlockPlace(@NotNull BlockPlaceEvent event) { - event.setCancelled(cancelPlayerEvent(BukkitPlayer.adapt(event.getPlayer()))); + event.setCancelled(cancelPlayerEvent(event.getPlayer().getUniqueId())); } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onBlockBreak(@NotNull BlockBreakEvent event) { - event.setCancelled(cancelPlayerEvent(BukkitPlayer.adapt(event.getPlayer()))); + event.setCancelled(cancelPlayerEvent(event.getPlayer().getUniqueId())); } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onInventoryOpen(@NotNull InventoryOpenEvent event) { if (event.getPlayer() instanceof Player player) { - event.setCancelled(cancelPlayerEvent(BukkitPlayer.adapt(player))); + event.setCancelled(cancelPlayerEvent(player.getUniqueId())); } } + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onInventoryClick(@NotNull InventoryClickEvent event) { + event.setCancelled(cancelPlayerEvent(event.getWhoClicked().getUniqueId())); + } + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onPlayerTakeDamage(@NotNull EntityDamageEvent event) { if (event.getEntity() instanceof Player player) { - event.setCancelled(cancelPlayerEvent(BukkitPlayer.adapt(player))); + event.setCancelled(cancelPlayerEvent(player.getUniqueId())); } } diff --git a/common/src/main/java/net/william278/husksync/listener/EventListener.java b/common/src/main/java/net/william278/husksync/listener/EventListener.java index 04334eeb..06c5ef9e 100644 --- a/common/src/main/java/net/william278/husksync/listener/EventListener.java +++ b/common/src/main/java/net/william278/husksync/listener/EventListener.java @@ -122,8 +122,8 @@ public abstract class EventListener { private void handleSynchronisationCompletion(@NotNull OnlineUser user, boolean succeeded) { if (succeeded) { plugin.getLocales().getLocale("synchronisation_complete").ifPresent(user::sendActionBar); - lockedPlayers.remove(user.uuid); plugin.getDatabase().ensureUser(user).join(); + lockedPlayers.remove(user.uuid); plugin.getEventCannon().fireSyncCompleteEvent(user); } else { plugin.getLocales().getLocale("synchronisation_failed") @@ -154,7 +154,8 @@ public abstract class EventListener { optionalUserData -> optionalUserData.ifPresent(userData -> plugin.getRedisManager() .setUserData(user, userData).thenRun(() -> plugin.getDatabase() .setUserData(user, userData, DataSaveCause.DISCONNECT))))) - .thenRun(() -> lockedPlayers.remove(user.uuid)).exceptionally(throwable -> { + .thenRun(() -> lockedPlayers.remove(user.uuid)) + .exceptionally(throwable -> { plugin.getLoggingAdapter().log(Level.SEVERE, "An exception occurred handling a player disconnection"); throwable.printStackTrace(); @@ -196,11 +197,11 @@ public abstract class EventListener { /** * Determine whether a player event should be cancelled * - * @param user {@link OnlineUser} performing the event + * @param userUuid The UUID of the user to check * @return Whether the event should be cancelled */ - protected final boolean cancelPlayerEvent(@NotNull OnlineUser user) { - return disabling || lockedPlayers.contains(user.uuid); + protected final boolean cancelPlayerEvent(@NotNull UUID userUuid) { + return disabling || lockedPlayers.contains(userUuid); } /**