1
0

start migration to lang file

This commit is contained in:
Lee
2024-03-28 14:00:15 +00:00
parent c80d1318d6
commit 48ad8a707b
13 changed files with 132 additions and 31 deletions

View File

@ -76,6 +76,8 @@ public class Account {
this.firstJoin = config.getLong("firstJoin");
this.lastLogin = config.getLong("lastLogin");
this.lastLogin = System.currentTimeMillis(); // Update last login
// Load profiles
this.playerColorProfile = new PlayerColor(this, this.getProfileSection("playerColor"));

View File

@ -2,21 +2,26 @@ package cc.fascinated.command;
import cc.fascinated.Aetheria;
import cc.fascinated.command.impl.HelpCommand;
import cc.fascinated.command.impl.SeedCommand;
import cc.fascinated.command.impl.TotalJoinsCommand;
import java.util.Objects;
import org.bukkit.command.PluginCommand;
public class CommandManager {
public CommandManager() {
registerCommand(new TotalJoinsCommand());
registerCommand(new HelpCommand());
registerCommand(new SeedCommand());
}
public static void registerCommand(Command command) {
if (command == null) {
throw new IllegalArgumentException("Command cannot be null.");
}
Objects.requireNonNull(Aetheria.INSTANCE.getCommand(command.getCommand())).setExecutor(command);
PluginCommand pluginCommand = Aetheria.INSTANCE.getCommand(command.getCommand());
if (pluginCommand == null) {
throw new IllegalArgumentException("Command " + command.getCommand() + " does not exist.");
}
pluginCommand.setExecutor(command);
}
}

View File

@ -1,10 +1,9 @@
package cc.fascinated.command.impl;
import cc.fascinated.Aetheria;
import cc.fascinated.account.Account;
import cc.fascinated.command.Command;
import java.util.Objects;
import cc.fascinated.config.Lang;
import cc.fascinated.utils.ChatUtils;
public class HelpCommand extends Command {
@ -14,9 +13,8 @@ public class HelpCommand extends Command {
@Override
public void execute(Account account, String[] args) {
account.sendMessage("§6§lAetheria §7» §fCommands:");
for (String line : Objects.requireNonNull(Aetheria.INSTANCE.getConfig().getStringList("help-command"))) {
account.sendMessage(" " + line.replaceAll("&", "§"));
for (String line : Lang.HELP_COMMAND.getAsStringList()) {
account.sendMessage(ChatUtils.color(line));
}
}
}

View File

@ -0,0 +1,21 @@
package cc.fascinated.command.impl;
import cc.fascinated.account.Account;
import cc.fascinated.command.Command;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.ClickEvent;
public class SeedCommand extends Command {
public SeedCommand() {
super("seed");
}
@Override
public void execute(Account account, String[] args) {
account.sendMessage(Component.text("§b§lSEED §7» §fThe seed of this world is: " + account.getPlayer().getWorld().getSeed() + ".")
.hoverEvent(Component.text("Click to copy the seed.").color(net.kyori.adventure.text.format.NamedTextColor.GRAY))
.clickEvent(ClickEvent.copyToClipboard(String.valueOf(account.getPlayer().getWorld().getSeed())))
);
}
}

View File

@ -0,0 +1,67 @@
package cc.fascinated.config;
import cc.fascinated.Aetheria;
import cc.fascinated.utils.io.Config;
import lombok.Getter;
import org.bukkit.configuration.file.FileConfiguration;
import java.util.HashMap;
import java.util.List;
@Getter
public enum Lang {
HELP_COMMAND("help-command");
/**
* The path of the lang in the lang.yml file.
*/
private final String path;
Lang(String path) {
this.path = path;
}
/**
* Cache of the lang values.
*/
private final HashMap<String, Object> cache = new HashMap<>();
/**
* The lang configuration.
*/
private final Config langConfig = new Config(Aetheria.INSTANCE, "lang.yml", null);
/**
* Gets as an object.
*
* @return the string
*/
public Object get() {
return cache.computeIfAbsent(path, key -> {
FileConfiguration configuration = langConfig.getFileConfiguration();
if (configuration.get(path) == null) {
throw new IllegalArgumentException("Path " + path + " does not exist in the lang.yml file.");
}
return configuration.get(path);
});
}
/**
* Gets as a string.
*
* @return the string
*/
public String getAsString() {
return (String) get();
}
/**
* Gets as a string list.
*
* @return the string list
*/
public List<String> getAsStringList() {
return (List<String>) get();
}
}

View File

@ -10,18 +10,8 @@ public abstract class Metric {
*/
private final String name;
/**
* Whether the metric should be collected asynchronously.
*/
private final boolean async;
public Metric(String name, boolean async) {
this.name = name;
this.async = async;
}
public Metric(String name) {
this(name, true);
this.name = name;
}
/**

View File

@ -11,7 +11,7 @@ import java.util.Map;
public class EntityCountMetric extends Metric {
public EntityCountMetric() {
super("entity_count", true);
super("entity_count");
}
@Override

View File

@ -11,7 +11,7 @@ import java.util.Map;
public class LoadedChunksMetric extends Metric {
public LoadedChunksMetric() {
super("loaded_chunks", true);
super("loaded_chunks");
}
@Override

View File

@ -0,0 +1,14 @@
package cc.fascinated.utils;
public class ChatUtils {
/**
* Replaces all '&' with '§' in the message.
*
* @param message the message
* @return the formatted string
*/
public static String color(String message) {
return message.replaceAll("&", "§");
}
}

View File

@ -21,8 +21,8 @@ public class Config {
public Config(JavaPlugin plugin, String configName, String folderName) {
this.plugin = plugin;
this.configName = (folderName == null ? "" : folderName + File.separator) + configName; // managers/config.yml
this.file = new File(plugin.getDataFolder(), (folderName == null ? "" : File.separator) + this.configName); // plugins/Plugin/managers/config.yml
this.configName = (folderName == null ? "" : folderName + File.separator) + configName;
this.file = new File(plugin.getDataFolder(), (folderName == null ? "" : File.separator) + this.configName);
this.saveDefaultConfig();
}

View File

@ -3,8 +3,3 @@ influxdb:
token: "aetheria"
org: "aetheria"
bucket: "aetheria"
help-command:
- "&e/help &7- &fShows this help message"
- "&e/kill &7- &fKills you"
- "&e/worldsize &7- &fShows the total file size of all worlds"

View File

@ -0,0 +1,6 @@
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"

View File

@ -18,3 +18,6 @@ commands:
playercolor:
description: "Changes your player color"
usage: "/playercolor <color>"
seed:
description: "Shows the seed of the world"
usage: "/seed"