v0.94.4.73 - more Class Limit Manager work; testing begins

This commit is contained in:
Brian 2012-06-07 21:13:15 -04:00
parent c6fada2bfd
commit cb06e2cb1e
5 changed files with 46 additions and 50 deletions

Binary file not shown.

View File

@ -1,7 +1,7 @@
name: MobArena name: MobArena
author: garbagemule author: garbagemule
main: com.garbagemule.MobArena.MobArena main: com.garbagemule.MobArena.MobArena
version: 0.94.4.72 version: 0.94.4.73
softdepend: [Spout,MultiVerse,XcraftGate,Towny,Heroes,MagicSpells,Vault] softdepend: [Spout,MultiVerse,XcraftGate,Towny,Heroes,MagicSpells,Vault]
commands: commands:
ma: ma:

View File

@ -132,7 +132,6 @@ public class ArenaImpl implements Arena
this.inventoryManager = new InventoryManager(this); this.inventoryManager = new InventoryManager(this);
this.rewardManager = new RewardManager(this); this.rewardManager = new RewardManager(this);
this.limitManager = new ClassLimitManager(this);
// Warps, points and locations // Warps, points and locations
this.leaderboard = new Leaderboard(plugin, this, region.getLeaderboard()); this.leaderboard = new Leaderboard(plugin, this, region.getLeaderboard());
@ -149,6 +148,7 @@ public class ArenaImpl implements Arena
// Classes, items and permissions // Classes, items and permissions
this.classes = plugin.getArenaMaster().getClasses(); this.classes = plugin.getArenaMaster().getClasses();
this.attachments = new HashMap<Player,PermissionAttachment>(); this.attachments = new HashMap<Player,PermissionAttachment>();
this.limitManager = new ClassLimitManager(this, classes);
// Blocks and pets // Blocks and pets
this.repairQueue = new PriorityBlockingQueue<Repairable>(100, new RepairableComparator()); this.repairQueue = new PriorityBlockingQueue<Repairable>(100, new RepairableComparator());

View File

@ -88,6 +88,7 @@ public class ArenaListener
private Arena arena; private Arena arena;
private ArenaRegion region; private ArenaRegion region;
private MonsterManager monsters; private MonsterManager monsters;
private ClassLimitManager classLimits;
private boolean softRestore, private boolean softRestore,
softRestoreDrops, softRestoreDrops,
@ -130,16 +131,7 @@ public class ArenaListener
this.canShare = s.getBoolean("share-items-in-arena", true); this.canShare = s.getBoolean("share-items-in-arena", true);
this.autoIgniteTNT = s.getBoolean("auto-ignite-tnt", false); this.autoIgniteTNT = s.getBoolean("auto-ignite-tnt", false);
/* this.classLimits = arena.getClassLimitManager();
* 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<String, Integer> to house the class names and defined limit
* Map<String, Integer> to house the current amounts
* clearing methods for the current amounts when the arena starts
*/
this.allowMonsters = arena.getWorld().getAllowMonsters(); this.allowMonsters = arena.getWorld().getAllowMonsters();
@ -797,16 +789,27 @@ public class ArenaListener
return; return;
} }
/* ArenaClass oldAC = arena.getArenaPlayer(p).getArenaClass();
* TODO put in class limit check (use ClassLimitManager) ArenaClass newAC = arena.getClasses().get(className);
* 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 // If they picked the same sign, don't do anything
* will need to display the new message for class limit exceeded - Msg.LOBBY_CLASS_FULL if (oldAC.equals(newAC)) {
* return;
* 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() // 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. // Delay the inventory stuff to ensure that right-clicking works.
delayAssignClass(p, className); delayAssignClass(p, className);

View File

@ -1,6 +1,7 @@
package com.garbagemule.MobArena; package com.garbagemule.MobArena;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map;
import com.garbagemule.MobArena.framework.Arena; import com.garbagemule.MobArena.framework.Arena;
import com.garbagemule.MobArena.util.config.ConfigSection; import com.garbagemule.MobArena.util.config.ConfigSection;
@ -10,11 +11,13 @@ public class ClassLimitManager
private HashMap<ArenaClass, Integer> classLimits, classesInUse; private HashMap<ArenaClass, Integer> classLimits, classesInUse;
private ConfigSection limits; private ConfigSection limits;
private MobArena plugin; private MobArena plugin;
private Map<String, ArenaClass> classes;
public ClassLimitManager(Arena arena) { public ClassLimitManager(Arena arena, Map<String, ArenaClass> classes) {
this.plugin = arena.getPlugin(); this.plugin = arena.getPlugin();
this.limits = new ConfigSection(plugin.getMAConfig(), "arenas." + arena.configName() + ".class-limits"); this.limits = new ConfigSection(plugin.getMAConfig(), "arenas." + arena.configName() + ".class-limits");
this.classes = classes;
this.classLimits = new HashMap<ArenaClass, Integer>(); this.classLimits = new HashMap<ArenaClass, Integer>();
this.classesInUse = new HashMap<ArenaClass, Integer>(); this.classesInUse = new HashMap<ArenaClass, Integer>();
@ -22,49 +25,39 @@ public class ClassLimitManager
initInUseMap(); 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() { private void loadLimitMap() {
for (ArenaClass ac : plugin.getArenaMaster().getClasses().values()) { for (ArenaClass ac : classes.values()) {
classLimits.put(ac, limits.getInt(ac.getName(), -1)); classLimits.put(ac, limits.getInt(ac.getName(), -1));
} }
} }
private void initInUseMap() { private void initInUseMap() {
for (ArenaClass ac : plugin.getArenaMaster().getClasses().values()) { for (ArenaClass ac : classes.values()) {
classesInUse.put(ac, 0); classesInUse.put(ac, 0);
} }
} }
private int addNewClass(ArenaClass ac) { /**
classLimits.put(ac, -1); * This is the class a player is changing to
classesInUse.put(ac, 0); * @param ac the new ArenaClass
limits.set(ac.getName(), -1); */
return -1;
}
public void playerPickedClass(ArenaClass ac) { public void playerPickedClass(ArenaClass ac) {
classesInUse.put(ac, classesInUse.get(ac) + 1); 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) { public void playerChangedClass(ArenaClass ac) {
classesInUse.put(ac, classesInUse.get(ac) - 1); 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) { public boolean canPlayerJoinClass(ArenaClass ac) {
if (classLimits.get(ac) <= -1) if (classLimits.get(ac) <= -1)
return true; return true;