From 00e78bfb14ae46acf51801047f1eb97aefdda16e Mon Sep 17 00:00:00 2001 From: Lukiiy <102190774+Lukiiy@users.noreply.github.com> Date: Wed, 3 Apr 2024 15:52:34 -0300 Subject: [PATCH] v1.1 - Configuration Update! Added config.yml and a ingame way to reload it (/niceformat). --- src/main/java/me/lukiiy/niceformat/Chat.java | 5 ++--- .../java/me/lukiiy/niceformat/ReloadCMD.java | 14 +++++++++++++ src/main/java/me/lukiiy/niceformat/main.java | 20 ++++++++++++++++++- src/main/resources/plugin.yml | 6 +++++- 4 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 src/main/java/me/lukiiy/niceformat/ReloadCMD.java diff --git a/src/main/java/me/lukiiy/niceformat/Chat.java b/src/main/java/me/lukiiy/niceformat/Chat.java index 0d85449..836ac27 100644 --- a/src/main/java/me/lukiiy/niceformat/Chat.java +++ b/src/main/java/me/lukiiy/niceformat/Chat.java @@ -4,9 +4,8 @@ import org.bukkit.event.player.PlayerListener; public class Chat extends PlayerListener { - public void onPlayerChat(PlayerChatEvent e) { - e.setMessage(e.getMessage().replace('&', '§')); // Chat Colr - e.setFormat("%1$s: %2$s"); // Format + if (main.Color) e.setMessage(e.getMessage().replace('&', '§')); + e.setFormat(main.Format); } } diff --git a/src/main/java/me/lukiiy/niceformat/ReloadCMD.java b/src/main/java/me/lukiiy/niceformat/ReloadCMD.java new file mode 100644 index 0000000..e1a2801 --- /dev/null +++ b/src/main/java/me/lukiiy/niceformat/ReloadCMD.java @@ -0,0 +1,14 @@ +package me.lukiiy.niceformat; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; + +public class ReloadCMD implements CommandExecutor { + @Override + public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) { + main.Plugin.config(); + commandSender.sendMessage("§aNiceFormat Reload complete."); + return true; + } +} diff --git a/src/main/java/me/lukiiy/niceformat/main.java b/src/main/java/me/lukiiy/niceformat/main.java index 7eef173..4d10250 100644 --- a/src/main/java/me/lukiiy/niceformat/main.java +++ b/src/main/java/me/lukiiy/niceformat/main.java @@ -4,9 +4,27 @@ import org.bukkit.plugin.java.JavaPlugin; public class main extends JavaPlugin { + public static main Plugin; + public static boolean Color = true; + public static String Format = "%1$s: %2$s"; + @Override - public void onEnable() {getServer().getPluginManager().registerEvent(Event.Type.PLAYER_CHAT, new Chat(), Event.Priority.Lowest, this);} + public void onEnable() { + Plugin = this; + getServer().getPluginManager().registerEvent(Event.Type.PLAYER_CHAT, new Chat(), Event.Priority.Lowest, this); + getCommand("niceformat").setExecutor(new ReloadCMD()); + config(); + } @Override public void onDisable() {} + + public void config() { + getConfiguration().load(); + Color = getConfiguration().getBoolean("color", Color); + Format = getConfiguration().getString("format", Format) + .replace("(p)", "%1$s") + .replace("(msg)", "%2$s"); + getConfiguration().save(); + } } \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 45ee434..00c901e 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,4 +1,8 @@ name: NiceFormat version: '${project.version}' main: me.lukiiy.niceformat.main -author: Lukiiy \ No newline at end of file +author: Lukiiy +commands: + niceformat: + description: "Reloads the plugin" + permission: niceformat.reload \ No newline at end of file