Fixed ClassLimitManager and split ArenaClass.getName() into
getConfigName() and getLowercaseName()
This commit is contained in:
Binary file not shown.
@@ -1,7 +1,7 @@
|
||||
name: MobArena
|
||||
author: garbagemule
|
||||
main: com.garbagemule.MobArena.MobArena
|
||||
version: 0.94.4.78
|
||||
version: 0.94.4.79
|
||||
softdepend: [Spout,MultiVerse,MultiWorld,XcraftGate,Towny,Heroes,MagicSpells,Vault]
|
||||
commands:
|
||||
ma:
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
Knight: -1
|
||||
Tank: -1
|
||||
Archer: -1
|
||||
Chemist: -1
|
||||
Oddjob: -1
|
||||
@@ -15,7 +15,7 @@ import org.bukkit.permissions.PermissionAttachment;
|
||||
|
||||
public class ArenaClass
|
||||
{
|
||||
private String name;
|
||||
private String configName, lowercaseName;
|
||||
private ItemStack helmet, chestplate, leggings, boots;
|
||||
private List<ItemStack> items, armor;
|
||||
private Map<String,Boolean> perms;
|
||||
@@ -23,10 +23,11 @@ public class ArenaClass
|
||||
|
||||
/**
|
||||
* Create a new, empty arena class with the given name.
|
||||
* @param name the class name
|
||||
* @param name the class name as it appears in the config-file
|
||||
*/
|
||||
public ArenaClass(String name) {
|
||||
this.name = name;
|
||||
this.configName = name;
|
||||
this.lowercaseName = name.toLowerCase();
|
||||
|
||||
this.items = new ArrayList<ItemStack>();
|
||||
this.armor = new ArrayList<ItemStack>(4);
|
||||
@@ -35,11 +36,19 @@ public class ArenaClass
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the arena class.
|
||||
* @return the class name
|
||||
* Get the name of the arena class as it appears in the config-file.
|
||||
* @return the class name as it appears in the config-file
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
public String getConfigName() {
|
||||
return configName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the lowercase class name.
|
||||
* @return the lowercase class name
|
||||
*/
|
||||
public String getLowercaseName() {
|
||||
return lowercaseName;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -217,7 +226,7 @@ public class ArenaClass
|
||||
String perm = entry.getKey() + ":" + entry.getValue();
|
||||
String player = p.getName();
|
||||
|
||||
Messenger.warning("[PERM00] Failed to attach permission '" + perm + "' to player '" + player + " with class " + this.name
|
||||
Messenger.warning("[PERM00] Failed to attach permission '" + perm + "' to player '" + player + " with class " + this.configName
|
||||
+ "'.\nPlease verify that your class permissions are well-formed.");
|
||||
}
|
||||
}
|
||||
@@ -286,4 +295,19 @@ public class ArenaClass
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == null) return false;
|
||||
if (this == o) return true;
|
||||
if (!this.getClass().equals(o.getClass())) return false;
|
||||
|
||||
ArenaClass other = (ArenaClass) o;
|
||||
return other.lowercaseName.equals(this.lowercaseName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return lowercaseName.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -804,31 +804,26 @@ public class ArenaListener
|
||||
ArenaClass oldAC = arena.getArenaPlayer(p).getArenaClass();
|
||||
ArenaClass newAC = arena.getClasses().get(className);
|
||||
|
||||
// If they already had a class, make sure to change the "in use" in the Class Limit Manager
|
||||
if (oldAC != null) {
|
||||
// If they picked the same class, don't do anything
|
||||
if (oldAC.equals(newAC)) {
|
||||
return;
|
||||
}
|
||||
// If they can join the class, decrement the previous class's count
|
||||
if (canPlayerJoinClass(newAC, p)) {
|
||||
classLimits.playerLeftClass(oldAC);
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
// Same class, do nothing.
|
||||
if (newAC.equals(oldAC)) {
|
||||
return;
|
||||
}
|
||||
else {
|
||||
if (!canPlayerJoinClass(newAC, p)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If the new class is full, inform the player.
|
||||
if (!classLimits.canPlayerJoinClass(newAC)) {
|
||||
Messenger.tellPlayer(p, Msg.LOBBY_CLASS_FULL);
|
||||
return;
|
||||
}
|
||||
|
||||
// Otherwise, leave the old class, and pick the new!
|
||||
classLimits.playerLeftClass(oldAC);
|
||||
classLimits.playerPickedClass(newAC);
|
||||
|
||||
// Delay the inventory stuff to ensure that right-clicking works.
|
||||
delayAssignClass(p, className);
|
||||
}
|
||||
|
||||
private boolean canPlayerJoinClass(ArenaClass ac, Player p) {
|
||||
/*private boolean cansPlayerJoinClass(ArenaClass ac, Player p) {
|
||||
// If they can not join the class, deny them
|
||||
if (!classLimits.canPlayerJoinClass(ac)) {
|
||||
Messenger.tellPlayer(p, Msg.LOBBY_CLASS_FULL);
|
||||
@@ -838,7 +833,7 @@ public class ArenaListener
|
||||
// Increment the "in use" in the Class Limit Manager
|
||||
classLimits.playerPickedClass(ac);
|
||||
return true;
|
||||
}
|
||||
}*/
|
||||
|
||||
private void delayAssignClass(final Player p, final String className) {
|
||||
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin,new Runnable() {
|
||||
|
||||
@@ -310,8 +310,8 @@ public class ArenaMasterImpl implements ArenaMaster
|
||||
return null;
|
||||
}
|
||||
|
||||
// Create an ArenaClass with the lowercase name.
|
||||
ArenaClass arenaClass = new ArenaClass(lowercase);
|
||||
// Create an ArenaClass with the config-file name.
|
||||
ArenaClass arenaClass = new ArenaClass(classname);
|
||||
|
||||
// Parse the items-node
|
||||
String items = section.getString("items", "");
|
||||
|
||||
@@ -21,7 +21,7 @@ public class ArenaPlayerStatistics
|
||||
public ArenaPlayerStatistics(ArenaPlayer player) {
|
||||
this.player = player;
|
||||
this.playerName = player.getPlayer().getName();
|
||||
this.className = player.getArenaClass().getName();
|
||||
this.className = player.getArenaClass().getLowercaseName();
|
||||
reset();
|
||||
}
|
||||
|
||||
|
||||
@@ -4,37 +4,45 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.garbagemule.MobArena.framework.Arena;
|
||||
import com.garbagemule.MobArena.util.MutableInt;
|
||||
import com.garbagemule.MobArena.util.config.ConfigSection;
|
||||
import com.garbagemule.MobArena.util.config.ConfigUtils;
|
||||
|
||||
public class ClassLimitManager
|
||||
{
|
||||
private HashMap<ArenaClass, Integer> classLimits, classesInUse;
|
||||
private HashMap<ArenaClass,MutableInt> classLimits, classesInUse;
|
||||
private ConfigSection limits;
|
||||
private MobArena plugin;
|
||||
private Map<String, ArenaClass> classes;
|
||||
private Map<String,ArenaClass> classes;
|
||||
|
||||
public ClassLimitManager(Arena arena, Map<String, ArenaClass> classes, ConfigSection limits) {
|
||||
this.plugin = arena.getPlugin();
|
||||
ConfigUtils.addMissingNodes(plugin, plugin.getMAConfig(), "arenas." + arena.configName() + ".class-limits", "class-limits.yml");
|
||||
public ClassLimitManager(Arena arena, Map<String,ArenaClass> classes, ConfigSection limits) {
|
||||
this.limits = limits;
|
||||
this.classes = classes;
|
||||
this.classLimits = new HashMap<ArenaClass, Integer>();
|
||||
this.classesInUse = new HashMap<ArenaClass, Integer>();
|
||||
this.classLimits = new HashMap<ArenaClass,MutableInt>();
|
||||
this.classesInUse = new HashMap<ArenaClass,MutableInt>();
|
||||
|
||||
loadLimitMap();
|
||||
initInUseMap();
|
||||
}
|
||||
|
||||
private void loadLimitMap() {
|
||||
// If the config-section is empty, create and populate it.
|
||||
if (limits.getKeys() == null) {
|
||||
for (ArenaClass ac : classes.values()) {
|
||||
limits.set(ac.getConfigName(), -1);
|
||||
}
|
||||
limits.getParent().save();
|
||||
}
|
||||
|
||||
// Populate the limits map using the values in the config-file.
|
||||
for (ArenaClass ac : classes.values()) {
|
||||
classLimits.put(ac, limits.getInt(ac.getName(), -1));
|
||||
classLimits.put(ac, new MutableInt(limits.getInt(ac.getConfigName(), -1)));
|
||||
}
|
||||
}
|
||||
|
||||
private void initInUseMap() {
|
||||
// Initialize the in-use map with zeros.
|
||||
for (ArenaClass ac : classes.values()) {
|
||||
classesInUse.put(ac, 0);
|
||||
classesInUse.put(ac, new MutableInt());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +51,7 @@ public class ClassLimitManager
|
||||
* @param ac the new ArenaClass
|
||||
*/
|
||||
public void playerPickedClass(ArenaClass ac) {
|
||||
classesInUse.put(ac, classesInUse.get(ac) + 1);
|
||||
classesInUse.get(ac).inc();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -51,7 +59,9 @@ public class ClassLimitManager
|
||||
* @param ac the current/old ArenaClass
|
||||
*/
|
||||
public void playerLeftClass(ArenaClass ac) {
|
||||
classesInUse.put(ac, classesInUse.get(ac) - 1);
|
||||
if (ac != null) {
|
||||
classesInUse.get(ac).dec();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -61,17 +71,15 @@ public class ClassLimitManager
|
||||
*/
|
||||
public boolean canPlayerJoinClass(ArenaClass ac) {
|
||||
if (classLimits.get(ac) == null) {
|
||||
limits.set(ac.getName(), -1);
|
||||
classLimits.put(ac, -1);
|
||||
classesInUse.put(ac, 0);
|
||||
limits.set(ac.getConfigName(), -1);
|
||||
classLimits.put(ac, new MutableInt(-1));
|
||||
classesInUse.put(ac, new MutableInt());
|
||||
}
|
||||
|
||||
if (classLimits.get(ac) <= -1)
|
||||
return true;
|
||||
else if (classesInUse.get(ac) >= classLimits.get(ac))
|
||||
return false;
|
||||
else
|
||||
if (classLimits.get(ac).value() <= -1)
|
||||
return true;
|
||||
|
||||
return (classesInUse.get(ac).value() < classLimits.get(ac).value());
|
||||
}
|
||||
|
||||
public void clearClassesInUse() {
|
||||
|
||||
@@ -188,8 +188,7 @@ public class MASpawnThread implements Runnable
|
||||
UpgradeWave uw = (UpgradeWave) w;
|
||||
|
||||
for (Player p : arena.getPlayersInArena()) {
|
||||
String className = arena.getArenaPlayer(p).getArenaClass().getName();
|
||||
//String className = arena.getClassOfPlayer(p);
|
||||
String className = arena.getArenaPlayer(p).getArenaClass().getLowercaseName();
|
||||
uw.grantItems(p, className);
|
||||
uw.grantItems(p, "All");
|
||||
}
|
||||
|
||||
@@ -161,7 +161,7 @@ public class MobArenaHandler
|
||||
ArenaClass ac = ap.getArenaClass();
|
||||
if (ac == null) return null;
|
||||
|
||||
return ac.getName();
|
||||
return ac.getLowercaseName();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -29,7 +29,7 @@ public class ArenaLog
|
||||
classDistribution.put(classname, new MutableInt());
|
||||
}
|
||||
for (ArenaPlayer ap : arena.getArenaPlayerSet()) {
|
||||
classDistribution.get(ap.getArenaClass().getName()).inc();
|
||||
classDistribution.get(ap.getArenaClass().getLowercaseName()).inc();
|
||||
}
|
||||
sessionBuilder.buildClassDistribution(classDistribution);
|
||||
totalsBuilder.updateClassDistribution(classDistribution);
|
||||
|
||||
@@ -36,7 +36,7 @@ public class ArenaLogPlayerEntry
|
||||
ArenaLogPlayerEntry entry = new ArenaLogPlayerEntry();
|
||||
|
||||
entry.playername = ap.getPlayer().getName();
|
||||
entry.classname = ap.getArenaClass().getName();
|
||||
entry.classname = ap.getArenaClass().getLowercaseName();
|
||||
|
||||
ArenaPlayerStatistics stats = ap.getStats();
|
||||
entry.kills = stats.getInt("kills");
|
||||
|
||||
@@ -4,22 +4,59 @@ public class MutableInt
|
||||
{
|
||||
private int value;
|
||||
|
||||
/**
|
||||
* Create a new MutableInt with the given value.
|
||||
* @param value the initial value of the MutableInt
|
||||
*/
|
||||
public MutableInt(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new MutableInt with value 0.
|
||||
*/
|
||||
public MutableInt() {
|
||||
this(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the given amount to the internal int value.
|
||||
* @param amount the amount to add
|
||||
*/
|
||||
public void add(int amount) {
|
||||
this.value += amount;
|
||||
}
|
||||
|
||||
public void inc() {
|
||||
this.value++;
|
||||
/**
|
||||
* Subtract the given amount from the internal int value.
|
||||
* @param amount the amount to subtract
|
||||
*/
|
||||
public void sub(int amount) {
|
||||
this.value -= amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Increment the value and return it.
|
||||
* This is essentially the same as calling add(1), followed by value().
|
||||
* @return the value after incrementing by one
|
||||
*/
|
||||
public int inc() {
|
||||
return ++this.value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrement the value and return it.
|
||||
* This is essentially the same as calling sub(1), followed by value().
|
||||
* @return the value after decrementing by one
|
||||
*/
|
||||
public int dec() {
|
||||
return --this.value;
|
||||
}
|
||||
|
||||
/**
|
||||
* The value of the MutableInt.
|
||||
* @return the current value
|
||||
*/
|
||||
public int value() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ public class UpgradeWave extends AbstractWave
|
||||
}
|
||||
|
||||
public void grantItems(Player p, String className) {
|
||||
List<ItemStack> stacks = classMap.get(className.toLowerCase());
|
||||
List<ItemStack> stacks = classMap.get(className);
|
||||
if (stacks == null || stacks.isEmpty()) return;
|
||||
|
||||
PlayerInventory inv = p.getInventory();
|
||||
|
||||
Reference in New Issue
Block a user