Add per-class lobby-permissions node.

This commit is contained in:
garbagemule 2013-08-03 01:13:18 +02:00
parent dbe5f4d20f
commit e6a0f30993
4 changed files with 64 additions and 11 deletions

View File

@ -1,7 +1,7 @@
name: MobArena
author: garbagemule
main: com.garbagemule.MobArena.MobArena
version: 0.95.5.8
version: 0.95.5.9
softdepend: [Spout,Towny,Heroes,MagicSpells,Vault]
commands:
ma:

View File

@ -15,6 +15,7 @@ public class ArenaClass
private ItemStack helmet, chestplate, leggings, boots;
private List<ItemStack> items, armor;
private Map<String,Boolean> perms;
private Map<String,Boolean> lobbyperms;
private boolean unbreakableWeapons;
private boolean mount;
@ -29,6 +30,7 @@ public class ArenaClass
this.items = new ArrayList<ItemStack>();
this.armor = new ArrayList<ItemStack>(4);
this.perms = new HashMap<String,Boolean>();
this.lobbyperms = new HashMap<String,Boolean>();
this.unbreakableWeapons = unbreakableWeapons;
}
@ -206,6 +208,14 @@ public class ArenaClass
return Collections.unmodifiableMap(perms);
}
public void addLobbyPermission(String perm, boolean value) {
lobbyperms.put(perm, value);
}
public Map<String,Boolean> getLobbyPermissions() {
return Collections.unmodifiableMap(lobbyperms);
}
/**
* Grant the given player all the permissions of the class.
* All permissions will be attached to a PermissionAttachment object, which
@ -218,8 +228,20 @@ public class ArenaClass
if (perms.isEmpty()) return null;
PermissionAttachment pa = p.addAttachment(plugin);
grantPerms(pa, perms, p);
return pa;
}
for (Entry<String,Boolean> entry : perms.entrySet()) {
public PermissionAttachment grantLobbyPermissions(MobArena plugin, Player p) {
if (lobbyperms.isEmpty()) return null;
PermissionAttachment pa = p.addAttachment(plugin);
grantPerms(pa, lobbyperms, p);
return pa;
}
private void grantPerms(PermissionAttachment pa, Map<String,Boolean> map, Player p) {
for (Entry<String,Boolean> entry : map.entrySet()) {
try {
pa.setPermission(entry.getKey(), entry.getValue());
}
@ -231,7 +253,6 @@ public class ArenaClass
+ "'.\nPlease verify that your class permissions are well-formed.");
}
}
return pa;
}
public boolean hasUnbreakableWeapons() {

View File

@ -985,6 +985,10 @@ public class ArenaImpl implements Arena
arenaPlayer.setArenaClass(arenaClass);
arenaClass.grantItems(p);
PermissionAttachment pa = arenaClass.grantLobbyPermissions(plugin, p);
replacePermissions(p, pa);
autoReady(p);
}
@ -1032,9 +1036,25 @@ public class ArenaImpl implements Arena
}
}
p.getInventory().setContents(contents);
PermissionAttachment pa = arenaClass.grantLobbyPermissions(plugin, p);
replacePermissions(p, pa);
autoReady(p);
}
private void replacePermissions(Player p, PermissionAttachment rep) {
PermissionAttachment old = attachments.get(p);
if (old != null) {
p.removeAttachment(old);
p.recalculatePermissions();
}
if (rep != null) {
attachments.put(p, rep);
p.recalculatePermissions();
}
}
private void autoReady(Player p) {
if (settings.getBoolean("auto-ready", false)) {
if (autoStartTimer.getRemaining() <= 0) {
@ -1076,10 +1096,7 @@ public class ArenaImpl implements Arena
public void assignClassPermissions(Player p)
{
PermissionAttachment pa = arenaPlayerMap.get(p).getArenaClass().grantPermissions(plugin, p);
if (pa == null) return;
attachments.put(p, pa);
p.recalculatePermissions();
replacePermissions(p, pa);
}
@Override

View File

@ -352,6 +352,7 @@ public class ArenaMasterImpl implements ArenaMaster
// Per-class permissions
loadClassPermissions(arenaClass, section);
loadClassLobbyPermissions(arenaClass, section);
// Register the permission.
registerPermission("mobarena.classes." + lowercase, PermissionDefault.TRUE).addParent("mobarena.classes", true);
@ -363,8 +364,7 @@ public class ArenaMasterImpl implements ArenaMaster
private void loadClassPermissions(ArenaClass arenaClass, ConfigSection section) {
List<String> perms = section.getStringList("permissions", null);
if (perms.isEmpty())
return;
if (perms.isEmpty()) return;
for (String perm : perms) {
// If the permission starts with - or ^, it must be revoked.
@ -377,6 +377,21 @@ public class ArenaMasterImpl implements ArenaMaster
}
}
private void loadClassLobbyPermissions(ArenaClass arenaClass, ConfigSection section) {
List<String> perms = section.getStringList("lobby-permissions", null);
if (perms.isEmpty()) return;
for (String perm : perms) {
// If the permission starts with - or ^, it must be revoked.
boolean value = true;
if (perm.startsWith("-") || perm.startsWith("^")) {
perm = perm.substring(1).trim();
value = false;
}
arenaClass.addLobbyPermission(perm, value);
}
}
public ArenaClass createClassNode(String classname, PlayerInventory inv, boolean safe) {
String path = "classes." + classname;
if (safe && config.getConfigSection(path) != null) {