Merge pull request #120 from acstache/bleeding

More bug fixes
This commit is contained in:
garbagemule 2012-07-29 20:41:41 -07:00
commit 62c78cc0d2
6 changed files with 63 additions and 45 deletions

View File

@ -1,8 +1,8 @@
name: MobArena name: MobArena
author: garbagemule author: garbagemule
main: com.garbagemule.MobArena.MobArena main: com.garbagemule.MobArena.MobArena
version: 0.94.4.75 version: 0.94.4.78
softdepend: [Spout,MultiVerse,XcraftGate,Towny,Heroes,MagicSpells,Vault] softdepend: [Spout,MultiVerse,MultiWorld,XcraftGate,Towny,Heroes,MagicSpells,Vault]
commands: commands:
ma: ma:
description: Base command for MobArena description: Base command for MobArena

View File

@ -148,7 +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); this.limitManager = new ClassLimitManager(this, classes, new ConfigSection(config, "arenas." + name + ".class-limits"));
// Blocks and pets // Blocks and pets
this.repairQueue = new PriorityBlockingQueue<Repairable>(100, new RepairableComparator()); this.repairQueue = new PriorityBlockingQueue<Repairable>(100, new RepairableComparator());
@ -729,8 +729,7 @@ public class ArenaImpl implements Arena
p.getInventory().removeItem(new ItemStack(Material.BONE, petAmount)); p.getInventory().removeItem(new ItemStack(Material.BONE, petAmount));
for (int i = 0; i < petAmount; i++) { for (int i = 0; i < petAmount; i++) {
Wolf wolf = (Wolf) world.spawnCreature(p.getLocation(), EntityType.WOLF); Wolf wolf = (Wolf) world.spawnEntity(p.getLocation(), EntityType.WOLF);
//Wolf wolf = (Wolf) world.spawnCreature(p.getLocation(), CreatureType.WOLF);
wolf.setTamed(true); wolf.setTamed(true);
wolf.setOwner(p); wolf.setOwner(p);
wolf.setHealth(wolf.getMaxHealth()); wolf.setHealth(wolf.getMaxHealth());

View File

@ -139,6 +139,14 @@ public class ArenaListener
} }
public void onBlockBreak(BlockBreakEvent event) { public void onBlockBreak(BlockBreakEvent event) {
// Check if the block is a sign, it might be a leaderboard
if (event.getBlock() instanceof Sign) {
// If the sign is the leaderboard sign, null out the config
if (event.getBlock().getLocation().equals(arena.getRegion().getLeaderboard())) {
arena.getRegion().set("leaderboard", null);
}
}
if (!arena.getRegion().contains(event.getBlock().getLocation())) if (!arena.getRegion().contains(event.getBlock().getLocation()))
return; return;
@ -631,9 +639,13 @@ public class ArenaListener
for (PotionEffect effect : potion.getEffects()) { for (PotionEffect effect : potion.getEffects()) {
PotionEffectType type = effect.getType(); PotionEffectType type = effect.getType();
if (type.equals(PotionEffectType.HARM) || type.equals(PotionEffectType.POISON)) { if (type.equals(PotionEffectType.HARM) || type.equals(PotionEffectType.POISON)) {
for (Player p : arena.getPlayersInArena()) { Set<LivingEntity> players = new HashSet<LivingEntity>();
event.setIntensity(p, 0D); for (LivingEntity le : event.getAffectedEntities()) {
if (le instanceof Player) {
players.add(le);
}
} }
event.getAffectedEntities().removeAll(players);
break; break;
} }
} }
@ -794,30 +806,40 @@ public class ArenaListener
// If they already had a class, make sure to change the "in use" in the Class Limit Manager // If they already had a class, make sure to change the "in use" in the Class Limit Manager
if (oldAC != null) { if (oldAC != null) {
p.sendMessage("already had a class"); // If they picked the same class, don't do anything
// If they picked the same sign, don't do anything
if (oldAC.equals(newAC)) { if (oldAC.equals(newAC)) {
p.sendMessage("picked the same class");
return; return;
} }
System.out.println("decrementing the classesInUse of " + oldAC.getName()); // If they can join the class, decrement the previous class's count
classLimits.playerLeftClass(oldAC); if (canPlayerJoinClass(newAC, p)) {
classLimits.playerLeftClass(oldAC);
}
else {
return;
}
} }
else {
// If they can not join the class, deny them if (!canPlayerJoinClass(newAC, p)) {
if (!classLimits.canPlayerJoinClass(newAC)) { return;
Messenger.tellPlayer(p, Msg.LOBBY_CLASS_FULL); }
return;
} }
// Increment the "in use" in the Class Limit Manager
System.out.println("incrementing the classesInUse of " + newAC.getName());
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);
} }
private boolean canPlayerJoinClass(ArenaClass ac, Player p) {
// If they can not join the class, deny them
if (!classLimits.canPlayerJoinClass(ac)) {
Messenger.tellPlayer(p, Msg.LOBBY_CLASS_FULL);
return false;
}
// Increment the "in use" in the Class Limit Manager
classLimits.playerPickedClass(ac);
return true;
}
private void delayAssignClass(final Player p, final String className) { private void delayAssignClass(final Player p, final String className) {
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin,new Runnable() { plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin,new Runnable() {
public void run() { public void run() {
@ -873,6 +895,11 @@ public class ArenaListener
Player p = event.getPlayer(); Player p = event.getPlayer();
if (region.contains(from)) { if (region.contains(from)) {
// Players with proper admin permission can warp out
if (p.hasPermission("mobarena.admin.teleport")) {
return TeleportResponse.ALLOW;
}
// Players not in the arena are free to warp out. // Players not in the arena are free to warp out.
if (!arena.inArena(p) && !arena.inLobby(p) && !arena.inSpec(p)) { if (!arena.inArena(p) && !arena.inLobby(p) && !arena.inSpec(p)) {
return TeleportResponse.ALLOW; return TeleportResponse.ALLOW;
@ -887,6 +914,11 @@ public class ArenaListener
return TeleportResponse.REJECT; return TeleportResponse.REJECT;
} }
else if (region.contains(to)) { else if (region.contains(to)) {
// Players with proper admin permission can warp in
if (p.hasPermission("mobarena.admin.teleport")) {
return TeleportResponse.ALLOW;
}
if (region.isWarp(from) || region.isWarp(to) || to.equals(arena.getPlayerEntry(p))) { if (region.isWarp(from) || region.isWarp(to) || to.equals(arena.getPlayerEntry(p))) {
return TeleportResponse.ALLOW; return TeleportResponse.ALLOW;
} }

View File

@ -14,14 +14,10 @@ public class ClassLimitManager
private MobArena plugin; private MobArena plugin;
private Map<String, ArenaClass> classes; private Map<String, ArenaClass> classes;
public ClassLimitManager(Arena arena, Map<String, ArenaClass> classes) { public ClassLimitManager(Arena arena, Map<String, ArenaClass> classes, ConfigSection limits) {
this.plugin = arena.getPlugin(); this.plugin = arena.getPlugin();
ConfigUtils.addMissingNodes(plugin, plugin.getMAConfig(), "arenas." + arena.configName() + ".class-limits", "class-limits.yml"); ConfigUtils.addMissingNodes(plugin, plugin.getMAConfig(), "arenas." + arena.configName() + ".class-limits", "class-limits.yml");
this.limits = new ConfigSection(plugin.getMAConfig(), "arenas." + arena.configName() + ".class-limits"); this.limits = limits;
//TODO figure out why limits is not loading the proper values from the config
//TODO perhaps send along the limits config section from the ArenaImpl class?
//TODO try to use ArenaRegion's config stuff to set up CLM properly
this.classes = classes; 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>();
@ -48,7 +44,6 @@ public class ClassLimitManager
*/ */
public void playerPickedClass(ArenaClass ac) { public void playerPickedClass(ArenaClass ac) {
classesInUse.put(ac, classesInUse.get(ac) + 1); classesInUse.put(ac, classesInUse.get(ac) + 1);
debug();
} }
/** /**
@ -57,7 +52,6 @@ public class ClassLimitManager
*/ */
public void playerLeftClass(ArenaClass ac) { public void playerLeftClass(ArenaClass ac) {
classesInUse.put(ac, classesInUse.get(ac) - 1); classesInUse.put(ac, classesInUse.get(ac) - 1);
debug();
} }
/** /**
@ -66,7 +60,12 @@ public class ClassLimitManager
* @return true/false * @return true/false
*/ */
public boolean canPlayerJoinClass(ArenaClass ac) { public boolean canPlayerJoinClass(ArenaClass ac) {
debug(); if (classLimits.get(ac) == null) {
limits.set(ac.getName(), -1);
classLimits.put(ac, -1);
classesInUse.put(ac, 0);
}
if (classLimits.get(ac) <= -1) if (classLimits.get(ac) <= -1)
return true; return true;
else if (classesInUse.get(ac) >= classLimits.get(ac)) else if (classesInUse.get(ac) >= classLimits.get(ac))
@ -78,16 +77,5 @@ public class ClassLimitManager
public void clearClassesInUse() { public void clearClassesInUse() {
classesInUse.clear(); classesInUse.clear();
initInUseMap(); initInUseMap();
debug();
}
private void debug() {
System.out.println("classesInUse:");
for (ArenaClass ac : classesInUse.keySet())
System.out.println(ac.getName() + " has " + classesInUse.get(ac).intValue() + " players using it.");
System.out.println();
System.out.println("classLimits:");
for (ArenaClass ac : classLimits.keySet())
System.out.println(ac.getName() + " has a limit of " + classLimits.get(ac).intValue() + " players.");
} }
} }

View File

@ -52,8 +52,8 @@ public enum Msg
LOBBY_CLASS_PICKED("You have chosen % as your class!", "%"), LOBBY_CLASS_PICKED("You have chosen % as your class!", "%"),
LOBBY_CLASS_RANDOM("You will get a random class on arena start."), LOBBY_CLASS_RANDOM("You will get a random class on arena start."),
LOBBY_CLASS_PERMISSION("You don't have permission to use this class!", "No permission!", Material.FENCE), LOBBY_CLASS_PERMISSION("You don't have permission to use this class!", "No permission!", Material.FENCE),
WARP_TO_ARENA("Can't warp to the arena during battle!"), WARP_TO_ARENA("Warping to the arena not allowed!"),
WARP_FROM_ARENA("Warping not allowed in the arena!"), WARP_FROM_ARENA("Warping from the arena not allowed!"),
WAVE_DEFAULT("Wave #%!", "Wave #%!", Material.YELLOW_FLOWER), WAVE_DEFAULT("Wave #%!", "Wave #%!", Material.YELLOW_FLOWER),
WAVE_SPECIAL("Wave #%! [SPECIAL]", "Wave #%! [SPECIAL]", Material.RED_ROSE), WAVE_SPECIAL("Wave #%! [SPECIAL]", "Wave #%! [SPECIAL]", Material.RED_ROSE),
WAVE_SWARM("Wave #%! [SWARM]", "Wave #%! [SWARM]", Material.LONG_GRASS), WAVE_SWARM("Wave #%! [SWARM]", "Wave #%! [SWARM]", Material.LONG_GRASS),

View File

@ -88,8 +88,7 @@ public enum MACreature
} }
public LivingEntity spawn(Arena arena, World world, Location loc) { public LivingEntity spawn(Arena arena, World world, Location loc) {
LivingEntity e = world.spawnCreature(loc, type); LivingEntity e = (LivingEntity) world.spawnEntity(loc, type);
//TODO change this to: LivingEntity e = (LivingEntity) world.spawnEntity(loc, type);
switch (this) { switch (this) {
case SHEEP: case SHEEP: