Compare commits

...

7 Commits

Author SHA1 Message Date
armagidon-exception e53264ff51
Merge 659a8378bf 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
Armagidon 659a8378bf Added events for placeholder requests 2023-04-19 15:08:12 +03:00
Armagidon 659d78aa78 Make REPLACER_PERCENT and REPLACER_BRACKET available for hijacking requests 2023-04-19 14:17:19 +03:00
5 changed files with 113 additions and 4 deletions

View File

@ -32,6 +32,7 @@ import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import me.clip.placeholderapi.expansion.Relational;
import me.clip.placeholderapi.expansion.manager.LocalExpansionManager;
import me.clip.placeholderapi.replacer.CharsReplacer;
import me.clip.placeholderapi.replacer.DelegatorReplacer;
import me.clip.placeholderapi.replacer.Replacer;
import me.clip.placeholderapi.replacer.Replacer.Closure;
import me.clip.placeholderapi.util.Msg;
@ -43,8 +44,8 @@ import org.jetbrains.annotations.NotNull;
public final class PlaceholderAPI {
private static final Replacer REPLACER_PERCENT = new CharsReplacer(Closure.PERCENT);
private static final Replacer REPLACER_BRACKET = new CharsReplacer(Closure.BRACKET);
private static final Replacer REPLACER_PERCENT = new DelegatorReplacer(new CharsReplacer(Closure.PERCENT));
private static final Replacer REPLACER_BRACKET = new DelegatorReplacer(new CharsReplacer(Closure.BRACKET));
private static final Pattern PLACEHOLDER_PATTERN = Pattern.compile("[%]([^%]+)[%]");
private static final Pattern BRACKET_PLACEHOLDER_PATTERN = Pattern.compile("[{]([^{}]+)[}]");

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

@ -0,0 +1,78 @@
package me.clip.placeholderapi.events;
import org.bukkit.OfflinePlayer;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import me.clip.placeholderapi.replacer.Replacer;
/**
* Fired when user requests for placeholder replacement via {@link Replacer}
* */
public class PlaceholderRequestEvent extends Event
{
private static final HandlerList HANDLER_LIST = new HandlerList();
private final String input;
private final OfflinePlayer player;
private final Replacer defaultReplacer;
private String output;
public PlaceholderRequestEvent(String input, OfflinePlayer player, Replacer defaultReplacer) {
this.input = input;
this.player = player;
this.defaultReplacer = defaultReplacer;
}
/**
* @return Input string of the request with no replacements
* */
public @NotNull String getInput() {
return input;
}
/**
* @return Player that was used for replacement
*/
public @Nullable OfflinePlayer getPlayer() {
return player;
}
/**
* Returns output that will be provided for this request.
* <br>If the output is equal to null, replacer will be used to provide final result
* @return Output that will be provided for this request
*/
public @Nullable String getOutput() {
return output;
}
/**
* Sets output that will be provided for this request
* <br>If the output is equal to null, replacer will be used to provide final result
* @param output Output that will be provided for this request
*/
public void setOutput(@Nullable String output) {
this.output = output;
}
/**
* @return {@link Replacer} that will be used to provide final result if {@link PlaceholderRequestEvent#getOutput()} is null
*/
public Replacer getDefaultReplacer() {
return defaultReplacer;
}
@NotNull
@Override
public HandlerList getHandlers() {
return HANDLER_LIST;
}
public static HandlerList getHandlerList() {
return HANDLER_LIST;
}
}

View File

@ -0,0 +1,28 @@
package me.clip.placeholderapi.replacer;
import me.clip.placeholderapi.events.PlaceholderRequestEvent;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.function.Function;
public class DelegatorReplacer implements Replacer {
private final Replacer defaultReplacer;
public DelegatorReplacer(Replacer defaultReplacer) {
this.defaultReplacer = defaultReplacer;
}
@Override
public @NotNull String apply(@NotNull String text, @Nullable OfflinePlayer player, @NotNull Function<String, @Nullable PlaceholderExpansion> lookup) {
PlaceholderRequestEvent placeholderRequestEvent = new PlaceholderRequestEvent(text, player, defaultReplacer);
Bukkit.getPluginManager().callEvent(placeholderRequestEvent);
return placeholderRequestEvent.getOutput() == null ? defaultReplacer.apply(text, player, lookup)
: placeholderRequestEvent.getOutput();
}
}