mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-27 21:29:14 +01:00
Optimise StringHelper#parseColors, fix an NPE
This commit is contained in:
parent
6e9593c4c3
commit
0d56317bc0
@ -972,9 +972,10 @@ public class NPCCommands {
|
||||
"tphere", "tph", "move" }, min = 1, max = 1, permission = "npc.tphere")
|
||||
public void tphere(CommandContext args, Player player, NPC npc) {
|
||||
// Spawn the NPC if it isn't spawned to prevent NPEs
|
||||
if (!npc.isSpawned())
|
||||
npc.spawn(npc.getTrait(CurrentLocation.class).getLocation());
|
||||
npc.getBukkitEntity().teleport(player, TeleportCause.COMMAND);
|
||||
if (!npc.isSpawned()) {
|
||||
npc.spawn(player.getLocation());
|
||||
} else
|
||||
npc.getBukkitEntity().teleport(player, TeleportCause.COMMAND);
|
||||
Messaging.sendTr(player, Messages.NPC_TELEPORTED, npc.getName());
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
package net.citizensnpcs.util;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import net.citizensnpcs.Settings.Setting;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
@ -60,13 +62,8 @@ public class StringHelper {
|
||||
return p[n];
|
||||
}
|
||||
|
||||
public static String parseColors(Object string) {
|
||||
String parsed = string.toString();
|
||||
for (ChatColor color : ChatColor.values()) {
|
||||
parsed = parsed.replace("<" + color.getChar() + ">", color.toString());
|
||||
}
|
||||
parsed = ChatColor.translateAlternateColorCodes('&', parsed);
|
||||
return parsed;
|
||||
public static String parseColors(String parsed) {
|
||||
return COLOR_MATCHER.matcher(parsed).replaceAll(ChatColor.COLOR_CHAR + "$1");
|
||||
}
|
||||
|
||||
public static String wrap(Object string) {
|
||||
@ -85,4 +82,13 @@ public class StringHelper {
|
||||
String highlight = Setting.HIGHLIGHT_COLOUR.asString();
|
||||
return highlight + "=====[ " + string.toString() + highlight + " ]=====";
|
||||
}
|
||||
|
||||
private static Pattern COLOR_MATCHER;
|
||||
static {
|
||||
String colors = "";
|
||||
for (ChatColor color : ChatColor.values())
|
||||
colors += color.getChar();
|
||||
COLOR_MATCHER = Pattern.compile("[&<]([COLORS])[>]?".replace("COLORS", colors),
|
||||
Pattern.CASE_INSENSITIVE);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user