From f4093cbe51229f21f7c5c925d2de55f2f289c6f7 Mon Sep 17 00:00:00 2001 From: fernferret Date: Mon, 10 Oct 2011 21:37:58 -0400 Subject: [PATCH] Implement new config items --- .../onarandombox/MultiverseCore/MVWorld.java | 149 ++++++++++-------- .../MultiverseCore/MultiverseCore.java | 55 +++---- .../onarandombox/MultiverseCore/api/Core.java | 8 - .../MultiverseCore/api/MultiverseWorld.java | 14 ++ .../commands/ConfigCommand.java | 4 +- .../commands/VersionCommand.java | 14 +- .../configuration/DefaultConfig.java | 57 ------- .../listeners/MVEntityListener.java | 6 +- .../listeners/MVPlayerListener.java | 8 +- .../MultiverseCore/utils/MVPlayerSession.java | 2 +- .../MultiverseCore/utils/WorldManager.java | 32 ++-- src/main/resources/defaults/worlds.yml | 44 ------ 12 files changed, 153 insertions(+), 240 deletions(-) delete mode 100644 src/main/java/com/onarandombox/MultiverseCore/configuration/DefaultConfig.java delete mode 100644 src/main/resources/defaults/worlds.yml diff --git a/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java b/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java index 4e743827..f1b484fa 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java @@ -11,11 +11,14 @@ import com.onarandombox.MultiverseCore.api.MultiverseWorld; import com.onarandombox.MultiverseCore.utils.EnglishChatColor; import org.bukkit.*; import org.bukkit.World.Environment; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; import org.bukkit.permissions.Permission; import org.bukkit.permissions.PermissionDefault; -import org.bukkit.util.config.Configuration; +import java.io.File; +import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -26,7 +29,8 @@ import java.util.logging.Level; public class MVWorld implements MultiverseWorld { private MultiverseCore plugin; // Hold the Plugin Instance. - private Configuration config; // Hold the Configuration File. + private FileConfiguration config; // Hold the Configuration File. + private ConfigurationSection worldSection; // Holds the section of the config file for this world. private World world; // The World Instance. private Environment environment; // Hold the Environment type EG Environment.NETHER / Environment.NORMAL @@ -63,7 +67,7 @@ public class MVWorld implements MultiverseWorld { private Location spawnLocation; private boolean isHidden = false; - public MVWorld(World world, Configuration config, MultiverseCore instance, Long seed, String generatorString) { + public MVWorld(World world, FileConfiguration config, MultiverseCore instance, Long seed, String generatorString) { this.config = config; this.plugin = instance; @@ -75,40 +79,41 @@ public class MVWorld implements MultiverseWorld { // Initialize our lists this.initLists(); - + worldSection = config.getConfigurationSection("worlds." + this.name); // Write these files to the config (once it's saved) if (generatorString != null) { - config.setProperty("worlds." + this.name + ".generator", generatorString); + worldSection.set("generator", generatorString); } if (seed != null) { - config.setProperty("worlds." + this.name + ".seed", this.seed); + worldSection.set("worlds." + this.name + "seed", this.seed); } - config.setProperty("worlds." + this.name + ".environment", this.environment.toString()); + worldSection.set("worlds." + this.name + "environment", this.environment.toString()); + // Set local values that CAN be changed by the user - this.setAlias(config.getString("worlds." + this.name + ".alias.name", "")); - this.setColor(config.getString("worlds." + this.name + ".alias.color", ChatColor.WHITE.toString())); - this.setFakePVPMode(config.getBoolean("worlds." + this.name + ".fakepvp", false)); - this.setPVPMode(config.getBoolean("worlds." + this.name + ".pvp", true)); - this.setScaling(config.getDouble("worlds." + this.name + ".scale", this.getDefaultScale(this.environment))); - this.setRespawnToWorld(config.getString("worlds." + this.name + ".respawnworld", "")); - this.setEnableWeather(config.getBoolean("worlds." + this.name + ".allowweather", true)); - this.setDifficulty(config.getString("worlds." + this.name + ".difficulty", "1")); + this.setAlias(worldSection.getString("alias.name", "")); + this.setColor(worldSection.getString("alias.color", ChatColor.WHITE.toString())); + this.setFakePVPMode(worldSection.getBoolean("fakepvp", false)); + this.setPVPMode(worldSection.getBoolean("pvp", true)); + this.setScaling(worldSection.getDouble("scale", this.getDefaultScale(this.environment))); + this.setRespawnToWorld(worldSection.getString("respawnworld", "")); + this.setEnableWeather(worldSection.getBoolean("allowweather", true)); + this.setDifficulty(worldSection.getString("difficulty", "1")); - this.setAllowAnimalSpawn(config.getBoolean("worlds." + this.name + ".animals.spawn", true)); - this.setAllowMonsterSpawn(config.getBoolean("worlds." + this.name + ".monsters.spawn", true)); - this.setPrice(config.getDouble("worlds." + this.name + ".entryfee.amount", 0.0)); - this.setCurrency(config.getInt("worlds." + this.name + ".entryfee.currency", -1)); - this.setHunger(config.getBoolean("worlds." + this.name + ".hunger", true)); - this.setHidden(config.getBoolean("worlds." + this.name + ".hidden", false)); + this.setAllowAnimalSpawn(worldSection.getBoolean("animals.spawn", true)); + this.setAllowMonsterSpawn(worldSection.getBoolean("monsters.spawn", true)); + this.setPrice(worldSection.getDouble("entryfee.amount", 0.0)); + this.setCurrency(worldSection.getInt("entryfee.currency", -1)); + this.setHunger(worldSection.getBoolean("hunger", true)); + this.setHidden(worldSection.getBoolean("hidden", false)); this.getMobExceptions(); - this.setGameMode(config.getString("worlds." + this.name + ".gamemode", GameMode.SURVIVAL.toString())); + this.setGameMode(worldSection.getString("gamemode", GameMode.SURVIVAL.toString())); - this.setKeepSpawnInMemory(config.getBoolean("worlds." + this.name + ".keepspawninmemory", true)); + this.setKeepSpawnInMemory(worldSection.getBoolean("keepspawninmemory", true)); - this.getWorldBlacklist().addAll(config.getStringList("worlds." + this.name + ".worldblacklist", new ArrayList())); - this.translateTempSpawn(config); + this.getWorldBlacklist().addAll(worldSection.getList("worldblacklist", new ArrayList())); + this.translateTempSpawn(worldSection); this.readSpawnFromConfig(this.getCBWorld()); this.canSave = true; saveConfig(); @@ -138,7 +143,7 @@ public class MVWorld implements MultiverseWorld { this.getCBWorld().setStorm(false); this.getCBWorld().setThundering(false); } - this.config.setProperty("worlds." + this.name + ".allowweather", weather); + this.worldSection.set("allowweather", weather); saveConfig(); } @@ -168,8 +173,8 @@ public class MVWorld implements MultiverseWorld { this.plugin.getServer().getPluginManager().recalculatePermissionDefaults(allWorlds); } - private void translateTempSpawn(Configuration config) { - String tempspawn = config.getString("worlds." + this.name + ".tempspawn", ""); + private void translateTempSpawn(ConfigurationSection section) { + String tempspawn = section.getString("tempspawn", ""); if (tempspawn.length() > 0) { String[] coordsString = tempspawn.split(":"); if (coordsString.length >= 3) { @@ -186,7 +191,7 @@ public class MVWorld implements MultiverseWorld { this.plugin.log(Level.WARNING, "A MV1 spawn value was found, but it could not be migrated. Format Error. Sorry."); } - this.config.removeProperty("worlds." + this.name + ".tempspawn"); + this.worldSection.set("tempspawn", null); } } @@ -196,13 +201,13 @@ public class MVWorld implements MultiverseWorld { private void getMobExceptions() { List temp; - temp = this.config.getStringList("worlds." + this.name + ".animals.exceptions", new ArrayList()); + temp = this.worldSection.getList("animals.exceptions", new ArrayList()); // Add Animals to the exclusion list for (String s : temp) { this.masterList.get("animals").add(s.toUpperCase()); } - temp = this.config.getStringList("worlds." + this.name + ".monsters.exceptions", new ArrayList()); + temp = this.worldSection.getList("monsters.exceptions", new ArrayList()); // Add Monsters to the exclusion list for (String s : temp) { this.masterList.get("monsters").add(s.toUpperCase()); @@ -227,7 +232,7 @@ public class MVWorld implements MultiverseWorld { } else { return false; } - this.config.setProperty("worlds." + this.name + "." + property.toLowerCase(), new ArrayList()); + this.worldSection.set(property.toLowerCase(), new ArrayList()); this.saveConfig(); return true; } @@ -238,11 +243,11 @@ public class MVWorld implements MultiverseWorld { if (property.equalsIgnoreCase("animals") || property.equalsIgnoreCase("monsters")) { this.masterList.get(property).add(value.toUpperCase()); - this.config.setProperty("worlds." + this.name + "." + property.toLowerCase() + ".exceptions", this.masterList.get(property)); + this.worldSection.set(property.toLowerCase() + ".exceptions", this.masterList.get(property)); this.syncMobs(); } else { this.masterList.get(property).add(value); - this.config.setProperty("worlds." + this.name + "." + property.toLowerCase(), this.masterList.get(property)); + this.worldSection.set(property.toLowerCase(), this.masterList.get(property)); } saveConfig(); return true; @@ -256,11 +261,11 @@ public class MVWorld implements MultiverseWorld { if (property.equalsIgnoreCase("animals") || property.equalsIgnoreCase("monsters")) { this.masterList.get(property).remove(value.toUpperCase()); - this.config.setProperty("worlds." + this.name + "." + property.toLowerCase() + ".exceptions", this.masterList.get(property)); + this.worldSection.set("" + property.toLowerCase() + ".exceptions", this.masterList.get(property)); this.syncMobs(); } else { this.masterList.get(property).remove(value); - this.config.setProperty("worlds." + this.name + "." + property.toLowerCase(), this.masterList.get(property)); + this.worldSection.set("" + property.toLowerCase(), this.masterList.get(property)); } saveConfig(); return true; @@ -320,7 +325,7 @@ public class MVWorld implements MultiverseWorld { public void setKeepSpawnInMemory(boolean value) { this.world.setKeepSpawnInMemory(value); this.keepSpawnInMemory = value; - this.config.setProperty("worlds." + this.name + ".keepspawninmemory", value); + this.worldSection.set("keepspawninmemory", value); saveConfig(); } @@ -417,7 +422,7 @@ public class MVWorld implements MultiverseWorld { @Override public void setAlias(String alias) { this.alias = alias; - this.config.setProperty("worlds." + this.name + ".alias.name", alias); + this.worldSection.set("alias.name", alias); saveConfig(); } @@ -431,7 +436,7 @@ public class MVWorld implements MultiverseWorld { this.allowAnimals = animals; // If animals are a boolean, then we can turn them on or off on the server // If there are ANY exceptions, there will be something spawning, so turn them on - this.config.setProperty("worlds." + this.name + ".animals.spawn", animals); + this.worldSection.set("animals.spawn", animals); saveConfig(); this.syncMobs(); } @@ -451,7 +456,7 @@ public class MVWorld implements MultiverseWorld { this.allowMonsters = monsters; // If monsters are a boolean, then we can turn them on or off on the server // If there are ANY exceptions, there will be something spawning, so turn them on - this.config.setProperty("worlds." + this.name + ".monsters.spawn", monsters); + this.worldSection.set("monsters.spawn", monsters); saveConfig(); this.syncMobs(); } @@ -474,7 +479,7 @@ public class MVWorld implements MultiverseWorld { this.world.setPVP(pvp); } this.pvp = pvp; - this.config.setProperty("worlds." + this.name + ".pvp", pvp); + this.worldSection.set("pvp", pvp); saveConfig(); } @@ -498,13 +503,13 @@ public class MVWorld implements MultiverseWorld { @Override public void setHidden(boolean hidden) { this.isHidden = hidden; - this.config.setProperty("worlds." + this.name + ".hidden", hidden); + this.worldSection.set("hidden", hidden); saveConfig(); } public void setFakePVPMode(Boolean fakePVPMode) { this.fakePVP = fakePVPMode; - this.config.setProperty("worlds." + this.name + ".fakepvp", this.fakePVP); + this.worldSection.set("fakepvp", this.fakePVP); // Now that we've set PVP mode, make sure to go through the normal setting too! // This method will perform the save for us to eliminate one write. this.setPVPMode(this.pvp); @@ -526,7 +531,7 @@ public class MVWorld implements MultiverseWorld { scaling = 1.0; } this.scaling = scaling; - this.config.setProperty("worlds." + this.name + ".scale", scaling); + this.worldSection.set("scale", scaling); saveConfig(); } @@ -537,7 +542,7 @@ public class MVWorld implements MultiverseWorld { return false; } this.aliasColor = color.getColor(); - this.config.setProperty("worlds." + this.name + ".alias.color", color.getText()); + this.worldSection.set("alias.color", color.getText()); saveConfig(); return true; } @@ -554,7 +559,7 @@ public class MVWorld implements MultiverseWorld { public boolean clearList(String property) { if (this.masterList.containsKey(property)) { this.masterList.get(property).clear(); - this.config.setProperty("worlds." + this.name + "." + property.toLowerCase(), this.masterList.get(property)); + this.worldSection.set(property.toLowerCase(), this.masterList.get(property)); this.syncMobs(); saveConfig(); return true; @@ -578,7 +583,7 @@ public class MVWorld implements MultiverseWorld { public boolean setRespawnToWorld(String respawnToWorld) { if (this.plugin.getServer().getWorld(respawnToWorld) != null) { this.respawnWorld = respawnToWorld; - this.config.setProperty("worlds." + this.name + ".respawnworld", respawnToWorld); + this.worldSection.set("respawnworld", respawnToWorld); saveConfig(); return true; } @@ -603,14 +608,14 @@ public class MVWorld implements MultiverseWorld { @Override public void setCurrency(int currency) { this.currency = currency; - config.setProperty("worlds." + this.name + ".entryfee.currency", currency); + this.worldSection.set("entryfee.currency", currency); saveConfig(); } @Override public void setPrice(double price) { this.price = price; - config.setProperty("worlds." + this.name + ".entryfee.amount", price); + this.worldSection.set("entryfee.amount", price); saveConfig(); } @@ -627,7 +632,11 @@ public class MVWorld implements MultiverseWorld { private void saveConfig() { if (this.canSave) { - this.config.save(); + try { + this.config.save(new File(this.plugin.getDataFolder(), "worlds.yml")); + } catch (IOException e) { + this.plugin.log(Level.SEVERE, "Could not save worlds.yml. Please check your filesystem permissions."); + } } } @@ -649,7 +658,7 @@ public class MVWorld implements MultiverseWorld { return false; } this.setGameMode(mode); - config.setProperty("worlds." + this.name + ".gamemode", mode.getValue()); + this.worldSection.set("gamemode", mode.getValue()); saveConfig(); return true; @@ -658,7 +667,7 @@ public class MVWorld implements MultiverseWorld { private boolean setGameMode(GameMode mode) { this.gameMode = mode; - config.setProperty("worlds." + this.name + ".gamemode", this.gameMode.toString()); + this.worldSection.set("gamemode", this.gameMode.toString()); saveConfig(); if (MultiverseCore.EnforceGameModes) { @@ -687,7 +696,7 @@ public class MVWorld implements MultiverseWorld { @Override public void setHunger(boolean hunger) { this.hunger = hunger; - config.setProperty("worlds." + this.name + ".hunger", this.hunger); + this.worldSection.set("hunger", this.hunger); saveConfig(); } @@ -699,22 +708,22 @@ public class MVWorld implements MultiverseWorld { @Override public void setSpawnLocation(Location l) { this.getCBWorld().setSpawnLocation(l.getBlockX(), l.getBlockY(), l.getBlockZ()); - config.setProperty("worlds." + this.name + ".spawn.x", l.getX()); - config.setProperty("worlds." + this.name + ".spawn.y", l.getY()); - config.setProperty("worlds." + this.name + ".spawn.z", l.getZ()); - config.setProperty("worlds." + this.name + ".spawn.pitch", l.getPitch()); - config.setProperty("worlds." + this.name + ".spawn.yaw", l.getYaw()); + this.worldSection.set("spawn.x", l.getX()); + this.worldSection.set("spawn.y", l.getY()); + this.worldSection.set("spawn.z", l.getZ()); + this.worldSection.set("spawn.pitch", l.getPitch()); + this.worldSection.set("spawn.yaw", l.getYaw()); this.getCBWorld().setSpawnLocation(l.getBlockX(), l.getBlockY(), l.getBlockZ()); this.spawnLocation = l.clone(); saveConfig(); } private void readSpawnFromConfig(World w) { - double x = config.getDouble("worlds." + this.name + ".spawn.x", w.getSpawnLocation().getX()); - double y = config.getDouble("worlds." + this.name + ".spawn.y", w.getSpawnLocation().getY()); - double z = config.getDouble("worlds." + this.name + ".spawn.z", w.getSpawnLocation().getZ()); - float pitch = (float) config.getDouble("worlds." + this.name + ".spawn.pitch", w.getSpawnLocation().getPitch()); - float yaw = (float) config.getDouble("worlds." + this.name + ".spawn.yaw", w.getSpawnLocation().getYaw()); + double x = config.getDouble("spawn.x", w.getSpawnLocation().getX()); + double y = config.getDouble("spawn.y", w.getSpawnLocation().getY()); + double z = config.getDouble("spawn.z", w.getSpawnLocation().getZ()); + float pitch = (float) config.getDouble("spawn.pitch", w.getSpawnLocation().getPitch()); + float yaw = (float) config.getDouble("spawn.yaw", w.getSpawnLocation().getYaw()); this.spawnLocation = new Location(w, x, y, z, yaw, pitch); } @@ -746,8 +755,20 @@ public class MVWorld implements MultiverseWorld { return false; } this.getCBWorld().setDifficulty(worlddiff); - config.setProperty("worlds." + this.name + ".difficulty", worlddiff.getValue()); + this.worldSection.set("difficulty", worlddiff.getValue()); saveConfig(); return true; } + + // TODO: Implment this, I'm going to bed tonight. + @Override + public boolean getAutoHeal() { + return true; + } + + // TODO: Implment this, I'm going to bed tonight. + @Override + public void setAutoHeal(boolean heal) { + + } } diff --git a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java index 79db20a3..c7087254 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -12,7 +12,6 @@ import com.fernferret.allpay.GenericBank; import com.onarandombox.MultiverseCore.api.Core; import com.onarandombox.MultiverseCore.api.MVPlugin; import com.onarandombox.MultiverseCore.commands.*; -import com.onarandombox.MultiverseCore.configuration.DefaultConfig; import com.onarandombox.MultiverseCore.configuration.MVConfigMigrator; import com.onarandombox.MultiverseCore.configuration.MVCoreConfigMigrator; import com.onarandombox.MultiverseCore.destination.*; @@ -28,7 +27,7 @@ import org.bukkit.Location; import org.bukkit.World.Environment; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; -import org.bukkit.configuration.InvalidConfigurationException; +import org.bukkit.configuration.Configuration; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; @@ -36,7 +35,6 @@ import org.bukkit.event.Event; import org.bukkit.event.Event.Priority; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.util.config.Configuration; import java.io.*; import java.util.ArrayList; @@ -52,6 +50,8 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core { // to worlds. public static boolean EnforceAccess; public static boolean EnforceGameModes; + public static boolean PrefixChat; + public static boolean BedRespawn; @Override @@ -89,7 +89,6 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core { private MVPermissions ph; // Configurations - private Configuration configMV = null; private FileConfiguration multiverseConfig = null; private WorldManager worldManager = new WorldManager(this); @@ -125,10 +124,6 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core { debugLog = new DebugLog("Multiverse-Core", getDataFolder() + File.separator + "debug.log"); } - public Configuration getMVConfig() { - return this.configMV; - } - public FileConfiguration getMVConfiguration() { return this.multiverseConfig; } @@ -259,40 +254,28 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core { /** Load the Configuration files OR create the default config files. */ public void loadConfigs() { - - // Call the defaultConfiguration class to create the config files if they don't already exist. - new DefaultConfig(getDataFolder(), "config.yml", this.migrator); - new DefaultConfig(getDataFolder(), "worlds.yml", this.migrator); // Now grab the Configuration Files. this.multiverseConfig = YamlConfiguration.loadConfiguration(new File(getDataFolder(), "config.yml")); - + Configuration coreDefaults = YamlConfiguration.loadConfiguration(this.getClass().getResourceAsStream("/defaults/config.yml")); + this.multiverseConfig.setDefaults(coreDefaults); this.worldManager.loadWorldConfig(new File(getDataFolder(), "worlds.yml")); - // Now attempt to Load the configurations. - try { - this.configMV.load(); - log(Level.INFO, "- Multiverse Config -- Loaded"); - } catch (Exception e) { - log(Level.INFO, "- Failed to load config.yml"); - } - - try { - this.worldManager.propagateConfigFile(); - log(Level.INFO, "- World Config -- Loaded"); - } catch (Exception e) { - log(Level.INFO, "- Failed to load worlds.yml"); - } - // Setup the Debug option, we'll default to false because this option will not be in the default config. - GlobalDebug = this.configMV.getInt("debug", 0); + GlobalDebug = this.multiverseConfig.getInt("debug", 0); // Lets cache this value due to the fact that it will be accessed many times. - EnforceAccess = this.configMV.getBoolean("enforceaccess", false); - EnforceGameModes = this.configMV.getBoolean("enforcegamemodes", true); - this.configMV.setProperty("enforceaccess", EnforceAccess); - this.configMV.setProperty("enforcegamemodes", EnforceAccess); + EnforceAccess = this.multiverseConfig.getBoolean("enforceaccess", false); + EnforceGameModes = this.multiverseConfig.getBoolean("enforcegamemodes", true); + PrefixChat = this.multiverseConfig.getBoolean("worldnameprefix", true); + BedRespawn = this.multiverseConfig.getBoolean("bedrespawn", true); + this.multiverseConfig.set("enforceaccess", EnforceAccess); + this.multiverseConfig.set("enforcegamemodes", EnforceAccess); this.messaging = new MVMessaging(this); - this.messaging.setCooldown(this.configMV.getInt("messagecooldown", 5000)); - this.configMV.save(); + this.messaging.setCooldown(this.multiverseConfig.getInt("messagecooldown", 5000)); + try { + this.multiverseConfig.save(new File(getDataFolder(), "config.yml")); + } catch (IOException e) { + this.log(Level.SEVERE, "Could not save Multiverse config. Please check your file permissions."); + } } public MVMessaging getMessaging() { @@ -381,7 +364,7 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core { if (this.playerSessions.containsKey(player.getName())) { return this.playerSessions.get(player.getName()); } else { - this.playerSessions.put(player.getName(), new MVPlayerSession(player, this.configMV, this)); + this.playerSessions.put(player.getName(), new MVPlayerSession(player, this.multiverseConfig, this)); return this.playerSessions.get(player.getName()); } } diff --git a/src/main/java/com/onarandombox/MultiverseCore/api/Core.java b/src/main/java/com/onarandombox/MultiverseCore/api/Core.java index 4f82a556..dfc0608b 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/api/Core.java +++ b/src/main/java/com/onarandombox/MultiverseCore/api/Core.java @@ -21,14 +21,6 @@ import org.bukkit.util.config.Configuration; * This API contains a bunch of useful things you can get out of Multiverse in general! */ public interface Core { - /** - * Gets the Multiverse config file. - * Now Deprecated, use {@link #getMVConfiguration()} - * - * @return The Multiverse config file. - */ - @Deprecated - public Configuration getMVConfig(); /** * Gets the Multiverse config file. diff --git a/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseWorld.java b/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseWorld.java index 8cce9ae6..a5725d00 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseWorld.java +++ b/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseWorld.java @@ -424,4 +424,18 @@ public interface MultiverseWorld { * @return */ public boolean clearList(String property); + + /** + * Sets whether or not a world will autoheal players if the difficulty is on peaceful. + * + * @param heal True if the world will heal. + */ + public void setAutoHeal(boolean heal); + + /** + * Gets whether or not a world will autoheal players if the difficulty is on peaceful. + * + * @return True if the world should heal (default), false if not. + */ + public boolean getAutoHeal(); } diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/ConfigCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/ConfigCommand.java index c06bed1e..622668a4 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/ConfigCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/ConfigCommand.java @@ -39,7 +39,7 @@ public class ConfigCommand extends MultiverseCommand { public void runCommand(CommandSender sender, List args) { if (args.get(0).equalsIgnoreCase("messagecooldown") || args.get(0).equalsIgnoreCase("teleportcooldown") || args.get(0).equalsIgnoreCase("debug")) { try { - this.plugin.getMVConfig().setProperty(args.get(0).toLowerCase(), Integer.parseInt(args.get(1))); + this.plugin.getMVConfiguration().set(args.get(0).toLowerCase(), Integer.parseInt(args.get(1))); this.plugin.loadConfigs(); } catch (NumberFormatException e) { sender.sendMessage(ChatColor.RED + "Sorry, " + ChatColor.AQUA + args.get(0) + ChatColor.WHITE + " must be an integer!"); @@ -47,7 +47,7 @@ public class ConfigCommand extends MultiverseCommand { } else { if (ConfigProperty.valueOf(args.get(0).toLowerCase()) != null) { try { - this.plugin.getMVConfig().setProperty(args.get(0).toLowerCase(), Boolean.parseBoolean(args.get(0))); + this.plugin.getMVConfiguration().set(args.get(0).toLowerCase(), Boolean.parseBoolean(args.get(0))); this.plugin.loadConfigs(); } catch (Exception e) { sender.sendMessage(ChatColor.RED + "Sorry, " + ChatColor.AQUA + args.get(0) + ChatColor.WHITE + " must be true or false!"); diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/VersionCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/VersionCommand.java index 0687c662..a9779a07 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/VersionCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/VersionCommand.java @@ -54,13 +54,13 @@ public class VersionCommand extends MultiverseCommand { logAndAddToPasteBinBuffer("Multiverse Plugins Loaded: " + this.plugin.getPluginCount()); logAndAddToPasteBinBuffer("Economy being used: " + this.plugin.getBank().getEconUsed()); logAndAddToPasteBinBuffer("Permissions Plugin: " + this.plugin.getMVPerms().getType()); - logAndAddToPasteBinBuffer("Dumping Config Values: (version " + this.plugin.getMVConfig().getString("version", "NOT SET") + ")"); - logAndAddToPasteBinBuffer("messagecooldown: " + this.plugin.getMVConfig().getString("messagecooldown", "NOT SET")); - logAndAddToPasteBinBuffer("teleportcooldown: " + this.plugin.getMVConfig().getString("teleportcooldown", "NOT SET")); - logAndAddToPasteBinBuffer("worldnameprefix: " + this.plugin.getMVConfig().getString("worldnameprefix", "NOT SET")); - logAndAddToPasteBinBuffer("opfallback: " + this.plugin.getMVConfig().getString("opfallback", "NOT SET")); - logAndAddToPasteBinBuffer("disableautoheal: " + this.plugin.getMVConfig().getString("disableautoheal", "NOT SET")); - logAndAddToPasteBinBuffer("fakepvp: " + this.plugin.getMVConfig().getString("fakepvp", "NOT SET")); + logAndAddToPasteBinBuffer("Dumping Config Values: (version " + this.plugin.getMVConfiguration().getString("version", "NOT SET") + ")"); + logAndAddToPasteBinBuffer("messagecooldown: " + this.plugin.getMVConfiguration().getString("messagecooldown", "NOT SET")); + logAndAddToPasteBinBuffer("teleportcooldown: " + this.plugin.getMVConfiguration().getString("teleportcooldown", "NOT SET")); + logAndAddToPasteBinBuffer("worldnameprefix: " + this.plugin.getMVConfiguration().getString("worldnameprefix", "NOT SET")); + logAndAddToPasteBinBuffer("opfallback: " + this.plugin.getMVConfiguration().getString("opfallback", "NOT SET")); + logAndAddToPasteBinBuffer("disableautoheal: " + this.plugin.getMVConfiguration().getString("disableautoheal", "NOT SET")); + logAndAddToPasteBinBuffer("fakepvp: " + this.plugin.getMVConfiguration().getString("fakepvp", "NOT SET")); logAndAddToPasteBinBuffer("Special Code: FRN001"); MVVersionRequestEvent versionEvent = new MVVersionRequestEvent(pasteBinBuffer); diff --git a/src/main/java/com/onarandombox/MultiverseCore/configuration/DefaultConfig.java b/src/main/java/com/onarandombox/MultiverseCore/configuration/DefaultConfig.java deleted file mode 100644 index 344fb962..00000000 --- a/src/main/java/com/onarandombox/MultiverseCore/configuration/DefaultConfig.java +++ /dev/null @@ -1,57 +0,0 @@ -/****************************************************************************** - * Multiverse 2 Copyright (c) the Multiverse Team 2011. * - * Multiverse 2 is licensed under the BSD License. * - * For more information please check the README.md file included * - * with this project. * - ******************************************************************************/ - -package com.onarandombox.MultiverseCore.configuration; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.InputStream; - -public class DefaultConfig { - - public DefaultConfig(File folder, String name, MVConfigMigrator migrator) { - File actual = new File(folder, name); - if (actual.exists() && migrator.createdDefaults.contains(name)) { - actual.delete(); - } - // If defaults have been created, and we're being called again, we should try to migrate - if (!actual.exists() && !migrator.migrate(name, folder)) { - - InputStream defConfig = this.getClass().getResourceAsStream("/defaults/" + name); - if (defConfig != null) { - FileOutputStream newConfig = null; - - try { - newConfig = new FileOutputStream(actual); - byte[] buf = new byte[8192]; - int length = 0; - - while ((length = defConfig.read(buf)) > 0) { - newConfig.write(buf, 0, length); - } - migrator.createdDefaults.add(name); - - } catch (Exception e) { - e.printStackTrace(); - } finally { - try { - if (defConfig != null) - defConfig.close(); - } catch (Exception e) { - } - - try { - if (newConfig != null) - newConfig.close(); - } catch (Exception e) { - - } - } - } - } - } -} diff --git a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVEntityListener.java b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVEntityListener.java index 58ad2466..e00206a7 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVEntityListener.java +++ b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVEntityListener.java @@ -7,6 +7,7 @@ package com.onarandombox.MultiverseCore.listeners; +import com.onarandombox.MultiverseCore.MVWorld; import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.api.MultiverseWorld; import com.onarandombox.MultiverseCore.utils.WorldManager; @@ -82,7 +83,7 @@ public class MVEntityListener extends EntityListener { MultiverseWorld world = this.worldManager.getMVWorld(w.getName()); if (attacker instanceof Player) { - if (!world.isPVPEnabled() && this.plugin.getMVConfig().getBoolean("fakepvp", false)) { + if (!world.isPVPEnabled() && world.getFakePVP()) { ((Player) attacker).sendMessage(ChatColor.RED + "PVP is disabled in this World."); event.setCancelled(true); } @@ -96,7 +97,8 @@ public class MVEntityListener extends EntityListener { return; } RegainReason reason = event.getRegainReason(); - if (reason == RegainReason.REGEN && this.plugin.getMVConfig().getBoolean("disableautoheal", false)) { + MultiverseWorld world = this.worldManager.getMVWorld(event.getEntity().getLocation().getWorld()); + if (world != null && reason == RegainReason.REGEN && !world.getAutoHeal()) { event.setCancelled(true); } } diff --git a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java index e4739fcf..00464bb3 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java +++ b/src/main/java/com/onarandombox/MultiverseCore/listeners/MVPlayerListener.java @@ -37,9 +37,9 @@ public class MVPlayerListener extends PlayerListener { if (event.isCancelled()) { return; } - // Check whether the Server is set to prefix the chat with the World name. If not we do nothing, if so we need to check if the World has an Alias. - if (this.plugin.getMVConfig().getBoolean("worldnameprefix", true)) { - this.plugin.getMVConfig().save(); + // Check whether the Server is set to prefix the chat with the World name. + // If not we do nothing, if so we need to check if the World has an Alias. + if (MultiverseCore.PrefixChat) { String world = event.getPlayer().getWorld().getName(); String prefix = ""; // If we're not a MV world, don't do anything @@ -62,7 +62,7 @@ public class MVPlayerListener extends PlayerListener { return; } - if (event.isBedSpawn() && this.plugin.getMVConfig().getBoolean("bedrespawn", true)) { + if (MultiverseCore.BedRespawn) { this.plugin.log(Level.FINE, "Spawning " + event.getPlayer().getName() + " at their bed"); return; } diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/MVPlayerSession.java b/src/main/java/com/onarandombox/MultiverseCore/utils/MVPlayerSession.java index a092de81..e13f5f65 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/MVPlayerSession.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/MVPlayerSession.java @@ -8,8 +8,8 @@ package com.onarandombox.MultiverseCore.utils; import com.onarandombox.MultiverseCore.MultiverseCore; +import org.bukkit.configuration.Configuration; import org.bukkit.entity.Player; -import org.bukkit.util.config.Configuration; import java.util.Date; diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/WorldManager.java b/src/main/java/com/onarandombox/MultiverseCore/utils/WorldManager.java index e8b5c22d..3d102b86 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/WorldManager.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/WorldManager.java @@ -14,16 +14,19 @@ import com.onarandombox.MultiverseCore.api.MultiverseWorld; import org.bukkit.World; import org.bukkit.World.Environment; import org.bukkit.WorldCreator; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; import org.bukkit.generator.ChunkGenerator; import org.bukkit.permissions.Permission; import org.bukkit.plugin.Plugin; -import org.bukkit.util.config.Configuration; import java.io.File; +import java.io.IOException; import java.util.Collection; import java.util.HashMap; import java.util.List; +import java.util.Set; import java.util.logging.Level; /** @@ -35,7 +38,7 @@ public class WorldManager implements MVWorldManager { private MultiverseCore plugin; private PurgeWorlds worldPurger; private HashMap worlds; - private Configuration configWorlds = null; + private FileConfiguration configWorlds = null; public WorldManager(MultiverseCore core) { @@ -126,11 +129,16 @@ public class WorldManager implements MVWorldManager { * @return True if success, false if failure. */ public boolean removeWorldFromConfig(String name) { - if (this.configWorlds.getProperty("worlds." + name) != null) { + if (this.configWorlds.get("worlds." + name) != null) { unloadWorld(name); this.plugin.log(Level.INFO, "World '" + name + "' was removed from config.yml"); - this.configWorlds.removeProperty("worlds." + name); - this.configWorlds.save(); + this.configWorlds.set("worlds." + name, null); + try { + this.configWorlds.save(new File(this.plugin.getDataFolder(), "config.yml")); + } catch (IOException e) { + this.plugin.log(Level.SEVERE, "Could not save worlds.yml. Please check your settings."); + } + return true; } else { this.plugin.log(Level.INFO, "World '" + name + "' was already removed from config.yml"); @@ -161,7 +169,7 @@ public class WorldManager implements MVWorldManager { } // Grab all the Worlds from the Config. - List worldKeys = this.configWorlds.getKeys("worlds"); + Set worldKeys = this.configWorlds.getConfigurationSection("worlds").getKeys(false); // Check that the list is not null and that the config contains the world if ((worldKeys != null) && (worldKeys.contains(name))) { @@ -349,7 +357,7 @@ public class WorldManager implements MVWorldManager { // Basic Counter to count how many Worlds we are loading. int count = 0; // Grab all the Worlds from the Config. - List worldKeys = this.configWorlds.getKeys("worlds"); + Set worldKeys = this.configWorlds.getConfigurationSection("worlds").getKeys(false); // Force the worlds to be loaded, ie don't just load new worlds. if (forceLoad) { @@ -413,14 +421,8 @@ public class WorldManager implements MVWorldManager { * * @return A loaded configuration. */ - public Configuration loadWorldConfig(File file) { - this.configWorlds = new Configuration(file); + public FileConfiguration loadWorldConfig(File file) { + this.configWorlds = YamlConfiguration.loadConfiguration(file); return this.configWorlds; } - - /** Reload the Config File */ - public void propagateConfigFile() { - this.configWorlds.load(); - } - } diff --git a/src/main/resources/defaults/worlds.yml b/src/main/resources/defaults/worlds.yml deleted file mode 100644 index 68faca8f..00000000 --- a/src/main/resources/defaults/worlds.yml +++ /dev/null @@ -1,44 +0,0 @@ -worlds: - -############################################# -### - Examples & Explanation of Settings- ### -############################################# -##worlds: -## default: ## This world is called 'default' -## environment: NORMAL ## Created with a NORMAL environment. -## animals: -## spawn: true ## We want animals to Spawn. -## exceptions: ## We want all animals to spawn so we won't make any exceptions. -## monsters: -## spawn: true ## We want monsters to Spawn. -## exceptions: 'CREEPER' ## But we don't want Creepers to spawn as they destroy peoples homes and valuables. -## pvp: true ## We wan't PVP to be enabled so players can fight each other. -## worldBlacklist: '' ## We are not blacklisting any worlds so this allows Players to teleport to this world from all other worlds. -## playerBlacklist: '' ## We are not blacklisting any players or groups so anyone can enter this world. -## playerWhitelist: '' ## Because we have not blacklisted anyone we do not have to Whitelist someone. -## -## creative: ## This world is called 'creative' -## environment: NORMAL ## Created with a NORMAL environment. -## animals: -## spawn: true ## We want animals to spawn. -## exceptions: ## We want all animals to spawn so we won't make any exceptions. -## monsters: -## spawn: false ## We don't want monsters to Spawn because this is a Creative World. -## enforced: true ## We want to enforce this rule, this means any Monster that was alive during world load/creation will be removed. No monsters can inhabit this world. -## exceptions: ## We don't want to make any exceptions to this. -## pvp: false ## We want to disable PVP because this world is for creativeness only. -## worldBlacklist: '' ## We are not blacklisting any worlds so this allows Players to teleport to this world from all other worlds. -## playerBlacklist: 'g:Griefers' ## We don't want to allow the group 'Griefers' into the World. -## playerWhitelist: 'g:Artists' ## We want to allow the group 'Artists' to enter this World. -## -## nether: ## This world is called 'nether' -## environment: NETHER ## Created with a NETHER environment. -## animals: -## spawn: true ## We want animals to spawn. -## monsters: -## spawn: true ## We want monsters to spawn. -## pvp: true ## We want to enable PVP on this World. -## worldBlacklist: '' ## We are not blacklisting any worlds so this allows Players to teleport to this world from all other worlds. -## playerBlacklist: '' ## We are not blacklisting any players or groups so anyone can enter this world. -## playerWhitelist: '' ## Because we have not blacklisted anyone we do not have to Whitelist someone. -