Fix Itemcases not being reloaded.

This commit is contained in:
Jesse Prescott 2018-05-31 12:05:06 +01:00
parent 8dcf36c93f
commit 6fc79e2f74
2 changed files with 58 additions and 31 deletions

View File

@ -109,6 +109,9 @@ public final class ItemCaseCore extends JavaPlugin {
// Log.
this.consoleLogger.info("console.info.listener-registered");
// Load itemcases for already loaded worlds.
this.itemcaseManager.initialize();
// Set version placeholder and log.
this.translator.setPlaceholder("%VERSION%",
this.getDescription().getVersion());

View File

@ -48,6 +48,59 @@ public final class ItemcaseManager {
*/
private final ArrayList<Itemcase> itemcases = new ArrayList<>();
/**
* Initialize this class.
*/
public void initialize() {
// For every currently loaded world.
for(World world : Bukkit.getWorlds()) {
// Request itemcases to be loaded.
this.loadItemcases(world);
}
}
/**
* Loads itemcases for the given world.
*
* @param world World.
*/
private void loadItemcases(World world) {
// Create WorldFile object.
WorldFile file = new WorldFile(world);
// Add to hashmap.
ItemcaseManager.this.worldFiles.put(world, file);
// Attempt to load itemcases and add them to list.
try {
// Load itemcaes.
ArrayList<Itemcase> loadedItemcases = file.loadItemcases();
// Add to list.
ItemcaseManager.this.itemcases.addAll(loadedItemcases);
} catch (IOException e) {
// Log error.
ItemCaseCore.instance.getConsoleLogger().severe(
"Failed to load itemcases for world: " +
world.getName(), e);
// Exit.
return;
}
// Set world name placeholder and log.
ItemCaseCore.instance.getTranslator().setPlaceholder(
"%WORLD_NAME%", world.getName());
ItemCaseCore.instance.getConsoleLogger().info(
"console.info.loaded");
}
/**
* Create a new Itemcase.
*
@ -128,37 +181,8 @@ public final class ItemcaseManager {
// Get world.
World world = event.getWorld();
// Create WorldFile object.
WorldFile file = new WorldFile(world);
// Add to hashmap.
ItemcaseManager.this.worldFiles.put(world, file);
// Attempt to load itemcases and add them to list.
try {
// Load itemcaes.
ArrayList<Itemcase> loadedItemcases = file.loadItemcases();
// Add to list.
ItemcaseManager.this.itemcases.addAll(loadedItemcases);
} catch (IOException e) {
// Log error.
ItemCaseCore.instance.getConsoleLogger().severe(
"Failed to load itemcases for world: " +
world.getName(), e);
// Exit.
return;
}
// Set world name placeholder and log.
ItemCaseCore.instance.getTranslator().setPlaceholder(
"%WORLD_NAME%", world.getName());
ItemCaseCore.instance.getConsoleLogger().info(
"console.info.loaded");
// Request itemcases to be loaded.
ItemcaseManager.this.loadItemcases(world);
}
}