From 4c4e06d3a85ce5fb99211afc98063d392f53d218 Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 27 Jul 2012 10:29:38 -0400 Subject: [PATCH 1/3] v0.94.4.77 - More CLM stuff, Updated Deprecated spawnCreature [requires 1.2.5-R4.1] --- resources/plugin.yml | 4 +- src/com/garbagemule/MobArena/ArenaImpl.java | 5 +- .../garbagemule/MobArena/ArenaListener.java | 56 +++++++++++++------ .../MobArena/ClassLimitManager.java | 28 +++------- src/com/garbagemule/MobArena/Msg.java | 4 +- .../MobArena/waves/MACreature.java | 3 +- 6 files changed, 55 insertions(+), 45 deletions(-) diff --git a/resources/plugin.yml b/resources/plugin.yml index fb7ab1c..04ba260 100644 --- a/resources/plugin.yml +++ b/resources/plugin.yml @@ -1,8 +1,8 @@ name: MobArena author: garbagemule main: com.garbagemule.MobArena.MobArena -version: 0.94.4.75 -softdepend: [Spout,MultiVerse,XcraftGate,Towny,Heroes,MagicSpells,Vault] +version: 0.94.4.77 +softdepend: [Spout,MultiVerse,MultiWorld,XcraftGate,Towny,Heroes,MagicSpells,Vault] commands: ma: description: Base command for MobArena diff --git a/src/com/garbagemule/MobArena/ArenaImpl.java b/src/com/garbagemule/MobArena/ArenaImpl.java index f172370..4adebb7 100644 --- a/src/com/garbagemule/MobArena/ArenaImpl.java +++ b/src/com/garbagemule/MobArena/ArenaImpl.java @@ -148,7 +148,7 @@ public class ArenaImpl implements Arena // Classes, items and permissions this.classes = plugin.getArenaMaster().getClasses(); this.attachments = new HashMap(); - this.limitManager = new ClassLimitManager(this, classes); + this.limitManager = new ClassLimitManager(this, classes, new ConfigSection(config, "arenas." + name + ".class-limits")); // Blocks and pets this.repairQueue = new PriorityBlockingQueue(100, new RepairableComparator()); @@ -729,8 +729,7 @@ public class ArenaImpl implements Arena p.getInventory().removeItem(new ItemStack(Material.BONE, petAmount)); for (int i = 0; i < petAmount; i++) { - Wolf wolf = (Wolf) world.spawnCreature(p.getLocation(), EntityType.WOLF); - //Wolf wolf = (Wolf) world.spawnCreature(p.getLocation(), CreatureType.WOLF); + Wolf wolf = (Wolf) world.spawnEntity(p.getLocation(), EntityType.WOLF); wolf.setTamed(true); wolf.setOwner(p); wolf.setHealth(wolf.getMaxHealth()); diff --git a/src/com/garbagemule/MobArena/ArenaListener.java b/src/com/garbagemule/MobArena/ArenaListener.java index 9f971d6..8973887 100644 --- a/src/com/garbagemule/MobArena/ArenaListener.java +++ b/src/com/garbagemule/MobArena/ArenaListener.java @@ -631,9 +631,13 @@ public class ArenaListener for (PotionEffect effect : potion.getEffects()) { PotionEffectType type = effect.getType(); if (type.equals(PotionEffectType.HARM) || type.equals(PotionEffectType.POISON)) { - for (Player p : arena.getPlayersInArena()) { - event.setIntensity(p, 0D); + Set players = new HashSet(); + for (LivingEntity le : event.getAffectedEntities()) { + if (le instanceof Player) { + players.add(le); + } } + event.getAffectedEntities().removeAll(players); break; } } @@ -794,29 +798,39 @@ public class ArenaListener // If they already had a class, make sure to change the "in use" in the Class Limit Manager if (oldAC != null) { - p.sendMessage("already had a class"); - // If they picked the same sign, don't do anything + // If they picked the same class, don't do anything if (oldAC.equals(newAC)) { - p.sendMessage("picked the same class"); return; } - System.out.println("decrementing the classesInUse of " + oldAC.getName()); - classLimits.playerLeftClass(oldAC); + // If they can join the class, decrement the previous class's count + if (canPlayerJoinClass(newAC, p)) { + classLimits.playerLeftClass(oldAC); + } + else { + return; + } } - - // If they can not join the class, deny them - if (!classLimits.canPlayerJoinClass(newAC)) { - Messenger.tellPlayer(p, Msg.LOBBY_CLASS_FULL); - return; + else { + if (!canPlayerJoinClass(newAC, p)) { + 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. 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) { plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin,new Runnable() { @@ -873,6 +887,11 @@ public class ArenaListener Player p = event.getPlayer(); 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. if (!arena.inArena(p) && !arena.inLobby(p) && !arena.inSpec(p)) { return TeleportResponse.ALLOW; @@ -887,6 +906,11 @@ public class ArenaListener return TeleportResponse.REJECT; } 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))) { return TeleportResponse.ALLOW; } diff --git a/src/com/garbagemule/MobArena/ClassLimitManager.java b/src/com/garbagemule/MobArena/ClassLimitManager.java index d030702..68a6895 100644 --- a/src/com/garbagemule/MobArena/ClassLimitManager.java +++ b/src/com/garbagemule/MobArena/ClassLimitManager.java @@ -14,14 +14,10 @@ public class ClassLimitManager private MobArena plugin; private Map classes; - public ClassLimitManager(Arena arena, Map classes) { + public ClassLimitManager(Arena arena, Map classes, ConfigSection limits) { this.plugin = arena.getPlugin(); ConfigUtils.addMissingNodes(plugin, plugin.getMAConfig(), "arenas." + arena.configName() + ".class-limits", "class-limits.yml"); - this.limits = new ConfigSection(plugin.getMAConfig(), "arenas." + arena.configName() + ".class-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.limits = limits; this.classes = classes; this.classLimits = new HashMap(); this.classesInUse = new HashMap(); @@ -48,7 +44,6 @@ public class ClassLimitManager */ public void playerPickedClass(ArenaClass ac) { classesInUse.put(ac, classesInUse.get(ac) + 1); - debug(); } /** @@ -57,7 +52,6 @@ public class ClassLimitManager */ public void playerLeftClass(ArenaClass ac) { classesInUse.put(ac, classesInUse.get(ac) - 1); - debug(); } /** @@ -66,7 +60,12 @@ public class ClassLimitManager * @return true/false */ 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) return true; else if (classesInUse.get(ac) >= classLimits.get(ac)) @@ -78,16 +77,5 @@ public class ClassLimitManager public void clearClassesInUse() { classesInUse.clear(); 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."); } } \ No newline at end of file diff --git a/src/com/garbagemule/MobArena/Msg.java b/src/com/garbagemule/MobArena/Msg.java index 1641980..77accf8 100644 --- a/src/com/garbagemule/MobArena/Msg.java +++ b/src/com/garbagemule/MobArena/Msg.java @@ -52,8 +52,8 @@ public enum Msg LOBBY_CLASS_PICKED("You have chosen % as your class!", "%"), 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), - WARP_TO_ARENA("Can't warp to the arena during battle!"), - WARP_FROM_ARENA("Warping not allowed in the arena!"), + WARP_TO_ARENA("Warping to the arena not allowed!"), + WARP_FROM_ARENA("Warping from the arena not allowed!"), WAVE_DEFAULT("Wave #%!", "Wave #%!", Material.YELLOW_FLOWER), WAVE_SPECIAL("Wave #%! [SPECIAL]", "Wave #%! [SPECIAL]", Material.RED_ROSE), WAVE_SWARM("Wave #%! [SWARM]", "Wave #%! [SWARM]", Material.LONG_GRASS), diff --git a/src/com/garbagemule/MobArena/waves/MACreature.java b/src/com/garbagemule/MobArena/waves/MACreature.java index 9cd8686..9c6a37a 100644 --- a/src/com/garbagemule/MobArena/waves/MACreature.java +++ b/src/com/garbagemule/MobArena/waves/MACreature.java @@ -88,8 +88,7 @@ public enum MACreature } public LivingEntity spawn(Arena arena, World world, Location loc) { - LivingEntity e = world.spawnCreature(loc, type); - //TODO change this to: LivingEntity e = (LivingEntity) world.spawnEntity(loc, type); + LivingEntity e = (LivingEntity) world.spawnEntity(loc, type); switch (this) { case SHEEP: From a93749225e22d160e884ed1d74e92b4de517e18e Mon Sep 17 00:00:00 2001 From: Brian Date: Sun, 29 Jul 2012 22:30:16 -0400 Subject: [PATCH 2/3] v0.94.4.78 - listen for sign breaks, if it is a leaderboard sign, remove it from the config --- resources/plugin.yml | 2 +- src/com/garbagemule/MobArena/ArenaListener.java | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/resources/plugin.yml b/resources/plugin.yml index 04ba260..4afc01a 100644 --- a/resources/plugin.yml +++ b/resources/plugin.yml @@ -1,7 +1,7 @@ name: MobArena author: garbagemule main: com.garbagemule.MobArena.MobArena -version: 0.94.4.77 +version: 0.94.4.78 softdepend: [Spout,MultiVerse,MultiWorld,XcraftGate,Towny,Heroes,MagicSpells,Vault] commands: ma: diff --git a/src/com/garbagemule/MobArena/ArenaListener.java b/src/com/garbagemule/MobArena/ArenaListener.java index 8973887..2266c63 100644 --- a/src/com/garbagemule/MobArena/ArenaListener.java +++ b/src/com/garbagemule/MobArena/ArenaListener.java @@ -139,6 +139,14 @@ public class ArenaListener } 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())) return; From b7f25504f29ac1901f57232ccf8cb838d403cba4 Mon Sep 17 00:00:00 2001 From: Brian Date: Sun, 29 Jul 2012 22:39:38 -0400 Subject: [PATCH 3/3] replace tabs with 4 spaces --- src/com/garbagemule/MobArena/ArenaListener.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/com/garbagemule/MobArena/ArenaListener.java b/src/com/garbagemule/MobArena/ArenaListener.java index 2266c63..b868cbf 100644 --- a/src/com/garbagemule/MobArena/ArenaListener.java +++ b/src/com/garbagemule/MobArena/ArenaListener.java @@ -139,14 +139,14 @@ public class ArenaListener } 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); - } - } - + // 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())) return;