From 24fe1195e0ab26a30dbc1a40b9ed5f87d7455bef Mon Sep 17 00:00:00 2001 From: xGinko Date: Tue, 2 Jan 2024 22:29:23 +0100 Subject: [PATCH] utilize util more generically --- .../modules/combat/Burrow.java | 6 +- .../modules/elytra/ElytraAtSpawn.java | 4 +- .../modules/elytra/ElytraGlobal.java | 4 +- .../modules/elytra/ElytraOnCeiling.java | 4 +- .../modules/elytra/ElytraPacketFly.java | 13 +- .../illegals/items/RevertOverstacked.java | 2 +- .../illegals/items/RevertUnbreakables.java | 2 +- .../items/bannedblocks/BanSpecificBlocks.java | 2 +- .../items/enchantments/HigherEnchants.java | 2 +- .../enchantments/InapplicableEnchants.java | 2 +- .../enchantments/IncompatibleEnchants.java | 2 +- .../enchantments/SpecificHigherEnchants.java | 2 +- .../items/nbt/DamageModifierTags.java | 2 +- .../items/nbt/FilledStorageItemTags.java | 2 +- .../items/playerheads/BanPlayerHeads.java | 2 +- .../spawneggs/PreventUsingSpawnEggs.java | 6 +- .../items/spawneggs/RemoveSpawnEggs.java | 4 +- .../PistonExplodePermBlockRemoval.java | 2 +- ...stonPlaceWhileRetractPermBlockRemoval.java | 2 +- .../{ItemUtil.java => MaterialUtil.java} | 146 ++++++++++------ .../modules/combat/Burrow.java | 6 +- .../modules/elytra/ElytraAtSpawn.java | 3 +- .../modules/elytra/ElytraGlobal.java | 3 +- .../modules/elytra/ElytraOnCeiling.java | 3 +- .../modules/elytra/ElytraPacketFly.java | 12 +- .../illegals/items/RevertOverstacked.java | 2 +- .../illegals/items/RevertUnbreakables.java | 2 +- .../items/bannedblocks/BanSpecificBlocks.java | 2 +- .../items/enchantments/HigherEnchants.java | 2 +- .../enchantments/InapplicableEnchants.java | 2 +- .../enchantments/IncompatibleEnchants.java | 2 +- .../enchantments/SpecificHigherEnchants.java | 2 +- .../items/nbt/DamageModifierTags.java | 2 +- .../items/nbt/FilledStorageItemTags.java | 2 +- .../items/playerheads/BanPlayerHeads.java | 2 +- .../spawneggs/PreventUsingSpawnEggs.java | 6 +- .../items/spawneggs/RemoveSpawnEggs.java | 4 +- .../PistonExplodePermBlockRemoval.java | 2 +- ...stonPlaceWhileRetractPermBlockRemoval.java | 2 +- .../{ItemUtil.java => MaterialUtil.java} | 157 +++++++++++------- 40 files changed, 261 insertions(+), 168 deletions(-) rename AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/utils/{ItemUtil.java => MaterialUtil.java} (70%) rename AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/utils/{ItemUtil.java => MaterialUtil.java} (66%) diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/combat/Burrow.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/combat/Burrow.java index a199ab9e0..e4e5dee94 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/combat/Burrow.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/combat/Burrow.java @@ -3,7 +3,7 @@ import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes; import me.moomoo.anarchyexploitfixes.config.Config; import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule; -import me.moomoo.anarchyexploitfixes.utils.ItemUtil; +import me.moomoo.anarchyexploitfixes.utils.MaterialUtil; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.Material; @@ -76,7 +76,7 @@ private void onPlayerMove(PlayerMoveEvent event) { || burrowMaterial.equals(Material.DIRT) // Fixes false positives when trampling farmland || burrowMaterial.equals(Material.SAND) || burrowMaterial.equals(Material.GRAVEL) - || ItemUtil.isShulkerBox(burrowMaterial) + || MaterialUtil.isShulkerBox(burrowMaterial) ) return; if (preventIfBlockAboveBurrow || burrowBlock.getRelative(BlockFace.UP).getType().equals(Material.AIR)) { @@ -120,7 +120,7 @@ private void onPlayerMove(PlayerMoveEvent event) { } // Beacon and Indestructibles - if (burrowMaterial.equals(Material.BEACON) || ItemUtil.isIndestructible(burrowMaterial)) { + if (burrowMaterial.equals(Material.BEACON) || MaterialUtil.isIndestructible(burrowMaterial)) { player.damage(damageWhenMovingInBurrow); if (shouldTeleportUp) teleportUpAndCenter(player, burrowBlock.getLocation()); } diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraAtSpawn.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraAtSpawn.java index c2ea6f59f..d936e7552 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraAtSpawn.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraAtSpawn.java @@ -5,10 +5,10 @@ import me.moomoo.anarchyexploitfixes.config.LanguageCache; import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule; import me.moomoo.anarchyexploitfixes.utils.LocationUtil; +import me.moomoo.anarchyexploitfixes.utils.MaterialUtil; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.TextReplacementConfig; import org.bukkit.Location; -import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -105,7 +105,7 @@ private void onPlayerMove(PlayerMoveEvent event) { if (spawn_AlsoRemoveElytraOnLowTPS) { player.getScheduler().run(plugin, removeElytra -> { PlayerInventory playerInv = player.getInventory(); - if (playerInv.getChestplate() != null && playerInv.getChestplate().getType().equals(Material.ELYTRA)) { + if (MaterialUtil.isElytra(playerInv.getChestplate())) { final ItemStack elytra = playerInv.getChestplate(); playerInv.setChestplate(null); player.getWorld().dropItemNaturally(playerLoc, elytra); diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraGlobal.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraGlobal.java index f17588819..a2d5d1cd9 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraGlobal.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraGlobal.java @@ -5,10 +5,10 @@ import me.moomoo.anarchyexploitfixes.config.LanguageCache; import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule; import me.moomoo.anarchyexploitfixes.utils.LocationUtil; +import me.moomoo.anarchyexploitfixes.utils.MaterialUtil; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.TextReplacementConfig; import org.bukkit.Location; -import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -114,7 +114,7 @@ private void onPlayerMove(PlayerMoveEvent event) { if (global_AlsoRemoveOnLowTPS) { player.getScheduler().run(plugin, removeElytra -> { PlayerInventory playerInv = player.getInventory(); - if (playerInv.getChestplate() != null && playerInv.getChestplate().getType().equals(Material.ELYTRA)) { + if (MaterialUtil.isElytra(playerInv.getChestplate())) { final ItemStack elytra = playerInv.getChestplate(); playerInv.setChestplate(null); player.getWorld().dropItemNaturally(playerLoc, elytra); diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraOnCeiling.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraOnCeiling.java index f0bb684a8..721aaccda 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraOnCeiling.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraOnCeiling.java @@ -5,10 +5,10 @@ import me.moomoo.anarchyexploitfixes.config.LanguageCache; import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule; import me.moomoo.anarchyexploitfixes.utils.LocationUtil; +import me.moomoo.anarchyexploitfixes.utils.MaterialUtil; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.TextReplacementConfig; import org.bukkit.Location; -import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -111,7 +111,7 @@ private void onPlayerMove(PlayerMoveEvent event) { if (ceiling_AlsoRemoveOnLowTPS) { player.getScheduler().run(plugin, removeElytra -> { PlayerInventory playerInv = player.getInventory(); - if (playerInv.getChestplate() != null && playerInv.getChestplate().getType().equals(Material.ELYTRA)) { + if (MaterialUtil.isElytra(playerInv.getChestplate())) { final ItemStack elytra = playerInv.getChestplate(); playerInv.setChestplate(null); player.getWorld().dropItemNaturally(playerLoc, elytra); diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraPacketFly.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraPacketFly.java index ef1e2f235..121f14e11 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraPacketFly.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraPacketFly.java @@ -3,7 +3,7 @@ import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes; import me.moomoo.anarchyexploitfixes.config.Config; import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule; -import org.bukkit.Material; +import me.moomoo.anarchyexploitfixes.utils.MaterialUtil; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -11,6 +11,7 @@ import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityToggleGlideEvent; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; import java.util.HashMap; import java.util.UUID; @@ -82,10 +83,12 @@ private void onElytraOpen(EntityToggleGlideEvent event) { player.getScheduler().run(plugin, kick -> player.kick(AnarchyExploitFixes.getLang(player.locale()).elytra_disablePacketElytraFly), null); } else { player.getScheduler().run(plugin, removeElytra -> { - final ItemStack chestItem = player.getInventory().getChestplate(); - if (chestItem == null || !chestItem.getType().equals(Material.ELYTRA)) return; - player.getInventory().setChestplate(null); - player.getWorld().dropItemNaturally(player.getEyeLocation(), chestItem).setPickupDelay(1); + PlayerInventory playerInv = player.getInventory(); + if (MaterialUtil.isElytra(playerInv.getChestplate())) { + ItemStack elytra = playerInv.getChestplate(); + playerInv.setChestplate(null); + player.getWorld().dropItemNaturally(player.getLocation(), elytra); + } if (notify) player.sendMessage(AnarchyExploitFixes.getLang(player.locale()).elytra_disablePacketElytraFly); }, null); } diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/RevertOverstacked.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/RevertOverstacked.java index 7cabe8c91..115b8b083 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/RevertOverstacked.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/RevertOverstacked.java @@ -31,7 +31,7 @@ import java.util.List; import java.util.logging.Level; -import static me.moomoo.anarchyexploitfixes.utils.ItemUtil.isShulkerBox; +import static me.moomoo.anarchyexploitfixes.utils.MaterialUtil.isShulkerBox; public class RevertOverstacked implements AnarchyExploitFixesModule, Listener { diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/RevertUnbreakables.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/RevertUnbreakables.java index fcb387b03..2a30a1c23 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/RevertUnbreakables.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/RevertUnbreakables.java @@ -34,7 +34,7 @@ import java.util.List; import java.util.logging.Level; -import static me.moomoo.anarchyexploitfixes.utils.ItemUtil.isShulkerBox; +import static me.moomoo.anarchyexploitfixes.utils.MaterialUtil.isShulkerBox; public class RevertUnbreakables implements AnarchyExploitFixesModule, Listener { diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/bannedblocks/BanSpecificBlocks.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/bannedblocks/BanSpecificBlocks.java index 8c06991b0..501c5460b 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/bannedblocks/BanSpecificBlocks.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/bannedblocks/BanSpecificBlocks.java @@ -31,7 +31,7 @@ import java.util.List; import java.util.logging.Level; -import static me.moomoo.anarchyexploitfixes.utils.ItemUtil.isShulkerBox; +import static me.moomoo.anarchyexploitfixes.utils.MaterialUtil.isShulkerBox; public class BanSpecificBlocks implements AnarchyExploitFixesModule, Listener { diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/enchantments/HigherEnchants.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/enchantments/HigherEnchants.java index b5c8030d3..a95f7167b 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/enchantments/HigherEnchants.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/enchantments/HigherEnchants.java @@ -33,7 +33,7 @@ import java.util.Map; import java.util.logging.Level; -import static me.moomoo.anarchyexploitfixes.utils.ItemUtil.isShulkerBox; +import static me.moomoo.anarchyexploitfixes.utils.MaterialUtil.isShulkerBox; public class HigherEnchants implements AnarchyExploitFixesModule, Listener { diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/enchantments/InapplicableEnchants.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/enchantments/InapplicableEnchants.java index 7b414a03f..d792dd3dd 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/enchantments/InapplicableEnchants.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/enchantments/InapplicableEnchants.java @@ -32,7 +32,7 @@ import java.util.Map; import java.util.logging.Level; -import static me.moomoo.anarchyexploitfixes.utils.ItemUtil.isShulkerBox; +import static me.moomoo.anarchyexploitfixes.utils.MaterialUtil.isShulkerBox; public class InapplicableEnchants implements AnarchyExploitFixesModule, Listener { diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/enchantments/IncompatibleEnchants.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/enchantments/IncompatibleEnchants.java index 3069837ea..c5f827300 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/enchantments/IncompatibleEnchants.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/enchantments/IncompatibleEnchants.java @@ -27,7 +27,7 @@ import java.util.List; import java.util.logging.Level; -import static me.moomoo.anarchyexploitfixes.utils.ItemUtil.*; +import static me.moomoo.anarchyexploitfixes.utils.MaterialUtil.*; public class IncompatibleEnchants implements AnarchyExploitFixesModule, Listener { diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/enchantments/SpecificHigherEnchants.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/enchantments/SpecificHigherEnchants.java index ac0d91381..1b5f21e85 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/enchantments/SpecificHigherEnchants.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/enchantments/SpecificHigherEnchants.java @@ -33,7 +33,7 @@ import java.util.Map; import java.util.logging.Level; -import static me.moomoo.anarchyexploitfixes.utils.ItemUtil.isShulkerBox; +import static me.moomoo.anarchyexploitfixes.utils.MaterialUtil.isShulkerBox; public class SpecificHigherEnchants implements AnarchyExploitFixesModule, Listener { diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/nbt/DamageModifierTags.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/nbt/DamageModifierTags.java index 6eca9d43b..77ca53143 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/nbt/DamageModifierTags.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/nbt/DamageModifierTags.java @@ -32,7 +32,7 @@ import java.util.List; import java.util.logging.Level; -import static me.moomoo.anarchyexploitfixes.utils.ItemUtil.isShulkerBox; +import static me.moomoo.anarchyexploitfixes.utils.MaterialUtil.isShulkerBox; import static me.moomoo.anarchyexploitfixes.utils.LogUtil.moduleLog; public class DamageModifierTags implements AnarchyExploitFixesModule, Listener { diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/nbt/FilledStorageItemTags.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/nbt/FilledStorageItemTags.java index eed5f9c8e..2110e011d 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/nbt/FilledStorageItemTags.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/nbt/FilledStorageItemTags.java @@ -28,7 +28,7 @@ import java.util.List; import java.util.logging.Level; -import static me.moomoo.anarchyexploitfixes.utils.ItemUtil.isShulkerBox; +import static me.moomoo.anarchyexploitfixes.utils.MaterialUtil.isShulkerBox; import static me.moomoo.anarchyexploitfixes.utils.LogUtil.materialNotRecognized; import static me.moomoo.anarchyexploitfixes.utils.LogUtil.moduleLog; 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 index 9f3eb25b0..f12da0a25 100755 --- 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 @@ -25,7 +25,7 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.BlockStateMeta; -import static me.moomoo.anarchyexploitfixes.utils.ItemUtil.isShulkerBox; +import static me.moomoo.anarchyexploitfixes.utils.MaterialUtil.isShulkerBox; public class BanPlayerHeads implements AnarchyExploitFixesModule, Listener { 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 index ad7c88636..addfaf5ad 100755 --- 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 @@ -2,7 +2,7 @@ import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes; import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule; -import me.moomoo.anarchyexploitfixes.utils.ItemUtil; +import me.moomoo.anarchyexploitfixes.utils.MaterialUtil; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.HandlerList; @@ -11,7 +11,7 @@ import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.PlayerInventory; -import static me.moomoo.anarchyexploitfixes.utils.ItemUtil.isSpawnEgg; +import static me.moomoo.anarchyexploitfixes.utils.MaterialUtil.isSpawnEgg; public class PreventUsingSpawnEggs implements AnarchyExploitFixesModule, Listener { @@ -50,7 +50,7 @@ public void disable() { private void onInteract(PlayerInteractEvent event) { if (event.getAction().isLeftClick()) return; PlayerInventory inventory = event.getPlayer().getInventory(); - if (ItemUtil.isSpawnEgg(inventory.getItemInMainHand()) || ItemUtil.isSpawnEgg(inventory.getItemInOffHand())) { + if (MaterialUtil.isSpawnEgg(inventory.getItemInMainHand()) || MaterialUtil.isSpawnEgg(inventory.getItemInOffHand())) { 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 index 53dda74e1..f3d4bf8a0 100755 --- 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 @@ -24,8 +24,8 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.BlockStateMeta; -import static me.moomoo.anarchyexploitfixes.utils.ItemUtil.isShulkerBox; -import static me.moomoo.anarchyexploitfixes.utils.ItemUtil.isSpawnEgg; +import static me.moomoo.anarchyexploitfixes.utils.MaterialUtil.isShulkerBox; +import static me.moomoo.anarchyexploitfixes.utils.MaterialUtil.isSpawnEgg; public class RemoveSpawnEggs implements AnarchyExploitFixesModule, Listener { diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/preventions/blockbreak/PistonExplodePermBlockRemoval.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/preventions/blockbreak/PistonExplodePermBlockRemoval.java index e637343f4..d3d792781 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/preventions/blockbreak/PistonExplodePermBlockRemoval.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/preventions/blockbreak/PistonExplodePermBlockRemoval.java @@ -15,7 +15,7 @@ import java.util.HashSet; import java.util.List; -import static me.moomoo.anarchyexploitfixes.utils.ItemUtil.isIndestructible; +import static me.moomoo.anarchyexploitfixes.utils.MaterialUtil.isIndestructible; public class PistonExplodePermBlockRemoval implements AnarchyExploitFixesModule, Listener { diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/preventions/blockbreak/PistonPlaceWhileRetractPermBlockRemoval.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/preventions/blockbreak/PistonPlaceWhileRetractPermBlockRemoval.java index 203e7d22f..b79324a79 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/preventions/blockbreak/PistonPlaceWhileRetractPermBlockRemoval.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/preventions/blockbreak/PistonPlaceWhileRetractPermBlockRemoval.java @@ -11,7 +11,7 @@ import java.util.HashSet; import java.util.List; -import static me.moomoo.anarchyexploitfixes.utils.ItemUtil.isIndestructible; +import static me.moomoo.anarchyexploitfixes.utils.MaterialUtil.isIndestructible; public class PistonPlaceWhileRetractPermBlockRemoval implements AnarchyExploitFixesModule, Listener { diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/utils/ItemUtil.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/utils/MaterialUtil.java similarity index 70% rename from AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/utils/ItemUtil.java rename to AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/utils/MaterialUtil.java index d5cff48c2..e77bd6481 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/utils/ItemUtil.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/utils/MaterialUtil.java @@ -1,13 +1,34 @@ package me.moomoo.anarchyexploitfixes.utils; +import com.destroystokyo.paper.MaterialTags; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; -public class ItemUtil { +public class MaterialUtil { + + public static boolean isIndestructible(Material material) { + return switch (material) { + case BEDROCK, + END_PORTAL_FRAME, + END_PORTAL, + REINFORCED_DEEPSLATE, + TRAPPED_CHEST, + STRUCTURE_BLOCK, + BARRIER, + COMMAND_BLOCK + -> true; + default -> false; + }; + } public static boolean isBook(ItemStack item) { if (item == null) return false; - return switch (item.getType()) { + return isBook(item.getType()); + } + + public static boolean isBook(Material material) { + if (material == null) return false; + return switch (material) { case WRITABLE_BOOK, WRITTEN_BOOK -> true; default -> false; }; @@ -15,31 +36,10 @@ public static boolean isBook(ItemStack item) { public static boolean isShulkerBox(ItemStack item) { if (item == null) return false; - return switch (item.getType()) { - case - SHULKER_BOX, - BLACK_SHULKER_BOX, - BLUE_SHULKER_BOX, - BROWN_SHULKER_BOX, - CYAN_SHULKER_BOX, - GRAY_SHULKER_BOX, - GREEN_SHULKER_BOX, - LIGHT_BLUE_SHULKER_BOX, - LIGHT_GRAY_SHULKER_BOX, - LIME_SHULKER_BOX, - MAGENTA_SHULKER_BOX, - ORANGE_SHULKER_BOX, - PINK_SHULKER_BOX, - PURPLE_SHULKER_BOX, - RED_SHULKER_BOX, - WHITE_SHULKER_BOX, - YELLOW_SHULKER_BOX - -> true; - default -> false; - }; + return isShulkerBox(item.getType()); } - public static boolean isShulkerBox(final Material material) { + public static boolean isShulkerBox(Material material) { return switch (material) { case SHULKER_BOX, @@ -66,7 +66,12 @@ public static boolean isShulkerBox(final Material material) { public static boolean isHelmet(ItemStack item) { if (item == null) return false; - return switch (item.getType()) { + return isHelmet(item.getType()); + } + + public static boolean isHelmet(Material material) { + if (material == null) return false; + return switch (material) { case CHAINMAIL_HELMET, DIAMOND_HELMET, @@ -82,7 +87,12 @@ public static boolean isHelmet(ItemStack item) { public static boolean isChestplate(ItemStack item) { if (item == null) return false; - return switch (item.getType()) { + return isChestplate(item.getType()); + } + + public static boolean isChestplate(Material material) { + if (material == null) return false; + return switch (material) { case CHAINMAIL_CHESTPLATE, DIAMOND_CHESTPLATE, @@ -97,7 +107,12 @@ public static boolean isChestplate(ItemStack item) { public static boolean isLeggings(ItemStack item) { if (item == null) return false; - return switch (item.getType()) { + return isLeggings(item.getType()); + } + + public static boolean isLeggings(Material material) { + if (material == null) return false; + return switch (material) { case CHAINMAIL_LEGGINGS, DIAMOND_LEGGINGS, @@ -112,7 +127,12 @@ public static boolean isLeggings(ItemStack item) { public static boolean isBoots(ItemStack item) { if (item == null) return false; - return switch (item.getType()) { + return isBoots(item.getType()); + } + + public static boolean isBoots(Material material) { + if (material == null) return false; + return switch (material) { case CHAINMAIL_BOOTS, DIAMOND_BOOTS, @@ -127,7 +147,12 @@ public static boolean isBoots(ItemStack item) { public static boolean isAxe(ItemStack item) { if (item == null) return false; - return switch (item.getType()) { + return isAxe(item.getType()); + } + + public static boolean isAxe(Material material) { + if (material == null) return false; + return switch (material) { case NETHERITE_AXE, DIAMOND_AXE, @@ -142,7 +167,12 @@ public static boolean isAxe(ItemStack item) { public static boolean isHoe(ItemStack item) { if (item == null) return false; - return switch (item.getType()) { + return isHoe(item.getType()); + } + + public static boolean isHoe(Material material) { + if (material == null) return false; + return switch (material) { case NETHERITE_HOE, DIAMOND_HOE, @@ -157,7 +187,12 @@ public static boolean isHoe(ItemStack item) { public static boolean isPickaxe(ItemStack item) { if (item == null) return false; - return switch (item.getType()) { + return isPickaxe(item.getType()); + } + + public static boolean isPickaxe(Material material) { + if (material == null) return false; + return switch (material) { case NETHERITE_PICKAXE, DIAMOND_PICKAXE, @@ -172,7 +207,12 @@ public static boolean isPickaxe(ItemStack item) { public static boolean isShovel(ItemStack item) { if (item == null) return false; - return switch (item.getType()) { + return isShovel(item.getType()); + } + + public static boolean isShovel(Material material) { + if (material == null) return false; + return switch (material) { case NETHERITE_SHOVEL, DIAMOND_SHOVEL, @@ -187,7 +227,12 @@ public static boolean isShovel(ItemStack item) { public static boolean isSword(ItemStack item) { if (item == null) return false; - return switch (item.getType()) { + return isSword(item.getType()); + } + + public static boolean isSword(Material material) { + if (material == null) return false; + return switch (material) { case NETHERITE_SWORD, DIAMOND_SWORD, @@ -202,8 +247,12 @@ public static boolean isSword(ItemStack item) { public static boolean isSpawnEgg(ItemStack item) { if (item == null) return false; - final String materialAsString = item.getType().name(); - return materialAsString.contains("SPAWN_EGG") || materialAsString.contains("MONSTER_EGG"); + return MaterialTags.SPAWN_EGGS.isTagged(item); + } + + public static boolean isSpawnEgg(Material material) { + if (material == null) return false; + return MaterialTags.SPAWN_EGGS.isTagged(material); } public static boolean isArmor(ItemStack item) { @@ -211,11 +260,21 @@ public static boolean isArmor(ItemStack item) { return isHelmet(item) || isChestplate(item) || isLeggings(item) || isBoots(item); } + public static boolean isArmor(Material material) { + if (material == null) return false; + return isHelmet(material) || isChestplate(material) || isLeggings(material) || isBoots(material); + } + public static boolean isTool(ItemStack item) { if (item == null) return false; return isAxe(item) || isHoe(item) || isPickaxe(item) || isShovel(item); } + public static boolean isTool(Material material) { + if (material == null) return false; + return isAxe(material) || isHoe(material) || isPickaxe(material) || isShovel(material); + } + public static boolean isElytra(ItemStack item) { if (item == null) return false; return item.getType().equals(Material.ELYTRA); @@ -235,19 +294,4 @@ public static boolean isBow(ItemStack item) { if (item == null) return false; return item.getType().equals(Material.BOW); } - - public static boolean isIndestructible(Material material) { - return switch (material) { - case BEDROCK, - END_PORTAL_FRAME, - END_PORTAL, - REINFORCED_DEEPSLATE, - TRAPPED_CHEST, - STRUCTURE_BLOCK, - BARRIER, - COMMAND_BLOCK - -> true; - default -> false; - }; - } } \ No newline at end of file diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/combat/Burrow.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/combat/Burrow.java index bbfce09b1..aa27c90a9 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/combat/Burrow.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/combat/Burrow.java @@ -5,7 +5,7 @@ import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes; import me.moomoo.anarchyexploitfixes.config.Config; import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule; -import me.moomoo.anarchyexploitfixes.utils.ItemUtil; +import me.moomoo.anarchyexploitfixes.utils.MaterialUtil; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.Material; @@ -113,7 +113,7 @@ private void onPlayerMove(PlayerMoveEvent event) { || burrowMaterial.equals(DIRT) // Fixes false positives when trampling farmland || burrowMaterial.equals(SAND) || burrowMaterial.equals(GRAVEL) - || ItemUtil.isShulkerBox(burrowMaterial) + || MaterialUtil.isShulkerBox(burrowMaterial) ) return; if (preventIfBlockAboveBurrow || burrowBlock.getRelative(BlockFace.UP).getType().equals(AIR)) { @@ -157,7 +157,7 @@ private void onPlayerMove(PlayerMoveEvent event) { } // Beacons and Indestructibles - if (burrowMaterial.equals(BEACON) || ItemUtil.isIndestructible(burrowMaterial)) { + if (burrowMaterial.equals(BEACON) || MaterialUtil.isIndestructible(burrowMaterial)) { player.damage(damageWhenMovingInBurrow); if (shouldTeleportUp) teleportUpAndCenter(player, burrowBlock.getLocation()); } diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraAtSpawn.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraAtSpawn.java index eaa1674b9..4c84c6d06 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraAtSpawn.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraAtSpawn.java @@ -7,6 +7,7 @@ import me.moomoo.anarchyexploitfixes.config.LanguageCache; import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule; import me.moomoo.anarchyexploitfixes.utils.LocationUtil; +import me.moomoo.anarchyexploitfixes.utils.MaterialUtil; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; @@ -102,7 +103,7 @@ private void onPlayerMove(PlayerMoveEvent event) { if (spawn_AlsoRemoveElytraOnLowTPS) { PlayerInventory playerInv = player.getInventory(); - if (playerInv.getChestplate() != null && playerInv.getChestplate().getType().equals(elytra)) { + if (MaterialUtil.isElytra(playerInv.getChestplate())) { ItemStack elytra = playerInv.getChestplate(); playerInv.setChestplate(null); player.getWorld().dropItemNaturally(player.getLocation(), elytra); diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraGlobal.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraGlobal.java index 68f668d11..df5b5fd9b 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraGlobal.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraGlobal.java @@ -7,6 +7,7 @@ import me.moomoo.anarchyexploitfixes.config.LanguageCache; import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule; import me.moomoo.anarchyexploitfixes.utils.LocationUtil; +import me.moomoo.anarchyexploitfixes.utils.MaterialUtil; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; @@ -111,7 +112,7 @@ private void onPlayerMove(PlayerMoveEvent event) { if (global_AlsoRemoveOnLowTPS) { PlayerInventory playerInv = player.getInventory(); - if (playerInv.getChestplate() != null && playerInv.getChestplate().getType().equals(elytra)) { + if (MaterialUtil.isElytra(playerInv.getChestplate())) { ItemStack elytra = playerInv.getChestplate(); playerInv.setChestplate(null); player.getWorld().dropItemNaturally(playerLoc, elytra); diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraOnCeiling.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraOnCeiling.java index 2e6f59738..a22d8a47e 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraOnCeiling.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraOnCeiling.java @@ -7,6 +7,7 @@ import me.moomoo.anarchyexploitfixes.config.LanguageCache; import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule; import me.moomoo.anarchyexploitfixes.utils.LocationUtil; +import me.moomoo.anarchyexploitfixes.utils.MaterialUtil; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; @@ -108,7 +109,7 @@ private void onPlayerMove(PlayerMoveEvent event) { if (ceiling_AlsoRemoveOnLowTPS) { PlayerInventory playerInv = player.getInventory(); - if (playerInv.getChestplate() != null && playerInv.getChestplate().getType().equals(elytra)) { + if (MaterialUtil.isElytra(playerInv.getChestplate())) { ItemStack elytra = playerInv.getChestplate(); playerInv.setChestplate(null); player.getWorld().dropItemNaturally(playerLoc, elytra); diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraPacketFly.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraPacketFly.java index d4fa3df6c..b7785bb55 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraPacketFly.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/elytra/ElytraPacketFly.java @@ -4,6 +4,7 @@ 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.entity.Player; import org.bukkit.event.EventHandler; @@ -11,6 +12,7 @@ import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityToggleGlideEvent; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; import java.util.HashMap; import java.util.UUID; @@ -80,10 +82,12 @@ private void onElytraOpen(EntityToggleGlideEvent event) { if (kickPlayer) { player.kickPlayer(AnarchyExploitFixes.getLang(player.getLocale()).elytra_disablePacketElytraFly); } else { - final ItemStack chestItem = player.getInventory().getChestplate(); - if (chestItem == null || !chestItem.getType().equals(elytra)) return; - player.getInventory().setChestplate(null); - player.getWorld().dropItemNaturally(player.getEyeLocation(), chestItem).setPickupDelay(1); + PlayerInventory playerInv = player.getInventory(); + if (MaterialUtil.isElytra(playerInv.getChestplate())) { + ItemStack elytra = playerInv.getChestplate(); + playerInv.setChestplate(null); + player.getWorld().dropItemNaturally(player.getLocation(), elytra); + } if (notify) player.sendMessage(AnarchyExploitFixes.getLang(player.getLocale()).elytra_disablePacketElytraFly); } } diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/RevertOverstacked.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/RevertOverstacked.java index 621ed73b0..2787409eb 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/RevertOverstacked.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/RevertOverstacked.java @@ -29,7 +29,7 @@ import java.util.List; import java.util.logging.Level; -import static me.moomoo.anarchyexploitfixes.utils.ItemUtil.isShulkerBox; +import static me.moomoo.anarchyexploitfixes.utils.MaterialUtil.isShulkerBox; public class RevertOverstacked implements AnarchyExploitFixesModule, Listener { diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/RevertUnbreakables.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/RevertUnbreakables.java index 0e5615404..ca0fe3e9c 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/RevertUnbreakables.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/RevertUnbreakables.java @@ -30,7 +30,7 @@ import java.util.List; import java.util.logging.Level; -import static me.moomoo.anarchyexploitfixes.utils.ItemUtil.isShulkerBox; +import static me.moomoo.anarchyexploitfixes.utils.MaterialUtil.isShulkerBox; public class RevertUnbreakables implements AnarchyExploitFixesModule, Listener { diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/bannedblocks/BanSpecificBlocks.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/bannedblocks/BanSpecificBlocks.java index ce96c09c6..38e7722ef 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/bannedblocks/BanSpecificBlocks.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/bannedblocks/BanSpecificBlocks.java @@ -29,7 +29,7 @@ import java.util.List; import java.util.logging.Level; -import static me.moomoo.anarchyexploitfixes.utils.ItemUtil.isShulkerBox; +import static me.moomoo.anarchyexploitfixes.utils.MaterialUtil.isShulkerBox; public class BanSpecificBlocks implements AnarchyExploitFixesModule, Listener { diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/enchantments/HigherEnchants.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/enchantments/HigherEnchants.java index 819aebf92..8f83fb78b 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/enchantments/HigherEnchants.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/enchantments/HigherEnchants.java @@ -31,7 +31,7 @@ import java.util.Map; import java.util.logging.Level; -import static me.moomoo.anarchyexploitfixes.utils.ItemUtil.isShulkerBox; +import static me.moomoo.anarchyexploitfixes.utils.MaterialUtil.isShulkerBox; public class HigherEnchants implements AnarchyExploitFixesModule, Listener { diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/enchantments/InapplicableEnchants.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/enchantments/InapplicableEnchants.java index 7cda77ab2..0a50383b4 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/enchantments/InapplicableEnchants.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/enchantments/InapplicableEnchants.java @@ -31,7 +31,7 @@ import java.util.Map; import java.util.logging.Level; -import static me.moomoo.anarchyexploitfixes.utils.ItemUtil.isShulkerBox; +import static me.moomoo.anarchyexploitfixes.utils.MaterialUtil.isShulkerBox; public class InapplicableEnchants implements AnarchyExploitFixesModule, Listener { diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/enchantments/IncompatibleEnchants.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/enchantments/IncompatibleEnchants.java index f773f2ba1..06c27c6c2 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/enchantments/IncompatibleEnchants.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/enchantments/IncompatibleEnchants.java @@ -27,7 +27,7 @@ import java.util.List; import java.util.logging.Level; -import static me.moomoo.anarchyexploitfixes.utils.ItemUtil.*; +import static me.moomoo.anarchyexploitfixes.utils.MaterialUtil.*; public class IncompatibleEnchants implements AnarchyExploitFixesModule, Listener { diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/enchantments/SpecificHigherEnchants.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/enchantments/SpecificHigherEnchants.java index b0a1c6035..f10fe80da 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/enchantments/SpecificHigherEnchants.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/enchantments/SpecificHigherEnchants.java @@ -31,7 +31,7 @@ import java.util.Map; import java.util.logging.Level; -import static me.moomoo.anarchyexploitfixes.utils.ItemUtil.isShulkerBox; +import static me.moomoo.anarchyexploitfixes.utils.MaterialUtil.isShulkerBox; public class SpecificHigherEnchants implements AnarchyExploitFixesModule, Listener { diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/nbt/DamageModifierTags.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/nbt/DamageModifierTags.java index 2161be97e..ba1700df8 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/nbt/DamageModifierTags.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/nbt/DamageModifierTags.java @@ -29,7 +29,7 @@ import java.util.HashSet; import java.util.logging.Level; -import static me.moomoo.anarchyexploitfixes.utils.ItemUtil.isShulkerBox; +import static me.moomoo.anarchyexploitfixes.utils.MaterialUtil.isShulkerBox; import static me.moomoo.anarchyexploitfixes.utils.LogUtil.moduleLog; public class DamageModifierTags implements AnarchyExploitFixesModule, Listener { diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/nbt/FilledStorageItemTags.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/nbt/FilledStorageItemTags.java index 069229935..5447afc53 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/nbt/FilledStorageItemTags.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/nbt/FilledStorageItemTags.java @@ -27,7 +27,7 @@ import java.util.HashSet; import java.util.logging.Level; -import static me.moomoo.anarchyexploitfixes.utils.ItemUtil.isShulkerBox; +import static me.moomoo.anarchyexploitfixes.utils.MaterialUtil.isShulkerBox; import static me.moomoo.anarchyexploitfixes.utils.LogUtil.materialNotRecognized; import static me.moomoo.anarchyexploitfixes.utils.LogUtil.moduleLog; diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/playerheads/BanPlayerHeads.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/playerheads/BanPlayerHeads.java index 0f454a625..7a32d61b4 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/playerheads/BanPlayerHeads.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/playerheads/BanPlayerHeads.java @@ -24,7 +24,7 @@ import org.bukkit.inventory.meta.BlockStateMeta; import org.bukkit.inventory.meta.SkullMeta; -import static me.moomoo.anarchyexploitfixes.utils.ItemUtil.isShulkerBox; +import static me.moomoo.anarchyexploitfixes.utils.MaterialUtil.isShulkerBox; public class BanPlayerHeads implements AnarchyExploitFixesModule, Listener { diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/spawneggs/PreventUsingSpawnEggs.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/spawneggs/PreventUsingSpawnEggs.java index 1eb0a39cb..9bb77e889 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/spawneggs/PreventUsingSpawnEggs.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/spawneggs/PreventUsingSpawnEggs.java @@ -2,7 +2,7 @@ import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes; import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule; -import me.moomoo.anarchyexploitfixes.utils.ItemUtil; +import me.moomoo.anarchyexploitfixes.utils.MaterialUtil; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; @@ -11,7 +11,7 @@ import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.PlayerInventory; -import static me.moomoo.anarchyexploitfixes.utils.ItemUtil.isSpawnEgg; +import static me.moomoo.anarchyexploitfixes.utils.MaterialUtil.isSpawnEgg; public class PreventUsingSpawnEggs implements AnarchyExploitFixesModule, Listener { @@ -46,7 +46,7 @@ private void onInteract(PlayerInteractEvent event) { final Action action = event.getAction(); if (action.equals(Action.LEFT_CLICK_AIR) || action.equals(Action.LEFT_CLICK_BLOCK)) return; PlayerInventory inventory = event.getPlayer().getInventory(); - if (ItemUtil.isSpawnEgg(inventory.getItemInMainHand()) || ItemUtil.isSpawnEgg(inventory.getItemInOffHand())) { + if (MaterialUtil.isSpawnEgg(inventory.getItemInMainHand()) || MaterialUtil.isSpawnEgg(inventory.getItemInOffHand())) { event.setCancelled(true); } } diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/spawneggs/RemoveSpawnEggs.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/spawneggs/RemoveSpawnEggs.java index a8406de80..6f3eda83d 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/spawneggs/RemoveSpawnEggs.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/illegals/items/spawneggs/RemoveSpawnEggs.java @@ -23,8 +23,8 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.BlockStateMeta; -import static me.moomoo.anarchyexploitfixes.utils.ItemUtil.isShulkerBox; -import static me.moomoo.anarchyexploitfixes.utils.ItemUtil.isSpawnEgg; +import static me.moomoo.anarchyexploitfixes.utils.MaterialUtil.isShulkerBox; +import static me.moomoo.anarchyexploitfixes.utils.MaterialUtil.isSpawnEgg; public class RemoveSpawnEggs implements AnarchyExploitFixesModule, Listener { diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/preventions/blockbreak/PistonExplodePermBlockRemoval.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/preventions/blockbreak/PistonExplodePermBlockRemoval.java index a7533329b..4f6cac078 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/preventions/blockbreak/PistonExplodePermBlockRemoval.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/preventions/blockbreak/PistonExplodePermBlockRemoval.java @@ -17,7 +17,7 @@ import java.util.Set; import java.util.logging.Level; -import static me.moomoo.anarchyexploitfixes.utils.ItemUtil.isIndestructible; +import static me.moomoo.anarchyexploitfixes.utils.MaterialUtil.isIndestructible; public class PistonExplodePermBlockRemoval implements AnarchyExploitFixesModule, Listener { diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/preventions/blockbreak/PistonPlaceWhileRetractPermBlockRemoval.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/preventions/blockbreak/PistonPlaceWhileRetractPermBlockRemoval.java index f865ab42a..105125a6e 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/preventions/blockbreak/PistonPlaceWhileRetractPermBlockRemoval.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/preventions/blockbreak/PistonPlaceWhileRetractPermBlockRemoval.java @@ -10,7 +10,7 @@ import java.util.Collections; import java.util.HashSet; -import static me.moomoo.anarchyexploitfixes.utils.ItemUtil.isIndestructible; +import static me.moomoo.anarchyexploitfixes.utils.MaterialUtil.isIndestructible; public class PistonPlaceWhileRetractPermBlockRemoval implements AnarchyExploitFixesModule, Listener { diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/utils/ItemUtil.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/utils/MaterialUtil.java similarity index 66% rename from AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/utils/ItemUtil.java rename to AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/utils/MaterialUtil.java index 9f73b10a8..35a7b8015 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/utils/ItemUtil.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/utils/MaterialUtil.java @@ -5,45 +5,45 @@ import static com.cryptomorin.xseries.XMaterial.*; -public class ItemUtil { +public class MaterialUtil { - public static boolean isBook(final ItemStack item) { - if (item == null) return false; - switch (matchXMaterial(item.getType())) { - case WRITABLE_BOOK: - case WRITTEN_BOOK: + public static boolean isIndestructible(Material material) { + switch (matchXMaterial(material)) { + case BEDROCK: + case END_PORTAL_FRAME: + case END_PORTAL: + case REINFORCED_DEEPSLATE: + case TRAPPED_CHEST: + case STRUCTURE_BLOCK: + case BARRIER: + case COMMAND_BLOCK: return true; default: return false; } } - public static boolean isShulkerBox(final ItemStack item) { + public static boolean isBook(ItemStack item) { if (item == null) return false; - switch (matchXMaterial(item.getType())) { - case SHULKER_BOX: - case BLACK_SHULKER_BOX: - case BLUE_SHULKER_BOX: - case BROWN_SHULKER_BOX: - case CYAN_SHULKER_BOX: - case GRAY_SHULKER_BOX: - case GREEN_SHULKER_BOX: - case LIGHT_BLUE_SHULKER_BOX: - case LIGHT_GRAY_SHULKER_BOX: - case LIME_SHULKER_BOX: - case MAGENTA_SHULKER_BOX: - case ORANGE_SHULKER_BOX: - case PINK_SHULKER_BOX: - case PURPLE_SHULKER_BOX: - case RED_SHULKER_BOX: - case WHITE_SHULKER_BOX: - case YELLOW_SHULKER_BOX: + return isBook(item.getType()); + } + + public static boolean isBook(Material material) { + if (material == null) return false; + switch (matchXMaterial(material)) { + case WRITABLE_BOOK: + case WRITTEN_BOOK: return true; default: return false; } } + public static boolean isShulkerBox(ItemStack item) { + if (item == null) return false; + return isShulkerBox(item.getType()); + } + public static boolean isShulkerBox(final Material material) { switch (matchXMaterial(material)) { case SHULKER_BOX: @@ -69,9 +69,14 @@ public static boolean isShulkerBox(final Material material) { } } - public static boolean isHelmet(final ItemStack item) { + public static boolean isHelmet(ItemStack item) { if (item == null) return false; - switch (matchXMaterial(item.getType())) { + return isHelmet(item.getType()); + } + + public static boolean isHelmet(Material item) { + if (item == null) return false; + switch (matchXMaterial(item)) { case CHAINMAIL_HELMET: case DIAMOND_HELMET: case GOLDEN_HELMET: @@ -85,9 +90,14 @@ public static boolean isHelmet(final ItemStack item) { } } - public static boolean isChestplate(final ItemStack item) { + public static boolean isChestplate(ItemStack item) { if (item == null) return false; - switch (matchXMaterial(item.getType())) { + return isChestplate(item.getType()); + } + + public static boolean isChestplate(Material material) { + if (material == null) return false; + switch (matchXMaterial(material)) { case CHAINMAIL_CHESTPLATE: case DIAMOND_CHESTPLATE: case GOLDEN_CHESTPLATE: @@ -100,9 +110,14 @@ public static boolean isChestplate(final ItemStack item) { } } - public static boolean isLeggings(final ItemStack item) { + public static boolean isLeggings(ItemStack item) { if (item == null) return false; - switch (matchXMaterial(item.getType())) { + return isLeggings(item.getType()); + } + + public static boolean isLeggings(Material material) { + if (material == null) return false; + switch (matchXMaterial(material)) { case CHAINMAIL_LEGGINGS: case DIAMOND_LEGGINGS: case GOLDEN_LEGGINGS: @@ -115,9 +130,14 @@ public static boolean isLeggings(final ItemStack item) { } } - public static boolean isBoots(final ItemStack item) { + public static boolean isBoots(ItemStack item) { if (item == null) return false; - switch (matchXMaterial(item.getType())) { + return isBoots(item.getType()); + } + + public static boolean isBoots(Material material) { + if (material == null) return false; + switch (matchXMaterial(material)) { case CHAINMAIL_BOOTS: case DIAMOND_BOOTS: case GOLDEN_BOOTS: @@ -130,9 +150,14 @@ public static boolean isBoots(final ItemStack item) { } } - public static boolean isAxe(final ItemStack item) { + public static boolean isAxe(ItemStack item) { if (item == null) return false; - switch (matchXMaterial(item.getType())) { + return isAxe(item.getType()); + } + + public static boolean isAxe(Material material) { + if (material == null) return false; + switch (matchXMaterial(material)) { case NETHERITE_AXE: case DIAMOND_AXE: case GOLDEN_AXE: @@ -145,9 +170,14 @@ public static boolean isAxe(final ItemStack item) { } } - public static boolean isHoe(final ItemStack item) { + public static boolean isHoe(ItemStack item) { if (item == null) return false; - switch (matchXMaterial(item.getType())) { + return isHoe(item.getType()); + } + + public static boolean isHoe(Material material) { + if (material == null) return false; + switch (matchXMaterial(material)) { case NETHERITE_HOE: case DIAMOND_HOE: case GOLDEN_HOE: @@ -160,9 +190,14 @@ public static boolean isHoe(final ItemStack item) { } } - public static boolean isPickaxe(final ItemStack item) { + public static boolean isPickaxe(ItemStack item) { if (item == null) return false; - switch (matchXMaterial(item.getType())) { + return isPickaxe(item.getType()); + } + + public static boolean isPickaxe(Material material) { + if (material == null) return false; + switch (matchXMaterial(material)) { case NETHERITE_PICKAXE: case DIAMOND_PICKAXE: case GOLDEN_PICKAXE: @@ -175,9 +210,14 @@ public static boolean isPickaxe(final ItemStack item) { } } - public static boolean isShovel(final ItemStack item) { + public static boolean isShovel(ItemStack item) { if (item == null) return false; - switch (matchXMaterial(item.getType())) { + return isShovel(item.getType()); + } + + public static boolean isShovel(Material material) { + if (material == null) return false; + switch (matchXMaterial(material)) { case NETHERITE_SHOVEL: case DIAMOND_SHOVEL: case GOLDEN_SHOVEL: @@ -190,9 +230,14 @@ public static boolean isShovel(final ItemStack item) { } } - public static boolean isSword(final ItemStack item) { + public static boolean isSword(ItemStack item) { if (item == null) return false; - switch (matchXMaterial(item.getType())) { + return isSword(item.getType()); + } + + public static boolean isSword(Material material) { + if (material == null) return false; + switch (matchXMaterial(material)) { case NETHERITE_SWORD: case DIAMOND_SWORD: case GOLDEN_SWORD: @@ -216,11 +261,21 @@ public static boolean isArmor(final ItemStack item) { return isHelmet(item) || isChestplate(item) || isLeggings(item) || isBoots(item); } + public static boolean isArmor(Material material) { + if (material == null) return false; + return isHelmet(material) || isChestplate(material) || isLeggings(material) || isBoots(material); + } + public static boolean isTool(final ItemStack item) { if (item == null) return false; return isAxe(item) || isHoe(item) || isPickaxe(item) || isShovel(item); } + public static boolean isTool(Material material) { + if (material == null) return false; + return isAxe(material) || isHoe(material) || isPickaxe(material) || isShovel(material); + } + public static boolean isElytra(final ItemStack item) { if (item == null) return false; return matchXMaterial(item.getType()).equals(ELYTRA); @@ -240,20 +295,4 @@ public static boolean isBow(final ItemStack item) { if (item == null) return false; return matchXMaterial(item.getType()).equals(BOW); } - - public static boolean isIndestructible(Material material) { - switch (matchXMaterial(material)) { - case BEDROCK: - case END_PORTAL_FRAME: - case END_PORTAL: - case REINFORCED_DEEPSLATE: - case TRAPPED_CHEST: - case STRUCTURE_BLOCK: - case BARRIER: - case COMMAND_BLOCK: - return true; - default: - return false; - } - } } \ No newline at end of file