From 37a773511d8219d294ff09f6a88111694fe4c048 Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Sun, 17 Dec 2023 04:07:51 +0100 Subject: [PATCH] Adds info about how to configure the plugin --- README.md | 30 ++++++++++++++++--- .../clearonworldguard/ClearOnWorldGuard.java | 8 ++--- .../clearonworldguard/WorldGuardListener.java | 16 +++++----- src/main/resources/config.yml | 6 ++-- 4 files changed, 41 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 02de36b..2126fe4 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,32 @@ # Clear on WorldGuard -This plugin will clear a player's items when they enter or leave one of the configured regions. This is mainly useful -if players are able to go in creative mode in specific WorldGuard regions. This plugin would prevent players from -leaving with all kinds of items. Note that this plugin won't necessarily be useful unless the region has proper +This plugin will clear a player's items when they enter or leave one of the configured regions. This is mainly useful +if players are able to go in creative mode in specific WorldGuard regions. This plugin would prevent players from +leaving with all kinds of items. Note that this plugin won't necessarily be useful unless the region has proper restrictions, like denying item dropping, and denying any sell commands within the region. ## Dependencies -- WorldGuard \ No newline at end of file +- WorldGuard + +## Configuration + +Add the identifier (name or UUID) of the world you want to specify a region for as a sub-key of clearRegions. Make sure +your world identifier is a string list "worldName: []", and add any regions you want to enable inventory clearing for to +the list of the world the region belongs to. + +Example config: + +```yaml +clearRegions: + world: + - "creative_building" + - "clear" +``` + +or + +```yaml +clearRegions: + world: [ "creative_building", "clear" ] +``` \ No newline at end of file diff --git a/src/main/java/net/knarcraft/clearonworldguard/ClearOnWorldGuard.java b/src/main/java/net/knarcraft/clearonworldguard/ClearOnWorldGuard.java index 27aad0e..c25c9a9 100644 --- a/src/main/java/net/knarcraft/clearonworldguard/ClearOnWorldGuard.java +++ b/src/main/java/net/knarcraft/clearonworldguard/ClearOnWorldGuard.java @@ -8,7 +8,7 @@ import java.util.logging.Logger; @SuppressWarnings("unused") public final class ClearOnWorldGuard extends JavaPlugin { - + private static ClearOnWorldGuard instance; @Override @@ -17,18 +17,18 @@ public final class ClearOnWorldGuard extends JavaPlugin { this.saveDefaultConfig(); this.reloadConfig(); FileConfiguration configuration = this.getConfig(); - + // Register the WorldGuard listener Bukkit.getPluginManager().registerEvents(new WorldGuardListener(configuration), this); } /** * Gets the logger used by this plugin - * + * * @return

The logger used by this plugin

*/ public static Logger logger() { return instance.getLogger(); } - + } diff --git a/src/main/java/net/knarcraft/clearonworldguard/WorldGuardListener.java b/src/main/java/net/knarcraft/clearonworldguard/WorldGuardListener.java index 7916fb8..6ba3d82 100644 --- a/src/main/java/net/knarcraft/clearonworldguard/WorldGuardListener.java +++ b/src/main/java/net/knarcraft/clearonworldguard/WorldGuardListener.java @@ -45,7 +45,7 @@ public class WorldGuardListener implements Listener { return; } Set worlds = worldsSection.getKeys(false); - + for (String worldId : worlds) { // Parse every world identifier World world; @@ -59,15 +59,15 @@ public class WorldGuardListener implements Listener { ClearOnWorldGuard.logger().log(Level.WARNING, "The specified world: \"" + worldId + "\" is invalid."); continue; } - + // Get a region manager for the world RegionManager regionManager = regionContainer.get(BukkitAdapter.adapt(world)); if (regionManager == null) { - ClearOnWorldGuard.logger().log(Level.WARNING, "Unable to get region manager for world: " + + ClearOnWorldGuard.logger().log(Level.WARNING, "Unable to get region manager for world: " + world.getName()); continue; } - + Set regions = new HashSet<>(); List regionNames = worldsSection.getStringList(worldId); for (String regionName : regionNames) { @@ -95,7 +95,7 @@ public class WorldGuardListener implements Listener { Set fromRegions = getOccupiedClearRegions(playerWorld, setFrom.getRegions()); Set toRegions = getOccupiedClearRegions(playerWorld, setTo.getRegions()); - + // If the player is in one or more clear regions, clear unless the clear regions are the same if ((!fromRegions.isEmpty() || !toRegions.isEmpty()) && !fromRegions.equals(toRegions)) { event.getPlayer().getInventory().clear(); @@ -104,8 +104,8 @@ public class WorldGuardListener implements Listener { /** * Gets all regions set as clear regions the player currently occupies - * - * @param playerWorld

The world the player is currently in

+ * + * @param playerWorld

The world the player is currently in

* @param playerRegions

The regions the player is in or will be in

* @return

All clear regions found in playerRegions

*/ @@ -117,7 +117,7 @@ public class WorldGuardListener implements Listener { result.add(region); } } - + return result; } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 81419e9..cf39f17 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -2,6 +2,6 @@ clearRegions: # The name or UUID of a world. Add any regions that should force inventory clearing as a comma-separated list inside # the square parentheses. - world: [] - world_nether: [] - world_the_end: [] \ No newline at end of file + world: [ ] + world_nether: [ ] + world_the_end: [ ] \ No newline at end of file