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:
@@ -622,7 +622,7 @@ public class ArenaImpl implements Arena
|
|||||||
ArenaPlayer ap = arenaPlayerMap.get(p);
|
ArenaPlayer ap = arenaPlayerMap.get(p);
|
||||||
if (inLobby(p)) {
|
if (inLobby(p)) {
|
||||||
if (ap.getArenaClass() != null) {
|
if (ap.getArenaClass() != null) {
|
||||||
limitManager.playerLeftClass(ap.getArenaClass());
|
limitManager.playerLeftClass(ap.getArenaClass(), ap.getPlayer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -863,8 +863,8 @@ public class ArenaListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, leave the old class, and pick the new!
|
// Otherwise, leave the old class, and pick the new!
|
||||||
classLimits.playerLeftClass(oldAC);
|
classLimits.playerLeftClass(oldAC, p);
|
||||||
classLimits.playerPickedClass(newAC);
|
classLimits.playerPickedClass(newAC, p);
|
||||||
|
|
||||||
// Delay the inventory stuff to ensure that right-clicking works.
|
// Delay the inventory stuff to ensure that right-clicking works.
|
||||||
delayAssignClass(p, className, sign);
|
delayAssignClass(p, className, sign);
|
||||||
|
|||||||
@@ -1,15 +1,19 @@
|
|||||||
package com.garbagemule.MobArena;
|
package com.garbagemule.MobArena;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.garbagemule.MobArena.framework.Arena;
|
import com.garbagemule.MobArena.framework.Arena;
|
||||||
import com.garbagemule.MobArena.util.MutableInt;
|
import com.garbagemule.MobArena.util.MutableInt;
|
||||||
import com.garbagemule.MobArena.util.config.ConfigSection;
|
import com.garbagemule.MobArena.util.config.ConfigSection;
|
||||||
|
|
||||||
public class ClassLimitManager
|
public class ClassLimitManager
|
||||||
{
|
{
|
||||||
private HashMap<ArenaClass,MutableInt> classLimits, classesInUse;
|
private HashMap<ArenaClass,MutableInt> classLimits;
|
||||||
|
private HashMap<ArenaClass, HashSet<String>> classesInUse;
|
||||||
private ConfigSection limits;
|
private ConfigSection limits;
|
||||||
private Map<String,ArenaClass> classes;
|
private Map<String,ArenaClass> classes;
|
||||||
|
|
||||||
@@ -17,7 +21,7 @@ public class ClassLimitManager
|
|||||||
this.limits = limits;
|
this.limits = limits;
|
||||||
this.classes = classes;
|
this.classes = classes;
|
||||||
this.classLimits = new HashMap<ArenaClass,MutableInt>();
|
this.classLimits = new HashMap<ArenaClass,MutableInt>();
|
||||||
this.classesInUse = new HashMap<ArenaClass,MutableInt>();
|
this.classesInUse = new HashMap<ArenaClass, HashSet<String>>();
|
||||||
|
|
||||||
loadLimitMap();
|
loadLimitMap();
|
||||||
initInUseMap();
|
initInUseMap();
|
||||||
@@ -41,7 +45,7 @@ public class ClassLimitManager
|
|||||||
private void initInUseMap() {
|
private void initInUseMap() {
|
||||||
// Initialize the in-use map with zeros.
|
// Initialize the in-use map with zeros.
|
||||||
for (ArenaClass ac : classes.values()) {
|
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
|
* This is the class a player is changing to
|
||||||
* @param ac the new ArenaClass
|
* @param ac the new ArenaClass
|
||||||
*/
|
*/
|
||||||
public void playerPickedClass(ArenaClass ac) {
|
public void playerPickedClass(ArenaClass ac, Player p) {
|
||||||
classesInUse.get(ac).inc();
|
classesInUse.get(ac).add(p.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the class a player left
|
* This is the class a player left
|
||||||
* @param ac the current/old ArenaClass
|
* @param ac the current/old ArenaClass
|
||||||
*/
|
*/
|
||||||
public void playerLeftClass(ArenaClass ac) {
|
public void playerLeftClass(ArenaClass ac, Player p) {
|
||||||
if (ac != null) {
|
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) {
|
if (classLimits.get(ac) == null) {
|
||||||
limits.set(ac.getConfigName(), -1);
|
limits.set(ac.getConfigName(), -1);
|
||||||
classLimits.put(ac, new MutableInt(-1));
|
classLimits.put(ac, new MutableInt(-1));
|
||||||
classesInUse.put(ac, new MutableInt());
|
classesInUse.put(ac, new HashSet<String>());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (classLimits.get(ac).value() <= -1)
|
if (classLimits.get(ac).value() <= -1)
|
||||||
return true;
|
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() {
|
public void clearClassesInUse() {
|
||||||
classesInUse.clear();
|
classesInUse.clear();
|
||||||
initInUseMap();
|
initInUseMap();
|
||||||
|
|||||||
Reference in New Issue
Block a user