Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
6423fb0d68 | |||
c905e8db77 | |||
25a99b8a3c | |||
eb429dfaed | |||
4079f56a90 |
@ -13,6 +13,12 @@ Listeners that are implemented by this plugin:
|
||||
- PlayerQuitEvent (print a beautified quit message "<< PlayerName")
|
||||
- PlayerChatEvent (deprecated, but beautify chat messages "PlayerName: message")
|
||||
|
||||
|
||||
Commands implemented:
|
||||
|
||||
- set-chat-color: lets you set your name's color in the chat over a nice gui (or as a cmd!)
|
||||
- currently only temporary, static colors (staying the same after quit/join) coming soon!
|
||||
|
||||
And all that in beautiful colors!
|
||||
|
||||
|
||||
|
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>de.privacynerd</groupId>
|
||||
<artifactId>ChatBeautifier</artifactId>
|
||||
<version>0.2.1</version>
|
||||
<version>0.3.1</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>ChatBeautifier</name>
|
||||
|
@ -1,22 +1,29 @@
|
||||
package de.privacynerd.chatbeautifier;
|
||||
|
||||
import de.privacynerd.chatbeautifier.displaynamecolor.ChatColorCommand;
|
||||
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.entity.Player;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import de.privacynerd.chatbeautifier.commands.*;
|
||||
import de.privacynerd.chatbeautifier.guis.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
||||
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 ChatBeautifier() {
|
||||
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
|
||||
@ -27,8 +34,11 @@ public final class ChatBeautifier extends JavaPlugin {
|
||||
log("JoinQuitListener has been registered.");
|
||||
pluginManager.registerEvents(new ChatListener(), this);
|
||||
log("ChatListener has been registered.");
|
||||
pluginManager.registerEvents(new ChooseChatColorListener(), this);
|
||||
log("ChooseChatColorListener has been registered.");
|
||||
|
||||
Bukkit.getPluginCommand("set-chat-color").setExecutor(new ChatColorCommand());
|
||||
log("ChatColorCommand has been set as executor for the command 'set-chat-color'.");
|
||||
|
||||
log("Plugin enabled.");
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package de.privacynerd.chatbeautifier;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -15,11 +16,12 @@ public class ChatListener implements Listener {
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
//player.getDisplayName() + ": " + event.getMessage()
|
||||
|
||||
Server server = Bukkit.getServer();
|
||||
|
||||
Component message = Component.text(player.getDisplayName() + ": " + event.getMessage());
|
||||
Component message = player.displayName().append(Component.text(": " + event.getMessage(), NamedTextColor.WHITE));
|
||||
if(player.isOp()) {
|
||||
message = player.displayName().append(Component.text(": " + event.getMessage(), NamedTextColor.YELLOW));
|
||||
}
|
||||
server.broadcast(message);
|
||||
}
|
||||
}
|
@ -1,5 +1,9 @@
|
||||
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;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -7,21 +11,20 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
|
||||
public class JoinQuitListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if(player.isOp()) {
|
||||
player.setDisplayName("§4[OP] "+player.getName()+"§e");
|
||||
player.setPlayerListName(player.getDisplayName());
|
||||
} else {
|
||||
player.setDisplayName("§7"+player.getName()+"§7");
|
||||
player.setPlayerListName(player.getDisplayName());
|
||||
}
|
||||
DisplayNameSetter.setName(player); // set display name according to color config etc...
|
||||
|
||||
event.setJoinMessage("§a§l>> §7"+ player.getDisplayName());
|
||||
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);
|
||||
}
|
||||
|
||||
@ -30,6 +33,9 @@ public class JoinQuitListener implements Listener {
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
event.setQuitMessage("§c§l<< §7"+ player.getDisplayName());
|
||||
event.quitMessage(Component.text("<< ")
|
||||
.color(NamedTextColor.RED)
|
||||
.decoration(TextDecoration.BOLD, true)
|
||||
.append(player.displayName()));
|
||||
}
|
||||
}
|
||||
|
@ -1,26 +0,0 @@
|
||||
package de.privacynerd.chatbeautifier.commands;
|
||||
|
||||
import de.privacynerd.chatbeautifier.ChatBeautifier;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ChatColorCommand implements CommandExecutor {
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
|
||||
ChatBeautifier.INSTANCE.log("Command /set-chat-name executed");
|
||||
|
||||
if(!(commandSender instanceof Player)) {
|
||||
ChatBeautifier.INSTANCE.log("Du bist kein Spieler.");
|
||||
return true;
|
||||
}
|
||||
Player player = (Player) commandSender;
|
||||
|
||||
player.sendMessage(Component.text("Dieses Kommando befindet sich noch in der Mache!"));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,149 @@
|
||||
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;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class ChatColorCommand implements CommandExecutor {
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
|
||||
ChatBeautifier.INSTANCE.log("Command /set-chat-name executed.");
|
||||
|
||||
if(!(commandSender instanceof Player)) {
|
||||
ChatBeautifier.INSTANCE.log("This command was not executed by a player. Not doing anything.");
|
||||
return false;
|
||||
}
|
||||
Player player = (Player) commandSender;
|
||||
String validArgument = "";
|
||||
Component newName;
|
||||
int colorCodesListIndex; // stores the index of the color code which was requested (0 for black color code, ...)
|
||||
|
||||
// check for the right args
|
||||
if(args.length == 1) {
|
||||
switch (args[0]) {
|
||||
case "black":
|
||||
validArgument = "black";
|
||||
colorCodesListIndex = 0;
|
||||
break;
|
||||
case "gray":
|
||||
validArgument = "gray";
|
||||
colorCodesListIndex = 1;
|
||||
break;
|
||||
case "light-gray":
|
||||
validArgument = "light-gray";
|
||||
colorCodesListIndex = 2;
|
||||
break;
|
||||
case "white":
|
||||
validArgument = "white";
|
||||
colorCodesListIndex = 3;
|
||||
break;
|
||||
case "brown":
|
||||
validArgument = "brown";
|
||||
colorCodesListIndex = 4;
|
||||
break;
|
||||
case "red":
|
||||
validArgument = "red";
|
||||
colorCodesListIndex = 5;
|
||||
break;
|
||||
case "orange":
|
||||
validArgument = "orange";
|
||||
colorCodesListIndex = 6;
|
||||
break;
|
||||
case "yellow":
|
||||
validArgument = "yellow";
|
||||
colorCodesListIndex = 7;
|
||||
break;
|
||||
case "light-green":
|
||||
validArgument = "light-green";
|
||||
colorCodesListIndex = 8;
|
||||
break;
|
||||
case "dark-green":
|
||||
validArgument = "dark-green";
|
||||
colorCodesListIndex = 9;
|
||||
break;
|
||||
case "cyan":
|
||||
validArgument = "cyan";
|
||||
colorCodesListIndex = 10;
|
||||
break;
|
||||
case "blue":
|
||||
validArgument = "blue";
|
||||
colorCodesListIndex = 11;
|
||||
break;
|
||||
case "purple":
|
||||
validArgument = "purple";
|
||||
colorCodesListIndex = 12;
|
||||
break;
|
||||
case "magenta":
|
||||
validArgument = "magenta";
|
||||
colorCodesListIndex = 13;
|
||||
break;
|
||||
case "pink":
|
||||
validArgument = "pink";
|
||||
colorCodesListIndex = 14;
|
||||
break;
|
||||
case "list":
|
||||
ChatBeautifier.INSTANCE.log("Got valid argument 'list', printing list of valid colors...");
|
||||
ArrayList<String> colorNames = ChatColorUtils.getChooseColorStrings();
|
||||
|
||||
// now compose the message containing all possible color args
|
||||
Component message = Component.text("Mögliche Farben: ")
|
||||
.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++) {
|
||||
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
|
||||
ChatBeautifier.INSTANCE.tellPlayer(message, player);
|
||||
return true;
|
||||
case "gui":
|
||||
ChatBeautifier.INSTANCE.log("Got valid argument 'gui', opening gui...");
|
||||
player.openInventory(new ChooseChatColorGUI().getGUI(player));
|
||||
return true;
|
||||
default:
|
||||
// print a help string if no valid argument is given
|
||||
ChatBeautifier.INSTANCE.tellPlayer("Verwendung: /" + alias + " [<color>, list, gui]", player);
|
||||
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.tellPlayer(Component.text("Dein neuer Name: ")
|
||||
.append(player.displayName()
|
||||
), player);
|
||||
return true;
|
||||
} else if (args.length > 1) { // print a help string if more than one argument is given
|
||||
ChatBeautifier.INSTANCE.tellPlayer("Verwendung: /" + alias + " [<color>, list, gui]", player);
|
||||
return true;
|
||||
} else {
|
||||
player.openInventory(new ChooseChatColorGUI().getGUI(player));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
package de.privacynerd.chatbeautifier.displaynamecolor;
|
||||
|
||||
import de.privacynerd.chatbeautifier.ChatBeautifier;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
||||
// Class containing functions returning arrays for gui creation
|
||||
|
||||
public final class ChatColorUtils {
|
||||
public static @NotNull ArrayList<ItemStack> getChooseColorItems() {
|
||||
ArrayList<ItemStack> chooseColors = new ArrayList<>();
|
||||
chooseColors.add(new ItemStack(Material.BLACK_WOOL));
|
||||
chooseColors.add(new ItemStack(Material.GRAY_WOOL));
|
||||
chooseColors.add(new ItemStack(Material.LIGHT_GRAY_WOOL));
|
||||
chooseColors.add(new ItemStack(Material.WHITE_WOOL));
|
||||
chooseColors.add(new ItemStack(Material.BROWN_WOOL));
|
||||
chooseColors.add(new ItemStack(Material.RED_WOOL));
|
||||
chooseColors.add(new ItemStack(Material.ORANGE_WOOL));
|
||||
chooseColors.add(new ItemStack(Material.YELLOW_WOOL));
|
||||
chooseColors.add(new ItemStack(Material.LIME_WOOL));
|
||||
chooseColors.add(new ItemStack(Material.GREEN_WOOL));
|
||||
chooseColors.add(new ItemStack(Material.CYAN_WOOL));
|
||||
chooseColors.add(new ItemStack(Material.BLUE_WOOL));
|
||||
chooseColors.add(new ItemStack(Material.PURPLE_WOOL));
|
||||
chooseColors.add(new ItemStack(Material.MAGENTA_WOOL));
|
||||
chooseColors.add(new ItemStack(Material.PINK_WOOL));
|
||||
return chooseColors;
|
||||
}
|
||||
public static @NotNull ArrayList<String> getChooseColorStrings() {
|
||||
ArrayList<String> chooseColorNames = new ArrayList<>();
|
||||
chooseColorNames.add("Black");
|
||||
chooseColorNames.add("Gray");
|
||||
chooseColorNames.add("Light gray");
|
||||
chooseColorNames.add("White");
|
||||
chooseColorNames.add("Brown");
|
||||
chooseColorNames.add("Red");
|
||||
chooseColorNames.add("Orange");
|
||||
chooseColorNames.add("Yellow");
|
||||
chooseColorNames.add("Light green");
|
||||
chooseColorNames.add("Dark green");
|
||||
chooseColorNames.add("Cyan");
|
||||
chooseColorNames.add("Blue");
|
||||
chooseColorNames.add("Purple");
|
||||
chooseColorNames.add("Magenta");
|
||||
chooseColorNames.add("Pink");
|
||||
return chooseColorNames;
|
||||
}
|
||||
public static @NotNull ArrayList<TextColor> getChooseColorCodes() {
|
||||
ArrayList<TextColor> getChooseColorCodes = new ArrayList<>();
|
||||
|
||||
getChooseColorCodes.add(NamedTextColor.BLACK);
|
||||
getChooseColorCodes.add(NamedTextColor.DARK_GRAY);
|
||||
getChooseColorCodes.add(NamedTextColor.GRAY);
|
||||
getChooseColorCodes.add(NamedTextColor.WHITE);
|
||||
getChooseColorCodes.add(TextColor.color(135, 72, 0));
|
||||
getChooseColorCodes.add(TextColor.color(255, 0, 0));
|
||||
getChooseColorCodes.add(TextColor.color(255, 112, 0));
|
||||
getChooseColorCodes.add(NamedTextColor.YELLOW);
|
||||
getChooseColorCodes.add(TextColor.color(103, 255, 0));
|
||||
getChooseColorCodes.add(TextColor.color(38, 157, 0));
|
||||
getChooseColorCodes.add(TextColor.color(0, 252, 255));
|
||||
getChooseColorCodes.add(TextColor.color(0, 92, 255));
|
||||
getChooseColorCodes.add(TextColor.color(157, 0, 255));
|
||||
getChooseColorCodes.add(TextColor.color(255, 0, 179));
|
||||
getChooseColorCodes.add(TextColor.color(255, 87, 228));
|
||||
|
||||
return getChooseColorCodes;
|
||||
}
|
||||
}
|
@ -0,0 +1,111 @@
|
||||
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;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
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
|
||||
|
||||
ArrayList<ItemStack> chooseColorItems = ChatColorUtils.getChooseColorItems();
|
||||
ArrayList<String> chooseColorNames = ChatColorUtils.getChooseColorStrings();
|
||||
ArrayList<TextColor> chooseColorCodes = ChatColorUtils.getChooseColorCodes();
|
||||
|
||||
for (int i=0; i<15; i++) {
|
||||
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 {
|
||||
color_meta.displayName(Component.text(chooseColorNames.get(i), chooseColorCodes.get(i)));
|
||||
}
|
||||
chooseColorItems.get(i).setItemMeta(color_meta);
|
||||
}
|
||||
|
||||
// set item metas (so that a listener can correctly identify the items)
|
||||
ItemMeta nothing_meta = nothing.getItemMeta();
|
||||
nothing_meta.displayName(Component.text(" "));
|
||||
nothing.setItemMeta(nothing_meta);
|
||||
|
||||
// fill the glass panes
|
||||
for (int i=0; i<11; i++) { gui.setItem(i, nothing); }
|
||||
for (int i=0; i<3; i++) {
|
||||
gui.setItem(16 + (8 * i) + i, nothing);
|
||||
gui.setItem(16 + (8 * i) + i + 1, nothing);
|
||||
gui.setItem(16 + (8 * i) + i + 2, nothing);
|
||||
gui.setItem(16 + (8 * i) + i + 3, 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++) {
|
||||
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,71 @@
|
||||
package de.privacynerd.chatbeautifier.displaynamecolor;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
|
||||
public class ChooseChatColorListener implements Listener {
|
||||
@EventHandler
|
||||
public void onClickOnItem(InventoryClickEvent event) {
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
|
||||
if (event.getView().title().equals(Component.text("Set chat color (0x01)", NamedTextColor.DARK_GRAY))) {
|
||||
switch (event.getCurrentItem().getType()) {
|
||||
case BLACK_WOOL:
|
||||
player.performCommand("scc black");
|
||||
break;
|
||||
case GRAY_WOOL:
|
||||
player.performCommand("scc gray");
|
||||
break;
|
||||
case LIGHT_GRAY_WOOL:
|
||||
player.performCommand("scc light-gray");
|
||||
break;
|
||||
case WHITE_WOOL:
|
||||
player.performCommand("scc white");
|
||||
break;
|
||||
case BROWN_WOOL:
|
||||
player.performCommand("scc brown");
|
||||
break;
|
||||
case RED_WOOL:
|
||||
player.performCommand("scc red");
|
||||
break;
|
||||
case ORANGE_WOOL:
|
||||
player.performCommand("scc orange");
|
||||
break;
|
||||
case YELLOW_WOOL:
|
||||
player.performCommand("scc yellow");
|
||||
break;
|
||||
case LIME_WOOL:
|
||||
player.performCommand("scc light-green");
|
||||
break;
|
||||
case GREEN_WOOL:
|
||||
player.performCommand("scc dark-green");
|
||||
break;
|
||||
case CYAN_WOOL:
|
||||
player.performCommand("scc cyan");
|
||||
break;
|
||||
case BLUE_WOOL:
|
||||
player.performCommand("scc blue");
|
||||
break;
|
||||
case PURPLE_WOOL:
|
||||
player.performCommand("scc purple");
|
||||
break;
|
||||
case MAGENTA_WOOL:
|
||||
player.performCommand("scc magenta");
|
||||
break;
|
||||
case PINK_WOOL:
|
||||
player.performCommand("scc pink");
|
||||
break;
|
||||
default:
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
player.openInventory(new ChooseChatColorGUI().getGUI(player));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
package de.privacynerd.chatbeautifier.guis;
|
||||
|
||||
public class ChooseChatColor {
|
||||
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -7,4 +7,4 @@ commands:
|
||||
set-chat-color:
|
||||
description: Mit diesem Befehl kannst du die Farbe deines Namens setzen.
|
||||
aliases: ["scc"]
|
||||
usage: /set-chat-color
|
||||
usage: /set-chat-color [<color>, list, gui]
|
BIN
target/ChatBeautifier-0.2.2.jar
Normal file
BIN
target/ChatBeautifier-0.2.2.jar
Normal file
Binary file not shown.
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.2.jar
Normal file
BIN
target/original-ChatBeautifier-0.2.2.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