3
0
Fork 0

Update menu on status(name, color, material) change

This commit is contained in:
thomas 2021-08-10 15:39:48 +02:00
parent 9b9b3d827c
commit f8a6df8479
3 changed files with 34 additions and 16 deletions

View file

@ -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<String, Attraction> 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

View file

@ -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));
}
}

View file

@ -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<Integer, Object>() {{
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());
}
}