Skip to content

Commit

Permalink
Regex treats the replacement as regex, back to normal string replacem…
Browse files Browse the repository at this point in the history
…ent for now
  • Loading branch information
fullwall committed Jan 1, 2022
1 parent 5d8a9d8 commit 7eb7494
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions src/main/java/net/citizensnpcs/api/util/Placeholders.java
@@ -1,7 +1,5 @@
package net.citizensnpcs.api.util;

import java.util.regex.Pattern;

import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
Expand All @@ -17,7 +15,7 @@ public static String replace(String text, CommandSender sender, NPC npc) {
return text;
}
for (int i = 0; i < CITIZENS_PLACEHOLDERS.length; i++) {
text = CITIZENS_PLACEHOLDERS[i].matcher(text).replaceAll(i == 0 ? Integer.toString(npc.getId())
text = text.replace(CITIZENS_PLACEHOLDERS[i], i == 0 ? Integer.toString(npc.getId())
: i == 1 ? npc.getName() : npc.getOrAddTrait(Owner.class).getOwner());
}
return text;
Expand All @@ -29,12 +27,12 @@ public static String replace(String text, OfflinePlayer player) {
}
if (player instanceof Entity && ((Entity) player).isValid()) {
for (int i = 0; i < PLAYER_WORLD_PLACEHOLDERS.length; i++) {
text = PLAYER_WORLD_PLACEHOLDERS[i].matcher(text)
.replaceAll(i < 4 ? player.getName() : ((Entity) player).getWorld().getName());
text = text.replace(PLAYER_WORLD_PLACEHOLDERS[i],
i < 4 ? player.getName() : ((Entity) player).getWorld().getName());
}
} else {
for (int i = 0; i < PLAYER_PLACEHOLDERS.length; i++) {
text = PLAYER_WORLD_PLACEHOLDERS[i].matcher(text).replaceAll(player.getName());
text = text.replace(PLAYER_PLACEHOLDERS[i], player.getName());
}
}
return setPlaceholderAPIPlaceholders(text, player);
Expand All @@ -52,11 +50,8 @@ private static String setPlaceholderAPIPlaceholders(String text, OfflinePlayer p
}
}

private static final Pattern[] CITIZENS_PLACEHOLDERS = { Pattern.compile("<id>"), Pattern.compile("<npc>"),
Pattern.compile("<owner>") };
private static final String[] CITIZENS_PLACEHOLDERS = { "<id>", "<npc>", "<owner>" };
private static boolean PLACEHOLDERAPI_ENABLED = true;
private static final Pattern[] PLAYER_PLACEHOLDERS = { Pattern.compile("<player>"), Pattern.compile("<p>"),
Pattern.compile("@p"), Pattern.compile("%player%") };
private static final Pattern[] PLAYER_WORLD_PLACEHOLDERS = { Pattern.compile("<player>"), Pattern.compile("<p>"),
Pattern.compile("@p"), Pattern.compile("%player%"), Pattern.compile("<world>") };
private static final String[] PLAYER_PLACEHOLDERS = { "<player>", "<p>", "@p", "%player%" };
private static final String[] PLAYER_WORLD_PLACEHOLDERS = { "<player>", "<p>", "@p", "%player%", "<world>" };
}

0 comments on commit 7eb7494

Please sign in to comment.