diff --git a/src/main/java/me/paradoxpixel/themepark/api/API.java b/src/main/java/me/paradoxpixel/themepark/api/API.java index 900fda3..300367d 100644 --- a/src/main/java/me/paradoxpixel/themepark/api/API.java +++ b/src/main/java/me/paradoxpixel/themepark/api/API.java @@ -68,6 +68,11 @@ public class API { regions.remove(id.toLowerCase()); } + public static void clearRegions() { + regions.clear(); + attractions.clear(); + } + public static void addAttraction(Attraction attraction) { if(!isRegion(attraction.getRegion_id())) return; diff --git a/src/main/java/me/paradoxpixel/themepark/attraction/AttractionMenu.java b/src/main/java/me/paradoxpixel/themepark/attraction/AttractionMenu.java index e3fae0c..1f4180d 100644 --- a/src/main/java/me/paradoxpixel/themepark/attraction/AttractionMenu.java +++ b/src/main/java/me/paradoxpixel/themepark/attraction/AttractionMenu.java @@ -26,10 +26,11 @@ public class AttractionMenu { private static YamlConfig settings = ThemeParkPlugin.getInstance().getSettings(); private static GUI gui; - private static HashMap index = new HashMap<>(); + private static HashMap index; public static void load() { gui = new GUI(settings.getConfig().getString("menu.title"), 9); + index = new HashMap<>(); loadData(); loadItems(); } @@ -106,10 +107,6 @@ public class AttractionMenu { Attraction attraction = new Attraction(id, name, region_id, location, type, status); API.addAttraction(attraction); } - - for(Region region : API.getRegions().values()) - if(region.getAttractions().isEmpty()) - API.removeRegion(region.getId()); } private static void loadItems() { diff --git a/src/main/java/me/paradoxpixel/themepark/command/ThemeParkCommand.java b/src/main/java/me/paradoxpixel/themepark/command/ThemeParkCommand.java index 4b17939..9ad8b4a 100644 --- a/src/main/java/me/paradoxpixel/themepark/command/ThemeParkCommand.java +++ b/src/main/java/me/paradoxpixel/themepark/command/ThemeParkCommand.java @@ -180,16 +180,13 @@ public class ThemeParkCommand extends BukkitCommand { ThemeParkPlugin.getInstance().getSigns().reload(); ThemeParkPlugin.getInstance().getSettings().reload(); ThemeParkPlugin.getInstance().getMessage().reload(); - - API.getRegions().clear(); - API.getAttractions().clear(); + API.clearRegions(); StatusManager.load(); AttractionMenu.load(); - for(Region region : API.getRegions().values()) - if(region.getAttractions().isEmpty()) - API.removeRegion(region.getId()); - + Bukkit.getScheduler().runTaskAsynchronously(ThemeParkPlugin.getInstance(),() -> { + ThemeParkPlugin.getInstance().getDatabaseHandler().load(); + }); sender.sendMessage(Utils.color(Message.getMessage("reloaded"))); } diff --git a/src/main/java/me/paradoxpixel/themepark/database/DatabaseHandler.java b/src/main/java/me/paradoxpixel/themepark/database/DatabaseHandler.java index 708e5cf..6967e1b 100644 --- a/src/main/java/me/paradoxpixel/themepark/database/DatabaseHandler.java +++ b/src/main/java/me/paradoxpixel/themepark/database/DatabaseHandler.java @@ -21,7 +21,7 @@ public class DatabaseHandler { load(); } - private void load() { + public void load() { database.execute("CREATE TABLE IF NOT EXISTS attraction (id VARCHAR(256) NOT NULL, name VARCHAR(256) NOT NULL, region_id VARCHAR(256) NOT NULL, type VARCHAR(256) NOT NULL, status VARCHAR(256) NOT NULL, PRIMARY KEY(id))", null); database.execute("CREATE TABLE IF NOT EXISTS region (id VARCHAR(256) NOT NULL, name VARCHAR(256) NOT NULL, PRIMARY KEY(id))", null); database.execute("CREATE TABLE IF NOT EXISTS status (statusId VARCHAR(256) NOT NULL, statusName VARCHAR(256) NOT NULL)", null);