diff --git a/MobArena.jar b/MobArena.jar index b3b1b8d..a5ecf5b 100644 Binary files a/MobArena.jar and b/MobArena.jar differ diff --git a/src/com/garbagemule/MobArena/Arena.java b/src/com/garbagemule/MobArena/Arena.java index d85ffa5..221f703 100644 --- a/src/com/garbagemule/MobArena/Arena.java +++ b/src/com/garbagemule/MobArena/Arena.java @@ -62,9 +62,9 @@ public class Arena // Setup fields protected String name; protected World world; - protected boolean enabled, running, setup, protect, autoEquip, forceRestore, softRestore, softRestoreDrops, emptyInvJoin, emptyInvSpec, pvp, monsterInfight, allowWarp; + protected boolean enabled, running, setup, lobbySetup, protect, autoEquip, forceRestore, softRestore, softRestoreDrops, emptyInvJoin, emptyInvSpec, pvp, monsterInfight, allowWarp; protected boolean edit, waveClear, detCreepers, detDamage, lightning, hellhounds; - protected Location p1, p2, arenaLoc, lobbyLoc, spectatorLoc; + protected Location p1, p2, l1, l2, arenaLoc, lobbyLoc, spectatorLoc; protected Map spawnpoints; // Wave/reward fields @@ -127,8 +127,6 @@ public class Arena public Arena(String name, World world, ArenaMaster am) { this(name, world); - //classItems = am.classItems; - //classArmor = am.classArmor; } public void startArena() @@ -238,7 +236,10 @@ public class Arena // Force leave. for (Player p : tmp) + { + plugin.getAM().arenaMap.remove(p); playerLeave(p); + } } /** @@ -321,6 +322,8 @@ public class Arena deadPlayers.remove(p); specPlayers.remove(p); removePets(p); + + if (!emptyInvJoin) MAUtils.restoreInventory(p); if (running && livePlayers.isEmpty()) endArena(); @@ -492,6 +495,8 @@ public class Arena p1 = MAUtils.getArenaCoord(config, world, configName, "p1"); p2 = MAUtils.getArenaCoord(config, world, configName, "p2"); + l1 = MAUtils.getArenaCoord(config, world, configName, "l1"); + l2 = MAUtils.getArenaCoord(config, world, configName, "l2"); arenaLoc = MAUtils.getArenaCoord(config, world, configName, "arena"); lobbyLoc = MAUtils.getArenaCoord(config, world, configName, "lobby"); spectatorLoc = MAUtils.getArenaCoord(config, world, configName, "spectator"); @@ -503,17 +508,20 @@ public class Arena // Determine if the arena is properly set up. Then add the to arena list. setup = MAUtils.verifyData(this); + lobbySetup = MAUtils.verifyLobby(this); } public void serializeConfig() { - String coords = "arenas." + configName() + ".coords."; + String coords = "arenas." + configName() + ".coords."; Configuration config = plugin.getConfig(); config.setProperty("arenas." + configName() + ".settings.enabled", enabled); config.setProperty("arenas." + configName() + ".settings.protect", protect); if (p1 != null) config.setProperty(coords + "p1", MAUtils.makeCoord(p1)); if (p2 != null) config.setProperty(coords + "p2", MAUtils.makeCoord(p2)); + if (l1 != null) config.setProperty(coords + "l1", MAUtils.makeCoord(l1)); + if (l2 != null) config.setProperty(coords + "l2", MAUtils.makeCoord(l2)); if (arenaLoc != null) config.setProperty(coords + "arena", MAUtils.makeCoord(arenaLoc)); if (lobbyLoc != null) config.setProperty(coords + "lobby", MAUtils.makeCoord(lobbyLoc)); if (spectatorLoc != null) config.setProperty(coords + "spectator", MAUtils.makeCoord(spectatorLoc)); @@ -612,16 +620,26 @@ public class Arena */ public boolean inRegion(Location loc) { - if (!loc.getWorld().getName().equals(world.getName())) + if (!loc.getWorld().getName().equals(world.getName()) || !setup) return false; - if (!setup) - return false; + int x = loc.getBlockX(); + int y = loc.getBlockY(); + int z = loc.getBlockZ(); + + // Check the lobby first. + if (lobbySetup) + { + if ((x >= l1.getBlockX() && x <= l2.getBlockX()) && + (z >= l1.getBlockZ() && z <= l2.getBlockZ()) && + (y >= l1.getBlockY() && y <= l2.getBlockY())) + return true; + } // Returns false if the location is outside of the region. - return ((loc.getX() >= p1.getX() && loc.getX() <= p2.getX()) && - (loc.getZ() >= p1.getZ() && loc.getZ() <= p2.getZ()) && - (loc.getY() >= p1.getY() && loc.getY() <= p2.getY())); + return ((x >= p1.getBlockX() && x <= p2.getBlockX()) && + (z >= p1.getBlockZ() && z <= p2.getBlockZ()) && + (y >= p1.getBlockY() && y <= p2.getBlockY())); } /** @@ -633,9 +651,22 @@ public class Arena if (!loc.getWorld().getName().equals(world.getName()) || !setup) return false; - return ((loc.getX() + radius >= p1.getX() && loc.getX() - radius <= p2.getX()) && - (loc.getZ() + radius >= p1.getZ() && loc.getZ() - radius <= p2.getZ()) && - (loc.getY() + radius >= p1.getY() && loc.getY() - radius <= p2.getY())); + int x = loc.getBlockX(); + int y = loc.getBlockY(); + int z = loc.getBlockZ(); + + // Check the lobby first. + if (lobbySetup) + { + if ((x + radius >= l1.getBlockX() && x - radius <= l2.getBlockX()) && + (z + radius >= l1.getBlockZ() && z - radius <= l2.getBlockZ()) && + (y + radius >= l1.getBlockY() && y - radius <= l2.getBlockY())) + return true; + } + + return ((x + radius >= p1.getBlockX() && x - radius <= p2.getBlockX()) && + (z + radius >= p1.getBlockZ() && z - radius <= p2.getBlockZ()) && + (y + radius >= p1.getBlockY() && y - radius <= p2.getBlockY())); } @@ -649,14 +680,14 @@ public class Arena // Block Listener public void onBlockBreak(BlockBreakEvent event) { - if (edit || !inRegion(event.getBlock().getLocation())) + if (!inRegion(event.getBlock().getLocation()) || edit) return; Block b = event.getBlock(); if (blocks.remove(b) || b.getType() == Material.TNT) return; - if (softRestore) + if (softRestore && running) { int[] buffer = new int[5]; buffer[0] = b.getX(); @@ -674,8 +705,7 @@ public class Arena public void onBlockPlace(BlockPlaceEvent event) { - // If in edit mode or the event didn't happen in this region, return. - if (edit || !inRegion(event.getBlock().getLocation())) + if (!inRegion(event.getBlock().getLocation()) || edit) return; Block b = event.getBlock(); @@ -708,17 +738,30 @@ public class Arena if (!monsters.contains(event.getEntity()) && !inRegionRadius(event.getLocation(), 10)) return; + event.setYield(0); + monsters.remove(event.getEntity()); + // If the arena isn't running if (!running || repairDelay == 0) { event.setCancelled(true); return; } + + // If there is a sign in the blocklist, cancel + for (Block b : event.blockList()) + { + if (!(b.getType() == Material.SIGN_POST || b.getType() == Material.WALL_SIGN)) + { + continue; + } + + event.setCancelled(true); + return; + } // Uncancel, just in case. event.setCancelled(false); - event.setYield(0); - monsters.remove(event.getEntity()); int[] buffer; final HashMap blockMap = new HashMap(); @@ -784,7 +827,7 @@ public class Arena if (!running) return; if (pets.contains(event.getEntity())) - { + { if (event.getReason() != TargetReason.TARGET_ATTACKED_OWNER && event.getReason() != TargetReason.OWNER_ATTACKED_TARGET) return; @@ -870,6 +913,8 @@ public class Arena damagee.setFireTicks(32768); // For mcMMO event.setCancelled(true); } + if (e != null && damager instanceof Player) + event.setCancelled(true); event.setDamage(0); return; @@ -919,7 +964,7 @@ public class Arena if (running) return; Player p = event.getPlayer(); - if (!inRegion(p.getLocation()) || !livePlayers.contains(p)) + if (!livePlayers.contains(p)) return; MAUtils.tellPlayer(p, MAMessages.get(Msg.LOBBY_DROP_ITEM)); @@ -1156,7 +1201,10 @@ public class Arena // Compare the current size with the previous size. if (monsters.size() < spawnThread.previousSize || spawnThread.previousSize == 0) + { + resetIdleTimer(); return; + } // Clear all player inventories, and "kill" all players. for (Player p : livePlayers) diff --git a/src/com/garbagemule/MobArena/ArenaMaster.java b/src/com/garbagemule/MobArena/ArenaMaster.java index cbfbd07..6e50b7b 100644 --- a/src/com/garbagemule/MobArena/ArenaMaster.java +++ b/src/com/garbagemule/MobArena/ArenaMaster.java @@ -20,7 +20,7 @@ public class ArenaMaster private MobArena plugin; private Configuration config; protected Arena selectedArena; - protected Lobby masterLobby; + //protected Lobby masterLobby; // Settings protected boolean enabled, updateNotify, autoEquip, emptyInvs, hellhounds; diff --git a/src/com/garbagemule/MobArena/MACommands.java b/src/com/garbagemule/MobArena/MACommands.java index 6a6439a..ea39a23 100644 --- a/src/com/garbagemule/MobArena/MACommands.java +++ b/src/com/garbagemule/MobArena/MACommands.java @@ -20,38 +20,40 @@ public class MACommands implements CommandExecutor public static final List COMMANDS = new LinkedList(); static { - COMMANDS.add("j"); // Join - COMMANDS.add("join"); // Join - COMMANDS.add("l"); // Leave - COMMANDS.add("leave"); // Leave - COMMANDS.add("notready"); // List of players who aren't ready - COMMANDS.add("spec"); // Watch arena - COMMANDS.add("spectate"); // Watch arena - COMMANDS.add("arenas"); // List of arenas - COMMANDS.add("list"); // List of players - COMMANDS.add("players"); // List of players - COMMANDS.add("restore"); // Restore inventory - COMMANDS.add("enable"); // Enabling - COMMANDS.add("disable"); // Disabling - COMMANDS.add("protect"); // Protection on/off - COMMANDS.add("force"); // Force start/end - COMMANDS.add("config"); // Reload config - COMMANDS.add("arena"); // Current arena - COMMANDS.add("setarena"); // Set current arena - COMMANDS.add("addarena"); // Add a new arena - COMMANDS.add("delarena"); // Delete current aren - COMMANDS.add("editarena"); // Editing - COMMANDS.add("setregion"); // Set a region point - COMMANDS.add("setwarp"); // Set arena/lobby/spec - COMMANDS.add("spawnpoints"); // List spawnpoints - COMMANDS.add("addspawn"); // Add a spawnpoint - COMMANDS.add("delspawn"); // Delete a spawnpoint - COMMANDS.add("expandregion"); // Expand the region - COMMANDS.add("reset"); // Reset arena coordinates - COMMANDS.add("auto-generate"); // Auto-generate arena - COMMANDS.add("auto-degenerate"); // Restore cuboid + COMMANDS.add("j"); // Join + COMMANDS.add("join"); // Join + COMMANDS.add("l"); // Leave + COMMANDS.add("leave"); // Leave + COMMANDS.add("notready"); // List of players who aren't ready + COMMANDS.add("spec"); // Watch arena + COMMANDS.add("spectate"); // Watch arena + COMMANDS.add("arenas"); // List of arenas + COMMANDS.add("list"); // List of players + COMMANDS.add("players"); // List of players + COMMANDS.add("restore"); // Restore inventory + COMMANDS.add("enable"); // Enabling + COMMANDS.add("disable"); // Disabling + COMMANDS.add("protect"); // Protection on/off + COMMANDS.add("force"); // Force start/end + COMMANDS.add("config"); // Reload config + COMMANDS.add("arena"); // Current arena + COMMANDS.add("setarena"); // Set current arena + COMMANDS.add("addarena"); // Add a new arena + COMMANDS.add("delarena"); // Delete current aren + COMMANDS.add("editarena"); // Editing + COMMANDS.add("setregion"); // Set a region point + COMMANDS.add("expandregion"); // Expand the region + COMMANDS.add("setlobbyregion"); // Set a region point + COMMANDS.add("expandlobbyregion"); // Expand the region + COMMANDS.add("setwarp"); // Set arena/lobby/spec + COMMANDS.add("spawnpoints"); // List spawnpoints + COMMANDS.add("addspawn"); // Add a spawnpoint + COMMANDS.add("delspawn"); // Delete a spawnpoint + COMMANDS.add("reset"); // Reset arena coordinates + COMMANDS.add("auto-generate"); // Auto-generate arena + COMMANDS.add("auto-degenerate"); // Restore cuboid } - private boolean player, op, console, meanAdmins; + private boolean meanAdmins; private Server server; private MobArena plugin; private ArenaMaster am; @@ -80,9 +82,9 @@ public class MACommands implements CommandExecutor } // Determine if the sender is a player (and an op), or the console. - player = (sender instanceof Player); - op = player && ((Player) sender).isOp(); - console = (sender instanceof ConsoleCommandSender); + boolean player = (sender instanceof Player); + boolean op = player && ((Player) sender).isOp(); + boolean console = (sender instanceof ConsoleCommandSender); // Cast the sender to Player if possible. Player p = (player) ? (Player)sender : null; @@ -306,14 +308,14 @@ public class MACommands implements CommandExecutor return true; } - String list = MAUtils.listToString(arena.getLivingPlayers()); + String list = MAUtils.playerListToString(arena.getLivingPlayers()); MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_LIST_PLAYERS, list)); } else { StringBuffer buffy = new StringBuffer(); for (Arena arena : am.arenas) - buffy.append(MAUtils.listToString(arena.getLivingPlayers(), false)); + buffy.append(MAUtils.playerListToString(arena.getLivingPlayers())); MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_LIST_PLAYERS, buffy.toString())); } return true; @@ -349,7 +351,7 @@ public class MACommands implements CommandExecutor return true; } - String list = MAUtils.listToString(arena.getNonreadyPlayers()); + String list = MAUtils.playerListToString(arena.getNonreadyPlayers()); MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_LIST_PLAYERS, list)); return true; } @@ -454,7 +456,7 @@ public class MACommands implements CommandExecutor /* * Force start/end arenas. */ - if (base.equals("force") && arg1.equals("end")) + if (base.equals("force")) { if (arg1.equals("end")) { @@ -737,6 +739,11 @@ public class MACommands implements CommandExecutor MAUtils.tellPlayer(sender, "Usage: /ma expandregion [up|down|out]"); return true; } + if (am.selectedArena.p1 == null || am.selectedArena.p2 == null) + { + MAUtils.tellPlayer(sender, "You must first define p1 and p2"); + return true; + } if (arg2.equals("up")) { @@ -765,6 +772,70 @@ public class MACommands implements CommandExecutor return true; } + if (base.equals("setlobbyregion")) + { + if (!(player && MobArena.has(p, "mobarena.setup.setlobbyregion")) && !op) + { + MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS)); + return true; + } + + if (!(arg1.equals("l1") || arg1.equals("l2"))) + { + MAUtils.tellPlayer(sender, "Usage: /ma setlobbyregion [l1|l2]"); + return true; + } + + MAUtils.setArenaCoord(plugin.getConfig(), am.selectedArena, arg1, p.getLocation()); + MAUtils.tellPlayer(sender, "Set lobby point " + arg1 + " for arena '" + am.selectedArena.configName() + "'"); + return true; + } + + if (base.equals("expandlobbyregion")) + { + if (!console && !(player && MobArena.has(p, "mobarena.setup.expandlobbyregion")) && !op) + { + MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS)); + return true; + } + if (args.length != 3 || !arg1.matches("[0-9]+")) + { + MAUtils.tellPlayer(sender, "Usage: /ma expandlobbyregion [up|down|out]"); + return true; + } + if (am.selectedArena.l1 == null || am.selectedArena.l2 == null) + { + MAUtils.tellPlayer(sender, "You must first define l1 and l2"); + return true; + } + + if (arg2.equals("up")) + { + am.selectedArena.l2.setY(Math.min(127, am.selectedArena.l2.getY() + Integer.parseInt(arg1))); + } + else if (arg2.equals("down")) + { + am.selectedArena.l1.setY(Math.max(0, am.selectedArena.l1.getY() - Integer.parseInt(arg1))); + } + else if (arg2.equals("out")) + { + am.selectedArena.l1.setX(am.selectedArena.l1.getX() - Integer.parseInt(arg1)); + am.selectedArena.l1.setZ(am.selectedArena.l1.getZ() - Integer.parseInt(arg1)); + am.selectedArena.l2.setX(am.selectedArena.l2.getX() + Integer.parseInt(arg1)); + am.selectedArena.l2.setZ(am.selectedArena.l2.getZ() + Integer.parseInt(arg1)); + } + else + { + MAUtils.tellPlayer(sender, "Usage: /ma expandlobbyregion [up|down|out]"); + return true; + } + + MAUtils.tellPlayer(sender, "Lobby region for '" + am.selectedArena.configName() + "' expanded " + arg2 + " by " + arg1 + " blocks."); + am.selectedArena.serializeConfig(); + am.selectedArena.load(plugin.getConfig()); + return true; + } + /* * Set warp points [arena|lobby|spectator] for the current arena. */ diff --git a/src/com/garbagemule/MobArena/MAUtils.java b/src/com/garbagemule/MobArena/MAUtils.java index 04b3a41..c54283e 100644 --- a/src/com/garbagemule/MobArena/MAUtils.java +++ b/src/com/garbagemule/MobArena/MAUtils.java @@ -261,11 +261,11 @@ public class MAUtils { config.setProperty(arenaPath + ".powered-creepers", 10); config.setProperty(arenaPath + ".zombie-pigmen", 10); - config.setProperty(arenaPath + ".slimes", 10); - config.setProperty(arenaPath + ".humans", 10); + config.setProperty(arenaPath + ".slimes", 10); + config.setProperty(arenaPath + ".humans", 10); config.setProperty(arenaPath + ".angry-wolves", 10); - config.setProperty(arenaPath + ".giants", 0); - config.setProperty(arenaPath + ".ghasts", 0); + config.setProperty(arenaPath + ".giants", 0); + config.setProperty(arenaPath + ".ghasts", 0); } //config.save(); dists = config.getKeys(arenaPath); @@ -561,14 +561,20 @@ public class MAUtils */ public static void sitPets(Player p) { + if (p == null) + { + System.out.println("Player is null!"); + return; + } + List entities = p.getNearbyEntities(80, 40, 80); for (Entity e : entities) { if (!(e instanceof Wolf)) continue; - Wolf w = (Wolf) e; - if (w.getOwner().equals(p)) + Wolf w = (Wolf) e; + if (w.isTamed() && w.getOwner() != null && w.getOwner().equals(p)) w.setSitting(true); } } @@ -616,6 +622,8 @@ public class MAUtils if (coord.equals("p1") || coord.equals("p2")) fixRegion(config, loc.getWorld(), arena); + if (coord.equals("l1") || coord.equals("l2")) + fixLobby(config, loc.getWorld(), arena); } public static boolean delArenaCoord(Configuration config, Arena arena, String coord) @@ -658,6 +666,35 @@ public class MAUtils arena.load(config); } + private static void fixLobby(Configuration config, World world, Arena arena) + { + if (arena.l1 == null || arena.l2 == null) + return; + + if (arena.l1.getX() > arena.l2.getX()) + { + double tmp = arena.l1.getX(); + arena.l1.setX(arena.l2.getX()); + arena.l2.setX(tmp); + } + + if (arena.l1.getZ() > arena.l2.getZ()) + { + double tmp = arena.l1.getZ(); + arena.l1.setZ(arena.l2.getZ()); + arena.l2.setZ(tmp); + } + + if (arena.l1.getY() > arena.l2.getY()) + { + double tmp = arena.l1.getY(); + arena.l1.setY(arena.l2.getY()); + arena.l2.setY(tmp); + } + arena.serializeConfig(); + arena.load(config); + } + /** * Create a Location from the input String in the input World. */ @@ -665,14 +702,14 @@ public class MAUtils { String[] parts = str.split(","); - double x = Double.parseDouble(parts[0]); - double y = Double.parseDouble(parts[1]); - double z = Double.parseDouble(parts[2]); + double x = Double.parseDouble(parts[0].trim()); + double y = Double.parseDouble(parts[1].trim()); + double z = Double.parseDouble(parts[2].trim()); if (extras && parts.length == 5) { - float yaw = Float.parseFloat(parts[3]); - float pitch = Float.parseFloat(parts[4]); + float yaw = Float.parseFloat(parts[3].trim()); + float pitch = Float.parseFloat(parts[4].trim()); return new Location(world, x, y, z, yaw, pitch); } @@ -850,6 +887,20 @@ public class MAUtils return buffy.toString(); } + public static String playerListToString(List list) + { + if (list.isEmpty()) + return MAMessages.get(Msg.MISC_NONE); + + StringBuffer buffy = new StringBuffer(); + for (Player p : list) + { + buffy.append(p.getName()); + buffy.append(" "); + } + return buffy.toString(); + } + /** * Returns a String-list version of a comma-separated list. */ @@ -891,6 +942,12 @@ public class MAUtils (arena.p2 != null) && (arena.spawnpoints.size() > 0)); } + + public static boolean verifyLobby(Arena arena) + { + return ((arena.l1 != null) && + (arena.l2 != null)); + } /** * Checks if there is a new update of MobArena and notifies the