Compare commits

...

7 Commits

Author SHA1 Message Date
Ruben 64cb8135ad
Merge 26934df8e5 into 882b7c5965 2024-03-11 00:51:25 -06:00
Gabriel Dumitru 882b7c5965
Merge pull request #1046 from PlaceholderAPI/feature/add-plugin-authors
Add Plugin Authors to /papi dump
2024-03-07 22:59:42 +02:00
Gabriel Dumitru 7a0be5edf8
Merge pull request #1040 from DevCyntrix/fix-class-cast-exception
Use the OfflinePlayer$getPlayer method instead of casting to Player class
2024-03-07 22:59:24 +02:00
Andre601 e94328935d
Add Plugin Authors to /papi dump 2024-02-25 14:42:48 +01:00
Ricardo Borutta 403622d205 Use the OfflinePlayer$getPlayer method instead of casting to Player class
You should use this to avoid a class cast exception if some other plugins uses an own Implementation of the offline player.
2024-01-29 10:21:24 +01:00
BlitzOffline 26934df8e5
Added unit tests for the new functionality 2023-03-25 03:25:09 +02:00
BlitzOffline ef73b765de
Make setPlaceholders behavior consistent with setRelationalPlaceholders
Relational placeholders require an underscore after the identifier to be considered valid. For example: `%rel_chatchat_%` is valid but `%rel_chatchat%` is not. Normal placeholders did not require this and `%chatchat%` worked the same as `%chatchat_%`.
2023-03-24 21:22:53 +02:00
5 changed files with 27 additions and 3 deletions

View File

@ -29,7 +29,7 @@ public abstract class PlaceholderHook {
@Nullable
public String onRequest(final OfflinePlayer player, @NotNull final String params) {
if (player != null && player.isOnline()) {
return onPlaceholderRequest((Player) player, params);
return onPlaceholderRequest(player.getPlayer(), params);
}
return onPlaceholderRequest(null, params);

View File

@ -200,7 +200,9 @@ public final class CommandDump extends PlaceholderCommand {
for (final Plugin other : plugins) {
builder.append(" ")
.append(String.format("%-" + size + "s", other.getName()))
.append(" [Version: ")
.append(" [Authors: [")
.append(String.join(", ", other.getDescription().getAuthors()))
.append("], Version: ")
.append(other.getDescription().getVersion())
.append("]")
.append("\n");

View File

@ -67,10 +67,14 @@ public final class CharsReplacer implements Replacer {
hadSpace = true;
break;
}
if (p == closure.tail) {
if (p == closure.tail && identified) {
invalid = false;
break;
}
if (p == closure.tail) {
identifier.append(p);
break;
}
if (p == '_' && !identified) {
identified = true;

View File

@ -30,6 +30,8 @@ import org.jetbrains.annotations.Nullable;
public interface Values {
String NO_ARGUMENTS_PLACEHOLDER = "%player%";
String EMPTY_ARGUMENT_PLACEHOLDER = "%player_%";
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%";
@ -43,6 +45,7 @@ public interface Values {
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_Y = "20";
public static final String PLAYER_Z = "30";
@ -83,6 +86,8 @@ public interface Values {
return PLAYER_Y;
case "z":
return PLAYER_Z;
case "":
return EMPTY_ARGUMENT;
}
return null;

View File

@ -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_Y;
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 me.clip.placeholderapi.Values;
@ -37,6 +38,18 @@ public final class ReplacerUnitTester {
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
void testCharsReplacerProducesExpectedSentence() {
assertEquals(String.format(