Remove deprecation usages
This commit is contained in:
parent
d7bd3aa222
commit
e99626cebb
|
|
@ -25,77 +25,77 @@ public class NickUtilities
|
|||
{
|
||||
public static String stringRegen;
|
||||
|
||||
public static String applyColor(String message) {
|
||||
ChatColor hexColor1 = null;
|
||||
ChatColor hexColor2;
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
message = ChatColor.translateAlternateColorCodes('&', message);
|
||||
boolean startsWithColor = false;
|
||||
boolean lastColorMatters = false;
|
||||
|
||||
if (message.matches(".*" + NickUtilities.stringRegen + ".*")) {
|
||||
String[] split = message.split(NickUtilities.stringRegen);
|
||||
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
int nextIndex = 0;
|
||||
if (message.indexOf("}") <= 11) {
|
||||
startsWithColor = true;
|
||||
list.add(message.substring(0, message.indexOf("}") + 1));
|
||||
}
|
||||
for (String s : split) {
|
||||
nextIndex += s.length();
|
||||
int tmp = message.indexOf("}", nextIndex);
|
||||
if (tmp < message.length() && tmp>=0) {
|
||||
list.add(message.substring(nextIndex, tmp + 1));
|
||||
nextIndex = tmp + 1;
|
||||
}
|
||||
}
|
||||
|
||||
int i;
|
||||
boolean firstLoop = true;
|
||||
if (startsWithColor) {
|
||||
i = -1;
|
||||
} else {
|
||||
i = 0;
|
||||
stringBuilder.append(split[i]);
|
||||
}
|
||||
|
||||
for (String s : list) {
|
||||
boolean lesser = s.contains("<");
|
||||
boolean bigger = s.contains(">");
|
||||
|
||||
if (bigger && lesser) {
|
||||
hexColor2 = ChatColor.of(s.substring(1, s.length() - 3));
|
||||
} else if (bigger || lesser) {
|
||||
hexColor2 = ChatColor.of(s.substring(1, s.length() - 2));
|
||||
} else {
|
||||
hexColor2 = ChatColor.of(s.substring(1, s.length() -1));
|
||||
}
|
||||
|
||||
if (firstLoop) {
|
||||
lastColorMatters = bigger;
|
||||
hexColor1 = hexColor2;
|
||||
firstLoop = false;
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (lesser && lastColorMatters) {
|
||||
stringBuilder.append(hexGradient(hexColor1.getColor(), hexColor2.getColor(), split[i]));
|
||||
} else {
|
||||
stringBuilder.append(hexColor1).append(split[i]);
|
||||
}
|
||||
|
||||
hexColor1 = hexColor2;
|
||||
lastColorMatters = bigger;
|
||||
i++;
|
||||
}
|
||||
if (split.length > i){
|
||||
stringBuilder.append(hexColor1).append(split[i]);
|
||||
}
|
||||
}
|
||||
return stringBuilder.length()==0 ? message : stringBuilder.toString();
|
||||
}
|
||||
// public static String applyColor(String message) {
|
||||
// ChatColor hexColor1 = null;
|
||||
// ChatColor hexColor2;
|
||||
// StringBuilder stringBuilder = new StringBuilder();
|
||||
// message = ChatColor.translateAlternateColorCodes('&', message);
|
||||
// boolean startsWithColor = false;
|
||||
// boolean lastColorMatters = false;
|
||||
//
|
||||
// if (message.matches(".*" + NickUtilities.stringRegen + ".*")) {
|
||||
// String[] split = message.split(NickUtilities.stringRegen);
|
||||
//
|
||||
// ArrayList<String> list = new ArrayList<>();
|
||||
// int nextIndex = 0;
|
||||
// if (message.indexOf("}") <= 11) {
|
||||
// startsWithColor = true;
|
||||
// list.add(message.substring(0, message.indexOf("}") + 1));
|
||||
// }
|
||||
// for (String s : split) {
|
||||
// nextIndex += s.length();
|
||||
// int tmp = message.indexOf("}", nextIndex);
|
||||
// if (tmp < message.length() && tmp>=0) {
|
||||
// list.add(message.substring(nextIndex, tmp + 1));
|
||||
// nextIndex = tmp + 1;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// int i;
|
||||
// boolean firstLoop = true;
|
||||
// if (startsWithColor) {
|
||||
// i = -1;
|
||||
// } else {
|
||||
// i = 0;
|
||||
// stringBuilder.append(split[i]);
|
||||
// }
|
||||
//
|
||||
// for (String s : list) {
|
||||
// boolean lesser = s.contains("<");
|
||||
// boolean bigger = s.contains(">");
|
||||
//
|
||||
// if (bigger && lesser) {
|
||||
// hexColor2 = ChatColor.of(s.substring(1, s.length() - 3));
|
||||
// } else if (bigger || lesser) {
|
||||
// hexColor2 = ChatColor.of(s.substring(1, s.length() - 2));
|
||||
// } else {
|
||||
// hexColor2 = ChatColor.of(s.substring(1, s.length() -1));
|
||||
// }
|
||||
//
|
||||
// if (firstLoop) {
|
||||
// lastColorMatters = bigger;
|
||||
// hexColor1 = hexColor2;
|
||||
// firstLoop = false;
|
||||
// i++;
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// if (lesser && lastColorMatters) {
|
||||
// stringBuilder.append(hexGradient(hexColor1.getColor(), hexColor2.getColor(), split[i]));
|
||||
// } else {
|
||||
// stringBuilder.append(hexColor1).append(split[i]);
|
||||
// }
|
||||
//
|
||||
// hexColor1 = hexColor2;
|
||||
// lastColorMatters = bigger;
|
||||
// i++;
|
||||
// }
|
||||
// if (split.length > i){
|
||||
// stringBuilder.append(hexColor1).append(split[i]);
|
||||
// }
|
||||
// }
|
||||
// return stringBuilder.length()==0 ? message : stringBuilder.toString();
|
||||
// }
|
||||
|
||||
public static String removeAllColors(String string) {
|
||||
|
||||
|
|
@ -110,28 +110,28 @@ public class NickUtilities
|
|||
NickUtilities.stringRegen = "\\{#[A-Fa-f0-9]{6}(<)?(>)?}";
|
||||
}
|
||||
|
||||
public static String hexGradient(Color color1, Color color2, String text){
|
||||
double r = color1.getRed();
|
||||
double g = color1.getGreen();
|
||||
double b = color1.getBlue();
|
||||
|
||||
double rDifference = (color1.getRed() - color2.getRed()) / ((double) text.length() - 1);
|
||||
double gDifference = (color1.getGreen() - color2.getGreen()) / ((double) text.length() - 1);
|
||||
double bDifference = (color1.getBlue() - color2.getBlue()) / ((double) text.length() - 1);
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
char[] chars = text.toCharArray();
|
||||
for (int i = 0; i < text.length(); i++) {
|
||||
if (i > 0) {
|
||||
r = r - rDifference;
|
||||
g = g - gDifference;
|
||||
b = b - bDifference;
|
||||
}
|
||||
stringBuilder.append(ChatColor.of(new Color((int) r, (int) g, (int) b))).append(chars[i]);
|
||||
}
|
||||
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
// public static String hexGradient(Color color1, Color color2, String text){
|
||||
// double r = color1.getRed();
|
||||
// double g = color1.getGreen();
|
||||
// double b = color1.getBlue();
|
||||
//
|
||||
// double rDifference = (color1.getRed() - color2.getRed()) / ((double) text.length() - 1);
|
||||
// double gDifference = (color1.getGreen() - color2.getGreen()) / ((double) text.length() - 1);
|
||||
// double bDifference = (color1.getBlue() - color2.getBlue()) / ((double) text.length() - 1);
|
||||
//
|
||||
// StringBuilder stringBuilder = new StringBuilder();
|
||||
// char[] chars = text.toCharArray();
|
||||
// for (int i = 0; i < text.length(); i++) {
|
||||
// if (i > 0) {
|
||||
// r = r - rDifference;
|
||||
// g = g - gDifference;
|
||||
// b = b - bDifference;
|
||||
// }
|
||||
// stringBuilder.append(ChatColor.of(new Color((int) r, (int) g, (int) b))).append(chars[i]);
|
||||
// }
|
||||
//
|
||||
// return stringBuilder.toString();
|
||||
// }
|
||||
|
||||
public static void updateCache() {
|
||||
if (!Nicknames.getInstance().nickCacheUpdate.isEmpty()){
|
||||
|
|
@ -165,7 +165,7 @@ public class NickUtilities
|
|||
if (uniqueId.equals(uuid)){
|
||||
ChatPlugin.getInstance().getLogger().info(uuid + " " + uniqueId);
|
||||
}
|
||||
sender.sendMessage(applyColor(Config.NICK_TAKEN));
|
||||
sender.sendMiniMessage(Config.NICK_TAKEN, null);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -174,13 +174,13 @@ public class NickUtilities
|
|||
return true;
|
||||
|
||||
} else {
|
||||
sender.sendMessage(applyColor(Config.NICK_INVALID_CHARACTERS));
|
||||
sender.sendMiniMessage(Config.NICK_INVALID_CHARACTERS, null);
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(applyColor(Config.NICK_INVALID_LENGTH));
|
||||
sender.sendMiniMessage(Config.NICK_INVALID_LENGTH, null);
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(applyColor(Config.NICK_BLOCKED_COLOR_CODES));
|
||||
sender.sendMiniMessage(Config.NICK_BLOCKED_COLOR_CODES, null);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -117,9 +117,7 @@ public class NicknamesEvents implements Listener, PluginMessageListener {
|
|||
MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||
switch (subChannel) {
|
||||
case "NickNameRequest":
|
||||
String notification = NickUtilities.applyColor(Config.NICK_REQUEST_NEW
|
||||
.replace("%player%", name)); //TODO fix this needing .replace
|
||||
Component component = miniMessage.deserialize(NickUtilities.applyColor(notification))
|
||||
Component component = miniMessage.deserialize(Config.NICK_REQUEST_NEW, Placeholder.parsed("player", name))
|
||||
.clickEvent(ClickEvent.clickEvent(ClickEvent.Action.RUN_COMMAND,
|
||||
"/nick review"))
|
||||
.hoverEvent(HoverEvent.hoverEvent(HoverEvent.Action.SHOW_TEXT,
|
||||
|
|
|
|||
|
|
@ -116,7 +116,8 @@ public class NicknamesGui implements Listener {
|
|||
meta.displayName(Component.text(name));
|
||||
|
||||
// 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);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user