diff --git a/MobArena.jar b/MobArena.jar index 64e3b1c..68bbbfb 100644 Binary files a/MobArena.jar and b/MobArena.jar differ diff --git a/resources/plugin.yml b/resources/plugin.yml index 81970ed..998f2ba 100644 --- a/resources/plugin.yml +++ b/resources/plugin.yml @@ -1,7 +1,7 @@ name: MobArena author: garbagemule main: com.garbagemule.MobArena.MobArena -version: 0.94.4.72 +version: 0.94.4.73 softdepend: [Spout,MultiVerse,XcraftGate,Towny,Heroes,MagicSpells,Vault] commands: ma: diff --git a/src/com/garbagemule/MobArena/ArenaImpl.java b/src/com/garbagemule/MobArena/ArenaImpl.java index 6a06686..f67c2fc 100644 --- a/src/com/garbagemule/MobArena/ArenaImpl.java +++ b/src/com/garbagemule/MobArena/ArenaImpl.java @@ -132,7 +132,6 @@ public class ArenaImpl implements Arena this.inventoryManager = new InventoryManager(this); this.rewardManager = new RewardManager(this); - this.limitManager = new ClassLimitManager(this); // Warps, points and locations this.leaderboard = new Leaderboard(plugin, this, region.getLeaderboard()); @@ -147,8 +146,9 @@ public class ArenaImpl implements Arena this.randoms = new HashSet(); // Classes, items and permissions - this.classes = plugin.getArenaMaster().getClasses(); - this.attachments = new HashMap(); + this.classes = plugin.getArenaMaster().getClasses(); + this.attachments = new HashMap(); + this.limitManager = new ClassLimitManager(this, classes); // Blocks and pets this.repairQueue = new PriorityBlockingQueue(100, new RepairableComparator()); diff --git a/src/com/garbagemule/MobArena/ArenaListener.java b/src/com/garbagemule/MobArena/ArenaListener.java index 74112f6..6c71c2c 100644 --- a/src/com/garbagemule/MobArena/ArenaListener.java +++ b/src/com/garbagemule/MobArena/ArenaListener.java @@ -88,6 +88,7 @@ public class ArenaListener private Arena arena; private ArenaRegion region; private MonsterManager monsters; + private ClassLimitManager classLimits; private boolean softRestore, softRestoreDrops, @@ -130,16 +131,7 @@ public class ArenaListener this.canShare = s.getBoolean("share-items-in-arena", true); this.autoIgniteTNT = s.getBoolean("auto-ignite-tnt", false); - /* - * TODO: ClassLimitManager limits = arena.getClassLimitManager(); - * For Each loop to go through each class - * Make sure each class is an actual class - * - * put this stuff in the limit manager - * Map to house the class names and defined limit - * Map to house the current amounts - * clearing methods for the current amounts when the arena starts - */ + this.classLimits = arena.getClassLimitManager(); this.allowMonsters = arena.getWorld().getAllowMonsters(); @@ -797,16 +789,27 @@ public class ArenaListener return; } - /* - * TODO put in class limit check (use ClassLimitManager) - * going to need to track how many pick what classes - * going to need to deny them if there is already too many of that class - * will need to display the new message for class limit exceeded - Msg.LOBBY_CLASS_FULL - * - * big todo: check if a player switches class. if the player already has a class, remove it, and add the new one - * will be "playerChangedClass(previous ArenaClass)" followed by "playerPickedClass(new ArenaClass)" - * however... if the previous and new classes are the same, ignore it completely, and let it move to delayAssignClass() - */ + ArenaClass oldAC = arena.getArenaPlayer(p).getArenaClass(); + ArenaClass newAC = arena.getClasses().get(className); + + // If they picked the same sign, don't do anything + if (oldAC.equals(newAC)) { + return; + } + + // If they can not join the class, deny them + if (!classLimits.canPlayerJoinClass(newAC)) { + Messenger.tellPlayer(p, Msg.LOBBY_CLASS_FULL); + return; + } + + // If they already had a class, make sure to change the "in use" in the Class Limit Manager + if (oldAC != null) { + classLimits.playerChangedClass(oldAC); + } + + // Increment the "in use" in the Class Limit Manager + classLimits.playerPickedClass(newAC); // Delay the inventory stuff to ensure that right-clicking works. delayAssignClass(p, className); diff --git a/src/com/garbagemule/MobArena/ClassLimitManager.java b/src/com/garbagemule/MobArena/ClassLimitManager.java index 07873c6..8ae9f4f 100644 --- a/src/com/garbagemule/MobArena/ClassLimitManager.java +++ b/src/com/garbagemule/MobArena/ClassLimitManager.java @@ -1,6 +1,7 @@ package com.garbagemule.MobArena; import java.util.HashMap; +import java.util.Map; import com.garbagemule.MobArena.framework.Arena; import com.garbagemule.MobArena.util.config.ConfigSection; @@ -10,11 +11,13 @@ public class ClassLimitManager private HashMap classLimits, classesInUse; private ConfigSection limits; private MobArena plugin; + private Map classes; - public ClassLimitManager(Arena arena) { + public ClassLimitManager(Arena arena, Map classes) { this.plugin = arena.getPlugin(); this.limits = new ConfigSection(plugin.getMAConfig(), "arenas." + arena.configName() + ".class-limits"); + this.classes = classes; this.classLimits = new HashMap(); this.classesInUse = new HashMap(); @@ -22,49 +25,39 @@ public class ClassLimitManager initInUseMap(); } - public int getClassLimit(ArenaClass ac) { - if (classLimits.get(ac) != null) - return classLimits.get(ac); - else - return addNewClass(ac); - } - - public int getClassInUse(ArenaClass ac) { - if (classesInUse.get(ac) != null) - return classesInUse.get(ac); - else { - addNewClass(ac); - return 0; - } - } - private void loadLimitMap() { - for (ArenaClass ac : plugin.getArenaMaster().getClasses().values()) { + for (ArenaClass ac : classes.values()) { classLimits.put(ac, limits.getInt(ac.getName(), -1)); } } private void initInUseMap() { - for (ArenaClass ac : plugin.getArenaMaster().getClasses().values()) { + for (ArenaClass ac : classes.values()) { classesInUse.put(ac, 0); } } - private int addNewClass(ArenaClass ac) { - classLimits.put(ac, -1); - classesInUse.put(ac, 0); - limits.set(ac.getName(), -1); - return -1; - } - + /** + * This is the class a player is changing to + * @param ac the new ArenaClass + */ public void playerPickedClass(ArenaClass ac) { classesInUse.put(ac, classesInUse.get(ac) + 1); } + /** + * This is the class a player changed from + * @param ac the current/old ArenaClass + */ public void playerChangedClass(ArenaClass ac) { classesInUse.put(ac, classesInUse.get(ac) - 1); } + /** + * Checks to see if a player can pick a specific class + * @param ac the ArenaClass to check + * @return true/false + */ public boolean canPlayerJoinClass(ArenaClass ac) { if (classLimits.get(ac) <= -1) return true;