Adds a configuration option to allow explosion/piston protection to be turned off

This commit is contained in:
Kristian Knarvik 2022-01-22 17:10:11 +01:00
parent 0283c917e7
commit 6cee659bd0
4 changed files with 24 additions and 10 deletions

View File

@ -34,6 +34,8 @@ permanently by another cause, when they expire.
- language - The language used for the plugin (en, nb-no) - language - The language used for the plugin (en, nb-no)
- perWorldPermissions - Sets permissions for the current world instead of setting them globally - 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 - 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. signs on "lag pyramids" or similar, but protects signs on top of, or attached to a pillar of sand.

View File

@ -44,6 +44,7 @@ public final class PermissionSigns extends JavaPlugin {
private static PermissionSigns instance; private static PermissionSigns instance;
private static boolean perWorldPermissions; private static boolean perWorldPermissions;
private static boolean enableExtensiveSignProtection; private static boolean enableExtensiveSignProtection;
private static boolean enableIndirectSignProtection;
/** /**
* Instantiates the permission signs class * Instantiates the permission signs class
@ -131,6 +132,15 @@ public final class PermissionSigns extends JavaPlugin {
return enableExtensiveSignProtection; return enableExtensiveSignProtection;
} }
/**
* Gets whether permission sign explosion and piston protection is enabled
*
* @return <p>Whether permission sign explosion and piston protection is enabled</p>
*/
public static boolean indirectProtectionEnabled() {
return enableIndirectSignProtection;
}
@Override @Override
public void reloadConfig() { public void reloadConfig() {
super.reloadConfig(); super.reloadConfig();
@ -172,6 +182,7 @@ public final class PermissionSigns extends JavaPlugin {
String language = config.getString("language", "en"); String language = config.getString("language", "en");
perWorldPermissions = config.getBoolean("perWorldPermissions", false); perWorldPermissions = config.getBoolean("perWorldPermissions", false);
enableExtensiveSignProtection = config.getBoolean("enableExtensiveSignProtection", false); enableExtensiveSignProtection = config.getBoolean("enableExtensiveSignProtection", false);
enableIndirectSignProtection = config.getBoolean("enableIndirectSignProtection", true);
saveConfig(); saveConfig();
return language; return language;
} }

View File

@ -1,5 +1,6 @@
package net.knarcraft.permissionsigns.listener; package net.knarcraft.permissionsigns.listener;
import net.knarcraft.permissionsigns.PermissionSigns;
import net.knarcraft.permissionsigns.formatting.StringFormatter; import net.knarcraft.permissionsigns.formatting.StringFormatter;
import net.knarcraft.permissionsigns.formatting.TranslatableMessage; import net.knarcraft.permissionsigns.formatting.TranslatableMessage;
import net.knarcraft.permissionsigns.manager.SignManager; import net.knarcraft.permissionsigns.manager.SignManager;
@ -15,7 +16,6 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockExplodeEvent; import org.bukkit.event.block.BlockExplodeEvent;
import org.bukkit.event.block.BlockPhysicsEvent;
import org.bukkit.event.block.BlockPistonExtendEvent; import org.bukkit.event.block.BlockPistonExtendEvent;
import org.bukkit.event.block.BlockPistonRetractEvent; import org.bukkit.event.block.BlockPistonRetractEvent;
import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntityExplodeEvent;
@ -30,14 +30,6 @@ import static net.knarcraft.permissionsigns.PermissionSigns.extensiveSignProtect
*/ */
public class BlockListener implements Listener { 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 @EventHandler
public void onPistonExtend(BlockPistonExtendEvent event) { public void onPistonExtend(BlockPistonExtendEvent event) {
preventDestruction(event.getBlocks(), event); preventDestruction(event.getBlocks(), event);
@ -107,6 +99,10 @@ public class BlockListener implements Listener {
* @param event <p>The event to cancel if a permission sign is found</p> * @param event <p>The event to cancel if a permission sign is found</p>
*/ */
private void preventDestruction(List<Block> blocks, Cancellable event) { private void preventDestruction(List<Block> blocks, Cancellable event) {
//Don't do anything if indirect protection is disabled
if (!PermissionSigns.indirectProtectionEnabled()) {
return;
}
for (Block block : blocks) { for (Block block : blocks) {
protectBlockIfPermissionSign(event, block, null); protectBlockIfPermissionSign(event, block, null);
if (event.isCancelled()) { if (event.isCancelled()) {

View File

@ -4,6 +4,11 @@ language: en
# Whether to only give permissions for a single world, instead of granting permissions for all worlds # Whether to only give permissions for a single world, instead of granting permissions for all worlds
perWorldPermissions: false 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 # 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 enableExtensiveSignProtection: false