Skip to content

Commit

Permalink
add another permanent block break prevention
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Jan 22, 2024
1 parent 36f0e90 commit 7333a27
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
}

0 comments on commit 7333a27

Please sign in to comment.