Skip to content

Commit

Permalink
add inventory interactions to silent swap
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Aug 20, 2024
1 parent 0e24c13 commit fd20a39
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.inventory.InventoryInteractEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerItemHeldEvent;
import org.bukkit.event.player.PlayerKickEvent;
Expand Down Expand Up @@ -57,6 +58,15 @@ private void onPlayerItemHeld(PlayerItemHeldEvent event) { // Fired when a hot b
}
}

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onInventoryInteract(InventoryInteractEvent event) {
if (!swapItemCooldowns.containsKey(event.getWhoClicked().getUniqueId())) return;

if (swapItemCooldowns.get(event.getWhoClicked().getUniqueId()) > System.nanoTime()) {
event.setCancelled(true);
}
}

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
private void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
if (event.getDamager().getType() == XEntityType.PLAYER.get()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.inventory.InventoryInteractEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerItemHeldEvent;
import org.bukkit.event.player.PlayerKickEvent;
Expand Down Expand Up @@ -57,6 +58,15 @@ private void onPlayerItemHeld(PlayerItemHeldEvent event) { // Fired when a hot b
}
}

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onInventoryInteract(InventoryInteractEvent event) {
if (!swapItemCooldowns.containsKey(event.getWhoClicked().getUniqueId())) return;

if (swapItemCooldowns.get(event.getWhoClicked().getUniqueId()) > System.nanoTime()) {
event.setCancelled(true);
}
}

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
private void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
if (event.getDamager().getType() == XEntityType.PLAYER.get()) {
Expand Down

0 comments on commit fd20a39

Please sign in to comment.