From f440bdf9d48b610906375a5e7344c81de0f8bb86 Mon Sep 17 00:00:00 2001 From: Maxlego08 Date: Thu, 22 Feb 2024 16:51:32 +0100 Subject: [PATCH] :memo: Add list commnad --- src/fr/maxlego08/koth/KothManager.java | 56 +++++++++++++++++++ .../koth/command/commands/CommandKoth.java | 1 + .../command/commands/CommandKothList.java | 24 ++++++++ .../maxlego08/koth/zcore/enums/Message.java | 5 ++ .../koth/zcore/enums/Permission.java | 1 + src/main/resources/config.yml | 1 + 6 files changed, 88 insertions(+) create mode 100644 src/fr/maxlego08/koth/command/commands/CommandKothList.java diff --git a/src/fr/maxlego08/koth/KothManager.java b/src/fr/maxlego08/koth/KothManager.java index dfe0690..78ea324 100644 --- a/src/fr/maxlego08/koth/KothManager.java +++ b/src/fr/maxlego08/koth/KothManager.java @@ -11,14 +11,18 @@ import fr.maxlego08.koth.hook.teams.NoneHook; import fr.maxlego08.koth.loader.KothLoader; import fr.maxlego08.koth.zcore.enums.Message; import fr.maxlego08.koth.zcore.logger.Logger; +import fr.maxlego08.koth.zcore.utils.Cuboid; import fr.maxlego08.koth.zcore.utils.ZUtils; import fr.maxlego08.koth.zcore.utils.builder.ItemBuilder; import fr.maxlego08.koth.zcore.utils.loader.Loader; import fr.maxlego08.koth.zcore.utils.storage.Persist; import fr.maxlego08.koth.zcore.utils.storage.Savable; +import net.md_5.bungee.api.chat.ClickEvent; +import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -216,4 +220,56 @@ public class KothManager extends ZUtils implements Savable { public List getKoths() { return this.koths; } + + public void sendKothList(CommandSender sender) { + + if (koths.isEmpty()) { + message(sender, Message.LIST_EMPTY); + return; + } + + if (sender instanceof ConsoleCommandSender) { + + String string = toList(koths.stream().map(Koth::getName).collect(Collectors.toList()), "§8", "§7"); + message(sender, Message.LIST_CONSOLE, "%koth%", string); + + } else { + + Player player = (Player) sender; + message(player, Message.LIST_PLAYER); + koths.forEach(koth -> buildKothMessage(player, koth)); + } + } + + private void buildKothMessage(Player player, Koth koth) { + + TextComponent component = buildTextComponent("§f§l» §7" + koth.getName() + " "); + + Cuboid cuboid = koth.getCuboid(); + Location center = cuboid.getCenter(); + String location = center.getWorld().getName() + ", " + center.getBlockX() + ", " + center.getBlockY() + ", " + center.getBlockZ(); + + setHoverMessage(component, "§7Location: §f" + location); + setClickAction(component, ClickEvent.Action.SUGGEST_COMMAND, "/zkoth info " + koth.getName()); + + TextComponent spawn = buildTextComponent("§8(§aSpawn§8)"); + setClickAction(spawn, ClickEvent.Action.SUGGEST_COMMAND, "/zkoth spawn " + koth.getName()); + setHoverMessage(spawn, "§7Click for spawn koth"); + + TextComponent now = buildTextComponent(" §8(§eSpawn now§8)"); + setClickAction(now, ClickEvent.Action.SUGGEST_COMMAND, "/zkoth now " + koth.getName()); + setHoverMessage(now, "§7Click for spawn koth now"); + + TextComponent delete = buildTextComponent(" §8(§cDelete§8)"); + setClickAction(delete, ClickEvent.Action.SUGGEST_COMMAND, "/zkoth delete " + koth.getName()); + setHoverMessage(delete, "§7Click for delete koth"); + + component.addExtra(spawn); + component.addExtra(now); + component.addExtra(delete); + + player.spigot().sendMessage(component); + + } + } diff --git a/src/fr/maxlego08/koth/command/commands/CommandKoth.java b/src/fr/maxlego08/koth/command/commands/CommandKoth.java index d7b7d9c..4d6f6b2 100644 --- a/src/fr/maxlego08/koth/command/commands/CommandKoth.java +++ b/src/fr/maxlego08/koth/command/commands/CommandKoth.java @@ -18,6 +18,7 @@ public class CommandKoth extends VCommand { this.addSubCommand(new CommandKothStop(plugin)); this.addSubCommand(new CommandKothMove(plugin)); this.addSubCommand(new CommandKothVersion(plugin)); + this.addSubCommand(new CommandKothList(plugin)); } @Override diff --git a/src/fr/maxlego08/koth/command/commands/CommandKothList.java b/src/fr/maxlego08/koth/command/commands/CommandKothList.java new file mode 100644 index 0000000..146d057 --- /dev/null +++ b/src/fr/maxlego08/koth/command/commands/CommandKothList.java @@ -0,0 +1,24 @@ +package fr.maxlego08.koth.command.commands; + +import fr.maxlego08.koth.KothPlugin; +import fr.maxlego08.koth.command.VCommand; +import fr.maxlego08.koth.zcore.enums.Message; +import fr.maxlego08.koth.zcore.enums.Permission; +import fr.maxlego08.koth.zcore.utils.commands.CommandType; + +public class CommandKothList extends VCommand { + + public CommandKothList(KothPlugin plugin) { + super(plugin); + this.setPermission(Permission.ZKOTH_LIST); + this.addSubCommand("list"); + this.setDescription(Message.DESCRIPTION_LIST); + } + + @Override + protected CommandType perform(KothPlugin plugin) { + this.manager.sendKothList(this.sender); + return CommandType.SUCCESS; + } + +} diff --git a/src/fr/maxlego08/koth/zcore/enums/Message.java b/src/fr/maxlego08/koth/zcore/enums/Message.java index 8aa9f9b..caa7a70 100644 --- a/src/fr/maxlego08/koth/zcore/enums/Message.java +++ b/src/fr/maxlego08/koth/zcore/enums/Message.java @@ -51,6 +51,7 @@ public enum Message { DESCRIPTION_MOVE("Move a koth"), DESCRIPTION_AXE("Getting the selection axe"), DESCRIPTION_CREATE("Create new koth"), + DESCRIPTION_LIST("Get koth list"), AXE_RECEIVE("§7You have just received the axe for zone selection."), AXE_NAME("§6✤ §7zKoth axe §6✤"), @@ -124,6 +125,10 @@ public enum Message { MOVE_SUCCESS("§7You have just moved the koth §f%name%§7."), + LIST_CONSOLE("§fKoths§8: §f%koth%"), + LIST_PLAYER("§fKoths§8: §8(§7Use your mouse)"), + LIST_EMPTY("§fKoths§8: §cempty"), + ; diff --git a/src/fr/maxlego08/koth/zcore/enums/Permission.java b/src/fr/maxlego08/koth/zcore/enums/Permission.java index c2e9e64..148a578 100644 --- a/src/fr/maxlego08/koth/zcore/enums/Permission.java +++ b/src/fr/maxlego08/koth/zcore/enums/Permission.java @@ -6,6 +6,7 @@ public enum Permission { ZKOTH_RELOAD, ZKOTH_NOW, ZKOTH_AXE, + ZKOTH_LIST, ZKOTH_CREATE, ZKOTH_SPAWN, ZKOTH_STOP, ZKOTH_MOVE; private String permission; diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 2fa7cfd..6cccba9 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -17,6 +17,7 @@ # /zkoth stop - zkoth.stop - Stop a koth # /zkoth move - zkoth.stop - Move a koth # /zkoth version - no permission - Show plugin version +# /zkoth list - zkoth.list - Get koth list # # Placeholders: #