Adds info about how to configure the plugin

This commit is contained in:
Kristian Knarvik 2023-12-17 04:07:51 +01:00
parent e233e5d918
commit 37a773511d
4 changed files with 41 additions and 19 deletions

View File

@ -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
- 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" ]
```

View File

@ -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 <p>The logger used by this plugin</p>
*/
public static Logger logger() {
return instance.getLogger();
}
}

View File

@ -45,7 +45,7 @@ public class WorldGuardListener implements Listener {
return;
}
Set<String> 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<ProtectedRegion> regions = new HashSet<>();
List<String> regionNames = worldsSection.getStringList(worldId);
for (String regionName : regionNames) {
@ -95,7 +95,7 @@ public class WorldGuardListener implements Listener {
Set<ProtectedRegion> fromRegions = getOccupiedClearRegions(playerWorld, setFrom.getRegions());
Set<ProtectedRegion> 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 <p>The world the player is currently in</p>
*
* @param playerWorld <p>The world the player is currently in</p>
* @param playerRegions <p>The regions the player is in or will be in</p>
* @return <p>All clear regions found in playerRegions</p>
*/
@ -117,7 +117,7 @@ public class WorldGuardListener implements Listener {
result.add(region);
}
}
return result;
}

View File

@ -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: []
world: [ ]
world_nether: [ ]
world_the_end: [ ]