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
author: garbagemule
main: com.garbagemule.MobArena.MobArena
version: 0.94.4.72
version: 0.94.4.73
softdepend: [Spout,MultiVerse,XcraftGate,Towny,Heroes,MagicSpells,Vault]
commands:
ma:

View File

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

View File

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

View File

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