Complete Config-overhaul, as well as preparation and initial classes for JUnit-testing and refactoring of commands.

This commit is contained in:
Garbage Mule 2011-12-10 18:33:04 +01:00
parent 2a2dcf3335
commit 289b1792f5
33 changed files with 2839 additions and 1761 deletions

Binary file not shown.

View File

@ -1,6 +1,6 @@
name: MobArena name: MobArena
main: com.garbagemule.MobArena.MobArena main: com.garbagemule.MobArena.MobArena
version: 0.94.4.3 version: 0.94.4.4
softdepend: [Spout,Permissions,MultiVerse,XcraftGate,Towny,Heroes,MagicSpells] softdepend: [Spout,Permissions,MultiVerse,XcraftGate,Towny,Heroes,MagicSpells]
commands: commands:
ma: ma:

View File

@ -1,155 +0,0 @@
name: MobArena
main: garbagemule.mobarena.MobArenaPlugin
version: 0.94.3.24
softdepend: [Spout,Permissions,MultiVerse,XcraftGate,Towny,Heroes,MagicSpells]
commands:
ma:
description: Base command for MobArena
usage: |
YOU HAVE AN ERROR!
Find the error in your server log, copy it into
http://pastebin.com, and then paste the link
in the IRC or on the forums.
mobarena:
description: Base command for MobArena
usage: |
YOU HAVE AN ERROR!
Find the error in your server log, copy it into
http://pastebin.com, and then paste the link
in the IRC or on the forums.
permissions:
mobarena.use:
description: Gives access to usage commands
default: true
children:
mobarena.use.join: true
mobarena.use.spec: true
mobarena.use.leave: true
mobarena.use.join:
default: true
mobarena.use.spec:
default: true
mobarena.use.leave:
default: true
mobarena.admin:
description: Gives access to all admin commands
default: op
children:
mobarena.admin.enable: true
mobarena.admin.kick: true
mobarena.admin.restore: true
mobarena.admin.force.end: true
mobarena.admin.force.start: true
mobarena.admin.config.reload: true
mobarena.admin.enable:
description: Enable and disable MobArena and/or arenas.
default: false
mobarena.admin.kick:
description: Kick a player from an arena.
default: false
mobarena.admin.restore:
description: Restore a player's inventory.
default: false
mobarena.admin.force.end:
description: Force end an arena.
default: false
mobarena.admin.force.start:
description: Force start an arena.
default: false
mobarena.admin.config.reload:
description: Reload the config-file.
default: false
mobarena.setup:
description: Gives access to all setup commands
default: op
children:
mobarena.setup.arena: true
mobarena.setup.setarena: true
mobarena.setup.addarena: true
mobarena.setup.delarena: true
mobarena.setup.protect: true
mobarena.setup.editarena: true
mobarena.setup.setregion: true
mobarena.setup.expandregion: true
mobarena.setup.showregion: true
mobarena.setup.setlobbyregion: true
mobarena.setup.expandlobbyregion: true
mobarena.setup.setwarp: true
mobarena.setup.spawnpoints: true
mobarena.setup.addspawn: true
mobarena.setup.delspawn: true
mobarena.setup.containers: true
mobarena.setup.addcontainer: true
mobarena.setup.delcontainer: true
mobarena.setup.leaderboards: true
mobarena.setup.checkdata: true
mobarena.setup.autogenerate: true
mobarena.setup.autodegenerate: true
mobarena.setup.arena:
description: Check which arena is the currently selected arena.
default: false
mobarena.setup.setarena:
description: Select a new arena.
default: false
mobarena.setup.addarena:
description: Add a new arena node.
default: false
mobarena.setup.delarena:
description: Delete an arena.
default: false
mobarena.setup.protect:
description: Turn arena protection on/off.
default: false
mobarena.setup.editarena:
description: Turn editmode on/off.
default: false
mobarena.setup.setregion:
description: Set region points p1/p2.
default: false
mobarena.setup.expandregion:
description: Expand arena region.
default: false
mobarena.setup.showregion:
description: Show arena region.
default: false
mobarena.setup.setlobbyregion:
description: Set lobby region points l1/l2.
default: false
mobarena.setup.expandlobbyregion:
description: Expand lobby region.
default: false
mobarena.setup.setwarp:
description: Set warp points arena/lobby/spectator.
default: false
mobarena.setup.spawnpoints:
description: List all spawnpoints.
default: false
mobarena.setup.addspawn:
description: Add a new spawnpoint.
default: false
mobarena.setup.delspawn:
description: Delete a spawnpoint.
default: false
mobarena.setup.containers:
description: List all containers.
default: false
mobarena.setup.addcontainer:
description: Add a new container.
default: false
mobarena.setup.delcontainer:
description: Delete a container.
default: false
mobarena.setup.leaderboards:
description: Set up leaderboards.
default: false
mobarena.setup.checkdata:
description: Check which points need to be set up.
default: false
mobarena.setup.autogenerate:
description: Auto-generate an arena.
default: false
mobarena.setup.autodegenerate:
description: Auto-degenerate an arena.
default: false

File diff suppressed because it is too large Load Diff

View File

