Implemented permanent display names finally. New minor version reached.
This commit is contained in:
parent
25a99b8a3c
commit
c905e8db77
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>de.privacynerd</groupId>
|
||||
<artifactId>ChatBeautifier</artifactId>
|
||||
<version>0.2.4</version>
|
||||
<version>0.3.0</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>ChatBeautifier</name>
|
||||
|
@ -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()));
|
||||
}
|
||||
}
|
||||
|
@ -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: ")
|
||||
|
@ -0,0 +1,5 @@
|
||||
package de.privacynerd.chatbeautifier.utils;
|
||||
|
||||
public class ConfigFilenames {
|
||||
public static final String chatNameColors = "chatnamecolors.yml";
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
BIN
target/ChatBeautifier-0.3.0.jar
Normal file
BIN
target/ChatBeautifier-0.3.0.jar
Normal file
Binary file not shown.
BIN
target/original-ChatBeautifier-0.3.0.jar
Normal file
BIN
target/original-ChatBeautifier-0.3.0.jar
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user