mirror of
https://github.com/PlaceholderAPI/PlaceholderAPI
synced 2026-02-28 18:45:10 +01:00
Enhance placeholder translation performance and improve code clarity
This commit is contained in:
@@ -20,12 +20,7 @@
|
||||
|
||||
package me.clip.placeholderapi;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -85,7 +80,12 @@ public final class PlaceholderAPI {
|
||||
@NotNull
|
||||
public static List<String> setPlaceholders(final OfflinePlayer player,
|
||||
@NotNull final List<String> text) {
|
||||
return text.stream().map(line -> setPlaceholders(player, line)).collect(Collectors.toList());
|
||||
final String[] parsed = new String[text.size()];
|
||||
int i = 0;
|
||||
for (final String line : text) {
|
||||
parsed[i++] = setPlaceholders(player, line);
|
||||
}
|
||||
return Arrays.asList(parsed);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -140,8 +140,12 @@ public final class PlaceholderAPI {
|
||||
@NotNull
|
||||
public static List<@NotNull String> setBracketPlaceholders(final OfflinePlayer player,
|
||||
@NotNull final List<@NotNull String> text) {
|
||||
return text.stream().map(line -> setBracketPlaceholders(player, line))
|
||||
.collect(Collectors.toList());
|
||||
final String[] parsed = new String[text.size()];
|
||||
int i = 0;
|
||||
for (final String line : text) {
|
||||
parsed[i++] = setBracketPlaceholders(player, line);
|
||||
}
|
||||
return Arrays.asList(parsed);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -179,14 +183,14 @@ public final class PlaceholderAPI {
|
||||
* @param text Text to parse the placeholders in
|
||||
* @return The text containing the parsed relational placeholders
|
||||
*/
|
||||
public static String setRelationalPlaceholders(Player one, Player two, String text) {
|
||||
public static String setRelationalPlaceholders(final Player one, final Player two, @NotNull String text) {
|
||||
final Matcher matcher = RELATIONAL_PLACEHOLDER_PATTERN.matcher(text);
|
||||
|
||||
while (matcher.find()) {
|
||||
final String format = matcher.group(2);
|
||||
final int index = format.indexOf("_");
|
||||
final int index = format.indexOf('_');
|
||||
|
||||
if (index <= 0 || index >= format.length()) {
|
||||
if (index <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -218,9 +222,13 @@ public final class PlaceholderAPI {
|
||||
* @param text text to parse the placeholder values to
|
||||
* @return The text containing the parsed relational placeholders
|
||||
*/
|
||||
public static List<String> setRelationalPlaceholders(Player one, Player two, List<String> text) {
|
||||
return text.stream().map(line -> setRelationalPlaceholders(one, two, line))
|
||||
.collect(Collectors.toList());
|
||||
public static List<String> setRelationalPlaceholders(final Player one, final Player two, final @NotNull List<String> text) {
|
||||
final String[] parsed = new String[text.size()];
|
||||
int i = 0;
|
||||
for (final String line : text) {
|
||||
parsed[i++] = setRelationalPlaceholders(one, two, line);
|
||||
}
|
||||
return Arrays.asList(parsed);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -241,8 +249,7 @@ public final class PlaceholderAPI {
|
||||
*/
|
||||
@NotNull
|
||||
public static Set<String> getRegisteredIdentifiers() {
|
||||
return ImmutableSet
|
||||
.copyOf(PlaceholderAPIPlugin.getInstance().getLocalExpansionManager().getIdentifiers());
|
||||
return PlaceholderAPIPlugin.getInstance().getLocalExpansionManager().getIdentifiers();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user