diff --git a/pom.xml b/pom.xml
index 478238a..2572f41 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
de.privacynerd
ChatBeautifier
- 0.2.4
+ 0.3.0
jar
ChatBeautifier
diff --git a/src/main/java/de/privacynerd/chatbeautifier/JoinQuitListener.java b/src/main/java/de/privacynerd/chatbeautifier/JoinQuitListener.java
index 3d434eb..1022c35 100644
--- a/src/main/java/de/privacynerd/chatbeautifier/JoinQuitListener.java
+++ b/src/main/java/de/privacynerd/chatbeautifier/JoinQuitListener.java
@@ -1,5 +1,6 @@
package de.privacynerd.chatbeautifier;
+import de.privacynerd.chatbeautifier.utils.DisplayNameSetter;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration;
@@ -16,25 +17,8 @@ public class JoinQuitListener implements Listener {
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
- Component newName;
- if(player.isOp()) {
- newName = Component.text("[OP] ")
- .color(NamedTextColor.RED)
- .decoration(TextDecoration.BOLD, true)
- .append(Component.text(player.getName())
- .color(NamedTextColor.GRAY)
- .decoration(TextDecoration.BOLD, false)
- );
- player.displayName(newName);
- player.playerListName(newName);
- } else {
- newName = Component.text(player.getName())
- .color(NamedTextColor.GRAY)
- .decoration(TextDecoration.BOLD, false);
- player.displayName(newName);
- player.playerListName(newName);
- }
+ DisplayNameSetter.setName(player); // set display name according to color config etc...
event.joinMessage(Component.text(">> ")
.color(NamedTextColor.GREEN)
@@ -48,11 +32,10 @@ public class JoinQuitListener implements Listener {
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
Player player = event.getPlayer();
- Component displayName = player.displayName();
event.quitMessage(Component.text("<< ")
.color(NamedTextColor.RED)
.decoration(TextDecoration.BOLD, true)
- .append(displayName));
+ .append(player.displayName()));
}
}
diff --git a/src/main/java/de/privacynerd/chatbeautifier/displaynamecolor/ChatColorCommand.java b/src/main/java/de/privacynerd/chatbeautifier/displaynamecolor/ChatColorCommand.java
index 59e7334..043703d 100644
--- a/src/main/java/de/privacynerd/chatbeautifier/displaynamecolor/ChatColorCommand.java
+++ b/src/main/java/de/privacynerd/chatbeautifier/displaynamecolor/ChatColorCommand.java
@@ -1,6 +1,9 @@
package de.privacynerd.chatbeautifier.displaynamecolor;
import de.privacynerd.chatbeautifier.ChatBeautifier;
+import de.privacynerd.chatbeautifier.utils.ConfigFilenames;
+import de.privacynerd.chatbeautifier.utils.DisplayNameSetter;
+import de.privacynerd.chatbeautifier.utils.FileConfig;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration;
@@ -23,7 +26,7 @@ public class ChatColorCommand implements CommandExecutor {
}
Player player = (Player) commandSender;
String validArgument = "";
- Component newDisplayName;
+ Component newName;
int colorCodesListIndex; // stores the index of the color code which was requested (0 for black color code, ...)
// check for the right args
@@ -122,20 +125,13 @@ public class ChatColorCommand implements CommandExecutor {
return true;
}
- if(player.isOp()) {
- newDisplayName = Component.text("[OP] ")
- .color(NamedTextColor.RED)
- .decoration(TextDecoration.BOLD, true)
- .append(Component.text(player.getName())
- .color(ChatColorUtils.getChooseColorCodes().get(colorCodesListIndex))
- .decoration(TextDecoration.BOLD, false)
- );
- } else {
- newDisplayName = player.displayName()
- .color(ChatColorUtils.getChooseColorCodes().get(colorCodesListIndex));
- }
- player.displayName(newDisplayName);
- player.playerListName(newDisplayName);
+ // save the selected color to the file
+ FileConfig chatColorConfig = new FileConfig(ConfigFilenames.chatNameColors);
+ chatColorConfig.set(String.valueOf(player.getUniqueId().toString()), colorCodesListIndex);
+ chatColorConfig.saveConfig();
+
+ // update name (this method respects color values in the file
+ DisplayNameSetter.setName(player);
ChatBeautifier.INSTANCE.log("Got valid color " + validArgument);
ChatBeautifier.INSTANCE.tellPlayer(Component.text("Dein neuer Name: ")
diff --git a/src/main/java/de/privacynerd/chatbeautifier/utils/ConfigFilenames.java b/src/main/java/de/privacynerd/chatbeautifier/utils/ConfigFilenames.java
new file mode 100644
index 0000000..8f76d9c
--- /dev/null
+++ b/src/main/java/de/privacynerd/chatbeautifier/utils/ConfigFilenames.java
@@ -0,0 +1,5 @@
+package de.privacynerd.chatbeautifier.utils;
+
+public class ConfigFilenames {
+ public static final String chatNameColors = "chatnamecolors.yml";
+}
diff --git a/src/main/java/de/privacynerd/chatbeautifier/utils/DisplayNameSetter.java b/src/main/java/de/privacynerd/chatbeautifier/utils/DisplayNameSetter.java
new file mode 100644
index 0000000..4816ae5
--- /dev/null
+++ b/src/main/java/de/privacynerd/chatbeautifier/utils/DisplayNameSetter.java
@@ -0,0 +1,46 @@
+package de.privacynerd.chatbeautifier.utils;
+
+import de.privacynerd.chatbeautifier.displaynamecolor.ChatColorUtils;
+import net.kyori.adventure.text.Component;
+import net.kyori.adventure.text.format.NamedTextColor;
+import net.kyori.adventure.text.format.TextColor;
+import net.kyori.adventure.text.format.TextDecoration;
+import org.bukkit.entity.Player;
+
+public class DisplayNameSetter {
+ public static void setName(Player player, Component newName) {
+ player.displayName(newName);
+ player.playerListName(newName);
+ }
+
+ public static void setName(Player player) {
+ Component newName;
+ TextColor textColor = NamedTextColor.GRAY; // default to gray
+
+ // get a potentially saved color (set from /set-chat-color command)
+ FileConfig chatColorConfig = new FileConfig(ConfigFilenames.chatNameColors);
+ String UUID_String = player.getUniqueId().toString();
+ if ( chatColorConfig.contains(UUID_String) ) {
+ int colorIndex = chatColorConfig.getInt(UUID_String);
+ textColor = ChatColorUtils.getChooseColorCodes().get(colorIndex);
+ }
+
+ // now compose the name (distinguish between operators and normal players by a red, bold [OP] in the beginning
+ if(player.isOp()) {
+ newName = Component.text("[OP] ")
+ .color(NamedTextColor.RED)
+ .decoration(TextDecoration.BOLD, true)
+ .append(Component.text(player.getName())
+ .color(textColor)
+ .decoration(TextDecoration.BOLD, false)
+ );
+ } else {
+ newName = Component.text(player.getName())
+ .color(textColor)
+ .decoration(TextDecoration.BOLD, false);
+ }
+
+ // now set the name as display and list name
+ setName(player, newName);
+ }
+}
diff --git a/src/main/java/de/privacynerd/chatbeautifier/utils/FileConfig.java b/src/main/java/de/privacynerd/chatbeautifier/utils/FileConfig.java
new file mode 100644
index 0000000..c545012
--- /dev/null
+++ b/src/main/java/de/privacynerd/chatbeautifier/utils/FileConfig.java
@@ -0,0 +1,32 @@
+package de.privacynerd.chatbeautifier.utils;
+
+import org.bukkit.configuration.InvalidConfigurationException;
+import org.bukkit.configuration.file.YamlConfiguration;
+import java.io.IOException;
+
+public class FileConfig extends YamlConfiguration {
+ private final String path;
+
+ public FileConfig(String folder, String filename) {
+ this.path = "plugins/ChatBeautifier/" + folder + "/" + filename;
+
+ try {
+ load(this.path);
+ } catch (InvalidConfigurationException | IOException ex) {
+ ex.printStackTrace();
+ }
+ }
+
+ public FileConfig(String filename) {
+ this(".", filename);
+ }
+
+ public void saveConfig() {
+ try {
+ save(this.path);
+ } catch (IOException ex){
+ ex.printStackTrace();
+ }
+ }
+
+}
diff --git a/target/ChatBeautifier-0.3.0.jar b/target/ChatBeautifier-0.3.0.jar
new file mode 100644
index 0000000..ae5fdd9
Binary files /dev/null and b/target/ChatBeautifier-0.3.0.jar differ
diff --git a/target/original-ChatBeautifier-0.3.0.jar b/target/original-ChatBeautifier-0.3.0.jar
new file mode 100644
index 0000000..a090f78
Binary files /dev/null and b/target/original-ChatBeautifier-0.3.0.jar differ