Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
6423fb0d68 | |||
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.1</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: ")
|
||||
|
@ -1,12 +1,16 @@
|
||||
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.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import de.privacynerd.chatbeautifier.displaynamecolor.ChatColorUtils;
|
||||
@ -18,6 +22,11 @@ public class ChooseChatColorGUI {
|
||||
public Inventory getGUI(Player player) {
|
||||
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
|
||||
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();
|
||||
|
||||
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
|
||||
color_meta.displayName(Component.text(chooseColorNames.get(i), NamedTextColor.WHITE));
|
||||
} else {
|
||||
@ -50,12 +59,51 @@ public class ChooseChatColorGUI {
|
||||
}
|
||||
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++) {
|
||||
gui.setItem(11 + (8 * i) + i, chooseColorItems.get((4 * i) + i));
|
||||
gui.setItem(11 + (8 * i) + i +1, chooseColorItems.get((4 * i) + i +1));
|
||||
gui.setItem(11 + (8 * i) + i +2, chooseColorItems.get((4 * i) + i +2));
|
||||
gui.setItem(11 + (8 * i) + i +3, chooseColorItems.get((4 * i) + i +3));
|
||||
gui.setItem(11 + (8 * i) + i +4, chooseColorItems.get((4 * i) + i +4));
|
||||
i1 = (4 * i) + i; is1 = chooseColorItems.get(i1);
|
||||
i2 = i1 + 1; is2 = chooseColorItems.get(i2);
|
||||
i3 = i1 + 2; is3 = chooseColorItems.get(i3);
|
||||
i4 = i1 + 3; is4 = chooseColorItems.get(i4);
|
||||
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;
|
||||
|
@ -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/ChatBeautifier-0.3.1.jar
Normal file
BIN
target/ChatBeautifier-0.3.1.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.
BIN
target/original-ChatBeautifier-0.3.1.jar
Normal file
BIN
target/original-ChatBeautifier-0.3.1.jar
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user