From 6cee659bd053503863460e9c85101d8bd848f308 Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Sat, 22 Jan 2022 17:10:11 +0100 Subject: [PATCH] Adds a configuration option to allow explosion/piston protection to be turned off --- README.md | 2 ++ .../knarcraft/permissionsigns/PermissionSigns.java | 11 +++++++++++ .../permissionsigns/listener/BlockListener.java | 14 +++++--------- src/main/resources/config.yml | 7 ++++++- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 7ab4b52..c02c85a 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,8 @@ permanently by another cause, when they expire. - language - The language used for the plugin (en, nb-no) - perWorldPermissions - Sets permissions for the current world instead of setting them globally +- enableIndirectSignProtection - Protects permission signs against indirect sources such as pistons and explosions. Only + disable this if your permission signs are protected by another plugin. - enableExtensiveSignProtection - Whether to protect signs on "unstable" blocks such as sand or anvils. Does not protect signs on "lag pyramids" or similar, but protects signs on top of, or attached to a pillar of sand. diff --git a/src/main/java/net/knarcraft/permissionsigns/PermissionSigns.java b/src/main/java/net/knarcraft/permissionsigns/PermissionSigns.java index 0bef189..c3b1c45 100644 --- a/src/main/java/net/knarcraft/permissionsigns/PermissionSigns.java +++ b/src/main/java/net/knarcraft/permissionsigns/PermissionSigns.java @@ -44,6 +44,7 @@ public final class PermissionSigns extends JavaPlugin { private static PermissionSigns instance; private static boolean perWorldPermissions; private static boolean enableExtensiveSignProtection; + private static boolean enableIndirectSignProtection; /** * Instantiates the permission signs class @@ -131,6 +132,15 @@ public final class PermissionSigns extends JavaPlugin { return enableExtensiveSignProtection; } + /** + * Gets whether permission sign explosion and piston protection is enabled + * + * @return

Whether permission sign explosion and piston protection is enabled

+ */ + public static boolean indirectProtectionEnabled() { + return enableIndirectSignProtection; + } + @Override public void reloadConfig() { super.reloadConfig(); @@ -172,6 +182,7 @@ public final class PermissionSigns extends JavaPlugin { String language = config.getString("language", "en"); perWorldPermissions = config.getBoolean("perWorldPermissions", false); enableExtensiveSignProtection = config.getBoolean("enableExtensiveSignProtection", false); + enableIndirectSignProtection = config.getBoolean("enableIndirectSignProtection", true); saveConfig(); return language; } diff --git a/src/main/java/net/knarcraft/permissionsigns/listener/BlockListener.java b/src/main/java/net/knarcraft/permissionsigns/listener/BlockListener.java index 4e0a7de..bf1748e 100644 --- a/src/main/java/net/knarcraft/permissionsigns/listener/BlockListener.java +++ b/src/main/java/net/knarcraft/permissionsigns/listener/BlockListener.java @@ -1,5 +1,6 @@ package net.knarcraft.permissionsigns.listener; +import net.knarcraft.permissionsigns.PermissionSigns; import net.knarcraft.permissionsigns.formatting.StringFormatter; import net.knarcraft.permissionsigns.formatting.TranslatableMessage; import net.knarcraft.permissionsigns.manager.SignManager; @@ -15,7 +16,6 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockExplodeEvent; -import org.bukkit.event.block.BlockPhysicsEvent; import org.bukkit.event.block.BlockPistonExtendEvent; import org.bukkit.event.block.BlockPistonRetractEvent; import org.bukkit.event.entity.EntityExplodeEvent; @@ -30,14 +30,6 @@ import static net.knarcraft.permissionsigns.PermissionSigns.extensiveSignProtect */ public class BlockListener implements Listener { - @EventHandler - public void onBlockPhysics(BlockPhysicsEvent event) { - //Block any physics events from destroying signs - if (SignManager.getSign(event.getBlock().getLocation()) != null) { - event.setCancelled(true); - } - } - @EventHandler public void onPistonExtend(BlockPistonExtendEvent event) { preventDestruction(event.getBlocks(), event); @@ -107,6 +99,10 @@ public class BlockListener implements Listener { * @param event

The event to cancel if a permission sign is found

*/ private void preventDestruction(List blocks, Cancellable event) { + //Don't do anything if indirect protection is disabled + if (!PermissionSigns.indirectProtectionEnabled()) { + return; + } for (Block block : blocks) { protectBlockIfPermissionSign(event, block, null); if (event.isCancelled()) { diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 3e7e18a..7feb3c5 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -4,6 +4,11 @@ language: en # Whether to only give permissions for a single world, instead of granting permissions for all worlds perWorldPermissions: false +# Whether to enable protection against indirect damage sources such as explosions and pistons. You can disable this to +# save some resources if permission signs are only placed in a protected area. WARNING: Disabling this and placing +# permission signs in an unprotected area allows unauthorized players to destroy (but not de-register) permission signs +enableIndirectSignProtection: true + # Whether to protect permission signs on falling blocks (sand, gravel, anvil, drip-stone, signs) by preventing breakage -# of the blocks that would cause a sign to be destroyed. +# of the blocks that would cause a sign to be destroyed enableExtensiveSignProtection: false \ No newline at end of file