Exploding sheep a la Notch-code.

This commit is contained in:
Andreas Troelsen 2011-08-09 19:33:08 +02:00
parent 07c6d5a178
commit 6791f40da4
24 changed files with 656 additions and 426 deletions

Binary file not shown.

View File

@ -3,24 +3,17 @@ main: com.garbagemule.MobArena.MobArena
version: 0.93.4
softdepend: [Permissions,MultiVerse,XcraftGate,Towny]
commands:
ma:
description: Base command for MobArena
usage: |
/ma join - Join the arena.
/ma leave - Leave the arena.
/ma notready - List of players who aren't ready.
/ma spectate - Warp to the spectator area.
marena:
description: Base command for MobArena
usage: |
/marena join - Join the arena.
/marena leave - Leave the arena.
/marena notready - List of players who aren't ready.
/marena spectate - Warp to the spectator area.
mobarena:
description: Base command for MobArena
usage: |
/mobarena join - Join the arena.
/mobarena leave - Leave the arena.
/mobarena notready - List of players who aren't ready.
/mobarena spectate - Warp to the spectator area.
ma:
description: Base command for MobArena
usage: |
/ma join - Join the arena.
/ma leave - Leave the arena.
/ma notready - List of players who aren't ready.
/ma spectate - Warp to the spectator area.
mobarena:
description: Base command for MobArena
usage: |
/mobarena join - Join the arena.
/mobarena leave - Leave the arena.
/mobarena notready - List of players who aren't ready.
/mobarena spectate - Warp to the spectator area.

View File

@ -11,6 +11,13 @@ public abstract class AbstractArena
*/
public abstract void startArena();
/**
* Stop the arena session.
* Distribute rewards, clean up arena floor and reset everything to how it was before
* the arena session was started, false otherwise
*/
public abstract void endArena();
/**
* Force the arena to start.
* If some players are ready, this method will force all non-ready players to leave,
@ -19,13 +26,6 @@ public abstract class AbstractArena
*/
public abstract boolean forceStart();
/**
* Stop the arena session.
* Distribute rewards, clean up arena floor and reset everything to how it was before
* the arena session was started, false otherwise
*/
public abstract void endArena();
/**
* Force the arena to end.
* Returns all players to their entry locations, distributes rewards, cleans the arena
@ -93,15 +93,15 @@ public abstract class AbstractArena
*/
public abstract boolean isEnabled();
/**
* Check if the arena is running.
* @return true, if the arena is running.
*/
public abstract boolean isRunning();
/**
* Check if the arena is set up and ready for use.
* @return true, if the arena is ready for use.
*/
public abstract boolean isSetup();
/**
* Check if the arena is running.
* @return true, if the arena is running.
*/
public abstract boolean isRunning();
}

View File

