SQL Fixes, GUI National Modifications DONE, GUIHelper and more.
This commit is contained in:
parent
ad81617b73
commit
9750e585cb
|
@ -3,6 +3,7 @@ package moe.oko.opennaw.command;
|
|||
import moe.oko.opennaw.OpenNAW;
|
||||
import moe.oko.opennaw.util.CommandHelper;
|
||||
import moe.oko.opennaw.util.GuiHelper;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
|
@ -39,16 +40,19 @@ public class NationCommand implements TabExecutor {
|
|||
|
||||
OpenNAW.getInstance().getNationHandler().addNation(args[1], group);
|
||||
sender.sendMessage("Created nation " + args[1]);
|
||||
return true;
|
||||
}
|
||||
case "list" -> {
|
||||
final var msg = nationList.size() == 0
|
||||
? "There are no nations"
|
||||
: "There are " + nationList.size() + " nations: " + nationList;
|
||||
sender.sendMessage(msg);
|
||||
return true;
|
||||
}
|
||||
case "remove" -> {
|
||||
OpenNAW.getInstance().getNationHandler().removeNation(args[1]);
|
||||
sender.sendMessage("Removed nation " + args[1]);
|
||||
return true;
|
||||
}
|
||||
case "join" -> {
|
||||
if(!(sender instanceof Player)) {
|
||||
|
@ -57,6 +61,7 @@ public class NationCommand implements TabExecutor {
|
|||
}
|
||||
var player = (Player) sender;
|
||||
player.openInventory(GuiHelper.getJoinMenu().getInventory());
|
||||
return true;
|
||||
}
|
||||
case "leave" -> {
|
||||
var player = args.length < 3
|
||||
|
@ -65,6 +70,19 @@ public class NationCommand implements TabExecutor {
|
|||
OpenNAW.getInstance().getGroupHandler().removePlayerFromGroup(player);
|
||||
|
||||
sender.sendMessage("Removed " + player.getName() + " from their nation");
|
||||
return true;
|
||||
}
|
||||
case "modify" -> {
|
||||
if(!(sender instanceof Player)) {
|
||||
sender.sendMessage("This is an in-game command only.");
|
||||
return true;
|
||||
}
|
||||
if(args.length == 1) {
|
||||
sender.sendMessage(ChatColor.RED + "You need to provide a nation in your argument.");
|
||||
}
|
||||
var player = (Player) sender;
|
||||
player.openInventory(GuiHelper.getNationModMenu(OpenNAW.getInstance().getNationHandler().fetchNationViaName(args[1])).getInventory());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
@ -74,7 +92,7 @@ public class NationCommand implements TabExecutor {
|
|||
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
||||
return switch (args.length) {
|
||||
case 1 -> List.of("add", "join", "leave", "list", "modify", "remove");
|
||||
case 2 -> OpenNAW.getInstance().getNationHandler().getNationList();
|
||||
case 2 -> OpenNAW.getInstance().getNationHandler().getNationStringList();
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -45,6 +45,8 @@ public class Nation {
|
|||
public Location getSpawn() { return spawn; }
|
||||
|
||||
public String getColour() { return colour; }
|
||||
|
||||
public void setColour(String colour) { this.colour = colour; }
|
||||
public void setSpawn(Location l) {
|
||||
this.spawn = l;
|
||||
}
|
||||
|
|
|
@ -41,10 +41,9 @@ public class NAWDatabase {
|
|||
private final String SELECT_NATION = "SELECT * FROM `nations`;";
|
||||
private final String SELECT_PLAYERS = "SELECT * FROM `nation_players`;";
|
||||
|
||||
//name 1,8; group 2,9; icon 3,10; colour 4, 11; world 5,12; x 6,13; y 7,14; z 8,15;
|
||||
//14
|
||||
//name 1,9; group 2,10; icon 3,11; colour 4, 12; world 5,13; x 6,14; y 7,15; z 8,16;
|
||||
private final String SAVE_NATION = "INSERT INTO `nations`(nation_name,groupName,dynmapIcon, colour, spawnworld,spawnx,spawny,spawnz) VALUES " +
|
||||
"(?,?,?,?,?,?,?)" +
|
||||
"(?,?,?,?,?,?,?,?)" +
|
||||
"ON DUPLICATE KEY UPDATE nation_name=?, groupName=?, dynmapIcon=?, colour=?, spawnworld=?, spawnx=?, spawny=?, spawnz=?;";
|
||||
//MAKE SURE YOU RUN AS BATCH (nation, 1,3) (playeruuid, 2,4);
|
||||
private final String SAVE_PLAYER = "INSERT INTO `nation_players`(nation_name, player_uuid) VALUES (?,?) " +
|
||||
|
@ -149,28 +148,27 @@ public class NAWDatabase {
|
|||
public void saveNations(Collection<Nation> nations) {
|
||||
try {
|
||||
OpenNAW.getInstance().getLogger().info("Starting nation save...");
|
||||
//name 1,8; group 2,9; icon 3,10; colour 4, 11; world 5,12; x 6,13; y 7,14; z 8,15;
|
||||
//14
|
||||
//name 1,9; group 2,10; icon 3,11; colour 4, 12; world 5,13; x 6,14; y 7,15; z 8,16;
|
||||
PreparedStatement nationSave = connection.prepareStatement(SAVE_NATION);
|
||||
int i = 0;
|
||||
for(Nation nation : nations) {
|
||||
nationSave.setString(1, nation.getName());
|
||||
nationSave.setString(8, nation.getName());
|
||||
nationSave.setString(9, nation.getName());
|
||||
nationSave.setString(2, nation.getGroup().getName());
|
||||
nationSave.setString(9, nation.getGroup().getName());
|
||||
nationSave.setString(10, nation.getGroup().getName());
|
||||
nationSave.setString(3, nation.getDynmapIcon());
|
||||
nationSave.setString(10, nation.getDynmapIcon());
|
||||
nationSave.setString(11, nation.getDynmapIcon());
|
||||
nationSave.setString(4, nation.getColour());
|
||||
nationSave.setString(11, nation.getColour());
|
||||
nationSave.setString(12, nation.getColour());
|
||||
var loc = nation.getSpawn();
|
||||
nationSave.setString(5, loc.getWorld().getName());
|
||||
nationSave.setString(12, loc.getWorld().getName());
|
||||
nationSave.setString(13, loc.getWorld().getName());
|
||||
nationSave.setInt(6, loc.getBlockX());
|
||||
nationSave.setInt(13, loc.getBlockX());
|
||||
nationSave.setInt(14, loc.getBlockX());
|
||||
nationSave.setInt(7, loc.getBlockY());
|
||||
nationSave.setInt(14, loc.getBlockY());
|
||||
nationSave.setInt(15, loc.getBlockY());
|
||||
nationSave.setInt(8, loc.getBlockZ());
|
||||
nationSave.setInt(15, loc.getBlockZ());
|
||||
nationSave.setInt(16, loc.getBlockZ());
|
||||
|
||||
//Values are set, this is autistic. Run.
|
||||
nationSave.addBatch();
|
||||
|
|
|
@ -7,6 +7,7 @@ import net.kyori.adventure.text.Component;
|
|||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
|
@ -19,7 +20,7 @@ public class ChatHandler implements Listener {
|
|||
var player = e.getPlayer();
|
||||
Audience audience;
|
||||
|
||||
var nationString = "[" + OpenNAW.getInstance().getGroupHandler().getPrefixFromPlayer(player) + "&r] ";
|
||||
var nationString = "[" + ChatColor.valueOf(OpenNAW.getInstance().getNationHandler().getNationByPlayer(player.getUniqueId()).getColour()) + "&r] ";
|
||||
var prefix = legacyComponentSerializer.deserialize(nationString);
|
||||
var message = e.message();
|
||||
|
||||
|
|
|
@ -1,16 +1,22 @@
|
|||
package moe.oko.opennaw.util;
|
||||
|
||||
import moe.oko.opennaw.OpenNAW;
|
||||
import moe.oko.opennaw.model.Nation;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.apache.commons.lang.enums.EnumUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import xyz.janboerman.guilib.api.menu.CycleButton;
|
||||
import xyz.janboerman.guilib.api.menu.ItemButton;
|
||||
import xyz.janboerman.guilib.api.menu.MenuHolder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
public class GuiHelper {
|
||||
public static MenuHolder<OpenNAW> getJoinMenu() {
|
||||
var menu = new MenuHolder<>(OpenNAW.getInstance(), 9, "Join a Nation!");
|
||||
|
@ -19,13 +25,15 @@ public class GuiHelper {
|
|||
int s = 0;
|
||||
for(var nation : OpenNAW.getInstance().getNationHandler().getNationList()) {
|
||||
var is = new ItemStack(Material.getMaterial(nation.getColour() + "_WOOL"));
|
||||
is.getItemMeta().displayName(Component.text(ChatColor.valueOf(nation.getColour()) + nation.getName()));
|
||||
var meta = is.getItemMeta();
|
||||
meta.displayName(Component.text(ChatColor.valueOf(nation.getColour()) + nation.getName()));
|
||||
is.setItemMeta(meta);
|
||||
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.
|
||||
var viewer = event.getViewers().get(1);
|
||||
var viewer = event.getViewers().get(0);
|
||||
if(!(viewer instanceof Player)) { return; } //fugged
|
||||
var player = (Player) viewer;
|
||||
|
||||
|
@ -37,7 +45,77 @@ public class GuiHelper {
|
|||
}
|
||||
}
|
||||
});
|
||||
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));
|
||||
}
|
||||
}
|
||||
/*
|
||||
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();
|
||||
}
|
||||
});
|
||||
return menu;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue