Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
6423fb0d68 | |||
c905e8db77 | |||
25a99b8a3c | |||
eb429dfaed |
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>de.privacynerd</groupId>
|
<groupId>de.privacynerd</groupId>
|
||||||
<artifactId>ChatBeautifier</artifactId>
|
<artifactId>ChatBeautifier</artifactId>
|
||||||
<version>0.2.2</version>
|
<version>0.3.1</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>ChatBeautifier</name>
|
<name>ChatBeautifier</name>
|
||||||
|
@ -2,21 +2,28 @@ package de.privacynerd.chatbeautifier;
|
|||||||
|
|
||||||
import de.privacynerd.chatbeautifier.displaynamecolor.ChatColorCommand;
|
import de.privacynerd.chatbeautifier.displaynamecolor.ChatColorCommand;
|
||||||
import de.privacynerd.chatbeautifier.displaynamecolor.ChooseChatColorListener;
|
import de.privacynerd.chatbeautifier.displaynamecolor.ChooseChatColorListener;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
|
||||||
public final class ChatBeautifier extends JavaPlugin {
|
public final class ChatBeautifier extends JavaPlugin {
|
||||||
public static String PREFIX = "§a[ChatBeautifier] §7§o";
|
public static Component PREFIX = Component.text("[ChatBeautifier] ", NamedTextColor.DARK_AQUA);
|
||||||
public static ChatBeautifier INSTANCE;
|
public static ChatBeautifier INSTANCE;
|
||||||
|
|
||||||
public ChatBeautifier() {
|
public ChatBeautifier() {
|
||||||
INSTANCE = this;
|
INSTANCE = this;
|
||||||
}
|
}
|
||||||
public void log(String text) {
|
|
||||||
Bukkit.getConsoleSender().sendMessage(PREFIX + text);
|
// some log functions
|
||||||
}
|
public void log(String message) { Bukkit.getConsoleSender().sendMessage(PREFIX.append(Component.text(message, NamedTextColor.GRAY))); }
|
||||||
|
public void log(@NotNull Component message) { Bukkit.getConsoleSender().sendMessage(PREFIX.append(message.color(NamedTextColor.GRAY))); }
|
||||||
|
public void tellPlayer(String message, @NotNull Player player) { player.sendMessage(PREFIX.append(Component.text(message, NamedTextColor.GRAY))); }
|
||||||
|
public void tellPlayer(@NotNull Component message, @NotNull Player player) { player.sendMessage(PREFIX.append(message.color(NamedTextColor.GRAY))); }
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
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 org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
@ -15,19 +17,14 @@ 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] "+player.getName(), NamedTextColor.RED);
|
|
||||||
player.displayName(newName);
|
|
||||||
player.playerListName(newName);
|
|
||||||
} else {
|
|
||||||
newName = Component.text(player.getName(), NamedTextColor.GRAY);
|
|
||||||
player.displayName(Component.text(player.getName()));
|
|
||||||
player.playerListName(newName);
|
|
||||||
}
|
|
||||||
|
|
||||||
event.joinMessage(Component.text(">> ", NamedTextColor.GREEN).append(player.displayName()));
|
event.joinMessage(Component.text(">> ")
|
||||||
|
.color(NamedTextColor.GREEN)
|
||||||
|
.decoration(TextDecoration.BOLD, true)
|
||||||
|
.append(player.displayName()
|
||||||
|
));
|
||||||
player.playSound(player.getLocation(), Sound.AMBIENT_CRIMSON_FOREST_MOOD, 0.5f, 0.4f);
|
player.playSound(player.getLocation(), Sound.AMBIENT_CRIMSON_FOREST_MOOD, 0.5f, 0.4f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,6 +33,9 @@ public class JoinQuitListener implements Listener {
|
|||||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
event.quitMessage(Component.text("<< ", NamedTextColor.RED).append(player.displayName()));
|
event.quitMessage(Component.text("<< ")
|
||||||
|
.color(NamedTextColor.RED)
|
||||||
|
.decoration(TextDecoration.BOLD, true)
|
||||||
|
.append(player.displayName()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,12 @@
|
|||||||
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 org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@ -22,114 +26,94 @@ 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, ...)
|
||||||
|
|
||||||
// check for the right args
|
// check for the right args
|
||||||
if(args.length == 1) {
|
if(args.length == 1) {
|
||||||
switch (args[0]) {
|
switch (args[0]) {
|
||||||
case "black":
|
case "black":
|
||||||
validArgument = "black";
|
validArgument = "black";
|
||||||
newDisplayName = Component.text("", ChatColorUtils.getChooseColorCodes().get(1)).append(player.displayName());
|
colorCodesListIndex = 0;
|
||||||
player.displayName(newDisplayName);
|
|
||||||
player.playerListName(newDisplayName);
|
|
||||||
break;
|
break;
|
||||||
case "gray":
|
case "gray":
|
||||||
validArgument = "gray";
|
validArgument = "gray";
|
||||||
newDisplayName = player.displayName().color(ChatColorUtils.getChooseColorCodes().get(1));
|
colorCodesListIndex = 1;
|
||||||
player.displayName(newDisplayName);
|
|
||||||
player.playerListName(newDisplayName);
|
|
||||||
break;
|
break;
|
||||||
case "light-gray":
|
case "light-gray":
|
||||||
validArgument = "light-gray";
|
validArgument = "light-gray";
|
||||||
newDisplayName = player.displayName().color(ChatColorUtils.getChooseColorCodes().get(2));
|
colorCodesListIndex = 2;
|
||||||
player.displayName(newDisplayName);
|
|
||||||
player.playerListName(newDisplayName);
|
|
||||||
break;
|
break;
|
||||||
case "white":
|
case "white":
|
||||||
validArgument = "white";
|
validArgument = "white";
|
||||||
newDisplayName = player.displayName().color(ChatColorUtils.getChooseColorCodes().get(3));
|
colorCodesListIndex = 3;
|
||||||
player.displayName(newDisplayName);
|
|
||||||
player.playerListName(newDisplayName);
|
|
||||||
break;
|
break;
|
||||||
case "brown":
|
case "brown":
|
||||||
validArgument = "brown";
|
validArgument = "brown";
|
||||||
newDisplayName = player.displayName().color(ChatColorUtils.getChooseColorCodes().get(4));
|
colorCodesListIndex = 4;
|
||||||
player.displayName(newDisplayName);
|
|
||||||
player.playerListName(newDisplayName);
|
|
||||||
break;
|
break;
|
||||||
case "red":
|
case "red":
|
||||||
validArgument = "red";
|
validArgument = "red";
|
||||||
newDisplayName = player.displayName().color(ChatColorUtils.getChooseColorCodes().get(5));
|
colorCodesListIndex = 5;
|
||||||
player.displayName(newDisplayName);
|
|
||||||
player.playerListName(newDisplayName);
|
|
||||||
break;
|
break;
|
||||||
case "orange":
|
case "orange":
|
||||||
validArgument = "orange";
|
validArgument = "orange";
|
||||||
newDisplayName = player.displayName().color(ChatColorUtils.getChooseColorCodes().get(6));
|
colorCodesListIndex = 6;
|
||||||
player.displayName(newDisplayName);
|
|
||||||
player.playerListName(newDisplayName);
|
|
||||||
break;
|
break;
|
||||||
case "yellow":
|
case "yellow":
|
||||||
validArgument = "yellow";
|
validArgument = "yellow";
|
||||||
newDisplayName = player.displayName().color(ChatColorUtils.getChooseColorCodes().get(7));
|
colorCodesListIndex = 7;
|
||||||
player.displayName(newDisplayName);
|
|
||||||
player.playerListName(newDisplayName);
|
|
||||||
break;
|
break;
|
||||||
case "light-green":
|
case "light-green":
|
||||||
validArgument = "light-green";
|
validArgument = "light-green";
|
||||||
newDisplayName = player.displayName().color(ChatColorUtils.getChooseColorCodes().get(8));
|
colorCodesListIndex = 8;
|
||||||
player.displayName(newDisplayName);
|
|
||||||
player.playerListName(newDisplayName);
|
|
||||||
break;
|
break;
|
||||||
case "dark-green":
|
case "dark-green":
|
||||||
validArgument = "dark-green";
|
validArgument = "dark-green";
|
||||||
newDisplayName = player.displayName().color(ChatColorUtils.getChooseColorCodes().get(9));
|
colorCodesListIndex = 9;
|
||||||
player.displayName(newDisplayName);
|
|
||||||
player.playerListName(newDisplayName);
|
|
||||||
break;
|
break;
|
||||||
case "cyan":
|
case "cyan":
|
||||||
validArgument = "cyan";
|
validArgument = "cyan";
|
||||||
newDisplayName = player.displayName().color(ChatColorUtils.getChooseColorCodes().get(10));
|
colorCodesListIndex = 10;
|
||||||
player.displayName(newDisplayName);
|
|
||||||
player.playerListName(newDisplayName);
|
|
||||||
break;
|
break;
|
||||||
case "blue":
|
case "blue":
|
||||||
validArgument = "blue";
|
validArgument = "blue";
|
||||||
newDisplayName = player.displayName().color(ChatColorUtils.getChooseColorCodes().get(11));
|
colorCodesListIndex = 11;
|
||||||
player.displayName(newDisplayName);
|
|
||||||
player.playerListName(newDisplayName);
|
|
||||||
break;
|
break;
|
||||||
case "purple":
|
case "purple":
|
||||||
validArgument = "purple";
|
validArgument = "purple";
|
||||||
newDisplayName = player.displayName().color(ChatColorUtils.getChooseColorCodes().get(12));
|
colorCodesListIndex = 12;
|
||||||
player.displayName(newDisplayName);
|
|
||||||
player.playerListName(newDisplayName);
|
|
||||||
break;
|
break;
|
||||||
case "magenta":
|
case "magenta":
|
||||||
validArgument = "magenta";
|
validArgument = "magenta";
|
||||||
newDisplayName = player.displayName().color(ChatColorUtils.getChooseColorCodes().get(13));
|
colorCodesListIndex = 13;
|
||||||
player.displayName(newDisplayName);
|
|
||||||
player.playerListName(newDisplayName);
|
|
||||||
break;
|
break;
|
||||||
case "pink":
|
case "pink":
|
||||||
validArgument = "pink";
|
validArgument = "pink";
|
||||||
newDisplayName = player.displayName().color(ChatColorUtils.getChooseColorCodes().get(14));
|
colorCodesListIndex = 14;
|
||||||
player.displayName(newDisplayName);
|
|
||||||
player.playerListName(newDisplayName);
|
|
||||||
break;
|
break;
|
||||||
case "list":
|
case "list":
|
||||||
ChatBeautifier.INSTANCE.log("Got valid argument 'list', printing list of valid colors...");
|
ChatBeautifier.INSTANCE.log("Got valid argument 'list', printing list of valid colors...");
|
||||||
ArrayList<String> colorNames = ChatColorUtils.getChooseColorStrings();
|
ArrayList<String> colorNames = ChatColorUtils.getChooseColorStrings();
|
||||||
|
|
||||||
// now compose the message containing all possible color args
|
// now compose the message containing all possible color args
|
||||||
StringBuilder message = new StringBuilder(ChatBeautifier.PREFIX + "§r§lMögliche Farben: §r§o");
|
Component message = Component.text("Mögliche Farben: ")
|
||||||
message.append(colorNames.get(0).toLowerCase().replace(" ", "-")).append(", ");
|
.decoration(TextDecoration.BOLD, true);
|
||||||
|
|
||||||
|
String newMessageItem = colorNames.get(0).toLowerCase().replace(" ", "-");
|
||||||
|
message = message.append(Component.text(newMessageItem, NamedTextColor.GRAY)
|
||||||
|
.decoration(TextDecoration.BOLD, false)
|
||||||
|
.decoration(TextDecoration.ITALIC, true));
|
||||||
|
|
||||||
for (int i=1; i<colorNames.toArray().length; i++) {
|
for (int i=1; i<colorNames.toArray().length; i++) {
|
||||||
message.append(colorNames.get(i).toLowerCase().replace(" ", "-")).append(", ");
|
newMessageItem = ", " + colorNames.get(i).toLowerCase().replace(" ", "-");
|
||||||
|
message = message.append(Component.text(newMessageItem, NamedTextColor.GRAY)
|
||||||
|
.decoration(TextDecoration.BOLD, false)
|
||||||
|
.decoration(TextDecoration.ITALIC, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
// and send it
|
// and send it
|
||||||
player.sendMessage(message.toString());
|
ChatBeautifier.INSTANCE.tellPlayer(message, player);
|
||||||
return true;
|
return true;
|
||||||
case "gui":
|
case "gui":
|
||||||
ChatBeautifier.INSTANCE.log("Got valid argument 'gui', opening gui...");
|
ChatBeautifier.INSTANCE.log("Got valid argument 'gui', opening gui...");
|
||||||
@ -137,14 +121,25 @@ public class ChatColorCommand implements CommandExecutor {
|
|||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
// print a help string if no valid argument is given
|
// print a help string if no valid argument is given
|
||||||
player.sendMessage(ChatBeautifier.PREFIX + "Verwendung: /" + alias + " [<color>, list, gui]");
|
ChatBeautifier.INSTANCE.tellPlayer("Verwendung: /" + alias + " [<color>, list, gui]", player);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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.log("Got valid color " + validArgument);
|
||||||
player.sendMessage(ChatBeautifier.PREFIX + "Name temporär " + validArgument + " gefärbt. Dieses Feature ist aktuell noch in der Mache, dauerhaft coming soon.");
|
ChatBeautifier.INSTANCE.tellPlayer(Component.text("Dein neuer Name: ")
|
||||||
|
.append(player.displayName()
|
||||||
|
), player);
|
||||||
return true;
|
return true;
|
||||||
} else if (args.length > 1) { // print a help string if more than one argument is given
|
} else if (args.length > 1) { // print a help string if more than one argument is given
|
||||||
player.sendMessage(ChatBeautifier.PREFIX + "Verwendung: /" + alias + " [<color>, list, gui]");
|
ChatBeautifier.INSTANCE.tellPlayer("Verwendung: /" + alias + " [<color>, list, gui]", player);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
player.openInventory(new ChooseChatColorGUI().getGUI(player));
|
player.openInventory(new ChooseChatColorGUI().getGUI(player));
|
||||||
|
@ -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;
|
||||||
|
@ -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.2.3.jar
Normal file
BIN
target/ChatBeautifier-0.2.3.jar
Normal file
Binary file not shown.
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.2.3.jar
Normal file
BIN
target/original-ChatBeautifier-0.2.3.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