@ -15,6 +15,8 @@ import java.util.Random;
import java.util.Set;
import java.util.TreeSet;
import net.minecraft.server.WorldServer;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Chunk;
@ -23,6 +25,8 @@ import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.entity.CraftEntity;
import org.bukkit.entity.Creature;
import org.bukkit.entity.CreatureType;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Item;
@ -55,7 +59,7 @@ public class Arena
protected String logging;
// Wave/reward/entryfee fields
protected int spawnTaskId, waveDelay, waveInterval, specialModulo, spawnMonstersInt, maxIdleTime;
protected int spawnTaskId, sheepTaskId, waveDelay, waveInterval, specialModulo, spawnMonstersInt, maxIdleTime;
protected MASpawnThread spawnThread;
protected Map<Integer,List<ItemStack>> everyWaveMap, afterWaveMap;
protected Map<String,Integer> distDefault, distSpecial;
@ -174,6 +178,7 @@ public class Arena
// Start spawning monsters.
startSpawning();
startBouncingSheep();
// Start logging
log = new ArenaLog(plugin, this);
@ -183,7 +188,7 @@ public class Arena
running = true;
// Announce and notify.
MAUtils.tellAll(this, MAMessages.get(Msg.ARENA_START));
MAUtils.tellAll(this, Msg.ARENA_START.get());
for (MobArenaListener listener : plugin.getAM().listeners)
listener.onArenaStart();
@ -221,7 +226,7 @@ public class Arena
deserializeRegion();
// Announce and clear sets.
MAUtils.tellAll(this, MAMessages.get(Msg.ARENA_END), true);
MAUtils.tellAll(this, Msg.ARENA_END.get(), true);
arenaPlayers.clear();
notifyPlayers.clear();
rewardedPlayers.clear();
@ -254,8 +259,9 @@ public class Arena
}
public void forceEnd()
{
{
Bukkit.getServer().getScheduler().cancelTask(spawnTaskId);
Bukkit.getServer().getScheduler().cancelTask(sheepTaskId);
for (Player p : getAllPlayers())
playerLeave(p);
@ -271,8 +277,9 @@ public class Arena
readyPlayers.clear();
cleanup();
spawnTaskId = -1;
sheepTaskId = -1;
}
public void playerJoin(Player p, Location loc)
@ -289,7 +296,7 @@ public class Arena
if (minPlayers > 0 && lobbyPlayers.size() < minPlayers)
{
MAUtils.tellPlayer(p, MAMessages.get(Msg.LOBBY_NOT_ENOUGH_PLAYERS, "" + minPlayers));
MAUtils.tellPlayer(p, Msg.LOBBY_NOT_ENOUGH_PLAYERS, "" + minPlayers);
return;
}
@ -298,10 +305,10 @@ public class Arena
public void playerLeave(Player p)
{
if (arenaPlayers.contains(p))
if (arenaPlayers.contains(p) || lobbyPlayers.contains(p))
finishArenaPlayer(p);
else if (lobbyPlayers.contains(p))
MAUtils.clearInventory(p);
//else if (lobbyPlayers.contains(p))
// MAUtils.clearInventory(p);
movePlayerToEntry(p);
discardPlayer(p);
@ -326,7 +333,7 @@ public class Arena
if (running && spawnThread != null)
spawnThread.updateTargets();
MAUtils.tellAll(this, MAMessages.get(Msg.PLAYER_DIED, p.getName()));
MAUtils.tellAll(this, Msg.PLAYER_DIED.get(p.getName()));
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { public void run() {
endArena();
}});
@ -378,7 +385,9 @@ public class Arena
{
Bukkit.getServer().getScheduler().cancelTask(spawnThread.getTaskId());
Bukkit.getServer().getScheduler().cancelTask(spawnTaskId);
Bukkit.getServer().getScheduler().cancelTask(sheepTaskId);
spawnTaskId = -1;
sheepTaskId = -1;
spawnThread = null;
}
@ -386,6 +395,40 @@ public class Arena
MAUtils.setSpawnFlags(plugin, world, spawnMonsters, allowMonsters, allowAnimals);
}
private void startBouncingSheep()
{
sheepTaskId = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(plugin,
new Runnable()
{
public void run()
{
if (explodingSheep.isEmpty()) return;
for (LivingEntity e : new LinkedList<LivingEntity>(explodingSheep))
{
Creature c = (Creature) e;
if (c.getTarget() != null && e.getLocation().distanceSquared(c.getTarget().getLocation()) < 8)
{
CraftEntity ce = (CraftEntity) e;
CraftWorld cw = (CraftWorld) e.getWorld();
WorldServer ws = cw.getHandle();
ws.createExplosion(ce.getHandle(), e.getLocation().getX(), e.getLocation().getY() + 1, e.getLocation().getZ(), 2f, false);
e.remove();
}
if (e.isDead())
{
explodingSheep.remove(e);
continue;
}
if (Math.abs(e.getVelocity().getY()) < 1)
e.setVelocity(e.getVelocity().setY(0.5));
}
}
}, waveDelay, 20);
}
private void updateChunk(Location loc)
{
if (!arenaPlayers.isEmpty() || !world.getName().equals(loc.getWorld().getName()))
@ -502,7 +545,7 @@ public class Arena
MAUtils.clearInventory(p);
restoreInvAndGiveRewards(p);
if (log != null)
if (log != null && spawnThread != null)
log.players.get(p).lastWave = spawnThread.getWave() - 1;
}
@ -554,7 +597,7 @@ public class Arena
}
assignClass(p, className);
MAUtils.tellPlayer(p, MAMessages.get(Msg.LOBBY_CLASS_PICKED, className));
MAUtils.tellPlayer(p, Msg.LOBBY_CLASS_PICKED, className);
}
private void cleanup()
@ -615,6 +658,7 @@ public class Arena
private void removeEntities()
{
if (p1 == null || p2 == null) return;
Chunk c1 = world.getChunkAt(p1);
Chunk c2 = world.getChunkAt(p2);
@ -687,7 +731,7 @@ public class Arena
singleWaves = WaveUtils.getWaves(this, config, WaveBranch.SINGLE);
recurrentWaves = WaveUtils.getWaves(this, config, WaveBranch.RECURRENT);
/*
System.out.println();
System.out.println("ARENA: " + configName);
System.out.println("- Single waves");
@ -697,7 +741,7 @@ public class Arena
for (Wave w : recurrentWaves)
System.out.println(" - " + w);
System.out.println();
*/
classes = plugin.getAM().classes;
classItems = plugin.getAM().classItems;
@ -937,6 +981,11 @@ public class Arena
monsters.add(e);
}
public void addExplodingSheep(LivingEntity e)
{
explodingSheep.add(e);
}
public List<Player> getAllPlayers()
{
List<Player> result = new LinkedList<Player>();
@ -961,13 +1010,21 @@ public class Arena
return result;
}
public Set<LivingEntity> getMonsters()
{
Set<LivingEntity> tmp = new HashSet<LivingEntity>(monsters);
tmp.addAll(explodingSheep);
return tmp;
}
public void resetIdleTimer()
{
if (maxIdleTime <= 0 || !running)
return;
// Reset the previousSize, cancel the previous timer, and start the new timer.
spawnThread.setPreviousSize(monsters.size());
//spawnThread.setPreviousSize(monsters.size());
spawnThread.setPreviousSize(getMonsters().size());
Bukkit.getServer().getScheduler().cancelTask(spawnThread.getTaskId());
int id = Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin,
new Runnable()
@ -992,7 +1049,7 @@ public class Arena
for (Player p : ps)
{
MAUtils.clearInventory(p);
MAUtils.tellPlayer(p, MAMessages.get(Msg.FORCE_END_IDLE));
MAUtils.tellPlayer(p, Msg.FORCE_END_IDLE);
playerDeath(p);
}
}
@ -1101,6 +1158,54 @@ public class Arena
MAUtils.giveItems(p, entryFee, false, plugin);
hasPaid.remove(p);
}
public boolean canJoin(Player p)
{
if (!enabled)
MAUtils.tellPlayer(p, Msg.JOIN_ARENA_NOT_ENABLED);
else if (!setup || recurrentWaves.isEmpty())
MAUtils.tellPlayer(p, Msg.JOIN_ARENA_NOT_SETUP);
else if (edit)
MAUtils.tellPlayer(p, Msg.JOIN_ARENA_EDIT_MODE);
else if (running && (notifyPlayers.contains(p) || notifyPlayers.add(p)))
MAUtils.tellPlayer(p, Msg.JOIN_ARENA_IS_RUNNING);
else if (arenaPlayers.contains(p) || lobbyPlayers.contains(p))
MAUtils.tellPlayer(p, Msg.JOIN_ALREADY_PLAYING);
else if (!plugin.has(p, "mobarena.arenas." + configName()))
MAUtils.tellPlayer(p, Msg.JOIN_ARENA_PERMISSION);
else if (maxPlayers > 0 && lobbyPlayers.size() >= maxPlayers)
MAUtils.tellPlayer(p, Msg.JOIN_PLAYER_LIMIT_REACHED);
else if (joinDistance > 0 && !inRegionRadius(p.getLocation(), joinDistance))
MAUtils.tellPlayer(p, Msg.JOIN_TOO_FAR);
else if (!canAfford(p) || !takeFee(p))
MAUtils.tellPlayer(p, Msg.JOIN_FEE_REQUIRED, MAUtils.listToString(entryFee, plugin));
else if (emptyInvJoin && !MAUtils.hasEmptyInventory(p))
MAUtils.tellPlayer(p, Msg.JOIN_EMPTY_INV);
else if (!emptyInvJoin && !MAUtils.storeInventory(p))
MAUtils.tellPlayer(p, Msg.JOIN_STORE_INV_FAIL);
else return true;
return false;
}
public boolean canSpec(Player p)
{
if (!enabled)
MAUtils.tellPlayer(p, Msg.JOIN_ARENA_NOT_ENABLED);
else if (!setup)
MAUtils.tellPlayer(p, Msg.JOIN_ARENA_NOT_SETUP);
else if (edit)
MAUtils.tellPlayer(p, Msg.JOIN_ARENA_EDIT_MODE);
else if (arenaPlayers.contains(p) || lobbyPlayers.contains(p))
MAUtils.tellPlayer(p, Msg.SPEC_ALREADY_PLAYING);
else if (emptyInvSpec && !MAUtils.hasEmptyInventory(p))
MAUtils.tellPlayer(p, Msg.SPEC_EMPTY_INV);
else if (joinDistance > 0 && !inRegionRadius(p.getLocation(), joinDistance))
MAUtils.tellPlayer(p, Msg.JOIN_TOO_FAR);
else return true;
return false;
}
/**
* The "perfect equals method" cf. "Object-Oriented Design and Patterns"

View File

@ -13,6 +13,7 @@ import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.permissions.Permission;
import org.bukkit.util.config.Configuration;
public class ArenaMaster
@ -69,6 +70,15 @@ public class ArenaMaster
return result;
}
public List<Arena> getPermittedArenas(Player p)
{
List<Arena> result = new LinkedList<Arena>();
for (Arena arena : arenas)
if (plugin.has(p, "mobarena.arenas." + arena.configName()))
result.add(arena);
return result;
}
public Arena getArenaAtLocation(Location loc)
{
for (Arena arena : arenas)
@ -222,7 +232,7 @@ public class ArenaMaster
if (config.getKeys("arenas") == null)
createArenaNode("default", Bukkit.getServer().getWorlds().get(0));
for (String configName : config.getKeys("arenas"))
{
String arenaPath = "arenas." + configName + ".";

View File

@ -59,6 +59,7 @@ public class MACommands implements CommandExecutor
COMMANDS.add("reset"); // Reset arena coordinates
COMMANDS.add("addclass"); // Add a new class
COMMANDS.add("delclass"); // Delete a class
COMMANDS.add("checkdata"); // Check arena well formedness
COMMANDS.add("auto-generate"); // Auto-generate arena
COMMANDS.add("auto-degenerate"); // Restore cuboid
COMMANDS.add("lol");
@ -128,63 +129,27 @@ public class MACommands implements CommandExecutor
{
if (!player || !plugin.has(p, "mobarena.use.join"))
{
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS));
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
return true;
}
List<Arena> arenas = am.getEnabledArenas();
if (!am.enabled || arenas.size() < 1)
{
MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_NOT_ENABLED));
MAUtils.tellPlayer(p, Msg.JOIN_NOT_ENABLED);
return true;
}
boolean error;
Arena arena;
if (!arg1.isEmpty())
arena = am.getArenaWithName(arg1);
else if (arenas.size() == 1)
arena = arenas.get(0);
else
arena = null;
// Grab the arena to join
Arena arena = arenas.size() == 1 ? arenas.get(0) : am.getArenaWithName(arg1);
if (arenas.size() > 1 && arg1.isEmpty())
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_ARG_NEEDED));
else if (arena == null)
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.ARENA_DOES_NOT_EXIST));
else if (am.arenaMap.containsKey(p) && (am.arenaMap.get(p).arenaPlayers.contains(p) || am.arenaMap.get(p).lobbyPlayers.contains(p)))
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_IN_OTHER_ARENA));
else if (!arena.enabled)
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_ARENA_NOT_ENABLED));
else if (!arena.setup || arena.recurrentWaves.isEmpty())
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_ARENA_NOT_SETUP));
else if (arena.edit)
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_ARENA_EDIT_MODE));
else if (arena.running && (arena.notifyPlayers.contains(p) || arena.notifyPlayers.add(p)))
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_ARENA_IS_RUNNING));
else if (arena.arenaPlayers.contains(p))
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_ALREADY_PLAYING));
else if (!plugin.has(p, "mobarena.arenas." + arena.configName()))
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_ARENA_PERMISSION));
else if (arena.maxPlayers > 0 && arena.lobbyPlayers.size() >= arena.maxPlayers)
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_PLAYER_LIMIT_REACHED));
else if (arena.joinDistance > 0 && !arena.inRegionRadius(p.getLocation(), arena.joinDistance))
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_TOO_FAR));
else if (!arena.canAfford(p) || !arena.takeFee(p))
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_FEE_REQUIRED, MAUtils.listToString(arena.entryFee, plugin)));
else if (arena.emptyInvJoin && !MAUtils.hasEmptyInventory(p))
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_EMPTY_INV));
else if (!arena.emptyInvJoin && !MAUtils.storeInventory(p))
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_STORE_INV_FAIL));
else error = false;
// If there was an error, don't join.
if (error)
{
if (arena != null)
arena.refund(p);
// Run a couple of basic sanity checks
if (!sanityChecks(p, arena, arg1, arenas))
return true;
// Run a bunch of per-arena sanity checks
if (!arena.canJoin(p))
return true;
}
// If player is in a boat/minecart, eject!
if (p.isInsideVehicle())
@ -197,12 +162,12 @@ public class MACommands implements CommandExecutor
return true;
}
//am.arenaMap.put(p,arena);
// Join the arena!
arena.playerJoin(p, p.getLocation());
MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_PLAYER_JOINED));
MAUtils.tellPlayer(p, Msg.JOIN_PLAYER_JOINED);
if (!arena.entryFee.isEmpty())
MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_FEE_PAID, MAUtils.listToString(arena.entryFee, plugin)));
MAUtils.tellPlayer(p, Msg.JOIN_FEE_PAID.get(MAUtils.listToString(arena.entryFee, plugin)));
if (arena.hasPaid.contains(p))
arena.hasPaid.remove(p);
@ -216,7 +181,7 @@ public class MACommands implements CommandExecutor
{
if (!player || !plugin.has(p, "mobarena.use.leave"))
{
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS));
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
return true;
}
@ -226,17 +191,17 @@ public class MACommands implements CommandExecutor
if (arena != null)
{
arena.playerLeave(p);
MAUtils.tellPlayer(p, MAMessages.get(Msg.LEAVE_PLAYER_LEFT));
MAUtils.tellPlayer(p, Msg.LEAVE_PLAYER_LEFT);
return true;
}
MAUtils.tellPlayer(p, MAMessages.get(Msg.LEAVE_NOT_PLAYING));
MAUtils.tellPlayer(p, Msg.LEAVE_NOT_PLAYING);
return true;
}
Arena arena = am.arenaMap.get(p);
arena.playerLeave(p);
MAUtils.tellPlayer(p, MAMessages.get(Msg.LEAVE_PLAYER_LEFT));
MAUtils.tellPlayer(p, Msg.LEAVE_PLAYER_LEFT);
return true;
}
@ -247,58 +212,42 @@ public class MACommands implements CommandExecutor
{
if (!player || !plugin.has(p, "mobarena.use.spectate"))
{
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS));
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
return true;
}
List<Arena> arenas = am.getEnabledArenas();
if (!am.enabled || arenas.size() < 1)
{
MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_NOT_ENABLED));
MAUtils.tellPlayer(p, Msg.JOIN_NOT_ENABLED);
return true;
}
boolean error;
Arena arena;
if (!arg1.isEmpty())
arena = am.getArenaWithName(arg1);
else if (arenas.size() == 1)
arena = arenas.get(0);
else
arena = null;
if (arenas.size() > 1 && arg1.isEmpty())
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_ARG_NEEDED));
else if (arena == null)
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.ARENA_DOES_NOT_EXIST));
//else if (am.arenaMap.containsKey(p) && am.arenaMap.get(p).livePlayers.contains(p))
else if (am.arenaMap.containsKey(p) && (am.arenaMap.get(p).arenaPlayers.contains(p) || am.arenaMap.get(p).lobbyPlayers.contains(p)))
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_IN_OTHER_ARENA));
else if (!arena.enabled)
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_ARENA_NOT_ENABLED));
else if (!arena.setup || arena.edit)
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_ARENA_NOT_SETUP));
//else if (arena.livePlayers.contains(p))
else if (arena.arenaPlayers.contains(p))
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.SPEC_ALREADY_PLAYING));
else if (arena.emptyInvSpec && !MAUtils.hasEmptyInventory(p))
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.SPEC_EMPTY_INV));
else if (arena.joinDistance > 0 && !arena.inRegionRadius(p.getLocation(), arena.joinDistance))
error = MAUtils.tellPlayer(p, MAMessages.get(Msg.JOIN_TOO_FAR));
else error = false;
// If there was an error, don't spec.
if (error)
// Grab the arena to join
Arena arena = arenas.size() == 1 ? arenas.get(0) : am.getArenaWithName(arg1);
// Run a couple of basic sanity checks
if (!sanityChecks(p, arena, arg1, arenas))
return true;
// Run a bunch of arena-specific sanity-checks
if (!arena.canSpec(p))
return true;
// If player is in a boat/minecart, eject!
if (p.isInsideVehicle())
p.leaveVehicle();
am.arenaMap.put(p,arena);
// If player is in a bed, unbed!
if (p.isSleeping())
{
p.kickPlayer("Banned for life... Nah, just don't join from a bed ;)");
return true;
}
// Spectate the arena!
arena.playerSpec(p, p.getLocation());
MAUtils.tellPlayer(p, MAMessages.get(Msg.SPEC_PLAYER_SPECTATE));
MAUtils.tellPlayer(p, Msg.SPEC_PLAYER_SPECTATE);
return true;
}
@ -307,8 +256,8 @@ public class MACommands implements CommandExecutor
*/
if (base.equals("arenas"))
{
String list = MAUtils.listToString(am.arenas, plugin);
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_LIST_ARENAS, list));
String list = MAUtils.listToString(player ? am.getPermittedArenas(p) : am.arenas, plugin);
MAUtils.tellPlayer(sender, Msg.MISC_LIST_ARENAS.get(list));
return true;
}
@ -322,12 +271,12 @@ public class MACommands implements CommandExecutor
Arena arena = am.getArenaWithName(arg1);
if (arena == null)
{
MAUtils.tellPlayer(sender, MAMessages.get(Msg.ARENA_DOES_NOT_EXIST));
MAUtils.tellPlayer(sender, Msg.ARENA_DOES_NOT_EXIST);
return true;
}
String list = MAUtils.listToString(arena.getLivingPlayers(), plugin);
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_LIST_PLAYERS, list));
MAUtils.tellPlayer(sender, Msg.MISC_LIST_PLAYERS.get(list));
}
else
{
@ -336,7 +285,7 @@ public class MACommands implements CommandExecutor
for (Arena arena : am.arenas)
players.addAll(arena.getLivingPlayers());
buffy.append(MAUtils.listToString(players, plugin));
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_LIST_PLAYERS, buffy.toString()));
MAUtils.tellPlayer(sender, Msg.MISC_LIST_PLAYERS.get(buffy.toString()));
}
return true;
}
@ -352,7 +301,7 @@ public class MACommands implements CommandExecutor
arena = am.getArenaWithName(arg1);
if (arena == null)
{
MAUtils.tellPlayer(sender, MAMessages.get(Msg.ARENA_DOES_NOT_EXIST));
MAUtils.tellPlayer(sender, Msg.ARENA_DOES_NOT_EXIST);
return true;
}
}
@ -361,7 +310,7 @@ public class MACommands implements CommandExecutor
arena = am.getArenaWithPlayer(p);
if (arena == null)
{
MAUtils.tellPlayer(sender, MAMessages.get(Msg.LEAVE_NOT_PLAYING));
MAUtils.tellPlayer(sender, Msg.LEAVE_NOT_PLAYING);
return true;
}
}
@ -372,7 +321,7 @@ public class MACommands implements CommandExecutor
}
String list = MAUtils.listToString(arena.getNonreadyPlayers(), plugin);
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_LIST_PLAYERS, list));
MAUtils.tellPlayer(sender, Msg.MISC_LIST_PLAYERS.get(list));
return true;
}
@ -391,7 +340,7 @@ public class MACommands implements CommandExecutor
{
if (!console && !(player && plugin.has(p, "mobarena.admin.enable")) && !op)
{
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS));
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
return true;
}
@ -406,7 +355,7 @@ public class MACommands implements CommandExecutor
}
else
{
MAUtils.tellPlayer(sender, MAMessages.get(Msg.ARENA_DOES_NOT_EXIST));
MAUtils.tellPlayer(sender, Msg.ARENA_DOES_NOT_EXIST);
}
}
else
@ -425,7 +374,7 @@ public class MACommands implements CommandExecutor
{
if (!console && !(player && plugin.has(p, "mobarena.admin.kick")) && !op)
{
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS));
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
return true;
}
@ -459,7 +408,7 @@ public class MACommands implements CommandExecutor
{
if (!console && !(player && plugin.has(p, "mobarena.admin.restore")) && !op)
{
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS));
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
return true;
}
@ -486,7 +435,7 @@ public class MACommands implements CommandExecutor
{
if (!console && !(player && plugin.has(p, "mobarena.admin.force.end")) && !op)
{
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS));
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
return true;
}
@ -502,25 +451,25 @@ public class MACommands implements CommandExecutor
Arena arena = am.getArenaWithName(arg2);
if (arena == null)
{
MAUtils.tellPlayer(sender, MAMessages.get(Msg.ARENA_DOES_NOT_EXIST));
MAUtils.tellPlayer(sender, Msg.ARENA_DOES_NOT_EXIST);
return true;
}
if (arena.getAllPlayers().isEmpty())
{
MAUtils.tellPlayer(sender, MAMessages.get(Msg.FORCE_END_EMPTY));
MAUtils.tellPlayer(sender, Msg.FORCE_END_EMPTY);
return true;
}
arena.forceEnd();
MAUtils.tellPlayer(sender, MAMessages.get(Msg.FORCE_END_ENDED));
MAUtils.tellPlayer(sender, Msg.FORCE_END_ENDED);
return true;
}
else if (arg1.equals("start"))
{
if (!console && !(player && plugin.has(p, "mobarena.admin.force.start")) && !op)
{
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS));
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
return true;
}
@ -533,23 +482,23 @@ public class MACommands implements CommandExecutor
Arena arena = am.getArenaWithName(arg2);
if (arena == null)
{
MAUtils.tellPlayer(sender, MAMessages.get(Msg.ARENA_DOES_NOT_EXIST));
MAUtils.tellPlayer(sender, Msg.ARENA_DOES_NOT_EXIST);
return true;
}
if (arena.running)
{
MAUtils.tellPlayer(sender, MAMessages.get(Msg.FORCE_START_RUNNING));
MAUtils.tellPlayer(sender, Msg.FORCE_START_RUNNING);
return true;
}
if (arena.readyPlayers.isEmpty())
{
MAUtils.tellPlayer(sender, MAMessages.get(Msg.FORCE_START_NOT_READY));
MAUtils.tellPlayer(sender, Msg.FORCE_START_NOT_READY);
return true;
}
arena.forceStart();
MAUtils.tellPlayer(sender, MAMessages.get(Msg.FORCE_START_STARTED));
MAUtils.tellPlayer(sender, Msg.FORCE_START_STARTED);
return true;
}
else
@ -566,7 +515,7 @@ public class MACommands implements CommandExecutor
{
if (!console && !(player && plugin.has(p, "mobarena.admin.config.reload")) && !op)
{
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS));
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
return true;
}
@ -588,7 +537,7 @@ public class MACommands implements CommandExecutor
{
if (!console && !(player && plugin.has(p, "mobarena.setup.arena")) && !op)
{
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS));
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
return true;
}
@ -601,7 +550,7 @@ public class MACommands implements CommandExecutor
if (!arena.equals(am.selectedArena))
buffy.append(arena.configName() + " ");
}
else buffy.append(MAMessages.get(Msg.MISC_NONE));
else buffy.append(Msg.MISC_NONE);
MAUtils.tellPlayer(sender, "Other arenas: " + buffy.toString());
return true;
@ -614,7 +563,7 @@ public class MACommands implements CommandExecutor
{
if (!console && !(player && plugin.has(p, "mobarena.setup.setarena")) && !op)
{
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS));
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
return true;
}
if (arg1.isEmpty())
@ -631,7 +580,7 @@ public class MACommands implements CommandExecutor
}
else
{
MAUtils.tellPlayer(sender, MAMessages.get(Msg.ARENA_DOES_NOT_EXIST));
MAUtils.tellPlayer(sender, Msg.ARENA_DOES_NOT_EXIST);
}
return true;
}
@ -643,7 +592,7 @@ public class MACommands implements CommandExecutor
{
if (!(player && plugin.has(p, "mobarena.setup.addarena")) && !op)
{
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS));
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
return true;
}
if (arg1.isEmpty())
@ -671,7 +620,7 @@ public class MACommands implements CommandExecutor
{
if (!console && !(player && plugin.has(p, "mobarena.setup.delarena")) && !op)
{
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS));
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
return true;
}
if (arg1.isEmpty())
@ -707,7 +656,7 @@ public class MACommands implements CommandExecutor
{
if (!console && !(player && plugin.has(p, "mobarena.setup.protect")) && !op)
{
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS));
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
return true;
}
@ -773,7 +722,7 @@ public class MACommands implements CommandExecutor
{
if (!console && !(player && plugin.has(p, "mobarena.setup.editarena")) && !op)
{
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS));
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
return true;
}
@ -842,7 +791,7 @@ public class MACommands implements CommandExecutor
{
if (!(player && plugin.has(p, "mobarena.setup.setregion")) && !op)
{
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS));
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
return true;
}
@ -864,7 +813,7 @@ public class MACommands implements CommandExecutor
{
if (!console && !(player && plugin.has(p, "mobarena.setup.expandregion")) && !op)
{
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS));
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
return true;
}
if (args.length != 3 || !arg1.matches("(-)?[0-9]+"))
@ -912,7 +861,7 @@ public class MACommands implements CommandExecutor
{
if (!(player && plugin.has(p, "mobarena.setup.showregion")) && !op)
{
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS));
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
return true;
}
if (am.selectedArena.p1 == null || am.selectedArena.p2 == null)
@ -964,7 +913,7 @@ public class MACommands implements CommandExecutor
{
if (!(player && plugin.has(p, "mobarena.setup.setlobbyregion")) && !op)
{
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS));
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
return true;
}
@ -983,7 +932,7 @@ public class MACommands implements CommandExecutor
{
if (!console && !(player && plugin.has(p, "mobarena.setup.expandlobbyregion")) && !op)
{
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS));
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
return true;
}
if (args.length != 3 || !arg1.matches("[0-9]+"))
@ -1031,7 +980,7 @@ public class MACommands implements CommandExecutor
{
if (!(player && plugin.has(p, "mobarena.setup.setwarp")) && !op)
{
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS));
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
return true;
}
if (!(arg1.equals("arena") || arg1.equals("lobby") || arg1.equals("spectator")))
@ -1041,7 +990,8 @@ public class MACommands implements CommandExecutor
}
MAUtils.setArenaCoord(plugin.getConfig(), am.selectedArena, arg1, p.getLocation());
MAUtils.tellPlayer(sender, "Set warp point " + arg1 + " for arena '" + am.selectedArena.configName() + "'");
MAUtils.tellPlayer(sender, "Warp point " + arg1 + " was set for arena '" + am.selectedArena.configName() + "'");
MAUtils.tellPlayer(sender, "Type /ma checkdata to see if you're missing anything...");
return true;
}
@ -1052,7 +1002,7 @@ public class MACommands implements CommandExecutor
{
if (!console && !(player && plugin.has(p, "mobarena.setup.spawnpoints")) && !op)
{
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS));
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
return true;
}
@ -1069,7 +1019,7 @@ public class MACommands implements CommandExecutor
}
else
{
buffy.append(MAMessages.get(Msg.MISC_NONE));
buffy.append(Msg.MISC_NONE);
}
MAUtils.tellPlayer(sender, "Spawnpoints for arena '" + am.selectedArena.configName() + "': " + buffy.toString());
@ -1083,7 +1033,7 @@ public class MACommands implements CommandExecutor
{
if (!(player && plugin.has(p, "mobarena.setup.addspawn")) && !op)
{
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS));
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
return true;
}
if (arg1 == null || !arg1.matches("^[a-zA-Z][a-zA-Z0-9]*$"))
@ -1093,7 +1043,7 @@ public class MACommands implements CommandExecutor
}
MAUtils.setArenaCoord(plugin.getConfig(), am.selectedArena, "spawnpoints." + arg1, p.getLocation());
MAUtils.tellPlayer(sender, "Added spawnpoint " + arg1 + " for arena \"" + am.selectedArena.configName() + "\"");
MAUtils.tellPlayer(sender, "Sspawnpoint " + arg1 + " added for arena \"" + am.selectedArena.configName() + "\"");
return true;
}
@ -1104,7 +1054,7 @@ public class MACommands implements CommandExecutor
{
if (!console && !(player && plugin.has(p, "mobarena.setup.delspawn")) && !op)
{
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS));
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
return true;
}
if (arg1 == null || !arg1.matches("^[a-zA-Z][a-zA-Z0-9]*$"))
@ -1114,22 +1064,41 @@ public class MACommands implements CommandExecutor
}
if (MAUtils.delArenaCoord(plugin.getConfig(), am.selectedArena, "spawnpoints." + arg1))
MAUtils.tellPlayer(sender, "Deleted spawnpoint " + arg1 + " for arena '" + am.selectedArena.configName() + "'");
MAUtils.tellPlayer(sender, "Spawnpoint " + arg1 + " deleted for arena '" + am.selectedArena.configName() + "'");
else
MAUtils.tellPlayer(sender, "Could not find the spawnpoint " + arg1 + "for the arena '" + am.selectedArena.configName() + "'");
return true;
}
if (base.equals("auto-generate"))
if (base.equals("checkdata"))
{
if (!console && !(player && plugin.has(p, "mobarena.setup.checkdata")) && !op)
{
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
return true;
}
Arena arena = arg1.isEmpty() ? am.selectedArena : am.getArenaWithName(arg1);
if (arena == null)
{
MAUtils.tellPlayer(sender, Msg.ARENA_DOES_NOT_EXIST);
return true;
}
MAUtils.checkData(arena, sender);
return true;
}
if (base.equals("auto-generate") || base.equals("autogenerate"))
{
if (!(player && plugin.has(p, "mobarena.setup.autogenerate")) && !op)
{
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS));
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
return true;
}
if (arg1 == null || !arg1.matches("^[a-zA-Z][a-zA-Z0-9]*$"))
{
MAUtils.tellPlayer(sender, "Usage: /ma autogenerate <arena name>");
MAUtils.tellPlayer(sender, "Usage: /ma auto-generate <arena name>");
return true;
}
if (am.getArenaWithName(arg1) != null)
@ -1145,11 +1114,11 @@ public class MACommands implements CommandExecutor
return true;
}
if (base.equals("auto-degenerate"))
if (base.equals("auto-degenerate") || base.equals("autodegenerate"))
{
if (!console && !(player && plugin.has(p, "mobarena.setup.autodegenerate")) && !op)
{
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS));
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
return true;
}
if (arg1.isEmpty())
@ -1164,7 +1133,7 @@ public class MACommands implements CommandExecutor
}
if (am.getArenaWithName(arg1) == null)
{
MAUtils.tellPlayer(sender, MAMessages.get(Msg.ARENA_DOES_NOT_EXIST));
MAUtils.tellPlayer(sender, Msg.ARENA_DOES_NOT_EXIST);
return true;
}
@ -1179,7 +1148,7 @@ public class MACommands implements CommandExecutor
{
if (!(player && plugin.has(p, "mobarena.setup.autogenerate")) && !op)
{
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS));
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
return true;
}
@ -1198,7 +1167,7 @@ public class MACommands implements CommandExecutor
{
if (!(player && plugin.has(p, "mobarena.setup.autodegenerate")) && !op)
{
MAUtils.tellPlayer(sender, MAMessages.get(Msg.MISC_NO_ACCESS));
MAUtils.tellPlayer(sender, Msg.MISC_NO_ACCESS);
return true;
}
if (am.arenas.size() < 2)
@ -1208,7 +1177,7 @@ public class MACommands implements CommandExecutor
}
if (am.getArenaWithName("a1") == null)
{
MAUtils.tellPlayer(sender, MAMessages.get(Msg.ARENA_DOES_NOT_EXIST));
MAUtils.tellPlayer(sender, Msg.ARENA_DOES_NOT_EXIST);
return true;
}
@ -1227,4 +1196,18 @@ public class MACommands implements CommandExecutor
MAUtils.tellPlayer(sender, "Command not found.");
return true;
}
private boolean sanityChecks(Player p, Arena arena, String arg1, List<Arena> arenas)
{
if (arenas.size() > 1 && arg1.isEmpty())
MAUtils.tellPlayer(p, Msg.JOIN_ARG_NEEDED);
else if (arena == null)
MAUtils.tellPlayer(p, Msg.ARENA_DOES_NOT_EXIST);
else if (am.arenaMap.containsKey(p) && (am.arenaMap.get(p).arenaPlayers.contains(p) || am.arenaMap.get(p).lobbyPlayers.contains(p)))
MAUtils.tellPlayer(p, Msg.JOIN_IN_OTHER_ARENA);
else
return true;
return false;
}
}

