v0.91 - Added API and fixed a few bugs.

This commit is contained in:
Garbage Mule 2011-06-15 02:35:22 +02:00
parent e2ee975336
commit 9a1b90fe53
8 changed files with 97 additions and 5 deletions

Binary file not shown.

View File

@ -1,6 +1,6 @@
name: MobArena
main: com.garbagemule.MobArena.MobArena
version: 0.90.2
version: 0.91
softdepend: [MultiVerse]
commands:
ma:

View File

@ -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<LivingEntity> monsterSet = new HashSet<LivingEntity>();
protected static Set<Block> blockSet = new HashSet<Block>();
// Hook listeners
protected static Set<MobArenaListener> listeners = new HashSet<MobArenaListener>();
/* ///////////////////////////////////////////////////////////////////// //
@ -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);
}
/**

View File

@ -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++;
}

View File

@ -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;

View File

@ -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);
}
}

View File

@ -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<Player> getPlayers() { return new LinkedList<Player>(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; }
}

View File

@ -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) {}
}