Merge pull request #194 from acstache/bleeding

Keep track of which players picked which class

- Change MutableInt counters to String sets of player names
- Add getPlayersWithClass() method
This commit is contained in:
garbagemule 2013-07-02 16:29:29 -07:00
commit 0fdffedf85
3 changed files with 28 additions and 12 deletions

View File

@ -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());
}
}

View File

@ -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);

View File

@ -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<ArenaClass,MutableInt> classLimits, classesInUse;
private HashMap<ArenaClass,MutableInt> classLimits;
private HashMap<ArenaClass, HashSet<String>> classesInUse;
private ConfigSection limits;
private Map<String,ArenaClass> classes;
@ -17,7 +21,7 @@ public class ClassLimitManager
this.limits = limits;
this.classes = classes;
this.classLimits = new HashMap<ArenaClass,MutableInt>();
this.classesInUse = new HashMap<ArenaClass,MutableInt>();
this.classesInUse = new HashMap<ArenaClass, HashSet<String>>();
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<String>());
}
}
@ -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<String>());
}
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<String> 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();