diff --git a/src/main/java/nl/iobyte/themepark/api/menu/objects/StatusMenu.java b/src/main/java/nl/iobyte/themepark/api/menu/objects/StatusMenu.java index 58fb289..69bf20a 100644 --- a/src/main/java/nl/iobyte/themepark/api/menu/objects/StatusMenu.java +++ b/src/main/java/nl/iobyte/themepark/api/menu/objects/StatusMenu.java @@ -8,6 +8,7 @@ import nl.iobyte.menuapi.multi.MenuPage; import nl.iobyte.menuapi.multi.MultiMenu; import nl.iobyte.themepark.ThemePark; import nl.iobyte.themepark.api.ThemeParkAPI; +import nl.iobyte.themepark.api.attraction.enums.Status; import nl.iobyte.themepark.api.attraction.objects.Attraction; import nl.iobyte.themepark.api.attraction.objects.Region; import nl.iobyte.themepark.api.config.enums.StorageKey; @@ -17,10 +18,7 @@ import nl.iobyte.themepark.api.message.MessageKey; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; +import java.util.*; public class StatusMenu { @@ -96,10 +94,7 @@ public class StatusMenu { if(attraction == null) return; - if(!attraction_index.containsKey(attraction.getID())) - return; - - int slot = attraction_index.get(attraction.getID()); + int slot = attraction_index.getOrDefault(attraction.getID(), 0); if(slot < 1) return; @@ -107,6 +102,21 @@ public class StatusMenu { menu.updateItem(slot); } + /** + * Update Attraction item where Status + * @param status Status + */ + public void updateStatus(Status status) { + for(Map.Entry entry : ThemePark.getInstance().getAPI().getAttractionService().getAttractionsByStatus(status).entrySet()) { + int slot = attraction_index.getOrDefault(entry.getKey(), 0); + if(slot < 1) + return; + + menu.setItem(slot, getAttraction(entry.getValue())); + menu.updateItem(slot); + } + } + /** * Open menu on first page for Player * @param player Player diff --git a/src/main/java/nl/iobyte/themepark/commands/subcommands/status/StatusNameCommand.java b/src/main/java/nl/iobyte/themepark/commands/subcommands/status/StatusNameCommand.java index f017046..1d0a3d1 100644 --- a/src/main/java/nl/iobyte/themepark/commands/subcommands/status/StatusNameCommand.java +++ b/src/main/java/nl/iobyte/themepark/commands/subcommands/status/StatusNameCommand.java @@ -6,7 +6,6 @@ import nl.iobyte.commandapi.objects.SubCommand; import nl.iobyte.themepark.api.attraction.enums.Status; import nl.iobyte.themepark.api.message.Text; import nl.iobyte.commandapi.interfaces.ICommandExecutor; -import org.bukkit.entity.Player; import java.util.List; public class StatusNameCommand extends SubCommand { @@ -24,7 +23,7 @@ public class StatusNameCommand extends SubCommand { Status status = (Status) list.get(0); String name = (String) list.get(1); status.setName(name); - sender.sendMessage(Text.color("&6&lThemeParkMC &f➢ &aSuccessfully changed the name of status &f"+status.toString())); + sender.sendMessage(Text.color("&6&lThemeParkMC &f➢ &aSuccessfully changed the name of status &f"+ status)); } } diff --git a/src/main/java/nl/iobyte/themepark/listeners/StatusListener.java b/src/main/java/nl/iobyte/themepark/listeners/StatusListener.java index a41903a..70fb707 100644 --- a/src/main/java/nl/iobyte/themepark/listeners/StatusListener.java +++ b/src/main/java/nl/iobyte/themepark/listeners/StatusListener.java @@ -11,16 +11,19 @@ import java.util.HashMap; public class StatusListener implements Listener { @EventHandler - public void onNameChange(StatusColorChangeEvent e) { - //Update Sign - for(Attraction attraction : ThemePark.getInstance().getAPI().getAttractionService().getAttractionsByStatus(e.getStatus()).values()) - ThemePark.getInstance().getAPI().getSignManager().update(attraction); - + public void onColorChange(StatusColorChangeEvent e) { ThemePark.getInstance().getAPI().getConfigurationManager().set( StorageLocation.STATUS_SETTINGS, "states."+e.getStatus().toString()+".color", e.getCurrent() ); + + //Update menu + ThemePark.getInstance().getAPI().getMenuService().getStatusMenu().updateStatus(e.getStatus()); + + //Update Sign + for(Attraction attraction : ThemePark.getInstance().getAPI().getAttractionService().getAttractionsByStatus(e.getStatus()).values()) + ThemePark.getInstance().getAPI().getSignManager().update(attraction); } @EventHandler @@ -41,6 +44,9 @@ public class StatusListener implements Listener { e.getCurrent() ); + //Update menu + ThemePark.getInstance().getAPI().getMenuService().getStatusMenu().updateStatus(e.getStatus()); + //Update Sign for(Attraction attraction : ThemePark.getInstance().getAPI().getAttractionService().getAttractionsByStatus(e.getStatus()).values()) ThemePark.getInstance().getAPI().getSignManager().update(attraction); @@ -52,7 +58,7 @@ public class StatusListener implements Listener { ThemePark.getInstance().getAPI().getDatabaseService().executeAsync( "remote", "UPDATE states SET color=? WHERE id=?", - new HashMap() {{ + new HashMap<>() {{ put(1, e.getCurrent()); put(2, e.getStatus().getID()); }} @@ -81,6 +87,9 @@ public class StatusListener implements Listener { "states."+e.getStatus().toString()+".material", e.getCurrent().toString() ); + + //Update menu + ThemePark.getInstance().getAPI().getMenuService().getStatusMenu().updateStatus(e.getStatus()); } }