Added support for per-class permissions
This commit is contained in:
Binary file not shown.
@@ -40,6 +40,7 @@ import org.bukkit.entity.Slime;
|
|||||||
import org.bukkit.entity.Wolf;
|
import org.bukkit.entity.Wolf;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.PlayerInventory;
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
|
import org.bukkit.permissions.PermissionAttachment;
|
||||||
import org.bukkit.util.config.Configuration;
|
import org.bukkit.util.config.Configuration;
|
||||||
|
|
||||||
import com.garbagemule.MobArena.MAMessages.Msg;
|
import com.garbagemule.MobArena.MAMessages.Msg;
|
||||||
@@ -72,6 +73,8 @@ public class Arena
|
|||||||
protected Map<Integer,List<ItemStack>> everyWaveMap, afterWaveMap;
|
protected Map<Integer,List<ItemStack>> everyWaveMap, afterWaveMap;
|
||||||
protected Map<Player,String> classMap;
|
protected Map<Player,String> classMap;
|
||||||
protected Map<String,List<ItemStack>> classItems, classArmor;
|
protected Map<String,List<ItemStack>> classItems, classArmor;
|
||||||
|
protected Map<String,List<String>> classPerms;
|
||||||
|
protected Map<Player,List<PermissionAttachment>> attachments;
|
||||||
protected List<ItemStack> entryFee;
|
protected List<ItemStack> entryFee;
|
||||||
|
|
||||||
// Player sets
|
// Player sets
|
||||||
@@ -137,6 +140,7 @@ public class Arena
|
|||||||
randoms = new HashSet<Player>();
|
randoms = new HashSet<Player>();
|
||||||
repairables = new LinkedList<Repairable>();
|
repairables = new LinkedList<Repairable>();
|
||||||
containables = new LinkedList<Repairable>();
|
containables = new LinkedList<Repairable>();
|
||||||
|
attachments = new HashMap<Player,List<PermissionAttachment>>();
|
||||||
|
|
||||||
running = false;
|
running = false;
|
||||||
edit = false;
|
edit = false;
|
||||||
@@ -176,6 +180,7 @@ public class Arena
|
|||||||
{
|
{
|
||||||
p.teleport(arenaLoc);
|
p.teleport(arenaLoc);
|
||||||
p.setHealth(20);
|
p.setHealth(20);
|
||||||
|
assignClassPermissions(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy the singleWaves Set for polling.
|
// Copy the singleWaves Set for polling.
|
||||||
@@ -619,6 +624,7 @@ public class Arena
|
|||||||
if (!arenaPlayers.contains(p) && !lobbyPlayers.contains(p))
|
if (!arenaPlayers.contains(p) && !lobbyPlayers.contains(p))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
removeClassPermissions(p);
|
||||||
MAUtils.clearInventory(p);
|
MAUtils.clearInventory(p);
|
||||||
restoreInvAndGiveRewards(p);
|
restoreInvAndGiveRewards(p);
|
||||||
|
|
||||||
@@ -629,12 +635,10 @@ public class Arena
|
|||||||
public void repairBlocks()
|
public void repairBlocks()
|
||||||
{
|
{
|
||||||
//long start = System.nanoTime();
|
//long start = System.nanoTime();
|
||||||
//System.out.println(start + " - Attempting to repair things...");
|
|
||||||
while (!repairQueue.isEmpty())
|
while (!repairQueue.isEmpty())
|
||||||
{
|
{
|
||||||
repairQueue.poll().repair();
|
repairQueue.poll().repair();
|
||||||
}
|
}
|
||||||
//System.out.println(start + " - Repair finished!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void queueRepairable(Repairable r)
|
public void queueRepairable(Repairable r)
|
||||||
@@ -693,6 +697,26 @@ public class Arena
|
|||||||
MAUtils.tellPlayer(p, Msg.LOBBY_CLASS_PICKED, className);
|
MAUtils.tellPlayer(p, Msg.LOBBY_CLASS_PICKED, className);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void assignClassPermissions(Player p)
|
||||||
|
{
|
||||||
|
Configuration config = plugin.getConfig();
|
||||||
|
String clazz = classMap.get(p);
|
||||||
|
String path = "classes." + clazz + ".permissions.";
|
||||||
|
|
||||||
|
List<String> permissions = classPerms.get(classMap.get(p));
|
||||||
|
if (permissions == null || permissions.isEmpty()) return;
|
||||||
|
|
||||||
|
attachments.put(p, new LinkedList<PermissionAttachment>());
|
||||||
|
for (String perm : permissions)
|
||||||
|
attachments.get(p).add(p.addAttachment(plugin, perm, config.getBoolean(path + perm, true)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeClassPermissions(Player p)
|
||||||
|
{
|
||||||
|
for (PermissionAttachment pa : attachments.get(p))
|
||||||
|
pa.remove();
|
||||||
|
}
|
||||||
|
|
||||||
private void cleanup()
|
private void cleanup()
|
||||||
{
|
{
|
||||||
removeMonsters();
|
removeMonsters();
|
||||||
@@ -827,6 +851,7 @@ public class Arena
|
|||||||
classes = plugin.getAM().classes;
|
classes = plugin.getAM().classes;
|
||||||
classItems = plugin.getAM().classItems;
|
classItems = plugin.getAM().classItems;
|
||||||
classArmor = plugin.getAM().classArmor;
|
classArmor = plugin.getAM().classArmor;
|
||||||
|
classPerms = plugin.getAM().classPerms;
|
||||||
|
|
||||||
// Determine if the arena is properly set up. Then add the to arena list.
|
// Determine if the arena is properly set up. Then add the to arena list.
|
||||||
setup = MAUtils.verifyData(this);
|
setup = MAUtils.verifyData(this);
|
||||||
|
|||||||
@@ -30,7 +30,8 @@ public class ArenaMaster //implements Master
|
|||||||
// Classes
|
// Classes
|
||||||
protected List<String> classes;
|
protected List<String> classes;
|
||||||
protected Map<String,List<ItemStack>> classItems, classArmor;
|
protected Map<String,List<ItemStack>> classItems, classArmor;
|
||||||
protected Map<Integer,Map<Player,List<ItemStack>>> classBonuses;
|
protected Map<String,List<String>> classPerms;
|
||||||
|
//protected Map<Integer,Map<Player,List<ItemStack>>> classBonuses;
|
||||||
protected Map<Player,Arena> arenaMap;
|
protected Map<Player,Arena> arenaMap;
|
||||||
|
|
||||||
// Location map
|
// Location map
|
||||||
@@ -219,9 +220,10 @@ public class ArenaMaster //implements Master
|
|||||||
config.setProperty("classes.Chef.items", "stone_sword, bread:6, grilled_pork:4, mushroom_soup, cake:3, cookie:12");
|
config.setProperty("classes.Chef.items", "stone_sword, bread:6, grilled_pork:4, mushroom_soup, cake:3, cookie:12");
|
||||||
config.setProperty("classes.Chef.armor", "314,315,316,317");
|
config.setProperty("classes.Chef.armor", "314,315,316,317");
|
||||||
}
|
}
|
||||||
classes = config.getKeys("classes");
|
classes = config.getKeys("classes");
|
||||||
classItems = MAUtils.getClassItems(config, "items");
|
classItems = MAUtils.getClassItems(config, "items");
|
||||||
classArmor = MAUtils.getClassItems(config, "armor");
|
classArmor = MAUtils.getClassItems(config, "armor");
|
||||||
|
classPerms = MAUtils.getClassPerms(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -205,6 +205,18 @@ public class MAUtils
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Map<String,List<String>> getClassPerms(Configuration config)
|
||||||
|
{
|
||||||
|
Map<String,List<String>> result = new HashMap<String,List<String>>();
|
||||||
|
List<String> classes = config.getKeys("classes");
|
||||||
|
if (classes == null) return result;
|
||||||
|
|
||||||
|
for (String c : classes)
|
||||||
|
result.put(c, config.getKeys("classes." + c + ".permissions"));
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public static List<ItemStack> getEntryFee(Configuration config, String arena)
|
public static List<ItemStack> getEntryFee(Configuration config, String arena)
|
||||||
{
|
{
|
||||||
return makeItemStackList(config.getString("arenas." + arena + ".settings.entry-fee", null));
|
return makeItemStackList(config.getString("arenas." + arena + ".settings.entry-fee", null));
|
||||||
|
|||||||
Reference in New Issue
Block a user