Closes gh-617, gh-609, gh-514, gh-319, tag gh-589. Add support for

permission specific loadouts.

Loadouts can be defined with a permission which can limit who can access
the loadout, in mostly the same manner as I did in the zone-permissions
commits. The permission can be used to only allow say VIP and above to get
a certain loadout (for donation benefits) or to allow the server's lower
ranks a class only (to allow lower ranks to survive faced with the server's
experienced players).

This is controlled by an additional argument to /zonecfg.
Example: /zonecfg loadout:vip:server.ranks.VIP - allow only VIP players
access to the vip loadout.
To remove the permission, re-make the loadout without the permission
parameter.
Example: /zonecfg loadout:vip - remove the permission requirement for the
vip loadout.

To allow a lower rank access to a loadout only, you can use your permission
manager's feature of negating a permission (if supported by the plugin).
Example: /pex group recruit add server.loadout.noob, /pex group builder add
-server.loadout.noob - allow only recruits to have access to a loadout
which requires the permission "server.loadout.noob" (with PermissionsEX).
This commit is contained in:
cmastudios 2013-03-22 22:33:38 -05:00
parent e6c1e64fef
commit d724f5a382
4 changed files with 92 additions and 20 deletions

View File

@ -378,11 +378,15 @@ public class War extends JavaPlugin {
public String updateTeamFromNamedParams(Team team, CommandSender commandSender, String[] arguments) {
try {
Map<String, String> namedParams = new HashMap<String, String>();
Map<String, String> namedParams = new HashMap();
Map<String, String> thirdParameter = new HashMap();
for (String namedPair : arguments) {
String[] pairSplit = namedPair.split(":");
if (pairSplit.length == 2) {
namedParams.put(pairSplit[0].toLowerCase(), pairSplit[1]);
} else if (pairSplit.length == 3) {
namedParams.put(pairSplit[0].toLowerCase(), pairSplit[1]);
thirdParameter.put(pairSplit[0].toLowerCase(), pairSplit[2]);
}
}
@ -415,6 +419,15 @@ public class War extends JavaPlugin {
returnMessage.append(loadoutName + " respawn loadout updated.");
}
this.inventoryToLoadout(player, loadout);
Loadout ldt = team.getInventories().getNewLoadout(loadoutName);
if (thirdParameter.containsKey("loadout")) {
String permission = thirdParameter.get("loadout");
ldt.setPermission(permission);
returnMessage.append(' ').append(loadoutName).append(" respawn loadout permission set to ").append(permission).append('.');
} else if (ldt.requiresPermission()) {
ldt.setPermission(null);
returnMessage.append(' ').append(loadoutName).append(" respawn loadout permission deleted.");
}
}
if (namedParams.containsKey("deleteloadout")) {
String loadoutName = namedParams.get("deleteloadout");
@ -441,11 +454,15 @@ public class War extends JavaPlugin {
public String updateZoneFromNamedParams(Warzone warzone, CommandSender commandSender, String[] arguments) {
try {
Map<String, String> namedParams = new HashMap<String, String>();
Map<String, String> namedParams = new HashMap();
Map<String, String> thirdParameter = new HashMap();
for (String namedPair : arguments) {
String[] pairSplit = namedPair.split(":");
if (pairSplit.length == 2) {
namedParams.put(pairSplit[0].toLowerCase(), pairSplit[1]);
} else if (pairSplit.length == 3) {
namedParams.put(pairSplit[0].toLowerCase(), pairSplit[1]);
thirdParameter.put(pairSplit[0].toLowerCase(), pairSplit[2]);
}
}
@ -496,6 +513,15 @@ public class War extends JavaPlugin {
returnMessage.append(loadoutName + " respawn loadout updated.");
}
this.inventoryToLoadout(player, loadout);
Loadout ldt = warzone.getDefaultInventories().getNewLoadout(loadoutName);
if (thirdParameter.containsKey("loadout")) {
String permission = thirdParameter.get("loadout");
ldt.setPermission(permission);
returnMessage.append(' ').append(loadoutName).append(" respawn loadout permission set to ").append(permission).append('.');
} else if (ldt.requiresPermission()) {
ldt.setPermission(null);
returnMessage.append(' ').append(loadoutName).append(" respawn loadout permission deleted.");
}
}
if (namedParams.containsKey("deleteloadout")) {
String loadoutName = namedParams.get("deleteloadout");
@ -620,11 +646,15 @@ public class War extends JavaPlugin {
public String updateFromNamedParams(CommandSender commandSender, String[] arguments) {
try {
Map<String, String> namedParams = new HashMap<String, String>();
Map<String, String> namedParams = new HashMap();
Map<String, String> thirdParameter = new HashMap();
for (String namedPair : arguments) {
String[] pairSplit = namedPair.split(":");
if (pairSplit.length == 2) {
namedParams.put(pairSplit[0].toLowerCase(), pairSplit[1]);
} else if (pairSplit.length == 3) {
namedParams.put(pairSplit[0].toLowerCase(), pairSplit[1]);
thirdParameter.put(pairSplit[0].toLowerCase(), pairSplit[2]);
}
}
@ -647,6 +677,15 @@ public class War extends JavaPlugin {
returnMessage.append(loadoutName + " respawn loadout updated.");
}
this.inventoryToLoadout(player, loadout);
Loadout ldt = this.getDefaultInventories().getNewLoadout(loadoutName);
if (thirdParameter.containsKey("loadout")) {
String permission = thirdParameter.get("loadout");
ldt.setPermission(permission);
returnMessage.append(' ').append(loadoutName).append(" respawn loadout permission set to ").append(permission).append('.');
} else if (ldt.requiresPermission()) {
ldt.setPermission(null);
returnMessage.append(' ').append(loadoutName).append(" respawn loadout permission deleted.");
}
}
if (namedParams.containsKey("deleteloadout")) {
String loadoutName = namedParams.get("deleteloadout");
@ -743,23 +782,27 @@ public class War extends JavaPlugin {
}
private String getLoadoutsString(InventoryBag invs) {
String loadoutsString = "";
StringBuilder loadoutsString = new StringBuilder();
ChatColor loadoutColor = ChatColor.GREEN;
ChatColor normalColor = ChatColor.WHITE;
if (invs.hasLoadouts()) {
String loadouts = "";
for (String loadoutName : invs.getLoadouts().keySet()) {
loadouts += loadoutName + ",";
StringBuilder loadouts = new StringBuilder();
for (Loadout ldt : invs.getNewLoadouts()) {
if (ldt.requiresPermission()) {
loadouts.append(ldt.getName()).append(":").append(ldt.getPermission()).append(",");
} else {
loadouts.append(ldt.getName()).append(",");
}
}
loadoutsString += " loadout:" + loadoutColor + loadouts + normalColor;
loadoutsString.append(" loadout:").append(loadoutColor).append(loadouts.toString()).append(normalColor);
}
if (invs.hasReward()) {
loadoutsString += " reward:" + loadoutColor + "default" + normalColor;
loadoutsString.append(" reward:").append(loadoutColor).append("default").append(normalColor);
}
return loadoutsString;
return loadoutsString.toString();
}
public String printConfig(Warzone zone) {

View File

@ -1,5 +1,6 @@
package com.tommytony.war;
import com.google.common.collect.ImmutableList;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
@ -41,6 +42,7 @@ import com.tommytony.war.structure.WarzoneMaterials;
import com.tommytony.war.structure.ZoneLobby;
import com.tommytony.war.structure.ZoneWallGuard;
import com.tommytony.war.utility.Direction;
import com.tommytony.war.utility.Loadout;
import com.tommytony.war.utility.LoadoutSelection;
import com.tommytony.war.utility.PlayerState;
import com.tommytony.war.utility.PotionEffectHelper;
@ -1329,13 +1331,24 @@ public class Warzone {
if (selection != null && !this.isRespawning(player) && playerTeam.getPlayers().contains(player)) {
// Make sure that inventory resets dont occur if player has already tp'ed out (due to game end, or somesuch)
// - repawn timer + this method is why inventories were getting wiped as players exited the warzone.
HashMap<String, HashMap<Integer, ItemStack>> loadouts = playerTeam.getInventories().resolveLoadouts();
List<String> sortedNames = LoadoutYmlMapper.sortNames(loadouts);
if (sortedNames.contains("first")) {
sortedNames.remove("first");
List<Loadout> loadouts = playerTeam.getInventories().resolveNewLoadouts();
List<String> sortedNames = LoadoutYmlMapper.sortNames(Loadout.toLegacyFormat(loadouts));
sortedNames.remove("first");
for (Iterator<String> it = sortedNames.iterator(); it.hasNext();) {
String loadoutName = it.next();
Loadout ldt = Loadout.getLoadout(loadouts, loadoutName);
if (ldt.requiresPermission() && !player.hasPermission(ldt.getPermission())) {
it.remove();
}
}
if (sortedNames.isEmpty()) {
// Fix for zones that mistakenly only specify a `first' loadout, but do not add any others.
this.handlePlayerLeave(player, this.getTeleport(), true);
War.war.badMsg(player, "We couldn't find a loadout for you! Please alert the warzone maker to add a `default' loadout to this warzone.");
return;
}
int currentIndex = selection.getSelectedIndex();
Loadout firstLoadout = Loadout.getLoadout(loadouts, "first");
int i = 0;
Iterator<String> it = sortedNames.iterator();
while (it.hasNext()) {
@ -1344,12 +1357,13 @@ public class Warzone {
if (playerTeam.getTeamConfig().resolveBoolean(TeamConfig.PLAYERLOADOUTASDEFAULT) && name.equals("default")) {
// Use player's own inventory as loadout
this.resetInventory(playerTeam, player, this.getPlayerInventoryFromSavedState(player));
} else if (isFirstRespawn && loadouts.containsKey("first") && name.equals("default")) {
} else if (isFirstRespawn && firstLoadout != null && name.equals("default")
&& (firstLoadout.requiresPermission() ? player.hasPermission(firstLoadout.getPermission()) : true)) {
// Get the loadout for the first spawn
this.resetInventory(playerTeam, player, loadouts.get("first"));
this.resetInventory(playerTeam, player, Loadout.getLoadout(loadouts, "first").getContents());
} else {
// Use the loadout from the list in the settings
this.resetInventory(playerTeam, player, loadouts.get(name));
this.resetInventory(playerTeam, player, Loadout.getLoadout(loadouts, name).getContents());
}
if (isFirstRespawn && playerTeam.getInventories().resolveLoadouts().keySet().size() > 1) {
War.war.msg(player, "Equipped " + name + " loadout (sneak to switch).");

View File

@ -41,7 +41,10 @@ import com.tommytony.war.structure.Cake;
import com.tommytony.war.structure.WarHub;
import com.tommytony.war.structure.ZoneLobby;
import com.tommytony.war.utility.Direction;
import com.tommytony.war.utility.Loadout;
import com.tommytony.war.utility.LoadoutSelection;
import java.util.ArrayList;
import java.util.Iterator;
/**
* @author tommytony, Tim Düsterhus
@ -820,8 +823,19 @@ public class WarPlayerListener implements Listener {
if (playerWarzone.getLoadoutSelections().keySet().contains(event.getPlayer().getName())
&& playerWarzone.getLoadoutSelections().get(event.getPlayer().getName()).isStillInSpawn()) {
LoadoutSelection selection = playerWarzone.getLoadoutSelections().get(event.getPlayer().getName());
boolean hasFirstLoadout = playerTeam.getInventories().resolveLoadouts().containsKey("first");
int currentIndex = (selection.getSelectedIndex() + 1) % (playerTeam.getInventories().resolveLoadouts().keySet().size() - (hasFirstLoadout ? 1 : 0));
List<Loadout> loadouts = (List<Loadout>)new ArrayList(playerTeam.getInventories().resolveNewLoadouts()).clone();
for (Iterator<Loadout> it = loadouts.iterator(); it.hasNext();) {
Loadout ldt = it.next();
if ("first".equals(ldt.getName())) {
it.remove();
continue;
}
if (ldt.requiresPermission() && !event.getPlayer().hasPermission(ldt.getPermission())) {
it.remove();
continue;
}
}
int currentIndex = (selection.getSelectedIndex() + 1) % loadouts.size();
selection.setSelectedIndex(currentIndex);
playerWarzone.equipPlayerLoadoutSelection(event.getPlayer(), playerTeam, false, true);

View File

@ -197,6 +197,7 @@ commands:
/zonecfg teamsize:10 flagmustbehome:on flagpointsonly:off flagreturn:<both/flag/spawn> nohunger:off respawntimer:0 saturation:10 spawnstyle:<small/flat/big/invisible> \\
/zonecfg loadout:default -> sets the default respawn inventory to your current items. \\
/zonecfg loadout:<extra-loadout-name> -> adds an extra loadout (i.e. another player class) that the players can toggle to by sneaking while inside the spawn. \\
/zonecfg loadout:<extra-loadout-name>:<permission> -> add/update a loadout that requires a permission. \\
/zonecfg deleteloadout:<extra-loadout-name> -> removes the specified loadout from the choices. \\
/zonecfg playerloadoutasdefault:true -> the player can bring a copy of his outside-world inventory to fight, it replaces the default loadout. \\
/zonecfg reward:default -> sets the winner's reward to your current items.