View File

@ -384,7 +384,7 @@ public class MAListener implements ArenaListener
if (!arena.arenaPlayers.contains(p) && !arena.lobbyPlayers.contains(p))
return;
MAUtils.tellPlayer(p, MAMessages.get(Msg.LOBBY_DROP_ITEM));
MAUtils.tellPlayer(p, Msg.LOBBY_DROP_ITEM);
event.setCancelled(true);
}
@ -429,12 +429,12 @@ public class MAListener implements ArenaListener
{
if (arena.classMap.containsKey(p))
{
MAUtils.tellPlayer(p, MAMessages.get(Msg.LOBBY_PLAYER_READY));
MAUtils.tellPlayer(p, Msg.LOBBY_PLAYER_READY);
arena.playerReady(p);
}
else
{
MAUtils.tellPlayer(p, MAMessages.get(Msg.LOBBY_PICK_CLASS));
MAUtils.tellPlayer(p, Msg.LOBBY_PICK_CLASS);
}
return;
}
@ -444,7 +444,7 @@ public class MAListener implements ArenaListener
{
if (a == Action.RIGHT_CLICK_BLOCK)
{
MAUtils.tellPlayer(p, MAMessages.get(Msg.LOBBY_RIGHT_CLICK));
MAUtils.tellPlayer(p, Msg.LOBBY_RIGHT_CLICK);
return;
}
@ -456,18 +456,18 @@ public class MAListener implements ArenaListener
if (!arena.classes.contains(className) && !className.equalsIgnoreCase("random"))
return;
if (!plugin.hasDefTrue(p, "mobarena.classes." + className) && !className.equalsIgnoreCase("random"))
if (!plugin.has(p, "mobarena.classes." + className) && !className.equalsIgnoreCase("random"))
{
MAUtils.tellPlayer(p, MAMessages.get(Msg.LOBBY_CLASS_PERMISSION));
MAUtils.tellPlayer(p, Msg.LOBBY_CLASS_PERMISSION);
return;
}
// Set the player's class.
arena.assignClass(p, className);
if (!className.equalsIgnoreCase("random"))
MAUtils.tellPlayer(p, MAMessages.get(Msg.LOBBY_CLASS_PICKED, className));
MAUtils.tellPlayer(p, Msg.LOBBY_CLASS_PICKED, className);
else
MAUtils.tellPlayer(p, MAMessages.get(Msg.LOBBY_CLASS_RANDOM));
MAUtils.tellPlayer(p, Msg.LOBBY_CLASS_RANDOM);
return;
}
@ -513,7 +513,7 @@ public class MAListener implements ArenaListener
if (arena.inRegion(to) || to.equals(arena.arenaLoc) || to.equals(arena.lobbyLoc) || to.equals(arena.spectatorLoc) || to.equals(old))
return;
MAUtils.tellPlayer(p, MAMessages.get(Msg.WARP_FROM_ARENA));
MAUtils.tellPlayer(p, Msg.WARP_FROM_ARENA);
event.setCancelled(true);
return;
}
@ -523,7 +523,7 @@ public class MAListener implements ArenaListener
if (to.equals(arena.arenaLoc) || to.equals(arena.lobbyLoc) || to.equals(arena.spectatorLoc) || to.equals(old))
return;
MAUtils.tellPlayer(p, MAMessages.get(Msg.WARP_TO_ARENA));
MAUtils.tellPlayer(p, Msg.WARP_TO_ARENA);
event.setCancelled(true);
return;
}
@ -553,6 +553,6 @@ public class MAListener implements ArenaListener
return;
event.setCancelled(true);
MAUtils.tellPlayer(p, MAMessages.get(Msg.MISC_COMMAND_NOT_ALLOWED));
MAUtils.tellPlayer(p, Msg.MISC_COMMAND_NOT_ALLOWED);
}
}

