-
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add another permanent block break prevention
- Loading branch information
Showing
4 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
...moo/anarchyexploitfixes/modules/preventions/blockbreak/StructureGrowPermBlockRemoval.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
...moo/anarchyexploitfixes/modules/preventions/blockbreak/StructureGrowPermBlockRemoval.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} | ||
} |