Attempt at fixing reload issues.

This commit is contained in:
garbagemule 2013-06-22 12:02:45 +02:00
parent 8294a4db95
commit 52599319c1
5 changed files with 16 additions and 29 deletions

View File

@ -65,7 +65,7 @@ public class MobArena extends JavaPlugin
public void onEnable() {
// Create default files and initialize config-file
FileUtils.extractResource(this.getDataFolder(), "config.yml");
FileUtils.extractResource(this.getDataFolder(), "config.yml", getClass());
loadConfigFile();
// Load boss abilities
@ -205,7 +205,7 @@ public class MobArena extends JavaPlugin
File dir = new File(this.getDataFolder(), "abilities");
if (!dir.exists()) dir.mkdir();
AbilityManager.loadAbilities(dir);
AbilityManager.loadAbilities(dir, getClass());
}
private void startMetrics() {

View File

@ -25,7 +25,7 @@ public class MagicSpellsListener implements Listener
this.plugin = plugin;
// Set up the MagicSpells config-file.
File spellFile = FileUtils.extractResource(plugin.getDataFolder(), "magicspells.yml");
File spellFile = FileUtils.extractResource(plugin.getDataFolder(), "magicspells.yml", plugin.getClass());
Config spellConfig = new Config(spellFile);
spellConfig.load();
setupSpells(spellConfig);

View File

@ -4,7 +4,6 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.List;
import java.util.jar.JarEntry;
@ -25,11 +24,11 @@ public class FileUtils
* @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) {
return extractResources(dir, "", resources);
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) {
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.
@ -47,7 +46,7 @@ public class FileUtils
// Extract each resource
for (String filename : filenames) {
File file = extractResource(dir, path + filename);
File file = extractResource(dir, path + filename, cls);
if (file != null) {
files.add(file);
@ -56,25 +55,13 @@ public class FileUtils
return files;
}
/**
* Extracts all of the given resources to the given directory.
* Convenience method, used if one is too lazy to create a new list for
* the resource names.
* @param dir a directory
* @param resources an array of resources to extract
* @return a list of all the files that were written
*/
public static List<File> extractResources(File dir, String... resources) {
return extractResources(dir, Arrays.asList(resources));
}
/**
* 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) {
public static File extractResource(File dir, String resource, Class<?> cls) {
if (!dir.exists()) dir.mkdirs();
// Set up our new file.
@ -85,7 +72,7 @@ public class FileUtils
if (file.exists()) return file;
// Grab the resource input stream.
InputStream in = MobArena.class.getResourceAsStream("/res/" + resource);
InputStream in = cls.getResourceAsStream("/res/" + resource);
if (in == null) return null;
try {
@ -163,8 +150,8 @@ public class FileUtils
return (slash < 0 ? resource : resource.substring(slash + 1));
}
public static YamlConfiguration getConfig(MobArena plugin, String filename) {
InputStream in = MobArena.class.getResourceAsStream("/res/" + filename);
public static YamlConfiguration getConfig(MobArena plugin, String filename, Class<?> cls) {
InputStream in = cls.getResourceAsStream("/res/" + filename);
if (in == null) {
Messenger.severe("Failed to load '" + filename + "', the server must be restarted!");
return null;

View File

@ -29,7 +29,7 @@ public class ConfigUtils
}
// Extract the yml file.
YamlConfiguration ymlConfig = FileUtils.getConfig(plugin, filename);
YamlConfiguration ymlConfig = FileUtils.getConfig(plugin, filename, plugin.getClass());
// Assert the nodes.
assertNodes(section, ymlConfig, keepOthers);

View File

@ -38,7 +38,7 @@ public class AbilityManager
* the specified directory.
* @param dir a directory of .class (and/or .java) files
*/
public static void loadAbilities(File classDir) {
public static void loadAbilities(File classDir, Class<?> cls) {
abilities = new HashMap<String,Ability>();
// Grab the source directory.
@ -62,14 +62,14 @@ public class AbilityManager
String[] files = classDir.list();
if (files.length == 0 || (files.length == 1 && files[0].equals("src"))) {
Messenger.info("No boss abilities found. Extracting defaults...");
extractDefaultAbilities(classDir);
extractDefaultAbilities(classDir, cls);
}
// Load all the custom abilities.
loadClasses(classDir);
}
private static void extractDefaultAbilities(File classDir) {
private static void extractDefaultAbilities(File classDir, Class<?> cls) {
// Grab a list of all the class files.
List<String> resources = FileUtils.listFilesOnPath("res/abilities/", ".class");
@ -80,7 +80,7 @@ public class AbilityManager
}
// Extract everything.
List<File> files = FileUtils.extractResources(classDir, "abilities/", resources);
List<File> files = FileUtils.extractResources(classDir, "abilities/", resources, cls);
Messenger.info("Extracted abilities: " + fileListToString(files, "$"));
}