From 07637d087afdafa1b51173a769057bf4ad751cb7 Mon Sep 17 00:00:00 2001 From: acstache Date: Mon, 1 Jul 2013 23:51:26 -0400 Subject: [PATCH] update ClassLimitManager to provide a set of names of Players who have picked the provided ArenaClass. This will allow manipulating players of just a certain class more easily than before. One possibility is (mind you this is NOT implemented) adding potion effects to a class --- src/com/garbagemule/MobArena/ArenaImpl.java | 2 +- .../garbagemule/MobArena/ArenaListener.java | 4 +-- .../MobArena/ClassLimitManager.java | 34 ++++++++++++++----- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/com/garbagemule/MobArena/ArenaImpl.java b/src/com/garbagemule/MobArena/ArenaImpl.java index 600906b..f1c3828 100644 --- a/src/com/garbagemule/MobArena/ArenaImpl.java +++ b/src/com/garbagemule/MobArena/ArenaImpl.java @@ -622,7 +622,7 @@ public class ArenaImpl implements Arena ArenaPlayer ap = arenaPlayerMap.get(p); if (inLobby(p)) { if (ap.getArenaClass() != null) { - limitManager.playerLeftClass(ap.getArenaClass()); + limitManager.playerLeftClass(ap.getArenaClass(), ap.getPlayer()); } } diff --git a/src/com/garbagemule/MobArena/ArenaListener.java b/src/com/garbagemule/MobArena/ArenaListener.java index 4df6256..02569b4 100644 --- a/src/com/garbagemule/MobArena/ArenaListener.java +++ b/src/com/garbagemule/MobArena/ArenaListener.java @@ -863,8 +863,8 @@ public class ArenaListener } // Otherwise, leave the old class, and pick the new! - classLimits.playerLeftClass(oldAC); - classLimits.playerPickedClass(newAC); + classLimits.playerLeftClass(oldAC, p); + classLimits.playerPickedClass(newAC, p); // Delay the inventory stuff to ensure that right-clicking works. delayAssignClass(p, className, sign); diff --git a/src/com/garbagemule/MobArena/ClassLimitManager.java b/src/com/garbagemule/MobArena/ClassLimitManager.java index df26116..4a2154c 100644 --- a/src/com/garbagemule/MobArena/ClassLimitManager.java +++ b/src/com/garbagemule/MobArena/ClassLimitManager.java @@ -1,15 +1,19 @@ package com.garbagemule.MobArena; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; +import org.bukkit.entity.Player; + import com.garbagemule.MobArena.framework.Arena; import com.garbagemule.MobArena.util.MutableInt; import com.garbagemule.MobArena.util.config.ConfigSection; public class ClassLimitManager { - private HashMap classLimits, classesInUse; + private HashMap classLimits; + private HashMap> classesInUse; private ConfigSection limits; private Map classes; @@ -17,7 +21,7 @@ public class ClassLimitManager this.limits = limits; this.classes = classes; this.classLimits = new HashMap(); - this.classesInUse = new HashMap(); + this.classesInUse = new HashMap>(); loadLimitMap(); initInUseMap(); @@ -41,7 +45,7 @@ public class ClassLimitManager private void initInUseMap() { // Initialize the in-use map with zeros. for (ArenaClass ac : classes.values()) { - classesInUse.put(ac, new MutableInt()); + classesInUse.put(ac, new HashSet()); } } @@ -49,17 +53,17 @@ public class ClassLimitManager * This is the class a player is changing to * @param ac the new ArenaClass */ - public void playerPickedClass(ArenaClass ac) { - classesInUse.get(ac).inc(); + public void playerPickedClass(ArenaClass ac, Player p) { + classesInUse.get(ac).add(p.getName()); } /** * This is the class a player left * @param ac the current/old ArenaClass */ - public void playerLeftClass(ArenaClass ac) { + public void playerLeftClass(ArenaClass ac, Player p) { if (ac != null) { - classesInUse.get(ac).dec(); + classesInUse.get(ac).remove(p.getName()); } } @@ -72,15 +76,27 @@ public class ClassLimitManager if (classLimits.get(ac) == null) { limits.set(ac.getConfigName(), -1); classLimits.put(ac, new MutableInt(-1)); - classesInUse.put(ac, new MutableInt()); + classesInUse.put(ac, new HashSet()); } if (classLimits.get(ac).value() <= -1) return true; - return (classesInUse.get(ac).value() < classLimits.get(ac).value()); + return classesInUse.get(ac).size() < classLimits.get(ac).value(); } + /** + * returns a set of Player Names who have picked an ArenaClass + * @param ac the ArenaClass in question + * @return the Player Names who have picked the provided ArenaClass + */ + public HashSet getPlayersWithClass(ArenaClass ac) { + return classesInUse.get(ac); + } + + /** + * Clear the classes in use map and reinitialize it for the next match + */ public void clearClassesInUse() { classesInUse.clear(); initInUseMap();