@ -2,32 +2,28 @@ package com.garbagemule.MobArena;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.util.config.Configuration; //import org.bukkit.util.config.Configuration;
//import com.garbagemule.ArenaPlugin.Master; //import com.garbagemule.ArenaPlugin.Master;
public class ArenaMaster //implements Master public abstract class ArenaMaster //implements Master
{ {
private MobArena plugin;
private Configuration config;
protected Arena selectedArena; protected Arena selectedArena;
// Settings // Settings
protected boolean enabled, updateNotify; protected boolean enabled, updateNotify;
// Classes // Classes
protected List<String> classes; protected Set<String> classes;
protected Map<String,List<ItemStack>> classItems, classArmor; protected Map<String,List<ItemStack>> classItems, classArmor;
protected Map<String,Map<String,Boolean>> classPerms; protected Map<String,Map<String,Boolean>> classPerms;
//protected Map<Integer,Map<Player,List<ItemStack>>> classBonuses; //protected Map<Integer,Map<Player,List<ItemStack>>> classBonuses;
@ -44,131 +40,40 @@ public class ArenaMaster //implements Master
/**
* Default constructor.
*/
public ArenaMaster(MobArena instance)
{
plugin = instance;
config = plugin.getMAConfig();
arenas = new LinkedList<Arena>();
arenaMap = new HashMap<Player,Arena>();
}
/*///////////////////////////////////////////////////////////////////////// /*/////////////////////////////////////////////////////////////////////////
// //
// Arena getters // Arena getters
// //
/////////////////////////////////////////////////////////////////////////*/ /////////////////////////////////////////////////////////////////////////*/
public List<Arena> getEnabledArenas()
{ public abstract List<Arena> getEnabledArenas();
List<Arena> result = new LinkedList<Arena>();
for (Arena arena : arenas)
if (arena.enabled)
result.add(arena);
return result;
}
public List<Arena> getPermittedArenas(Player p) public abstract 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) public abstract Arena getArenaAtLocation(Location loc);
{
for (Arena arena : arenas)
if (arena.inRegion(loc))
return arena;
return null;
}
public List<Arena> getArenasInWorld(World world) public abstract List<Arena> getArenasInWorld(World world);
{
List<Arena> result = new LinkedList<Arena>();
for (Arena arena : arenas)
if (arena.world.equals(world))
result.add(arena);
return result;
}
public List<Player> getAllPlayers() public abstract List<Player> getAllPlayers();
{
List<Player> result = new LinkedList<Player>();
for (Arena arena : arenas)
result.addAll(arena.getAllPlayers());
return result;
}
public List<Player> getAllPlayersInArena(String arenaName) public abstract List<Player> getAllPlayersInArena(String arenaName);
{
Arena arena = getArenaWithName(arenaName);
return (arena != null) ? arena.getLivingPlayers() : new LinkedList<Player>();
}
public List<Player> getAllLivingPlayers() public abstract List<Player> getAllLivingPlayers();
{
List<Player> result = new LinkedList<Player>();
for (Arena arena : arenas)
result.addAll(arena.getLivingPlayers());
return result;
}
public List<Player> getLivingPlayersInArena(String arenaName) public abstract List<Player> getLivingPlayersInArena(String arenaName);
{
Arena arena = getArenaWithName(arenaName);
return (arena != null) ? arena.getLivingPlayers() : new LinkedList<Player>();
}
public Arena getArenaWithPlayer(Player p) public abstract Arena getArenaWithPlayer(Player p);
{
return arenaMap.get(p);
}
public Arena getArenaWithPlayer(String playerName) public abstract Arena getArenaWithPlayer(String playerName);
{
return arenaMap.get(Bukkit.getServer().getPlayer(playerName));
}
public Arena getArenaWithSpectator(Player p) public abstract Arena getArenaWithSpectator(Player p);
{
for (Arena arena : arenas)
{
if (arena.specPlayers.contains(p))
return arena;
}
return null;
}
public Arena getArenaWithMonster(Entity e) public abstract Arena getArenaWithMonster(Entity e);
{
for (Arena arena : arenas)
if (arena.monsters.contains(e))
return arena;
return null;
}
public Arena getArenaWithPet(Entity e) public abstract Arena getArenaWithPet(Entity e);
{
for (Arena arena : arenas)
if (arena.pets.contains(e))
return arena;
return null;
}
public Arena getArenaWithName(String configName) public abstract Arena getArenaWithName(String configName);
{
for (Arena arena : arenas)
if (arena.configName().equals(configName))
return arena;
return null;
}
@ -178,140 +83,26 @@ public class ArenaMaster //implements Master
// //
/////////////////////////////////////////////////////////////////////////*/ /////////////////////////////////////////////////////////////////////////*/
public void initialize() public abstract void initialize();
{
config.load();
loadSettings();
loadClasses();
loadArenas();
config.save();
}
/** /**
* Load the global settings. * Load the global settings.
*/ */
public void loadSettings() public abstract void loadSettings();
{
if (config.getKeys("global-settings") == null)
{
config.setProperty("global-settings.enabled", true);
config.setProperty("global-settings.update-notification", true);
}
enabled = config.getBoolean("global-settings.enabled", true);
updateNotify = config.getBoolean("global-settings.update-notification", true);
}
/** /**
* Load all class-related stuff. * Load all class-related stuff.
*/ */
public void loadClasses() public abstract void loadClasses();
{
classes = config.getKeys("classes");
if (classes == null)
{
config.setProperty("classes.Archer.items", "wood_sword, bow, arrow:128, grilled_pork");
config.setProperty("classes.Archer.armor", "298,299,300,301");
config.setProperty("classes.Knight.items", "diamond_sword, grilled_pork:2");
config.setProperty("classes.Knight.armor", "306,307,308,309");
config.setProperty("classes.Tank.items", "iron_sword, grilled_pork:3, apple");
config.setProperty("classes.Tank.armor", "310,311,312,313");
config.setProperty("classes.Oddjob.items", "stone_sword, flint_and_steel, netherrack:2, wood_pickaxe, tnt:4, fishing_rod, apple, grilled_pork:3");
config.setProperty("classes.Oddjob.armor", "298,299,300,301");
config.setProperty("classes.Chef.items", "stone_sword, bread:6, grilled_pork:4, mushroom_soup, cake:3, cookie:12");
config.setProperty("classes.Chef.armor", "314,315,316,317");
classes = config.getKeys("classes");
}
classItems = MAUtils.getClassItems(config, "items");
classArmor = MAUtils.getClassItems(config, "armor");
classPerms = MAUtils.getClassPerms(config);
}
/** /**
* Load all arena-related stuff. * Load all arena-related stuff.
*/ */
public void loadArenas() public abstract void loadArenas();
{
arenas = new LinkedList<Arena>();
if (config.getKeys("arenas") == null)
createArenaNode("default", Bukkit.getServer().getWorlds().get(0));
for (String configName : config.getKeys("arenas"))
{
String arenaPath = "arenas." + configName + ".";
String worldName = config.getString(arenaPath + "settings.world", null);
World world;
if (worldName == null || worldName.equals(""))
{
MobArena.warning("Could not find the world for arena '" + configName + "'. Using default world! Check the config-file!");
world = Bukkit.getServer().getWorlds().get(0);
}
else world = Bukkit.getServer().getWorld(worldName);
Arena arena = new Arena(MAUtils.nameConfigToArena(configName), world);
arena.load(config);
arenas.add(arena);
}
selectedArena = arenas.get(0);
}
public Arena createArenaNode(String configName, World world) public abstract Arena createArenaNode(String configName, World world);
{
config.setProperty("arenas." + configName + ".settings.world", world.getName());
config.save();
config.load();
config.setProperty("arenas." + configName + ".settings.enabled", true);
config.save();
config.load();
config.setProperty("arenas." + configName + ".settings.protect", true);
config.save();
config.load();
config.setProperty("arenas." + configName + ".settings.entry-fee", "");
config.save();
config.load();
config.setProperty("arenas." + configName + ".settings.logging", false);
config.setProperty("arenas." + configName + ".settings.clear-wave-before-next", false);
config.setProperty("arenas." + configName + ".settings.detonate-creepers", false);
config.setProperty("arenas." + configName + ".settings.detonate-damage", false);
config.setProperty("arenas." + configName + ".settings.lightning", true);
config.setProperty("arenas." + configName + ".settings.auto-equip-armor", true);
config.setProperty("arenas." + configName + ".settings.force-restore", false);
config.setProperty("arenas." + configName + ".settings.soft-restore", false);
config.setProperty("arenas." + configName + ".settings.soft-restore-drops", false);
config.setProperty("arenas." + configName + ".settings.require-empty-inv-join", true);
config.setProperty("arenas." + configName + ".settings.require-empty-inv-spec", true);
config.setProperty("arenas." + configName + ".settings.hellhounds", false);
config.setProperty("arenas." + configName + ".settings.pvp-enabled", false);
config.setProperty("arenas." + configName + ".settings.monster-infight", false);
config.setProperty("arenas." + configName + ".settings.allow-teleporting", false);
config.setProperty("arenas." + configName + ".settings.spectate-on-death", true);
config.setProperty("arenas." + configName + ".settings.share-items-in-arena", true);
config.save();
config.load();
config.setProperty("arenas." + configName + ".settings.player-limit", 0);
config.setProperty("arenas." + configName + ".settings.max-join-distance", 0);
config.save();
config.load();
config.setProperty("arenas." + configName + ".settings.repair-delay", 5);
config.setProperty("arenas." + configName + ".settings.first-wave-delay", 5);
config.setProperty("arenas." + configName + ".settings.wave-interval", 20);
config.setProperty("arenas." + configName + ".settings.special-modulo", 4);
config.setProperty("arenas." + configName + ".settings.max-idle-time", 0);
config.save();
config.load();
Arena arena = new Arena(MAUtils.nameConfigToArena(configName), world);
arena.load(config);
return arena;
}
public void removeArenaNode(String configName) public abstract void removeArenaNode(String configName);
{
config.removeProperty("arenas." + configName);
config.save();
}
@ -325,73 +116,27 @@ public class ArenaMaster //implements Master
* Update one, two or all three of global settings, classes * Update one, two or all three of global settings, classes
* and arenas (arenas with deserialization). * and arenas (arenas with deserialization).
*/ */
public void update(boolean settings, boolean classes, boolean arenalist) public abstract void update(boolean settings, boolean classes, boolean arenalist);
{
boolean tmp = enabled;
enabled = false;
for (Arena arena : arenas)
arena.forceEnd();
config.load();
if (settings) loadSettings();
if (classes) loadClasses();
if (arenalist) deserializeArenas();
config.save();
enabled = tmp;
}
/** /**
* Serialize the global settings. * Serialize the global settings.
*/ */
public void serializeSettings() public abstract void serializeSettings();
{
String settings = "global-settings.";
config.setProperty(settings + "enabled", enabled);
config.save();
}
/** /**
* Serialize all arena configs. * Serialize all arena configs.
*/ */
public void serializeArenas() public abstract void serializeArenas();
{
for (Arena arena : arenas)
arena.serializeConfig();
}
/** /**
* Deserialize all arena configs. Updates the arena list to * Deserialize all arena configs. Updates the arena list to
* include only the current arenas (not ones added in the * include only the current arenas (not ones added in the
* actual file) that are also in the config-file. * actual file) that are also in the config-file.
*/ */
public void deserializeArenas() public abstract void deserializeArenas();
{
// Get only the arenas in the config.
List<String> strings = config.getKeys("arenas");
if (strings == null)
return;
// Get their Arena objects.
List<Arena> configArenas = new LinkedList<Arena>();
for (String s : strings)
if (getArenaWithName(s) != null)
configArenas.add(getArenaWithName(s));
// Remove all Arenas no longer in the config.
arenas.retainAll(configArenas);
for (Arena arena : arenas)
arena.deserializeConfig();
// Make sure to update the selected arena to a valid one.
if (!arenas.contains(selectedArena) && arenas.size() >= 1)
selectedArena = arenas.get(0);
}
public void updateSettings() { update(true, false, false); } public abstract void updateSettings();
public void updateClasses() { update(false, true, false); } public abstract void updateClasses();
public void updateArenas() { update(false, false, true); } public abstract void updateArenas();
public void updateAll() { update(true, true, true); } public abstract void updateAll();
} }

View File

