mirror of
https://github.com/garbagemule/MobArena.git
synced 2024-11-27 13:07:16 +01:00
Fix reload issues! Woooo!
This commit is contained in:
parent
3386ba3794
commit
4d95b67cb1
@ -19,8 +19,6 @@ import org.bukkit.permissions.Permission;
|
|||||||
import org.bukkit.permissions.PermissionDefault;
|
import org.bukkit.permissions.PermissionDefault;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
|
|
||||||
import com.garbagemule.MobArena.ArenaImpl;
|
|
||||||
import com.garbagemule.MobArena.MobArena;
|
|
||||||
import com.garbagemule.MobArena.ArenaClass.ArmorType;
|
import com.garbagemule.MobArena.ArenaClass.ArmorType;
|
||||||
import com.garbagemule.MobArena.framework.Arena;
|
import com.garbagemule.MobArena.framework.Arena;
|
||||||
import com.garbagemule.MobArena.framework.ArenaMaster;
|
import com.garbagemule.MobArena.framework.ArenaMaster;
|
||||||
@ -252,7 +250,7 @@ public class ArenaMasterImpl implements ArenaMaster
|
|||||||
* Load the global settings.
|
* Load the global settings.
|
||||||
*/
|
*/
|
||||||
public void loadSettings() {
|
public void loadSettings() {
|
||||||
ConfigUtils.replaceAllNodes(plugin, config, "global-settings", "global-settings.yml");
|
ConfigUtils.replaceAllNodes(config, "global-settings", "global-settings.yml");
|
||||||
ConfigSection section = config.getConfigSection("global-settings");
|
ConfigSection section = config.getConfigSection("global-settings");
|
||||||
|
|
||||||
// Grab the commands string
|
// Grab the commands string
|
||||||
@ -295,7 +293,7 @@ public class ArenaMasterImpl implements ArenaMaster
|
|||||||
* Loads the classes in res/classes.yml into the config-file.
|
* Loads the classes in res/classes.yml into the config-file.
|
||||||
*/
|
*/
|
||||||
public void loadDefaultClasses() {
|
public void loadDefaultClasses() {
|
||||||
ConfigUtils.addMissingNodes(plugin, config, "classes", "classes.yml");
|
ConfigUtils.addMissingNodes(config, "classes", "classes.yml");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -553,7 +551,7 @@ public class ArenaMasterImpl implements ArenaMaster
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Assert all settings nodes.
|
// Assert all settings nodes.
|
||||||
ConfigUtils.replaceAllNodes(plugin, config, path + ".settings", "settings.yml");
|
ConfigUtils.replaceAllNodes(config, path + ".settings", "settings.yml");
|
||||||
|
|
||||||
// Create an Arena with the name and world.
|
// Create an Arena with the name and world.
|
||||||
Arena arena = new ArenaImpl(plugin, config, arenaname, world);
|
Arena arena = new ArenaImpl(plugin, config, arenaname, world);
|
||||||
@ -578,14 +576,14 @@ public class ArenaMasterImpl implements ArenaMaster
|
|||||||
throw new IllegalArgumentException("Arena already exists!");
|
throw new IllegalArgumentException("Arena already exists!");
|
||||||
|
|
||||||
// Extract the default settings and update the world-node.
|
// Extract the default settings and update the world-node.
|
||||||
ConfigUtils.replaceAllNodes(plugin, config, path + ".settings", "settings.yml");
|
ConfigUtils.replaceAllNodes(config, path + ".settings", "settings.yml");
|
||||||
config.set(path + ".settings.world", world.getName());
|
config.set(path + ".settings.world", world.getName());
|
||||||
|
|
||||||
// Extract the default waves.
|
// Extract the default waves.
|
||||||
ConfigUtils.replaceAllNodes(plugin, config, path + ".waves", "waves.yml");
|
ConfigUtils.replaceAllNodes(config, path + ".waves", "waves.yml");
|
||||||
|
|
||||||
// Extract the default rewards.
|
// Extract the default rewards.
|
||||||
ConfigUtils.replaceAllNodes(plugin, config, path + ".rewards", "rewards.yml");
|
ConfigUtils.replaceAllNodes(config, path + ".rewards", "rewards.yml");
|
||||||
|
|
||||||
// Save the changes.
|
// Save the changes.
|
||||||
config.save();
|
config.save();
|
||||||
|
@ -18,8 +18,6 @@ import org.bukkit.plugin.RegisteredServiceProvider;
|
|||||||
import org.bukkit.plugin.ServicesManager;
|
import org.bukkit.plugin.ServicesManager;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import com.garbagemule.MobArena.ArenaMasterImpl;
|
|
||||||
import com.garbagemule.MobArena.MAMessages;
|
|
||||||
import com.garbagemule.MobArena.commands.CommandHandler;
|
import com.garbagemule.MobArena.commands.CommandHandler;
|
||||||
import com.garbagemule.MobArena.framework.Arena;
|
import com.garbagemule.MobArena.framework.Arena;
|
||||||
import com.garbagemule.MobArena.framework.ArenaMaster;
|
import com.garbagemule.MobArena.framework.ArenaMaster;
|
||||||
@ -235,7 +233,7 @@ public class MobArena extends JavaPlugin
|
|||||||
|
|
||||||
for (String arena : arenas) {
|
for (String arena : arenas) {
|
||||||
String path = "arenas." + arena + ".settings";
|
String path = "arenas." + arena + ".settings";
|
||||||
ConfigUtils.replaceAllNodes(this, config, path, "settings.yml");
|
ConfigUtils.replaceAllNodes(config, path, "settings.yml");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,14 +1,16 @@
|
|||||||
package com.garbagemule.MobArena.util;
|
package com.garbagemule.MobArena.util;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.*;
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.jar.JarEntry;
|
import java.util.jar.JarEntry;
|
||||||
import java.util.jar.JarFile;
|
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 org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
|
||||||
import com.garbagemule.MobArena.Messenger;
|
import com.garbagemule.MobArena.Messenger;
|
||||||
@ -150,24 +152,21 @@ public class FileUtils
|
|||||||
return (slash < 0 ? resource : resource.substring(slash + 1));
|
return (slash < 0 ? resource : resource.substring(slash + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static YamlConfiguration getConfig(MobArena plugin, String filename, Class<?> cls) {
|
private static final String JAR = "plugins/MobArena.jar";
|
||||||
InputStream in = cls.getResourceAsStream("/res/" + filename);
|
private static final String RES = "res/";
|
||||||
if (in == null) {
|
|
||||||
Messenger.severe("Failed to load '" + filename + "', the server must be restarted!");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
/**
|
||||||
YamlConfiguration result = new YamlConfiguration();
|
* Get a YamlConfiguration of a given resource.
|
||||||
result.load(in);
|
* @param filename the name of the resource
|
||||||
|
* @return a YamlConfiguration for the given resource
|
||||||
return result;
|
* @throws IOException if the resource does not exist
|
||||||
}
|
* @throws InvalidConfigurationException if the resource is not a valid config
|
||||||
catch (Exception e) {
|
*/
|
||||||
e.printStackTrace();
|
public static YamlConfiguration getConfig(String filename) throws IOException, InvalidConfigurationException {
|
||||||
Messenger.warning("Couldn't load '" + filename + "' as stream!");
|
ZipFile zip = new ZipFile(JAR);
|
||||||
}
|
ZipEntry entry = zip.getEntry(RES + filename);
|
||||||
|
YamlConfiguration yaml = new YamlConfiguration();
|
||||||
return null;
|
yaml.load(zip.getInputStream(entry));
|
||||||
|
return yaml;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package com.garbagemule.MobArena.util.config;
|
|||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import com.garbagemule.MobArena.Messenger;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
|
||||||
import com.garbagemule.MobArena.MobArena;
|
import com.garbagemule.MobArena.MobArena;
|
||||||
@ -10,15 +11,15 @@ import com.garbagemule.MobArena.util.FileUtils;
|
|||||||
|
|
||||||
public class ConfigUtils
|
public class ConfigUtils
|
||||||
{
|
{
|
||||||
public static void addMissingNodes(MobArena plugin, Config config, String path, String filename) {
|
public static void addMissingNodes(Config config, String path, String filename) {
|
||||||
assertNodes(plugin, config, path, filename, true);
|
assertNodes(config, path, filename, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void replaceAllNodes(MobArena plugin, Config config, String path, String filename) {
|
public static void replaceAllNodes(Config config, String path, String filename) {
|
||||||
assertNodes(plugin, config, path, filename, false);
|
assertNodes(config, path, filename, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void assertNodes(MobArena plugin, Config config, String path, String filename, boolean keepOthers) {
|
private static void assertNodes(Config config, String path, String filename, boolean keepOthers) {
|
||||||
// Grab the section that the path is pointing to.
|
// Grab the section that the path is pointing to.
|
||||||
ConfigSection section = config.getConfigSection(path);
|
ConfigSection section = config.getConfigSection(path);
|
||||||
|
|
||||||
@ -28,11 +29,16 @@ public class ConfigUtils
|
|||||||
section = config.getConfigSection(path);
|
section = config.getConfigSection(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract the yml file.
|
try {
|
||||||
YamlConfiguration ymlConfig = FileUtils.getConfig(plugin, filename, plugin.getClass());
|
// Extract the yml file.
|
||||||
|
YamlConfiguration ymlConfig = FileUtils.getConfig(filename);
|
||||||
|
|
||||||
// Assert the nodes.
|
// Assert the nodes.
|
||||||
assertNodes(section, ymlConfig, keepOthers);
|
assertNodes(section, ymlConfig, keepOthers);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
Messenger.severe("Failed to load '" + filename + "'. Restart required!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void assertNodes(ConfigSection config, YamlConfiguration ymlConfig, boolean keepOthers) {
|
private static void assertNodes(ConfigSection config, YamlConfiguration ymlConfig, boolean keepOthers) {
|
||||||
|
Loading…
Reference in New Issue
Block a user