mirror of
https://github.com/PlaceholderAPI/PlaceholderAPI
synced 2026-02-26 05:51:12 +01:00
Merge pull request #1178 from PlaceholderAPI/fix/argumentless-expansions
Make setPlaceholders behavior consistent with setRelationalPlaceholders
This commit is contained in:
@@ -22,9 +22,7 @@ package me.clip.placeholderapi.replacer;
|
|||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@@ -68,10 +66,14 @@ public final class CharsReplacer implements Replacer {
|
|||||||
hadSpace = true;
|
hadSpace = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (p == closure.tail) {
|
if (p == closure.tail && identified) {
|
||||||
invalid = false;
|
invalid = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (p == closure.tail) {
|
||||||
|
identifier.append(p);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (p == '_' && !identified) {
|
if (p == '_' && !identified) {
|
||||||
identified = true;
|
identified = true;
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
|
|
||||||
public interface Values {
|
public interface Values {
|
||||||
|
|
||||||
|
String NO_ARGUMENTS_PLACEHOLDER = "%player%";
|
||||||
|
String EMPTY_ARGUMENT_PLACEHOLDER = "%player_%";
|
||||||
String SMALL_TEXT = "My name is %player_name%";
|
String SMALL_TEXT = "My name is %player_name%";
|
||||||
String LARGE_TEXT = "My name is %player_name% and my location is (%player_x%, %player_y%, %player_z%), this placeholder is invalid %server_name%";
|
String LARGE_TEXT = "My name is %player_name% and my location is (%player_x%, %player_y%, %player_z%), this placeholder is invalid %server_name%";
|
||||||
|
|
||||||
@@ -43,6 +45,7 @@ public interface Values {
|
|||||||
|
|
||||||
final class MockPlayerPlaceholderExpansion extends PlaceholderExpansion {
|
final class MockPlayerPlaceholderExpansion extends PlaceholderExpansion {
|
||||||
|
|
||||||
|
public static final String EMPTY_ARGUMENT = "Empty Argument";
|
||||||
public static final String PLAYER_X = "10";
|
public static final String PLAYER_X = "10";
|
||||||
public static final String PLAYER_Y = "20";
|
public static final String PLAYER_Y = "20";
|
||||||
public static final String PLAYER_Z = "30";
|
public static final String PLAYER_Z = "30";
|
||||||
@@ -83,6 +86,8 @@ public interface Values {
|
|||||||
return PLAYER_Y;
|
return PLAYER_Y;
|
||||||
case "z":
|
case "z":
|
||||||
return PLAYER_Z;
|
return PLAYER_Z;
|
||||||
|
case "":
|
||||||
|
return EMPTY_ARGUMENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import static me.clip.placeholderapi.Values.MockPlayerPlaceholderExpansion.PLAYE
|
|||||||
import static me.clip.placeholderapi.Values.MockPlayerPlaceholderExpansion.PLAYER_X;
|
import static me.clip.placeholderapi.Values.MockPlayerPlaceholderExpansion.PLAYER_X;
|
||||||
import static me.clip.placeholderapi.Values.MockPlayerPlaceholderExpansion.PLAYER_Y;
|
import static me.clip.placeholderapi.Values.MockPlayerPlaceholderExpansion.PLAYER_Y;
|
||||||
import static me.clip.placeholderapi.Values.MockPlayerPlaceholderExpansion.PLAYER_Z;
|
import static me.clip.placeholderapi.Values.MockPlayerPlaceholderExpansion.PLAYER_Z;
|
||||||
|
import static me.clip.placeholderapi.Values.MockPlayerPlaceholderExpansion.EMPTY_ARGUMENT;
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
import me.clip.placeholderapi.Values;
|
import me.clip.placeholderapi.Values;
|
||||||
@@ -37,6 +38,18 @@ public final class ReplacerUnitTester {
|
|||||||
Values.CHARS_REPLACER.apply("%player_name%", null, Values.PLACEHOLDERS::get));
|
Values.CHARS_REPLACER.apply("%player_name%", null, Values.PLACEHOLDERS::get));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void charsReplacersDoesNotParsePlaceholdersWithNoArguments() {
|
||||||
|
assertEquals(Values.NO_ARGUMENTS_PLACEHOLDER,
|
||||||
|
Values.CHARS_REPLACER.apply(Values.NO_ARGUMENTS_PLACEHOLDER, null, Values.PLACEHOLDERS::get));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void charsReplacersParsesPlaceholdersWithOneArgumentThatIsEmpty() {
|
||||||
|
assertEquals(EMPTY_ARGUMENT,
|
||||||
|
Values.CHARS_REPLACER.apply(Values.EMPTY_ARGUMENT_PLACEHOLDER, null, Values.PLACEHOLDERS::get));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testCharsReplacerProducesExpectedSentence() {
|
void testCharsReplacerProducesExpectedSentence() {
|
||||||
assertEquals(String.format(
|
assertEquals(String.format(
|
||||||
|
|||||||
Reference in New Issue
Block a user