Compare commits

..

2 Commits
0.2.4 ... main

11 changed files with 152 additions and 42 deletions

View File

@ -6,7 +6,7 @@
<groupId>de.privacynerd</groupId> <groupId>de.privacynerd</groupId>
<artifactId>ChatBeautifier</artifactId> <artifactId>ChatBeautifier</artifactId>
<version>0.2.4</version> <version>0.3.1</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>ChatBeautifier</name> <name>ChatBeautifier</name>

View File

@ -1,5 +1,6 @@
package de.privacynerd.chatbeautifier; package de.privacynerd.chatbeautifier;
import de.privacynerd.chatbeautifier.utils.DisplayNameSetter;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration; import net.kyori.adventure.text.format.TextDecoration;
@ -16,25 +17,8 @@ public class JoinQuitListener implements Listener {
@EventHandler @EventHandler
public void onPlayerJoin(PlayerJoinEvent event) { public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
Component newName;
if(player.isOp()) { DisplayNameSetter.setName(player); // set display name according to color config etc...
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);
}
event.joinMessage(Component.text(">> ") event.joinMessage(Component.text(">> ")
.color(NamedTextColor.GREEN) .color(NamedTextColor.GREEN)
@ -48,11 +32,10 @@ public class JoinQuitListener implements Listener {
@EventHandler @EventHandler
public void onPlayerQuit(PlayerQuitEvent event) { public void onPlayerQuit(PlayerQuitEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
Component displayName = player.displayName();
event.quitMessage(Component.text("<< ") event.quitMessage(Component.text("<< ")
.color(NamedTextColor.RED) .color(NamedTextColor.RED)
.decoration(TextDecoration.BOLD, true) .decoration(TextDecoration.BOLD, true)
.append(displayName)); .append(player.displayName()));
} }
} }

View File

@ -1,6 +1,9 @@
package de.privacynerd.chatbeautifier.displaynamecolor; package de.privacynerd.chatbeautifier.displaynamecolor;
import de.privacynerd.chatbeautifier.ChatBeautifier; 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.Component;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration; import net.kyori.adventure.text.format.TextDecoration;
@ -23,7 +26,7 @@ public class ChatColorCommand implements CommandExecutor {
} }
Player player = (Player) commandSender; Player player = (Player) commandSender;
String validArgument = ""; String validArgument = "";
Component newDisplayName; Component newName;
int colorCodesListIndex; // stores the index of the color code which was requested (0 for black color code, ...) int colorCodesListIndex; // stores the index of the color code which was requested (0 for black color code, ...)
// check for the right args // check for the right args
@ -122,20 +125,13 @@ public class ChatColorCommand implements CommandExecutor {
return true; return true;
} }
if(player.isOp()) { // save the selected color to the file
newDisplayName = Component.text("[OP] ") FileConfig chatColorConfig = new FileConfig(ConfigFilenames.chatNameColors);
.color(NamedTextColor.RED) chatColorConfig.set(String.valueOf(player.getUniqueId().toString()), colorCodesListIndex);
.decoration(TextDecoration.BOLD, true) chatColorConfig.saveConfig();
.append(Component.text(player.getName())
.color(ChatColorUtils.getChooseColorCodes().get(colorCodesListIndex)) // update name (this method respects color values in the file
.decoration(TextDecoration.BOLD, false) DisplayNameSetter.setName(player);
);
} else {
newDisplayName = player.displayName()
.color(ChatColorUtils.getChooseColorCodes().get(colorCodesListIndex));
}
player.displayName(newDisplayName);
player.playerListName(newDisplayName);
ChatBeautifier.INSTANCE.log("Got valid color " + validArgument); ChatBeautifier.INSTANCE.log("Got valid color " + validArgument);
ChatBeautifier.INSTANCE.tellPlayer(Component.text("Dein neuer Name: ") ChatBeautifier.INSTANCE.tellPlayer(Component.text("Dein neuer Name: ")

View File

@ -1,12 +1,16 @@
package de.privacynerd.chatbeautifier.displaynamecolor; package de.privacynerd.chatbeautifier.displaynamecolor;
import de.privacynerd.chatbeautifier.utils.ConfigFilenames;
import de.privacynerd.chatbeautifier.utils.FileConfig;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextColor; import net.kyori.adventure.text.format.TextColor;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import de.privacynerd.chatbeautifier.displaynamecolor.ChatColorUtils; import de.privacynerd.chatbeautifier.displaynamecolor.ChatColorUtils;
@ -18,6 +22,11 @@ public class ChooseChatColorGUI {
public Inventory getGUI(Player player) { public Inventory getGUI(Player player) {
Inventory gui = Bukkit.createInventory(player, 45, Component.text("Set chat color (0x01)", NamedTextColor.DARK_GRAY)); Inventory gui = Bukkit.createInventory(player, 45, Component.text("Set chat color (0x01)", NamedTextColor.DARK_GRAY));
int currentColorCodesIndex = -1;
FileConfig chatColorConfig = new FileConfig(ConfigFilenames.chatNameColors);
String uuidStr = player.getUniqueId().toString();
if ( chatColorConfig.contains(uuidStr) ) currentColorCodesIndex = chatColorConfig.getInt(uuidStr);
// create item stacks to be filled into the gui later // create item stacks to be filled into the gui later
ItemStack nothing = new ItemStack(Material.LIGHT_BLUE_STAINED_GLASS_PANE); // for filling the gaps ItemStack nothing = new ItemStack(Material.LIGHT_BLUE_STAINED_GLASS_PANE); // for filling the gaps
@ -26,7 +35,7 @@ public class ChooseChatColorGUI {
ArrayList<TextColor> chooseColorCodes = ChatColorUtils.getChooseColorCodes(); ArrayList<TextColor> chooseColorCodes = ChatColorUtils.getChooseColorCodes();
for (int i=0; i<15; i++) { for (int i=0; i<15; i++) {
ItemMeta color_meta = nothing.getItemMeta(); ItemMeta color_meta = chooseColorItems.get(i).getItemMeta();
if(i==0) { // make it the black text readable if(i==0) { // make it the black text readable
color_meta.displayName(Component.text(chooseColorNames.get(i), NamedTextColor.WHITE)); color_meta.displayName(Component.text(chooseColorNames.get(i), NamedTextColor.WHITE));
} else { } else {
@ -50,12 +59,51 @@ public class ChooseChatColorGUI {
} }
for (int i=38; i<45; i++) { gui.setItem(i, nothing); } for (int i=38; i<45; i++) { gui.setItem(i, nothing); }
// now fill the actual selectables
int i1, i2, i3, i4, i5; // indexes
ItemStack is1, is2, is3, is4, is5; // the item stacks
ItemMeta itemMeta; // just to declare it here and fill it later
for(int i=0; i<3; i++) { for(int i=0; i<3; i++) {
gui.setItem(11 + (8 * i) + i, chooseColorItems.get((4 * i) + i)); i1 = (4 * i) + i; is1 = chooseColorItems.get(i1);
gui.setItem(11 + (8 * i) + i +1, chooseColorItems.get((4 * i) + i +1)); i2 = i1 + 1; is2 = chooseColorItems.get(i2);
gui.setItem(11 + (8 * i) + i +2, chooseColorItems.get((4 * i) + i +2)); i3 = i1 + 2; is3 = chooseColorItems.get(i3);
gui.setItem(11 + (8 * i) + i +3, chooseColorItems.get((4 * i) + i +3)); i4 = i1 + 3; is4 = chooseColorItems.get(i4);
gui.setItem(11 + (8 * i) + i +4, chooseColorItems.get((4 * i) + i +4)); i5 = i1 + 4; is5 = chooseColorItems.get(i5);
if(i1 == currentColorCodesIndex) {
itemMeta = is1.getItemMeta();
itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
itemMeta.addEnchant(Enchantment.THORNS, 1, true);
is1.setItemMeta(itemMeta);
}
if(i2 == currentColorCodesIndex) {
itemMeta = is2.getItemMeta();
itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
itemMeta.addEnchant(Enchantment.THORNS, 1, true);
is2.setItemMeta(itemMeta);
}
if(i3 == currentColorCodesIndex) {
itemMeta = is3.getItemMeta();
itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
itemMeta.addEnchant(Enchantment.THORNS, 1, true);
is3.setItemMeta(itemMeta);
}
if(i4 == currentColorCodesIndex) {
itemMeta = is4.getItemMeta();
itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
itemMeta.addEnchant(Enchantment.THORNS, 1, true);
is4.setItemMeta(itemMeta);
}
if(i5 == currentColorCodesIndex) {
itemMeta = is5.getItemMeta();
itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
itemMeta.addEnchant(Enchantment.THORNS, 1, true);
is5.setItemMeta(itemMeta);
}
gui.setItem(11 + (8 * i) + i, is1);
gui.setItem(11 + (8 * i) + i +1, is2);
gui.setItem(11 + (8 * i) + i +2, is3);
gui.setItem(11 + (8 * i) + i +3, is4);
gui.setItem(11 + (8 * i) + i +4, is5);
} }
return gui; return gui;

View File

@ -0,0 +1,5 @@
package de.privacynerd.chatbeautifier.utils;
public class ConfigFilenames {
public static final String chatNameColors = "chatnamecolors.yml";
}

View File

@ -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);
}
}

View File

@ -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();
}
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.