View File

@ -6,172 +6,140 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
public class MAMessages
{
protected static Map<Msg,String> msgMap;
private static Map<Msg,String> defaults = new HashMap<Msg,String>();
public static enum Msg
{
ARENA_START,
ARENA_END,
ARENA_DOES_NOT_EXIST,
JOIN_PLAYER_JOINED,
JOIN_NOT_ENABLED,
JOIN_IN_OTHER_ARENA,
JOIN_ARENA_NOT_ENABLED,
JOIN_ARENA_NOT_SETUP,
JOIN_ARENA_EDIT_MODE,
JOIN_ARENA_PERMISSION,
JOIN_FEE_REQUIRED,
JOIN_FEE_PAID,
JOIN_ARENA_IS_RUNNING,
JOIN_ALREADY_PLAYING,
JOIN_ARG_NEEDED,
JOIN_TOO_FAR,
JOIN_EMPTY_INV,
JOIN_PLAYER_LIMIT_REACHED,
JOIN_STORE_INV_FAIL,
LEAVE_PLAYER_LEFT,
LEAVE_NOT_PLAYING,
PLAYER_DIED,
SPEC_PLAYER_SPECTATE,
SPEC_NOT_RUNNING,
SPEC_ARG_NEEDED,
SPEC_EMPTY_INV,
SPEC_ALREADY_PLAYING,
NOT_READY_PLAYERS,
FORCE_START_STARTED,
FORCE_START_RUNNING,
FORCE_START_NOT_READY,
FORCE_END_ENDED,
FORCE_END_EMPTY,
FORCE_END_IDLE,
REWARDS_GIVE,
LOBBY_CLASS_PICKED,
LOBBY_CLASS_RANDOM,
LOBBY_CLASS_PERMISSION,
LOBBY_NOT_ENOUGH_PLAYERS,
LOBBY_PLAYER_READY,
LOBBY_DROP_ITEM,
LOBBY_PICK_CLASS,
LOBBY_RIGHT_CLICK,
WARP_TO_ARENA,
WARP_FROM_ARENA,
WAVE_DEFAULT,
WAVE_SPECIAL,
WAVE_SWARM,
WAVE_BOSS,
WAVE_BOSS_ABILITY,
WAVE_REWARD,
MISC_LIST_ARENAS,
MISC_LIST_PLAYERS,
MISC_COMMAND_NOT_ALLOWED,
MISC_NO_ACCESS,
MISC_NONE;
ARENA_START("Let the slaughter begin!"),
ARENA_END("Arena finished."),
ARENA_DOES_NOT_EXIST("That arena does not exist. Type /ma arenas for a list."),
JOIN_NOT_ENABLED("MobArena is not enabled."),
JOIN_IN_OTHER_ARENA("You are already in an arena! Leave that one first."),
JOIN_ARENA_NOT_ENABLED("This arena is not enabled."),
JOIN_ARENA_NOT_SETUP("This arena has not been set up yet."),
JOIN_ARENA_EDIT_MODE("This arena is in edit mode."),
JOIN_ARENA_PERMISSION("You don't have permission to join this arena."),
JOIN_FEE_REQUIRED("Insufficient funds. Price: %"),
JOIN_FEE_PAID("Price to join was: %"),
JOIN_ARENA_IS_RUNNING("This arena is in already progress."),
JOIN_ALREADY_PLAYING("You are already playing!"),
JOIN_ARG_NEEDED("You must specify an arena. Type /ma arenas for a list."),
JOIN_TOO_FAR("You are too far away from the arena to join/spectate."),
JOIN_EMPTY_INV("You must empty your inventory to join the arena."),
JOIN_PLAYER_LIMIT_REACHED("The player limit of this arena has been reached."),
JOIN_STORE_INV_FAIL("Failed to store inventory. Try again."),
JOIN_PLAYER_JOINED("You joined the arena. Have fun!"),
LEAVE_NOT_PLAYING("You are not in the arena."),
LEAVE_PLAYER_LEFT("You left the arena. Thanks for playing!"),
PLAYER_DIED("% died!"),
SPEC_PLAYER_SPECTATE("Enjoy the show!"),
SPEC_NOT_RUNNING("This arena isn't running."),
SPEC_ARG_NEEDED("You must specify an arena. Type /ma arenas for a list."),
SPEC_EMPTY_INV("Empty your inventory first!"),
SPEC_ALREADY_PLAYING("Can't spectate when in the arena!"),
NOT_READY_PLAYERS("Not ready: %"),
FORCE_START_RUNNING("Arena has already started."),
FORCE_START_NOT_READY("Can't force start, no players are ready."),
FORCE_START_STARTED("Forced arena start."),
FORCE_END_EMPTY("No one is in the arena."),
FORCE_END_ENDED("Forced arena end."),
FORCE_END_IDLE("You weren't quick enough!"),
REWARDS_GIVE("Here are all of your rewards!"),
LOBBY_DROP_ITEM("No sharing allowed at this time!"),
LOBBY_PLAYER_READY("You have been flagged as ready!"),
LOBBY_PICK_CLASS("You must first pick a class!"),
LOBBY_NOT_ENOUGH_PLAYERS("Not enough players to start. Need at least % players."),
LOBBY_RIGHT_CLICK("Punch the sign. Don't right-click."),
LOBBY_CLASS_PICKED("You have chosen % as your class!"),
LOBBY_CLASS_RANDOM("You will get a random class on arena start."),
LOBBY_CLASS_PERMISSION("You don't have permission to use this class!"),
WARP_TO_ARENA("Can't warp to the arena during battle!"),
WARP_FROM_ARENA("Warping not allowed in the arena!"),
WAVE_DEFAULT("Wave #%!"),
WAVE_SPECIAL("Wave #%! [SPECIAL]"),
WAVE_SWARM("Wave #%! [SWARM]"),
WAVE_BOSS("Wave #%! [BOSS]"),
WAVE_BOSS_ABILITY("Boss used ability: %!"),
WAVE_REWARD("You just earned a reward: %"),
MISC_LIST_PLAYERS("Live players: %"),
MISC_LIST_ARENAS("Available arenas: %"),
MISC_COMMAND_NOT_ALLOWED("You can't use that command in the arena!"),
MISC_NO_ACCESS("You don't have access to this command."),
MISC_NONE("<none>");
private String msg;
private Msg(String msg)
{
this.msg = msg;
}
public String get()
{
return msg;
}
public String get(String s)
{
return msg.replace("%", s);
}
public static String get(Msg m)
{
return m.msg;
}
public static String get(Msg m, String s)
{
return m.msg.replace("%", s);
}
public void set(String msg)
{
this.msg = msg;
}
public static void set(Msg m, String msg)
{
m.msg = msg;
}
}
// Populate the defaults map.
static
{
defaults.put(Msg.ARENA_START, "Let the slaughter begin!");
defaults.put(Msg.ARENA_END, "Arena finished.");
defaults.put(Msg.ARENA_DOES_NOT_EXIST, "That arena does not exist. Type /ma arenas for a list.");
defaults.put(Msg.JOIN_NOT_ENABLED, "MobArena is not enabled.");
defaults.put(Msg.JOIN_IN_OTHER_ARENA, "You are already in an arena! Leave that one first.");
defaults.put(Msg.JOIN_ARENA_NOT_ENABLED, "This arena is not enabled.");
defaults.put(Msg.JOIN_ARENA_NOT_SETUP, "This arena has not been set up yet.");
defaults.put(Msg.JOIN_ARENA_EDIT_MODE, "This arena is in edit mode.");
defaults.put(Msg.JOIN_ARENA_PERMISSION, "You don't have permission to join this arena.");
defaults.put(Msg.JOIN_FEE_REQUIRED, "Insufficient funds. Price: %");
defaults.put(Msg.JOIN_FEE_PAID, "Price to join was: %");
defaults.put(Msg.JOIN_ARENA_IS_RUNNING, "This arena is in already progress.");
defaults.put(Msg.JOIN_ALREADY_PLAYING, "You are already playing!");
defaults.put(Msg.JOIN_ARG_NEEDED, "You must specify an arena. Type /ma arenas for a list.");
defaults.put(Msg.JOIN_TOO_FAR, "You are too far away from the arena to join/spectate.");
defaults.put(Msg.JOIN_EMPTY_INV, "You must empty your inventory to join the arena.");
defaults.put(Msg.JOIN_PLAYER_LIMIT_REACHED, "The player limit of this arena has been reached.");
defaults.put(Msg.JOIN_STORE_INV_FAIL, "Failed to store inventory. Try again.");
defaults.put(Msg.JOIN_PLAYER_JOINED, "You joined the arena. Have fun!");
defaults.put(Msg.LEAVE_NOT_PLAYING, "You are not in the arena.");
defaults.put(Msg.LEAVE_PLAYER_LEFT, "You left the arena. Thanks for playing!");
defaults.put(Msg.PLAYER_DIED, "% died!");
defaults.put(Msg.SPEC_PLAYER_SPECTATE, "Enjoy the show!");
defaults.put(Msg.SPEC_NOT_RUNNING, "This arena isn't running.");
defaults.put(Msg.SPEC_ARG_NEEDED, "You must specify an arena. Type /ma arenas for a list.");
defaults.put(Msg.SPEC_EMPTY_INV, "Empty your inventory first!");
defaults.put(Msg.SPEC_ALREADY_PLAYING, "Can't spectate when in the arena!");
defaults.put(Msg.NOT_READY_PLAYERS, "Not ready: %");
defaults.put(Msg.FORCE_START_RUNNING, "Arena has already started.");
defaults.put(Msg.FORCE_START_NOT_READY, "Can't force start, no players are ready.");
defaults.put(Msg.FORCE_START_STARTED, "Forced arena start.");
defaults.put(Msg.FORCE_END_EMPTY, "No one is in the arena.");
defaults.put(Msg.FORCE_END_ENDED, "Forced arena end.");
defaults.put(Msg.FORCE_END_IDLE, "You weren't quick enough!");
defaults.put(Msg.REWARDS_GIVE, "Here are all of your rewards!");
defaults.put(Msg.LOBBY_DROP_ITEM, "No sharing allowed at this time!");
defaults.put(Msg.LOBBY_PLAYER_READY, "You have been flagged as ready!");
defaults.put(Msg.LOBBY_PICK_CLASS, "You must first pick a class!");
defaults.put(Msg.LOBBY_NOT_ENOUGH_PLAYERS, "Not enough players to start. Need at least % players.");
defaults.put(Msg.LOBBY_RIGHT_CLICK, "Punch the sign. Don't right-click.");
defaults.put(Msg.LOBBY_CLASS_PICKED, "You have chosen % as your class!");
defaults.put(Msg.LOBBY_CLASS_RANDOM, "You will get a random class on arena start.");
defaults.put(Msg.LOBBY_CLASS_PERMISSION, "You don't have permission to use this class!");
defaults.put(Msg.WARP_TO_ARENA, "Can't warp to the arena during battle!");
defaults.put(Msg.WARP_FROM_ARENA, "Warping not allowed in the arena!");
defaults.put(Msg.WAVE_DEFAULT, "Wave #%!");
defaults.put(Msg.WAVE_SPECIAL, "Wave #%! [SPECIAL]");
defaults.put(Msg.WAVE_SWARM, "Wave #%! [SWARM]");
defaults.put(Msg.WAVE_BOSS, "Wave #%! [BOSS]");
defaults.put(Msg.WAVE_BOSS_ABILITY, "Boss used ability: %!");
defaults.put(Msg.WAVE_REWARD, "You just earned a reward: %");
defaults.put(Msg.MISC_LIST_PLAYERS, "Live players: %");
defaults.put(Msg.MISC_LIST_ARENAS, "Available arenas: %");
defaults.put(Msg.MISC_COMMAND_NOT_ALLOWED, "You can't use that command in the arena!");
defaults.put(Msg.MISC_NO_ACCESS, "You don't have access to this command.");
defaults.put(Msg.MISC_NONE, "<none>");
}
/**
* Initializes the msgMap by reading from the announcements-file.
*/
public static void init(MobArena plugin)
{
// Use defaults in case of any errors.
msgMap = defaults;
{
// Grab the announcements-file.
File msgFile;
try
File msgFile = new File(MobArena.dir, "announcements.properties");
// If the file doesn't exist, create it and use defaults.
if (!msgFile.exists())
{
msgFile = new File(plugin.getDataFolder(), "announcements.properties");
// If it doesn't exist, create it.
if (!msgFile.exists())
try
{
MobArena.info("Announcements-file not found. Creating one...");
msgFile.createNewFile();
BufferedWriter bw = new BufferedWriter(new FileWriter(msgFile));
for (Msg m : Msg.values())
{
bw.write(m.toString() + "=" + defaults.get(m));
bw.write(m + "=" + m.msg);
bw.newLine();
}
bw.close();
bw.close();
return;
}
}
catch (Exception e)
{
MobArena.warning("Couldn't initialize announcements-file. Using defaults.");
catch (Exception e)
{
MobArena.warning("Couldn't initialize announcements-file. Using defaults.");
}
return;
}
// If the file was found, populate the msgMap.
// Otherwise, read the file's contents.
try
{
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(msgFile), "UTF-8"));
@ -194,36 +162,15 @@ public class MAMessages
}
}
/**
* Grabs the announcement from the msgMap, and in case of
* s not being null, replaces the % with s.
*/
public static String get(Msg msg, String s)
{
// If p is null, just return the announcement as is.
if (s == null)
return msgMap.get(msg);
// Otherwise, replace the % with the input string.
return msgMap.get(msg).replace("%", s);
}
/**
* Grabs the announcement from the msgMap.
*/
public static String get(Msg msg)
{
return get(msg, null);
}
/**
* Helper-method for parsing the strings from the
* announcements-file.
*/
private static void process(String s)
{
if (s.endsWith("="))
s += " ";
// If the line ends with =, just add a space
if (s.endsWith("=")) s += " ";
// Split the string by the equals-sign.
String[] split = s.split("=");
if (split.length != 2)
@ -235,12 +182,11 @@ public class MAMessages
// For simplicity...
String key = split[0];
String val = split[1];
Msg msg;
try
{
msg = Msg.valueOf(key);
msgMap.put(msg, val);
Msg msg = Msg.valueOf(key);
msg.set(val);
}
catch (Exception e)
{

View File

@ -186,12 +186,12 @@ public class MASpawnThread implements Runnable
else if (reward.getTypeId() == MobArena.ECONOMY_MONEY_ID)
{
if (plugin.Methods.hasMethod())
MAUtils.tellPlayer(p, MAMessages.get(Msg.WAVE_REWARD, plugin.Method.format(reward.getAmount())));
MAUtils.tellPlayer(p, Msg.WAVE_REWARD, plugin.Method.format(reward.getAmount()));
else MobArena.warning("Tried to add money, but no economy plugin detected!");
}
else
{
MAUtils.tellPlayer(p, MAMessages.get(Msg.WAVE_REWARD, MAUtils.toCamelCase(reward.getType().toString()) + ":" + reward.getAmount()));
MAUtils.tellPlayer(p, Msg.WAVE_REWARD, MAUtils.toCamelCase(reward.getType().toString()) + ":" + reward.getAmount());
}
}
}

