Adds info about how to configure the plugin
This commit is contained in:
parent
e233e5d918
commit
37a773511d
30
README.md
30
README.md
@ -1,10 +1,32 @@
|
|||||||
# Clear on WorldGuard
|
# 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
|
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
|
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
|
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.
|
restrictions, like denying item dropping, and denying any sell commands within the region.
|
||||||
|
|
||||||
## Dependencies
|
## 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" ]
|
||||||
|
```
|
@ -8,7 +8,7 @@ import java.util.logging.Logger;
|
|||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public final class ClearOnWorldGuard extends JavaPlugin {
|
public final class ClearOnWorldGuard extends JavaPlugin {
|
||||||
|
|
||||||
private static ClearOnWorldGuard instance;
|
private static ClearOnWorldGuard instance;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -17,18 +17,18 @@ public final class ClearOnWorldGuard extends JavaPlugin {
|
|||||||
this.saveDefaultConfig();
|
this.saveDefaultConfig();
|
||||||
this.reloadConfig();
|
this.reloadConfig();
|
||||||
FileConfiguration configuration = this.getConfig();
|
FileConfiguration configuration = this.getConfig();
|
||||||
|
|
||||||
// Register the WorldGuard listener
|
// Register the WorldGuard listener
|
||||||
Bukkit.getPluginManager().registerEvents(new WorldGuardListener(configuration), this);
|
Bukkit.getPluginManager().registerEvents(new WorldGuardListener(configuration), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the logger used by this plugin
|
* Gets the logger used by this plugin
|
||||||
*
|
*
|
||||||
* @return <p>The logger used by this plugin</p>
|
* @return <p>The logger used by this plugin</p>
|
||||||
*/
|
*/
|
||||||
public static Logger logger() {
|
public static Logger logger() {
|
||||||
return instance.getLogger();
|
return instance.getLogger();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ public class WorldGuardListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Set<String> worlds = worldsSection.getKeys(false);
|
Set<String> worlds = worldsSection.getKeys(false);
|
||||||
|
|
||||||
for (String worldId : worlds) {
|
for (String worldId : worlds) {
|
||||||
// Parse every world identifier
|
// Parse every world identifier
|
||||||
World world;
|
World world;
|
||||||
@ -59,15 +59,15 @@ public class WorldGuardListener implements Listener {
|
|||||||
ClearOnWorldGuard.logger().log(Level.WARNING, "The specified world: \"" + worldId + "\" is invalid.");
|
ClearOnWorldGuard.logger().log(Level.WARNING, "The specified world: \"" + worldId + "\" is invalid.");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get a region manager for the world
|
// Get a region manager for the world
|
||||||
RegionManager regionManager = regionContainer.get(BukkitAdapter.adapt(world));
|
RegionManager regionManager = regionContainer.get(BukkitAdapter.adapt(world));
|
||||||
if (regionManager == null) {
|
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());
|
world.getName());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Set<ProtectedRegion> regions = new HashSet<>();
|
Set<ProtectedRegion> regions = new HashSet<>();
|
||||||
List<String> regionNames = worldsSection.getStringList(worldId);
|
List<String> regionNames = worldsSection.getStringList(worldId);
|
||||||
for (String regionName : regionNames) {
|
for (String regionName : regionNames) {
|
||||||
@ -95,7 +95,7 @@ public class WorldGuardListener implements Listener {
|
|||||||
|
|
||||||
Set<ProtectedRegion> fromRegions = getOccupiedClearRegions(playerWorld, setFrom.getRegions());
|
Set<ProtectedRegion> fromRegions = getOccupiedClearRegions(playerWorld, setFrom.getRegions());
|
||||||
Set<ProtectedRegion> toRegions = getOccupiedClearRegions(playerWorld, setTo.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 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)) {
|
if ((!fromRegions.isEmpty() || !toRegions.isEmpty()) && !fromRegions.equals(toRegions)) {
|
||||||
event.getPlayer().getInventory().clear();
|
event.getPlayer().getInventory().clear();
|
||||||
@ -104,8 +104,8 @@ public class WorldGuardListener implements Listener {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets all regions set as clear regions the player currently occupies
|
* 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>
|
* @param playerRegions <p>The regions the player is in or will be in</p>
|
||||||
* @return <p>All clear regions found in playerRegions</p>
|
* @return <p>All clear regions found in playerRegions</p>
|
||||||
*/
|
*/
|
||||||
@ -117,7 +117,7 @@ public class WorldGuardListener implements Listener {
|
|||||||
result.add(region);
|
result.add(region);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,6 @@
|
|||||||
clearRegions:
|
clearRegions:
|
||||||
# The name or UUID of a world. Add any regions that should force inventory clearing as a comma-separated list inside
|
# The name or UUID of a world. Add any regions that should force inventory clearing as a comma-separated list inside
|
||||||
# the square parentheses.
|
# the square parentheses.
|
||||||
world: []
|
world: [ ]
|
||||||
world_nether: []
|
world_nether: [ ]
|
||||||
world_the_end: []
|
world_the_end: [ ]
|
Loading…
Reference in New Issue
Block a user