1
0

add vote command

This commit is contained in:
Lee
2024-03-28 15:12:18 +00:00
parent 48ad8a707b
commit 2ea78e5462
10 changed files with 67 additions and 20 deletions

View File

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

View File

@ -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));
}
/**

View File

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

View File

@ -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) {

View File

@ -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.");
}
}

View File

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

View File

@ -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.

View File

@ -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<World, Long> entry : WorldSizeManager.getWorldSizes().entrySet()) {
long size = entry.getValue();

View File

@ -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"

View File

@ -20,4 +20,7 @@ commands:
usage: "/playercolor <color>"
seed:
description: "Shows the seed of the world"
usage: "/seed"
usage: "/seed"
vote:
description: "Shows the vote links"
usage: "/vote"