mirror of
https://github.com/garbagemule/MobArena.git
synced 2024-11-23 19:16:41 +01:00
Attempt at fixing reload issues.
This commit is contained in:
parent
8294a4db95
commit
52599319c1
@ -65,7 +65,7 @@ public class MobArena extends JavaPlugin
|
|||||||
|
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
// Create default files and initialize config-file
|
// Create default files and initialize config-file
|
||||||
FileUtils.extractResource(this.getDataFolder(), "config.yml");
|
FileUtils.extractResource(this.getDataFolder(), "config.yml", getClass());
|
||||||
loadConfigFile();
|
loadConfigFile();
|
||||||
|
|
||||||
// Load boss abilities
|
// Load boss abilities
|
||||||
@ -205,7 +205,7 @@ public class MobArena extends JavaPlugin
|
|||||||
File dir = new File(this.getDataFolder(), "abilities");
|
File dir = new File(this.getDataFolder(), "abilities");
|
||||||
if (!dir.exists()) dir.mkdir();
|
if (!dir.exists()) dir.mkdir();
|
||||||
|
|
||||||
AbilityManager.loadAbilities(dir);
|
AbilityManager.loadAbilities(dir, getClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startMetrics() {
|
private void startMetrics() {
|
||||||
|
@ -25,7 +25,7 @@ public class MagicSpellsListener implements Listener
|
|||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
|
|
||||||
// Set up the MagicSpells config-file.
|
// 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);
|
Config spellConfig = new Config(spellFile);
|
||||||
spellConfig.load();
|
spellConfig.load();
|
||||||
setupSpells(spellConfig);
|
setupSpells(spellConfig);
|
||||||
|
@ -4,7 +4,6 @@ import java.io.File;
|
|||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
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;
|
||||||
@ -25,11 +24,11 @@ public class FileUtils
|
|||||||
* @param resources a list of resources to extract
|
* @param resources a list of resources to extract
|
||||||
* @return a list of all the files that were written
|
* @return a list of all the files that were written
|
||||||
*/
|
*/
|
||||||
public static List<File> extractResources(File dir, List<String> resources) {
|
public static List<File> extractResources(File dir, List<String> resources, Class<?> cls) {
|
||||||
return extractResources(dir, "", resources);
|
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>();
|
List<File> files = new ArrayList<File>();
|
||||||
|
|
||||||
// If the path is empty, just forget about it.
|
// If the path is empty, just forget about it.
|
||||||
@ -47,7 +46,7 @@ public class FileUtils
|
|||||||
|
|
||||||
// Extract each resource
|
// Extract each resource
|
||||||
for (String filename : filenames) {
|
for (String filename : filenames) {
|
||||||
File file = extractResource(dir, path + filename);
|
File file = extractResource(dir, path + filename, cls);
|
||||||
|
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
files.add(file);
|
files.add(file);
|
||||||
@ -56,25 +55,13 @@ public class FileUtils
|
|||||||
return files;
|
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.
|
* Extracts the given resource to the given directory.
|
||||||
* @param dir a directory
|
* @param dir a directory
|
||||||
* @param resource a resource to extract
|
* @param resource a resource to extract
|
||||||
* @return the file that was written, or null
|
* @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();
|
if (!dir.exists()) dir.mkdirs();
|
||||||
|
|
||||||
// Set up our new file.
|
// Set up our new file.
|
||||||
@ -85,7 +72,7 @@ public class FileUtils
|
|||||||
if (file.exists()) return file;
|
if (file.exists()) return file;
|
||||||
|
|
||||||
// Grab the resource input stream.
|
// Grab the resource input stream.
|
||||||
InputStream in = MobArena.class.getResourceAsStream("/res/" + resource);
|
InputStream in = cls.getResourceAsStream("/res/" + resource);
|
||||||
if (in == null) return null;
|
if (in == null) return null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -163,8 +150,8 @@ 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) {
|
public static YamlConfiguration getConfig(MobArena plugin, String filename, Class<?> cls) {
|
||||||
InputStream in = MobArena.class.getResourceAsStream("/res/" + filename);
|
InputStream in = cls.getResourceAsStream("/res/" + filename);
|
||||||
if (in == null) {
|
if (in == null) {
|
||||||
Messenger.severe("Failed to load '" + filename + "', the server must be restarted!");
|
Messenger.severe("Failed to load '" + filename + "', the server must be restarted!");
|
||||||
return null;
|
return null;
|
||||||
|
@ -29,7 +29,7 @@ public class ConfigUtils
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Extract the yml file.
|
// Extract the yml file.
|
||||||
YamlConfiguration ymlConfig = FileUtils.getConfig(plugin, filename);
|
YamlConfiguration ymlConfig = FileUtils.getConfig(plugin, filename, plugin.getClass());
|
||||||
|
|
||||||
// Assert the nodes.
|
// Assert the nodes.
|
||||||
assertNodes(section, ymlConfig, keepOthers);
|
assertNodes(section, ymlConfig, keepOthers);
|
||||||
|
@ -38,7 +38,7 @@ public class AbilityManager
|
|||||||
* the specified directory.
|
* the specified directory.
|
||||||
* @param dir a directory of .class (and/or .java) files
|
* @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>();
|
abilities = new HashMap<String,Ability>();
|
||||||
|
|
||||||
// Grab the source directory.
|
// Grab the source directory.
|
||||||
@ -62,14 +62,14 @@ public class AbilityManager
|
|||||||
String[] files = classDir.list();
|
String[] files = classDir.list();
|
||||||
if (files.length == 0 || (files.length == 1 && files[0].equals("src"))) {
|
if (files.length == 0 || (files.length == 1 && files[0].equals("src"))) {
|
||||||
Messenger.info("No boss abilities found. Extracting defaults...");
|
Messenger.info("No boss abilities found. Extracting defaults...");
|
||||||
extractDefaultAbilities(classDir);
|
extractDefaultAbilities(classDir, cls);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load all the custom abilities.
|
// Load all the custom abilities.
|
||||||
loadClasses(classDir);
|
loadClasses(classDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void extractDefaultAbilities(File classDir) {
|
private static void extractDefaultAbilities(File classDir, Class<?> cls) {
|
||||||
// Grab a list of all the class files.
|
// Grab a list of all the class files.
|
||||||
List<String> resources = FileUtils.listFilesOnPath("res/abilities/", ".class");
|
List<String> resources = FileUtils.listFilesOnPath("res/abilities/", ".class");
|
||||||
|
|
||||||
@ -80,7 +80,7 @@ public class AbilityManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Extract everything.
|
// 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, "$"));
|
Messenger.info("Extracted abilities: " + fileListToString(files, "$"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user