From 708ed2821d564610ee6ff5172f75a9cf14042196 Mon Sep 17 00:00:00 2001 From: Brian Date: Sun, 13 May 2012 02:22:21 -0400 Subject: [PATCH] 0.94.4.66 - bug fixes, works for 1.2.5-R1.3 --- src/com/garbagemule/MobArena/ArenaClass.java | 8 +++- src/com/garbagemule/MobArena/ArenaImpl.java | 32 ++++++++++--- .../garbagemule/MobArena/ArenaMasterImpl.java | 15 ++++++ .../MobArena/commands/CommandHandler.java | 1 + .../commands/setup/ListClassesCommand.java | 2 +- .../setup/RemoveLeaderboardCommand.java | 47 +++++++++++++++++++ .../garbagemule/MobArena/framework/Arena.java | 4 ++ .../MobArena/log/YMLSessionBuilder.java | 29 +++++++----- .../MobArena/region/ArenaRegion.java | 5 +- .../garbagemule/MobArena/util/ItemParser.java | 4 +- .../MobArena/waves/WaveParser.java | 6 +-- .../MobArena/waves/types/BossWave.java | 17 +++++-- 12 files changed, 138 insertions(+), 32 deletions(-) create mode 100644 src/com/garbagemule/MobArena/commands/setup/RemoveLeaderboardCommand.java diff --git a/src/com/garbagemule/MobArena/ArenaClass.java b/src/com/garbagemule/MobArena/ArenaClass.java index d3d3b51..85940ab 100644 --- a/src/com/garbagemule/MobArena/ArenaClass.java +++ b/src/com/garbagemule/MobArena/ArenaClass.java @@ -101,6 +101,12 @@ public class ArenaClass else if (stack.getType() == Material.BONE) { pets += stack.getAmount(); } + else if (stack.getAmount() > 64) { + while (stack.getAmount() > 64) { + items.add(new ItemStack(stack.getType(), 64)); + stack.setAmount(stack.getAmount() - 64); + } + } items.add(stack); } @@ -229,7 +235,7 @@ public class ArenaClass /** * Used by isWeapon() to determine if an ItemStack is a weapon type. */ - private static int[] weaponTypes = new int[]{256,257,258,267,268,269,270,271,272,273,274,275,276,277,278,279,283,284,285,286,290,291,292,293,294}; + private static int[] weaponTypes = new int[]{256,257,258,261,267,268,269,270,271,272,273,274,275,276,277,278,279,283,284,285,286,290,291,292,293,294}; /** * Returns true, if the ItemStack appears to be a weapon, in which case diff --git a/src/com/garbagemule/MobArena/ArenaImpl.java b/src/com/garbagemule/MobArena/ArenaImpl.java index 3e48b6d..0c241d7 100644 --- a/src/com/garbagemule/MobArena/ArenaImpl.java +++ b/src/com/garbagemule/MobArena/ArenaImpl.java @@ -100,6 +100,7 @@ public class ArenaImpl implements Arena private Map> everyWaveMap, afterWaveMap; // Logging + private boolean logging; private ArenaLog log; private LogSessionBuilder sessionBuilder; private LogTotalsBuilder totalsBuilder; @@ -124,6 +125,7 @@ public class ArenaImpl implements Arena this.enabled = settings.getBoolean("enabled", false); this.protect = settings.getBoolean("protect", true); + this.logging = settings.getBoolean("logging", true); this.running = false; this.edit = false; @@ -170,11 +172,13 @@ public class ArenaImpl implements Arena Time time = Enums.getEnumFromString(Time.class, timeString); this.timeStrategy = (time != null ? new TimeStrategyLocked(time) : new TimeStrategyNull()); - this.dir = new File(plugin.getDataFolder() + File.separator + "arenas" + File.separator + name); - this.sessionBuilder = new YMLSessionBuilder(new File(dir, "log_session.yml")); - this.totalsBuilder = new YMLTotalsBuilder(new File(dir, "log_totals.yml")); - - this.log = new ArenaLog(this, sessionBuilder, totalsBuilder); + if(isLogging()) { + this.dir = new File(plugin.getDataFolder() + File.separator + "arenas" + File.separator + name); + this.sessionBuilder = new YMLSessionBuilder(new File(dir, "log_session.yml")); + this.totalsBuilder = new YMLTotalsBuilder(new File(dir, "log_totals.yml")); + + this.log = new ArenaLog(this, sessionBuilder, totalsBuilder); + } } @@ -219,6 +223,18 @@ public class ArenaImpl implements Arena @Override public void setProtected(boolean value) { protect = value; + settings.set("protect", protect); + } + + @Override + public boolean isLogging() { + return logging; + } + + @Override + public void setLogging(boolean value) { + logging = value; + settings.set("logging", logging); } @Override @@ -436,7 +452,8 @@ public class ArenaImpl implements Arena // Start logging rewardManager.reset(); - log.start(); + if(isLogging()) + log.start(); // Initialize leaderboards and start displaying info. leaderboard.initialize(); @@ -471,7 +488,8 @@ public class ArenaImpl implements Arena leaderboard.update(); // Finish logging - log.end(); + if(isLogging()) + log.end(); // Stop spawning. stopSpawner(); diff --git a/src/com/garbagemule/MobArena/ArenaMasterImpl.java b/src/com/garbagemule/MobArena/ArenaMasterImpl.java index 9548694..65f4f08 100644 --- a/src/com/garbagemule/MobArena/ArenaMasterImpl.java +++ b/src/com/garbagemule/MobArena/ArenaMasterImpl.java @@ -24,6 +24,7 @@ import com.garbagemule.MobArena.ArenaClass.ArmorType; import com.garbagemule.MobArena.framework.Arena; import com.garbagemule.MobArena.framework.ArenaMaster; import com.garbagemule.MobArena.util.ItemParser; +import com.garbagemule.MobArena.util.TextUtils; import com.garbagemule.MobArena.util.config.Config; import com.garbagemule.MobArena.util.config.ConfigSection; import com.garbagemule.MobArena.util.config.ConfigUtils; @@ -424,6 +425,7 @@ public class ArenaMasterImpl implements ArenaMaster } private boolean addRemoveClassPermission(String classname, String perm, boolean add) { + classname = TextUtils.camelCase(classname); String path = "classes." + classname; if (config.getConfigSection(path) == null) return false; @@ -433,6 +435,18 @@ public class ArenaMasterImpl implements ArenaMaster // Get any previous nodes List nodes = section.getStringList("permissions", null); + + if (nodes.contains(perm) && add) + return false; + else if (nodes.contains(perm) && !add) + nodes.remove(perm); + else if (!nodes.contains(perm) && add) + nodes.add(perm); + else if (!nodes.contains(perm) && !add) + return false; + + /* erroneous logic - if it contains the perm when trying to remove, it won't remove it. + * it would return false early. if (nodes.contains(perm)) return false; @@ -444,6 +458,7 @@ public class ArenaMasterImpl implements ArenaMaster else { nodes.remove(perm); } + */ // Replace the set. section.set("permissions", nodes); diff --git a/src/com/garbagemule/MobArena/commands/CommandHandler.java b/src/com/garbagemule/MobArena/commands/CommandHandler.java index 2c2fa65..c49eaa4 100644 --- a/src/com/garbagemule/MobArena/commands/CommandHandler.java +++ b/src/com/garbagemule/MobArena/commands/CommandHandler.java @@ -185,6 +185,7 @@ public class CommandHandler implements CommandExecutor register(RemoveClassCommand.class); register(RemoveClassPermCommand.class); register(RemoveContainerCommand.class); + register(RemoveLeaderboardCommand.class); register(RemoveSpawnpointCommand.class); register(SetArenaCommand.class); register(SetClassCommand.class); diff --git a/src/com/garbagemule/MobArena/commands/setup/ListClassesCommand.java b/src/com/garbagemule/MobArena/commands/setup/ListClassesCommand.java index fc08fc0..b13d938 100644 --- a/src/com/garbagemule/MobArena/commands/setup/ListClassesCommand.java +++ b/src/com/garbagemule/MobArena/commands/setup/ListClassesCommand.java @@ -10,7 +10,7 @@ import com.garbagemule.MobArena.framework.ArenaMaster; @CommandInfo( name = "listclasses", - pattern = "(list)?class(.)*", + pattern = "(list)?classes(.)*", usage = "/ma listclasses", desc = "list all current classes", permission = "mobarena.setup.classes" diff --git a/src/com/garbagemule/MobArena/commands/setup/RemoveLeaderboardCommand.java b/src/com/garbagemule/MobArena/commands/setup/RemoveLeaderboardCommand.java new file mode 100644 index 0000000..c84f155 --- /dev/null +++ b/src/com/garbagemule/MobArena/commands/setup/RemoveLeaderboardCommand.java @@ -0,0 +1,47 @@ +package com.garbagemule.MobArena.commands.setup; + +import org.bukkit.command.CommandSender; + +import com.garbagemule.MobArena.Messenger; +import com.garbagemule.MobArena.commands.Command; +import com.garbagemule.MobArena.commands.CommandInfo; +import com.garbagemule.MobArena.framework.ArenaMaster; + +@CommandInfo( + name = "removeleaderboard", + pattern = "(del(.)*|r(e)?m(ove)?)leaderboard", + usage = "/ma removeleaderboard ", + desc = "remove the selected arena's leaderboard", + permission = "mobarena.setup.leaderboards" + ) +public class RemoveLeaderboardCommand implements Command{ + + @Override + public boolean execute(ArenaMaster am, CommandSender sender, String... args) { + // Grab the argument, if any. + String arg1 = (args.length > 0 ? args[0] : ""); + + // If no argument, use the currently selected arena + if (arg1.equals("")) { + if(am.getSelectedArena().getRegion().getLeaderboard() != null) { + am.getSelectedArena().getRegion().set("leaderboard", null); + Messenger.tellPlayer(sender, "Leaderboard for " + am.getSelectedArena().arenaName() + " successfully removed!"); + return true; + } + } + else { + if(am.getArenaWithName(arg1) != null) { + am.getArenaWithName(arg1).getRegion().set("leaderboard", null); + Messenger.tellPlayer(sender, "Leaderboard for " + am.getSelectedArena().arenaName() + " successfully removed!"); + return true; + } + else { + Messenger.tellPlayer(sender, "Usage: /ma removeleaderboard "); + return false; + } + } + + return false; + } + +} \ No newline at end of file diff --git a/src/com/garbagemule/MobArena/framework/Arena.java b/src/com/garbagemule/MobArena/framework/Arena.java index c194c69..aa1d6a1 100644 --- a/src/com/garbagemule/MobArena/framework/Arena.java +++ b/src/com/garbagemule/MobArena/framework/Arena.java @@ -48,6 +48,10 @@ public interface Arena public void setProtected(boolean value); + public boolean isLogging(); + + public void setLogging(boolean value); + public boolean isRunning(); public boolean inEditMode(); diff --git a/src/com/garbagemule/MobArena/log/YMLSessionBuilder.java b/src/com/garbagemule/MobArena/log/YMLSessionBuilder.java index 3a2b7ee..d5f2cc1 100644 --- a/src/com/garbagemule/MobArena/log/YMLSessionBuilder.java +++ b/src/com/garbagemule/MobArena/log/YMLSessionBuilder.java @@ -16,9 +16,9 @@ import com.garbagemule.MobArena.util.config.Config; public class YMLSessionBuilder implements LogSessionBuilder { - private final String GENERAL = "general-info."; - private final String PLAYERS = "players."; - private final String CLASSES = "class-distribution."; + private final String GENERAL = "general-info"; + private final String PLAYERS = "players"; + private final String CLASSES = "class-distribution"; private Config config; private long start, end; @@ -31,42 +31,42 @@ public class YMLSessionBuilder implements LogSessionBuilder @Override public void buildStartTime() { start = new Date().getTime(); - config.set(GENERAL + "start-time", TimeUtils.toDateTime(start)); + config.set(GENERAL + ".start-time", TimeUtils.toDateTime(start)); } @Override public void buildEndTime() { end = new Date().getTime(); - config.set(GENERAL + "end-time", TimeUtils.toDateTime(end)); + config.set(GENERAL + ".end-time", TimeUtils.toDateTime(end)); } @Override public void buildDuration() { String duration = TimeUtils.toTime(end - start); - config.set(GENERAL + "duration", duration); + config.set(GENERAL + ".duration", duration); } @Override public void buildLastWave(int lastWave) { - config.set(GENERAL + "last-wave", lastWave); + config.set(GENERAL + ".last-wave", lastWave); } @Override public void buildNumberOfPlayers(int amount) { - config.set(GENERAL + "number-of-players", amount); + config.set(GENERAL + ".number-of-players", amount); } @Override public void buildClassDistribution(Map classDistribution) { for (Entry entry : classDistribution.entrySet()) { int amount = entry.getValue().value(); - config.set(CLASSES + entry.getKey(), amount); + config.set(CLASSES + "." + entry.getKey(), amount); } } @Override public void buildPlayerEntry(ArenaLogPlayerEntry entry, List rewards) { - String path = PLAYERS + entry.playername + "."; + String path = PLAYERS + "." + entry.playername + "."; // Name and class config.set(path + "name", entry.playername); @@ -106,8 +106,11 @@ public class YMLSessionBuilder implements LogSessionBuilder } private void reset() { - config.set(GENERAL, null); - config.set(CLASSES, null); - config.set(PLAYERS, null); + if(config.get(GENERAL) != null) + config.set(GENERAL, null); + if(config.get(CLASSES) != null) + config.set(CLASSES, null); + if(config.get(PLAYERS) != null) + config.set(PLAYERS, null); } } diff --git a/src/com/garbagemule/MobArena/region/ArenaRegion.java b/src/com/garbagemule/MobArena/region/ArenaRegion.java index d437976..2ac74f1 100644 --- a/src/com/garbagemule/MobArena/region/ArenaRegion.java +++ b/src/com/garbagemule/MobArena/region/ArenaRegion.java @@ -7,6 +7,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.Location; import org.bukkit.World; @@ -193,7 +194,7 @@ public class ArenaRegion // Region expand public void expandUp(int amount) { - p2.setY(Math.min(127D, p2.getY() + amount)); + p2.setY(Math.min(arena.getWorld().getMaxHeight(), p2.getY() + amount)); set(RegionPoint.P2, p2); } @@ -221,7 +222,7 @@ public class ArenaRegion // Lobby expand public void expandLobbyUp(int amount) { - l2.setY(Math.min(127D, l2.getY() + amount)); + l2.setY(Math.min(arena.getWorld().getMaxHeight(), l2.getY() + amount)); set(RegionPoint.L2, l2); } diff --git a/src/com/garbagemule/MobArena/util/ItemParser.java b/src/com/garbagemule/MobArena/util/ItemParser.java index 12d45c4..5736ccb 100644 --- a/src/com/garbagemule/MobArena/util/ItemParser.java +++ b/src/com/garbagemule/MobArena/util/ItemParser.java @@ -57,12 +57,12 @@ public class ItemParser int lvl = entry.getValue(); // :; - enchantments += "; " + id + ":" + lvl; + enchantments += ";" + id + ":" + lvl; } // Trim off the leading ';' if it is there if (!enchantments.equals("")) { - enchantments = enchantments.substring(2); + enchantments = enchantments.substring(1); } // diff --git a/src/com/garbagemule/MobArena/waves/WaveParser.java b/src/com/garbagemule/MobArena/waves/WaveParser.java index 7920ee2..0bc9bf4 100644 --- a/src/com/garbagemule/MobArena/waves/WaveParser.java +++ b/src/com/garbagemule/MobArena/waves/WaveParser.java @@ -250,9 +250,9 @@ public class WaveParser } } - // As well as the ability interval. - int interval = config.getInt("ability-interval", 3) * 20; - result.setAbilityInterval(interval); + // As well as the ability interval and ability announce. + result.setAbilityInterval(config.getInt("ability-interval", 3) * 20); + result.setAbilityAnnounce(config.getBoolean("ability-announce", true)); return result; } diff --git a/src/com/garbagemule/MobArena/waves/types/BossWave.java b/src/com/garbagemule/MobArena/waves/types/BossWave.java index b9814fd..e5d6045 100644 --- a/src/com/garbagemule/MobArena/waves/types/BossWave.java +++ b/src/com/garbagemule/MobArena/waves/types/BossWave.java @@ -25,7 +25,7 @@ public class BossWave extends AbstractWave private BossHealth health; private List abilities; - private boolean activated; + private boolean activated, abilityAnnounce; private int abilityInterval; @@ -34,6 +34,7 @@ public class BossWave extends AbstractWave this.bosses = new HashSet(); this.abilities = new ArrayList(); this.activated = false; + this.abilityAnnounce = false; this.setType(WaveType.BOSS); } @@ -78,6 +79,14 @@ public class BossWave extends AbstractWave this.abilityInterval = abilityInterval; } + public boolean getAbilityAnnounce() { + return abilityAnnounce; + } + + public void setAbilityAnnounce(boolean abilityAnnounce) { + this.abilityAnnounce = abilityAnnounce; + } + public void activateAbilities(Arena arena) { if (activated) { return; @@ -89,7 +98,9 @@ public class BossWave extends AbstractWave } public void announceAbility(Ability ability, MABoss boss, Arena arena) { - AbilityInfo info = ability.getClass().getAnnotation(AbilityInfo.class); - Messenger.tellAll(arena, Msg.WAVE_BOSS_ABILITY, info.name()); + if(getAbilityAnnounce()) { + AbilityInfo info = ability.getClass().getAnnotation(AbilityInfo.class); + Messenger.tellAll(arena, Msg.WAVE_BOSS_ABILITY, info.name()); + } } }