mirror of
https://github.com/taoneill/war.git
synced 2025-01-23 15:51:22 +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.SATURATION, 10);
|
||||||
teamDefaultConfig.put(TeamConfig.SPAWNSTYLE, TeamSpawnStyle.SMALL);
|
teamDefaultConfig.put(TeamConfig.SPAWNSTYLE, TeamSpawnStyle.SMALL);
|
||||||
teamDefaultConfig.put(TeamConfig.TEAMSIZE, 10);
|
teamDefaultConfig.put(TeamConfig.TEAMSIZE, 10);
|
||||||
|
teamDefaultConfig.put(TeamConfig.PERMISSION, "war.player");
|
||||||
|
|
||||||
this.getDefaultInventories().getLoadouts().clear();
|
this.getDefaultInventories().getLoadouts().clear();
|
||||||
HashMap<Integer, ItemStack> defaultLoadout = new HashMap<Integer, ItemStack>();
|
HashMap<Integer, ItemStack> defaultLoadout = new HashMap<Integer, ItemStack>();
|
||||||
@ -939,13 +940,14 @@ public class War extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
* @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) {
|
public boolean canPlayWar(Player player, Team team) {
|
||||||
return player.hasPermission("war.player");
|
return player.hasPermission(team.getTeamConfig().resolveString(TeamConfig.PERMISSION));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -830,9 +830,11 @@ public class Warzone {
|
|||||||
Team lowestNoOfPlayers = null;
|
Team lowestNoOfPlayers = null;
|
||||||
for (Team t : this.teams) {
|
for (Team t : this.teams) {
|
||||||
if (lowestNoOfPlayers == null || (lowestNoOfPlayers != null && lowestNoOfPlayers.getPlayers().size() > t.getPlayers().size())) {
|
if (lowestNoOfPlayers == null || (lowestNoOfPlayers != null && lowestNoOfPlayers.getPlayers().size() > t.getPlayers().size())) {
|
||||||
|
if (War.war.canPlayWar(player, t)) {
|
||||||
lowestNoOfPlayers = t;
|
lowestNoOfPlayers = t;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (lowestNoOfPlayers != null) {
|
if (lowestNoOfPlayers != null) {
|
||||||
lowestNoOfPlayers.addPlayer(player);
|
lowestNoOfPlayers.addPlayer(player);
|
||||||
lowestNoOfPlayers.resetSign();
|
lowestNoOfPlayers.resetSign();
|
||||||
|
@ -32,10 +32,6 @@ public class JoinCommand extends AbstractWarCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Player player = (Player) this.getSender();
|
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;
|
Warzone zone;
|
||||||
if (this.args.length == 0) {
|
if (this.args.length == 0) {
|
||||||
@ -87,6 +83,10 @@ public class JoinCommand extends AbstractWarCommand {
|
|||||||
boolean foundTeam = false;
|
boolean foundTeam = false;
|
||||||
for (Team team : teams) {
|
for (Team team : teams) {
|
||||||
if (team.getName().startsWith(name) || team.getKind() == kind) {
|
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())) {
|
if (!zone.hasPlayerState(player.getName())) {
|
||||||
zone.keepPlayerState(player);
|
zone.keepPlayerState(player);
|
||||||
this.msg("Your inventory is in storage until you use '/war leave'.");
|
this.msg("Your inventory is in storage until you use '/war leave'.");
|
||||||
|
@ -12,7 +12,8 @@ public enum TeamConfig {
|
|||||||
RESPAWNTIMER (Integer.class),
|
RESPAWNTIMER (Integer.class),
|
||||||
SATURATION (Integer.class),
|
SATURATION (Integer.class),
|
||||||
SPAWNSTYLE (TeamSpawnStyle.class),
|
SPAWNSTYLE (TeamSpawnStyle.class),
|
||||||
TEAMSIZE (Integer.class);
|
TEAMSIZE (Integer.class),
|
||||||
|
PERMISSION (String.class);
|
||||||
|
|
||||||
private final Class<?> configType;
|
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() {
|
public FlagReturn resolveFlagReturn() {
|
||||||
if (this.contains(TeamConfig.FLAGRETURN)) {
|
if (this.contains(TeamConfig.FLAGRETURN)) {
|
||||||
return (FlagReturn)this.bag.get(TeamConfig.FLAGRETURN);
|
return (FlagReturn)this.bag.get(TeamConfig.FLAGRETURN);
|
||||||
@ -136,6 +155,8 @@ public class TeamConfigBag {
|
|||||||
this.put(config, teamConfigSection.getInt(config.toString()));
|
this.put(config, teamConfigSection.getInt(config.toString()));
|
||||||
} else if (config.getConfigType().equals(Boolean.class)) {
|
} else if (config.getConfigType().equals(Boolean.class)) {
|
||||||
this.put(config, teamConfigSection.getBoolean(config.toString()));
|
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)) {
|
} else if (config.getConfigType().equals(FlagReturn.class)) {
|
||||||
String flagReturnStr = teamConfigSection.getString(config.toString());
|
String flagReturnStr = teamConfigSection.getString(config.toString());
|
||||||
FlagReturn returnMode = FlagReturn.getFromString(flagReturnStr);
|
FlagReturn returnMode = FlagReturn.getFromString(flagReturnStr);
|
||||||
@ -177,6 +198,9 @@ public class TeamConfigBag {
|
|||||||
} else if (teamConfig.getConfigType().equals(Boolean.class)) {
|
} else if (teamConfig.getConfigType().equals(Boolean.class)) {
|
||||||
String onOff = namedParams.get(namedParam);
|
String onOff = namedParams.get(namedParam);
|
||||||
this.bag.put(teamConfig, onOff.equals("on") || onOff.equals("true"));
|
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)) {
|
} else if (teamConfig.getConfigType().equals(FlagReturn.class)) {
|
||||||
FlagReturn flagValue = FlagReturn.getFromString(namedParams.get(namedParam));
|
FlagReturn flagValue = FlagReturn.getFromString(namedParams.get(namedParam));
|
||||||
this.bag.put(teamConfig, flagValue);
|
this.bag.put(teamConfig, flagValue);
|
||||||
|
@ -257,7 +257,6 @@ public class WarPlayerListener implements Listener {
|
|||||||
Warzone locZone = Warzone.getZoneByLocation(playerLoc);
|
Warzone locZone = Warzone.getZoneByLocation(playerLoc);
|
||||||
ZoneLobby locLobby = ZoneLobby.getLobbyByLocation(playerLoc);
|
ZoneLobby locLobby = ZoneLobby.getLobbyByLocation(playerLoc);
|
||||||
|
|
||||||
boolean canPlay = War.war.canPlayWar(player);
|
|
||||||
boolean isMaker = War.war.isZoneMaker(player);
|
boolean isMaker = War.war.isZoneMaker(player);
|
||||||
|
|
||||||
// Zone walls
|
// Zone walls
|
||||||
@ -288,7 +287,7 @@ public class WarPlayerListener implements Listener {
|
|||||||
Warzone zone = locLobby.getZone();
|
Warzone zone = locLobby.getZone();
|
||||||
Team oldTeam = Team.getTeamByPlayerName(player.getName());
|
Team oldTeam = Team.getTeamByPlayerName(player.getName());
|
||||||
boolean isAutoAssignGate = false;
|
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);
|
isAutoAssignGate = zone.getLobby().isAutoAssignGate(playerLoc);
|
||||||
if (isAutoAssignGate) {
|
if (isAutoAssignGate) {
|
||||||
if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.DISABLED)) {
|
if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.DISABLED)) {
|
||||||
@ -303,9 +302,13 @@ public class WarPlayerListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (noOfPlayers < totalCap) {
|
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);
|
War.war.getWarHub().resetZoneSign(zone);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -323,7 +326,8 @@ public class WarPlayerListener implements Listener {
|
|||||||
this.dropFromOldTeamIfAny(player);
|
this.dropFromOldTeamIfAny(player);
|
||||||
if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.DISABLED)) {
|
if (zone.getWarzoneConfig().getBoolean(WarzoneConfig.DISABLED)) {
|
||||||
this.handleDisabledZone(event, player, zone);
|
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.addPlayer(player);
|
||||||
team.resetSign();
|
team.resetSign();
|
||||||
if (War.war.getWarHub() != null) {
|
if (War.war.getWarHub() != null) {
|
||||||
@ -335,6 +339,9 @@ public class WarPlayerListener implements Listener {
|
|||||||
for (Team t : zone.getTeams()) {
|
for (Team t : zone.getTeams()) {
|
||||||
t.teamcast("" + player.getName() + " joined team " + team.getName() + ".");
|
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 {
|
} else {
|
||||||
event.setTo(zone.getTeleport());
|
event.setTo(zone.getTeleport());
|
||||||
War.war.badMsg(player, "Team " + team.getName() + " is full.");
|
War.war.badMsg(player, "Team " + team.getName() + " is full.");
|
||||||
|
Loading…
Reference in New Issue
Block a user