Refactoring, temporarily remove PlaceholderAPI support

This commit is contained in:
filoghost 2021-12-07 21:12:08 +01:00
parent 4e21d317f3
commit 69f2ecbd23
20 changed files with 207 additions and 218 deletions

View File

@ -33,7 +33,7 @@ public class HologramLineParser {
} else {
// Don't apply display format inside placeholders
String displayText = StringWithPlaceholders.of(serializedLine).replaceLiteralParts(DisplayFormat::apply);
String displayText = StringWithPlaceholders.of(serializedLine).replaceStrings(DisplayFormat::apply);
hologramLine = hologram.createTextLine(displayText, serializedLine);
}

View File

@ -6,11 +6,8 @@
package me.filoghost.holographicdisplays.plugin.hologram.tracking;
import me.filoghost.fcommons.Preconditions;
import me.filoghost.holographicdisplays.plugin.bridge.placeholderapi.PlaceholderAPIHook;
import me.filoghost.holographicdisplays.plugin.placeholder.parsing.PlaceholderOccurrence;
import me.filoghost.holographicdisplays.plugin.placeholder.parsing.StringWithPlaceholders;
import me.filoghost.holographicdisplays.plugin.placeholder.tracking.ActivePlaceholderTracker;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -24,7 +21,6 @@ class DisplayText {
private @Nullable StringWithPlaceholders unreplacedText;
private boolean allowPlaceholders;
private @Nullable String globalText;
private boolean containsPlaceholderAPIPattern;
private @Nullable Boolean containsIndividualPlaceholders;
private long lastPlaceholderRegistryVersion;
@ -36,9 +32,6 @@ class DisplayText {
if (!allowPlaceholders || unreplacedText == null) {
return false;
}
if (containsPlaceholderAPIPattern) {
return true;
}
long currentPlaceholderRegistryVersion = placeholderTracker.getRegistryVersion();
if (containsIndividualPlaceholders == null || lastPlaceholderRegistryVersion != currentPlaceholderRegistryVersion) {
containsIndividualPlaceholders = placeholderTracker.containsIndividualPlaceholders(unreplacedText);
@ -50,8 +43,6 @@ class DisplayText {
void setUnreplacedText(@Nullable String text) {
unreplacedText = text != null ? StringWithPlaceholders.of(text) : null;
globalText = null;
containsPlaceholderAPIPattern = unreplacedText != null
&& unreplacedText.anyLiteralPartMatch(PlaceholderAPIHook::containsPlaceholderPattern);
containsIndividualPlaceholders = null;
}
@ -77,8 +68,7 @@ class DisplayText {
if (containsIndividualPlaceholders()) {
this.globalText = null;
for (TextLineViewer viewer : viewers) {
String individualText = computeIndividualText(viewer);
if (viewer.updateIndividualText(individualText)) {
if (viewer.updateIndividualText()) {
changed = true;
}
}
@ -95,7 +85,7 @@ class DisplayText {
private @Nullable String computeGlobalText() {
if (allowPlaceholders && unreplacedText != null && unreplacedText.containsPlaceholders()) {
return unreplacedText.replacePlaceholders(placeholderTracker::computeGlobalReplacement);
return unreplacedText.replacePlaceholders(null, placeholderTracker);
} else {
return unreplacedText != null ? unreplacedText.getString() : null;
}
@ -103,22 +93,8 @@ class DisplayText {
public @NotNull String computeIndividualText(Viewer viewer) {
Preconditions.notNull(unreplacedText, "unreplacedText");
Player player = viewer.getPlayer();
return unreplacedText.replaceParts(
(PlaceholderOccurrence placeholderOccurrence) -> {
return placeholderTracker.computeReplacement(placeholderOccurrence, player);
},
(String literalPart) -> {
if (containsPlaceholderAPIPattern
&& PlaceholderAPIHook.isEnabled()
&& PlaceholderAPIHook.containsPlaceholderPattern(literalPart)) {
return PlaceholderAPIHook.replacePlaceholders(player, literalPart);
} else {
return literalPart;
}
}
);
return unreplacedText.replacePlaceholders(viewer.getPlayer(), placeholderTracker);
}
}

View File

@ -50,7 +50,8 @@ class TextLineViewer extends Viewer {
}
}
public boolean updateIndividualText(String individualText) {
public boolean updateIndividualText() {
String individualText = displayText.computeIndividualText(this);
if (!Objects.equals(this.individualText, individualText)) {
this.individualText = individualText;
return true;

View File

@ -3,7 +3,7 @@
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.holographicdisplays.plugin.placeholder.parsing;
package me.filoghost.holographicdisplays.plugin.placeholder;
import me.filoghost.fcommons.collection.CaseInsensitiveString;

View File

@ -3,7 +3,7 @@
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.holographicdisplays.plugin.placeholder.parsing;
package me.filoghost.holographicdisplays.plugin.placeholder;
import me.filoghost.fcommons.Strings;
import org.jetbrains.annotations.NotNull;

View File

@ -3,7 +3,7 @@
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.holographicdisplays.plugin.placeholder.parsing;
package me.filoghost.holographicdisplays.plugin.placeholder;
import me.filoghost.fcommons.collection.CaseInsensitiveString;
import org.bukkit.plugin.Plugin;

View File

@ -0,0 +1,77 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.holographicdisplays.plugin.placeholder.parsing;
import me.filoghost.holographicdisplays.plugin.placeholder.PlaceholderOccurrence;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
class Parser {
private static final char PLACEHOLDER_START_CHAR = '{';
private static final char PLACEHOLDER_END_CHAR = '}';
/**
* Returns null if the string doesn't contain any placeholder (optimization).
*/
static @Nullable List<Part> parse(@NotNull String string) {
List<Part> parts = null;
int placeholderStartIndex = -1;
int lastAppendIndex = 0;
for (int currentIndex = 0; currentIndex < string.length(); currentIndex++) {
char currentChar = string.charAt(currentIndex);
if (placeholderStartIndex >= 0) {
// Inside placeholder
if (currentChar == PLACEHOLDER_END_CHAR) {
int endIndex = currentIndex + 1;
// The unparsed string includes the opening and closing tags (e.g.: "{online: lobby}")
String unparsedString = string.substring(placeholderStartIndex, endIndex);
// The content string does NOT include the opening and closing tags (e.g.: "online: lobby")
String contentString = unparsedString.substring(1, unparsedString.length() - 1);
PlaceholderOccurrence content = PlaceholderOccurrence.parse(contentString);
if (parts == null) {
parts = new ArrayList<>();
}
// Append leading literal part (if any)
if (placeholderStartIndex != lastAppendIndex) {
parts.add(new StringPart(string.substring(lastAppendIndex, placeholderStartIndex)));
}
// Append placeholder part
parts.add(new PlaceholderPart(content, unparsedString));
lastAppendIndex = endIndex;
placeholderStartIndex = -1;
} else if (currentChar == PLACEHOLDER_START_CHAR) {
// Nested placeholder, ignore outer placeholder and update start index
placeholderStartIndex = currentIndex;
}
} else {
// Outside placeholders, just look for the start of a placeholder
if (currentChar == PLACEHOLDER_START_CHAR) {
placeholderStartIndex = currentIndex;
}
}
}
// Append trailing literal part (if any)
if (lastAppendIndex != string.length() && parts != null) {
parts.add(new StringPart(string.substring(lastAppendIndex)));
}
return parts;
}
}

View File

@ -0,0 +1,10 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.holographicdisplays.plugin.placeholder.parsing;
interface Part {
}

View File

@ -0,0 +1,37 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.holographicdisplays.plugin.placeholder.parsing;
import me.filoghost.holographicdisplays.plugin.placeholder.PlaceholderOccurrence;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
class PlaceholderPart implements Part {
private final PlaceholderOccurrence placeholderOccurrence;
private final String unreplacedString;
PlaceholderPart(@NotNull PlaceholderOccurrence placeholderOccurrence, @NotNull String unreplacedString) {
this.placeholderOccurrence = placeholderOccurrence;
this.unreplacedString = unreplacedString;
}
@NotNull String getValue(@Nullable Player player, PlaceholderReplaceFunction placeholderReplaceFunction) {
String replacement = placeholderReplaceFunction.getReplacement(player, placeholderOccurrence);
if (replacement != null) {
return replacement;
} else {
// If no replacement is provided return the unreplaced placeholder string
return unreplacedString;
}
}
PlaceholderOccurrence getPlaceholderOccurrence() {
return placeholderOccurrence;
}
}

View File

@ -5,14 +5,16 @@
*/
package me.filoghost.holographicdisplays.plugin.placeholder.parsing;
import me.filoghost.holographicdisplays.plugin.placeholder.PlaceholderOccurrence;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@FunctionalInterface
public interface PlaceholderReplaceFunction {
PlaceholderReplaceFunction NO_REPLACEMENTS = placeholderOccurrence -> null;
PlaceholderReplaceFunction NO_REPLACEMENTS = (player, placeholderOccurrence) -> null;
@Nullable String getReplacement(@NotNull PlaceholderOccurrence placeholderOccurrence);
@Nullable String getReplacement(@Nullable Player player, @NotNull PlaceholderOccurrence placeholderOccurrence);
}

View File

@ -0,0 +1,22 @@
/*
* Copyright (C) filoghost and contributors
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package me.filoghost.holographicdisplays.plugin.placeholder.parsing;
import org.jetbrains.annotations.NotNull;
class StringPart implements Part {
private final String value;
StringPart(@NotNull String value) {
this.value = value;
}
@NotNull String getValue(StringReplaceFunction stringReplaceFunction) {
return stringReplaceFunction.getReplacement(value);
}
}

View File

@ -5,29 +5,27 @@
*/
package me.filoghost.holographicdisplays.plugin.placeholder.parsing;
import me.filoghost.holographicdisplays.plugin.placeholder.PlaceholderOccurrence;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.function.Predicate;
public final class StringWithPlaceholders {
private static final char PLACEHOLDER_END_CHAR = '}';
private static final char PLACEHOLDER_START_CHAR = '{';
private final @NotNull String string;
private final @Nullable List<StringPart> stringParts;
private final @Nullable List<Part> parts;
public static @NotNull StringWithPlaceholders of(@NotNull String string) {
return new StringWithPlaceholders(string, splitToParts(string));
return new StringWithPlaceholders(string, Parser.parse(string));
}
private StringWithPlaceholders(@NotNull String string, @Nullable List<StringPart> stringParts) {
StringWithPlaceholders(@NotNull String string, @Nullable List<Part> parts) {
this.string = string;
this.stringParts = stringParts;
this.parts = parts;
}
public @NotNull String getString() {
@ -35,12 +33,12 @@ public final class StringWithPlaceholders {
}
public boolean containsPlaceholders() {
if (stringParts == null) {
if (parts == null) {
return false;
}
for (StringPart stringPart : stringParts) {
if (stringPart instanceof PlaceholderPart) {
for (Part part : parts) {
if (part instanceof PlaceholderPart) {
return true;
}
}
@ -49,13 +47,13 @@ public final class StringWithPlaceholders {
}
public boolean anyPlaceholderMatch(Predicate<PlaceholderOccurrence> filter) {
if (stringParts == null) {
if (parts == null) {
return false;
}
for (StringPart stringPart : stringParts) {
if (stringPart instanceof PlaceholderPart) {
PlaceholderPart placeholderPart = (PlaceholderPart) stringPart;
for (Part part : parts) {
if (part instanceof PlaceholderPart) {
PlaceholderPart placeholderPart = (PlaceholderPart) part;
if (filter.test(placeholderPart.getPlaceholderOccurrence())) {
return true;
}
@ -65,104 +63,39 @@ public final class StringWithPlaceholders {
return false;
}
public boolean anyLiteralPartMatch(Predicate<String> filter) {
if (stringParts == null) {
return filter.test(string);
}
for (StringPart stringPart : stringParts) {
if (stringPart instanceof LiteralPart) {
if (filter.test(stringPart.getRawValue())) {
return true;
}
}
}
return false;
public @NotNull String replacePlaceholders(Player player, PlaceholderReplaceFunction replaceFunction) {
return replace(player, replaceFunction, StringReplaceFunction.NO_REPLACEMENTS);
}
public @NotNull String replacePlaceholders(PlaceholderReplaceFunction replaceFunction) {
return replaceParts(replaceFunction, StringReplaceFunction.NO_REPLACEMENTS);
public @NotNull String replaceStrings(StringReplaceFunction replaceFunction) {
return replace(null, PlaceholderReplaceFunction.NO_REPLACEMENTS, replaceFunction);
}
public @NotNull String replaceLiteralParts(StringReplaceFunction replaceFunction) {
return replaceParts(PlaceholderReplaceFunction.NO_REPLACEMENTS, replaceFunction);
}
public @NotNull String replaceParts(
private @NotNull String replace(
Player player,
PlaceholderReplaceFunction placeholderReplaceFunction,
StringReplaceFunction literalPartReplaceFunction) {
if (stringParts == null) {
if (parts == null) {
return literalPartReplaceFunction.getReplacement(string);
}
StringBuilder output = new StringBuilder(string.length());
for (StringPart part : stringParts) {
if (part instanceof LiteralPart) {
output.append(literalPartReplaceFunction.getReplacement(part.getRawValue()));
for (Part part : parts) {
String replacement;
if (part instanceof StringPart) {
replacement = ((StringPart) part).getValue(literalPartReplaceFunction);
} else if (part instanceof PlaceholderPart) {
replacement = ((PlaceholderPart) part).getValue(player, placeholderReplaceFunction);
} else {
output.append(part.getValue(placeholderReplaceFunction));
throw new AssertionError();
}
output.append(replacement);
}
return output.toString();
}
private static @Nullable List<StringPart> splitToParts(@NotNull String string) {
int placeholderStartIndex = -1;
int lastAppendIndex = 0;
List<StringPart> stringParts = null; // Lazy initialization
for (int currentIndex = 0; currentIndex < string.length(); currentIndex++) {
char currentChar = string.charAt(currentIndex);
if (placeholderStartIndex >= 0) {
// Inside placeholder
if (currentChar == PLACEHOLDER_END_CHAR) {
int endIndex = currentIndex + 1;
// The unparsed string includes the opening and closing tags (e.g.: "{online: lobby}")
String unparsedString = string.substring(placeholderStartIndex, endIndex);
// The content string does NOT include the opening and closing tags (e.g.: "online: lobby")
String contentString = unparsedString.substring(1, unparsedString.length() - 1);
PlaceholderOccurrence content = PlaceholderOccurrence.parse(contentString);
if (stringParts == null) {
stringParts = new ArrayList<>();
}
// Append leading literal part (if any)
if (placeholderStartIndex != lastAppendIndex) {
stringParts.add(new LiteralPart(string.substring(lastAppendIndex, placeholderStartIndex)));
}
// Append placeholder part
stringParts.add(new PlaceholderPart(content, unparsedString));
lastAppendIndex = endIndex;
placeholderStartIndex = -1;
} else if (currentChar == PLACEHOLDER_START_CHAR) {
// Nested placeholder, ignore outer placeholder and update start index
placeholderStartIndex = currentIndex;
}
} else {
// Outside placeholders, just look for the start of a placeholder
if (currentChar == PLACEHOLDER_START_CHAR) {
placeholderStartIndex = currentIndex;
}
}
}
// Append trailing literal part (if any)
if (lastAppendIndex != string.length() && stringParts != null) {
stringParts.add(new LiteralPart(string.substring(lastAppendIndex)));
}
return stringParts;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
@ -182,66 +115,4 @@ public final class StringWithPlaceholders {
}
private interface StringPart {
String getValue(PlaceholderReplaceFunction placeholderReplaceFunction);
String getRawValue();
}
private static class LiteralPart implements StringPart {
private final String value;
LiteralPart(@NotNull String value) {
this.value = value;
}
@Override
public String getValue(PlaceholderReplaceFunction placeholderReplaceFunction) {
return value;
}
@Override
public String getRawValue() {
return value;
}
}
private static class PlaceholderPart implements StringPart {
private final PlaceholderOccurrence placeholderOccurrence;
private final String unreplacedString;
PlaceholderPart(@NotNull PlaceholderOccurrence placeholderOccurrence, @NotNull String unreplacedString) {
this.placeholderOccurrence = placeholderOccurrence;
this.unreplacedString = unreplacedString;
}
@Override
public String getValue(PlaceholderReplaceFunction placeholderReplaceFunction) {
String replacement = placeholderReplaceFunction.getReplacement(placeholderOccurrence);
if (replacement != null) {
return replacement;
} else {
// If no replacement is provided return the unreplaced placeholder string
return unreplacedString;
}
}
@Override
public String getRawValue() {
return unreplacedString;
}
public PlaceholderOccurrence getPlaceholderOccurrence() {
return placeholderOccurrence;
}
}
}

View File

@ -8,8 +8,8 @@ package me.filoghost.holographicdisplays.plugin.placeholder.registry;
import me.filoghost.holographicdisplays.api.beta.placeholder.RegisteredPlaceholder;
import me.filoghost.holographicdisplays.plugin.placeholder.PlaceholderException;
import me.filoghost.holographicdisplays.plugin.placeholder.StandardPlaceholder;
import me.filoghost.holographicdisplays.plugin.placeholder.parsing.PlaceholderIdentifier;
import me.filoghost.holographicdisplays.plugin.placeholder.parsing.PluginName;
import me.filoghost.holographicdisplays.plugin.placeholder.PlaceholderIdentifier;
import me.filoghost.holographicdisplays.plugin.placeholder.PluginName;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

View File

@ -15,9 +15,9 @@ import me.filoghost.holographicdisplays.api.beta.placeholder.IndividualPlacehold
import me.filoghost.holographicdisplays.api.beta.placeholder.IndividualPlaceholderFactory;
import me.filoghost.holographicdisplays.api.beta.placeholder.IndividualPlaceholderReplacementSupplier;
import me.filoghost.holographicdisplays.api.beta.placeholder.RegisteredPlaceholder;
import me.filoghost.holographicdisplays.plugin.placeholder.parsing.PlaceholderIdentifier;
import me.filoghost.holographicdisplays.plugin.placeholder.parsing.PlaceholderOccurrence;
import me.filoghost.holographicdisplays.plugin.placeholder.parsing.PluginName;
import me.filoghost.holographicdisplays.plugin.placeholder.PlaceholderIdentifier;
import me.filoghost.holographicdisplays.plugin.placeholder.PlaceholderOccurrence;
import me.filoghost.holographicdisplays.plugin.placeholder.PluginName;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.Nullable;

View File

@ -30,7 +30,7 @@ abstract class ActivePlaceholder implements TickExpiringValue {
return lastRequestTick;
}
final @Nullable String computeReplacement(Player player, long currentTick) throws PlaceholderException {
final @Nullable String computeReplacement(@Nullable Player player, long currentTick) throws PlaceholderException {
this.lastRequestTick = currentTick;
return doComputeReplacement(player, currentTick);
}

View File

@ -6,8 +6,9 @@
package me.filoghost.holographicdisplays.plugin.placeholder.tracking;
import me.filoghost.holographicdisplays.plugin.placeholder.PlaceholderException;
import me.filoghost.holographicdisplays.plugin.placeholder.PlaceholderOccurrence;
import me.filoghost.holographicdisplays.plugin.placeholder.StandardPlaceholder;
import me.filoghost.holographicdisplays.plugin.placeholder.parsing.PlaceholderOccurrence;
import me.filoghost.holographicdisplays.plugin.placeholder.parsing.PlaceholderReplaceFunction;
import me.filoghost.holographicdisplays.plugin.placeholder.parsing.StringWithPlaceholders;
import me.filoghost.holographicdisplays.plugin.placeholder.registry.PlaceholderExpansion;
import me.filoghost.holographicdisplays.plugin.placeholder.registry.PlaceholderRegistry;
@ -20,7 +21,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.Objects;
public class ActivePlaceholderTracker {
public class ActivePlaceholderTracker implements PlaceholderReplaceFunction {
private final PlaceholderRegistry registry;
private final TickClock tickClock;
@ -56,22 +57,13 @@ public class ActivePlaceholderTracker {
activePlaceholders.clearUnusedEntries(tickClock.getCurrentTick());
}
public @Nullable String computeGlobalReplacement(PlaceholderOccurrence placeholderOccurrence) {
@Override
public @Nullable String getReplacement(@Nullable Player player, @NotNull PlaceholderOccurrence placeholderOccurrence) {
try {
ActivePlaceholder activePlaceholder = trackAndGetPlaceholder(placeholderOccurrence);
if (activePlaceholder.isIndividual()) {
if (player == null && activePlaceholder.isIndividual()) {
return null;
}
return activePlaceholder.computeReplacement(null, tickClock.getCurrentTick());
} catch (PlaceholderException e) {
exceptionHandler.handle(e);
return "[Error]";
}
}
public @Nullable String computeReplacement(PlaceholderOccurrence placeholderOccurrence, Player player) {
try {
ActivePlaceholder activePlaceholder = trackAndGetPlaceholder(placeholderOccurrence);
return activePlaceholder.computeReplacement(player, tickClock.getCurrentTick());
} catch (PlaceholderException e) {
exceptionHandler.handle(e);

View File

@ -7,7 +7,7 @@ package me.filoghost.holographicdisplays.plugin.placeholder.tracking;
import me.filoghost.holographicdisplays.plugin.placeholder.PlaceholderException;
import me.filoghost.holographicdisplays.plugin.placeholder.StandardPlaceholder;
import me.filoghost.holographicdisplays.plugin.placeholder.parsing.PlaceholderOccurrence;
import me.filoghost.holographicdisplays.plugin.placeholder.PlaceholderOccurrence;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

View File

@ -7,7 +7,7 @@ package me.filoghost.holographicdisplays.plugin.placeholder.tracking;
import me.filoghost.holographicdisplays.plugin.placeholder.PlaceholderException;
import me.filoghost.holographicdisplays.plugin.placeholder.StandardPlaceholder;
import me.filoghost.holographicdisplays.plugin.placeholder.parsing.PlaceholderOccurrence;
import me.filoghost.holographicdisplays.plugin.placeholder.PlaceholderOccurrence;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

View File

@ -7,7 +7,7 @@ package me.filoghost.holographicdisplays.plugin.placeholder.tracking;
import me.filoghost.holographicdisplays.plugin.placeholder.PlaceholderException;
import me.filoghost.holographicdisplays.plugin.placeholder.StandardPlaceholder;
import me.filoghost.holographicdisplays.plugin.placeholder.parsing.PlaceholderOccurrence;
import me.filoghost.holographicdisplays.plugin.placeholder.PlaceholderOccurrence;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

View File

@ -5,6 +5,7 @@
*/
package me.filoghost.holographicdisplays.plugin.placeholder.parsing;
import me.filoghost.holographicdisplays.plugin.placeholder.PlaceholderOccurrence;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
@ -24,7 +25,7 @@ class StringWithPlaceholdersTest {
boolean expectedContainsPlaceholders = expectedOutput.contains("#");
StringWithPlaceholders s = StringWithPlaceholders.of(input);
assertThat(s.replacePlaceholders(occurrence -> "#")).isEqualTo(expectedOutput);
assertThat(s.replacePlaceholders(null, (player, occurrence) -> "#")).isEqualTo(expectedOutput);
assertThat(s.containsPlaceholders()).isEqualTo(expectedContainsPlaceholders);
}
@ -45,7 +46,7 @@ class StringWithPlaceholdersTest {
@MethodSource("replaceLiteralPartsTestArguments")
void replaceLiteralParts(String input, String expectedOutput) {
StringWithPlaceholders s = StringWithPlaceholders.of(input);
assertThat(s.replaceLiteralParts(literalPart -> "_")).isEqualTo(expectedOutput);
assertThat(s.replaceStrings(literalPart -> "_")).isEqualTo(expectedOutput);
}
static Stream<Arguments> replaceLiteralPartsTestArguments() {
@ -61,7 +62,7 @@ class StringWithPlaceholdersTest {
void skipReplacing() {
String input = "{p} a {p} b {p}";
StringWithPlaceholders s = StringWithPlaceholders.of(input);
assertThat(s.replacePlaceholders(occurrence -> null)).isEqualTo(input);
assertThat(s.replacePlaceholders(null, (player, occurrence) -> null)).isEqualTo(input);
}
@ParameterizedTest(name = "[{index}] {0} -> {1}, {2}, {3}")
@ -70,7 +71,7 @@ class StringWithPlaceholdersTest {
StringWithPlaceholders s = StringWithPlaceholders.of(input);
List<PlaceholderOccurrence> placeholders = new ArrayList<>();
s.replacePlaceholders(occurrence -> {
s.replacePlaceholders(null, (player, occurrence) -> {
placeholders.add(occurrence); // Just collect occurrences
return null;
});