Added MAX_PLAYER and MAX_PLAYER_MESSAGE flags

Allows setting maximum number of players in a region
and sends a message if a region is at capacity.
This commit is contained in:
Wizjany 2013-01-11 17:09:15 -05:00
parent c1b98b9e40
commit 955b0e991c
2 changed files with 33 additions and 4 deletions

View File

@ -89,7 +89,9 @@ public void onPlayerMove(PlayerMoveEvent event) {
ConfigurationManager cfg = plugin.getGlobalStateManager(); ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(world); WorldConfiguration wcfg = cfg.get(world);
if (player.getVehicle() != null) return; // handled in vehicle listener if (player.getVehicle() != null) {
return; // handled in vehicle listener
}
if (wcfg.useRegions) { if (wcfg.useRegions) {
// Did we move a block? // Did we move a block?
if (event.getFrom().getBlockX() != event.getTo().getBlockX() if (event.getFrom().getBlockX() != event.getTo().getBlockX()
@ -110,9 +112,34 @@ public void onPlayerMove(PlayerMoveEvent event) {
Vector pt = new Vector(event.getTo().getBlockX(), event.getTo().getBlockY(), event.getTo().getBlockZ()); Vector pt = new Vector(event.getTo().getBlockX(), event.getTo().getBlockY(), event.getTo().getBlockZ());
ApplicableRegionSet set = mgr.getApplicableRegions(pt); ApplicableRegionSet set = mgr.getApplicableRegions(pt);
// check if region is full
Integer maxPlayers = set.getFlag(DefaultFlag.MAX_PLAYERS);
boolean regionFull = false;
String maxPlayerMessage = null;
if (maxPlayers != null && !hasBypass) {
for (ProtectedRegion region : set) {
int occupantCount = 0;
for(Player occupant : world.getPlayers()) {
// Make sure you're not checking the same player
// A person with bypass doesn't count as an occupant of the region
if (!occupant.equals(player) && !plugin.getGlobalRegionManager().hasBypass(occupant, world)) {
if (region.contains(BukkitUtil.toVector(occupant.getLocation()))) {
if (++occupantCount >= maxPlayers) {
regionFull = true;
maxPlayerMessage = region.getFlag(DefaultFlag.MAX_PLAYERS_MESSAGE);
break;
}
}
}
}
}
}
boolean entryAllowed = set.allows(DefaultFlag.ENTRY, localPlayer); boolean entryAllowed = set.allows(DefaultFlag.ENTRY, localPlayer);
if (!hasBypass && !entryAllowed) { if (!hasBypass && (!entryAllowed || regionFull)) {
player.sendMessage(ChatColor.DARK_RED + "You are not permitted to enter this area."); String message = maxPlayerMessage != null ? maxPlayerMessage : "You are not permitted to enter this area.";
player.sendMessage(ChatColor.DARK_RED + message);
Location newLoc = event.getFrom(); Location newLoc = event.getFrom();
newLoc.setX(newLoc.getBlockX() + 0.5); newLoc.setX(newLoc.getBlockX() + 0.5);

View File

@ -71,6 +71,7 @@ public final class DefaultFlag {
public static final StateFlag POTION_SPLASH = new StateFlag("potion-splash", true); public static final StateFlag POTION_SPLASH = new StateFlag("potion-splash", true);
public static final StringFlag GREET_MESSAGE = new StringFlag("greeting", RegionGroup.ALL); public static final StringFlag GREET_MESSAGE = new StringFlag("greeting", RegionGroup.ALL);
public static final StringFlag FAREWELL_MESSAGE = new StringFlag("farewell", RegionGroup.ALL); public static final StringFlag FAREWELL_MESSAGE = new StringFlag("farewell", RegionGroup.ALL);
public static final StringFlag MAX_PLAYERS_MESSAGE = new StringFlag("max-players-reject-message", RegionGroup.ALL);
public static final BooleanFlag NOTIFY_ENTER = new BooleanFlag("notify-enter", RegionGroup.ALL); public static final BooleanFlag NOTIFY_ENTER = new BooleanFlag("notify-enter", RegionGroup.ALL);
public static final BooleanFlag NOTIFY_LEAVE = new BooleanFlag("notify-leave", RegionGroup.ALL); public static final BooleanFlag NOTIFY_LEAVE = new BooleanFlag("notify-leave", RegionGroup.ALL);
public static final SetFlag<EntityType> DENY_SPAWN = new SetFlag<EntityType>("deny-spawn", RegionGroup.ALL, new EntityTypeFlag(null)); public static final SetFlag<EntityType> DENY_SPAWN = new SetFlag<EntityType>("deny-spawn", RegionGroup.ALL, new EntityTypeFlag(null));
@ -83,6 +84,7 @@ public final class DefaultFlag {
public static final IntegerFlag FEED_AMOUNT = new IntegerFlag("feed-amount", RegionGroup.ALL); public static final IntegerFlag FEED_AMOUNT = new IntegerFlag("feed-amount", RegionGroup.ALL);
public static final IntegerFlag MIN_FOOD = new IntegerFlag("feed-min-hunger", RegionGroup.ALL); public static final IntegerFlag MIN_FOOD = new IntegerFlag("feed-min-hunger", RegionGroup.ALL);
public static final IntegerFlag MAX_FOOD = new IntegerFlag("feed-max-hunger", RegionGroup.ALL); public static final IntegerFlag MAX_FOOD = new IntegerFlag("feed-max-hunger", RegionGroup.ALL);
public static final IntegerFlag MAX_PLAYERS = new IntegerFlag("max-players-allowed", RegionGroup.ALL);
public static final LocationFlag TELE_LOC = new LocationFlag("teleport", RegionGroup.MEMBERS); public static final LocationFlag TELE_LOC = new LocationFlag("teleport", RegionGroup.MEMBERS);
public static final LocationFlag SPAWN_LOC = new LocationFlag("spawn", RegionGroup.MEMBERS); public static final LocationFlag SPAWN_LOC = new LocationFlag("spawn", RegionGroup.MEMBERS);
public static final BooleanFlag BUYABLE = new BooleanFlag("buyable"); public static final BooleanFlag BUYABLE = new BooleanFlag("buyable");
@ -97,7 +99,7 @@ public final class DefaultFlag {
CREEPER_EXPLOSION, ENDERDRAGON_BLOCK_DAMAGE, GHAST_FIREBALL, ENDER_BUILD, CREEPER_EXPLOSION, ENDERDRAGON_BLOCK_DAMAGE, GHAST_FIREBALL, ENDER_BUILD,
GREET_MESSAGE, FAREWELL_MESSAGE, NOTIFY_ENTER, NOTIFY_LEAVE, GREET_MESSAGE, FAREWELL_MESSAGE, NOTIFY_ENTER, NOTIFY_LEAVE,
EXIT, ENTRY, LIGHTNING, ENTITY_PAINTING_DESTROY, EXIT, ENTRY, LIGHTNING, ENTITY_PAINTING_DESTROY,
ENTITY_ITEM_FRAME_DESTROY, ITEM_DROP, ENTITY_ITEM_FRAME_DESTROY, ITEM_DROP, MAX_PLAYERS, MAX_PLAYERS_MESSAGE,
HEAL_AMOUNT, HEAL_DELAY, MIN_HEAL, MAX_HEAL, HEAL_AMOUNT, HEAL_DELAY, MIN_HEAL, MAX_HEAL,
FEED_DELAY, FEED_AMOUNT, MIN_FOOD, MAX_FOOD, FEED_DELAY, FEED_AMOUNT, MIN_FOOD, MAX_FOOD,
SNOW_FALL, SNOW_MELT, ICE_FORM, ICE_MELT, GAME_MODE, SNOW_FALL, SNOW_MELT, ICE_FORM, ICE_MELT, GAME_MODE,