start migration to lang file
This commit is contained in:
@ -76,6 +76,8 @@ public class Account {
|
|||||||
this.firstJoin = config.getLong("firstJoin");
|
this.firstJoin = config.getLong("firstJoin");
|
||||||
this.lastLogin = config.getLong("lastLogin");
|
this.lastLogin = config.getLong("lastLogin");
|
||||||
|
|
||||||
|
this.lastLogin = System.currentTimeMillis(); // Update last login
|
||||||
|
|
||||||
// Load profiles
|
// Load profiles
|
||||||
this.playerColorProfile = new PlayerColor(this, this.getProfileSection("playerColor"));
|
this.playerColorProfile = new PlayerColor(this, this.getProfileSection("playerColor"));
|
||||||
|
|
||||||
|
@ -2,21 +2,26 @@ package cc.fascinated.command;
|
|||||||
|
|
||||||
import cc.fascinated.Aetheria;
|
import cc.fascinated.Aetheria;
|
||||||
import cc.fascinated.command.impl.HelpCommand;
|
import cc.fascinated.command.impl.HelpCommand;
|
||||||
|
import cc.fascinated.command.impl.SeedCommand;
|
||||||
import cc.fascinated.command.impl.TotalJoinsCommand;
|
import cc.fascinated.command.impl.TotalJoinsCommand;
|
||||||
|
import org.bukkit.command.PluginCommand;
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public class CommandManager {
|
public class CommandManager {
|
||||||
|
|
||||||
public CommandManager() {
|
public CommandManager() {
|
||||||
registerCommand(new TotalJoinsCommand());
|
registerCommand(new TotalJoinsCommand());
|
||||||
registerCommand(new HelpCommand());
|
registerCommand(new HelpCommand());
|
||||||
|
registerCommand(new SeedCommand());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void registerCommand(Command command) {
|
public static void registerCommand(Command command) {
|
||||||
if (command == null) {
|
if (command == null) {
|
||||||
throw new IllegalArgumentException("Command cannot be 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
package cc.fascinated.command.impl;
|
package cc.fascinated.command.impl;
|
||||||
|
|
||||||
import cc.fascinated.Aetheria;
|
|
||||||
import cc.fascinated.account.Account;
|
import cc.fascinated.account.Account;
|
||||||
import cc.fascinated.command.Command;
|
import cc.fascinated.command.Command;
|
||||||
|
import cc.fascinated.config.Lang;
|
||||||
import java.util.Objects;
|
import cc.fascinated.utils.ChatUtils;
|
||||||
|
|
||||||
public class HelpCommand extends Command {
|
public class HelpCommand extends Command {
|
||||||
|
|
||||||
@ -14,9 +13,8 @@ public class HelpCommand extends Command {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(Account account, String[] args) {
|
public void execute(Account account, String[] args) {
|
||||||
account.sendMessage("§6§lAetheria §7» §fCommands:");
|
for (String line : Lang.HELP_COMMAND.getAsStringList()) {
|
||||||
for (String line : Objects.requireNonNull(Aetheria.INSTANCE.getConfig().getStringList("help-command"))) {
|
account.sendMessage(ChatUtils.color(line));
|
||||||
account.sendMessage(" " + line.replaceAll("&", "§"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
21
src/main/java/cc/fascinated/command/impl/SeedCommand.java
Normal file
21
src/main/java/cc/fascinated/command/impl/SeedCommand.java
Normal 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())))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
67
src/main/java/cc/fascinated/config/Lang.java
Normal file
67
src/main/java/cc/fascinated/config/Lang.java
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
@ -10,18 +10,8 @@ public abstract class Metric {
|
|||||||
*/
|
*/
|
||||||
private final String name;
|
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) {
|
public Metric(String name) {
|
||||||
this(name, true);
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -11,7 +11,7 @@ import java.util.Map;
|
|||||||
public class EntityCountMetric extends Metric {
|
public class EntityCountMetric extends Metric {
|
||||||
|
|
||||||
public EntityCountMetric() {
|
public EntityCountMetric() {
|
||||||
super("entity_count", true);
|
super("entity_count");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -11,7 +11,7 @@ import java.util.Map;
|
|||||||
public class LoadedChunksMetric extends Metric {
|
public class LoadedChunksMetric extends Metric {
|
||||||
|
|
||||||
public LoadedChunksMetric() {
|
public LoadedChunksMetric() {
|
||||||
super("loaded_chunks", true);
|
super("loaded_chunks");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
14
src/main/java/cc/fascinated/utils/ChatUtils.java
Normal file
14
src/main/java/cc/fascinated/utils/ChatUtils.java
Normal 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("&", "§");
|
||||||
|
}
|
||||||
|
}
|
@ -21,8 +21,8 @@ public class Config {
|
|||||||
|
|
||||||
public Config(JavaPlugin plugin, String configName, String folderName) {
|
public Config(JavaPlugin plugin, String configName, String folderName) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.configName = (folderName == null ? "" : folderName + File.separator) + configName; // managers/config.yml
|
this.configName = (folderName == null ? "" : folderName + File.separator) + configName;
|
||||||
this.file = new File(plugin.getDataFolder(), (folderName == null ? "" : File.separator) + this.configName); // plugins/Plugin/managers/config.yml
|
this.file = new File(plugin.getDataFolder(), (folderName == null ? "" : File.separator) + this.configName);
|
||||||
this.saveDefaultConfig();
|
this.saveDefaultConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,8 +3,3 @@ influxdb:
|
|||||||
token: "aetheria"
|
token: "aetheria"
|
||||||
org: "aetheria"
|
org: "aetheria"
|
||||||
bucket: "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"
|
|
6
src/main/resources/lang.yml
Normal file
6
src/main/resources/lang.yml
Normal 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"
|
@ -18,3 +18,6 @@ commands:
|
|||||||
playercolor:
|
playercolor:
|
||||||
description: "Changes your player color"
|
description: "Changes your player color"
|
||||||
usage: "/playercolor <color>"
|
usage: "/playercolor <color>"
|
||||||
|
seed:
|
||||||
|
description: "Shows the seed of the world"
|
||||||
|
usage: "/seed"
|
Reference in New Issue
Block a user