Add per-class lobby-permissions node.
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
name: MobArena
|
name: MobArena
|
||||||
author: garbagemule
|
author: garbagemule
|
||||||
main: com.garbagemule.MobArena.MobArena
|
main: com.garbagemule.MobArena.MobArena
|
||||||
version: 0.95.5.8
|
version: 0.95.5.9
|
||||||
softdepend: [Spout,Towny,Heroes,MagicSpells,Vault]
|
softdepend: [Spout,Towny,Heroes,MagicSpells,Vault]
|
||||||
commands:
|
commands:
|
||||||
ma:
|
ma:
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ public class ArenaClass
|
|||||||
private ItemStack helmet, chestplate, leggings, boots;
|
private ItemStack helmet, chestplate, leggings, boots;
|
||||||
private List<ItemStack> items, armor;
|
private List<ItemStack> items, armor;
|
||||||
private Map<String,Boolean> perms;
|
private Map<String,Boolean> perms;
|
||||||
|
private Map<String,Boolean> lobbyperms;
|
||||||
private boolean unbreakableWeapons;
|
private boolean unbreakableWeapons;
|
||||||
private boolean mount;
|
private boolean mount;
|
||||||
|
|
||||||
@@ -29,6 +30,7 @@ public class ArenaClass
|
|||||||
this.items = new ArrayList<ItemStack>();
|
this.items = new ArrayList<ItemStack>();
|
||||||
this.armor = new ArrayList<ItemStack>(4);
|
this.armor = new ArrayList<ItemStack>(4);
|
||||||
this.perms = new HashMap<String,Boolean>();
|
this.perms = new HashMap<String,Boolean>();
|
||||||
|
this.lobbyperms = new HashMap<String,Boolean>();
|
||||||
|
|
||||||
this.unbreakableWeapons = unbreakableWeapons;
|
this.unbreakableWeapons = unbreakableWeapons;
|
||||||
}
|
}
|
||||||
@@ -205,6 +207,14 @@ public class ArenaClass
|
|||||||
public Map<String,Boolean> getPermissions() {
|
public Map<String,Boolean> getPermissions() {
|
||||||
return Collections.unmodifiableMap(perms);
|
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.
|
* Grant the given player all the permissions of the class.
|
||||||
@@ -218,20 +228,31 @@ public class ArenaClass
|
|||||||
if (perms.isEmpty()) return null;
|
if (perms.isEmpty()) return null;
|
||||||
|
|
||||||
PermissionAttachment pa = p.addAttachment(plugin);
|
PermissionAttachment pa = p.addAttachment(plugin);
|
||||||
|
grantPerms(pa, perms, p);
|
||||||
for (Entry<String,Boolean> entry : perms.entrySet()) {
|
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<String,Boolean> map, Player p) {
|
||||||
|
for (Entry<String,Boolean> entry : map.entrySet()) {
|
||||||
try {
|
try {
|
||||||
pa.setPermission(entry.getKey(), entry.getValue());
|
pa.setPermission(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
String perm = entry.getKey() + ":" + entry.getValue();
|
String perm = entry.getKey() + ":" + entry.getValue();
|
||||||
String player = p.getName();
|
String player = p.getName();
|
||||||
|
|
||||||
Messenger.warning("[PERM00] Failed to attach permission '" + perm + "' to player '" + player + " with class " + this.configName
|
Messenger.warning("[PERM00] Failed to attach permission '" + perm + "' to player '" + player + " with class " + this.configName
|
||||||
+ "'.\nPlease verify that your class permissions are well-formed.");
|
+ "'.\nPlease verify that your class permissions are well-formed.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return pa;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasUnbreakableWeapons() {
|
public boolean hasUnbreakableWeapons() {
|
||||||
|
|||||||
@@ -985,6 +985,10 @@ public class ArenaImpl implements Arena
|
|||||||
|
|
||||||
arenaPlayer.setArenaClass(arenaClass);
|
arenaPlayer.setArenaClass(arenaClass);
|
||||||
arenaClass.grantItems(p);
|
arenaClass.grantItems(p);
|
||||||
|
|
||||||
|
PermissionAttachment pa = arenaClass.grantLobbyPermissions(plugin, p);
|
||||||
|
replacePermissions(p, pa);
|
||||||
|
|
||||||
autoReady(p);
|
autoReady(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1032,8 +1036,24 @@ public class ArenaImpl implements Arena
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
p.getInventory().setContents(contents);
|
p.getInventory().setContents(contents);
|
||||||
|
|
||||||
|
PermissionAttachment pa = arenaClass.grantLobbyPermissions(plugin, p);
|
||||||
|
replacePermissions(p, pa);
|
||||||
|
|
||||||
autoReady(p);
|
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) {
|
private void autoReady(Player p) {
|
||||||
if (settings.getBoolean("auto-ready", false)) {
|
if (settings.getBoolean("auto-ready", false)) {
|
||||||
@@ -1076,10 +1096,7 @@ public class ArenaImpl implements Arena
|
|||||||
public void assignClassPermissions(Player p)
|
public void assignClassPermissions(Player p)
|
||||||
{
|
{
|
||||||
PermissionAttachment pa = arenaPlayerMap.get(p).getArenaClass().grantPermissions(plugin, p);
|
PermissionAttachment pa = arenaPlayerMap.get(p).getArenaClass().grantPermissions(plugin, p);
|
||||||
if (pa == null) return;
|
replacePermissions(p, pa);
|
||||||
|
|
||||||
attachments.put(p, pa);
|
|
||||||
p.recalculatePermissions();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -352,6 +352,7 @@ public class ArenaMasterImpl implements ArenaMaster
|
|||||||
|
|
||||||
// Per-class permissions
|
// Per-class permissions
|
||||||
loadClassPermissions(arenaClass, section);
|
loadClassPermissions(arenaClass, section);
|
||||||
|
loadClassLobbyPermissions(arenaClass, section);
|
||||||
|
|
||||||
// Register the permission.
|
// Register the permission.
|
||||||
registerPermission("mobarena.classes." + lowercase, PermissionDefault.TRUE).addParent("mobarena.classes", true);
|
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) {
|
private void loadClassPermissions(ArenaClass arenaClass, ConfigSection section) {
|
||||||
List<String> perms = section.getStringList("permissions", null);
|
List<String> perms = section.getStringList("permissions", null);
|
||||||
if (perms.isEmpty())
|
if (perms.isEmpty()) return;
|
||||||
return;
|
|
||||||
|
|
||||||
for (String perm : perms) {
|
for (String perm : perms) {
|
||||||
// If the permission starts with - or ^, it must be revoked.
|
// 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) {
|
public ArenaClass createClassNode(String classname, PlayerInventory inv, boolean safe) {
|
||||||
String path = "classes." + classname;
|
String path = "classes." + classname;
|
||||||
if (safe && config.getConfigSection(path) != null) {
|
if (safe && config.getConfigSection(path) != null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user