From ed294714ac7c83666e1cc29bf0977f4767ae592c Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Thu, 18 Aug 2022 13:43:57 -0400 Subject: [PATCH] Stop Game Items From Dropping --- pom.xml | 4 ++-- .../hideAndSeek/configuration/Items.java | 20 +++++++++++++++++++ .../game/listener/PlayerHandler.java | 13 ++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 45b173b..4c3ea75 100644 --- a/pom.xml +++ b/pom.xml @@ -1,7 +1,7 @@ 4.0.0 net.tylermurphy KenshinsHideAndSeek - 1.6.1 + 1.6.2 Hide and Seek Plugin @@ -95,7 +95,7 @@ org.spigotmc spigot-api - 1.13-R0.1-SNAPSHOT + 1.8-R0.1-SNAPSHOT provided diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java index dfdb197..06dbb99 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Items.java @@ -21,6 +21,7 @@ package net.tylermurphy.hideAndSeek.configuration; import com.cryptomorin.xseries.XItemStack; import net.tylermurphy.hideAndSeek.Main; +import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; @@ -129,4 +130,23 @@ public class Items { item.getBoolean("particles") ); } + + public static boolean matchItem(ItemStack stack){ + for(ItemStack check : HIDER_ITEMS) + if(equals(stack,check)) return true; + for(ItemStack check : SEEKER_ITEMS) + if(equals(stack,check)) return true; + return false; + } + + private static boolean equals(ItemStack a, ItemStack b) { + if (a == null) { + return false; + } else if (a == b) { + return true; + } else { + return a.getType() == b.getType() && a.hasItemMeta() == b.hasItemMeta() && (!a.hasItemMeta() || Bukkit.getItemFactory().equals(a.getItemMeta(), b.getItemMeta())); + } + } + } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/listener/PlayerHandler.java b/src/main/java/net/tylermurphy/hideAndSeek/game/listener/PlayerHandler.java index d8790fd..1e7ba69 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/listener/PlayerHandler.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/listener/PlayerHandler.java @@ -1,13 +1,18 @@ package net.tylermurphy.hideAndSeek.game.listener; import net.tylermurphy.hideAndSeek.Main; +import net.tylermurphy.hideAndSeek.configuration.Items; +import net.tylermurphy.hideAndSeek.game.Game; +import net.tylermurphy.hideAndSeek.game.util.Status; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityRegainHealthEvent; import org.bukkit.event.entity.FoodLevelChangeEvent; +import org.bukkit.event.entity.ItemSpawnEvent; import org.bukkit.event.player.PlayerDropItemEvent; +import org.bukkit.inventory.ItemStack; public class PlayerHandler implements Listener { @@ -36,4 +41,12 @@ public class PlayerHandler implements Listener { } } + @EventHandler(priority = EventPriority.HIGHEST) + public void onItemSpawn(ItemSpawnEvent event){ + if(Main.getInstance().getGame().getStatus() == Status.STANDBY) return; + ItemStack item = event.getEntity().getItemStack(); + if(!Items.matchItem(item)) return; + event.setCancelled(true); + } + }