mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-09-25 13:22:52 +02:00
2046 null player placeholder support (#2048)
* Fixes #2046. Handles null players for placeholders. * Remove unused import
This commit is contained in:
parent
1c4fb76828
commit
2629e940c7
@ -6,6 +6,7 @@ import java.util.Map;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import world.bentobox.bentobox.api.placeholders.PlaceholderReplacer;
|
||||
@ -42,9 +43,9 @@ abstract class BasicPlaceholderExpansion extends PlaceholderExpansion {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String onPlaceholderRequest(Player p, @NonNull String placeholder) {
|
||||
if (placeholders.containsKey(placeholder) && p != null) {
|
||||
return placeholders.get(placeholder).onReplace(User.getInstance(p));
|
||||
public String onPlaceholderRequest(@Nullable Player p, @NonNull String placeholder) {
|
||||
if (placeholders.containsKey(placeholder)) {
|
||||
return placeholders.get(placeholder).onReplace(p != null ? User.getInstance(p) : null);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import java.util.regex.Pattern;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
@ -109,7 +110,10 @@ public class PlaceholderAPIHook extends PlaceholderHook {
|
||||
*/
|
||||
@Override
|
||||
@NonNull
|
||||
public String replacePlaceholders(@NonNull Player player, @NonNull String string) {
|
||||
public String replacePlaceholders(@Nullable Player player, @NonNull String string) {
|
||||
if (player == null) {
|
||||
return PlaceholderAPI.setPlaceholders(player, removeGMPlaceholder(string));
|
||||
}
|
||||
// Transform [gamemode] in string to the game mode description name, or remove it for the default replacement
|
||||
String newString = BentoBox.getInstance().getIWM().getAddon(player.getWorld()).map(gm ->
|
||||
string.replace(TextVariables.GAMEMODE, gm.getDescription().getName().toLowerCase())
|
||||
|
@ -116,12 +116,12 @@ public class PlaceholdersManager {
|
||||
|
||||
/**
|
||||
* Replaces the placeholders in this String and returns it.
|
||||
* @param player the Player to get the placeholders for.
|
||||
* @param player the Player to get the placeholders for or null for non-player-specific placeholders
|
||||
* @param string the String to replace the placeholders in.
|
||||
* @return the String with placeholders replaced, or the identical String if no placeholders were available.
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public String replacePlaceholders(@NonNull Player player, @NonNull String string) {
|
||||
public String replacePlaceholders(@Nullable Player player, @NonNull String string) {
|
||||
return getPlaceholderAPIHook().map(papi -> papi.replacePlaceholders(player, string)).orElse(string);
|
||||
}
|
||||
|
||||
@ -131,6 +131,6 @@ public class PlaceholdersManager {
|
||||
*/
|
||||
public void unregisterAll() {
|
||||
getPlaceholderAPIHook().ifPresent(PlaceholderAPIHook::unregisterAll);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user