diff --git a/src/main/java/cc/fascinated/account/Account.java b/src/main/java/cc/fascinated/account/Account.java index 354285e..443cff5 100644 --- a/src/main/java/cc/fascinated/account/Account.java +++ b/src/main/java/cc/fascinated/account/Account.java @@ -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")); diff --git a/src/main/java/cc/fascinated/command/CommandManager.java b/src/main/java/cc/fascinated/command/CommandManager.java index 0f02891..58c89d1 100644 --- a/src/main/java/cc/fascinated/command/CommandManager.java +++ b/src/main/java/cc/fascinated/command/CommandManager.java @@ -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); } } diff --git a/src/main/java/cc/fascinated/command/impl/HelpCommand.java b/src/main/java/cc/fascinated/command/impl/HelpCommand.java index 5a3ea55..cfd69c0 100644 --- a/src/main/java/cc/fascinated/command/impl/HelpCommand.java +++ b/src/main/java/cc/fascinated/command/impl/HelpCommand.java @@ -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)); } } } diff --git a/src/main/java/cc/fascinated/command/impl/SeedCommand.java b/src/main/java/cc/fascinated/command/impl/SeedCommand.java new file mode 100644 index 0000000..91587c2 --- /dev/null +++ b/src/main/java/cc/fascinated/command/impl/SeedCommand.java @@ -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()))) + ); + } +} diff --git a/src/main/java/cc/fascinated/config/Lang.java b/src/main/java/cc/fascinated/config/Lang.java new file mode 100644 index 0000000..0067f34 --- /dev/null +++ b/src/main/java/cc/fascinated/config/Lang.java @@ -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 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 getAsStringList() { + return (List) get(); + } +} diff --git a/src/main/java/cc/fascinated/metrics/Metric.java b/src/main/java/cc/fascinated/metrics/Metric.java index b8b064a..a8c1afc 100644 --- a/src/main/java/cc/fascinated/metrics/Metric.java +++ b/src/main/java/cc/fascinated/metrics/Metric.java @@ -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; } /** diff --git a/src/main/java/cc/fascinated/metrics/impl/server/EntityCountMetric.java b/src/main/java/cc/fascinated/metrics/impl/server/EntityCountMetric.java index 501ac28..d1678f1 100644 --- a/src/main/java/cc/fascinated/metrics/impl/server/EntityCountMetric.java +++ b/src/main/java/cc/fascinated/metrics/impl/server/EntityCountMetric.java @@ -11,7 +11,7 @@ import java.util.Map; public class EntityCountMetric extends Metric { public EntityCountMetric() { - super("entity_count", true); + super("entity_count"); } @Override diff --git a/src/main/java/cc/fascinated/metrics/impl/server/LoadedChunksMetric.java b/src/main/java/cc/fascinated/metrics/impl/server/LoadedChunksMetric.java index 6de4057..b293be8 100644 --- a/src/main/java/cc/fascinated/metrics/impl/server/LoadedChunksMetric.java +++ b/src/main/java/cc/fascinated/metrics/impl/server/LoadedChunksMetric.java @@ -11,7 +11,7 @@ import java.util.Map; public class LoadedChunksMetric extends Metric { public LoadedChunksMetric() { - super("loaded_chunks", true); + super("loaded_chunks"); } @Override diff --git a/src/main/java/cc/fascinated/utils/ChatUtils.java b/src/main/java/cc/fascinated/utils/ChatUtils.java new file mode 100644 index 0000000..50b48f3 --- /dev/null +++ b/src/main/java/cc/fascinated/utils/ChatUtils.java @@ -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("&", "§"); + } +} diff --git a/src/main/java/cc/fascinated/utils/io/Config.java b/src/main/java/cc/fascinated/utils/io/Config.java index 8402733..abbc75a 100644 --- a/src/main/java/cc/fascinated/utils/io/Config.java +++ b/src/main/java/cc/fascinated/utils/io/Config.java @@ -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(); } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index e540806..9d59628 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -2,9 +2,4 @@ influxdb: url: "http://localhost:8086" 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" \ No newline at end of file + bucket: "aetheria" \ No newline at end of file diff --git a/src/main/resources/lang.yml b/src/main/resources/lang.yml new file mode 100644 index 0000000..5eb0cfb --- /dev/null +++ b/src/main/resources/lang.yml @@ -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" diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 67894ba..aa732fd 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -17,4 +17,7 @@ commands: usage: "/help" playercolor: description: "Changes your player color" - usage: "/playercolor " \ No newline at end of file + usage: "/playercolor " + seed: + description: "Shows the seed of the world" + usage: "/seed" \ No newline at end of file