View File

@ -35,6 +35,8 @@ import org.bukkit.inventory.PlayerInventory;
import org.bukkit.util.config.Configuration;
import com.garbagemule.MobArena.MAMessages.Msg;
import com.garbagemule.MobArena.util.EntityPosition;
import com.garbagemule.MobArena.util.MAInventoryItem;
public class MAUtils
{
@ -765,6 +767,10 @@ public class MAUtils
arena.p1.setY(arena.p2.getY());
arena.p2.setY(tmp);
}
if (!arena.world.getName().equals(world.getName()))
arena.world = world;
arena.serializeConfig();
arena.load(config);
}
@ -882,10 +888,19 @@ public class MAUtils
return true;
}
public static boolean tellPlayer(CommandSender p, Msg msg)
{
return tellPlayer(p, msg.get());
}
public static boolean tellPlayer(CommandSender p, Msg msg, String s)
{
return tellPlayer(p, msg.get(s));
}
/**
* Sends a message to all players in and around the arena.
*/
public static void tellAll(Arena arena, String msg) { tellAll(arena, msg, false); }
public static void tellAll(Arena arena, String msg, boolean notifyPlayers)
{
Set<Player> tmp = new HashSet<Player>();
@ -899,6 +914,11 @@ public class MAUtils
tellPlayer(p, msg);
}
public static void tellAll(Arena arena, String msg)
{
tellAll(arena, msg, false);
}
public static Player getClosestPlayer(Entity e, Arena arena)
{
// Set up the comparison variable and the result.
@ -979,7 +999,7 @@ public class MAUtils
if (list == null || list.isEmpty())
{
if (none)
return MAMessages.get(Msg.MISC_NONE);
return Msg.MISC_NONE.get();
else
return "";
}
@ -1066,7 +1086,7 @@ public class MAUtils
* and spawnpoints are all set up.
*/
public static boolean verifyData(Arena arena)
{
{
return ((arena.arenaLoc != null) &&
(arena.lobbyLoc != null) &&
(arena.spectatorLoc != null) &&
@ -1080,6 +1100,24 @@ public class MAUtils
return ((arena.l1 != null) &&
(arena.l2 != null));
}
public static void checkData(Arena arena, CommandSender p)
{
if (arena.arenaLoc == null)
tellPlayer(p, "Missing warp: arena");
if (arena.lobbyLoc == null)
tellPlayer(p, "Missing warp: lobby");
if (arena.spectatorLoc == null)
tellPlayer(p, "Missing warp: spectator");
if (arena.p1 == null)
tellPlayer(p, "Missing region point: p1");
if (arena.p2 == null)
tellPlayer(p, "Missing region point: p2");
if (arena.spawnpoints.size() <= 0)
tellPlayer(p, "Missing spawnpoints");
if (arena.setup)
tellPlayer(p, "Arena is ready to be used!");
}
/**
* Checks if there is a new update of MobArena and notifies the

View File

@ -1,6 +1,7 @@
package com.garbagemule.MobArena;
import java.io.File;
import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
@ -9,6 +10,7 @@ import org.bukkit.event.Event.Priority;
import org.bukkit.event.block.BlockListener;
import org.bukkit.event.player.PlayerListener;
import org.bukkit.event.entity.EntityListener;
import org.bukkit.permissions.Permission;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin;
@ -53,13 +55,14 @@ public class MobArena extends JavaPlugin
if (!arenaDir.exists()) arenaDir.mkdir();
// Create default files and initialize config-file
FileUtils.extractDefaults("config.yml", "announcements.properties");
FileUtils.extractDefaults("config.yml");
loadConfig();
// Download external libraries if needed.
FileUtils.fetchLibs(config);
// Set up permissions and economy
//setupSuperPerms();
setupPermissions();
setupRegister();
@ -78,6 +81,7 @@ public class MobArena extends JavaPlugin
public void onDisable()
{
// Force all arenas to end.
if (am == null) return;
for (Arena arena : am.arenas)
arena.forceEnd();
am.arenaMap.clear();
@ -109,10 +113,9 @@ public class MobArena extends JavaPlugin
private void registerListeners()
{
// Bind the /ma, /marena, and /mobarena commands to MACommands.
// Bind the /ma, /mobarena commands to MACommands.
MACommands commandExecutor = new MACommands(this, am);
getCommand("ma").setExecutor(commandExecutor);
getCommand("marena").setExecutor(commandExecutor);
getCommand("mobarena").setExecutor(commandExecutor);
// Create event listeners.
@ -146,13 +149,18 @@ public class MobArena extends JavaPlugin
// Permissions stuff
public boolean has(Player p, String s)
{
//return (permissionHandler != null && permissionHandler.has(p, s));
return (permissionHandler == null || permissionHandler.has(p, s));
//return (permissionHandler == null || permissionHandler.has(p, s));
return hasSuperPerms(p, s) || hasNijikoPerms(p, s);
}
public boolean hasDefTrue(Player p, String s)
public boolean hasSuperPerms(Player p, String s)
{
return (permissionHandler == null || permissionHandler.has(p, s));
return p.hasPermission(s);
}
public boolean hasNijikoPerms(Player p, String s)
{
return permissionHandler != null && permissionHandler.has(p, s);
}
// Console printing
@ -160,6 +168,12 @@ public class MobArena extends JavaPlugin
public static void warning(String msg) { Bukkit.getServer().getLogger().warning("[MobArena] " + msg); }
public static void error(String msg) { Bukkit.getServer().getLogger().severe("[MobArena] " + msg); }
private void setupSuperPerms()
{
getServer().getPluginManager().addPermission(new Permission("mobarena.classes"));
getServer().getPluginManager().addPermission(new Permission("mobarena.arenas"));
}
private void setupPermissions()
{
if (permissionHandler != null)

View File

@ -0,0 +1,89 @@
package com.garbagemule.MobArena.util;
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
*/
@SuppressWarnings("serial")
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;
}
}

View File

@ -0,0 +1,22 @@
package com.garbagemule.MobArena.util;
import java.io.Serializable;
public class MAInventoryItem implements Serializable
{
private static final long serialVersionUID = 739709220350581510L;
private int typeId;
private int amount;
private short durability;
public MAInventoryItem(int typeId, int amount, short durability)
{
this.typeId = typeId;
this.amount = amount;
this.durability = durability;
}
public int getTypeId() { return typeId; }
public int getAmount() { return amount; }
public short getDurability() { return durability; }
}

View File

@ -133,7 +133,7 @@ public class WaveUtils
if (type == null || !isWaveWellDefined(config, path, branch, type))
return null;
// TODO: Generate waves properly. These are place-holders!
//
Wave result = null;
if (branch == WaveBranch.RECURRENT)
{

View File

@ -2,6 +2,7 @@ package com.garbagemule.MobArena.util.data;
import java.io.File;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.config.Configuration;
import com.garbagemule.MobArena.Arena;
@ -34,17 +35,26 @@ public class Totals
updateDuration(totals, "general-info.longest-session-duration", log.getDurationLong(), false);
// Classes
updateInt(totals, "classes.overall-distribution.total-count", log.players.keySet().size(), true);
//updateInt(totals, "classes.overall-distribution.total-count", log.players.keySet().size(), true);
for (String c : log.arena.getClasses())
{
// Array {kills, dmgDone, dmgTaken}
int[] a = getKillsAndDamageByClass(log, c);
updateInt(totals,"classes." + c + ".kills", a[0],true);
updateInt(totals,"classes." + c + ".damage-done", a[1],true);
updateInt(totals,"classes." + c + ".damage-taken",a[2],true);
updateInt(totals, "classes." + c + ".kills", a[0], true);
updateInt(totals, "classes." + c + ".damage-done", a[1], true);
updateInt(totals, "classes." + c + ".damage-taken", a[2], true);
updateInt(totals, "classes." + c + ".played", log.distribution.get(c), true);
}
// Rewards
for (ArenaPlayer ap : log.players.values())
{
for (ItemStack stack : ap.rewards)
{
boolean money = stack.getTypeId() == MobArena.ECONOMY_MONEY_ID;
updateInt(totals, "rewards." + (money ? "money" : stack.getType().toString().toLowerCase()), stack.getAmount(), true);
}
}
// Players
for (ArenaPlayer ap : log.players.values())
@ -126,17 +136,6 @@ public class Totals
return kills;
}
/*
private static int getKillsByClass(ArenaLog log, String className)
{
int kills = 0;
for (ArenaPlayer ap : log.players.values())
if (ap.className.equals(className))
kills += ap.kills;
return kills;
}
*/
/**
* Get a (dirty) int-array in the form {kills, damage done, damage taken} for a class
* @param log ArenaLog to count kills, damage done/taken from

View File

@ -59,10 +59,12 @@ public class XML
Element rewards = new Element("rewards");
for (ItemStack stack : ap.rewards)
{
// TODO: Move this to a method
boolean money = stack.getTypeId() == MobArena.ECONOMY_MONEY_ID;
Element r = new Element("reward");
r.setAttribute(new Attribute("id", stack.getTypeId() + ""));
r.setAttribute(new Attribute("material", stack.getType().toString().toLowerCase()));
r.setAttribute(new Attribute("data", (stack.getData() != null) ? stack.getData().toString().toLowerCase() : "0"));
r.setAttribute(new Attribute("material", money ? "money" : stack.getType().toString().toLowerCase()));
r.setAttribute(new Attribute("data", money || stack.getData() == null ? "0" : stack.getData().toString().toLowerCase()));
r.setAttribute(new Attribute("amount", stack.getAmount() + ""));
rewards.addContent(r);
@ -110,7 +112,23 @@ public class XML
cl.addContent(e);
}
// Rewards TODO: THIS!
// Rewards
Element rw = new Element("rewards");
for (ArenaPlayer ap : log.players.values())
{
for (ItemStack stack : ap.rewards)
{
// TODO: Move this to a method
boolean money = stack.getTypeId() == MobArena.ECONOMY_MONEY_ID;
Element r = new Element("reward");
r.setAttribute(new Attribute("id", stack.getTypeId() + ""));
r.setAttribute(new Attribute("material", money ? "money" : stack.getType().toString().toLowerCase()));
r.setAttribute(new Attribute("data", money || stack.getData() == null ? "0" : stack.getData().toString().toLowerCase()));
r.setAttribute(new Attribute("amount", stack.getAmount() + ""));
rw.addContent(r);
}
}
// Players
Element pl = new Element("players");
@ -141,6 +159,7 @@ public class XML
Element root = new Element("last-session");
root.addContent(gd);
root.addContent(cl);
root.addContent(rw);
root.addContent(pl);
// Create a new document

View File

@ -51,7 +51,8 @@ public class YAML
config.setProperty("player-data." + p + ".hits", ap.hits);
for (ItemStack stack : ap.rewards)
{
String path = "player-data." + p + ".rewards." + stack.getType().toString().toLowerCase();
boolean money = stack.getTypeId() == MobArena.ECONOMY_MONEY_ID;
String path = "player-data." + p + ".rewards." + (money ? "money" : stack.getType().toString().toLowerCase());
config.setProperty(path, config.getInt(path, 0) + stack.getAmount());
}
}

View File

@ -84,7 +84,7 @@ public abstract class AbstractWave implements Wave
public LivingEntity spawnMonster(MACreature creature, Location loc)
{
// Spawn and add to collection
LivingEntity e = creature.spawn(getWorld(), loc);
LivingEntity e = creature.spawn(getArena(), getWorld(), loc);
getArena().addMonster(e);
// Grab a random target.
@ -185,10 +185,15 @@ public abstract class AbstractWave implements Wave
// MISC
public String toString()
{
return "[name=" + waveName +
", wave=" + wave +
", frequency=" + frequency +
", priority=" + priority +
", type=" + type + "]";
if (branch == WaveBranch.RECURRENT)
return "[Wave type=" + type +
" name=" + waveName +
" branch=" + branch.toString().charAt(0) +
" freq=" + frequency +
" prio=" + priority + "]";
return "[Wave type=" + type +
" name=" + waveName +
" branch=" + branch.toString().charAt(0) +
" wave=" + wave + "]";
}
}

View File

@ -10,7 +10,6 @@ import org.bukkit.entity.LivingEntity;
import org.bukkit.util.config.Configuration;
import com.garbagemule.MobArena.Arena;
import com.garbagemule.MobArena.MAMessages;
import com.garbagemule.MobArena.MAUtils;
import com.garbagemule.MobArena.MAMessages.Msg;
import com.garbagemule.MobArena.util.WaveUtils;
@ -64,10 +63,10 @@ public class BossWave extends AbstractWave// TODO: implement/extend something?
public void spawn(int wave)
{
// Announce spawning
MAUtils.tellAll(getArena(), MAMessages.get(Msg.WAVE_BOSS, ""+wave));
MAUtils.tellAll(getArena(), Msg.WAVE_BOSS.get(""+wave));
// Spawn the boss and set the arena
bossCreature = boss.spawn(getWorld(), getArena().getBossSpawnpoint());
bossCreature = boss.spawn(getArena(), getWorld(), getArena().getBossSpawnpoint());
if (bossCreature instanceof Creature)
((Creature) bossCreature).setTarget(MAUtils.getClosestPlayer(bossCreature, getArena()));
getArena().addMonster(bossCreature);
@ -78,6 +77,7 @@ public class BossWave extends AbstractWave// TODO: implement/extend something?
healthAmount = bossHealth.getAmount(getArena().getPlayerCount());
startAbilityTasks();
System.out.println(this);
}
private void startAbilityTasks()
@ -94,7 +94,7 @@ public class BossWave extends AbstractWave// TODO: implement/extend something?
public void run()
{
// Announce ability
MAUtils.tellAll(getArena(), MAMessages.get(Msg.WAVE_BOSS_ABILITY, MAUtils.toCamelCase(ability.toString())));
MAUtils.tellAll(getArena(), Msg.WAVE_BOSS_ABILITY.get(MAUtils.toCamelCase(ability.toString())));
// Activate!
ability.activate(getArena(), bossCreature);

View File

@ -9,7 +9,6 @@ import org.bukkit.Location;
import org.bukkit.util.config.Configuration;
import com.garbagemule.MobArena.Arena;
import com.garbagemule.MobArena.MAMessages;
import com.garbagemule.MobArena.MAMessages.Msg;
import com.garbagemule.MobArena.MAUtils;
import com.garbagemule.MobArena.util.WaveUtils;
@ -38,7 +37,7 @@ public class DefaultWave extends NormalWave
public void spawn(int wave)
{
// Announce spawning
MAUtils.tellAll(getArena(), MAMessages.get(Msg.WAVE_DEFAULT, ""+wave));
MAUtils.tellAll(getArena(), Msg.WAVE_DEFAULT.get(""+wave));
// Get the valid spawnpoints, and initialize counter
List<Location> validSpawnpoints = WaveUtils.getValidSpawnpoints(getArena().getSpawnpoints(), getArena().getLivingPlayers());
@ -48,7 +47,7 @@ public class DefaultWave extends NormalWave
// Spawn all the monsters
spawnAll(getMonstersToSpawn(totalToSpawn), validSpawnpoints);
System.out.println("WAVE SPAWN! Wave: " + wave + ", name: " + getName() + ", type: " + getType());
System.out.println(this);
}
private Map<MACreature,Integer> getMonstersToSpawn(int totalToSpawn)

View File

@ -8,6 +8,7 @@ import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Slime;
import org.bukkit.entity.Wolf;
import com.garbagemule.MobArena.Arena;
import com.garbagemule.MobArena.util.WaveUtils;
public enum MACreature
@ -26,7 +27,13 @@ public enum MACreature
HUMAN(CreatureType.MONSTER), HUMANS(CreatureType.MONSTER),
SLIME(CreatureType.SLIME), SLIMES(CreatureType.SLIME),
GIANT(CreatureType.GIANT), GIANTS(CreatureType.GIANT),
GHAST(CreatureType.GHAST), GHASTS(CreatureType.GHAST);
GHAST(CreatureType.GHAST), GHASTS(CreatureType.GHAST),
// Passive creatures
CHICKEN(CreatureType.CHICKEN), CHICKENS(CreatureType.CHICKEN),
COW(CreatureType.COW), COWS(CreatureType.COW),
PIG(CreatureType.PIG), PIGS(CreatureType.PIG),
SHEEP(CreatureType.SHEEP);
// Misc
// EXPLODING_SHEEP(CreatureType.SHEEP), // Explode (power: 1) when close enough to players
@ -51,12 +58,15 @@ public enum MACreature
return WaveUtils.getEnumFromString(MACreature.class, string);
}
public LivingEntity spawn(World world, Location loc)
public LivingEntity spawn(Arena arena, World world, Location loc)
{
LivingEntity e = world.spawnCreature(loc, type);
switch (this)
{
case SHEEP:
arena.addExplodingSheep(e);
break;
case POWERED_CREEPERS:
((Creeper) e).setPowered(true);
break;

View File

@ -74,7 +74,6 @@ public abstract class NormalWave extends AbstractWave
totalProbability = 40;
}
}
System.out.println(probabilities);
}
public int getTotalProbability()

View File

@ -9,7 +9,6 @@ import org.bukkit.Location;
import org.bukkit.util.config.Configuration;
import com.garbagemule.MobArena.Arena;
import com.garbagemule.MobArena.MAMessages;
import com.garbagemule.MobArena.MAUtils;
import com.garbagemule.MobArena.MAMessages.Msg;
import com.garbagemule.MobArena.util.WaveUtils;
@ -33,14 +32,14 @@ public class SpecialWave extends NormalWave
public void spawn(int wave)
{
// Announce spawning
MAUtils.tellAll(getArena(), MAMessages.get(Msg.WAVE_SPECIAL, ""+wave));
MAUtils.tellAll(getArena(), Msg.WAVE_SPECIAL.get(""+wave));
// Get the valid spawnpoints, and initialize counter
List<Location> validSpawnpoints = WaveUtils.getValidSpawnpoints(getArena().getSpawnpoints(), getArena().getLivingPlayers());
// Spawn all the monsters
spawnAll(getMonstersToSpawn(getArena().getPlayerCount()), validSpawnpoints);
System.out.println("WAVE SPAWN! Wave: " + wave + ", name: " + getName() + ", type: " + getType());
System.out.println(this);
}
private Map<MACreature,Integer> getMonstersToSpawn(int playerCount)

View File

@ -7,7 +7,6 @@ import org.bukkit.entity.LivingEntity;
import org.bukkit.util.config.Configuration;
import com.garbagemule.MobArena.Arena;
import com.garbagemule.MobArena.MAMessages;
import com.garbagemule.MobArena.MAUtils;
import com.garbagemule.MobArena.MAMessages.Msg;
import com.garbagemule.MobArena.util.WaveUtils;
@ -46,14 +45,14 @@ public class SwarmWave extends AbstractWave
public void spawn(int wave)
{
// Announce spawning
MAUtils.tellAll(getArena(), MAMessages.get(Msg.WAVE_SWARM, ""+wave));
MAUtils.tellAll(getArena(), Msg.WAVE_SWARM.get(""+wave));
// Get the valid spawnpoints, and initialize counter
List<Location> validSpawnpoints = WaveUtils.getValidSpawnpoints(getArena().getSpawnpoints(), getArena().getLivingPlayers());
// Spawn the hellians!
spawnAll(monster, amount.getAmount(getArena().getPlayerCount()), validSpawnpoints);
System.out.println("WAVE SPAWN! Wave: " + wave + ", name: " + getName() + ", type: " + getType() + ", amount: " + amount);
System.out.println(this);
}
public void spawnAll(MACreature monster, int amount, List<Location> spawnpoints)