Update nicknames for Player and CMI.
This commit is contained in:
parent
5b06049265
commit
d90f5ac376
|
|
@ -13,6 +13,7 @@ dependencies {
|
||||||
compileOnly("com.gitlab.ruany:LiteBansAPI:0.3.5") // move to proxy
|
compileOnly("com.gitlab.ruany:LiteBansAPI:0.3.5") // move to proxy
|
||||||
compileOnly("org.apache.commons:commons-lang3:3.12.0") // needs an alternative, already removed from upstream api and will be removed in server
|
compileOnly("org.apache.commons:commons-lang3:3.12.0") // needs an alternative, already removed from upstream api and will be removed in server
|
||||||
compileOnly("net.luckperms:api:5.3") // Luckperms
|
compileOnly("net.luckperms:api:5.3") // Luckperms
|
||||||
|
compileOnly(files("../libs/CMI.jar"))
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks {
|
tasks {
|
||||||
|
|
|
||||||
|
|
@ -25,77 +25,77 @@ public class NickUtilities
|
||||||
{
|
{
|
||||||
public static String stringRegen;
|
public static String stringRegen;
|
||||||
|
|
||||||
// public static String applyColor(String message) {
|
public static String applyColor(String message) {
|
||||||
// ChatColor hexColor1 = null;
|
ChatColor hexColor1 = null;
|
||||||
// ChatColor hexColor2;
|
ChatColor hexColor2;
|
||||||
// StringBuilder stringBuilder = new StringBuilder();
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
// message = ChatColor.translateAlternateColorCodes('&', message);
|
message = ChatColor.translateAlternateColorCodes('&', message);
|
||||||
// boolean startsWithColor = false;
|
boolean startsWithColor = false;
|
||||||
// boolean lastColorMatters = false;
|
boolean lastColorMatters = false;
|
||||||
//
|
|
||||||
// if (message.matches(".*" + NickUtilities.stringRegen + ".*")) {
|
if (message.matches(".*" + NickUtilities.stringRegen + ".*")) {
|
||||||
// String[] split = message.split(NickUtilities.stringRegen);
|
String[] split = message.split(NickUtilities.stringRegen);
|
||||||
//
|
|
||||||
// ArrayList<String> list = new ArrayList<>();
|
ArrayList<String> list = new ArrayList<>();
|
||||||
// int nextIndex = 0;
|
int nextIndex = 0;
|
||||||
// if (message.indexOf("}") <= 11) {
|
if (message.indexOf("}") <= 11) {
|
||||||
// startsWithColor = true;
|
startsWithColor = true;
|
||||||
// list.add(message.substring(0, message.indexOf("}") + 1));
|
list.add(message.substring(0, message.indexOf("}") + 1));
|
||||||
// }
|
}
|
||||||
// for (String s : split) {
|
for (String s : split) {
|
||||||
// nextIndex += s.length();
|
nextIndex += s.length();
|
||||||
// int tmp = message.indexOf("}", nextIndex);
|
int tmp = message.indexOf("}", nextIndex);
|
||||||
// if (tmp < message.length() && tmp>=0) {
|
if (tmp < message.length() && tmp>=0) {
|
||||||
// list.add(message.substring(nextIndex, tmp + 1));
|
list.add(message.substring(nextIndex, tmp + 1));
|
||||||
// nextIndex = tmp + 1;
|
nextIndex = tmp + 1;
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// int i;
|
int i;
|
||||||
// boolean firstLoop = true;
|
boolean firstLoop = true;
|
||||||
// if (startsWithColor) {
|
if (startsWithColor) {
|
||||||
// i = -1;
|
i = -1;
|
||||||
// } else {
|
} else {
|
||||||
// i = 0;
|
i = 0;
|
||||||
// stringBuilder.append(split[i]);
|
stringBuilder.append(split[i]);
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// for (String s : list) {
|
for (String s : list) {
|
||||||
// boolean lesser = s.contains("<");
|
boolean lesser = s.contains("<");
|
||||||
// boolean bigger = s.contains(">");
|
boolean bigger = s.contains(">");
|
||||||
//
|
|
||||||
// if (bigger && lesser) {
|
if (bigger && lesser) {
|
||||||
// hexColor2 = ChatColor.of(s.substring(1, s.length() - 3));
|
hexColor2 = ChatColor.of(s.substring(1, s.length() - 3));
|
||||||
// } else if (bigger || lesser) {
|
} else if (bigger || lesser) {
|
||||||
// hexColor2 = ChatColor.of(s.substring(1, s.length() - 2));
|
hexColor2 = ChatColor.of(s.substring(1, s.length() - 2));
|
||||||
// } else {
|
} else {
|
||||||
// hexColor2 = ChatColor.of(s.substring(1, s.length() -1));
|
hexColor2 = ChatColor.of(s.substring(1, s.length() -1));
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// if (firstLoop) {
|
if (firstLoop) {
|
||||||
// lastColorMatters = bigger;
|
lastColorMatters = bigger;
|
||||||
// hexColor1 = hexColor2;
|
hexColor1 = hexColor2;
|
||||||
// firstLoop = false;
|
firstLoop = false;
|
||||||
// i++;
|
i++;
|
||||||
// continue;
|
continue;
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// if (lesser && lastColorMatters) {
|
if (lesser && lastColorMatters) {
|
||||||
// stringBuilder.append(hexGradient(hexColor1.getColor(), hexColor2.getColor(), split[i]));
|
stringBuilder.append(hexGradient(hexColor1.getColor(), hexColor2.getColor(), split[i]));
|
||||||
// } else {
|
} else {
|
||||||
// stringBuilder.append(hexColor1).append(split[i]);
|
stringBuilder.append(hexColor1).append(split[i]);
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// hexColor1 = hexColor2;
|
hexColor1 = hexColor2;
|
||||||
// lastColorMatters = bigger;
|
lastColorMatters = bigger;
|
||||||
// i++;
|
i++;
|
||||||
// }
|
}
|
||||||
// if (split.length > i){
|
if (split.length > i){
|
||||||
// stringBuilder.append(hexColor1).append(split[i]);
|
stringBuilder.append(hexColor1).append(split[i]);
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// return stringBuilder.length()==0 ? message : stringBuilder.toString();
|
return stringBuilder.length()==0 ? message : stringBuilder.toString();
|
||||||
// }
|
}
|
||||||
|
|
||||||
public static String removeAllColors(String string) {
|
public static String removeAllColors(String string) {
|
||||||
|
|
||||||
|
|
@ -110,28 +110,28 @@ public class NickUtilities
|
||||||
NickUtilities.stringRegen = "\\{#[A-Fa-f0-9]{6}(<)?(>)?}";
|
NickUtilities.stringRegen = "\\{#[A-Fa-f0-9]{6}(<)?(>)?}";
|
||||||
}
|
}
|
||||||
|
|
||||||
// public static String hexGradient(Color color1, Color color2, String text){
|
public static String hexGradient(Color color1, Color color2, String text){
|
||||||
// double r = color1.getRed();
|
double r = color1.getRed();
|
||||||
// double g = color1.getGreen();
|
double g = color1.getGreen();
|
||||||
// double b = color1.getBlue();
|
double b = color1.getBlue();
|
||||||
//
|
|
||||||
// double rDifference = (color1.getRed() - color2.getRed()) / ((double) text.length() - 1);
|
double rDifference = (color1.getRed() - color2.getRed()) / ((double) text.length() - 1);
|
||||||
// double gDifference = (color1.getGreen() - color2.getGreen()) / ((double) text.length() - 1);
|
double gDifference = (color1.getGreen() - color2.getGreen()) / ((double) text.length() - 1);
|
||||||
// double bDifference = (color1.getBlue() - color2.getBlue()) / ((double) text.length() - 1);
|
double bDifference = (color1.getBlue() - color2.getBlue()) / ((double) text.length() - 1);
|
||||||
//
|
|
||||||
// StringBuilder stringBuilder = new StringBuilder();
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
// char[] chars = text.toCharArray();
|
char[] chars = text.toCharArray();
|
||||||
// for (int i = 0; i < text.length(); i++) {
|
for (int i = 0; i < text.length(); i++) {
|
||||||
// if (i > 0) {
|
if (i > 0) {
|
||||||
// r = r - rDifference;
|
r = r - rDifference;
|
||||||
// g = g - gDifference;
|
g = g - gDifference;
|
||||||
// b = b - bDifference;
|
b = b - bDifference;
|
||||||
// }
|
}
|
||||||
// stringBuilder.append(ChatColor.of(new Color((int) r, (int) g, (int) b))).append(chars[i]);
|
stringBuilder.append(ChatColor.of(new Color((int) r, (int) g, (int) b))).append(chars[i]);
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// return stringBuilder.toString();
|
return stringBuilder.toString();
|
||||||
// }
|
}
|
||||||
|
|
||||||
public static void updateCache() {
|
public static void updateCache() {
|
||||||
if (!Nicknames.getInstance().nickCacheUpdate.isEmpty()){
|
if (!Nicknames.getInstance().nickCacheUpdate.isEmpty()){
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
package com.alttd.chat.nicknames;
|
package com.alttd.chat.nicknames;
|
||||||
|
|
||||||
|
import com.Zrips.CMI.CMI;
|
||||||
|
import com.Zrips.CMI.Containers.CMIUser;
|
||||||
import com.alttd.chat.ChatAPI;
|
import com.alttd.chat.ChatAPI;
|
||||||
import com.alttd.chat.ChatPlugin;
|
import com.alttd.chat.ChatPlugin;
|
||||||
import com.alttd.chat.config.Config;
|
import com.alttd.chat.config.Config;
|
||||||
|
|
@ -22,6 +24,7 @@ import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.TabCompleter;
|
import org.bukkit.command.TabCompleter;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
|
@ -284,7 +287,7 @@ public class Nicknames implements CommandExecutor, TabCompleter {
|
||||||
|
|
||||||
} else if (NickUtilities.validNick(sender, target, nickName)) {
|
} else if (NickUtilities.validNick(sender, target, nickName)) {
|
||||||
if (target.isOnline()) {
|
if (target.isOnline()) {
|
||||||
setNick(target.getUniqueId(), nickName);
|
setNick(target.getPlayer(), nickName);
|
||||||
} else {
|
} else {
|
||||||
NickUtilities.bungeeMessageHandled(target.getUniqueId(), sender, "Set");
|
NickUtilities.bungeeMessageHandled(target.getUniqueId(), sender, "Set");
|
||||||
}
|
}
|
||||||
|
|
@ -297,7 +300,7 @@ public class Nicknames implements CommandExecutor, TabCompleter {
|
||||||
Nick nick = NickCache.get(target.getUniqueId());
|
Nick nick = NickCache.get(target.getUniqueId());
|
||||||
nick.setCurrentNick(nickName);
|
nick.setCurrentNick(nickName);
|
||||||
nick.setLastChangedDate(new Date().getTime());
|
nick.setLastChangedDate(new Date().getTime());
|
||||||
setNick(target.getUniqueId(), nickName);
|
setNick(target.getPlayer(), nickName);
|
||||||
} else {
|
} else {
|
||||||
NickCache.put(target.getUniqueId(), new Nick(target.getUniqueId(), nickName, new Date().getTime()));
|
NickCache.put(target.getUniqueId(), new Nick(target.getUniqueId(), nickName, new Date().getTime()));
|
||||||
}
|
}
|
||||||
|
|
@ -380,6 +383,8 @@ public class Nicknames implements CommandExecutor, TabCompleter {
|
||||||
public void resetNick(final Player player) {
|
public void resetNick(final Player player) {
|
||||||
ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
||||||
user.setDisplayName(player.getName());
|
user.setDisplayName(player.getName());
|
||||||
|
player.displayName(user.getDisplayName());
|
||||||
|
updateCMIUser(player, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getNick(final Player player) {
|
public String getNick(final Player player) {
|
||||||
|
|
@ -387,18 +392,45 @@ public class Nicknames implements CommandExecutor, TabCompleter {
|
||||||
return user.getNickNameString();
|
return user.getNickNameString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNick(final UUID uuid, final String nickName) {
|
public void setNick(final Player player, final String nickName) {
|
||||||
ChatUser user = ChatUserManager.getChatUser(uuid);
|
if (player == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
||||||
user.setDisplayName(nickName);
|
user.setDisplayName(nickName);
|
||||||
Player player = Bukkit.getPlayer(uuid);
|
player.displayName(user.getDisplayName());
|
||||||
if (player != null)
|
updateCMIUser(player, nickName);
|
||||||
player.displayName(user.getDisplayName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// public static String format(final String m) {
|
// public static String format(final String m) {
|
||||||
// return NickUtilities.applyColor(m);
|
// return NickUtilities.applyColor(m);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
public void updateCMIUser(Player player, String nickName) {
|
||||||
|
if (!isCMIEnabled())
|
||||||
|
return;
|
||||||
|
|
||||||
|
CMIUser cmiUser = CMI.getInstance().getPlayerManager().getUser(player);
|
||||||
|
if (nickName == null){
|
||||||
|
cmiUser.setNickName(null, true);
|
||||||
|
} else {
|
||||||
|
cmiUser.setNickName(NickUtilities.applyColor(nickName), true);
|
||||||
|
}
|
||||||
|
cmiUser.updateDisplayName();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Boolean isCMIEnabled = null;
|
||||||
|
private Boolean isCMIEnabled() {
|
||||||
|
if (!(isCMIEnabled == null))
|
||||||
|
return isCMIEnabled;
|
||||||
|
|
||||||
|
Plugin plugin = Bukkit.getPluginManager().getPlugin("CMI");
|
||||||
|
if (plugin != null && plugin.isEnabled())
|
||||||
|
return isCMIEnabled = true;
|
||||||
|
|
||||||
|
return isCMIEnabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
public static Nicknames getInstance() {
|
public static Nicknames getInstance() {
|
||||||
return Nicknames.instance;
|
return Nicknames.instance;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,12 @@
|
||||||
package com.alttd.chat.nicknames;
|
package com.alttd.chat.nicknames;
|
||||||
|
|
||||||
|
import com.Zrips.CMI.commands.list.colorlimits;
|
||||||
|
import com.Zrips.CMI.utils.Util;
|
||||||
import com.alttd.chat.ChatPlugin;
|
import com.alttd.chat.ChatPlugin;
|
||||||
import com.alttd.chat.config.Config;
|
import com.alttd.chat.config.Config;
|
||||||
import com.alttd.chat.database.Queries;
|
import com.alttd.chat.database.Queries;
|
||||||
|
import com.alttd.chat.managers.ChatUserManager;
|
||||||
|
import com.alttd.chat.objects.ChatUser;
|
||||||
import com.alttd.chat.objects.Nick;
|
import com.alttd.chat.objects.Nick;
|
||||||
import com.alttd.chat.util.ALogger;
|
import com.alttd.chat.util.ALogger;
|
||||||
import com.google.common.io.ByteArrayDataInput;
|
import com.google.common.io.ByteArrayDataInput;
|
||||||
|
|
@ -50,18 +54,18 @@ public class NicknamesEvents implements Listener, PluginMessageListener {
|
||||||
|
|
||||||
String nickName = nick.getCurrentNick();
|
String nickName = nick.getCurrentNick();
|
||||||
String strippedNick = Nicknames.getInstance().getNick(player);
|
String strippedNick = Nicknames.getInstance().getNick(player);
|
||||||
// try {
|
try {
|
||||||
// strippedNick = MiniMessage.miniMessage().stripTokens(Nicknames.getInstance().getNick(player));
|
strippedNick = MiniMessage.miniMessage().stripTags(Nicknames.getInstance().getNick(player));
|
||||||
// } catch (NullPointerException ignored) {
|
} catch (NullPointerException ignored) {
|
||||||
// }
|
}
|
||||||
// final String strippedNick = CMIChatColor.stripColor(Nicknames.getInstance().getNick(player));
|
// final String strippedNick = CMIChatColor.stripColor(Nicknames.getInstance().getNick(player));
|
||||||
|
|
||||||
//final String cmiNick = Util.CMIChatColor.deColorize(Nicknames.getInstance().getNick(player));
|
// final String cmiNick = Util.CMIChatColor.deColorize(Nicknames.getInstance().getNick(player));
|
||||||
|
|
||||||
if (nickName == null) {
|
if (nickName == null) {
|
||||||
Nicknames.getInstance().resetNick(player);
|
Nicknames.getInstance().resetNick(player);
|
||||||
} else if (!nickName.equals(strippedNick)) {
|
} else if (!nickName.equals(strippedNick)) {
|
||||||
Nicknames.getInstance().setNick(player.getUniqueId(), nickName);
|
Nicknames.getInstance().setNick(player, nickName);
|
||||||
}
|
}
|
||||||
|
|
||||||
Nicknames.getInstance().NickCache.put(e.getPlayer().getUniqueId(), nick);
|
Nicknames.getInstance().NickCache.put(e.getPlayer().getUniqueId(), nick);
|
||||||
|
|
@ -133,7 +137,7 @@ public class NicknamesEvents implements Listener, PluginMessageListener {
|
||||||
if (offlinePlayer.isOnline()) {
|
if (offlinePlayer.isOnline()) {
|
||||||
Nick nick = Queries.getNick(playerUUID);
|
Nick nick = Queries.getNick(playerUUID);
|
||||||
if (nick != null && nick.getCurrentNick() != null) {
|
if (nick != null && nick.getCurrentNick() != null) {
|
||||||
Nicknames.getInstance().setNick(offlinePlayer.getUniqueId(), nick.getCurrentNick());
|
Nicknames.getInstance().setNick(offlinePlayer.getPlayer(), nick.getCurrentNick());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
@ -152,7 +156,7 @@ public class NicknamesEvents implements Listener, PluginMessageListener {
|
||||||
Nick nick = Queries.getNick(playerUUID);
|
Nick nick = Queries.getNick(playerUUID);
|
||||||
Player target = Bukkit.getPlayer(playerUUID);
|
Player target = Bukkit.getPlayer(playerUUID);
|
||||||
if (target != null && nick != null && nick.getCurrentNick() != null) {
|
if (target != null && nick != null && nick.getCurrentNick() != null) {
|
||||||
Nicknames.getInstance().setNick(target.getUniqueId(), nick.getCurrentNick());
|
Nicknames.getInstance().setNick(target, nick.getCurrentNick());
|
||||||
target.sendMessage(MiniMessage.miniMessage().deserialize(Config.NICK_CHANGED,
|
target.sendMessage(MiniMessage.miniMessage().deserialize(Config.NICK_CHANGED,
|
||||||
Placeholder.unparsed("nickname", nick.getCurrentNick())));
|
Placeholder.unparsed("nickname", nick.getCurrentNick())));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -198,7 +198,7 @@ public class NicknamesGui implements Listener {
|
||||||
Placeholder.component("oldnick", Utility.applyColor(nick.getCurrentNick() == null ? clickedItem.getItemMeta().getDisplayName() : nick.getCurrentNick()))));
|
Placeholder.component("oldnick", Utility.applyColor(nick.getCurrentNick() == null ? clickedItem.getItemMeta().getDisplayName() : nick.getCurrentNick()))));
|
||||||
|
|
||||||
if (owningPlayer.isOnline() && owningPlayer.getPlayer() != null) {
|
if (owningPlayer.isOnline() && owningPlayer.getPlayer() != null) {
|
||||||
Nicknames.getInstance().setNick(owningPlayer.getUniqueId(), nick.getNewNick());
|
Nicknames.getInstance().setNick(owningPlayer.getPlayer(), nick.getNewNick());
|
||||||
// owningPlayer.getPlayer().sendMessage(MiniMessage.miniMessage().deserialize(Config.NICK_CHANGED // This message is also send when the plugin message is received
|
// owningPlayer.getPlayer().sendMessage(MiniMessage.miniMessage().deserialize(Config.NICK_CHANGED // This message is also send when the plugin message is received
|
||||||
// .replace("%nickname%", nick.getNewNick())));
|
// .replace("%nickname%", nick.getNewNick())));
|
||||||
}
|
}
|
||||||
|
|
@ -254,7 +254,7 @@ public class NicknamesGui implements Listener {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (owningPlayer.isOnline() && owningPlayer.getPlayer() != null) {
|
if (owningPlayer.isOnline() && owningPlayer.getPlayer() != null) {
|
||||||
Nicknames.getInstance().setNick(owningPlayer.getUniqueId(), nick.getCurrentNick() == null ? owningPlayer.getName() : nick.getCurrentNick());
|
Nicknames.getInstance().setNick(owningPlayer.getPlayer(), nick.getCurrentNick() == null ? owningPlayer.getName() : nick.getCurrentNick());
|
||||||
owningPlayer.getPlayer().sendMessage(MiniMessage.miniMessage().deserialize(Config.NICK_NOT_CHANGED));
|
owningPlayer.getPlayer().sendMessage(MiniMessage.miniMessage().deserialize(Config.NICK_NOT_CHANGED));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
BIN
libs/CMI.jar
Executable file
BIN
libs/CMI.jar
Executable file
Binary file not shown.
Loading…
Reference in New Issue
Block a user