From 2ea78e5462a848a3570307360d023f6f99ba69a5 Mon Sep 17 00:00:00 2001 From: Liam Date: Thu, 28 Mar 2024 15:12:18 +0000 Subject: [PATCH] add vote command --- src/main/java/cc/fascinated/Aetheria.java | 3 -- .../java/cc/fascinated/account/Account.java | 12 ++++---- .../java/cc/fascinated/command/Command.java | 8 ++--- .../cc/fascinated/command/CommandManager.java | 2 ++ .../command/impl/TotalJoinsCommand.java | 4 +-- .../fascinated/command/impl/VoteCommand.java | 29 +++++++++++++++++++ src/main/java/cc/fascinated/config/Lang.java | 6 +++- .../worldsize/impl/WorldSizeCommand.java | 4 +-- src/main/resources/lang.yml | 14 +++++++++ src/main/resources/plugin.yml | 5 +++- 10 files changed, 67 insertions(+), 20 deletions(-) create mode 100644 src/main/java/cc/fascinated/command/impl/VoteCommand.java diff --git a/src/main/java/cc/fascinated/Aetheria.java b/src/main/java/cc/fascinated/Aetheria.java index 7e6e702..bc1541a 100644 --- a/src/main/java/cc/fascinated/Aetheria.java +++ b/src/main/java/cc/fascinated/Aetheria.java @@ -22,9 +22,6 @@ public class Aetheria extends JavaPlugin { public static ThreadPoolExecutor EXECUTOR = new ThreadPoolExecutor(2, 8, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>()); - // todo: move to config - public static final String PREFIX = "§6§lAetheria §7» §f"; - public Aetheria() { INSTANCE = this; } diff --git a/src/main/java/cc/fascinated/account/Account.java b/src/main/java/cc/fascinated/account/Account.java index 443cff5..2731195 100644 --- a/src/main/java/cc/fascinated/account/Account.java +++ b/src/main/java/cc/fascinated/account/Account.java @@ -105,19 +105,19 @@ public class Account { /** * Send a message to the player. * - * @param message the message to send + * @param component the message to send */ - public void sendMessage(String message) { - getPlayer().sendPlainMessage(message); + public void sendMessage(Component component) { + getPlayer().sendMessage(component); } /** * Send a message to the player. * - * @param component the message to send + * @param message the message to send */ - public void sendMessage(Component component) { - getPlayer().sendMessage(component); + public void sendMessage(String message) { + this.sendMessage(Component.text(message)); } /** diff --git a/src/main/java/cc/fascinated/command/Command.java b/src/main/java/cc/fascinated/command/Command.java index efb618c..6da8c48 100644 --- a/src/main/java/cc/fascinated/command/Command.java +++ b/src/main/java/cc/fascinated/command/Command.java @@ -32,11 +32,9 @@ public abstract class Command implements CommandExecutor { @Override public boolean onCommand(@NotNull CommandSender commandSender, org.bukkit.command.@NotNull Command command, @NotNull String s, @NotNull String[] strings) { - if (this.permission != null) { - if (!commandSender.hasPermission(permission)) { - commandSender.sendMessage("§cYou do not have permission to execute this command."); - return true; - } + if (this.permission != null && !commandSender.hasPermission(permission)) { + commandSender.sendMessage("§cYou do not have permission to execute this command."); + return true; } Player player = (Player) commandSender; diff --git a/src/main/java/cc/fascinated/command/CommandManager.java b/src/main/java/cc/fascinated/command/CommandManager.java index 58c89d1..6a9f9f0 100644 --- a/src/main/java/cc/fascinated/command/CommandManager.java +++ b/src/main/java/cc/fascinated/command/CommandManager.java @@ -4,6 +4,7 @@ import cc.fascinated.Aetheria; import cc.fascinated.command.impl.HelpCommand; import cc.fascinated.command.impl.SeedCommand; import cc.fascinated.command.impl.TotalJoinsCommand; +import cc.fascinated.command.impl.VoteCommand; import org.bukkit.command.PluginCommand; public class CommandManager { @@ -12,6 +13,7 @@ public class CommandManager { registerCommand(new TotalJoinsCommand()); registerCommand(new HelpCommand()); registerCommand(new SeedCommand()); + registerCommand(new VoteCommand()); } public static void registerCommand(Command command) { diff --git a/src/main/java/cc/fascinated/command/impl/TotalJoinsCommand.java b/src/main/java/cc/fascinated/command/impl/TotalJoinsCommand.java index 48159de..9d47fa7 100644 --- a/src/main/java/cc/fascinated/command/impl/TotalJoinsCommand.java +++ b/src/main/java/cc/fascinated/command/impl/TotalJoinsCommand.java @@ -1,8 +1,8 @@ package cc.fascinated.command.impl; -import cc.fascinated.Aetheria; import cc.fascinated.account.Account; import cc.fascinated.command.Command; +import cc.fascinated.config.Lang; import org.bukkit.Bukkit; public class TotalJoinsCommand extends Command { @@ -13,6 +13,6 @@ public class TotalJoinsCommand extends Command { @Override public void execute(Account account, String[] args) { - account.sendMessage(Aetheria.PREFIX + "§fTotal joins: §e" + Bukkit.getOfflinePlayers().length + "§f."); + account.sendMessage(Lang.PREFIX.getAsString() + "§fTotal joins: §e" + Bukkit.getOfflinePlayers().length + "§f."); } } diff --git a/src/main/java/cc/fascinated/command/impl/VoteCommand.java b/src/main/java/cc/fascinated/command/impl/VoteCommand.java new file mode 100644 index 0000000..a2cd158 --- /dev/null +++ b/src/main/java/cc/fascinated/command/impl/VoteCommand.java @@ -0,0 +1,29 @@ +package cc.fascinated.command.impl; + +import cc.fascinated.account.Account; +import cc.fascinated.command.Command; +import cc.fascinated.config.Lang; +import cc.fascinated.utils.ChatUtils; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.event.ClickEvent; + +import java.util.List; + +public class VoteCommand extends Command { + + public VoteCommand() { + super("vote"); + } + + @Override + public void execute(Account account, String[] args) { + account.sendMessage(ChatUtils.color(Lang.VOTE_HEADER.getAsString())); + List voteLinks = Lang.VOTE_LINKS.getAsStringList(); + for (String link : voteLinks) { + account.sendMessage(Component.text(ChatUtils.color(Lang.VOTE_FORMAT.getAsString()) + .replace("%link%", link) + .replace("%number%", String.valueOf(voteLinks.indexOf(link) + 1)) + ).clickEvent(ClickEvent.openUrl(link))); + } + } +} diff --git a/src/main/java/cc/fascinated/config/Lang.java b/src/main/java/cc/fascinated/config/Lang.java index 0067f34..2b64fa4 100644 --- a/src/main/java/cc/fascinated/config/Lang.java +++ b/src/main/java/cc/fascinated/config/Lang.java @@ -11,7 +11,11 @@ import java.util.List; @Getter public enum Lang { - HELP_COMMAND("help-command"); + PREFIX("prefix"), + HELP_COMMAND("help-command"), + VOTE_HEADER("vote.header"), + VOTE_FORMAT("vote.format"), + VOTE_LINKS("vote.links"); /** * The path of the lang in the lang.yml file. diff --git a/src/main/java/cc/fascinated/worldsize/impl/WorldSizeCommand.java b/src/main/java/cc/fascinated/worldsize/impl/WorldSizeCommand.java index 67df47a..112002a 100644 --- a/src/main/java/cc/fascinated/worldsize/impl/WorldSizeCommand.java +++ b/src/main/java/cc/fascinated/worldsize/impl/WorldSizeCommand.java @@ -1,8 +1,8 @@ package cc.fascinated.worldsize.impl; -import cc.fascinated.Aetheria; import cc.fascinated.account.Account; import cc.fascinated.command.Command; +import cc.fascinated.config.Lang; import cc.fascinated.utils.FormatterUtils; import cc.fascinated.utils.TimeUtils; import cc.fascinated.worldsize.WorldSizeManager; @@ -18,7 +18,7 @@ public class WorldSizeCommand extends Command { @Override public void execute(Account account, String[] args) { - account.sendMessage(Aetheria.PREFIX + "§fWorld information:"); + account.sendMessage(Lang.PREFIX + "§fWorld information:"); long totalSize = 0; for (Map.Entry entry : WorldSizeManager.getWorldSizes().entrySet()) { long size = entry.getValue(); diff --git a/src/main/resources/lang.yml b/src/main/resources/lang.yml index 5eb0cfb..cf31dca 100644 --- a/src/main/resources/lang.yml +++ b/src/main/resources/lang.yml @@ -1,6 +1,20 @@ +prefix: "&6&lAetheria &7» &f" + help-command: - "&6&lAetheria &7» &fCommands:" - "&e/kill &7- &fKills you" - "&e/worldsize &7- &fShows the total file size of all worlds" - "&e/playercolor [color] &7- &fChange your player name color" - "&e/seed &7- &fShows you the world seed" + +vote: + header: "&6&lAetheria &7» &fVote for us on the following websites:" + format: "&e%number%. &f%link%" + links: + - "https://minecraft.menu/server-aetheria-anarchy.2827/vote" + - "https://topg.org/minecraft-servers/server-662463" + - "https://minecraft-server-list.com/server/496608/vote" + - "https://minecraftservers.org/vote/650863" + - "https://servers-minecraft.net/server-aetheria.24701" + - "https://topminecraftservers.org/vote/33565" + - "https://best-minecraft-servers.co/server-aetheria.16373/vote" \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index aa732fd..e4105ae 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -20,4 +20,7 @@ commands: usage: "/playercolor " seed: description: "Shows the seed of the world" - usage: "/seed" \ No newline at end of file + usage: "/seed" + vote: + description: "Shows the vote links" + usage: "/vote" \ No newline at end of file