Get rid of config adapter.

This change involves many classes because the adapter was relied upon
heavily throughout the project. The change is motivated by the fact
that the wrapper created more problems than it solved. Those problems
(listed here) are solved by this commit. Some classes have undergone
notable changes (e.g. ArenaRegion).

- The config-file will no longer overwrite and regenerate itself
  seemingly randomly.
- The config-file will now save correctly when setting points and
  expanding regions.
- The "no class items in lobby" problem has been fixed.
- The "must be inside region" problem has been fixed.
This commit is contained in:
garbagemule
2013-08-15 14:37:10 +02:00
parent 2475ae3633
commit a3ab2203be
23 changed files with 318 additions and 1190 deletions
+3 -118
View File
@@ -1,118 +1,3 @@
# MobArena v0.0.0 - Config-file
# Read the Wiki for details on how to set up this file: http://goo.gl/F5TTc
# Note: You -must- use spaces instead of tabs!
global-settings:
enabled: true
allowed-commands: /list, /pl
update-notification: true
classes:
Knight:
items: diamond_sword, potion:8197:3
armor: 306,307,308,309
Tank:
items: iron_sword, potion:8229:2
armor: 310,311,312,313
Archer:
items: wood_sword, bow, arrow:256, potion:8197:3, bone
armor: 298,299,300,301
Chemist:
items: stone_sword, potion:16428:30, potion:16388:8, potion:16389:20, potion:8197:3, potion:8226:1
armor: 314,315,316,317
Oddjob:
items: stone_sword, flint_and_steel, netherrack:2, tnt:4, potion:8197:3
armor: 298,299,300,301
arenas:
default:
settings:
world: world
enabled: true
protect: true
entry-fee: ''
clear-wave-before-next: false
clear-boss-before-next: false
clear-wave-before-boss: false
lightning: true
auto-equip-armor: true
soft-restore: false
soft-restore-drops: false
require-empty-inv-join: false
require-empty-inv-spec: false
hellhounds: false
pvp-enabled: false
monster-infight: false
allow-teleporting: false
spectate-on-death: true
auto-respawn: true
share-items-in-arena: true
min-players: 0
max-players: 0
max-join-distance: 0
first-wave-delay: 5
wave-interval: 15
final-wave: 0
monster-limit: 100
monster-exp: false
keep-exp: true
food-regen: false
lock-food-level: true
spout-class-select: false
player-time-in-arena: world
auto-ignite-tnt: false
auto-start-timer: 0
auto-ready: false
use-class-chests: false
display-waves-as-level: false
display-timer-as-level: false
use-scoreboards: true
isolated-chat: false
global-first-join-announce: false
global-end-announce: false
waves:
recurrent:
def1:
type: default
priority: 1
frequency: 1
monsters:
zombies: 10
skeletons: 10
spiders: 10
creepers: 10
wolves: 10
spec1:
type: special
priority: 2
frequency: 4
monsters:
powered-creepers: 10
zombie-pigmen: 10
angry-wolves: 10
blazes: 10
single:
swarm1:
type: swarm
wave: 6
monster: slime
amount: low
boss1:
type: boss
wave: 10
monster: cave_spider
health: high
abilities: arrows, root-target, throw-nearby
rewards:
waves:
every:
'3': feather, bone, stick
'5': dirt:4, gravel:4, stone:4
'10': iron_ingot:10, gold_ingot:8
after:
'7': minecart, storage_minecart, powered_minecart
'13': iron_sword, iron_pickaxe, iron_spade
'16': diamond_sword
class-limits:
Archer: -1
Oddjob: -1
Chemist: -1
Tank: -1
Knight: -1
global-settings: {}
classes: {}
arenas: {}
+13 -12
View File
@@ -13,6 +13,7 @@ import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.*;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
@@ -20,6 +21,8 @@ import org.bukkit.inventory.PlayerInventory;
import org.bukkit.permissions.PermissionAttachment;
import org.bukkit.potion.PotionEffect;
import static com.garbagemule.MobArena.util.config.ConfigUtils.makeSection;
import com.garbagemule.MobArena.ArenaClass.ArmorType;
import com.garbagemule.MobArena.autostart.AutoStartTimer;
import com.garbagemule.MobArena.events.*;
@@ -33,8 +36,6 @@ import com.garbagemule.MobArena.time.TimeStrategy;
import com.garbagemule.MobArena.time.TimeStrategyLocked;
import com.garbagemule.MobArena.time.TimeStrategyNull;
import com.garbagemule.MobArena.util.*;
import com.garbagemule.MobArena.util.config.Config;
import com.garbagemule.MobArena.util.config.ConfigSection;
import com.garbagemule.MobArena.util.inventory.InventoryManager;
import com.garbagemule.MobArena.util.inventory.InventoryUtils;
import com.garbagemule.MobArena.waves.*;
@@ -48,7 +49,7 @@ public class ArenaImpl implements Arena
private World world;
// Settings section of the config-file for this arena.
private ConfigSection settings;
private ConfigurationSection settings;
// Run-time settings and critical config settings
private boolean enabled, protect, running, edit;
@@ -105,15 +106,15 @@ public class ArenaImpl implements Arena
/**
* Primary constructor. Requires a name and a world.
*/
public ArenaImpl(MobArena plugin, Config config, String name, World world) {
public ArenaImpl(MobArena plugin, ConfigurationSection section, String name, World world) {
if (world == null)
throw new NullPointerException("[MobArena] ERROR! World for arena '" + name + "' does not exist!");
this.name = name;
this.world = world;
this.plugin = plugin;
this.settings = new ConfigSection(config, "arenas." + name + ".settings");
this.region = new ArenaRegion(new ConfigSection(config, "arenas." + name + ".coords"), this);
this.settings = makeSection(section, "settings");
this.region = new ArenaRegion(section, this);
this.enabled = settings.getBoolean("enabled", false);
this.protect = settings.getBoolean("protect", true);
@@ -138,7 +139,7 @@ public class ArenaImpl implements Arena
// Classes, items and permissions
this.classes = plugin.getArenaMaster().getClasses();
this.attachments = new HashMap<Player,PermissionAttachment>();
this.limitManager = new ClassLimitManager(this, classes, new ConfigSection(config, "arenas." + name + ".class-limits"));
this.limitManager = new ClassLimitManager(this, classes, makeSection(section, "class-limits"));
// Blocks and pets
this.repairQueue = new PriorityBlockingQueue<Repairable>(100, new RepairableComparator());
@@ -150,9 +151,9 @@ public class ArenaImpl implements Arena
this.monsterManager = new MonsterManager();
// Wave stuff
this.waveManager = new WaveManager(this, config);
this.everyWaveMap = MAUtils.getArenaRewardMap(plugin, config, name, "every");
this.afterWaveMap = MAUtils.getArenaRewardMap(plugin, config, name, "after");
this.waveManager = new WaveManager(this, section.getConfigurationSection("waves"));
this.everyWaveMap = MAUtils.getArenaRewardMap(plugin, section, name, "every");
this.afterWaveMap = MAUtils.getArenaRewardMap(plugin, section, name, "after");
// Misc
this.eventListener = new ArenaListener(this, plugin);
@@ -182,7 +183,7 @@ public class ArenaImpl implements Arena
/////////////////////////////////////////////////////////////////////////*/
@Override
public ConfigSection getSettings() {
public ConfigurationSection getSettings() {
return settings;
}
@@ -195,7 +196,7 @@ public class ArenaImpl implements Arena
public void setWorld(World world) {
this.world = world;
settings.set("world", world.getName());
settings.getParent().save();
plugin.saveConfig();
if (region != null) region.refreshWorld();
}
@@ -15,6 +15,7 @@ import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.block.Sign;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.*;
import org.bukkit.event.Event.Result;
import org.bukkit.event.block.Action;
@@ -77,7 +78,6 @@ import com.garbagemule.MobArena.region.ArenaRegion;
import com.garbagemule.MobArena.region.RegionPoint;
import com.garbagemule.MobArena.repairable.*;
import com.garbagemule.MobArena.util.TextUtils;
import com.garbagemule.MobArena.util.config.ConfigSection;
import com.garbagemule.MobArena.waves.MABoss;
public class ArenaListener
@@ -118,7 +118,7 @@ public class ArenaListener
* fairly easy to implement an observer pattern - More private fields -
* Uglier code
*/
ConfigSection s = arena.getSettings();
ConfigurationSection s = arena.getSettings();
this.softRestore = s.getBoolean("soft-restore", false);
this.softRestoreDrops = s.getBoolean("soft-restore-drops", false);
this.protect = s.getBoolean("protect", true);
@@ -11,6 +11,8 @@ import java.util.Set;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@@ -19,19 +21,20 @@ import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionDefault;
import org.bukkit.plugin.PluginManager;
import static com.garbagemule.MobArena.util.config.ConfigUtils.makeSection;
import static com.garbagemule.MobArena.util.config.ConfigUtils.parseLocation;
import com.garbagemule.MobArena.ArenaClass.ArmorType;
import com.garbagemule.MobArena.framework.Arena;
import com.garbagemule.MobArena.framework.ArenaMaster;
import com.garbagemule.MobArena.util.ItemParser;
import com.garbagemule.MobArena.util.TextUtils;
import com.garbagemule.MobArena.util.config.Config;
import com.garbagemule.MobArena.util.config.ConfigSection;
import com.garbagemule.MobArena.util.config.ConfigUtils;
public class ArenaMasterImpl implements ArenaMaster
{
private MobArena plugin;
private Config config;
private FileConfiguration config;
private List<Arena> arenas;
private Map<Player, Arena> arenaMap;
@@ -48,7 +51,7 @@ public class ArenaMasterImpl implements ArenaMaster
*/
public ArenaMasterImpl(MobArena plugin) {
this.plugin = plugin;
this.config = plugin.getMAConfig();
this.config = plugin.getConfig();
this.arenas = new LinkedList<Arena>();
this.arenaMap = new HashMap<Player, Arena>();
@@ -239,21 +242,17 @@ public class ArenaMasterImpl implements ArenaMaster
*/
public void initialize() {
config.load();
loadSettings();
loadClasses();
loadArenas();
config.save();
// Apparently necessary...
reloadConfig();
}
/**
* Load the global settings.
*/
public void loadSettings() {
ConfigUtils.replaceAllNodes(plugin.getFilename(), config, "global-settings", "global-settings.yml");
ConfigSection section = config.getConfigSection("global-settings");
ConfigurationSection section = plugin.getConfig().getConfigurationSection("global-settings");
ConfigUtils.addMissingRemoveObsolete(plugin, "global-settings.yml", section);
// Grab the commands string
String cmds = section.getString("allowed-commands", "");
@@ -274,16 +273,13 @@ public class ArenaMasterImpl implements ArenaMaster
* Load all class-related stuff.
*/
public void loadClasses() {
Set<String> classNames = config.getKeys("classes");
ConfigurationSection section = makeSection(plugin.getConfig(), "classes");
ConfigUtils.addIfEmpty(plugin, "classes.yml", section);
// If no classes were found, load the defaults.
if (classNames == null || classNames.isEmpty()) {
loadDefaultClasses();
classNames = config.getKeys("classes");
}
// Establish the map.
classes = new HashMap<String, ArenaClass>();
Set<String> classNames = section.getKeys(false);
// Load each individual class.
for (String className : classNames) {
@@ -291,22 +287,12 @@ public class ArenaMasterImpl implements ArenaMaster
}
}
/**
* Loads the classes in res/classes.yml into the config-file.
*/
public void loadDefaultClasses() {
ConfigUtils.addMissingNodes(plugin.getFilename(), config, "classes", "classes.yml");
}
/**
* Helper method for loading a single class.
*/
private ArenaClass loadClass(String classname) {
// Lowercase version.
ConfigurationSection section = config.getConfigurationSection("classes." + classname);
String lowercase = classname.toLowerCase();
// Grab the class section.
ConfigSection section = config.getConfigSection("classes." + classname);
// If the section doesn't exist, the class doesn't either.
if (section == null) {
@@ -361,7 +347,7 @@ public class ArenaMasterImpl implements ArenaMaster
registerPermission("mobarena.classes." + lowercase, PermissionDefault.TRUE).addParent("mobarena.classes", true);
// Check for class chests
Location cc = section.getLocation("classchest", null);
Location cc = parseLocation(section, "classchest", null);
arenaClass.setClassChest(cc);
// Finally add the class to the classes map.
@@ -369,8 +355,8 @@ public class ArenaMasterImpl implements ArenaMaster
return arenaClass;
}
private void loadClassPermissions(ArenaClass arenaClass, ConfigSection section) {
List<String> perms = section.getStringList("permissions", null);
private void loadClassPermissions(ArenaClass arenaClass, ConfigurationSection section) {
List<String> perms = section.getStringList("permissions");
if (perms.isEmpty()) return;
for (String perm : perms) {
@@ -384,8 +370,8 @@ public class ArenaMasterImpl implements ArenaMaster
}
}
private void loadClassLobbyPermissions(ArenaClass arenaClass, ConfigSection section) {
List<String> perms = section.getStringList("lobby-permissions", null);
private void loadClassLobbyPermissions(ArenaClass arenaClass, ConfigurationSection section) {
List<String> perms = section.getStringList("lobby-permissions");
if (perms.isEmpty()) return;
for (String perm : perms) {
@@ -401,7 +387,7 @@ public class ArenaMasterImpl implements ArenaMaster
public ArenaClass createClassNode(String classname, PlayerInventory inv, boolean safe) {
String path = "classes." + classname;
if (safe && config.getConfigSection(path) != null) {
if (safe && config.getConfigurationSection(path) != null) {
return null;
}
@@ -409,7 +395,7 @@ public class ArenaMasterImpl implements ArenaMaster
config.set(path, "");
// Grab the section.
ConfigSection section = config.getConfigSection(path);
ConfigurationSection section = config.getConfigurationSection(path);
// Take the current items and armor.
section.set("items", ItemParser.parseString(inv.getContents()));
@@ -422,7 +408,7 @@ public class ArenaMasterImpl implements ArenaMaster
}
// Save changes.
config.save();
plugin.saveConfig();
// Load the class
return loadClass(classname);
@@ -434,8 +420,8 @@ public class ArenaMasterImpl implements ArenaMaster
throw new IllegalArgumentException("Class does not exist!");
// Remove the class from the config-file and save it.
config.remove("classes." + classname);
config.save();
config.set("classes." + classname, null);
plugin.saveConfig();
// Remove the class from the map.
classes.remove(lowercase);
@@ -454,15 +440,14 @@ public class ArenaMasterImpl implements ArenaMaster
private boolean addRemoveClassPermission(String classname, String perm, boolean add) {
classname = TextUtils.camelCase(classname);
String path = "classes." + classname;
if (config.getConfigSection(path) == null)
if (config.getConfigurationSection(path) == null)
return false;
// Grab the class section
ConfigSection section = config.getConfigSection(path);
ConfigurationSection section = config.getConfigurationSection(path);
// Get any previous nodes
List<String> nodes = section.getStringList("permissions", null);
List<String> nodes = section.getStringList("permissions");
if (nodes.contains(perm) && add) {
return false;
}
@@ -479,7 +464,7 @@ public class ArenaMasterImpl implements ArenaMaster
// Replace the set.
section.set("permissions", nodes);
config.save();
plugin.saveConfig();
// Reload the class.
loadClass(classname);
@@ -506,11 +491,12 @@ public class ArenaMasterImpl implements ArenaMaster
* Load all arena-related stuff.
*/
public void loadArenas() {
Set<String> arenanames = config.getKeys("arenas");
ConfigurationSection section = makeSection(config, "arenas");
Set<String> arenanames = section.getKeys(false);
// If no arenas were found, create a default node.
if (arenanames == null || arenanames.isEmpty()) {
createArenaNode("default", plugin.getServer().getWorlds().get(0), false);
createArenaNode(section, "default", plugin.getServer().getWorlds().get(0), false);
}
arenas = new LinkedList<Arena>();
@@ -520,7 +506,7 @@ public class ArenaMasterImpl implements ArenaMaster
}
public void loadArenasInWorld(String worldName) {
Set<String> arenaNames = config.getKeys("arenas");
Set<String> arenaNames = config.getConfigurationSection("arenas").getKeys(false);
if (arenaNames == null || arenaNames.isEmpty()) {
return;
}
@@ -528,7 +514,7 @@ public class ArenaMasterImpl implements ArenaMaster
Arena arena = getArenaWithName(arenaName);
if (arena != null) continue;
String arenaWorld = config.getString("arenas." + arenaName + ".settings.world", null);
String arenaWorld = config.getString("arenas." + arenaName + ".settings.world", "");
if (!arenaWorld.equals(worldName)) continue;
loadArena(arenaName);
@@ -536,7 +522,7 @@ public class ArenaMasterImpl implements ArenaMaster
}
public void unloadArenasInWorld(String worldName) {
Set<String> arenaNames = config.getKeys("arenas");
Set<String> arenaNames = config.getConfigurationSection("arenas").getKeys(false);
if (arenaNames == null || arenaNames.isEmpty()) {
return;
}
@@ -552,90 +538,74 @@ public class ArenaMasterImpl implements ArenaMaster
}
}
// Load an already existing arena node
private Arena loadArena(String arenaname) {
String path = "arenas." + arenaname;
String worldName = config.getString(path + ".settings.world", "");
World world = null;
ConfigurationSection section = makeSection(config, "arenas." + arenaname);
ConfigurationSection settings = makeSection(section, "settings");
String worldName = settings.getString("world", "");
World world;
// If a string was found, try to fetch the world from the server.
if (!worldName.equals("")) {
world = plugin.getServer().getWorld(worldName);
if (world == null) {
Messenger.warning("World '" + worldName + "' for arena '" + arenaname + "' was not found...");
return null;
}
}
// Otherwise, use the default world.
else {
} else {
world = plugin.getServer().getWorlds().get(0);
Messenger.warning("Could not find the world for arena '" + arenaname + "'. Using default world ('" + world.getName() + "')! Check the config-file!");
}
// Assert all settings nodes.
ConfigUtils.replaceAllNodes(plugin.getFilename(), config, path + ".settings", "settings.yml");
ConfigUtils.addMissingRemoveObsolete(plugin, "settings.yml", settings);
ConfigUtils.addIfEmpty(plugin, "waves.yml", makeSection(section, "waves"));
// Create an Arena with the name and world.
Arena arena = new ArenaImpl(plugin, config, arenaname, world);
// Register the permission
Arena arena = new ArenaImpl(plugin, section, arenaname, world);
registerPermission("mobarena.arenas." + arenaname.toLowerCase(), PermissionDefault.TRUE);
// Finally, add it to the arena list.
arenas.add(arena);
plugin.getLogger().info("Loaded arena '" + arenaname + "'");
return arena;
}
// Create and load a new arena node
public Arena createArenaNode(String arenaName, World world) {
return createArenaNode(arenaName, world, true);
ConfigurationSection section = makeSection(config, "arenas");
return createArenaNode(section, arenaName, world, true);
}
private Arena createArenaNode(String arenaName, World world, boolean load) {
String path = "arenas." + arenaName;
if (config.getConfigSection(path) != null)
// Create a new arena node, and (optionally) load it
private Arena createArenaNode(ConfigurationSection arenas, String arenaName, World world, boolean load) {
if (arenas.contains(arenaName)) {
throw new IllegalArgumentException("Arena already exists!");
}
ConfigurationSection section = makeSection(arenas, arenaName);
// Extract the default settings and update the world-node.
ConfigUtils.replaceAllNodes(plugin.getFilename(), config, path + ".settings", "settings.yml");
config.set(path + ".settings.world", world.getName());
// Extract the default waves.
ConfigUtils.replaceAllNodes(plugin.getFilename(), config, path + ".waves", "waves.yml");
// Extract the default rewards.
ConfigUtils.replaceAllNodes(plugin.getFilename(), config, path + ".rewards", "rewards.yml");
// Save the changes.
config.save();
// Add missing settings and remove obsolete ones
ConfigUtils.addMissingRemoveObsolete(plugin, "settings.yml", makeSection(section, "settings"));
section.set("settings.world", world.getName());
ConfigUtils.addIfEmpty(plugin, "waves.yml", makeSection(section, "waves"));
ConfigUtils.addIfEmpty(plugin, "rewards.yml", makeSection(section, "rewards"));
plugin.saveConfig();
// Load the arena
return (load ? loadArena(arenaName) : null);
}
public void removeArenaNode(Arena arena) {
// Remove the arena from the config-file and save it.
config.remove("arenas." + arena.configName());
config.save();
// Remove the arena from the list.
arenas.remove(arena);
unregisterPermission("mobarena.arenas." + arena.configName());
config.set("arenas." + arena.configName(), null);
plugin.saveConfig();
}
public void reloadConfig() {
boolean wasEnabled = isEnabled();
// If MobArena was enabled, disable it before updating.
if (wasEnabled) {
setEnabled(false);
}
if (wasEnabled) setEnabled(false);
for (Arena a : arenas) {
a.forceEnd();
}
config.load();
loadSettings();
loadClasses();
loadArenas();
@@ -643,15 +613,11 @@ public class ArenaMasterImpl implements ArenaMaster
for (Arena arena : arenas) {
Messenger.info("Loaded arena '" + arena.configName() + "'");
}
// If MobArena was enabled, re-enable it after updating.
if (wasEnabled) {
setEnabled(true);
}
setEnabled(wasEnabled);
}
public void saveConfig() {
config.save();
plugin.saveConfig();
}
private Permission registerPermission(String permString, PermissionDefault value) {
@@ -4,36 +4,37 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import com.garbagemule.MobArena.framework.Arena;
import com.garbagemule.MobArena.util.MutableInt;
import com.garbagemule.MobArena.util.config.ConfigSection;
import org.bukkit.plugin.Plugin;
public class ClassLimitManager
{
private HashMap<ArenaClass,MutableInt> classLimits;
private HashMap<ArenaClass, HashSet<String>> classesInUse;
private ConfigSection limits;
private ConfigurationSection limits;
private Map<String,ArenaClass> classes;
public ClassLimitManager(Arena arena, Map<String,ArenaClass> classes, ConfigSection limits) {
public ClassLimitManager(Arena arena, Map<String,ArenaClass> classes, ConfigurationSection limits) {
this.limits = limits;
this.classes = classes;
this.classLimits = new HashMap<ArenaClass,MutableInt>();
this.classesInUse = new HashMap<ArenaClass, HashSet<String>>();
loadLimitMap();
loadLimitMap(arena.getPlugin());
initInUseMap();
}
private void loadLimitMap() {
private void loadLimitMap(Plugin plugin) {
// If the config-section is empty, create and populate it.
if (limits.getKeys() == null) {
if (limits.getKeys(false).isEmpty()) {
for (ArenaClass ac : classes.values()) {
limits.set(ac.getConfigName(), -1);
}
limits.getParent().save();
plugin.saveConfig();
}
// Populate the limits map using the values in the config-file.
+10 -25
View File
@@ -19,6 +19,7 @@ import org.bukkit.block.Sign;
import org.bukkit.World;
import org.bukkit.Material;
import org.bukkit.Location;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Wolf;
@@ -34,7 +35,6 @@ import com.garbagemule.MobArena.region.ArenaRegion;
import com.garbagemule.MobArena.util.EntityPosition;
import com.garbagemule.MobArena.util.ItemParser;
import com.garbagemule.MobArena.util.TextUtils;
import com.garbagemule.MobArena.util.config.Config;
import com.garbagemule.MobArena.util.config.ConfigUtils;
public class MAUtils
@@ -54,30 +54,16 @@ public class MAUtils
* type of wave ("after" or "every") and the config-file. If
* no keys exist in the config-file, an empty map is returned.
*/
public static Map<Integer,List<ItemStack>> getArenaRewardMap(MobArena plugin, Config config, String arena, String type)
public static Map<Integer,List<ItemStack>> getArenaRewardMap(MobArena plugin, ConfigurationSection config, String arena, String type)
{
//String arenaPath = "arenas." + arena + ".rewards.waves.";
String typePath = ConfigUtils.waveRewardList(arena, type);
Map<Integer,List<ItemStack>> result = new HashMap<Integer,List<ItemStack>>();
if (config.getKeys(typePath) == null)
{
if (type.equals("every"))
{
config.set(typePath + ".3", "feather, bone, stick");
config.set(typePath + ".5", "dirt:4, gravel:4, stone:4");
config.set(typePath + ".10", "iron_ingot:10, gold_ingot:8");
}
else if (type.equals("after"))
{
config.set(typePath + ".7", "minecart, storage_minecart, powered_minecart");
config.set(typePath + ".13", "iron_sword, iron_pickaxe, iron_spade");
config.set(typePath + ".16", "diamond_sword");
}
}
String typePath = "rewards." + type;
if (!config.contains(typePath)) return result;
//Set<String> waves = config.getKeys(arenaPath + type);
Set<String> waves = config.getKeys(typePath);
Set<String> waves = config.getConfigurationSection(typePath).getKeys(false);
if (waves == null) return result;
for (String n : waves)
@@ -86,7 +72,7 @@ public class MAUtils
continue;
int wave = Integer.parseInt(n);
String path = ConfigUtils.waveReward(arena, type, wave);
String path = typePath + "." + wave;
String rewards = config.getString(path);
result.put(wave, ItemParser.parseItems(rewards));
@@ -494,10 +480,9 @@ public class MAUtils
{
world.getBlockAt(entry.getKey().getLocation(world)).setTypeId(entry.getValue());
}
Config config = plugin.getMAConfig();
config.remove("arenas." + name);
config.save();
plugin.getConfig().set("arenas." + name, null);
plugin.saveConfig();
file.delete();
+16 -36
View File
@@ -29,9 +29,7 @@ import com.garbagemule.MobArena.listeners.MAGlobalListener;
import com.garbagemule.MobArena.listeners.MagicSpellsListener;
import com.garbagemule.MobArena.listeners.SpoutScreenListener;
import com.garbagemule.MobArena.metrics.Metrics;
import com.garbagemule.MobArena.util.FileUtils;
import com.garbagemule.MobArena.util.VersionChecker;
import com.garbagemule.MobArena.util.config.Config;
import com.garbagemule.MobArena.util.config.ConfigUtils;
import com.garbagemule.MobArena.util.inventory.InventoryManager;
import com.garbagemule.MobArena.waves.ability.AbilityManager;
@@ -42,7 +40,6 @@ import com.garbagemule.MobArena.waves.ability.AbilityManager;
*/
public class MobArena extends JavaPlugin
{
private Config config;
private ArenaMaster arenaMaster;
private CommandHandler commandHandler;
@@ -69,35 +66,35 @@ public class MobArena extends JavaPlugin
// Load boss abilities
loadAbilities();
// Set up soft dependencies
setupVault();
setupHeroes();
setupSpout();
setupMagicSpells();
setupStrategies();
// Set up the ArenaMaster
arenaMaster = new ArenaMasterImpl(this);
arenaMaster.initialize();
// Register any inventories to restore.
registerInventories();
// Make sure all the announcements are configured.
MAMessages.init(this);
// Register event listeners
registerListeners();
// Go go Metrics
startMetrics();
// Announce enable!
Messenger.info("v" + this.getDescription().getVersion() + " enabled.");
// Check for updates
if (config.getBoolean("global-settings.update-notification", false)) {
if (getConfig().getBoolean("global-settings.update-notification", false)) {
VersionChecker.checkForUpdates(this, null);
}
}
@@ -117,11 +114,12 @@ public class MobArena extends JavaPlugin
}
private void loadConfigFile() {
// Create if missing
saveDefaultConfig();
config = new Config(new File(getDataFolder(), "config.yml"));
updateSettings(config);
config.setHeader(getHeader());
config.save();
// Set the header and save
getConfig().options().header(getHeader());
saveConfig();
}
private void registerListeners() {
@@ -184,7 +182,7 @@ public class MobArena extends JavaPlugin
private void setupMagicSpells() {
Plugin spells = this.getServer().getPluginManager().getPlugin("MagicSpells");
if (spells == null) return;
this.getServer().getPluginManager().registerEvents(new MagicSpellsListener(this), this);
}
@@ -213,10 +211,6 @@ public class MobArena extends JavaPlugin
return healthStrategy;
}
public Config getMAConfig() {
return config;
}
public ArenaMaster getArenaMaster() {
return arenaMaster;
}
@@ -225,21 +219,11 @@ public class MobArena extends JavaPlugin
return commandHandler;
}
private void updateSettings(Config config) {
Set<String> arenas = config.getKeys("arenas");
if (arenas == null) return;
for (String arena : arenas) {
String path = "arenas." + arena + ".settings";
ConfigUtils.replaceAllNodes(getFilename(), config, path, "settings.yml");
}
}
private String getHeader() {
String sep = System.getProperty("line.separator");
return "MobArena v" + this.getDescription().getVersion() + " - Config-file" + sep +
"Read the Wiki for details on how to set up this file: http://goo.gl/F5TTc" + sep +
"Note: You -must- use spaces instead of tabs!\r";
"Note: You -must- use spaces instead of tabs!";
}
private void registerInventories() {
@@ -303,8 +287,4 @@ public class MobArena extends JavaPlugin
double minor = item.getDurability() / 100D;
return major + minor;
}
public String getFilename() {
return super.getFile().getName();
}
}
@@ -49,7 +49,7 @@ public class DisableCommand implements Command
private void disable(Arena arena, CommandSender sender) {
arena.setEnabled(false);
arena.getSettings().getParent().save();
arena.getPlugin().saveConfig();
Messenger.tellPlayer(sender, "Arena '" + arena.configName() + "' " + ChatColor.RED + "disabled");
}
}
@@ -49,7 +49,7 @@ public class EnableCommand implements Command
private void enable(Arena arena, CommandSender sender) {
arena.setEnabled(true);
arena.getSettings().getParent().save();
arena.getPlugin().saveConfig();
Messenger.tellPlayer(sender, "Arena '" + arena.configName() + "' " + ChatColor.GREEN + "enabled");
}
}
@@ -51,7 +51,7 @@ public class ClassChestCommand implements Command {
return true;
}
am.getPlugin().getMAConfig().set("classes." + ac.getConfigName() + ".classchest", b.getLocation());
am.getPlugin().getConfig().set("classes." + ac.getConfigName() + ".classchest", b.getLocation());
am.saveConfig();
Messenger.tellPlayer(sender, "Class chest updated for class " + ac.getConfigName());
am.loadClasses();
@@ -19,8 +19,8 @@ public class ContainersCommand implements Command
{
@Override
public boolean execute(ArenaMaster am, CommandSender sender, String... args) {
StringBuffer buffy = new StringBuffer();
Set<String> containers = am.getPlugin().getMAConfig().getKeys("arenas." + am.getSelectedArena().configName() + ".coords.containers");
StringBuilder buffy = new StringBuilder();
Set<String> containers = am.getPlugin().getConfig().getConfigurationSection("arenas." + am.getSelectedArena().configName() + ".coords.containers").getKeys(false);
if (containers != null) {
for (String c : containers) {
@@ -67,8 +67,8 @@ public class ProtectCommand implements Command
}
arena.setProtected(arg2.equals("true"));
}
arena.getSettings().getParent().save();
arena.getPlugin().saveConfig();
Messenger.tellPlayer(sender, "Protection for arena '" + arena.configName() + "': " + ((arena.isProtected()) ? ChatColor.GREEN + "on" : ChatColor.RED + "off"));
return true;
}
@@ -19,8 +19,8 @@ public class SpawnpointsCommand implements Command
{
@Override
public boolean execute(ArenaMaster am, CommandSender sender, String... args) {
StringBuffer buffy = new StringBuffer();
Set<String> spawnpoints = am.getPlugin().getMAConfig().getKeys("arenas." + am.getSelectedArena().configName() + ".coords.spawnpoints");
StringBuilder buffy = new StringBuilder();
Set<String> spawnpoints = am.getPlugin().getConfig().getConfigurationSection("arenas." + am.getSelectedArena().configName() + ".coords.spawnpoints").getKeys(false);
if (spawnpoints != null) {
for (String s : spawnpoints) {
@@ -6,6 +6,7 @@ import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@@ -22,7 +23,6 @@ import com.garbagemule.MobArena.ScoreboardManager;
import com.garbagemule.MobArena.leaderboards.Leaderboard;
import com.garbagemule.MobArena.region.ArenaRegion;
import com.garbagemule.MobArena.repairable.Repairable;
import com.garbagemule.MobArena.util.config.ConfigSection;
import com.garbagemule.MobArena.util.inventory.InventoryManager;
import com.garbagemule.MobArena.waves.WaveManager;
@@ -33,8 +33,8 @@ public interface Arena
// NEW METHODS IN REFACTORING
//
/////////////////////////////////////////////////////////////////////////*/
public ConfigSection getSettings();
public ConfigurationSection getSettings();
public World getWorld();
@@ -4,13 +4,14 @@ import java.io.File;
import java.util.LinkedList;
import java.util.List;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import com.garbagemule.MobArena.framework.Arena;
import com.garbagemule.MobArena.util.FileUtils;
import com.garbagemule.MobArena.util.config.Config;
import com.garbagemule.MobArena.waves.enums.*;
import com.garbagemule.MobArena.MobArena;
import com.nisovin.magicspells.events.SpellCastEvent;
@@ -23,12 +24,16 @@ public class MagicSpellsListener implements Listener
public MagicSpellsListener(MobArena plugin)
{
this.plugin = plugin;
// Set up the MagicSpells config-file.
File spellFile = FileUtils.extractResource(plugin.getDataFolder(), "magicspells.yml", plugin.getClass());
Config spellConfig = new Config(spellFile);
spellConfig.load();
setupSpells(spellConfig);
plugin.saveResource("res/magicspells.yml", false);
FileConfiguration config = new YamlConfiguration();
try {
config.load(new File(plugin.getDataFolder(), "magicspells.yml"));
setupSpells(config);
} catch (Exception e) {
e.printStackTrace();
}
}
@EventHandler(priority = EventPriority.NORMAL)
@@ -47,10 +52,10 @@ public class MagicSpellsListener implements Listener
}
}
private void setupSpells(Config config)
private void setupSpells(ConfigurationSection config)
{
this.disabled = config.getStringList("disabled-spells", new LinkedList<String>());
this.disabledOnBoss = config.getStringList("disabled-on-bosses", new LinkedList<String>());
this.disabledOnSwarm = config.getStringList("disabled-on-swarms", new LinkedList<String>());
this.disabled = config.getStringList("disabled-spells");
this.disabledOnBoss = config.getStringList("disabled-on-bosses");
this.disabledOnSwarm = config.getStringList("disabled-on-swarms");
}
}
@@ -1,13 +1,9 @@
package com.garbagemule.MobArena.region;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.garbagemule.MobArena.MAUtils;
import com.garbagemule.MobArena.Messenger;
import com.garbagemule.MobArena.MobArena;
import com.garbagemule.MobArena.framework.Arena;
import com.garbagemule.MobArena.util.Enums;
import org.bukkit.ChatColor;
import org.bukkit.Chunk;
@@ -16,12 +12,12 @@ import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import com.garbagemule.MobArena.Messenger;
import com.garbagemule.MobArena.MobArena;
import com.garbagemule.MobArena.framework.Arena;
import com.garbagemule.MobArena.util.config.ConfigSection;
import java.util.*;
import static com.garbagemule.MobArena.util.config.ConfigUtils.*;
public class ArenaRegion
{
@@ -34,17 +30,17 @@ public class ArenaRegion
private boolean setup, lobbySetup;
private ConfigSection coords;
private ConfigSection spawns;
private ConfigSection chests;
private ConfigurationSection coords;
private ConfigurationSection spawns;
private ConfigurationSection chests;
public ArenaRegion(ConfigSection coords, Arena arena) {
public ArenaRegion(ConfigurationSection section, Arena arena) {
this.arena = arena;
refreshWorld();
this.coords = coords;
this.spawns = coords.getConfigSection("spawnpoints");
this.chests = coords.getConfigSection("containers");
this.coords = makeSection(section, "coords");
this.spawns = makeSection(coords, "spawnpoints");
this.chests = makeSection(coords, "containers");
reloadAll();
}
@@ -64,24 +60,24 @@ public class ArenaRegion
}
public void reloadRegion() {
p1 = coords.getLocation("p1", world);
p2 = coords.getLocation("p2", world);
p1 = parseLocation(coords, "p1", world);
p2 = parseLocation(coords, "p2", world);
//fixRegion();
l1 = coords.getLocation("l1", world);
l2 = coords.getLocation("l2", world);
l1 = parseLocation(coords, "l1", world);
l2 = parseLocation(coords, "l2", world);
//fixLobbyRegion();
}
public void reloadWarps() {
arenaWarp = coords.getLocation("arena", world);
lobbyWarp = coords.getLocation("lobby", world);
specWarp = coords.getLocation("spectator", world);
exitWarp = coords.getLocation("exit", null);
arenaWarp = parseLocation(coords, "arena", world);
lobbyWarp = parseLocation(coords, "lobby", world);
specWarp = parseLocation(coords, "spectator", world);
exitWarp = parseLocation(coords, "exit", null);
}
public void reloadLeaderboards() {
leaderboard = coords.getLocation("leaderboard", null);
leaderboard = parseLocation(coords, "leaderboard", null);
if (leaderboard != null && leaderboard.getWorld() == null) {
leaderboard.setWorld(world);
}
@@ -89,20 +85,20 @@ public class ArenaRegion
public void reloadSpawnpoints() {
spawnpoints = new HashMap<String,Location>();
Set<String> keys = spawns.getKeys();
Set<String> keys = spawns.getKeys(false);
if (keys != null) {
for (String spwn : keys) {
spawnpoints.put(spwn, spawns.getLocation(spwn, world));
spawnpoints.put(spwn, parseLocation(spawns, spwn, world));
}
}
}
public void reloadChests() {
containers = new HashMap<String,Location>();
Set<String> keys = chests.getKeys();
Set<String> keys = chests.getKeys(false);
if (keys != null) {
for (String chst : keys) {
containers.put(chst, chests.getLocation(chst, world));
containers.put(chst, parseLocation(chests, chst, world));
}
}
}
@@ -229,25 +225,31 @@ public class ArenaRegion
// Region expand
public void expandUp(int amount) {
p2.setY(Math.min(arena.getWorld().getMaxHeight(), p2.getY() + amount));
set(RegionPoint.P2, p2);
Location l = new Location(p2.getWorld(), p2.getX(), Math.min(p2.getWorld().getMaxHeight(), p2.getY() + amount), p2.getZ());
setLocation(coords, "p2", l);
save();
reloadRegion();
}
public void expandDown(int amount) {
p1.setY(Math.max(0D, p1.getY() - amount));
set(RegionPoint.P1, p1);
Location l = new Location(p1.getWorld(), p1.getX(), Math.max(0D, p1.getY() - amount), p1.getZ());
setLocation(coords, "p1", l);
save();
reloadRegion();
}
public void expandP1(int x, int z) {
p1.setX(p1.getX() - x);
p1.setZ(p1.getZ() - z);
set(RegionPoint.P1, p1);
Location l = new Location(p1.getWorld(), p1.getX() - x, p1.getY(), p1.getZ() - z);
setLocation(coords, "p1", l);
save();
reloadRegion();
}
public void expandP2(int x, int z) {
p2.setX(p2.getX() + x);
p2.setZ(p2.getZ() + z);
set(RegionPoint.P2, p2);
Location l = new Location(p2.getWorld(), p2.getX() + x, p2.getY(), p2.getZ() + z);
setLocation(coords, "p2", l);
save();
reloadRegion();
}
public void expandOut(int amount) {
@@ -292,8 +294,8 @@ public class ArenaRegion
}
private void fix(String location1, String location2) {
Location loc1 = coords.getLocation(location1, world);
Location loc2 = coords.getLocation(location2, world);
Location loc1 = parseLocation(coords, location1, world);
Location loc2 = parseLocation(coords, location2, world);
if (loc1 == null || loc2 == null) {
return;
@@ -331,8 +333,8 @@ public class ArenaRegion
return;
}
coords.set(location1, loc1);
coords.set(location2, loc2);
setLocation(coords, location1, loc1);
setLocation(coords, location2, loc2);
save();
}
@@ -479,8 +481,8 @@ public class ArenaRegion
}
// Set the coords and save
if (lower != null) coords.set(r1.name().toLowerCase(), lower);
if (upper != null) coords.set(r2.name().toLowerCase(), upper);
if (lower != null) setLocation(coords, r1.name().toLowerCase(), lower);
if (upper != null) setLocation(coords, r2.name().toLowerCase(), upper);
save();
// Reload regions and verify data
@@ -499,7 +501,7 @@ public class ArenaRegion
public void setWarp(RegionPoint point, Location l) {
// Set the point and save
coords.set(point.toString(), l);
setLocation(coords, point.toString(), l);
save();
// Then reload warps
@@ -508,7 +510,7 @@ public class ArenaRegion
public void setLeaderboard(Location l) {
// Set the point and save
coords.set("leaderboard", l);
setLocation(coords, "leaderboard", l);
save();
// Then reload the leaderboards
@@ -517,7 +519,7 @@ public class ArenaRegion
public void addSpawn(String name, Location loc) {
// Add the spawn and save
spawns.set(name, loc);
setLocation(spawns, name, loc);
save();
// Reload spawnpoints and verify data
@@ -532,7 +534,7 @@ public class ArenaRegion
}
// Null the spawnpoint and save
spawns.set(name, null);
setLocation(spawns, name, null);
save();
// Reload spawnpoints and verify data
@@ -543,7 +545,7 @@ public class ArenaRegion
public void addChest(String name, Location loc) {
// Add the chest location and save
chests.set(name, loc);
setLocation(chests, name, loc);
save();
// Reload the chests
@@ -557,7 +559,7 @@ public class ArenaRegion
}
// Null the chest and save
chests.set(name, null);
setLocation(chests, name, null);
save();
// Reload the chests
@@ -566,7 +568,7 @@ public class ArenaRegion
}
public void save() {
spawns.getParent().save();
arena.getPlugin().saveConfig();
}
public void showRegion(final Player p) {
@@ -1,125 +0,0 @@
package com.garbagemule.MobArena.util;
import java.io.*;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipInputStream;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import com.garbagemule.MobArena.Messenger;
import com.garbagemule.MobArena.MobArena;
public class FileUtils
{
/**
* Extracts all of the given resources to the given directory.
* Note that even if the resources have different paths, they will all
* be extracted to the given directory.
* @param dir a directory
* @param resources a list of resources to extract
* @return a list of all the files that were written
*/
public static List<File> extractResources(File dir, List<String> resources, Class<?> cls) {
return extractResources(dir, "", resources, cls);
}
public static List<File> extractResources(File dir, String path, List<String> filenames, Class<?> cls) {
List<File> files = new ArrayList<File>();
// If the path is empty, just forget about it.
if (!path.equals("")) {
// We want no leading slashes
if (path.startsWith("/")) {
path = path.substring(1);
}
// But we do want trailing slashes
if (!path.endsWith("/")) {
path = path + "/";
}
}
// Extract each resource
for (String filename : filenames) {
File file = extractResource(dir, path + filename, cls);
if (file != null) {
files.add(file);
}
}
return files;
}
/**
* Extracts the given resource to the given directory.
* @param dir a directory
* @param resource a resource to extract
* @return the file that was written, or null
*/
public static File extractResource(File dir, String resource, Class<?> cls) {
if (!dir.exists()) dir.mkdirs();
// Set up our new file.
String filename = getFilename(resource);
File file = new File(dir, filename);
// If the file already exists, don't do anything.
if (file.exists()) return file;
// Grab the resource input stream.
InputStream in = cls.getResourceAsStream("/res/" + resource);
if (in == null) return null;
try {
// Set up an output stream.
FileOutputStream out = new FileOutputStream(file);
byte[] buffer = new byte[4096];
// Read into the buffer and write it out to the file.
int read = 0;
while ((read = in.read(buffer)) > 0) {
out.write(buffer, 0, read);
}
// Close stuff.
in.close();
out.close();
// Return the new file.
return file;
}
catch (Exception e) {}
return null;
}
private static String getFilename(String resource) {
int slash = resource.lastIndexOf("/");
return (slash < 0 ? resource : resource.substring(slash + 1));
}
private static final String RES = "res/";
private static final String PLUGINS = "plugins/";
/**
* Get a YamlConfiguration of a given resource.
* @param filename the name of the resource
* @return a YamlConfiguration for the given resource
* @throws IOException if the resource does not exist
* @throws InvalidConfigurationException if the resource is not a valid config
*/
public static YamlConfiguration getConfig(String filename, String resourcename) throws IOException, InvalidConfigurationException {
ZipFile zip = new ZipFile(PLUGINS + filename);
ZipEntry entry = zip.getEntry(RES + resourcename);
YamlConfiguration yaml = new YamlConfiguration();
yaml.load(zip.getInputStream(entry));
return yaml;
}
}
@@ -1,492 +0,0 @@
package com.garbagemule.MobArena.util.config;
import java.io.File;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.inventory.ItemStack;
import com.garbagemule.MobArena.Messenger;
/**
* Wrapper class for Bukkit's Configuration classes.
*
* The motivation for this class is two-fold:
*
* 1) Provide a means of keeping a reference to the physical disk file
* in the same class as the YamlConfiguration for easy load and save.
* 2) Speed up the access times for the YamlConfiguration by loading all
* values into maps, as to avoid local fields in certain classes.
*
* The specific getters (getInteger, getBoolean, etc.) never call methods on
* the YamlConfiguration. Instead, they interact only with the value maps,
* which speeds up the access times 20-fold. The generic getter (get), does,
* however, interact with the YamlConfiguration (for now).
*
* The mutators (set, remove, etc.) interact with both the YamlConfiguration
* and the value maps for consistency. This means modifications become slightly
* slower, but the difference is neglegible.
*
* @author garbagemule, slipcor
*
* Use this class however you see fit, but please leave this description in,
* as to not unrightfully take credit for our work :)
*/
public class Config
{
private YamlConfiguration config;
private File configFile;
private Map<String,Boolean> booleans;
private Map<String,Integer> ints;
private Map<String,Double> doubles;
private Map<String,String> strings;
private Map<String,ItemStack> items;
/**
* Create a new Config instance that uses the specified file for
* loading and saving.
* @param configFile a YAML file
*/
public Config(File configFile) {
this.config = new YamlConfiguration();
this.configFile = configFile;
this.booleans = new HashMap<String,Boolean>();
this.ints = new HashMap<String,Integer>();
this.doubles = new HashMap<String,Double>();
this.strings = new HashMap<String,String>();
this.items = new HashMap<String,ItemStack>();
this.config.options().indent(4);
}
/**
* Load the config-file into the YamlConfiguration, and then populate
* the value maps.
* @return true, if the load succeeded, false otherwise.
*/
public boolean load() {
try {
if (!configFile.exists()) {
configFile.createNewFile();
}
config.load(configFile);
reloadMaps();
return true;
}
catch (Exception e) {
Messenger.severe("The config-file failed to load. This is the error:\n" + e.getMessage());
return false;
}
}
/**
* Iterates through all keys in the config-file, and populates the
* value maps. Boolean values are stored in the booleans-map, Strings
* in the strings-map, etc.
*/
public void reloadMaps() {
for (String s : config.getKeys(true)) {
Object o = config.get(s);
if (o instanceof Boolean) {
booleans.put(s, (Boolean) o);
} else if (o instanceof Integer) {
ints.put(s, (Integer) o);
} else if (o instanceof Double) {
doubles.put(s, (Double) o);
} else if (o instanceof ItemStack) {
items.put(s, (ItemStack) o);
} else if (o instanceof String) {
strings.put(s, (String) o);
}
}
}
/**
* Save the YamlConfiguration to the config-file.
* @return true, if the save succeeded, false otherwise.
*/
public boolean save() {
try {
config.save(configFile);
load(); // enforce consistency
return true;
}
catch (Exception e) {
e.printStackTrace();
return false;
}
}
/**
* Get the header of the config-file.
* @return the header
*/
public String getHeader() {
return config.options().header();
}
/**
* Set the header of the config-file.
* @param header the header
*/
public void setHeader(String header) {
config.options().header(header);
}
///////////////////////////////////////////////////////////////////////////
// //
// GETTERS //
// //
///////////////////////////////////////////////////////////////////////////
/**
* Get the YamlConfiguration associated with this Config instance.
* Note that changes made directly to the YamlConfiguration will cause an
* inconsistency with the value maps unless reloadMaps() is called.
* @return the YamlConfiguration of this Config instance
*/
public YamlConfiguration getYamlConfiguration() {
return config;
}
/**
* Grab a section of this Config.
* @param node
* @return
*/
public ConfigSection getConfigSection(String node) {
if (get(node) != null) {
return new ConfigSection(this, node);
}
return null;
}
/**
* Retrieve a value from the YamlConfiguration.
* @param path the path of the value
* @return the value of the path
*/
public Object get(String path) {
return config.get(path);
}
/**
* Retrieve a boolean from the value maps.
* @param path the path of the value
* @return the boolean value of the path if the path exists, false otherwise
*/
public boolean getBoolean(String path) {
return getBoolean(path, false);
}
/**
* Retrieve a boolean from the value maps.
* @param path the path of the value
* @param def a default value to return if the value was not in the map
* @return the boolean value of the path if it exists, def otherwise
*/
public boolean getBoolean(String path, boolean def) {
Boolean result = booleans.get(path);
return (result != null ? result : def);
}
/**
* Retrieve an int from the value maps.
* @param path the path of the value
* @return the int value of the path if the path exists, 0 otherwise
*/
public int getInt(String path) {
return getInt(path, 0);
}
/**
* Retrieve an int from the value maps.
* @param path the path of the value
* @param def a default value to return if the value was not in the map
* @return the int value of the path if it exists, def otherwise
*/
public int getInt(String path, int def) {
Integer result = ints.get(path);
return (result != null ? result : def);
}
/**
* Retrieve a double from the value maps.
* @param path the path of the value
* @return the double value of the path if the path exists, 0D otherwise
*/
public double getDouble(String path) {
return getDouble(path, 0D);
}
/**
* Retrieve a double from the value maps.
* @param path the path of the value
* @param def a default value to return if the value was not in the map
* @return the double value of the path if it exists, def otherwise
*/
public double getDouble(String path, double def) {
Double result = doubles.get(path);
return (result != null ? result : def);
}
/**
* Retrieve a string from the value maps.
* @param path the path of the value
* @return the string value of the path if the path exists, null otherwise
*/
public String getString(String path) {
return getString(path, null);
}
/**
* Retrieve a string from the value maps.
* @param path the path of the value
* @param def a default value to return if the value was not in the map
* @return the string value of the path if it exists, def otherwise
*/
public String getString(String path, String def) {
String result = strings.get(path);
return (result != null ? result : def);
}
public Location getLocation(String path, World world) {
return getLocation(path, world, null);
}
public Location getLocation(String path, World world, Location def) {
String string = getString(path);
if (string == null)
return def;
if (world == null && string.split(",").length == 6)
return parseLocation(string);
return parseLocation(world, string);
}
public ItemStack getItemStack(String path) {
return getItemStack(path, null);
}
public ItemStack getItemStack(String path, ItemStack def) {
ItemStack result = items.get(path);
return (result != null ? result : def);
}
public Set<String> getKeys(String path) {
if (config.get(path) == null)
return null;
ConfigurationSection section = config.getConfigurationSection(path);
if (section == null)
return null;
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 ArrayList<String>();
List<?> list = config.getStringList(path);
return (List<String>) list;
}
///////////////////////////////////////////////////////////////////////////
// //
// MUTATORS //
// //
///////////////////////////////////////////////////////////////////////////
/**
* Set the value of the given path in both the value maps and the
* YamlConfiguration. Note that this will only properly put the value
* in its relevant value map, if it is of one of the supported types.
* The method can also be used to remove values from their maps and
* the YamlConfiguration by passing null for the value.
* @param path the path on which to set the value
* @param value the value to set
*/
public void set(String path, Object value) {
if (value instanceof Boolean) {
booleans.put(path, (Boolean) value);
} else if (value instanceof Integer) {
ints.put(path, (Integer) value);
} else if (value instanceof Double) {
doubles.put(path, (Double) value);
} else if (value instanceof ItemStack) {
items.put(path, (ItemStack) value);
} else if (value instanceof String) {
strings.put(path, (String) value);
} else if (value instanceof Location) {
value = locationToString((Location) value);
strings.put(path, value.toString());
}
if (value == null) {
booleans.remove(path);
ints.remove(path);
doubles.remove(path);
strings.remove(path);
items.remove(path);
}
config.set(path, value);
}
/**
* Remove the node at the given path. Uses the set() method with null
* as the value.
* @param path the path of the node to remove
*/
public void remove(String path) {
this.set(path, null);
}
///////////////////////////////////////////////////////////////////////////
// //
// UTILITY METHODS //
// //
///////////////////////////////////////////////////////////////////////////
/**
* Parse an input string on the form "x,y,z" and an input World to create
* a Location. This method will only accept strings of the specified form.
* @param world the World in which the Location exists
* @param coords a string on the form "x,y,z"
* @return a Location in the given world with the given coordinates
*/
public static Location parseSimpleLocation(World world, String coords) {
String[] parts = coords.split(",");
if (parts.length != 3)
throw new IllegalArgumentException("Input string must contain only x, y, and z");
Integer x = parseInteger(parts[0]);
Integer y = parseInteger(parts[1]);
Integer z = parseInteger(parts[2]);
if (x == null || y == null || z == null)
throw new NullPointerException("Some of the parsed values are null!");
return new Location(world, x, y, z);
}
public static Location parseLocation(String coords) {
String[] parts = coords.split(",");
if (parts.length != 6)
throw new IllegalArgumentException("Input string must contain x, y, z, yaw, pitch, and world");
Float x = parseFloat(parts[0]);
Float y = parseFloat(parts[1]);
Float z = parseFloat(parts[2]);
Float yaw = parseFloat(parts[3]);
Float pitch = parseFloat(parts[4]);
World world = Bukkit.getServer().getWorld(parts[5]);
Validate.notNull(x, "x value is null");
Validate.notNull(y, "y value is null");
Validate.notNull(z, "z value is null");
Validate.notNull(yaw, "yaw value is null");
Validate.notNull(pitch, "pitch value is null");
Validate.notNull(world, "pitch value is null");
return new Location(world, x, y, z, yaw, pitch);
}
/**
* Parse an input string on the form "x,y,z,yaw,pitch" and an input World
* to create a Location. This method will only accept strings of the
* specified form.
* @param world the World in which the Location exists
* @param coords a string on the form "x,y,z,yaw,pitch"
* @return a Location in the given world with the given coordinates
*/
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");
Float x = parseFloat(parts[0]);
Float y = parseFloat(parts[1]);
Float z = parseFloat(parts[2]);
Float yaw = parseFloat(parts[3]);
Float pitch = parseFloat(parts[4]);
Validate.notNull(x, "x value is null");
Validate.notNull(y, "y value is null");
Validate.notNull(z, "z value is null");
Validate.notNull(yaw, "yaw value is null");
Validate.notNull(pitch, "pitch value is null");
return new Location(world, x, y, z, yaw, pitch);
}
/**
* Create a String representation of a Location object.
* @param loc a Location
* @return a String of the form "x,y,z,yaw,pitch"
*/
public static String locationToString(Location loc) {
StringBuilder result = new StringBuilder();
result.append(twoPlaces(loc.getX())).append(",");
result.append(twoPlaces(loc.getY())).append(",");
result.append(twoPlaces(loc.getZ())).append(",");
result.append(twoPlaces(loc.getYaw(), true)).append(",");
result.append(twoPlaces(loc.getPitch(), true)).append(",");
result.append(loc.getWorld().getName());
return result.toString();
}
private static Integer parseInteger(String s) {
try {
return Integer.parseInt(s.trim());
}
catch (Exception e) {
e.printStackTrace();
return null;
}
}
private static Float parseFloat(String s) {
try {
return Float.parseFloat(s.trim());
}
catch (Exception e) {
e.printStackTrace();
return null;
}
}
private static String twoPlaces(double value, boolean force) {
return force ? DF_FORCE.format(value) : DF_NORMAL.format(value);
}
private static String twoPlaces(double value) {
return twoPlaces(value, false);
}
private static final DecimalFormat DF_NORMAL = new DecimalFormat("0.##");
private static final DecimalFormat DF_FORCE = new DecimalFormat("0.0#");
}
@@ -1,97 +0,0 @@
package com.garbagemule.MobArena.util.config;
import java.util.List;
import java.util.Set;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.inventory.ItemStack;
import com.garbagemule.MobArena.util.config.Config;
public class ConfigSection
{
private Config config;
private String path;
public ConfigSection(Config config, String path) {
this.config = config;
this.path = (path.endsWith(".") ? path : path + ".");
}
public Config getParent() {
return config;
}
public ConfigSection getConfigSection(String path) {
return new ConfigSection(config, this.path + path);
}
public Object get(String node) {
return config.get(path + node);
}
public int getInt(String node) {
return config.getInt(path + node);
}
public int getInt(String node, int def) {
return config.getInt(path + node, def);
}
public double getDouble(String node) {
return config.getDouble(path + node);
}
public double getDouble(String node, double def) {
return config.getDouble(path + node, def);
}
public boolean getBoolean(String node) {
return config.getBoolean(path + node);
}
public boolean getBoolean(String node, boolean def) {
return config.getBoolean(path + node, def);
}
public String getString(String node) {
return config.getString(path + node);
}
public String getString(String node, String def) {
return config.getString(path + node, def);
}
public Location getLocation(String node, World world) {
return config.getLocation(path + node, world);
}
public Location getLocation(String node, World world, Location def) {
return config.getLocation(path + node, world, def);
}
public ItemStack getItemStack(String path) {
return config.getItemStack(path);
}
public ItemStack getItemStack(String path, ItemStack def) {
return config.getItemStack(path, def);
}
public Set<String> getKeys() {
return config.getKeys(path);
}
public Set<String> getKeys(String node) {
return config.getKeys(path + node);
}
public List<String> getStringList(String node, List<String> def) {
return config.getStringList(path + node, def);
}
public void set(String node, Object value) {
config.set(path + node, value);
}
}
@@ -1,85 +1,112 @@
package com.garbagemule.MobArena.util.config;
import java.util.Set;
import com.garbagemule.MobArena.Messenger;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin;
import com.garbagemule.MobArena.MobArena;
import com.garbagemule.MobArena.framework.Arena;
import com.garbagemule.MobArena.util.FileUtils;
import java.text.DecimalFormat;
import java.util.Set;
public class ConfigUtils
{
public static void addMissingNodes(String filename, Config config, String path, String resourcename) {
assertNodes(filename, config, path, resourcename, true);
public static void addIfEmpty(Plugin plugin, String resource, ConfigurationSection section) {
process(plugin, resource, section, true, false);
}
public static void replaceAllNodes(String filename, Config config, String path, String resourcename) {
assertNodes(filename, config, path, resourcename, false);
}
private static void assertNodes(String filename, Config config, String path, String resourcename, boolean keepOthers) {
// Grab the section that the path is pointing to.
ConfigSection section = config.getConfigSection(path);
// If null, create the node.
if (section == null) {
config.set(path, "");
section = config.getConfigSection(path);
}
public static void addMissingRemoveObsolete(Plugin plugin, String resource, ConfigurationSection section) {
process(plugin, resource, section, false, true);
}
private static void process(Plugin plugin, String resource, ConfigurationSection section, boolean addOnlyIfEmpty, boolean removeObsolete) {
try {
// Extract the yml file.
YamlConfiguration ymlConfig = FileUtils.getConfig(filename, resourcename);
// Assert the nodes.
assertNodes(section, ymlConfig, keepOthers);
YamlConfiguration defaults = new YamlConfiguration();
defaults.load(plugin.getResource("res/" + resource));
Set<String> present = section.getKeys(true);
Set<String> required = defaults.getKeys(true);
if (!addOnlyIfEmpty || present.isEmpty()) {
for (String req : required) {
if (!present.remove(req)) {
section.set(req, defaults.get(req));
}
}
}
if (removeObsolete) {
for (String obs : present) {
section.set(obs, null);
}
}
plugin.saveConfig();
} catch (Exception e) {
e.printStackTrace();
Messenger.severe("Failed to load '" + resourcename + "'. Restart required!");
}
}
private static void assertNodes(ConfigSection config, YamlConfiguration ymlConfig, boolean keepOthers) {
if (config == null || ymlConfig == null) return;
// Grab the default keys.
Set<String> keys = ymlConfig.getKeys(false);
if (keys == null || keys.isEmpty()) return;
// First ensure that all default nodes exist
for (String key : keys) {
if (config.get(key) == null) {
Object o = ymlConfig.get(key);
config.set(key, o);
}
}
// If any other nodes in the config should remain, return
if (keepOthers) return;
// Otherwise, grab all the current nodes.
Set<String> oldKeys = config.getKeys();
if (oldKeys == null || oldKeys.isEmpty()) return;
// Remove all nodes that aren't in the defaults.
for (String old : oldKeys) {
if (!keys.contains(old)) {
config.set(old, null);
}
public static ConfigurationSection makeSection(ConfigurationSection config, String section) {
if (!config.contains(section)) {
return config.createSection(section);
} else {
return config.getConfigurationSection(section);
}
}
public static String waveRewardList(String arena, String type) {
return "arenas." + arena + ".rewards.waves." + type;
public static Location parseLocation(ConfigurationSection config, String path, World world) {
String value = config.getString(path);
if (value == null) return null;
String[] parts = value.split(",");
if (parts.length < 3) {
throw new IllegalArgumentException("A location must be at least (x,y,z)");
}
Double x = Double.parseDouble(parts[0]);
Double y = Double.parseDouble(parts[1]);
Double z = Double.parseDouble(parts[2]);
if (parts.length == 3) {
return new Location(world, x, y, z);
}
if (parts.length < 5) {
throw new IllegalArgumentException("Expected location of type (x,y,z,yaw,pitch)");
}
Float yaw = Float.parseFloat(parts[3]);
Float pit = Float.parseFloat(parts[4]);
if (world == null) {
if (parts.length != 6) {
throw new IllegalArgumentException("Expected location of type (x,y,z,yaw,pitch,world)");
}
world = Bukkit.getWorld(parts[5]);
}
return new Location(world, x, y, z, yaw, pit);
}
public static String waveReward(String arena, String type, int wave) {
return "arenas." + arena + ".rewards.waves." + type + "." + wave;
public static void setLocation(ConfigurationSection config, String path, Location location) {
String x = twoPlaces(location.getX());
String y = twoPlaces(location.getY());
String z = twoPlaces(location.getZ());
String yaw = twoPlaces(location.getYaw(), true);
String pit = twoPlaces(location.getPitch(), true);
String world = location.getWorld().getName();
StringBuilder buffy = new StringBuilder();
buffy.append(x).append(",").append(y).append(",").append(z);
buffy.append(",").append(yaw).append(",").append(pit);
buffy.append(",").append(world);
config.set(path, buffy.toString());
}
public static String waveReward(Arena arena, String type, int wave) {
return "arenas." + arena.configName() + ".rewards.waves." + type + "." + wave;
private static String twoPlaces(double value, boolean force) {
return force ? DF_FORCE.format(value) : DF_NORMAL.format(value);
}
private static String twoPlaces(double value) {
return twoPlaces(value, false);
}
private static final DecimalFormat DF_NORMAL = new DecimalFormat("0.##");
private static final DecimalFormat DF_FORCE = new DecimalFormat("0.0#");
}
@@ -5,38 +5,28 @@ import java.util.TreeSet;
import com.garbagemule.MobArena.Messenger;
import com.garbagemule.MobArena.framework.Arena;
import com.garbagemule.MobArena.util.config.Config;
import com.garbagemule.MobArena.util.config.ConfigSection;
import com.garbagemule.MobArena.waves.enums.*;
import org.bukkit.configuration.ConfigurationSection;
public class WaveManager
{
private Arena arena;
private Config config;
private ConfigurationSection section;
private Wave defaultWave, currentWave;
private TreeSet<Wave> recurrentWaves, singleWaves, singleWavesInstance;
private int wave, finalWave;
public WaveManager(Arena arena, Config config) {
public WaveManager(Arena arena, ConfigurationSection section) {
this.arena = arena;
this.config = config;
this.section = section;
this.wave = 0;
this.finalWave = 0;
reloadWaves();
}
public void reload() {
config.load();
reloadWaves();
}
public void save() {
config.save();
}
public TreeSet<Wave> getRecurrentWaves() {
return recurrentWaves;
}
@@ -48,13 +38,13 @@ public class WaveManager
}
public void reloadWaves() {
ConfigSection rConfig = config.getConfigSection("arenas." + arena.configName() + ".waves.recurrent");
ConfigSection sConfig = config.getConfigSection("arenas." + arena.configName() + ".waves.single");
ConfigurationSection rConfig = section.getConfigurationSection("recurrent");
ConfigurationSection sConfig = section.getConfigurationSection("single");
recurrentWaves = WaveParser.parseWaves(arena, rConfig, WaveBranch.RECURRENT);
singleWaves = WaveParser.parseWaves(arena, sConfig, WaveBranch.SINGLE);
finalWave = config.getInt("arenas." + arena.configName() + ".settings.final-wave", 0);
finalWave = section.getInt("arenas." + arena.configName() + ".settings.final-wave", 0);
if (recurrentWaves.isEmpty()) {
Messenger.warning(WaveError.NO_RECURRENT_WAVES.format(arena.configName()));
@@ -4,13 +4,13 @@ import java.util.*;
import com.garbagemule.MobArena.ArenaClass;
import org.bukkit.Location;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemStack;
import com.garbagemule.MobArena.Messenger;
import com.garbagemule.MobArena.framework.Arena;
import com.garbagemule.MobArena.region.ArenaRegion;
import com.garbagemule.MobArena.util.ItemParser;
import com.garbagemule.MobArena.util.config.ConfigSection;
import com.garbagemule.MobArena.waves.ability.Ability;
import com.garbagemule.MobArena.waves.ability.AbilityManager;
import com.garbagemule.MobArena.waves.enums.*;
@@ -24,7 +24,7 @@ import com.garbagemule.MobArena.waves.types.UpgradeWave.*;
public class WaveParser
{
public static TreeSet<Wave> parseWaves(Arena arena, ConfigSection config, WaveBranch branch) {
public static TreeSet<Wave> parseWaves(Arena arena, ConfigurationSection config, WaveBranch branch) {
// Create a TreeSet with the Comparator for the specific branch.
TreeSet<Wave> result = new TreeSet<Wave>(WaveUtils.getComparator(branch));
@@ -35,15 +35,15 @@ public class WaveParser
}
// If no waves were found, return the empty set.
Set<String> waves = config.getKeys();
if (waves == null/* || waves.isEmpty()*/) {
Set<String> waves = config.getKeys(false);
if (waves == null) {
Messenger.warning(WaveError.BRANCH_MISSING.format(branch.toString().toLowerCase(), arena.configName()));
return result;
}
// Otherwise, parse each wave in the branch.
for (String wave : waves) {
ConfigSection waveSection = config.getConfigSection(wave);
ConfigurationSection waveSection = config.getConfigurationSection(wave);
Wave w = parseWave(arena, wave, waveSection, branch);
// Only add properly parsed waves.
@@ -57,7 +57,7 @@ public class WaveParser
return result;
}
public static Wave parseWave(Arena arena, String name, ConfigSection config, WaveBranch branch) {
public static Wave parseWave(Arena arena, String name, ConfigurationSection config, WaveBranch branch) {
// Grab the WaveType and verify that it isn't null.
String t = config.getString("type", null);
WaveType type = WaveType.fromString(t);
@@ -143,7 +143,7 @@ public class WaveParser
return result;
}
private static Wave parseDefaultWave(Arena arena, String name, ConfigSection config) {
private static Wave parseDefaultWave(Arena arena, String name, ConfigurationSection config) {
// Grab the monster map.
SortedMap<Integer,MACreature> monsters = getMonsterMap(config);
if (monsters == null || monsters.isEmpty()) {
@@ -169,7 +169,7 @@ public class WaveParser
return result;
}
private static Wave parseSpecialWave(Arena arena, String name, ConfigSection config) {
private static Wave parseSpecialWave(Arena arena, String name, ConfigurationSection config) {
SortedMap<Integer,MACreature> monsters = getMonsterMap(config);
if (monsters == null || monsters.isEmpty()) {
Messenger.warning(WaveError.MONSTER_MAP_MISSING.format(name, arena.configName()));
@@ -180,7 +180,7 @@ public class WaveParser
return result;
}
private static Wave parseSwarmWave(Arena arena, String name, ConfigSection config) {
private static Wave parseSwarmWave(Arena arena, String name, ConfigurationSection config) {
MACreature monster = getSingleMonster(config);
if (monster == null) {
Messenger.warning(WaveError.SINGLE_MONSTER_MISSING.format(name, arena.configName()));
@@ -197,7 +197,7 @@ public class WaveParser
return result;
}
private static Wave parseSupplyWave(Arena arena, String name, ConfigSection config) {
private static Wave parseSupplyWave(Arena arena, String name, ConfigurationSection config) {
SortedMap<Integer,MACreature> monsters = getMonsterMap(config);
if (monsters == null || monsters.isEmpty()) {
Messenger.warning(WaveError.MONSTER_MAP_MISSING.format(name, arena.configName()));
@@ -214,7 +214,7 @@ public class WaveParser
return result;
}
private static Wave parseUpgradeWave(Arena arena, String name, ConfigSection config) {
private static Wave parseUpgradeWave(Arena arena, String name, ConfigurationSection config) {
Map<String,List<Upgrade>> upgrades = getUpgradeMap(config);
if (upgrades == null || upgrades.isEmpty()) {
Messenger.warning(WaveError.UPGRADE_MAP_MISSING.format(name, arena.configName()));
@@ -230,7 +230,7 @@ public class WaveParser
return result;
}
private static Wave parseBossWave(Arena arena, String name, ConfigSection config) {
private static Wave parseBossWave(Arena arena, String name, ConfigurationSection config) {
MACreature monster = getSingleMonster(config);
if (monster == null) {
Messenger.warning(WaveError.SINGLE_MONSTER_MISSING.format(name, arena.configName()));
@@ -301,7 +301,7 @@ public class WaveParser
* @param config a ConfigSection
* @return an MACreature, if the monster node contains one that is valid
*/
private static MACreature getSingleMonster(ConfigSection config) {
private static MACreature getSingleMonster(ConfigurationSection config) {
String monster = config.getString("monster");
if (monster == null) {
return null;
@@ -317,8 +317,8 @@ public class WaveParser
* @param config
* @return a "reverse" map of monsters and numbers
*/
private static SortedMap<Integer,MACreature> getMonsterMap(ConfigSection config) {
Set<String> monsters = config.getKeys("monsters");
private static SortedMap<Integer,MACreature> getMonsterMap(ConfigurationSection config) {
Set<String> monsters = config.getConfigurationSection("monsters").getKeys(false);
if (monsters == null || monsters.isEmpty()) {
return null;
}
@@ -343,7 +343,7 @@ public class WaveParser
return monsterMap;
}
private static List<Location> getSpawnpoints(Arena arena, String name, ConfigSection config) {
private static List<Location> getSpawnpoints(Arena arena, String name, ConfigurationSection config) {
List<Location> result = new ArrayList<Location>();
String spawnString = config.getString("spawnpoints");
@@ -369,8 +369,8 @@ public class WaveParser
return result;
}
private static Map<String,List<Upgrade>> getUpgradeMap(ConfigSection config) {
Set<String> classes = config.getKeys("upgrades");
private static Map<String,List<Upgrade>> getUpgradeMap(ConfigurationSection config) {
Set<String> classes = config.getConfigurationSection("upgrades").getKeys(false);
if (classes == null || classes.isEmpty()) {
return null;
}
@@ -410,7 +410,7 @@ public class WaveParser
}
// Permissions
List<String> perms = config.getStringList(path + className + ".permissions", Collections.EMPTY_LIST);
List<String> perms = config.getStringList(path + className + ".permissions");
if (!perms.isEmpty()) {
for (String perm : perms) {
list.add(new PermissionUpgrade(perm));
@@ -1,7 +1,7 @@
package com.garbagemule.MobArena.waves.ability;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;;
import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.RUNTIME)
public @interface AbilityInfo