Fixed some wolf issues

This commit is contained in:
Garbage Mule
2011-07-05 18:22:43 +02:00
parent 40e5d60335
commit 3d20364405
5 changed files with 248 additions and 72 deletions
BIN
View File
Binary file not shown.
+68 -20
View File
@@ -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<String,Location> 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,8 +236,11 @@ public class Arena
// Force leave.
for (Player p : tmp)
{
plugin.getAM().arenaMap.remove(p);
playerLeave(p);
}
}
/**
* Force an arena end by forcing all players to leave.
@@ -322,6 +323,8 @@ public class Arena
specPlayers.remove(p);
removePets(p);
if (!emptyInvJoin) MAUtils.restoreInventory(p);
if (running && livePlayers.isEmpty())
endArena();
else if (!readyPlayers.isEmpty() && readyPlayers.equals(livePlayers))
@@ -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,6 +508,7 @@ 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()
@@ -514,6 +520,8 @@ public class Arena
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,6 +738,9 @@ 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)
{
@@ -715,10 +748,20 @@ public class Arena
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<Block,Integer> blockMap = new HashMap<Block,Integer>();
@@ -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)
@@ -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;
+80 -9
View File
@@ -42,16 +42,18 @@ public class MACommands implements CommandExecutor
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("expandregion"); // Expand the region
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 <amount> [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 <amount> [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 <amount> [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.
*/
+63 -6
View File
@@ -561,6 +561,12 @@ public class MAUtils
*/
public static void sitPets(Player p)
{
if (p == null)
{
System.out.println("Player is null!");
return;
}
List<Entity> entities = p.getNearbyEntities(80, 40, 80);
for (Entity e : entities)
{
@@ -568,7 +574,7 @@ public class MAUtils
continue;
Wolf w = (Wolf) e;
if (w.getOwner().equals(p))
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<Player> 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.
*/
@@ -892,6 +943,12 @@ public class MAUtils
(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
* player if the boolean specified is true