v0.90.2 - Fixed a reward bug and added spawn-monsters=false support

This commit is contained in:
Garbage Mule 2011-06-14 16:38:25 +02:00
parent b349f84d9e
commit 729ddcdd12
7 changed files with 74 additions and 24 deletions

Binary file not shown.

View File

@ -1,6 +1,6 @@
name: MobArena
main: com.garbagemule.MobArena.MobArena
version: 0.90.1
version: 0.90.2
commands:
ma:
description: Base command for MobArena

View File

@ -36,7 +36,7 @@ public class ArenaManager
protected static boolean isProtected = true;
protected static int spawnTaskId = -1;
protected static int waveDelay, waveInterval, specialModulo, repairDelay;
protected static boolean checkUpdates, lightning;
protected static boolean checkUpdates, lightning, spawnMonsters;
// Location variables for the arena region.
protected static Location p1 = null;
@ -88,12 +88,13 @@ public class ArenaManager
if (instance != null)
{
// General variables.
config = MAUtils.getConfig();
plugin = instance;
server = plugin.getServer();
world = MAUtils.getWorld();
lightning = MAUtils.getBoolean("settings.lightning", true);
repairDelay = MAUtils.getInt("settings.repairdelay", 5);
config = MAUtils.getConfig();
plugin = instance;
server = plugin.getServer();
world = MAUtils.getWorld();
lightning = MAUtils.getBoolean("settings.lightning", true);
repairDelay = MAUtils.getInt("settings.repairdelay", 5);
spawnMonsters = MAUtils.spawnBypass(false);
// Class list and maps.
classes = MAUtils.getClasses();
@ -159,6 +160,7 @@ public class ArenaManager
{
isRunning = true;
readySet.clear();
MAUtils.spawnBypass(true);
// Clear the floor for good measure.
clearEntities();
@ -184,13 +186,13 @@ public class ArenaManager
{
isRunning = false;
server.getScheduler().cancelTask(spawnTaskId);
MAUtils.spawnBypass(true);
killMonsters();
clearBlocks();
clearEntities();
giveRewards();
// TO-DO: Fix this, maybe add a Set<Player> dead
tellAll("Arena finished.");
}
@ -502,16 +504,24 @@ public class ArenaManager
*/
public static void giveRewards()
{
for (Player p : rewardMap.keySet())
{
String r = rewardMap.get(p);
if (r.isEmpty()) continue;
tellPlayer(p, "Here are all of your rewards!");
MAUtils.giveItems(true, p, r);
}
rewardMap.clear();
/* This has to be delayed for players to actually receive
* their rewards after they die. Not sure why. */
server.getScheduler().scheduleSyncDelayedTask(plugin,
new Runnable()
{
public void run()
{
for (Player p : rewardMap.keySet())
{
String r = rewardMap.get(p);
if (r.isEmpty()) continue;
tellPlayer(p, "Here are all of your rewards!");
MAUtils.giveItems(true, p, r);
}
rewardMap.clear();
}}, 20);
}

View File

@ -14,9 +14,9 @@ import org.bukkit.event.entity.EntityDeathEvent;
* By the end of the arena session, the rewards are given.
*/
// TO-DO: Perhaps implement TeamFluff's respawn-packet-code.
public class MADamageListener extends EntityListener
public class MADeathListener extends EntityListener
{
public MADamageListener(MobArena instance)
public MADeathListener(MobArena instance)
{
}

View File

@ -31,13 +31,23 @@ public class MAMonsterListener extends EntityListener
* it's running.
*/
public void onCreatureSpawn(CreatureSpawnEvent event)
{
{
// If monster spawning is disabled, only spawn inside the region.
if (!ArenaManager.spawnMonsters)
{
if (ArenaManager.isRunning && MAUtils.inRegion(event.getLocation()))
return;
event.setCancelled(true);
}
// Otherwise, ignore spawns inside the region...
if (!MAUtils.inRegion(event.getLocation()))
return;
if (!(event.getEntity() instanceof LivingEntity))
return;
// .. And cancel those inside the region if the arena isn't running.
if (!ArenaManager.isRunning)
event.setCancelled(true);
}

View File

@ -14,6 +14,7 @@ import java.util.HashMap;
import java.util.Random;
import java.util.Iterator;
import org.bukkit.block.Sign;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.World;
import org.bukkit.Material;
import org.bukkit.Location;
@ -223,6 +224,35 @@ public class MAUtils
return ArenaManager.server.getWorld(world);
}
/**
* Handles all spawn-monster bypassing.
* If toggle is true, swap the allowMonsters field if possible. Otherwise, just
* return the current value.
*/
public static boolean spawnBypass(boolean toggle)
{
// Cast the world to an nmsWorld.
net.minecraft.server.World nmsWorld = ((CraftWorld) ArenaManager.world).getHandle();
// If not toggling, just return the current variable.
if (!toggle)
return nmsWorld.allowMonsters;
// If arena is running, allow monsters, otherwise don't.
if (ArenaManager.isRunning)
{
nmsWorld.allowMonsters = true;
nmsWorld.spawnMonsters = 1;
}
else
{
nmsWorld.allowMonsters = false;
nmsWorld.spawnMonsters = 0;
}
return true;
}
/**
* Grabs the list of classes from the config-file. If no list is
* found, generate a set of default classes.

View File

@ -49,7 +49,7 @@ public class MobArena extends JavaPlugin
PlayerListener teleportListener = new MATeleportListener(this);
PlayerListener discListener = new MADisconnectListener(this);
BlockListener blockListener = new MABlockListener(this);
EntityListener damageListener = new MADamageListener(this);
EntityListener deathListener = new MADeathListener(this);
EntityListener monsterListener = new MAMonsterListener(this);
// TO-DO: PlayerListener to check for kills/deaths.
@ -64,7 +64,7 @@ public class MobArena extends JavaPlugin
pm.registerEvent(Event.Type.PLAYER_JOIN, discListener, Priority.Normal, this);
pm.registerEvent(Event.Type.BLOCK_BREAK, blockListener, Priority.Normal, this);
pm.registerEvent(Event.Type.BLOCK_PLACE, blockListener, Priority.Normal, this);
pm.registerEvent(Event.Type.ENTITY_DEATH, damageListener, Priority.Normal, this);
pm.registerEvent(Event.Type.ENTITY_DEATH, deathListener, Priority.Normal, this);
pm.registerEvent(Event.Type.ENTITY_EXPLODE, monsterListener, Priority.Normal, this);
pm.registerEvent(Event.Type.ENTITY_COMBUST, monsterListener, Priority.Normal, this);
pm.registerEvent(Event.Type.ENTITY_TARGET, monsterListener, Priority.Normal, this);