diff --git a/MobArena.jar b/MobArena.jar index b40653c..771f73d 100644 Binary files a/MobArena.jar and b/MobArena.jar differ diff --git a/bin/plugin.yml b/bin/plugin.yml index 2f3713e..0699f68 100644 --- a/bin/plugin.yml +++ b/bin/plugin.yml @@ -1,6 +1,6 @@ name: MobArena main: com.garbagemule.MobArena.MobArena -version: 0.90.2 +version: 0.91 softdepend: [MultiVerse] commands: ma: diff --git a/src/com/garbagemule/MobArena/ArenaManager.java b/src/com/garbagemule/MobArena/ArenaManager.java index 970f230..9e1242c 100644 --- a/src/com/garbagemule/MobArena/ArenaManager.java +++ b/src/com/garbagemule/MobArena/ArenaManager.java @@ -34,9 +34,12 @@ public class ArenaManager protected static boolean isSetup = false; protected static boolean isEnabled = true; protected static boolean isProtected = true; + protected static int wave = 0; protected static int spawnTaskId = -1; protected static int waveDelay, waveInterval, specialModulo, repairDelay; protected static boolean checkUpdates, lightning, spawnMonsters; + protected static int spawnMonstersInt; + protected static MASpawnThread spawnThread = null; // Location variables for the arena region. protected static Location p1 = null; @@ -71,6 +74,9 @@ public class ArenaManager protected static Set monsterSet = new HashSet(); protected static Set blockSet = new HashSet(); + // Hook listeners + protected static Set listeners = new HashSet(); + /* ///////////////////////////////////////////////////////////////////// // @@ -171,10 +177,13 @@ public class ArenaManager rewardMap.put(p,""); } - MASpawnThread thread = new MASpawnThread(); - spawnTaskId = server.getScheduler().scheduleSyncRepeatingTask(plugin,thread,(long)waveDelay,(long)waveInterval); + spawnThread = new MASpawnThread(); + spawnTaskId = server.getScheduler().scheduleSyncRepeatingTask(plugin,spawnThread,(long)waveDelay,(long)waveInterval); tellAll("Let the slaughter begin!"); + + for (MobArenaListener m : listeners) + m.onArenaStart(); } /** @@ -185,6 +194,7 @@ public class ArenaManager public static void endArena() { isRunning = false; + wave = 0; server.getScheduler().cancelTask(spawnTaskId); MAUtils.spawnBypass(true); @@ -194,6 +204,9 @@ public class ArenaManager giveRewards(); tellAll("Arena finished."); + + for (MobArenaListener m : listeners) + m.onArenaEnd(); } /** @@ -239,6 +252,9 @@ public class ArenaManager p.teleport(lobbyLoc); tellPlayer(p, "You joined the arena. Have fun!"); + + for (MobArenaListener m : listeners) + m.onPlayerJoin(p); } /** @@ -270,6 +286,9 @@ public class ArenaManager startArena(); tellPlayer(p, "You left the arena. Thanks for playing!"); + + for (MobArenaListener m : listeners) + m.onPlayerLeave(p); } /** @@ -302,6 +321,9 @@ public class ArenaManager if (isRunning && playerSet.isEmpty()) endArena(); + + for (MobArenaListener m : listeners) + m.onPlayerDeath(p); } /** diff --git a/src/com/garbagemule/MobArena/MASpawnThread.java b/src/com/garbagemule/MobArena/MASpawnThread.java index 2a4e01e..d0d25fb 100644 --- a/src/com/garbagemule/MobArena/MASpawnThread.java +++ b/src/com/garbagemule/MobArena/MASpawnThread.java @@ -92,14 +92,19 @@ public class MASpawnThread implements Runnable if (wave % modulo == 0) { ArenaManager.tellAll("Get ready for wave #" + wave + "! [SPECIAL]"); + for (MobArenaListener m : ArenaManager.listeners) + m.onSpecialWave(wave, wave/modulo); specialWave(); } else { ArenaManager.tellAll("Get ready for wave #" + wave + "!"); + for (MobArenaListener m : ArenaManager.listeners) + m.onDefaultWave(wave); defaultWave(); } - + + ArenaManager.wave = wave; wave++; } diff --git a/src/com/garbagemule/MobArena/MAUtils.java b/src/com/garbagemule/MobArena/MAUtils.java index 47cfc2a..b3b795f 100644 --- a/src/com/garbagemule/MobArena/MAUtils.java +++ b/src/com/garbagemule/MobArena/MAUtils.java @@ -236,7 +236,10 @@ public class MAUtils // If not toggling, just return the current variable. if (!toggle) + { + ArenaManager.spawnMonstersInt = nmsWorld.spawnMonsters; return nmsWorld.allowMonsters; + } // If arena is running, allow monsters, otherwise don't. if (ArenaManager.isRunning) @@ -247,7 +250,7 @@ public class MAUtils else { nmsWorld.allowMonsters = false; - nmsWorld.spawnMonsters = 0; + nmsWorld.spawnMonsters = ArenaManager.spawnMonstersInt; } return true; diff --git a/src/com/garbagemule/MobArena/MobArena.java b/src/com/garbagemule/MobArena/MobArena.java index 0f11d5d..7a52fba 100644 --- a/src/com/garbagemule/MobArena/MobArena.java +++ b/src/com/garbagemule/MobArena/MobArena.java @@ -1,6 +1,8 @@ package com.garbagemule.MobArena; import java.util.List; + +import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.bukkit.event.Event.Priority; import org.bukkit.event.block.BlockListener; @@ -41,6 +43,8 @@ public class MobArena extends JavaPlugin getCommand("ma").setExecutor(new MACommands()); getCommand("marena").setExecutor(new MACommands()); getCommand("mobarena").setExecutor(new MACommands()); + + // Create event listeners. PluginManager pm = getServer().getPluginManager(); @@ -79,4 +83,9 @@ public class MobArena extends JavaPlugin ArenaManager.forceEnd(null); } + + public boolean isPlaying(Player p) + { + return ArenaManager.playerSet.contains(p); + } } \ No newline at end of file diff --git a/src/com/garbagemule/MobArena/MobArenaHandler.java b/src/com/garbagemule/MobArena/MobArenaHandler.java new file mode 100644 index 0000000..9cd0701 --- /dev/null +++ b/src/com/garbagemule/MobArena/MobArenaHandler.java @@ -0,0 +1,31 @@ +package com.garbagemule.MobArena; + +import java.util.List; +import java.util.LinkedList; + +import org.bukkit.Location; +import org.bukkit.entity.Player; + +public class MobArenaHandler +{ + public MobArenaHandler() + { + } + + // Check if there is an active arena session running. + public boolean isRunning() { return ArenaManager.isRunning; } + + // Check if the specified player is in the arena/lobby. + public boolean isPlaying(Player p) { return ArenaManager.playerSet.contains(p); } + + // Get a list of all players currently in the arena. + public List getPlayers() { return new LinkedList(ArenaManager.playerSet); } + + // Get the warp locations. + public Location getArenaLocation() { return ArenaManager.arenaLoc; } + public Location getLobbyLocation() { return ArenaManager.lobbyLoc; } + public Location getSpectatorLocation() { return ArenaManager.spectatorLoc; } + + // Get the current wave number. + public int getWave() { return ArenaManager.wave; } +} diff --git a/src/com/garbagemule/MobArena/MobArenaListener.java b/src/com/garbagemule/MobArena/MobArenaListener.java new file mode 100644 index 0000000..a71e8bf --- /dev/null +++ b/src/com/garbagemule/MobArena/MobArenaListener.java @@ -0,0 +1,22 @@ +package com.garbagemule.MobArena; + +import org.bukkit.entity.Player; + +public class MobArenaListener +{ + protected MobArena plugin; + + public MobArenaListener() + { + plugin = ArenaManager.plugin; + ArenaManager.listeners.add(this); + } + + public void onArenaStart() {} + public void onArenaEnd() {} + public void onDefaultWave(int waveNumber) {} + public void onSpecialWave(int waveNumber, int specialwaveNumber) {} + public void onPlayerJoin(Player p) {} + public void onPlayerLeave(Player p) {} + public void onPlayerDeath(Player p) {} +}