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();