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 b55c841bc..9d0ebe086 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/AnarchyExploitFixesModule.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/AnarchyExploitFixesModule.java @@ -40,6 +40,7 @@ import me.moomoo.anarchyexploitfixes.modules.preventions.PreventOppedPlayers; import me.moomoo.anarchyexploitfixes.modules.preventions.blockbreak.PistonExplodePermBlockRemoval; import me.moomoo.anarchyexploitfixes.modules.preventions.blockbreak.PistonPlaceWhileRetractPermBlockRemoval; +import me.moomoo.anarchyexploitfixes.modules.preventions.blockbreak.StructureGrowPermBlockRemoval; import me.moomoo.anarchyexploitfixes.modules.preventions.portals.*; import me.moomoo.anarchyexploitfixes.modules.preventions.withers.*; import me.moomoo.anarchyexploitfixes.modules.protocollib.boatfly.AntiBoatFlyModule; @@ -188,6 +189,7 @@ static void reloadModules() { // Blockbreak modules.add(new PistonExplodePermBlockRemoval()); modules.add(new PistonPlaceWhileRetractPermBlockRemoval()); + modules.add(new StructureGrowPermBlockRemoval()); // Portals modules.add(new EndPortalDestruction()); modules.add(new PreventAllEntitiesInPortals()); diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/preventions/blockbreak/StructureGrowPermBlockRemoval.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/preventions/blockbreak/StructureGrowPermBlockRemoval.java new file mode 100644 index 000000000..32a81d4b7 --- /dev/null +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/preventions/blockbreak/StructureGrowPermBlockRemoval.java @@ -0,0 +1,60 @@ +package me.moomoo.anarchyexploitfixes.modules.preventions.blockbreak; + +import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes; +import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule; +import me.moomoo.anarchyexploitfixes.utils.LogUtil; +import me.moomoo.anarchyexploitfixes.utils.MaterialUtil; +import org.bukkit.World; +import org.bukkit.block.BlockState; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.world.StructureGrowEvent; + +import java.util.logging.Level; + +public class StructureGrowPermBlockRemoval implements AnarchyExploitFixesModule, Listener { + + public StructureGrowPermBlockRemoval() { + shouldEnable(); + AnarchyExploitFixes.getConfiguration().addComment("preventions.permanent-block-breaking.by-growing-structures.enable", + "Prevents removal of permanent blocks by growing structures like mushrooms into them."); + } + + @Override + public String name() { + return "prevent-removing-bedrock-by-growing-structures"; + } + + @Override + public String category() { + return "bedrock"; + } + + @Override + public void enable() { + AnarchyExploitFixes plugin = AnarchyExploitFixes.getInstance(); + plugin.getServer().getPluginManager().registerEvents(this, plugin); + } + + @Override + public boolean shouldEnable() { + return AnarchyExploitFixes.getConfiguration().getBoolean("preventions.permanent-block-breaking.by-growing-structures.enable", true); + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onStructureGrow(StructureGrowEvent event) { + final World world = event.getWorld(); + for (final BlockState blockState : event.getBlocks()) { + if (MaterialUtil.isIndestructible(world.getBlockAt(blockState.getLocation()).getType())) { + event.setCancelled(true); + LogUtil.moduleLog(Level.INFO, name(), "Prevented permanent block break by growing a structure at\n" + + "x: "+blockState.getLocation().getX() + ", " + + "y: "+blockState.getLocation().getY() + ", " + + "z: "+blockState.getLocation().getX() + ", " + + "world: "+blockState.getLocation().getWorld().getName()); + return; + } + } + } +} diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/AnarchyExploitFixesModule.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/AnarchyExploitFixesModule.java index 78e916822..fcab6a3f3 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/AnarchyExploitFixesModule.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/AnarchyExploitFixesModule.java @@ -40,6 +40,7 @@ import me.moomoo.anarchyexploitfixes.modules.preventions.*; import me.moomoo.anarchyexploitfixes.modules.preventions.blockbreak.PistonExplodePermBlockRemoval; import me.moomoo.anarchyexploitfixes.modules.preventions.blockbreak.PistonPlaceWhileRetractPermBlockRemoval; +import me.moomoo.anarchyexploitfixes.modules.preventions.blockbreak.StructureGrowPermBlockRemoval; import me.moomoo.anarchyexploitfixes.modules.preventions.portals.*; import me.moomoo.anarchyexploitfixes.modules.preventions.withers.*; import me.moomoo.anarchyexploitfixes.modules.protocollib.boatfly.AntiBoatFlyModule; @@ -201,6 +202,7 @@ static void reloadModules() { // Blockbreak modules.add(new PistonExplodePermBlockRemoval()); modules.add(new PistonPlaceWhileRetractPermBlockRemoval()); + modules.add(new StructureGrowPermBlockRemoval()); // Portals modules.add(new EndPortalDestruction()); modules.add(new PreventAllEntitiesInPortals()); diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/preventions/blockbreak/StructureGrowPermBlockRemoval.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/preventions/blockbreak/StructureGrowPermBlockRemoval.java new file mode 100644 index 000000000..18bb66864 --- /dev/null +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/preventions/blockbreak/StructureGrowPermBlockRemoval.java @@ -0,0 +1,60 @@ +package me.moomoo.anarchyexploitfixes.modules.preventions.blockbreak; + +import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes; +import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule; +import me.moomoo.anarchyexploitfixes.utils.LogUtil; +import me.moomoo.anarchyexploitfixes.utils.MaterialUtil; +import org.bukkit.World; +import org.bukkit.block.BlockState; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.world.StructureGrowEvent; + +import java.util.logging.Level; + +public class StructureGrowPermBlockRemoval implements AnarchyExploitFixesModule, Listener { + + public StructureGrowPermBlockRemoval() { + shouldEnable(); + AnarchyExploitFixes.getConfiguration().addComment("preventions.permanent-block-breaking.by-growing-structures.enable", + "Prevents removal of permanent blocks by growing structures like mushrooms into them."); + } + + @Override + public String name() { + return "prevent-removing-bedrock-by-growing-structures"; + } + + @Override + public String category() { + return "bedrock"; + } + + @Override + public void enable() { + AnarchyExploitFixes plugin = AnarchyExploitFixes.getInstance(); + plugin.getServer().getPluginManager().registerEvents(this, plugin); + } + + @Override + public boolean shouldEnable() { + return AnarchyExploitFixes.getConfiguration().getBoolean("preventions.permanent-block-breaking.by-growing-structures.enable", true); + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onStructureGrow(StructureGrowEvent event) { + final World world = event.getWorld(); + for (final BlockState blockState : event.getBlocks()) { + if (MaterialUtil.INDESTRUCTIBLES.contains(world.getBlockAt(blockState.getLocation()).getType())) { + event.setCancelled(true); + LogUtil.moduleLog(Level.INFO, name(), "Prevented permanent block break by growing a structure at\n" + + "x: "+blockState.getLocation().getX() + ", " + + "y: "+blockState.getLocation().getY() + ", " + + "z: "+blockState.getLocation().getX() + ", " + + "world: "+blockState.getLocation().getWorld().getName()); + return; + } + } + } +}