2022-05-04 21:09:41 +00:00
|
|
|
package moe.oko.opennaw.util;
|
|
|
|
|
|
|
|
import moe.oko.opennaw.OpenNAW;
|
2022-05-05 19:22:21 +00:00
|
|
|
import moe.oko.opennaw.model.City;
|
2022-05-05 06:28:48 +00:00
|
|
|
import moe.oko.opennaw.model.Nation;
|
2022-05-05 19:22:21 +00:00
|
|
|
import moe.oko.opennaw.model.type.CityType;
|
2022-05-04 21:09:41 +00:00
|
|
|
import net.kyori.adventure.text.Component;
|
2022-05-05 06:28:48 +00:00
|
|
|
import org.apache.commons.lang.enums.EnumUtils;
|
2022-05-04 21:09:41 +00:00
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.Material;
|
2022-05-05 19:22:21 +00:00
|
|
|
import org.bukkit.conversations.ConversationContext;
|
|
|
|
import org.bukkit.conversations.ConversationFactory;
|
|
|
|
import org.bukkit.conversations.Prompt;
|
|
|
|
import org.bukkit.conversations.StringPrompt;
|
2022-05-04 21:09:41 +00:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.event.inventory.ClickType;
|
|
|
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
2022-05-05 19:22:21 +00:00
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
import org.jetbrains.annotations.Nullable;
|
2022-05-05 06:28:48 +00:00
|
|
|
import xyz.janboerman.guilib.api.menu.CycleButton;
|
2022-05-04 21:09:41 +00:00
|
|
|
import xyz.janboerman.guilib.api.menu.ItemButton;
|
|
|
|
import xyz.janboerman.guilib.api.menu.MenuHolder;
|
|
|
|
|
2022-05-05 06:28:48 +00:00
|
|
|
import java.util.ArrayList;
|
2022-05-05 19:22:21 +00:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
2022-05-05 06:28:48 +00:00
|
|
|
|
2022-05-04 21:09:41 +00:00
|
|
|
public class GuiHelper {
|
|
|
|
public static MenuHolder<OpenNAW> getJoinMenu() {
|
|
|
|
var menu = new MenuHolder<>(OpenNAW.getInstance(), 9, "Join a Nation!");
|
|
|
|
|
|
|
|
int i = 9;
|
|
|
|
int s = 0;
|
|
|
|
for(var nation : OpenNAW.getInstance().getNationHandler().getNationList()) {
|
|
|
|
var is = new ItemStack(Material.getMaterial(nation.getColour() + "_WOOL"));
|
2022-05-05 06:28:48 +00:00
|
|
|
var meta = is.getItemMeta();
|
|
|
|
meta.displayName(Component.text(ChatColor.valueOf(nation.getColour()) + nation.getName()));
|
|
|
|
is.setItemMeta(meta);
|
2022-05-04 21:09:41 +00:00
|
|
|
menu.setButton(s, new ItemButton<>(is) {
|
|
|
|
@Override
|
|
|
|
public void onClick(MenuHolder<?> menu, InventoryClickEvent event) {
|
|
|
|
if(event.getClick().equals(ClickType.LEFT)) {
|
|
|
|
//Left click, run join logic.
|
2022-05-05 06:28:48 +00:00
|
|
|
var viewer = event.getViewers().get(0);
|
2022-05-04 21:09:41 +00:00
|
|
|
if(!(viewer instanceof Player)) { return; } //fugged
|
|
|
|
var player = (Player) viewer;
|
|
|
|
|
|
|
|
nation.getPlayerMap().put(player.getUniqueId(), player);
|
|
|
|
OpenNAW.getInstance().getGroupHandler().addPlayerToGroup(player, nation.getGroup());
|
|
|
|
|
|
|
|
player.sendMessage(ChatColor.GREEN + "Joined " + nation.getName() + " successfully.");
|
|
|
|
event.getView().close(); //Close inv.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2022-05-05 06:28:48 +00:00
|
|
|
s++;
|
|
|
|
}
|
|
|
|
return menu;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static MenuHolder<OpenNAW> getNationModMenu(Nation nation) {
|
|
|
|
var menu = new MenuHolder<>(OpenNAW.getInstance(), 9, nation.getName() + " Modification");
|
|
|
|
|
|
|
|
var colour = new ItemStack(Material.valueOf(nation.getColour() + "_WOOL"));
|
|
|
|
var meta = colour.getItemMeta();
|
|
|
|
meta.displayName(Component.text(colour.getType().name().replace("_WOOL", "").toUpperCase()));
|
|
|
|
colour.setItemMeta(meta);
|
|
|
|
var woolCollection = new ArrayList<>();
|
|
|
|
for(var mat : Material.values()) {
|
|
|
|
var material = (Material) mat;
|
|
|
|
if (material.name().contains("_WOOL")) {
|
|
|
|
woolCollection.add(new ItemStack(material));
|
|
|
|
}
|
2022-05-04 21:09:41 +00:00
|
|
|
}
|
2022-05-05 06:28:48 +00:00
|
|
|
/*
|
|
|
|
Colour Selection Button
|
|
|
|
*/
|
|
|
|
menu.setButton(0, new CycleButton<>(colour, woolCollection, 0) {
|
|
|
|
@Override
|
|
|
|
public void updateStateForwards(MenuHolder<?> menu, InventoryClickEvent event) {
|
|
|
|
incrementCursor();
|
|
|
|
var i = getCursor();
|
|
|
|
var player = (Player) event.getViewers().get(0);
|
|
|
|
var is = (ItemStack) woolCollection.get(i);
|
|
|
|
var meta = is.getItemMeta();
|
|
|
|
meta.displayName(Component.text(is.getType().name().replace("_WOOL", "").toUpperCase()));
|
|
|
|
is.setItemMeta(meta);
|
|
|
|
setIcon(is);
|
|
|
|
nation.setColour(this.getIcon().getType().name().replace("_WOOL", ""));
|
|
|
|
player.sendMessage(ChatColor.GREEN + "Colour for this nation was changed to " + nation.getColour());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void updateStateBackwards(MenuHolder<?> menu, InventoryClickEvent event) {
|
|
|
|
decrementCursor();
|
|
|
|
var i = getCursor();
|
|
|
|
var player = (Player) event.getViewers().get(0);
|
|
|
|
var is = (ItemStack) woolCollection.get(i);
|
|
|
|
var meta = is.getItemMeta();
|
|
|
|
meta.displayName(Component.text(is.getType().name().replace("_WOOL", "").toUpperCase()));
|
|
|
|
is.setItemMeta(meta);
|
|
|
|
setIcon(is);
|
|
|
|
nation.setColour(this.getIcon().getType().name().replace("_WOOL", ""));
|
|
|
|
player.sendMessage(ChatColor.GREEN + "Colour for this nation was changed to " + nation.getColour());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Spawn Setting
|
|
|
|
*/
|
|
|
|
var is = new ItemStack(Material.BARRIER);
|
|
|
|
var meta1 = is.getItemMeta();
|
|
|
|
meta1.displayName(Component.text("Spawn Location"));
|
|
|
|
var lore = new ArrayList<Component>();
|
|
|
|
lore.add(Component.text(ChatColor.GRAY + "Click to set your current location as the spawn for this nation."));
|
|
|
|
meta1.lore(lore);
|
|
|
|
is.setItemMeta(meta1);
|
|
|
|
menu.setButton(1, new ItemButton<>(is) {
|
|
|
|
@Override
|
|
|
|
public void onClick(MenuHolder<?> menu, InventoryClickEvent event) {
|
|
|
|
var player = (Player) event.getViewers().get(0);
|
|
|
|
nation.setSpawn(player.getLocation());
|
|
|
|
player.sendMessage(ChatColor.GREEN + "Successfully set new spawn location for " + nation.getName() + " to " + player.getLocation());
|
|
|
|
player.closeInventory();
|
|
|
|
}
|
|
|
|
});
|
2022-05-04 21:09:41 +00:00
|
|
|
return menu;
|
|
|
|
}
|
2022-05-05 19:22:21 +00:00
|
|
|
public static MenuHolder<OpenNAW> getCityModMenu(City city) {
|
|
|
|
var menu = new MenuHolder<>(OpenNAW.getInstance(), 9, city.getName() + " Modification");
|
|
|
|
var map = new HashMap<CityType, Material>();
|
|
|
|
map.put(CityType.CAPITAL, Material.RED_BANNER);
|
|
|
|
map.put(CityType.NORMAL, Material.SPONGE);
|
|
|
|
map.put(CityType.PORT, Material.OAK_BOAT);
|
|
|
|
|
|
|
|
var typeis = new ItemStack(map.get(city.getType()));
|
|
|
|
var typemeta = typeis.getItemMeta();
|
|
|
|
typemeta.displayName(Component.text(city.getType().name()));
|
|
|
|
List<Component> list = new ArrayList<>();
|
|
|
|
list.add(Component.text(city.getType().getDescription()));
|
|
|
|
typemeta.lore(list);
|
|
|
|
typeis.setItemMeta(typemeta);
|
|
|
|
menu.setButton(0, new CycleButton<>(typeis, map.keySet().stream().toList(), 0) {
|
|
|
|
@Override
|
|
|
|
public void updateStateBackwards(MenuHolder<?> menuHolder, InventoryClickEvent event) {
|
|
|
|
decrementCursor();
|
|
|
|
var i = getCursor();
|
|
|
|
var player = (Player) event.getViewers().get(0);
|
|
|
|
var typeis = new ItemStack(map.get(map.keySet().stream().toList().get(i)));
|
|
|
|
var typemeta = typeis.getItemMeta();
|
|
|
|
typemeta.displayName(Component.text(map.keySet().stream().toList().get(i).name()));
|
|
|
|
List<Component> list = new ArrayList<>();
|
|
|
|
list.add(Component.text(map.keySet().stream().toList().get(i).getDescription()));
|
|
|
|
typemeta.lore(list);
|
|
|
|
typeis.setItemMeta(typemeta);
|
|
|
|
setIcon(typeis);
|
|
|
|
city.setType(map.keySet().stream().toList().get(i));
|
|
|
|
player.sendMessage(ChatColor.GREEN + "Successfully set city type to " + city.getType() + "!");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void updateStateForwards(MenuHolder<?> menuHolder, InventoryClickEvent event) {
|
|
|
|
incrementCursor();
|
|
|
|
var i = getCursor();
|
|
|
|
var player = (Player) event.getViewers().get(0);
|
|
|
|
var typeis = new ItemStack(map.get(map.keySet().stream().toList().get(i)));
|
|
|
|
var typemeta = typeis.getItemMeta();
|
|
|
|
typemeta.displayName(Component.text(map.keySet().stream().toList().get(i).name()));
|
|
|
|
List<Component> list = new ArrayList<>();
|
|
|
|
list.add(Component.text(map.keySet().stream().toList().get(i).getDescription()));
|
|
|
|
typemeta.lore(list);
|
|
|
|
typeis.setItemMeta(typemeta);
|
|
|
|
setIcon(typeis);
|
|
|
|
city.setType(map.keySet().stream().toList().get(i));
|
|
|
|
player.sendMessage(ChatColor.GREEN + "Successfully set city type to " + city.getType() + "!");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var nameis = new ItemStack(Material.OAK_SIGN);
|
|
|
|
var namemeta = nameis.getItemMeta();
|
|
|
|
namemeta.displayName(Component.text("Set City Name"));
|
|
|
|
nameis.setItemMeta(namemeta);
|
|
|
|
menu.setButton(1, new ItemButton<>(nameis) {
|
|
|
|
@Override
|
|
|
|
public void onClick(MenuHolder<?> holder, InventoryClickEvent event) {
|
|
|
|
var player = (Player) event.getViewers().get(0);
|
|
|
|
player.closeInventory();
|
|
|
|
//Make our string prompt which has multiple hhhhh
|
|
|
|
var namePrompt = new StringPrompt() {
|
|
|
|
@Override
|
|
|
|
public @NotNull String getPromptText(@NotNull ConversationContext conversationContext) {
|
|
|
|
return ChatColor.GOLD + "Please enter the name you would like to set the city name (less than 50 char) to within 15 seconds." +
|
|
|
|
"\n" + ChatColor.YELLOW + "Type CANCEL if you would like to cancel this prompt.";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public @Nullable Prompt acceptInput(@NotNull ConversationContext conversationContext, @Nullable String s) {
|
|
|
|
conversationContext.getForWhom().sendRawMessage(ChatColor.GREEN + "Successfully set the city name to " + s);
|
|
|
|
city.setName(s);
|
|
|
|
return END_OF_CONVERSATION;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
var factory = new ConversationFactory(OpenNAW.getInstance()).withFirstPrompt(namePrompt)
|
|
|
|
.withEscapeSequence("CANCEL").withTimeout(15).thatExcludesNonPlayersWithMessage("no console");
|
|
|
|
factory.buildConversation(player).begin();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return menu;
|
|
|
|
}
|
2022-05-04 21:09:41 +00:00
|
|
|
}
|