mirror of
https://github.com/taoneill/war.git
synced 2025-01-23 07:41:21 +01:00
Merge pull request #579 from cmastudios/zone-permissions
Add team-based permission requirement
This commit is contained in:
commit
4317b2fc8c
@ -184,6 +184,7 @@ public class War extends JavaPlugin {
|
||||
teamDefaultConfig.put(TeamConfig.SATURATION, 10);
|
||||
teamDefaultConfig.put(TeamConfig.SPAWNSTYLE, TeamSpawnStyle.SMALL);
|
||||
teamDefaultConfig.put(TeamConfig.TEAMSIZE, 10);
|
||||
teamDefaultConfig.put(TeamConfig.PERMISSION, "war.player");
|
||||
|
||||
this.getDefaultInventories().getLoadouts().clear();
|
||||
HashMap<Integer, ItemStack> defaultLoadout = new HashMap<Integer, ItemStack>();
|
||||
@ -937,15 +938,16 @@ public class War extends JavaPlugin {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks whether the given player is allowed to play war.
|
||||
* Checks whether the given player is allowed to play in a certain team
|
||||
*
|
||||
* @param player Player to check
|
||||
* @return true if the player may play war
|
||||
* @param team Team to check
|
||||
* @return true if the player may play in the team
|
||||
*/
|
||||
public boolean canPlayWar(Player player) {
|
||||
return player.hasPermission("war.player");
|
||||
public boolean canPlayWar(Player player, Team team) {
|
||||
return player.hasPermission(team.getTeamConfig().resolveString(TeamConfig.PERMISSION));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -830,7 +830,9 @@ public class Warzone {
|
||||
Team lowestNoOfPlayers = null;
|
||||
for (Team t : this.teams) {
|
||||
if (lowestNoOfPlayers == null || (lowestNoOfPlayers != null && lowestNoOfPlayers.getPlayers().size() > t.getPlayers().size())) {
|
||||
lowestNoOfPlayers = t;
|
||||
if (War.war.canPlayWar(player, t)) {
|
||||
lowestNoOfPlayers = t;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (lowestNoOfPlayers != null) {
|
||||
|
@ -32,10 +32,6 @@ public class JoinCommand extends AbstractWarCommand {
|
||||
}
|
||||
|
||||
Player player = (Player) this.getSender();
|
||||
if (!War.war.canPlayWar(player)) {
|
||||
this.badMsg("Cannot play war. You need the war.player permission.");
|
||||
return true;
|
||||
}
|
||||
|
||||
Warzone zone;
|
||||
if (this.args.length == 0) {
|
||||
@ -87,6 +83,10 @@ public class JoinCommand extends AbstractWarCommand {
|
||||
boolean foundTeam = false;
|
||||
for (Team team : teams) {
|
||||
if (team.getName().startsWith(name) || team.getKind() == kind) {
|
||||
if (!War.war.canPlayWar(player, team)) {
|
||||
this.badMsg("You don't have permission to join this team.");
|
||||
return true;
|
||||
}
|
||||
if (!zone.hasPlayerState(player.getName())) {
|
||||
zone.keepPlayerState(player);
|
||||
this.msg("Your inventory is in storage until you use '/war leave'.");
|
||||
|
@ -12,7 +12,8 @@ public enum TeamConfig {
|
||||
RESPAWNTIMER (Integer.class),
|
||||
SATURATION (Integer.class),
|
||||
SPAWNSTYLE (TeamSpawnStyle.class),
|
||||
TEAMSIZE (Integer.class);
|
||||
TEAMSIZE (Integer.class),
|
||||
PERMISSION (String.class);
|
||||
|
||||
private final Class<?> configType;
|
||||
|
||||
|
@ -92,6 +92,25 @@ public class TeamConfigBag {
|
||||
}
|
||||
}
|
||||
|
||||
public String getString(TeamConfig config) {
|
||||
if (this.contains(config)) {
|
||||
return (String)this.bag.get(config);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String resolveString(TeamConfig config) {
|
||||
if (this.contains(config)) {
|
||||
return (String)this.bag.get(config);
|
||||
} else if (this.warzone != null && this.warzone.getTeamDefaultConfig().contains(config)){
|
||||
// use Warzone default config
|
||||
return this.warzone.getTeamDefaultConfig().resolveString(config);
|
||||
} else {
|
||||
// use War default config
|
||||
return War.war.getTeamDefaultConfig().resolveString(config);
|
||||
}
|
||||
}
|
||||
|
||||
public FlagReturn resolveFlagReturn() {
|
||||
if (this.contains(TeamConfig.FLAGRETURN)) {
|
||||
return (FlagReturn)this.bag.get(TeamConfig.FLAGRETURN);
|
||||
@ -136,6 +155,8 @@ public class TeamConfigBag {
|
||||
this.put(config, teamConfigSection.getInt(config.toString()));
|
||||
} else if (config.getConfigType().equals(Boolean.class)) {
|
||||
this.put(config, teamConfigSection.getBoolean(config.toString()));
|
||||
} else if (config.getConfigType().equals(String.class)) {
|
||||
this.put(config, teamConfigSection.getString(config.toString()));
|
||||
} else if (config.getConfigType().equals(FlagReturn.class)) {
|
||||
String flagReturnStr = teamConfigSection.getString(config.toString());
|
||||
FlagReturn returnMode = FlagReturn.getFromString(flagReturnStr);
|
||||
@ -177,6 +198,9 @@ public class TeamConfigBag {
|
||||
} else if (teamConfig.getConfigType().equals(Boolean.class)) {
|
||||
String onOff = namedParams.get(namedParam);
|
||||
this.bag.put(teamConfig, onOff.equals("on") || onOff.equals("true"));
|
||||
} else if (teamConfig.getConfigType().equals(String.class)) {
|
||||
String str = namedParams.get(namedParam);
|
||||
this.bag.put(teamConfig, str);
|
||||
} else if (teamConfig.getConfigType().equals(FlagReturn.class)) {
|
||||
FlagReturn flagValue = FlagReturn.getFromString(namedParams.get(namedParam));
|
||||
this.bag.put(teamConfig, flagValue);
|
||||
|
@ -257,7 +257,6 @@ public class WarPlayerListener implements Listener {
|
||||
Warzone locZone = Warzone.getZoneByLocation(playerLoc);
|
||||
ZoneLobby locLobby = ZoneLobby.getLobbyByLocation(playerLoc);
|
||||
|
||||
boolean canPlay = War.war.canPlayWar(player);
|
||||
boolean isMaker = War.war.isZoneMaker(player);
|
||||
|
||||
// Zone walls
|
||||
@ -288,7 +287,7 @@ public class WarPlayerListener implements Listener {
|
||||
Warzone zone = locLobby.getZone();
|
||||
Team oldTeam = Team.getTeamByPlayerName(player.getName());
|
||||
boolean isAutoAssignGate = false;
|
||||
if (oldTeam == null && canPlay) { // trying to counter spammy player move
|
||||
if (oldTeam == null) { // trying to counter spammy player move
|
||||
isAutoAssignGate = zone.getLobby().isAutoAssignGate(playerLoc);
|
||||
if (isAutoAssignGate) {
|
||||
if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.DISABLED)) {
|
||||
@ -303,9 +302,13 @@ public class WarPlayerListener implements Listener {
|
||||
}
|
||||
|
||||
if (noOfPlayers < totalCap) {
|
||||
zone.autoAssign(player);
|
||||
boolean assigned = zone.autoAssign(player) != null ? true : false;
|
||||
if (!assigned) {
|
||||
event.setTo(zone.getTeleport());
|
||||
War.war.badMsg(player, "You don't have permission for any of the available teams in this warzone");
|
||||
}
|
||||
|
||||
if (War.war.getWarHub() != null) {
|
||||
if (War.war.getWarHub() != null && assigned) {
|
||||
War.war.getWarHub().resetZoneSign(zone);
|
||||
}
|
||||
} else {
|
||||
@ -323,7 +326,8 @@ public class WarPlayerListener implements Listener {
|
||||
this.dropFromOldTeamIfAny(player);
|
||||
if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.DISABLED)) {
|
||||
this.handleDisabledZone(event, player, zone);
|
||||
} else if (team.getPlayers().size() < team.getTeamConfig().resolveInt(TeamConfig.TEAMSIZE)) {
|
||||
} else if (team.getPlayers().size() < team.getTeamConfig().resolveInt(TeamConfig.TEAMSIZE)
|
||||
&& War.war.canPlayWar(player, team)) {
|
||||
team.addPlayer(player);
|
||||
team.resetSign();
|
||||
if (War.war.getWarHub() != null) {
|
||||
@ -335,6 +339,9 @@ public class WarPlayerListener implements Listener {
|
||||
for (Team t : zone.getTeams()) {
|
||||
t.teamcast("" + player.getName() + " joined team " + team.getName() + ".");
|
||||
}
|
||||
} else if (!War.war.canPlayWar(player, team)) {
|
||||
event.setTo(zone.getTeleport());
|
||||
War.war.badMsg(player, "You don't have permission to join team " + team.getName());
|
||||
} else {
|
||||
event.setTo(zone.getTeleport());
|
||||
War.war.badMsg(player, "Team " + team.getName() + " is full.");
|
||||
|
Loading…
Reference in New Issue
Block a user