📝 Add list commnad

This commit is contained in:
Maxlego08 2024-02-22 16:51:32 +01:00
parent 45bc5c3845
commit f440bdf9d4
6 changed files with 88 additions and 0 deletions

View File

@ -11,14 +11,18 @@ import fr.maxlego08.koth.hook.teams.NoneHook;
import fr.maxlego08.koth.loader.KothLoader; import fr.maxlego08.koth.loader.KothLoader;
import fr.maxlego08.koth.zcore.enums.Message; import fr.maxlego08.koth.zcore.enums.Message;
import fr.maxlego08.koth.zcore.logger.Logger; 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.ZUtils;
import fr.maxlego08.koth.zcore.utils.builder.ItemBuilder; import fr.maxlego08.koth.zcore.utils.builder.ItemBuilder;
import fr.maxlego08.koth.zcore.utils.loader.Loader; import fr.maxlego08.koth.zcore.utils.loader.Loader;
import fr.maxlego08.koth.zcore.utils.storage.Persist; import fr.maxlego08.koth.zcore.utils.storage.Persist;
import fr.maxlego08.koth.zcore.utils.storage.Savable; 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.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -216,4 +220,56 @@ public class KothManager extends ZUtils implements Savable {
public List<Koth> getKoths() { public List<Koth> getKoths() {
return this.koths; 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);
}
} }

View File

@ -18,6 +18,7 @@ public class CommandKoth extends VCommand {
this.addSubCommand(new CommandKothStop(plugin)); this.addSubCommand(new CommandKothStop(plugin));
this.addSubCommand(new CommandKothMove(plugin)); this.addSubCommand(new CommandKothMove(plugin));
this.addSubCommand(new CommandKothVersion(plugin)); this.addSubCommand(new CommandKothVersion(plugin));
this.addSubCommand(new CommandKothList(plugin));
} }
@Override @Override

View File

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

View File

@ -51,6 +51,7 @@ public enum Message {
DESCRIPTION_MOVE("Move a koth"), DESCRIPTION_MOVE("Move a koth"),
DESCRIPTION_AXE("Getting the selection axe"), DESCRIPTION_AXE("Getting the selection axe"),
DESCRIPTION_CREATE("Create new koth"), DESCRIPTION_CREATE("Create new koth"),
DESCRIPTION_LIST("Get koth list"),
AXE_RECEIVE("§7You have just received the axe for zone selection."), AXE_RECEIVE("§7You have just received the axe for zone selection."),
AXE_NAME("§6✤ §7zKoth axe §6✤"), AXE_NAME("§6✤ §7zKoth axe §6✤"),
@ -124,6 +125,10 @@ public enum Message {
MOVE_SUCCESS("§7You have just moved the koth §f%name%§7."), 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"),
; ;

View File

@ -6,6 +6,7 @@ public enum Permission {
ZKOTH_RELOAD, ZKOTH_RELOAD,
ZKOTH_NOW, ZKOTH_NOW,
ZKOTH_AXE, ZKOTH_AXE,
ZKOTH_LIST,
ZKOTH_CREATE, ZKOTH_SPAWN, ZKOTH_STOP, ZKOTH_MOVE; ZKOTH_CREATE, ZKOTH_SPAWN, ZKOTH_STOP, ZKOTH_MOVE;
private String permission; private String permission;

View File

@ -17,6 +17,7 @@
# /zkoth stop <koth name> - zkoth.stop - Stop a koth # /zkoth stop <koth name> - zkoth.stop - Stop a koth
# /zkoth move <koth name> - zkoth.stop - Move a koth # /zkoth move <koth name> - zkoth.stop - Move a koth
# /zkoth version - no permission - Show plugin version # /zkoth version - no permission - Show plugin version
# /zkoth list - zkoth.list - Get koth list
# #
# Placeholders: # Placeholders:
# #