@ -0,0 +1,397 @@
package com.garbagemule.MobArena;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
//import org.bukkit.util.config.Configuration;
import com.garbagemule.MobArena.util.Config;
//import com.garbagemule.ArenaPlugin.Master;
public class ArenaMasterStandard extends ArenaMaster
{
private MobArena plugin;
//private Configuration config;
private Config config;
//protected Arena selectedArena;
// Settings
//protected boolean enabled, updateNotify;
// Classes
//protected Set<String> classes;
//protected Map<String,List<ItemStack>> classItems, classArmor;
//protected Map<String,Map<String,Boolean>> classPerms;
//protected Map<Integer,Map<Player,List<ItemStack>>> classBonuses;
//protected Map<Player,Arena> arenaMap;
// Location map
//protected Map<Player,Location> locations = new HashMap<Player,Location>();
// Arena list
//protected List<Arena> arenas;
// Listeners
//protected Set<MobArenaListener> listeners = new HashSet<MobArenaListener>();
/**
* Default constructor.
*/
public ArenaMasterStandard(MobArenaPlugin instance)
{
plugin = (MobArena) instance;
config = plugin.getMAConfig();
arenas = new LinkedList<Arena>();
arenaMap = new HashMap<Player,Arena>();
}
/*/////////////////////////////////////////////////////////////////////////
//
// Arena getters
//
/////////////////////////////////////////////////////////////////////////*/
public List<Arena> getEnabledArenas()
{
List<Arena> result = new LinkedList<Arena>();
for (Arena arena : arenas)
if (arena.enabled)
result.add(arena);
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)
if (arena.inRegion(loc))
return arena;
return null;
}
public List<Arena> getArenasInWorld(World world)
{
List<Arena> result = new LinkedList<Arena>();
for (Arena arena : arenas)
if (arena.world.equals(world))
result.add(arena);
return result;
}
public List<Player> getAllPlayers()
{
List<Player> result = new LinkedList<Player>();
for (Arena arena : arenas)
result.addAll(arena.getAllPlayers());
return result;
}
public List<Player> getAllPlayersInArena(String arenaName)
{
Arena arena = getArenaWithName(arenaName);
return (arena != null) ? arena.getLivingPlayers() : new LinkedList<Player>();
}
public List<Player> getAllLivingPlayers()
{
List<Player> result = new LinkedList<Player>();
for (Arena arena : arenas)
result.addAll(arena.getLivingPlayers());
return result;
}
public List<Player> getLivingPlayersInArena(String arenaName)
{
Arena arena = getArenaWithName(arenaName);
return (arena != null) ? arena.getLivingPlayers() : new LinkedList<Player>();
}
public Arena getArenaWithPlayer(Player p)
{
return arenaMap.get(p);
}
public Arena getArenaWithPlayer(String playerName)
{
return arenaMap.get(Bukkit.getServer().getPlayer(playerName));
}
public Arena getArenaWithSpectator(Player p)
{
for (Arena arena : arenas)
{
if (arena.specPlayers.contains(p))
return arena;
}
return null;
}
public Arena getArenaWithMonster(Entity e)
{
for (Arena arena : arenas)
if (arena.monsters.contains(e))
return arena;
return null;
}
public Arena getArenaWithPet(Entity e)
{
for (Arena arena : arenas)
if (arena.pets.contains(e))
return arena;
return null;
}
public Arena getArenaWithName(String configName)
{
for (Arena arena : arenas)
if (arena.configName().equals(configName))
return arena;
return null;
}
/*/////////////////////////////////////////////////////////////////////////
//
// Initialization
//
/////////////////////////////////////////////////////////////////////////*/
public void initialize()
{
config.load();
loadSettings();
loadClasses();
loadArenas();
config.save();
}
/**
* Load the global settings.
*/
public void loadSettings()
{
if (config.getKeys("global-settings") == null)
{
config.setProperty("global-settings.enabled", true);
config.setProperty("global-settings.update-notification", true);
}
enabled = config.getBoolean("global-settings.enabled", true);
updateNotify = config.getBoolean("global-settings.update-notification", true);
}
/**
* Load all class-related stuff.
*/
public void loadClasses()
{
classes = config.getKeys("classes");
if (classes == null)
{
config.setProperty("classes.Archer.items", "wood_sword, bow, arrow:128, grilled_pork");
config.setProperty("classes.Archer.armor", "298,299,300,301");
config.setProperty("classes.Knight.items", "diamond_sword, grilled_pork:2");
config.setProperty("classes.Knight.armor", "306,307,308,309");
config.setProperty("classes.Tank.items", "iron_sword, grilled_pork:3, apple");
config.setProperty("classes.Tank.armor", "310,311,312,313");
config.setProperty("classes.Oddjob.items", "stone_sword, flint_and_steel, netherrack:2, wood_pickaxe, tnt:4, fishing_rod, apple, grilled_pork:3");
config.setProperty("classes.Oddjob.armor", "298,299,300,301");
config.setProperty("classes.Chef.items", "stone_sword, bread:6, grilled_pork:4, mushroom_soup, cake:3, cookie:12");
config.setProperty("classes.Chef.armor", "314,315,316,317");
classes = config.getKeys("classes");
}
classItems = MAUtils.getClassItems(config, "items");
classArmor = MAUtils.getClassItems(config, "armor");
classPerms = MAUtils.getClassPerms(config);
}
/**
* Load all arena-related stuff.
*/
public void loadArenas()
{
arenas = new LinkedList<Arena>();
if (config.getKeys("arenas") == null)
createArenaNode("default", Bukkit.getServer().getWorlds().get(0));
for (String configName : config.getKeys("arenas"))
{
String arenaPath = "arenas." + configName + ".";
String worldName = config.getString(arenaPath + "settings.world", null);
World world;
if (worldName == null || worldName.equals(""))
{
MobArena.warning("Could not find the world for arena '" + configName + "'. Using default world! Check the config-file!");
world = Bukkit.getServer().getWorlds().get(0);
}
else world = Bukkit.getServer().getWorld(worldName);
Arena arena = new ArenaStandard(MAUtils.nameConfigToArena(configName), world);
arena.load(config);
arenas.add(arena);
}
selectedArena = arenas.get(0);
}
public Arena createArenaNode(String configName, World world)
{
config.setProperty("arenas." + configName + ".settings.world", world.getName());
config.save();
config.load();
config.setProperty("arenas." + configName + ".settings.enabled", true);
config.save();
config.load();
config.setProperty("arenas." + configName + ".settings.protect", true);
config.save();
config.load();
config.setProperty("arenas." + configName + ".settings.entry-fee", "");
config.save();
config.load();
config.setProperty("arenas." + configName + ".settings.logging", false);
config.setProperty("arenas." + configName + ".settings.clear-wave-before-next", false);
config.setProperty("arenas." + configName + ".settings.detonate-creepers", false);
config.setProperty("arenas." + configName + ".settings.detonate-damage", false);
config.setProperty("arenas." + configName + ".settings.lightning", true);
config.setProperty("arenas." + configName + ".settings.auto-equip-armor", true);
config.setProperty("arenas." + configName + ".settings.force-restore", false);
config.setProperty("arenas." + configName + ".settings.soft-restore", false);
config.setProperty("arenas." + configName + ".settings.soft-restore-drops", false);
config.setProperty("arenas." + configName + ".settings.require-empty-inv-join", true);
config.setProperty("arenas." + configName + ".settings.require-empty-inv-spec", true);
config.setProperty("arenas." + configName + ".settings.hellhounds", false);
config.setProperty("arenas." + configName + ".settings.pvp-enabled", false);
config.setProperty("arenas." + configName + ".settings.monster-infight", false);
config.setProperty("arenas." + configName + ".settings.allow-teleporting", false);
config.setProperty("arenas." + configName + ".settings.spectate-on-death", true);
config.setProperty("arenas." + configName + ".settings.share-items-in-arena", true);
config.save();
config.load();
config.setProperty("arenas." + configName + ".settings.player-limit", 0);
config.setProperty("arenas." + configName + ".settings.max-join-distance", 0);
config.save();
config.load();
config.setProperty("arenas." + configName + ".settings.repair-delay", 5);
config.setProperty("arenas." + configName + ".settings.first-wave-delay", 5);
config.setProperty("arenas." + configName + ".settings.wave-interval", 20);
config.setProperty("arenas." + configName + ".settings.special-modulo", 4);
config.setProperty("arenas." + configName + ".settings.max-idle-time", 0);
config.save();
config.load();
Arena arena = new ArenaStandard(MAUtils.nameConfigToArena(configName), world);
arena.load(config);
return arena;
}
public void removeArenaNode(String configName)
{
config.removeProperty("arenas." + configName);
config.save();
}
/*/////////////////////////////////////////////////////////////////////////
//
// Update and serialization methods
//
/////////////////////////////////////////////////////////////////////////*/
/**
* Update one, two or all three of global settings, classes
* and arenas (arenas with deserialization).
*/
public void update(boolean settings, boolean classes, boolean arenalist)
{
boolean tmp = enabled;
enabled = false;
for (Arena arena : arenas)
arena.forceEnd();
config.load();
if (settings) loadSettings();
if (classes) loadClasses();
if (arenalist) deserializeArenas();
config.save();
enabled = tmp;
}
/**
* Serialize the global settings.
*/
public void serializeSettings()
{
String settings = "global-settings.";
config.setProperty(settings + "enabled", enabled);
config.save();
}
/**
* Serialize all arena configs.
*/
public void serializeArenas()
{
for (Arena arena : arenas)
arena.serializeConfig();
}
/**
* Deserialize all arena configs. Updates the arena list to
* include only the current arenas (not ones added in the
* actual file) that are also in the config-file.
*/
public void deserializeArenas()
{
// Get only the arenas in the config.
Set<String> strings = config.getKeys("arenas");
if (strings == null)
return;
// Get their Arena objects.
List<Arena> configArenas = new LinkedList<Arena>();
for (String s : strings)
if (getArenaWithName(s) != null)
configArenas.add(getArenaWithName(s));
// Remove all Arenas no longer in the config.
arenas.retainAll(configArenas);
for (Arena arena : arenas)
arena.deserializeConfig();
// Make sure to update the selected arena to a valid one.
if (!arenas.contains(selectedArena) && arenas.size() >= 1)
selectedArena = arenas.get(0);
}
public void updateSettings() { update(true, false, false); }
public void updateClasses() { update(false, true, false); }
public void updateArenas() { update(false, false, true); }
public void updateAll() { update(true, true, true); }
}

File diff suppressed because it is too large Load Diff

View File

