mirror of
https://github.com/PlaceholderAPI/PlaceholderAPI
synced 2026-01-17 05:48:49 +01:00
Cleanup formatting / spacing
This commit is contained in:
@@ -72,14 +72,16 @@ public class PlaceholderAPI {
|
||||
* @return true if the hook was successfully registered, false if there is already a hook
|
||||
* registered for the specified identifier
|
||||
*/
|
||||
public static boolean registerPlaceholderHook(String identifier,
|
||||
PlaceholderHook placeholderHook) {
|
||||
public static boolean registerPlaceholderHook(String identifier, PlaceholderHook placeholderHook) {
|
||||
Validate.notNull(identifier, "Identifier can not be null");
|
||||
Validate.notNull(placeholderHook, "Placeholderhook can not be null");
|
||||
|
||||
if (isRegistered(identifier)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
placeholders.put(identifier.toLowerCase(), placeholderHook);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -117,6 +119,7 @@ public class PlaceholderAPI {
|
||||
Set<PlaceholderExpansion> set = getPlaceholders().values().stream()
|
||||
.filter(PlaceholderExpansion.class::isInstance).map(PlaceholderExpansion.class::cast)
|
||||
.collect(Collectors.toCollection(HashSet::new));
|
||||
|
||||
return ImmutableSet.copyOf(set);
|
||||
}
|
||||
|
||||
@@ -177,6 +180,7 @@ public class PlaceholderAPI {
|
||||
if (text == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return text.stream().map(line -> setPlaceholders(p, line, pattern))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
@@ -215,24 +219,29 @@ public class PlaceholderAPI {
|
||||
* underscore separating the identifier from the params
|
||||
* @return text with all placeholders set to the corresponding values
|
||||
*/
|
||||
public static String setPlaceholders(OfflinePlayer player, String text,
|
||||
Pattern placeholderPattern) {
|
||||
public static String setPlaceholders(OfflinePlayer player, String text, Pattern placeholderPattern) {
|
||||
if (text == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (placeholders.isEmpty()) {
|
||||
return color(text);
|
||||
}
|
||||
|
||||
Matcher m = placeholderPattern.matcher(text);
|
||||
Map<String, PlaceholderHook> hooks = getPlaceholders();
|
||||
|
||||
while (m.find()) {
|
||||
String format = m.group(1);
|
||||
int index = format.indexOf("_");
|
||||
|
||||
if (index <= 0 || index >= format.length()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String identifier = format.substring(0, index).toLowerCase();
|
||||
String params = format.substring(index + 1);
|
||||
|
||||
if (hooks.containsKey(identifier)) {
|
||||
String value = hooks.get(identifier).onRequest(player, params);
|
||||
if (value != null) {
|
||||
@@ -240,6 +249,7 @@ public class PlaceholderAPI {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return color(text);
|
||||
}
|
||||
|
||||
@@ -256,6 +266,7 @@ public class PlaceholderAPI {
|
||||
if (text == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return text.stream().map(line -> setRelationalPlaceholders(one, two, line))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
@@ -273,30 +284,39 @@ public class PlaceholderAPI {
|
||||
if (text == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (placeholders.isEmpty()) {
|
||||
return color(text);
|
||||
}
|
||||
|
||||
Matcher m = RELATIONAL_PLACEHOLDER_PATTERN.matcher(text);
|
||||
Map<String, PlaceholderHook> hooks = getPlaceholders();
|
||||
|
||||
while (m.find()) {
|
||||
String format = m.group(2);
|
||||
int index = format.indexOf("_");
|
||||
|
||||
if (index <= 0 || index >= format.length()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String identifier = format.substring(0, index).toLowerCase();
|
||||
String params = format.substring(index + 1);
|
||||
|
||||
if (hooks.containsKey(identifier)) {
|
||||
if (!(hooks.get(identifier) instanceof Relational)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Relational rel = (Relational) hooks.get(identifier);
|
||||
String value = rel.onPlaceholderRequest(one, two, params);
|
||||
|
||||
if (value != null) {
|
||||
text = text.replaceAll(Pattern.quote(m.group()), Matcher.quoteReplacement(value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return color(text);
|
||||
}
|
||||
|
||||
@@ -315,9 +335,11 @@ public class PlaceholderAPI {
|
||||
if (placeholders.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
getPlaceholders().forEach((key, value) -> {
|
||||
if (value instanceof PlaceholderExpansion) {
|
||||
PlaceholderExpansion ex = (PlaceholderExpansion) value;
|
||||
|
||||
if (!ex.persist()) {
|
||||
unregisterExpansion(ex);
|
||||
}
|
||||
@@ -330,6 +352,7 @@ public class PlaceholderAPI {
|
||||
Bukkit.getPluginManager().callEvent(new ExpansionRegisterEvent(ex));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -338,6 +361,7 @@ public class PlaceholderAPI {
|
||||
Bukkit.getPluginManager().callEvent(new ExpansionUnregisterEvent(ex));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user