From 9b48be366e5243082a8b3ea90e2fd67bfc2fe60b Mon Sep 17 00:00:00 2001 From: xGinko Date: Wed, 6 Mar 2024 21:15:39 +0100 Subject: [PATCH] rewrite playerheads and spawneggs module --- .../enums/AEFPermission.java | 11 +- .../modules/AnarchyExploitFixesModule.java | 17 +- .../modules/illegals/items/PlayerHeads.java | 156 +++++++++++++++ .../modules/illegals/items/SpawnEggs.java | 155 +++++++++++++++ .../items/playerheads/BanPlayerHeads.java | 177 ------------------ .../PreventPlacingPlayerHeads.java | 57 ------ .../spawneggs/PreventUsingSpawnEggs.java | 65 ------- .../items/spawneggs/RemoveSpawnEggs.java | 160 ---------------- 8 files changed, 316 insertions(+), 482 deletions(-) create mode 100755 AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/PlayerHeads.java create mode 100755 AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/SpawnEggs.java delete mode 100755 AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/playerheads/BanPlayerHeads.java delete mode 100755 AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/playerheads/PreventPlacingPlayerHeads.java delete mode 100755 AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/spawneggs/PreventUsingSpawnEggs.java delete mode 100755 AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/spawneggs/RemoveSpawnEggs.java diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/enums/AEFPermission.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/enums/AEFPermission.java index b37200a3e..92a28753c 100644 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/enums/AEFPermission.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/enums/AEFPermission.java @@ -1,7 +1,5 @@ package me.moomoo.anarchyexploitfixes.enums; -import org.bukkit.permissions.Permissible; - public enum AEFPermission { BYPASS_ELYTRA("bypass.elytra"), @@ -12,6 +10,8 @@ public enum AEFPermission { BYPASS_ILLEGAL_BANNEDMATERIAL("bypass.illegal.bannedmaterial"), BYPASS_ILLEGAL_BANNEDNAME("bypass.illegal.bannedname"), BYPASS_ILLEGAL_UNBREAKABLE("bypass.illegal.unbreakable"), + BYPASS_ILLEGAL_SPAWNEGG("bypass.illegal.spawnegg"), + BYPASS_ILLEGAL_PLAYERHEAD("bypass.illegal.playerhead"), SILENT_JOIN("silentJoin"), SILENT_LEAVE("silentLeave"); @@ -24,11 +24,4 @@ public enum AEFPermission { public String get() { return permission; } - - public static boolean hasPermission(Iterable toCheck, AEFPermission aefPerm) { - for (Permissible permissible : toCheck) { - if (permissible.hasPermission(aefPerm.get())) return true; - } - return false; - } } diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/AnarchyExploitFixesModule.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/AnarchyExploitFixesModule.java index 22992d48d..2424bc155 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/AnarchyExploitFixesModule.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/AnarchyExploitFixesModule.java @@ -9,20 +9,13 @@ import me.moomoo.anarchyexploitfixes.modules.combat.*; import me.moomoo.anarchyexploitfixes.modules.dupepreventions.*; import me.moomoo.anarchyexploitfixes.modules.elytra.*; -import me.moomoo.anarchyexploitfixes.modules.illegals.items.BannedMaterial; -import me.moomoo.anarchyexploitfixes.modules.illegals.items.BannedItemNames; -import me.moomoo.anarchyexploitfixes.modules.illegals.items.OverstackedItems; -import me.moomoo.anarchyexploitfixes.modules.illegals.items.RevertUnbreakables; +import me.moomoo.anarchyexploitfixes.modules.illegals.items.*; import me.moomoo.anarchyexploitfixes.modules.illegals.items.enchantments.HigherEnchants; import me.moomoo.anarchyexploitfixes.modules.illegals.items.enchantments.InapplicableEnchants; import me.moomoo.anarchyexploitfixes.modules.illegals.items.enchantments.IncompatibleEnchants; import me.moomoo.anarchyexploitfixes.modules.illegals.items.enchantments.SpecificHigherEnchants; import me.moomoo.anarchyexploitfixes.modules.illegals.items.nbt.DamageModifierTags; import me.moomoo.anarchyexploitfixes.modules.illegals.items.nbt.FilledStorageItemTags; -import me.moomoo.anarchyexploitfixes.modules.illegals.items.playerheads.BanPlayerHeads; -import me.moomoo.anarchyexploitfixes.modules.illegals.items.playerheads.PreventPlacingPlayerHeads; -import me.moomoo.anarchyexploitfixes.modules.illegals.items.spawneggs.PreventUsingSpawnEggs; -import me.moomoo.anarchyexploitfixes.modules.illegals.items.spawneggs.RemoveSpawnEggs; import me.moomoo.anarchyexploitfixes.modules.illegals.placedblocks.PeriodicallyRemoveIllegalBlocks; import me.moomoo.anarchyexploitfixes.modules.illegals.placedblocks.RemoveIllegalBlocksOnChunkload; import me.moomoo.anarchyexploitfixes.modules.illegals.placedblocks.RemoveUnnaturalSpawners; @@ -116,6 +109,8 @@ static void reloadModules() { modules.add(new BannedItemNames()); modules.add(new OverstackedItems()); modules.add(new RevertUnbreakables()); + modules.add(new PlayerHeads()); + modules.add(new SpawnEggs()); // Banned Blocks modules.add(new BannedMaterial()); // Enchantments @@ -126,12 +121,6 @@ static void reloadModules() { // NBT Items modules.add(new DamageModifierTags()); modules.add(new FilledStorageItemTags()); - // Player head items - modules.add(new BanPlayerHeads()); - modules.add(new PreventPlacingPlayerHeads()); - // Spawn Eggs - modules.add(new PreventUsingSpawnEggs()); - modules.add(new RemoveSpawnEggs()); /* Lag Preventions */ diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/PlayerHeads.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/PlayerHeads.java new file mode 100755 index 000000000..13e505fe6 --- /dev/null +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/PlayerHeads.java @@ -0,0 +1,156 @@ +package me.moomoo.anarchyexploitfixes.modules.illegals.items; + +import io.papermc.paper.event.player.PrePlayerAttackEntityEvent; +import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes; +import me.moomoo.anarchyexploitfixes.config.Config; +import me.moomoo.anarchyexploitfixes.enums.AEFPermission; +import me.moomoo.anarchyexploitfixes.utils.ItemUtil; +import me.moomoo.anarchyexploitfixes.utils.models.HumanPermHelper; +import org.bukkit.Material; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.HandlerList; +import org.bukkit.event.block.BlockDispenseEvent; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.player.PlayerDropItemEvent; +import org.bukkit.event.player.PlayerInteractEntityEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.ItemStack; + +public class PlayerHeads implements IllegalItemModule { + + private final boolean shouldDelete, checkStored; + + public PlayerHeads() { + shouldEnable(); + Config config = AnarchyExploitFixes.getConfiguration(); + config.addComment("illegals.ban-player-heads.enable", + "Prevents usage of player heads. Bypass permission: " + AEFPermission.BYPASS_ILLEGAL_PLAYERHEAD.get()); + this.shouldDelete = config.getBoolean("illegals.ban-player-heads.remove-items", false); + this.checkStored = config.getBoolean("illegals.ban-player-heads.check-stored-items", false, + "Will delete shulker/bundle if they contain any spawneggs."); + } + + @Override + public String name() { + return "ban-player-heads"; + } + + @Override + public String category() { + return "illegals"; + } + + @Override + public void enable() { + AnarchyExploitFixes plugin = AnarchyExploitFixes.getInstance(); + plugin.getServer().getPluginManager().registerEvents(this, plugin); + } + + @Override + public boolean shouldEnable() { + return AnarchyExploitFixes.getConfiguration().getBoolean("illegals.ban-player-heads.enable", false); + } + + @Override + public void disable() { + HandlerList.unregisterAll(this); + } + + @Override + public ItemCheckResult checkItem(ItemStack itemStack) { + if (itemStack == null) { + return ItemCheckResult.FINE; + } + + switch (itemStack.getType()) { + case PLAYER_HEAD, PLAYER_WALL_HEAD -> { + return ItemCheckResult.IS_ILLEGAL; + } + } + + if (checkStored) { + Iterable storedItems = ItemUtil.getStoredItems(itemStack); + if (storedItems != null) { + for (ItemStack stored : storedItems) { + if (checkItem(stored) != ItemCheckResult.FINE) { + return ItemCheckResult.CONTAINS_ILLEGAL; + } + } + } + } + + return ItemCheckResult.FINE; + } + + @Override + public void takeAction(ItemStack itemStack, ItemCheckResult result) { + if (shouldDelete) itemStack.setType(Material.AIR); + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + private void onDispense(BlockDispenseEvent event) { + switch (event.getItem().getType()) { + case PLAYER_HEAD, PLAYER_WALL_HEAD -> event.setCancelled(true); + } + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + private void onInventoryClick(InventoryClickEvent event) { + if (HumanPermHelper.hasPermission(AEFPermission.BYPASS_ILLEGAL_PLAYERHEAD, event.getWhoClicked())) return; + + takeAction(event.getCurrentItem(), checkItem(event.getCurrentItem())); + takeAction(event.getCursor(), checkItem(event.getCursor())); + for (ItemStack itemStack : event.getWhoClicked().getInventory()) { + takeAction(itemStack, checkItem(itemStack)); + } + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + private void onAttack(PrePlayerAttackEntityEvent event) { + if (!event.willAttack()) return; + ItemStack attackItem = event.getPlayer().getActiveItem(); + final ItemCheckResult result = checkItem(attackItem); + if (result != ItemCheckResult.FINE) { + if (HumanPermHelper.hasPermission(AEFPermission.BYPASS_ILLEGAL_PLAYERHEAD, event.getPlayer())) return; + + event.setCancelled(true); + takeAction(attackItem, result); + } + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + private void onPlayerDropItem(PlayerDropItemEvent event) { + ItemStack droppedItem = event.getItemDrop().getItemStack(); + final ItemCheckResult result = checkItem(droppedItem); + if (result != ItemCheckResult.FINE) { + if (HumanPermHelper.hasPermission(AEFPermission.BYPASS_ILLEGAL_PLAYERHEAD, event.getPlayer())) return; + + takeAction(droppedItem, result); + event.getItemDrop().setItemStack(droppedItem); + } + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = false) + private void onInteract(PlayerInteractEvent event) { + final ItemCheckResult result = checkItem(event.getItem()); + if (result != ItemCheckResult.FINE) { + if (HumanPermHelper.hasPermission(AEFPermission.BYPASS_ILLEGAL_PLAYERHEAD, event.getPlayer())) return; + + event.setCancelled(true); + takeAction(event.getItem(), result); + } + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + private void onInteractEntity(PlayerInteractEntityEvent event) { + ItemStack handItem = event.getPlayer().getInventory().getItem(event.getHand()); + final ItemCheckResult result = checkItem(handItem); + if (result != ItemCheckResult.FINE) { + if (HumanPermHelper.hasPermission(AEFPermission.BYPASS_ILLEGAL_PLAYERHEAD, event.getPlayer())) return; + + event.setCancelled(true); + takeAction(handItem, result); + } + } +} diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/SpawnEggs.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/SpawnEggs.java new file mode 100755 index 000000000..fae56704e --- /dev/null +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/SpawnEggs.java @@ -0,0 +1,155 @@ +package me.moomoo.anarchyexploitfixes.modules.illegals.items; + +import io.papermc.paper.event.player.PrePlayerAttackEntityEvent; +import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes; +import me.moomoo.anarchyexploitfixes.config.Config; +import me.moomoo.anarchyexploitfixes.enums.AEFPermission; +import me.moomoo.anarchyexploitfixes.utils.ItemUtil; +import me.moomoo.anarchyexploitfixes.utils.MaterialUtil; +import me.moomoo.anarchyexploitfixes.utils.models.HumanPermHelper; +import org.bukkit.Material; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.HandlerList; +import org.bukkit.event.block.BlockDispenseEvent; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.player.PlayerDropItemEvent; +import org.bukkit.event.player.PlayerInteractEntityEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.ItemStack; + +public class SpawnEggs implements IllegalItemModule { + + private final boolean shouldDelete, checkStored; + + public SpawnEggs() { + shouldEnable(); + Config config = AnarchyExploitFixes.getConfiguration(); + config.addComment("illegals.ban-spawn-eggs.enable", + "Prevents usage of spawn eggs. Bypass permission: " + AEFPermission.BYPASS_ILLEGAL_SPAWNEGG.get()); + this.shouldDelete = config.getBoolean("illegals.ban-spawn-eggs.remove-spawn-eggs", false); + this.checkStored = config.getBoolean("illegals.ban-spawn-eggs.check-stored-items", false, + "Will delete shulker/bundle if they contain any spawneggs."); + } + + @Override + public String name() { + return "ban-spawn-eggs"; + } + + @Override + public String category() { + return "illegals"; + } + + @Override + public void enable() { + AnarchyExploitFixes plugin = AnarchyExploitFixes.getInstance(); + plugin.getServer().getPluginManager().registerEvents(this, plugin); + } + + @Override + public boolean shouldEnable() { + return AnarchyExploitFixes.getConfiguration().getBoolean("illegals.ban-spawn-eggs.enable", false); + } + + @Override + public void disable() { + HandlerList.unregisterAll(this); + } + + @Override + public ItemCheckResult checkItem(ItemStack itemStack) { + if (itemStack == null) { + return ItemCheckResult.FINE; + } + + if (MaterialUtil.isSpawnEgg(itemStack.getType())) { + return ItemCheckResult.IS_ILLEGAL; + } + + if (checkStored) { + Iterable storedItems = ItemUtil.getStoredItems(itemStack); + if (storedItems != null) { + for (ItemStack stored : storedItems) { + if (checkItem(stored) != ItemCheckResult.FINE) { + return ItemCheckResult.CONTAINS_ILLEGAL; + } + } + } + } + + return ItemCheckResult.FINE; + } + + @Override + public void takeAction(ItemStack itemStack, ItemCheckResult result) { + if (shouldDelete) itemStack.setType(Material.AIR); + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + private void onDispense(BlockDispenseEvent event) { + if (MaterialUtil.isSpawnEgg(event.getItem())) { + event.setCancelled(true); + } + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + private void onInventoryClick(InventoryClickEvent event) { + if (HumanPermHelper.hasPermission(AEFPermission.BYPASS_ILLEGAL_SPAWNEGG, event.getWhoClicked())) return; + + takeAction(event.getCurrentItem(), checkItem(event.getCurrentItem())); + takeAction(event.getCursor(), checkItem(event.getCursor())); + for (ItemStack itemStack : event.getWhoClicked().getInventory()) { + takeAction(itemStack, checkItem(itemStack)); + } + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + private void onAttack(PrePlayerAttackEntityEvent event) { + if (!event.willAttack()) return; + ItemStack attackItem = event.getPlayer().getActiveItem(); + final ItemCheckResult result = checkItem(attackItem); + if (result != ItemCheckResult.FINE) { + if (HumanPermHelper.hasPermission(AEFPermission.BYPASS_ILLEGAL_SPAWNEGG, event.getPlayer())) return; + + event.setCancelled(true); + takeAction(attackItem, result); + } + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + private void onPlayerDropItem(PlayerDropItemEvent event) { + ItemStack droppedItem = event.getItemDrop().getItemStack(); + final ItemCheckResult result = checkItem(droppedItem); + if (result != ItemCheckResult.FINE) { + if (HumanPermHelper.hasPermission(AEFPermission.BYPASS_ILLEGAL_SPAWNEGG, event.getPlayer())) return; + + takeAction(droppedItem, result); + event.getItemDrop().setItemStack(droppedItem); + } + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = false) + private void onInteract(PlayerInteractEvent event) { + final ItemCheckResult result = checkItem(event.getItem()); + if (result != ItemCheckResult.FINE) { + if (HumanPermHelper.hasPermission(AEFPermission.BYPASS_ILLEGAL_SPAWNEGG, event.getPlayer())) return; + + event.setCancelled(true); + takeAction(event.getItem(), result); + } + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + private void onInteractEntity(PlayerInteractEntityEvent event) { + ItemStack handItem = event.getPlayer().getInventory().getItem(event.getHand()); + final ItemCheckResult result = checkItem(handItem); + if (result != ItemCheckResult.FINE) { + if (HumanPermHelper.hasPermission(AEFPermission.BYPASS_ILLEGAL_SPAWNEGG, event.getPlayer())) return; + + event.setCancelled(true); + takeAction(handItem, result); + } + } +} diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/playerheads/BanPlayerHeads.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/playerheads/BanPlayerHeads.java deleted file mode 100755 index cea7e3a31..000000000 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/playerheads/BanPlayerHeads.java +++ /dev/null @@ -1,177 +0,0 @@ -package me.moomoo.anarchyexploitfixes.modules.illegals.items.playerheads; - -import com.destroystokyo.paper.MaterialTags; -import io.papermc.paper.threadedregions.scheduler.ScheduledTask; -import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes; -import me.moomoo.anarchyexploitfixes.config.Config; -import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.block.ShulkerBox; -import org.bukkit.entity.HumanEntity; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.HandlerList; -import org.bukkit.event.Listener; -import org.bukkit.event.block.BlockPlaceEvent; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.event.inventory.InventoryDragEvent; -import org.bukkit.event.inventory.InventoryMoveItemEvent; -import org.bukkit.event.inventory.InventoryOpenEvent; -import org.bukkit.event.player.PlayerAttemptPickupItemEvent; -import org.bukkit.event.player.PlayerDropItemEvent; -import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.BlockStateMeta; - -import static me.moomoo.anarchyexploitfixes.utils.MaterialUtil.isShulkerBox; - -public class BanPlayerHeads implements AnarchyExploitFixesModule, Listener { - - private final AnarchyExploitFixes plugin; - private ScheduledTask periodicInvCheck; - private Listener hopperListener; - private final long checkPeriod; - private final boolean enableStrictPrevention, removeIllegalShulkers, preventHopperBypass; - - public BanPlayerHeads() { - shouldEnable(); - this.plugin = AnarchyExploitFixes.getInstance(); - Config config = AnarchyExploitFixes.getConfiguration(); - config.addComment("illegals.player-heads.remove-items.enable", "This deletes playerheads with and without owners"); - this.preventHopperBypass = config.getBoolean("illegals.player-heads.remove-items.prevent-hopper32k-mechanic", false, """ - Prevents Hopper32k mechanic of placing a shulker containing illegals on top of a hopper and using the illegal\s - out of the hoppers inventory.\s - WARNING: Hooks into InventoryMoveItemEvent, which can become resource intense. Enable only if you need to."""); - this.removeIllegalShulkers = config.getBoolean("illegals.player-heads.remove-items.delete-shulker-if-contains-player-head", false); - this.enableStrictPrevention = config.getBoolean("illegals.player-heads.remove-items.periodically-check-player-inventories.enable", false); - this.checkPeriod = config.getInt("illegals.player-heads.remove-items.periodically-check-player-inventories.check-period-in-ticks", 20); - } - - @Override - public String name() { - return "player-heads.remove-items"; - } - - @Override - public String category() { - return "illegals"; - } - - @Override - public void enable() { - plugin.getServer().getPluginManager().registerEvents(this, plugin); - - if (preventHopperBypass) { - this.hopperListener = new Listener() { - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - private void onInventoryMove(InventoryMoveItemEvent event) { - final Material material = event.getItem().getType(); - if (material.equals(Material.PLAYER_HEAD) || material.equals(Material.PLAYER_WALL_HEAD)) { - event.setCancelled(true); - } - } - }; - plugin.getServer().getPluginManager().registerEvents(hopperListener, plugin); - } - - if (enableStrictPrevention) { - this.periodicInvCheck = plugin.getServer().getGlobalRegionScheduler().runAtFixedRate(plugin, task -> - plugin.getServer().getOnlinePlayers().forEach(player -> player.getScheduler().run(plugin, periodicInvCheck -> - player.getInventory().forEach(this::removePlayerHeadItemIfPresent), null)), checkPeriod, checkPeriod); - } - } - - @Override - public boolean shouldEnable() { - return AnarchyExploitFixes.getConfiguration().getBoolean("illegals.player-heads.remove-items.enable", false); - } - - @Override - public void disable() { - if (periodicInvCheck != null) periodicInvCheck.cancel(); - if (hopperListener != null) HandlerList.unregisterAll(hopperListener); - HandlerList.unregisterAll(this); - } - - private void removePlayerHeadItemIfPresent(ItemStack item) { - if (item == null) return; - - final Material material = item.getType(); - if (material.equals(Material.PLAYER_HEAD) || material.equals(Material.PLAYER_WALL_HEAD)) { - item.subtract(item.getAmount()); - } - - if (removeIllegalShulkers) { - if (isShulkerBox(item) && shulkerContainsIllegalHead((ShulkerBox) ((BlockStateMeta) item.getItemMeta()).getBlockState())) { - item.subtract(item.getAmount()); - } - } - } - - private boolean shulkerContainsIllegalHead(ShulkerBox shulkerBox) { - for (ItemStack shulkerContentItem : shulkerBox.getInventory()) { - if (shulkerContentItem == null) continue; - final Material material = shulkerContentItem.getType(); - if (material.equals(Material.PLAYER_HEAD) || material.equals(Material.PLAYER_WALL_HEAD)) { - return true; - } - } - return false; - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - private void onPlayerJoinEvent(PlayerJoinEvent event) { - Player player = event.getPlayer(); - player.getInventory().forEach(this::removePlayerHeadItemIfPresent); - player.getEnderChest().forEach(this::removePlayerHeadItemIfPresent); - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = false) - private void onPlayerInteractEvent(PlayerInteractEvent event) { - removePlayerHeadItemIfPresent(event.getItem()); - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - private void onPlayerDropItemEvent(PlayerDropItemEvent event) { - removePlayerHeadItemIfPresent(event.getItemDrop().getItemStack()); - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - private void onPlayerPickupItem(PlayerAttemptPickupItemEvent event) { - removePlayerHeadItemIfPresent(event.getItem().getItemStack()); - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - private void onBlockPlace(BlockPlaceEvent event) { - if (!removeIllegalShulkers) return; - Block placedBlock = event.getBlockPlaced(); - if (MaterialTags.SHULKER_BOXES.isTagged(placedBlock) && shulkerContainsIllegalHead((ShulkerBox) placedBlock.getState())) { - placedBlock.setType(Material.AIR); - } - } - - // Inventory Events - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - private void onInventoryOpenEvent(InventoryOpenEvent event) { - event.getInventory().forEach(this::removePlayerHeadItemIfPresent); - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = false) - private void onInventoryClick(InventoryClickEvent event) { - HumanEntity player = event.getWhoClicked(); - player.getScheduler().runDelayed(plugin, checkInvAfterClick -> { - removePlayerHeadItemIfPresent(event.getCursor()); - removePlayerHeadItemIfPresent(event.getCurrentItem()); - event.getInventory().forEach(this::removePlayerHeadItemIfPresent); - player.getInventory().forEach(this::removePlayerHeadItemIfPresent); - }, null, 2L); - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - private void onInventoryInteractEvent(InventoryDragEvent event) { - event.getInventory().forEach(this::removePlayerHeadItemIfPresent); - } -} diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/playerheads/PreventPlacingPlayerHeads.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/playerheads/PreventPlacingPlayerHeads.java deleted file mode 100755 index 8f6157432..000000000 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/playerheads/PreventPlacingPlayerHeads.java +++ /dev/null @@ -1,57 +0,0 @@ -package me.moomoo.anarchyexploitfixes.modules.illegals.items.playerheads; - -import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes; -import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule; -import org.bukkit.Material; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.HandlerList; -import org.bukkit.event.Listener; -import org.bukkit.event.block.BlockPlaceEvent; -import org.bukkit.event.player.PlayerInteractEvent; - -public class PreventPlacingPlayerHeads implements AnarchyExploitFixesModule, Listener { - - public PreventPlacingPlayerHeads() {} - - @Override - public String name() { - return "player-heads.prevent-placing"; - } - - @Override - public String category() { - return "illegals"; - } - - @Override - public void enable() { - AnarchyExploitFixes plugin = AnarchyExploitFixes.getInstance(); - plugin.getServer().getPluginManager().registerEvents(this, plugin); - } - - @Override - public boolean shouldEnable() { - return AnarchyExploitFixes.getConfiguration().getBoolean("illegals.player-heads.prevent-placing", false); - } - - @Override - public void disable() { - HandlerList.unregisterAll(this); - } - - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - private void onInteract(PlayerInteractEvent event) { - if (event.getAction().isLeftClick()) return; - if (event.getMaterial() == Material.PLAYER_HEAD || event.getMaterial() == Material.PLAYER_WALL_HEAD) { - event.setCancelled(true); - } - } - - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - private void onBlockPlace(BlockPlaceEvent event) { - if (event.getBlock().getType() == Material.PLAYER_HEAD || event.getBlock().getType() == Material.PLAYER_WALL_HEAD) { - event.setCancelled(true); - } - } -} diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/spawneggs/PreventUsingSpawnEggs.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/spawneggs/PreventUsingSpawnEggs.java deleted file mode 100755 index 940f484c3..000000000 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/spawneggs/PreventUsingSpawnEggs.java +++ /dev/null @@ -1,65 +0,0 @@ -package me.moomoo.anarchyexploitfixes.modules.illegals.items.spawneggs; - -import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes; -import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule; -import me.moomoo.anarchyexploitfixes.utils.MaterialUtil; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.HandlerList; -import org.bukkit.event.Listener; -import org.bukkit.event.block.BlockDispenseEvent; -import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.inventory.PlayerInventory; - -public class PreventUsingSpawnEggs implements AnarchyExploitFixesModule, Listener { - - public PreventUsingSpawnEggs() { - shouldEnable(); - AnarchyExploitFixes.getConfiguration().addComment("illegals.spawn-eggs.prevent-using", - "Also prevents them from being used in combination with dispensers."); - } - - @Override - public String name() { - return "spawn-eggs.prevent-using"; - } - - @Override - public String category() { - return "illegals"; - } - - @Override - public void enable() { - AnarchyExploitFixes plugin = AnarchyExploitFixes.getInstance(); - plugin.getServer().getPluginManager().registerEvents(this, plugin); - } - - @Override - public boolean shouldEnable() { - return AnarchyExploitFixes.getConfiguration().getBoolean("illegals.spawn-eggs.prevent-using", false); - } - - @Override - public void disable() { - HandlerList.unregisterAll(this); - } - - @EventHandler(priority = EventPriority.HIGHEST) - private void onInteract(PlayerInteractEvent event) { - if (event.getAction().isLeftClick()) return; - - final PlayerInventory inventory = event.getPlayer().getInventory(); - - if (MaterialUtil.isSpawnEgg(inventory.getItemInMainHand()) || MaterialUtil.isSpawnEgg(inventory.getItemInOffHand())) { - event.setCancelled(true); - } - } - - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - private void onDispense(BlockDispenseEvent event) { - if (MaterialUtil.isSpawnEgg(event.getItem())) { - event.setCancelled(true); - } - } -} diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/spawneggs/RemoveSpawnEggs.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/spawneggs/RemoveSpawnEggs.java deleted file mode 100755 index e3bebd0c6..000000000 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/spawneggs/RemoveSpawnEggs.java +++ /dev/null @@ -1,160 +0,0 @@ -package me.moomoo.anarchyexploitfixes.modules.illegals.items.spawneggs; - -import com.destroystokyo.paper.MaterialTags; -import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes; -import me.moomoo.anarchyexploitfixes.config.Config; -import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule; -import me.moomoo.anarchyexploitfixes.utils.MaterialUtil; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.block.ShulkerBox; -import org.bukkit.entity.HumanEntity; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.HandlerList; -import org.bukkit.event.Listener; -import org.bukkit.event.block.BlockPlaceEvent; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.event.inventory.InventoryDragEvent; -import org.bukkit.event.inventory.InventoryMoveItemEvent; -import org.bukkit.event.inventory.InventoryOpenEvent; -import org.bukkit.event.player.PlayerAttemptPickupItemEvent; -import org.bukkit.event.player.PlayerDropItemEvent; -import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.BlockStateMeta; - -import static me.moomoo.anarchyexploitfixes.utils.MaterialUtil.isShulkerBox; - -public class RemoveSpawnEggs implements AnarchyExploitFixesModule, Listener { - - private final AnarchyExploitFixes plugin; - private Listener hopperListener; - private final boolean removeIllegalShulkers, preventHopperBypass; - - public RemoveSpawnEggs() { - shouldEnable(); - this.plugin = AnarchyExploitFixes.getInstance(); - Config config = AnarchyExploitFixes.getConfiguration(); - this.removeIllegalShulkers = config.getBoolean("illegals.spawn-eggs.remove-spawn-eggs.delete-shulker-if-contains-spawn-egg", false); - this.preventHopperBypass = config.getBoolean("illegals.spawn-eggs.remove-spawn-eggs.prevent-hopper32k-mechanic", false, """ - Prevents Hopper32k mechanic of placing a shulker containing illegals on top of a hopper and using the illegal\s - out of the hoppers inventory.\s - WARNING: Hooks into InventoryMoveItemEvent, which can become resource intense. Enable only if you need to."""); - } - - @Override - public String name() { - return "spawn-eggs.remove-spawn-eggs"; - } - - @Override - public String category() { - return "illegals"; - } - - @Override - public void enable() { - plugin.getServer().getPluginManager().registerEvents(this, plugin); - - if (preventHopperBypass) { - this.hopperListener = new Listener() { - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - private void onInventoryMove(InventoryMoveItemEvent event) { - if (MaterialUtil.isSpawnEgg(event.getItem())) { - event.setCancelled(true); - } - } - }; - plugin.getServer().getPluginManager().registerEvents(hopperListener, plugin); - } - } - - @Override - public boolean shouldEnable() { - return AnarchyExploitFixes.getConfiguration().getBoolean("illegals.spawn-eggs.remove-spawn-eggs.enable", false); - } - - @Override - public void disable() { - if (hopperListener != null) HandlerList.unregisterAll(hopperListener); - HandlerList.unregisterAll(this); - } - - private void removeSpawnEggIfPresent(ItemStack item) { - if (item == null || item.getType().equals(Material.AIR)) return; - - if (MaterialUtil.isSpawnEgg(item)) { - item.subtract(item.getAmount()); - } - - if (removeIllegalShulkers) { - if (isShulkerBox(item) && shulkerContainsSpawnEgg((ShulkerBox) ((BlockStateMeta) item.getItemMeta()).getBlockState())) { - item.subtract(item.getAmount()); - } - } - } - - private boolean shulkerContainsSpawnEgg(ShulkerBox shulkerBox) { - for (ItemStack shulkerContentItem : shulkerBox.getInventory()) { - if (MaterialUtil.isSpawnEgg(shulkerContentItem)) return true; - } - return false; - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - private void onPlayerJoinEvent(PlayerJoinEvent event) { - Player player = event.getPlayer(); - player.getInventory().forEach(this::removeSpawnEggIfPresent); - player.getEnderChest().forEach(this::removeSpawnEggIfPresent); - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = false) - private void onPlayerInteractEvent(PlayerInteractEvent event) { - removeSpawnEggIfPresent(event.getItem()); - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - private void onPlayerDropItemEvent(PlayerDropItemEvent event) { - removeSpawnEggIfPresent(event.getItemDrop().getItemStack()); - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - private void onPlayerPickupItem(PlayerAttemptPickupItemEvent event) { - removeSpawnEggIfPresent(event.getItem().getItemStack()); - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - private void onBlockPlace(BlockPlaceEvent event) { - if (removeIllegalShulkers) { - Block placedBlock = event.getBlockPlaced(); - if (MaterialTags.SHULKER_BOXES.isTagged(placedBlock) && shulkerContainsSpawnEgg((ShulkerBox) placedBlock.getState())) { - placedBlock.setType(Material.AIR); - } - } - } - - // Inventory Events - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - private void onInventoryOpenEvent(InventoryOpenEvent event) { - event.getInventory().forEach(this::removeSpawnEggIfPresent); - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = false) - private void onInventoryClick(InventoryClickEvent event) { - HumanEntity player = event.getWhoClicked(); - player.getScheduler().runDelayed(plugin, checkInvAfterClick -> { - removeSpawnEggIfPresent(event.getCursor()); - removeSpawnEggIfPresent(event.getCurrentItem()); - event.getInventory().forEach(this::removeSpawnEggIfPresent); - player.getInventory().forEach(this::removeSpawnEggIfPresent); - }, null, 2L); - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - private void onInventoryInteractEvent(InventoryDragEvent event) { - event.getInventory().forEach(this::removeSpawnEggIfPresent); - } -}