diff --git a/README.md b/README.md index c02c85a..05828fd 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 +- removePermissionSignIfMissing - If enabled, permission signs that have lost their physical sign will be removed during + startup. This prevents permission signs from staying in a broken state until the sign is replaced. - 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 diff --git a/src/main/java/net/knarcraft/permissionsigns/PermissionSigns.java b/src/main/java/net/knarcraft/permissionsigns/PermissionSigns.java index c3b1c45..c630a0e 100644 --- a/src/main/java/net/knarcraft/permissionsigns/PermissionSigns.java +++ b/src/main/java/net/knarcraft/permissionsigns/PermissionSigns.java @@ -45,6 +45,7 @@ public final class PermissionSigns extends JavaPlugin { private static boolean perWorldPermissions; private static boolean enableExtensiveSignProtection; private static boolean enableIndirectSignProtection; + private static boolean removePermissionSignIfMissing; /** * Instantiates the permission signs class @@ -141,6 +142,15 @@ public final class PermissionSigns extends JavaPlugin { return enableIndirectSignProtection; } + /** + * Gets whether to remove permissions signs if their physical signs are missing + * + * @return

Whether tor remove permission signs if their signs are missing

+ */ + public static boolean removePermissionSignIfMissing() { + return removePermissionSignIfMissing; + } + @Override public void reloadConfig() { super.reloadConfig(); @@ -183,6 +193,7 @@ public final class PermissionSigns extends JavaPlugin { perWorldPermissions = config.getBoolean("perWorldPermissions", false); enableExtensiveSignProtection = config.getBoolean("enableExtensiveSignProtection", false); enableIndirectSignProtection = config.getBoolean("enableIndirectSignProtection", true); + removePermissionSignIfMissing = config.getBoolean("removePermissionSignIfMissing", true); saveConfig(); return language; } diff --git a/src/main/java/net/knarcraft/permissionsigns/manager/SignManager.java b/src/main/java/net/knarcraft/permissionsigns/manager/SignManager.java index e1fa5f2..14cc854 100644 --- a/src/main/java/net/knarcraft/permissionsigns/manager/SignManager.java +++ b/src/main/java/net/knarcraft/permissionsigns/manager/SignManager.java @@ -31,7 +31,7 @@ public final class SignManager { private static final File signsFile = new File(PermissionSigns.getInstance().getDataFolder(), "data.yml"); private SignManager() { - + } /** @@ -114,11 +114,15 @@ public final class SignManager { */ private static void redrawSigns() { Bukkit.getScheduler().scheduleSyncDelayedTask(PermissionSigns.getInstance(), () -> { + List invalidPermissionSigns = new ArrayList<>(); for (Location key : managedSigns.keySet()) { PermissionSign permissionSign = managedSigns.get(key); Block signBlock = key.getBlock(); BlockState state = signBlock.getState(); if (!(state instanceof Sign sign)) { + if (PermissionSigns.removePermissionSignIfMissing()) { + invalidPermissionSigns.add(permissionSign.getSignLocation()); + } continue; } String[] newLines = permissionSign.getSignLines(); @@ -130,6 +134,9 @@ public final class SignManager { } sign.update(); } + for (Location signLocation : invalidPermissionSigns) { + SignManager.removeSign(signLocation); + } }); } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 7feb3c5..6fe1bc1 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,14 +1,18 @@ # The language to use for the plugin (en, nb-no) 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 +# Whether to remove permission signs during loading if the physical sign is missing. This prevents permission signs from +# existing in a strange state until a new sign is placed in the permission sign's defined location. +removePermissionSignIfMissing: true + # 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 +# 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