Remove deprecation usages

This commit is contained in:
Len 2022-10-02 10:53:26 +02:00
parent d7bd3aa222
commit e99626cebb
3 changed files with 100 additions and 101 deletions

View File

@ -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()){
@ -165,7 +165,7 @@ public class NickUtilities
if (uniqueId.equals(uuid)){ if (uniqueId.equals(uuid)){
ChatPlugin.getInstance().getLogger().info(uuid + " " + uniqueId); ChatPlugin.getInstance().getLogger().info(uuid + " " + uniqueId);
} }
sender.sendMessage(applyColor(Config.NICK_TAKEN)); sender.sendMiniMessage(Config.NICK_TAKEN, null);
return false; return false;
} }
} }
@ -174,13 +174,13 @@ public class NickUtilities
return true; return true;
} else { } else {
sender.sendMessage(applyColor(Config.NICK_INVALID_CHARACTERS)); sender.sendMiniMessage(Config.NICK_INVALID_CHARACTERS, null);
} }
} else { } else {
sender.sendMessage(applyColor(Config.NICK_INVALID_LENGTH)); sender.sendMiniMessage(Config.NICK_INVALID_LENGTH, null);
} }
} else { } else {
sender.sendMessage(applyColor(Config.NICK_BLOCKED_COLOR_CODES)); sender.sendMiniMessage(Config.NICK_BLOCKED_COLOR_CODES, null);
} }
return false; return false;
} }

View File

@ -117,9 +117,7 @@ public class NicknamesEvents implements Listener, PluginMessageListener {
MiniMessage miniMessage = MiniMessage.miniMessage(); MiniMessage miniMessage = MiniMessage.miniMessage();
switch (subChannel) { switch (subChannel) {
case "NickNameRequest": case "NickNameRequest":
String notification = NickUtilities.applyColor(Config.NICK_REQUEST_NEW Component component = miniMessage.deserialize(Config.NICK_REQUEST_NEW, Placeholder.parsed("player", name))
.replace("%player%", name)); //TODO fix this needing .replace
Component component = miniMessage.deserialize(NickUtilities.applyColor(notification))
.clickEvent(ClickEvent.clickEvent(ClickEvent.Action.RUN_COMMAND, .clickEvent(ClickEvent.clickEvent(ClickEvent.Action.RUN_COMMAND,
"/nick review")) "/nick review"))
.hoverEvent(HoverEvent.hoverEvent(HoverEvent.Action.SHOW_TEXT, .hoverEvent(HoverEvent.hoverEvent(HoverEvent.Action.SHOW_TEXT,

View File

@ -116,7 +116,8 @@ public class NicknamesGui implements Listener {
meta.displayName(Component.text(name)); meta.displayName(Component.text(name));
// Set the lore of the item // Set the lore of the item
meta.setLore(Arrays.asList(lore)); MiniMessage miniMessage = MiniMessage.miniMessage();
meta.lore(Arrays.stream(lore).map(miniMessage::deserialize).collect(Collectors.toList()));
item.setItemMeta(meta); item.setItemMeta(meta);