diff --git a/resources/plugin.yml b/resources/plugin.yml index 6d58da1..686fa46 100644 --- a/resources/plugin.yml +++ b/resources/plugin.yml @@ -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: diff --git a/src/com/garbagemule/MobArena/ArenaClass.java b/src/com/garbagemule/MobArena/ArenaClass.java index b0bd644..a32d6b1 100644 --- a/src/com/garbagemule/MobArena/ArenaClass.java +++ b/src/com/garbagemule/MobArena/ArenaClass.java @@ -15,6 +15,7 @@ public class ArenaClass private ItemStack helmet, chestplate, leggings, boots; private List items, armor; private Map perms; + private Map lobbyperms; private boolean unbreakableWeapons; private boolean mount; @@ -29,6 +30,7 @@ public class ArenaClass this.items = new ArrayList(); this.armor = new ArrayList(4); this.perms = new HashMap(); + this.lobbyperms = new HashMap(); this.unbreakableWeapons = unbreakableWeapons; } @@ -205,6 +207,14 @@ public class ArenaClass public Map getPermissions() { return Collections.unmodifiableMap(perms); } + + public void addLobbyPermission(String perm, boolean value) { + lobbyperms.put(perm, value); + } + + public Map getLobbyPermissions() { + return Collections.unmodifiableMap(lobbyperms); + } /** * Grant the given player all the permissions of the class. @@ -218,20 +228,31 @@ public class ArenaClass if (perms.isEmpty()) return null; PermissionAttachment pa = p.addAttachment(plugin); - - for (Entry entry : perms.entrySet()) { + grantPerms(pa, perms, p); + return pa; + } + + 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 map, Player p) { + for (Entry entry : map.entrySet()) { try { pa.setPermission(entry.getKey(), entry.getValue()); } catch (Exception e) { String perm = entry.getKey() + ":" + entry.getValue(); String player = p.getName(); - + Messenger.warning("[PERM00] Failed to attach permission '" + perm + "' to player '" + player + " with class " + this.configName + "'.\nPlease verify that your class permissions are well-formed."); } } - return pa; } public boolean hasUnbreakableWeapons() { diff --git a/src/com/garbagemule/MobArena/ArenaImpl.java b/src/com/garbagemule/MobArena/ArenaImpl.java index e190971..fa473cb 100644 --- a/src/com/garbagemule/MobArena/ArenaImpl.java +++ b/src/com/garbagemule/MobArena/ArenaImpl.java @@ -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,8 +1036,24 @@ 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)) { @@ -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 diff --git a/src/com/garbagemule/MobArena/ArenaMasterImpl.java b/src/com/garbagemule/MobArena/ArenaMasterImpl.java index 159b36a..72e3fb0 100644 --- a/src/com/garbagemule/MobArena/ArenaMasterImpl.java +++ b/src/com/garbagemule/MobArena/ArenaMasterImpl.java @@ -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 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 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) {