@ -73,6 +73,11 @@ public class MACommands implements CommandExecutor
private MobArena plugin; private MobArena plugin;
private ArenaMaster am; private ArenaMaster am;
public MACommands()
{
}
public MACommands(MobArena plugin, ArenaMaster am) public MACommands(MobArena plugin, ArenaMaster am)
{ {
this.plugin = plugin; this.plugin = plugin;
@ -1029,7 +1034,7 @@ public class MACommands implements CommandExecutor
} }
StringBuffer buffy = new StringBuffer(); StringBuffer buffy = new StringBuffer();
List<String> spawnpoints = plugin.getMAConfig().getKeys("arenas." + am.selectedArena.configName() + ".coords.spawnpoints"); Set<String> spawnpoints = plugin.getMAConfig().getKeys("arenas." + am.selectedArena.configName() + ".coords.spawnpoints");
if (spawnpoints != null) if (spawnpoints != null)
{ {
@ -1101,7 +1106,7 @@ public class MACommands implements CommandExecutor
} }
StringBuffer buffy = new StringBuffer(); StringBuffer buffy = new StringBuffer();
List<String> containers = plugin.getMAConfig().getKeys("arenas." + am.selectedArena.configName() + ".coords.containers"); Set<String> containers = plugin.getMAConfig().getKeys("arenas." + am.selectedArena.configName() + ".coords.containers");
if (containers != null) if (containers != null)
{ {

View File

@ -33,11 +33,12 @@ import org.bukkit.entity.Player;
import org.bukkit.entity.Wolf; import org.bukkit.entity.Wolf;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory; import org.bukkit.inventory.PlayerInventory;
import org.bukkit.util.config.Configuration; //import org.bukkit.util.config.Configuration;
import org.getspout.spoutapi.SpoutManager; import org.getspout.spoutapi.SpoutManager;
import org.getspout.spoutapi.player.SpoutPlayer; import org.getspout.spoutapi.player.SpoutPlayer;
import com.garbagemule.MobArena.MAMessages.Msg; import com.garbagemule.MobArena.MAMessages.Msg;
import com.garbagemule.MobArena.util.Config;
import com.garbagemule.MobArena.util.EntityPosition; import com.garbagemule.MobArena.util.EntityPosition;
import com.garbagemule.MobArena.util.InventoryItem; import com.garbagemule.MobArena.util.InventoryItem;
@ -136,7 +137,7 @@ public class MAUtils
// ///////////////////////////////////////////////////////////////////// */ // ///////////////////////////////////////////////////////////////////// */
public static Map<String,Location> getArenaContainers(Configuration config, World world, String arena) public static Map<String,Location> getArenaContainers(Config config, World world, String arena)
{ {
Map<String,Location> containers = new HashMap<String,Location>(); Map<String,Location> containers = new HashMap<String,Location>();
String arenaPath = "arenas." + arena + ".coords.containers"; String arenaPath = "arenas." + arena + ".coords.containers";
@ -153,7 +154,7 @@ public class MAUtils
/** /**
* Grab all the spawnpoints for a specific arena. * Grab all the spawnpoints for a specific arena.
*/ */
public static Map<String,Location> getArenaSpawnpoints(Configuration config, World world, String arena) public static Map<String,Location> getArenaSpawnpoints(Config config, World world, String arena)
{ {
Map<String,Location> spawnpoints = new HashMap<String,Location>(); Map<String,Location> spawnpoints = new HashMap<String,Location>();
String arenaPath = "arenas." + arena + ".coords.spawnpoints"; String arenaPath = "arenas." + arena + ".coords.spawnpoints";
@ -168,7 +169,7 @@ public class MAUtils
return spawnpoints; return spawnpoints;
} }
public static Map<String,Location> getArenaBossSpawnpoints(Configuration config, World world, String arena) public static Map<String,Location> getArenaBossSpawnpoints(Config config, World world, String arena)
{ {
Map<String,Location> spawnpoints = new HashMap<String,Location>(); Map<String,Location> spawnpoints = new HashMap<String,Location>();
String arenaPath = "arenas." + arena + ".coords.spawnpoints"; String arenaPath = "arenas." + arena + ".coords.spawnpoints";
@ -186,7 +187,7 @@ public class MAUtils
/** /**
* Returns a map of classnames mapped to lists of ItemStacks. * Returns a map of classnames mapped to lists of ItemStacks.
*/ */
public static Map<String,List<ItemStack>> getClassItems(Configuration config, String type) public static Map<String,List<ItemStack>> getClassItems(Config config, String type)
{ {
Map<String,List<ItemStack>> result = new HashMap<String,List<ItemStack>>(); Map<String,List<ItemStack>> result = new HashMap<String,List<ItemStack>>();
@ -196,11 +197,11 @@ public class MAUtils
return result; return result;
} }
public static Map<String,Map<String,Boolean>> getClassPerms(Configuration config) public static Map<String,Map<String,Boolean>> getClassPerms(Config config)
{ {
Map<String, Map<String,Boolean>> result = new HashMap<String, Map<String,Boolean>>(); Map<String, Map<String,Boolean>> result = new HashMap<String, Map<String,Boolean>>();
List<String> classes = config.getKeys("classes"); Set<String> classes = config.getKeys("classes");
if (classes == null) return result; if (classes == null) return result;
for (String c : classes) for (String c : classes)
@ -224,7 +225,7 @@ public class MAUtils
return result; return result;
} }
public static List<ItemStack> getEntryFee(Configuration config, String arena) public static List<ItemStack> getEntryFee(Config config, String arena)
{ {
return makeItemStackList(config.getString("arenas." + arena + ".settings.entry-fee", null)); return makeItemStackList(config.getString("arenas." + arena + ".settings.entry-fee", null));
} }
@ -276,7 +277,7 @@ public class MAUtils
* type of wave ("after" or "every") and the config-file. If * type of wave ("after" or "every") and the config-file. If
* no keys exist in the config-file, an empty map is returned. * no keys exist in the config-file, an empty map is returned.
*/ */
public static Map<Integer,List<ItemStack>> getArenaRewardMap(Configuration config, String arena, String type) public static Map<Integer,List<ItemStack>> getArenaRewardMap(Config config, String arena, String type)
{ {
String arenaPath = "arenas." + arena + ".rewards.waves."; String arenaPath = "arenas." + arena + ".rewards.waves.";
Map<Integer,List<ItemStack>> result = new HashMap<Integer,List<ItemStack>>(); Map<Integer,List<ItemStack>> result = new HashMap<Integer,List<ItemStack>>();
@ -297,7 +298,7 @@ public class MAUtils
} }
} }
List<String> waves = config.getKeys(arenaPath + type); Set<String> waves = config.getKeys(arenaPath + type);
if (waves == null) return result; if (waves == null) return result;
for (String n : waves) for (String n : waves)
@ -313,7 +314,7 @@ public class MAUtils
return result; return result;
} }
public static List<String> getAllowedCommands(Configuration config) public static List<String> getAllowedCommands(Config config)
{ {
String commands = config.getString("global-settings.allowed-commands"); String commands = config.getString("global-settings.allowed-commands");
if (commands == null) if (commands == null)
@ -768,7 +769,7 @@ public class MAUtils
/** /**
* Create a Location object from the config-file. * Create a Location object from the config-file.
*/ */
public static Location getArenaCoord(Configuration config, World world, String arena, String coord) public static Location getArenaCoord(Config config, World world, String arena, String coord)
{ {
//config.load(); //config.load();
String str = config.getString("arenas." + arena + ".coords." + coord); String str = config.getString("arenas." + arena + ".coords." + coord);
@ -778,9 +779,9 @@ public class MAUtils
} }
/** /**
* Save an arena location to the Configuration. * Save an arena location to the Config.
*/ */
public static void setArenaCoord(Configuration config, Arena arena, String coord, Location loc) public static void setArenaCoord(Config config, Arena arena, String coord, Location loc)
{ {
if (coord.equals("arena") || coord.equals("lobby") || coord.equals("spectator")) if (coord.equals("arena") || coord.equals("lobby") || coord.equals("spectator"))
loc.setY(loc.getY() + 1); loc.setY(loc.getY() + 1);
@ -795,7 +796,7 @@ public class MAUtils
fixLobby(config, loc.getWorld(), arena); fixLobby(config, loc.getWorld(), arena);
} }
public static boolean delArenaCoord(Configuration config, Arena arena, String coord) public static boolean delArenaCoord(Config config, Arena arena, String coord)
{ {
if (config.getString("arenas." + arena.configName() + ".coords." + coord) == null) if (config.getString("arenas." + arena.configName() + ".coords." + coord) == null)
return false; return false;
@ -806,7 +807,7 @@ public class MAUtils
return true; return true;
} }
public static void fixRegion(Configuration config, World world, Arena arena) public static void fixRegion(Config config, World world, Arena arena)
{ {
if (arena.p1 == null || arena.p2 == null) if (arena.p1 == null || arena.p2 == null)
return; return;
@ -839,7 +840,7 @@ public class MAUtils
arena.load(config); arena.load(config);
} }
private static void fixLobby(Configuration config, World world, Arena arena) private static void fixLobby(Config config, World world, Arena arena)
{ {
if (arena.l1 == null || arena.l2 == null) if (arena.l1 == null || arena.l2 == null)
return; return;
@ -932,12 +933,12 @@ public class MAUtils
return false; return false;
} }
public static double getDouble(Configuration config, String path) public static double getDouble(Config config, String path)
{ {
return getDouble(config, path, 0D); return getDouble(config, path, 0D);
} }
public static double getDouble(Configuration config, String path, double def) public static double getDouble(Config config, String path, double def)
{ {
Object o = config.getProperty(path); Object o = config.getProperty(path);
if (o instanceof Double) if (o instanceof Double)
@ -947,12 +948,12 @@ public class MAUtils
return def; return def;
} }
public static int getInt(Configuration config, String path) public static int getInt(Config config, String path)
{ {
return getInt(config, path, 0); return getInt(config, path, 0);
} }
public static int getInt(Configuration config, String path, int def) public static int getInt(Config config, String path, int def)
{ {
Object o = config.getProperty(path); Object o = config.getProperty(path);
if (o instanceof Integer) if (o instanceof Integer)
@ -1638,7 +1639,7 @@ public class MAUtils
world.getBlockAt(entry.getKey().getLocation(world)).setTypeId(entry.getValue()); world.getBlockAt(entry.getKey().getLocation(world)).setTypeId(entry.getValue());
} }
Configuration config = plugin.getMAConfig(); Config config = plugin.getMAConfig();
config.removeProperty("arenas." + name); config.removeProperty("arenas." + name);
config.save(); config.save();

View File

@ -14,10 +14,11 @@ import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.bukkit.util.config.Configuration; //import org.bukkit.util.config.Configuration;
import com.garbagemule.MobArena.listeners.MagicSpellsListener; import com.garbagemule.MobArena.listeners.MagicSpellsListener;
import com.garbagemule.MobArena.spout.Spouty; import com.garbagemule.MobArena.spout.Spouty;
import com.garbagemule.MobArena.util.Config;
import com.garbagemule.MobArena.util.FileUtils; import com.garbagemule.MobArena.util.FileUtils;
import com.garbagemule.register.payment.Method; import com.garbagemule.register.payment.Method;
import com.garbagemule.register.payment.Methods; import com.garbagemule.register.payment.Methods;
@ -26,9 +27,10 @@ import com.garbagemule.register.payment.Methods;
* MobArena * MobArena
* @author garbagemule * @author garbagemule
*/ */
public class MobArena extends JavaPlugin public class MobArena extends JavaPlugin implements MobArenaPlugin
{ {
private Configuration config; //private Configuration config;
private Config config;
private ArenaMaster am; private ArenaMaster am;
// Economy stuff // Economy stuff
@ -54,7 +56,7 @@ public class MobArena extends JavaPlugin
desc = getDescription(); desc = getDescription();
dir = getDataFolder(); dir = getDataFolder();
arenaDir = new File(dir, "arenas"); arenaDir = new File(dir, "arenas");
if (!dir.exists()) dir.mkdir(); if (!dir.exists()) dir.mkdirs();
if (!arenaDir.exists()) arenaDir.mkdir(); if (!arenaDir.exists()) arenaDir.mkdir();
// Create default files and initialize config-file // Create default files and initialize config-file
@ -71,8 +73,9 @@ public class MobArena extends JavaPlugin
setupMagicSpells(); setupMagicSpells();
// Set up the ArenaMaster and the announcements // Set up the ArenaMaster and the announcements
am = new ArenaMaster(this); am = new ArenaMasterStandard(this);
am.initialize(); am.initialize();
System.out.println(am.arenas);
MAMessages.init(this); MAMessages.init(this);
// Register event listeners // Register event listeners
@ -99,7 +102,7 @@ public class MobArena extends JavaPlugin
private void loadConfig() private void loadConfig()
{ {
File file = new File(dir, "config.yml"); File file = new File(dir, "config.yml");
config = new Configuration(file); config = new Config(file);
config.load(); config.load();
config.setHeader(getHeader()); config.setHeader(getHeader());
} }
@ -199,8 +202,10 @@ public class MobArena extends JavaPlugin
pm.registerEvent(Event.Type.CUSTOM_EVENT, new MagicSpellsListener(this), Priority.Normal, this); pm.registerEvent(Event.Type.CUSTOM_EVENT, new MagicSpellsListener(this), Priority.Normal, this);
} }
public Configuration getMAConfig() { return config; } public Config getMAConfig() { return config; }
public ArenaMaster getAM() { return am; } // More convenient. public ArenaMaster getAM() { return am; } // More convenient.
@Override
public ArenaMaster getArenaMaster() { return am; } public ArenaMaster getArenaMaster() { return am; }
/*public HeroManager getHeroManager() /*public HeroManager getHeroManager()

View File

@ -0,0 +1,6 @@
package com.garbagemule.MobArena;
public interface MobArenaPlugin
{
public ArenaMaster getArenaMaster();
}

View File

@ -0,0 +1,123 @@
package com.garbagemule.MobArena.commands;
import java.io.File;
import java.util.*;
import org.bukkit.command.*;
import org.bukkit.entity.Player;
import com.garbagemule.MobArena.*;
import com.garbagemule.MobArena.util.classparsing.*;
public class CommandHandler implements CommandExecutor
{
/* COMMAND_PATH is an incomplete package-name for all commands in MobArena,
* hence the trailing dot, and the COMMAND_TYPES array contains all the
* different types of commands (the sub-folders). Both are used in the
* loadCommands() method. */
private static final String COMMAND_PATH = "com.garbagemule.MobArena.commands.";
private static final String[] COMMAND_TYPES = new String[]{"user", "admin", "setup"};
private MobArenaPlugin plugin;
private Map<String,MACommand> commands;
public CommandHandler(MobArenaPlugin plugin) {
this.plugin = plugin;
this.commands = new HashMap<String,MACommand>();
loadCommands();
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (args.length == 0) {
sender.sendMessage("You need arguments, pal!");
return true;
}
// Grab the command from the map, and if null, didn't work.
MACommand command = commands.get(args[0]);
if (command == null) {
System.out.println("Command '" + label + "' not recognized");
return true;
}
// Cast if sender is a Player, null otherwise.
Player p = (sender instanceof Player) ? (Player) sender : null;
// If null, must be console.
if (p == null) {
if (!command.executeFromConsole(plugin, sender, args)) {
sender.sendMessage("Can't use that command from the console.");
}
return true;
}
// Otherwise, check permissions
if (!p.hasPermission(command.getPermission())) {
sender.sendMessage("No permission");
return true;
}
// Execute!
command.execute(plugin, p, trimFirstArg(args));
return true;
}
/**
* Since Java doesn't support pointer arithmetic, this method
* attempts to remove the first element of a String[] object
* by creating a new array of the same size -1 and copying all
* the elements over.
* @param args a String[] to trim
* @return a String[] with the same elements except for the very first
*/
private String[] trimFirstArg(String[] args) {
String[] result = new String[args.length - 1];
for (int i = 0; i < result.length; i++) {
result[i] = args[i+1];
}
return result;
}
/**
* Load all of the MobArena commands from either the jar or the bin
* folder into the commands-map. Each one of a commands' names/aliases
* is added to the map, such that both "/ma join" and "/ma j" work, for
* instance.
*/
private void loadCommands() {
// Prepare a strategy for the class parser.
ClassIterationStrategy strategy = null;
File f = new File("plugins" + File.separator + "MobArena.jar");
try {
// If jar exists, use it - otherwise, use bin.
strategy = (f.exists()) ? new JarClassIterationStrategy(f) :
new DirClassIterationStrategy(new File("bin"));
// Create a new ClassParser with the given strategy.
ClassParser parser = new ClassParser(strategy);
// Iterate through all three folders, user/admin/setup
for (String type : COMMAND_TYPES) {
Collection<Class<?>> classes = parser.getClasses(COMMAND_PATH + type);
for (Class<?> c : classes) {
// Make sure the class is indeed an instance of MACommand
Object obj = c.newInstance();
if (!(obj instanceof MACommand))
continue;
// Then cast, and add for each command name/alias
MACommand command = (MACommand) obj;
for (String name : command.getNames()) {
commands.put(name, command);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,40 @@
package com.garbagemule.MobArena.commands;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.garbagemule.MobArena.MobArenaPlugin;
public interface MACommand
{
/**
* Get an array of names/aliases for this command.
* Every command must have at least one name/alias to work.
* @return a String[] of names/aliases
*/
public String[] getNames();
/**
* Get the permission required to execute this command.
* If there is no permission required, the method returns
* the empty string.
* @return a permission or null
*/
public String getPermission();
/**
* Execute the implementing command with the input Player as the executor.
* @param sender The Player executing the command
* @param args A list of arguments
* @return true, if the command was executed successfully, false otherwise
*/
public boolean execute(MobArenaPlugin plugin, Player sender, String... args);
/**
* Execute the implementing command with the console as the executor.
* @param sender The console executing the command
* @param args A list of arguments
* @return true, if the command was executed successfully, false otherwise
*/
public boolean executeFromConsole(MobArenaPlugin plugin, CommandSender sender, String... args);
}

View File

@ -0,0 +1,30 @@
package com.garbagemule.MobArena.commands.admin;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.garbagemule.MobArena.*;
import com.garbagemule.MobArena.commands.*;
public class EnableCommand implements MACommand
{
@Override
public String[] getNames() {
return new String[] { "enable" };
}
@Override
public String getPermission() {
return "mobarena.admin.enable";
}
@Override
public boolean execute(MobArenaPlugin plugin, Player sender, String... args) {
return false;
}
@Override
public boolean executeFromConsole(MobArenaPlugin plugin, CommandSender sender, String... args) {
return false;
}
}

View File

@ -0,0 +1,29 @@
package com.garbagemule.MobArena.commands.setup;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.garbagemule.MobArena.commands.*;
import com.garbagemule.MobArena.*;
public class SetRegionCommand implements MACommand
{
@Override
public String[] getNames() {
return new String[] { "setregion" };
}
@Override
public String getPermission() {
return "mobarena.setup.setregion";
}
@Override
public boolean execute(MobArenaPlugin plugin, Player sender, String... args) {
return false;
}
@Override
public boolean executeFromConsole(MobArenaPlugin plugin, CommandSender sender, String... args) {
return false;
}
}

View File

@ -0,0 +1,53 @@
package com.garbagemule.MobArena.commands.user;
import java.util.List;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.garbagemule.MobArena.commands.*;
import com.garbagemule.MobArena.*;
public class ArenaListCommand implements MACommand
{
@Override
public String[] getNames() {
return new String[] { "arenas" , "list" };
}
@Override
public String getPermission() {
return "mobarena.use.arenalist";
}
@Override
public boolean execute(MobArenaPlugin plugin, Player sender, String... args) {
// Grab the arena master.
ArenaMaster am = plugin.getArenaMaster();
// Get the arenas.
List<Arena> arenas = am.getEnabledArenas();
String msg = "Available arenas: ";
if (arenas.size() == 0) {
sender.sendMessage(msg + "<none>");
return true;
}
// Enumerate arenas.
for (Arena a : arenas) {
msg += a.configName() + ", ";
}
// Trim off the trailing comma.
msg = msg.substring(0, msg.length() - 2);
// Send the message!
sender.sendMessage(msg);
return true;
}
@Override
public boolean executeFromConsole(MobArenaPlugin plugin, CommandSender sender, String... args) {
return false;
}
}

View File

@ -0,0 +1,53 @@
package com.garbagemule.MobArena.commands.user;
import java.util.*;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.garbagemule.MobArena.commands.*;
import com.garbagemule.MobArena.*;
public class JoinCommand implements MACommand
{
@Override
public String[] getNames() {
return new String[] { "join" , "j" };
}
@Override
public String getPermission() {
return "mobarena.use.join";
}
@Override
public boolean execute(MobArenaPlugin plugin, Player sender, String... args) {
// Grab the arena master
ArenaMaster am = plugin.getArenaMaster();
// Get all enabled arenas.
List<Arena> arenas = am.getEnabledArenas();
// If no arena was specified, and multiple arenas are available, notify.
if (args.length < 1 && arenas.size() > 1) {
sender.sendMessage("There are more than one arena. Pick one, damnit!");
return false;
}
// If only one arena, pick it no matter what, otherwise, look for name.
Arena arena = arenas.size() == 1 ? arenas.get(0) : am.getArenaWithName(args[0]);
// If null, no arena was found.
if (arena == null) {
sender.sendMessage("The arena '" + args[0] + "' does not exist.");
return false;
}
sender.sendMessage("You've joined arena '" + arena.configName() + "'!");
return true;
}
@Override
public boolean executeFromConsole(MobArenaPlugin plugin, CommandSender sender, String... args) {
return false;
}
}

View File

@ -0,0 +1,29 @@
package com.garbagemule.MobArena.commands.user;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.garbagemule.MobArena.commands.*;
import com.garbagemule.MobArena.*;
public class LeaveCommand implements MACommand
{
@Override
public String[] getNames() {
return new String[] { "leave" , "l" };
}
@Override
public String getPermission() {
return "mobarena.use.leave";
}
@Override
public boolean execute(MobArenaPlugin plugin, Player sender, String... args) {
return true;
}
@Override
public boolean executeFromConsole(MobArenaPlugin plugin, CommandSender sender, String... args) {
return false;
}
}

View File

@ -0,0 +1,29 @@
package com.garbagemule.MobArena.commands.user;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.garbagemule.MobArena.commands.*;
import com.garbagemule.MobArena.*;
public class NotReadyCommand implements MACommand
{
@Override
public String[] getNames() {
return new String[] { "notready" , "check" };
}
@Override
public String getPermission() {
return "mobarena.use.notready";
}
@Override
public boolean execute(MobArenaPlugin plugin, Player sender, String... args) {
return true;
}
@Override
public boolean executeFromConsole(MobArenaPlugin plugin, CommandSender sender, String... args) {
return false;
}
}

View File

@ -0,0 +1,29 @@
package com.garbagemule.MobArena.commands.user;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.garbagemule.MobArena.commands.*;
import com.garbagemule.MobArena.*;
public class PlayerListCommand implements MACommand
{
@Override
public String[] getNames() {
return new String[] { "who" , "players" };
}
@Override
public String getPermission() {
return "mobarena.use.playerlist";
}
@Override
public boolean execute(MobArenaPlugin plugin, Player sender, String... args) {
return true;
}
@Override
public boolean executeFromConsole(MobArenaPlugin plugin, CommandSender sender, String... args) {
return false;
}
}

View File

@ -10,13 +10,13 @@ import org.bukkit.Location;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;
import org.bukkit.block.Sign; import org.bukkit.block.Sign;
import org.bukkit.util.config.Configuration; //import org.bukkit.util.config.Configuration;
import com.garbagemule.MobArena.Arena; import com.garbagemule.MobArena.Arena;
import com.garbagemule.MobArena.ArenaPlayer; import com.garbagemule.MobArena.ArenaPlayer;
import com.garbagemule.MobArena.ArenaPlayerStatistics; import com.garbagemule.MobArena.ArenaPlayerStatistics;
import com.garbagemule.MobArena.MobArena; import com.garbagemule.MobArena.MobArena;
import com.garbagemule.MobArena.util.ConfigUtils; import com.garbagemule.MobArena.util.Config;
public class Leaderboard public class Leaderboard
{ {
@ -54,7 +54,7 @@ public class Leaderboard
* @param arena The arena to which this leaderboard belongs. * @param arena The arena to which this leaderboard belongs.
* @param config The config-file in which the location is specified. * @param config The config-file in which the location is specified.
*/ */
public Leaderboard(MobArena plugin, Arena arena, Configuration config) public Leaderboard(MobArena plugin, Arena arena, Config config)
{ {
this(plugin, arena); this(plugin, arena);
@ -64,7 +64,7 @@ public class Leaderboard
if (coords != null) if (coords != null)
{ {
// Grab the top left sign. // Grab the top left sign.
topLeft = ConfigUtils.parseLocation(arena.getWorld(), coords); topLeft = Config.parseLocation(arena.getWorld(), coords);
// If it is a sign, validate. // If it is a sign, validate.
if (topLeft.getBlock().getState() instanceof Sign) if (topLeft.getBlock().getState() instanceof Sign)

View File

@ -0,0 +1,177 @@
package com.garbagemule.MobArena.util;
import java.io.File;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
public class Config
{
private YamlConfiguration config;
private File configFile;
public Config(File configFile) {
this.config = new YamlConfiguration();
this.configFile = configFile;
config.options().indent(4);
}
public boolean load() {
try {
config.load(configFile);
return true;
}
catch (Exception e) {
e.printStackTrace();
return false;
}
}
public boolean save() {
try {
config.save(configFile);
return true;
}
catch (Exception e) {
e.printStackTrace();
return false;
}
}
public void setHeader(String header) {
config.options().header(header);
}
///////////////////////////////////////////////////////////////////////////
// //
// GETTERS //
// //
///////////////////////////////////////////////////////////////////////////
public Object getProperty(String path) {
return config.get(path);
}
public boolean getBoolean(String path) {
return config.getBoolean(path);
}
public boolean getBoolean(String path, boolean def) {
return config.getBoolean(path, def);
}
public int getInt(String path) {
return config.getInt(path);
}
public int getInt(String path, int def) {
return config.getInt(path, def);
}
public String getString(String path) {
String result = config.getString(path);
return result != null ? result : null;
}
public String getString(String path, String def) {
return config.getString(path, def);
}
public Set<String> getKeys(String path) {
if (config.get(path) == null)
return null;
ConfigurationSection section = config.getConfigurationSection(path);
return section.getKeys(false);
}
@SuppressWarnings("unchecked")
public List<String> getStringList(String path, List<String> def) {
if (config.get(path) == null)
return def != null ? def : new LinkedList<String>();
List<?> list = config.getStringList(path);
return (List<String>) list;
}
///////////////////////////////////////////////////////////////////////////
// //
// MUTATORS //
// //
///////////////////////////////////////////////////////////////////////////
public void set(String path, Object value) {
config.set(path, value);
}
public void setProperty(String path, Object value) {
this.set(path, value);
}
public void remove(String path) {
this.set(path, null);
}
public void removeProperty(String path) {
this.remove(path);
}
///////////////////////////////////////////////////////////////////////////
// //
// UTILITY METHODS //
// //
///////////////////////////////////////////////////////////////////////////
public static Location parseLocation(World world, String coords)
{
String[] parts = coords.split(",");
if (parts.length != 5)
throw new IllegalArgumentException("Input string must contain x, y, z, yaw and pitch");
Integer x = getInteger(parts[0]);
Integer y = getInteger(parts[1]);
Integer z = getInteger(parts[2]);
Float yaw = getFloat(parts[3]);
Float pitch = getFloat(parts[4]);
if (x == null || y == null || z == null || yaw == null || pitch == null)
throw new NullPointerException("Some of the parsed values are null!");
return new Location(world, x, y, z, yaw, pitch);
}
private static Integer getInteger(String s)
{
try
{
return Integer.parseInt(s.trim());
}
catch (Exception e) {}
return null;
}
private static Float getFloat(String s)
{
try
{
return Float.parseFloat(s.trim());
}
catch (Exception e) {}
return null;
}
}

View File

@ -9,10 +9,9 @@ import java.net.URL;
import java.net.URLClassLoader; import java.net.URLClassLoader;
import java.net.URLConnection; import java.net.URLConnection;
import java.util.HashSet; import java.util.HashSet;
import java.util.List;
import java.util.Set; import java.util.Set;
import org.bukkit.util.config.Configuration; //import org.bukkit.util.config.Configuration;
import com.garbagemule.MobArena.MobArena; import com.garbagemule.MobArena.MobArena;
@ -41,10 +40,10 @@ public class FileUtils
* Download all necessary libraries. * Download all necessary libraries.
* @param config The MobArena config-file * @param config The MobArena config-file
*/ */
public static void fetchLibs(Configuration config) public static void fetchLibs(Config config)
{ {
// Get all arenas // Get all arenas
List<String> arenas = config.getKeys("arenas"); Set<String> arenas = config.getKeys("arenas");
if (arenas == null) return; if (arenas == null) return;
// Add all the logging types // Add all the logging types

View File

@ -4,12 +4,13 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.util.config.Configuration; //import org.bukkit.util.config.Configuration;
import com.garbagemule.MobArena.Arena; import com.garbagemule.MobArena.Arena;
import com.garbagemule.MobArena.MAUtils; import com.garbagemule.MobArena.MAUtils;
@ -80,7 +81,7 @@ public class WaveUtils
/** /**
* Grab and process all the waves in the config-file for the arena. * Grab and process all the waves in the config-file for the arena.
*/ */
public static TreeSet<Wave> getWaves(Arena arena, Configuration config, WaveBranch branch) public static TreeSet<Wave> getWaves(Arena arena, Config config, WaveBranch branch)
{ {
// Determine the branch type of the wave, and grab the appropriate comparator // Determine the branch type of the wave, and grab the appropriate comparator
String b = branch.toString().toLowerCase(); String b = branch.toString().toLowerCase();
@ -88,7 +89,7 @@ public class WaveUtils
// Grab the waves from the config-file // Grab the waves from the config-file
String path = "arenas." + arena.configName() + ".waves." + b; // waves.yml, change to either "waves." + b, or simply b String path = "arenas." + arena.configName() + ".waves." + b; // waves.yml, change to either "waves." + b, or simply b
List<String> waves = config.getKeys(path); Set<String> waves = config.getKeys(path);
// If there are any waves, process them // If there are any waves, process them
if (waves != null) if (waves != null)
@ -122,7 +123,7 @@ public class WaveUtils
* Get a single wave based on the config-file, the path, and branch * Get a single wave based on the config-file, the path, and branch
* @return A Wave object if it is well defined, null otherwise. * @return A Wave object if it is well defined, null otherwise.
*/ */
private static Wave getWave(Arena arena, Configuration config, String path, String name, WaveBranch branch) private static Wave getWave(Arena arena, Config config, String path, String name, WaveBranch branch)
{ {
// Grab the wave type, if null or not well defined, return null // Grab the wave type, if null or not well defined, return null
WaveType type = WaveType.fromString(config.getString(path + "type")); WaveType type = WaveType.fromString(config.getString(path + "type"));
@ -177,13 +178,13 @@ public class WaveUtils
* the node 'wave'. * the node 'wave'.
* Any other requirements are type-specific, and thus we check if the * Any other requirements are type-specific, and thus we check if the
* type is well-defined. * type is well-defined.
* @param config Config-file Configuration * @param config Config-file Config
* @param path The absolute path of the wave * @param path The absolute path of the wave
* @param branch The branch of the wave * @param branch The branch of the wave
* @param type The wave type * @param type The wave type
* @return true, only if the entire wave-node is well-defined. * @return true, only if the entire wave-node is well-defined.
*/ */
private static boolean isWaveWellDefined(Configuration config, String path, WaveBranch branch, WaveType type) private static boolean isWaveWellDefined(Config config, String path, WaveBranch branch, WaveType type)
{ {
// This boolean is used in the "leaf methods" // This boolean is used in the "leaf methods"
boolean wellDefined = true; boolean wellDefined = true;
@ -254,13 +255,13 @@ public class WaveUtils
* Check if a wave type in the config-file is well-defined. * Check if a wave type in the config-file is well-defined.
* The method calls the appropriate sub-method to check if the type * The method calls the appropriate sub-method to check if the type
* is well-defined. * is well-defined.
* @param config Config-file Configuration * @param config Config-file Config
* @param path The absolute path of the wave * @param path The absolute path of the wave
* @param type The wave type * @param type The wave type
* @param wellDefined Pass-through boolean for "leaf methods". * @param wellDefined Pass-through boolean for "leaf methods".
* @return true, only if the entire wave-node is well-defined. * @return true, only if the entire wave-node is well-defined.
*/ */
private static boolean isTypeWellDefined(Configuration config, String path, WaveType type, boolean wellDefined) private static boolean isTypeWellDefined(Config config, String path, WaveType type, boolean wellDefined)
{ {
if (type == WaveType.DEFAULT) if (type == WaveType.DEFAULT)
return isDefaultWaveWellDefined(config, path, wellDefined); return isDefaultWaveWellDefined(config, path, wellDefined);
@ -278,12 +279,12 @@ public class WaveUtils
* Check if a default wave is well-defined. * Check if a default wave is well-defined.
* The default waves have an optional wave growth node. Otherwise, * The default waves have an optional wave growth node. Otherwise,
* they share nodes with special waves. * they share nodes with special waves.
* @param config Config-file Configuration * @param config Config-file Config
* @param path The absolute path of the wave * @param path The absolute path of the wave
* @param wellDefined Pass-through boolean for "leaf methods". * @param wellDefined Pass-through boolean for "leaf methods".
* @return true, only if the entire wave-node is well-defined. * @return true, only if the entire wave-node is well-defined.
*/ */
private static boolean isDefaultWaveWellDefined(Configuration config, String path, boolean wellDefined) private static boolean isDefaultWaveWellDefined(Config config, String path, boolean wellDefined)
{ {
// OPTIONAL: Wave growth // OPTIONAL: Wave growth
String growth = config.getString(path + "growth"); String growth = config.getString(path + "growth");
@ -299,12 +300,12 @@ public class WaveUtils
/** /**
* Check if a special wave is well-defined. * Check if a special wave is well-defined.
* The special waves have no unique nodes. * The special waves have no unique nodes.
* @param config Config-file Configuration * @param config Config-file Config
* @param path The absolute path of the wave * @param path The absolute path of the wave
* @param wellDefined Pass-through boolean for "leaf methods". * @param wellDefined Pass-through boolean for "leaf methods".
* @return true, only if the entire wave-node is well-defined. * @return true, only if the entire wave-node is well-defined.
*/ */
private static boolean isSpecialWaveWellDefined(Configuration config, String path, boolean wellDefined) private static boolean isSpecialWaveWellDefined(Config config, String path, boolean wellDefined)
{ {
return isNormalWaveWellDefined(config, path, wellDefined); return isNormalWaveWellDefined(config, path, wellDefined);
} }
@ -314,15 +315,15 @@ public class WaveUtils
* There are no REQUIRED nodes for default or special wave types, besides * There are no REQUIRED nodes for default or special wave types, besides
* the ones for the branch they belong to. * the ones for the branch they belong to.
* The only OPTIONAL node is (currently) 'monsters' * The only OPTIONAL node is (currently) 'monsters'
* @param config Config-file Configuration * @param config Config-file Config
* @param path The absolute path of the wave * @param path The absolute path of the wave
* @param wellDefined Pass-through boolean for "leaf methods". * @param wellDefined Pass-through boolean for "leaf methods".
* @return true, wellDefined is true. * @return true, wellDefined is true.
*/ */
private static boolean isNormalWaveWellDefined(Configuration config, String path, boolean wellDefined) private static boolean isNormalWaveWellDefined(Config config, String path, boolean wellDefined)
{ {
// OPTIONAL: Monsters // OPTIONAL: Monsters
List<String> monsters = config.getKeys(path + "monsters"); Set<String> monsters = config.getKeys(path + "monsters");
if (monsters != null) if (monsters != null)
{ {
for (String monster : monsters) for (String monster : monsters)
@ -341,12 +342,12 @@ public class WaveUtils
/** /**
* Check if a swarm wave is well defined * Check if a swarm wave is well defined
* @param config Config-file Configuration * @param config Config-file Config
* @param path The absolute path of the wave * @param path The absolute path of the wave
* @param wellDefined Pass-through boolean for "leaf methods". * @param wellDefined Pass-through boolean for "leaf methods".
* @return true, wellDefined is true. * @return true, wellDefined is true.
*/ */
private static boolean isSwarmWaveWellDefined(Configuration config, String path, boolean wellDefined) private static boolean isSwarmWaveWellDefined(Config config, String path, boolean wellDefined)
{ {
// REQUIRED: Monster type // REQUIRED: Monster type
String monster = config.getString(path + "monster"); String monster = config.getString(path + "monster");
@ -374,12 +375,12 @@ public class WaveUtils
/** /**
* Check if a boss wave is well defined. * Check if a boss wave is well defined.
* @param config Config-file Configuration * @param config Config-file Config
* @param path The absolute path of the wave * @param path The absolute path of the wave
* @param wellDefined Pass-through boolean for "leaf methods". * @param wellDefined Pass-through boolean for "leaf methods".
* @return true, wellDefined is true. * @return true, wellDefined is true.
*/ */
private static boolean isBossWaveWellDefined(Configuration config, String path, boolean wellDefined) private static boolean isBossWaveWellDefined(Config config, String path, boolean wellDefined)
{ {
// REQUIRED: Monster type // REQUIRED: Monster type
String monster = config.getString(path + "monster"); String monster = config.getString(path + "monster");

View File

@ -0,0 +1,15 @@
package com.garbagemule.MobArena.util.classparsing;
import java.util.Collection;
public interface ClassIterationStrategy
{
/**
* Given a package, e.g. com.garbagemule.MobArena.commands.user, the
* concrete strategy will return a collection of qualified class names
* either from a directory or a jar file.
* @param packagePath path from which to extract classes
* @return a list of qualified class names or null
*/
public Collection<String> getClassesFromPackage(String packagePath);
}

View File

@ -0,0 +1,46 @@
package com.garbagemule.MobArena.util.classparsing;
import java.util.*;
public class ClassParser
{
private ClassIterationStrategy strategy;
public ClassParser(ClassIterationStrategy strategy) {
this.strategy = strategy;
}
/**
* Using an iteration strategy provided in the constructor, this method tries
* to iterate through all classes within a given "package".
* @param packagePath a package path, e.g. com.garbagemule.MobArena.commands.user
* @return a list of Class objects
*/
public Collection<Class<?>> getClasses(String packagePath) {
Collection<Class<?>> result = new LinkedList<Class<?>>();
for (String classname : strategy.getClassesFromPackage(packagePath)) {
Class<?> c = makeClass(classname);
if (c != null) {
result.add(c);
}
}
return result;
}
/**
* Get a class using its qualified (full package) name.
* @param qualifiedName qualified name of a class
* @return a Class object, or null if the class could not be made.
*/
private static Class<?> makeClass(String qualifiedName) {
try {
return Class.forName(qualifiedName);
}
catch (Exception e) {
return null;
}
}
}

View File

@ -0,0 +1,52 @@
package com.garbagemule.MobArena.util.classparsing;
import java.io.*;
import java.util.*;
public class DirClassIterationStrategy implements ClassIterationStrategy
{
private File baseDir;
/**
* Dir iterator. The input file must be a directory, whose
* contents are iterated over upon calling the implemented
* method. This dir could be bin/ or build/.
* @param file a directory
* @throws Exception
*/
public DirClassIterationStrategy(File baseDir) throws Exception {
this.baseDir = baseDir;
}
@Override
public Collection<String> getClassesFromPackage(String packagePath) {
// The resulting list.
Collection<String> result = new LinkedList<String>();
// Convert to an actual path.
String path = packageToPath(packagePath);
// Make a new dir from it.
File dir = new File(baseDir, path);
for (File f : dir.listFiles()) {
String name = f.getName();
String absolutePath = f.getAbsolutePath();
if (absolutePath.contains(path) && name.endsWith(".class")) {
result.add( packagePath + "." + stripExtension(name) );
}
}
return result;
}
private String stripExtension(String file) {
int dot = file.lastIndexOf(".");
return file.substring(0, dot);
}
private String packageToPath(String path) {
return path.replace(".", File.separator);
}
}

View File

@ -0,0 +1,62 @@
package com.garbagemule.MobArena.util.classparsing;
import java.io.*;
import java.util.*;
import java.util.jar.*;
public class JarClassIterationStrategy implements ClassIterationStrategy
{
private JarFile jarFile;
/**
* Jar iterator. The input file is turned into a JarFile object,
* which is later used to extract a list of entries to iterate
* over. The implemented method filters through the entries and
* returns any matches.
* @param file a jar file
* @throws Exception
*/
public JarClassIterationStrategy(File file) throws Exception {
this.jarFile = new JarFile(file);
}
@Override
public Collection<String> getClassesFromPackage(String packagePath) {
// The resulting list.
Collection<String> result = new LinkedList<String>();
// Convert to an actual path.
String path = packageToPath(packagePath);
// Grab the entries from the jar file.
Enumeration<JarEntry> entries = jarFile.entries();
/* Iterate through all the entries in the jar file, and
* if a file starts with the package path and ends with
* .class, we have a match, in which case we strip the
* extension and convert to a package representation. */
while (entries.hasMoreElements()) {
String entry = entries.nextElement().getName();
if (entry.startsWith(path) && entry.endsWith(".class")) {
result.add( pathToPackage( stripExtension(entry) ) );
}
}
// Return the resulting list.
return result;
}
private String stripExtension(String file) {
int dot = file.lastIndexOf(".");
return file.substring(0, dot);
}
private String packageToPath(String path) {
return path.replace(".", "/");
}
private String pathToPackage(String path) {
return path.replace("/", ".");
}
}

View File

@ -12,11 +12,12 @@ import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.entity.CraftEntity; import org.bukkit.craftbukkit.entity.CraftEntity;
import org.bukkit.entity.Creature; import org.bukkit.entity.Creature;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.util.config.Configuration; //import org.bukkit.util.config.Configuration;
import com.garbagemule.MobArena.Arena; import com.garbagemule.MobArena.Arena;
import com.garbagemule.MobArena.MAUtils; import com.garbagemule.MobArena.MAUtils;
import com.garbagemule.MobArena.MAMessages.Msg; import com.garbagemule.MobArena.MAMessages.Msg;
import com.garbagemule.MobArena.util.Config;
import com.garbagemule.MobArena.util.WaveUtils; import com.garbagemule.MobArena.util.WaveUtils;
public class BossWave extends AbstractWave public class BossWave extends AbstractWave
@ -30,20 +31,20 @@ public class BossWave extends AbstractWave
private boolean lowHealthAnnounced = false, abilityAnnounce; private boolean lowHealthAnnounced = false, abilityAnnounce;
// Recurrent // Recurrent
public BossWave(Arena arena, String name, int wave, int frequency, int priority, Configuration config, String path) public BossWave(Arena arena, String name, int wave, int frequency, int priority, Config config, String path)
{ {
super(arena, name, wave, frequency, priority); super(arena, name, wave, frequency, priority);
load(config, path); load(config, path);
} }
// Single // Single
public BossWave(Arena arena, String name, int wave, Configuration config, String path) public BossWave(Arena arena, String name, int wave, Config config, String path)
{ {
super(arena, name, wave); super(arena, name, wave);
load(config, path); load(config, path);
} }
private void load(Configuration config, String path) private void load(Config config, String path)
{ {
setType(WaveType.BOSS); setType(WaveType.BOSS);
abilityTask = -1; abilityTask = -1;

View File

@ -6,24 +6,25 @@ import java.util.Map;
import java.util.Random; import java.util.Random;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.util.config.Configuration; //import org.bukkit.util.config.Configuration;
import com.garbagemule.MobArena.Arena; import com.garbagemule.MobArena.Arena;
import com.garbagemule.MobArena.MAUtils; import com.garbagemule.MobArena.MAUtils;
import com.garbagemule.MobArena.MAMessages.Msg; import com.garbagemule.MobArena.MAMessages.Msg;
import com.garbagemule.MobArena.util.Config;
import com.garbagemule.MobArena.util.WaveUtils; import com.garbagemule.MobArena.util.WaveUtils;
public class DefaultWave extends NormalWave public class DefaultWave extends NormalWave
{ {
// Recurrent // Recurrent
public DefaultWave(Arena arena, String name, int wave, int frequency, int priority, Configuration config, String path) public DefaultWave(Arena arena, String name, int wave, int frequency, int priority, Config config, String path)
{ {
super(arena, name, wave, frequency, priority, config, path); super(arena, name, wave, frequency, priority, config, path);
load(config, path, WaveType.DEFAULT); load(config, path, WaveType.DEFAULT);
} }
// Single // Single
public DefaultWave(Arena arena, String name, int wave, Configuration config, String path) public DefaultWave(Arena arena, String name, int wave, Config config, String path)
{ {
super(arena, name, wave, config, path); super(arena, name, wave, config, path);
load(config, path, WaveType.DEFAULT); load(config, path, WaveType.DEFAULT);

View File

@ -1,13 +1,14 @@
package com.garbagemule.MobArena.waves; package com.garbagemule.MobArena.waves;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.TreeMap; import java.util.TreeMap;
import org.bukkit.util.config.Configuration; //import org.bukkit.util.config.Configuration;
import com.garbagemule.MobArena.Arena; import com.garbagemule.MobArena.Arena;
import com.garbagemule.MobArena.MAUtils; import com.garbagemule.MobArena.MAUtils;
import com.garbagemule.MobArena.util.Config;
import com.garbagemule.MobArena.util.WaveUtils; import com.garbagemule.MobArena.util.WaveUtils;
public abstract class NormalWave extends AbstractWave public abstract class NormalWave extends AbstractWave
@ -16,13 +17,13 @@ public abstract class NormalWave extends AbstractWave
private Map<Integer,MACreature> probabilities = new TreeMap<Integer,MACreature>(); private Map<Integer,MACreature> probabilities = new TreeMap<Integer,MACreature>();
// Recurrent // Recurrent
public NormalWave(Arena arena, String name, int wave, int frequency, int priority, Configuration config, String path) public NormalWave(Arena arena, String name, int wave, int frequency, int priority, Config config, String path)
{ {
super(arena, name, wave, frequency, priority); super(arena, name, wave, frequency, priority);
} }
// Single // Single
public NormalWave(Arena arena, String name, int wave, Configuration config, String path) public NormalWave(Arena arena, String name, int wave, Config config, String path)
{ {
super(arena, name, wave); super(arena, name, wave);
} }
@ -34,7 +35,7 @@ public abstract class NormalWave extends AbstractWave
* @param path The absolute path of the wave * @param path The absolute path of the wave
* @param type DEFAULT or SPECIAL * @param type DEFAULT or SPECIAL
*/ */
public void load(Configuration config, String path, WaveType type) public void load(Config config, String path, WaveType type)
{ {
// Set type and (for DEFAULT) growth. // Set type and (for DEFAULT) growth.
setType(type); setType(type);
@ -43,7 +44,7 @@ public abstract class NormalWave extends AbstractWave
// Load monsters // Load monsters
int prob; int prob;
List<String> monsters = config.getKeys(path + "monsters"); Set<String> monsters = config.getKeys(path + "monsters");
if (monsters != null && !monsters.isEmpty()) if (monsters != null && !monsters.isEmpty())
{ {
for (String m : config.getKeys(path + "monsters")) for (String m : config.getKeys(path + "monsters"))

View File

@ -6,24 +6,25 @@ import java.util.Map;
import java.util.Random; import java.util.Random;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.util.config.Configuration; //import org.bukkit.util.config.Configuration;
import com.garbagemule.MobArena.Arena; import com.garbagemule.MobArena.Arena;
import com.garbagemule.MobArena.MAUtils; import com.garbagemule.MobArena.MAUtils;
import com.garbagemule.MobArena.MAMessages.Msg; import com.garbagemule.MobArena.MAMessages.Msg;
import com.garbagemule.MobArena.util.Config;
import com.garbagemule.MobArena.util.WaveUtils; import com.garbagemule.MobArena.util.WaveUtils;
public class SpecialWave extends NormalWave public class SpecialWave extends NormalWave
{ {
// Recurrent // Recurrent
public SpecialWave(Arena arena, String name, int wave, int frequency, int priority, Configuration config, String path) public SpecialWave(Arena arena, String name, int wave, int frequency, int priority, Config config, String path)
{ {
super(arena, name, wave, frequency, priority, config, path); super(arena, name, wave, frequency, priority, config, path);
load(config, path, WaveType.SPECIAL); load(config, path, WaveType.SPECIAL);
} }
// Single // Single
public SpecialWave(Arena arena, String name, int wave, Configuration config, String path) public SpecialWave(Arena arena, String name, int wave, Config config, String path)
{ {
super(arena, name, wave, config, path); super(arena, name, wave, config, path);
load(config, path, WaveType.SPECIAL); load(config, path, WaveType.SPECIAL);

View File

@ -4,11 +4,12 @@ import java.util.List;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.util.config.Configuration; //import org.bukkit.util.config.Configuration;
import com.garbagemule.MobArena.Arena; import com.garbagemule.MobArena.Arena;
import com.garbagemule.MobArena.MAUtils; import com.garbagemule.MobArena.MAUtils;
import com.garbagemule.MobArena.MAMessages.Msg; import com.garbagemule.MobArena.MAMessages.Msg;
import com.garbagemule.MobArena.util.Config;
import com.garbagemule.MobArena.util.WaveUtils; import com.garbagemule.MobArena.util.WaveUtils;
public class SwarmWave extends AbstractWave public class SwarmWave extends AbstractWave
@ -17,20 +18,20 @@ public class SwarmWave extends AbstractWave
private SwarmAmount amount; private SwarmAmount amount;
// Recurrent // Recurrent
public SwarmWave(Arena arena, String name, int wave, int frequency, int priority, Configuration config, String path) public SwarmWave(Arena arena, String name, int wave, int frequency, int priority, Config config, String path)
{ {
super(arena, name, wave, frequency, priority); super(arena, name, wave, frequency, priority);
load(config, path); load(config, path);
} }
// Single // Single
public SwarmWave(Arena arena, String name, int wave, Configuration config, String path) public SwarmWave(Arena arena, String name, int wave, Config config, String path)
{ {
super(arena, name, wave); super(arena, name, wave);
load(config, path); load(config, path);
} }
private void load(Configuration config, String path) private void load(Config config, String path)
{ {
// Set the wave type // Set the wave type
setType(WaveType.SWARM); setType(WaveType.SWARM);