diff --git a/MobArena.jar b/MobArena.jar index 2794e4c..cb17fa2 100644 Binary files a/MobArena.jar and b/MobArena.jar differ diff --git a/bin/plugin.yml b/bin/plugin.yml index ac7e7e5..5cefa3d 100644 --- a/bin/plugin.yml +++ b/bin/plugin.yml @@ -1,6 +1,6 @@ name: MobArena main: com.garbagemule.MobArena.MobArena -version: 0.67 +version: 0.81 commands: marena: description: Base command for MobArena diff --git a/src/com/garbagemule/MobArena/ArenaManager.java b/src/com/garbagemule/MobArena/ArenaManager.java index f3e38ed..2f279fc 100644 --- a/src/com/garbagemule/MobArena/ArenaManager.java +++ b/src/com/garbagemule/MobArena/ArenaManager.java @@ -225,6 +225,9 @@ public class ArenaManager if (playerSet.contains(p)) playerSet.remove(p); + + if (readySet.contains(p)) + readySet.remove(p); if (classMap.keySet().contains(p)) classMap.remove(p); diff --git a/src/com/garbagemule/MobArena/EntityPosition.java b/src/com/garbagemule/MobArena/EntityPosition.java new file mode 100644 index 0000000..d2fdd63 --- /dev/null +++ b/src/com/garbagemule/MobArena/EntityPosition.java @@ -0,0 +1,88 @@ +package com.garbagemule.MobArena; + +import java.io.Serializable; +import org.bukkit.Location; +import org.bukkit.World; + +/** + * NOTE: I (garbagemule) DID NOT WRITE THIS CLASS (notice the author below) + * @author creadri + */ +public class EntityPosition implements Serializable{ + private double x; + private double y; + private double z; + private String world; + private float yaw; + private float pitch; + + public EntityPosition(double x, double y, double z, String world, float yaw, float pitch) { + this.x = x; + this.y = y; + this.z = z; + this.world = world; + this.yaw = yaw; + this.pitch = pitch; + } + + public EntityPosition(Location location) { + this.x = location.getX(); + this.y = location.getY(); + this.z = location.getZ(); + this.world = location.getWorld().getName(); + this.yaw = location.getYaw(); + this.pitch = location.getPitch(); + } + + public Location getLocation(World world) { + return new Location(world, x, y, z, yaw, pitch); + } + + public float getPitch() { + return pitch; + } + + public void setPitch(float pitch) { + this.pitch = pitch; + } + + public String getWorld() { + return world; + } + + public void setWorld(String world) { + this.world = world; + } + + public double getX() { + return x; + } + + public void setX(double x) { + this.x = x; + } + + public double getY() { + return y; + } + + public void setY(double y) { + this.y = y; + } + + public float getYaw() { + return yaw; + } + + public void setYaw(float yaw) { + this.yaw = yaw; + } + + public double getZ() { + return z; + } + + public void setZ(double z) { + this.z = z; + } +} \ No newline at end of file diff --git a/src/com/garbagemule/MobArena/MACommands.java b/src/com/garbagemule/MobArena/MACommands.java index ffd8b17..bae3b2d 100644 --- a/src/com/garbagemule/MobArena/MACommands.java +++ b/src/com/garbagemule/MobArena/MACommands.java @@ -200,6 +200,48 @@ public class MACommands implements CommandExecutor return true; } + // ma dooooo it hippie monster + if (cmd.equals("dooooo")) + { + if (args.length != 4) + return false; + /* + if (!args[4].matches("[0-9]+")) + return false; + + int radius = Integer.parseInt(args[4]); + if (radius < 5) + { + ArenaManager.tellPlayer(p, "You don't want an arena that small..."); + return true; + } + else if (radius > 10) + { + ArenaManager.tellPlayer(p, "If you want a bigger arena, build it yourself >:O"); + return true; + } + */ + if (args[1].equals("it") && args[2].equals("hippie") && args[3].equals("monster")) + { + MAUtils.DoooooItHippieMonster(p.getLocation(), 10); + ArenaManager.tellPlayer(p, "Auto-generated a working MobArena!"); + return true; + } + } + + if (cmd.equals("undo")) + { + if (args.length != 4) + return false; + + if (args[1].equals("it") && args[2].equals("hippie") && args[3].equals("monster")) + { + MAUtils.UnDoooooItHippieMonster(); + ArenaManager.tellPlayer(p, "Restored your precious little patch >_>"); + return true; + } + } + return false; } } \ No newline at end of file diff --git a/src/com/garbagemule/MobArena/MADamageListener.java b/src/com/garbagemule/MobArena/MADamageListener.java index 06e17da..bb2b2fa 100644 --- a/src/com/garbagemule/MobArena/MADamageListener.java +++ b/src/com/garbagemule/MobArena/MADamageListener.java @@ -39,6 +39,7 @@ public class MADamageListener extends EntityListener return; event.setCancelled(true); + p.setFireTicks(0); ArenaManager.playerDeath(p); } } \ No newline at end of file diff --git a/src/com/garbagemule/MobArena/MAMonsterListener.java b/src/com/garbagemule/MobArena/MAMonsterListener.java index b4b878d..3b71af3 100644 --- a/src/com/garbagemule/MobArena/MAMonsterListener.java +++ b/src/com/garbagemule/MobArena/MAMonsterListener.java @@ -1,8 +1,8 @@ package com.garbagemule.MobArena; import java.util.HashMap; +import org.bukkit.Material; import org.bukkit.block.Block; -import org.bukkit.entity.Spider; import org.bukkit.event.entity.EntityListener; import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntityCombustEvent; @@ -37,7 +37,10 @@ public class MAMonsterListener extends EntityListener final HashMap blockMap = new HashMap(); for (Block b : event.blockList()) { - blockMap.put(b, b.getTypeId()); + if (b.getType() == Material.CAKE_BLOCK) + blockMap.put(b, 0); + else + blockMap.put(b, b.getTypeId()); } // Wait a couple of ticks, then rebuild the blocks. @@ -51,7 +54,7 @@ public class MAMonsterListener extends EntityListener b.getLocation().getBlock().setTypeId(blockMap.get(b)); } } - }, 3); + }, 5); } } diff --git a/src/com/garbagemule/MobArena/MASpawnThread.java b/src/com/garbagemule/MobArena/MASpawnThread.java index 58f3947..58c32c5 100644 --- a/src/com/garbagemule/MobArena/MASpawnThread.java +++ b/src/com/garbagemule/MobArena/MASpawnThread.java @@ -9,6 +9,8 @@ import org.bukkit.entity.Player; import org.bukkit.entity.Creature; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.CreatureType; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; /** * Core class for handling wave spawning. @@ -47,8 +49,7 @@ public class MASpawnThread implements Runnable } public void run() - { - long start = System.nanoTime(); + { // Check if we need to grant more rewards with the recurrent waves. for (Integer i : ArenaManager.everyWaveMap.keySet()) { @@ -56,7 +57,7 @@ public class MASpawnThread implements Runnable continue; for (Player p : ArenaManager.playerSet) - { + { currentRewards = ArenaManager.rewardMap.get(p); reward = MAUtils.getRandomReward(ArenaManager.everyWaveMap.get(i)); currentRewards += reward + ","; @@ -92,7 +93,6 @@ public class MASpawnThread implements Runnable } wave++; - System.out.println("Spawns and rewards took " + (System.nanoTime() - start) + " ns"); } /** @@ -124,9 +124,10 @@ public class MASpawnThread implements Runnable ArenaManager.monsterSet.add(e); // Grab a random target. - ran = random.nextInt(noOfPlayers); - Creature c = (Creature) e; - c.setTarget(MAUtils.getRandomPlayer()); + // TO-DO: Find a different solution to this. + //ran = random.nextInt(noOfPlayers); + //Creature c = (Creature) e; + //c.setTarget(MAUtils.getRandomPlayer()); //c.setTarget((Player)playerArray[ran]); // This is faster, but unstable } } @@ -189,13 +190,13 @@ public class MASpawnThread implements Runnable if (wolf) ((Wolf)e).setAngry(true); // Slimes can't have targets, apparently. - if (!(e instanceof Creature)) - continue; + //if (!(e instanceof Creature)) + // continue; // Grab a random target. - ran = random.nextInt(noOfPlayers); - Creature c = (Creature) e; - c.setTarget(MAUtils.getRandomPlayer()); + //ran = random.nextInt(noOfPlayers); + //Creature c = (Creature) e; + //c.setTarget(MAUtils.getRandomPlayer()); //c.setTarget((Player)playerArray[ran]); // This is faster, but unstable } diff --git a/src/com/garbagemule/MobArena/MAUtils.java b/src/com/garbagemule/MobArena/MAUtils.java index 18ef44d..bd1ea93 100644 --- a/src/com/garbagemule/MobArena/MAUtils.java +++ b/src/com/garbagemule/MobArena/MAUtils.java @@ -5,11 +5,14 @@ import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; +import java.util.Arrays; import java.util.List; import java.util.LinkedList; import java.util.Map; import java.util.HashMap; import java.util.Random; +import org.bukkit.block.Sign; +import org.bukkit.block.BlockFace; import org.bukkit.World; import org.bukkit.Material; import org.bukkit.Location; @@ -20,6 +23,13 @@ import org.bukkit.util.config.Configuration; public class MAUtils { + public static final int[] SWORDS_ID = {267,268,272,276,283}; + public static final Material[] SWORDS_TYPE = {Material.WOOD_SWORD, + Material.STONE_SWORD, + Material.GOLD_SWORD, + Material.IRON_SWORD, + Material.DIAMOND_SWORD}; + /* ///////////////////////////////////////////////////////////////////// // INVENTORY AND REWARD METHODS @@ -90,11 +100,15 @@ public class MAUtils { id = Integer.parseInt(item[0]); stack = new ItemStack(id, amount); + if (Arrays.asList(SWORDS_ID).contains(id)) + stack.setDurability((short)-3276); } else { stack = makeItemStack(item[0], amount); if (stack == null) continue; + if (Arrays.asList(SWORDS_TYPE).contains(stack.getType())) + stack.setDurability((short)-3276); } // Put the item in the first empty inventory slot. @@ -504,4 +518,185 @@ public class MAUtils Object[] array = ArenaManager.playerSet.toArray(); return (Player) array[random.nextInt(array.length)]; } + + /** + * Stand back, I'm going to try science! + */ + public static void DoooooItHippieMonster(Location loc, int radius) + { + // Get the hippie bounds. + int x1 = (int)loc.getX() - radius; + int x2 = (int)loc.getX() + radius; + int y1 = (int)loc.getY() - 8; + int y2 = (int)loc.getY() - 1; + int z1 = (int)loc.getZ() - radius; + int z2 = (int)loc.getZ() + radius; + + int lx1 = x1; + int lx2 = x1 + ArenaManager.classes.size() + 3; + int ly1 = y1-5; + int ly2 = y1-1; + int lz1 = z1; + int lz2 = z1 + 6; + + // Save the precious patch + HashMap preciousPatch = new HashMap(); + Location lo; + int id; + for (int i = x1; i <= x2; i++) + { + for (int j = ly1; j <= y2; j++) + { + for (int k = z1; k <= z2; k++) + { + lo = ArenaManager.world.getBlockAt(i,j,k).getLocation(); + id = ArenaManager.world.getBlockAt(i,j,k).getTypeId(); + preciousPatch.put(new EntityPosition(lo),id); + } + } + } + try + { + FileOutputStream fos = new FileOutputStream("plugins/MobArena/precious.tmp"); + ObjectOutputStream oos = new ObjectOutputStream(fos); + oos.writeObject(preciousPatch); + oos.close(); + } + catch (Exception e) + { + System.out.println("Couldn't create backup file. Aborting..."); + e.printStackTrace(); + return; + } + + // Build some monster walls. + for (int i = x1; i <= x2; i++) + { + for (int j = y1; j <= y2; j++) + { + ArenaManager.world.getBlockAt(i,j,z1).setTypeId(5); + ArenaManager.world.getBlockAt(i,j,z2).setTypeId(5); + } + } + for (int k = z1; k <= z2; k++) + { + for (int j = y1; j <= y2; j++) + { + ArenaManager.world.getBlockAt(x1,j,k).setTypeId(5); + ArenaManager.world.getBlockAt(x2,j,k).setTypeId(5); + } + } + + // Add some hippie light. + for (int i = x1; i <= x2; i++) + { + ArenaManager.world.getBlockAt(i,y1+2,z1).setTypeId(89); + ArenaManager.world.getBlockAt(i,y1+2,z2).setTypeId(89); + } + for (int k = z1; k <= z2; k++) + { + ArenaManager.world.getBlockAt(x1,y1+2,k).setTypeId(89); + ArenaManager.world.getBlockAt(x2,y1+2,k).setTypeId(89); + } + + // Build a monster floor. + for (int i = x1; i <= x2; i++) + { + for (int k = z1; k <= z2; k++) + ArenaManager.world.getBlockAt(i,y1,k).setTypeId(5); + } + + // Make a hippie roof. + for (int i = x1; i <= x2; i++) + { + for (int k = z1; k <= z2; k++) + ArenaManager.world.getBlockAt(i,y2,k).setTypeId(20); + } + + // Monster bulldoze + for (int i = x1+1; i < x2; i++) + for (int j = y1+1; j < y2; j++) + for (int k = z1+1; k < z2; k++) + ArenaManager.world.getBlockAt(i,j,k).setTypeId(0); + + // Build a hippie lobby + for (int i = lx1; i <= lx2; i++) // Walls + { + for (int j = ly1; j <= ly2; j++) + { + ArenaManager.world.getBlockAt(i,j,lz1).setTypeId(24); + ArenaManager.world.getBlockAt(i,j,lz2).setTypeId(24); + } + } + for (int k = lz1; k <= lz2; k++) // Walls + { + for (int j = ly1; j <= ly2; j++) + { + ArenaManager.world.getBlockAt(lx1,j,k).setTypeId(24); + ArenaManager.world.getBlockAt(lx2,j,k).setTypeId(24); + } + } + for (int k = lz1; k <= lz2; k++) // Lights + { + ArenaManager.world.getBlockAt(lx1,ly1+2,k).setTypeId(89); + ArenaManager.world.getBlockAt(lx2,ly1+2,k).setTypeId(89); + ArenaManager.world.getBlockAt(lx1,ly1+3,k).setTypeId(89); + ArenaManager.world.getBlockAt(lx2,ly1+3,k).setTypeId(89); + } + for (int i = lx1; i <= lx2; i++) // Floor + { + for (int k = lz1; k <= lz2; k++) + ArenaManager.world.getBlockAt(i,ly1,k).setTypeId(24); + } + for (int i = x1+1; i < lx2; i++) // Bulldoze + for (int j = ly1+1; j <= ly2; j++) + for (int k = lz1+1; k < lz2; k++) + ArenaManager.world.getBlockAt(i,j,k).setTypeId(0); + + // Place the hippie signs + java.util.Iterator iterator = ArenaManager.classes.iterator(); + for (int i = lx1+2; i <= lx2-2; i++) // Signs + { + ArenaManager.world.getBlockAt(i,ly1+1,lz2-1).setTypeIdAndData(63, (byte)0x8, false); + Sign sign = (Sign) ArenaManager.world.getBlockAt(i,ly1+1,lz2-1).getState(); + sign.setLine(0, (String)iterator.next()); + } + ArenaManager.world.getBlockAt(lx2-2,ly1+1,lz1+2).setType(Material.IRON_BLOCK); + + // Set up the monster points. + setCoords("arena", new Location(ArenaManager.world, loc.getX(), y1+1, loc.getZ())); + setCoords("lobby", new Location(ArenaManager.world, x1+2, y1-3, z1+2)); + setCoords("spectator", new Location(ArenaManager.world, loc.getX(), y2+1, loc.getZ())); + setCoords("p1", new Location(ArenaManager.world, x1, y1-4, z1)); + setCoords("p2", new Location(ArenaManager.world, x2, y2, z2)); + setCoords("spawnpoints.s1", new Location(ArenaManager.world, x1+3, y1+2, z1+3)); + setCoords("spawnpoints.s2", new Location(ArenaManager.world, x1+3, y1+2, z2-3)); + setCoords("spawnpoints.s3", new Location(ArenaManager.world, x2-3, y1+2, z1+3)); + setCoords("spawnpoints.s4", new Location(ArenaManager.world, x2-3, y1+2, z2-3)); + } + + public static void UnDoooooItHippieMonster() + { + HashMap preciousPatch; + try + { + FileInputStream fis = new FileInputStream("plugins/MobArena/precious.tmp"); + ObjectInputStream ois = new ObjectInputStream(fis); + preciousPatch = (HashMap) ois.readObject(); + ois.close(); + } + catch (Exception e) + { + System.out.println("Couldn't find backup file..."); + e.printStackTrace(); + return; + } + + for (EntityPosition ep : preciousPatch.keySet()) + { + ArenaManager.world.getBlockAt(ep.getLocation(ArenaManager.world)).setTypeId(preciousPatch.get(ep)); + } + + delCoords("coords"); + } } \ No newline at end of file