mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-22 10:36:06 +01:00
Merge pull request #931 from ammaraskar/limit
Add player limit per world. Closes #727.
This commit is contained in:
commit
9691a0f978
@ -76,6 +76,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld {
|
||||
PROPERTY_ALIASES.put("mode", "gameMode");
|
||||
PROPERTY_ALIASES.put("diff", "difficulty");
|
||||
PROPERTY_ALIASES.put("spawnlocation", "spawn");
|
||||
PROPERTY_ALIASES.put("limit", "playerLimit");
|
||||
PROPERTY_ALIASES.put("animals", "spawning.animals.spawn");
|
||||
PROPERTY_ALIASES.put("monsters", "spawning.monsters.spawn");
|
||||
PROPERTY_ALIASES.put("animalsrate", "spawning.animals.spawnrate");
|
||||
@ -473,12 +474,15 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld {
|
||||
private volatile long seed;
|
||||
@Property
|
||||
private volatile String generator;
|
||||
@Property
|
||||
private volatile int playerLimit;
|
||||
// End of properties
|
||||
// --------------------------------------------------------------
|
||||
|
||||
private Permission permission;
|
||||
private Permission exempt;
|
||||
private Permission ignoreperm;
|
||||
private Permission limitbypassperm;
|
||||
|
||||
public MVWorld(boolean fixSpawn) {
|
||||
super();
|
||||
@ -584,15 +588,21 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld {
|
||||
|
||||
this.exempt = new Permission("multiverse.exempt." + this.getName(),
|
||||
"A player who has this does not pay to enter this world, or use any MV portals in it " + this.getName(), PermissionDefault.OP);
|
||||
|
||||
this.limitbypassperm = new Permission("mv.bypass.playerlimit." + this.getName(),
|
||||
"A player who can enter this world regardless of wether its full", PermissionDefault.OP);
|
||||
try {
|
||||
this.plugin.getServer().getPluginManager().addPermission(this.permission);
|
||||
this.plugin.getServer().getPluginManager().addPermission(this.exempt);
|
||||
this.plugin.getServer().getPluginManager().addPermission(this.ignoreperm);
|
||||
this.plugin.getServer().getPluginManager().addPermission(this.limitbypassperm);
|
||||
// Add the permission and exempt to parents.
|
||||
this.addToUpperLists(this.permission);
|
||||
|
||||
// Add ignore to it's parent:
|
||||
this.ignoreperm.addParent("mv.bypass.gamemode.*", true);
|
||||
// Add limit bypass to it's parent
|
||||
this.limitbypassperm.addParent("mv.bypass.playerlimit.*", true);
|
||||
} catch (IllegalArgumentException e) {
|
||||
this.plugin.log(Level.FINER, "Permissions nodes were already added for " + this.name);
|
||||
}
|
||||
@ -664,6 +674,7 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld {
|
||||
this.bedRespawn = true;
|
||||
this.worldBlacklist = new ArrayList<String>();
|
||||
this.generator = null;
|
||||
this.playerLimit = -1;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -922,6 +933,22 @@ public class MVWorld extends SerializationConfig implements MultiverseWorld {
|
||||
public void setGenerator(String generator) {
|
||||
this.setPropertyValueUnchecked("generator", generator);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public int getPlayerLimit() {
|
||||
return this.playerLimit;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void setPlayerLimit(int limit) {
|
||||
this.setPropertyValueUnchecked("playerLimit", limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
|
@ -620,6 +620,22 @@ public interface MultiverseWorld {
|
||||
* @param autoLoad True if players dying in this world respawn at their bed.
|
||||
*/
|
||||
void setBedRespawn(boolean autoLoad);
|
||||
|
||||
/**
|
||||
* Sets the player limit for this world after which players without an override
|
||||
* permission node will not be allowed in. A value of -1 or less signifies no limit
|
||||
*
|
||||
* @param limit The new limit
|
||||
*/
|
||||
void setPlayerLimit(int limit);
|
||||
|
||||
/**
|
||||
* Gets the player limit for this world after which players without an override
|
||||
* permission node will not be allowed in. A value of -1 or less signifies no limit
|
||||
*
|
||||
* @return The player limit
|
||||
*/
|
||||
int getPlayerLimit();
|
||||
|
||||
/**
|
||||
* Same as {@link #getTime()}, but returns a string.
|
||||
|
@ -193,6 +193,8 @@ public class MVPlayerListener implements Listener {
|
||||
+ "' don't have the FUNDS required to enter it.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if player is allowed to enter the world if we're enforcing permissions
|
||||
if (plugin.getMVConfig().getEnforceAccess()) {
|
||||
event.setCancelled(!pt.playerCanGoFromTo(fromWorld, toWorld, teleporter, teleportee));
|
||||
if (event.isCancelled() && teleporter != null) {
|
||||
@ -200,13 +202,31 @@ public class MVPlayerListener implements Listener {
|
||||
+ "' was DENIED ACCESS to '" + toWorld.getAlias()
|
||||
+ "' because '" + teleporter.getName()
|
||||
+ "' don't have: multiverse.access." + event.getTo().getWorld().getName());
|
||||
} else {
|
||||
this.stateSuccess(teleportee.getName(), toWorld.getAlias());
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
this.plugin.log(Level.FINE, "Player '" + teleportee.getName()
|
||||
+ "' was allowed to go to '" + toWorld.getAlias() + "' because enforceaccess is off.");
|
||||
}
|
||||
|
||||
// Does a limit actually exist?
|
||||
if (toWorld.getPlayerLimit() > -1) {
|
||||
// Are there equal or more people on the world than the limit?
|
||||
if (toWorld.getCBWorld().getPlayers().size() >= toWorld.getPlayerLimit()) {
|
||||
// Ouch the world is full, lets see if the player can bypass that limitation
|
||||
if (!pt.playerCanBypassPlayerLimit(toWorld, teleporter, teleportee)) {
|
||||
this.plugin.log(Level.FINE, "Player '" + teleportee.getName()
|
||||
+ "' was DENIED ACCESS to '" + toWorld.getAlias()
|
||||
+ "' because the world is full and '" + teleporter.getName()
|
||||
+ "' doesn't have: mv.bypass.playerlimit." + event.getTo().getWorld().getName());
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// By this point anything cancelling the event has returned on the method, meaning the teleport is a success \o/
|
||||
this.stateSuccess(teleportee.getName(), toWorld.getAlias());
|
||||
}
|
||||
|
||||
private void stateSuccess(String playerName, String worldName) {
|
||||
|
@ -257,6 +257,25 @@ public class PermissionTools {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean playerCanBypassPlayerLimit(MultiverseWorld toWorld, CommandSender teleporter, Player teleportee) {
|
||||
|
||||
if (teleporter == null) {
|
||||
teleporter = teleportee;
|
||||
}
|
||||
|
||||
if (!(teleporter instanceof Player)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
MVPermissions perms = plugin.getMVPerms();
|
||||
if (perms.hasPermission(teleportee, "mv.bypass.playerlimit." + toWorld.getName(), false)) {
|
||||
return true;
|
||||
} else {
|
||||
teleporter.sendMessage("The world " + toWorld.getColoredWorldString() + " is full");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if a player should bypass game mode restrictions.
|
||||
|
Loading…
Reference in New Issue
Block a user