mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-12 13:54:22 +01:00
Handles placeholder reloading. (#1503)
https://github.com/BentoBoxWorld/BentoBox/issues/1502
This commit is contained in:
parent
42622d6e38
commit
2a3ac0bd3b
@ -39,6 +39,10 @@ public class BentoBoxReloadCommand extends ConfirmableCommand {
|
||||
public boolean execute(User user, String label, List<String> args) {
|
||||
if (args.isEmpty()) {
|
||||
this.askConfirmation(user, user.getTranslation("commands.bentobox.reload.warning"), () -> {
|
||||
|
||||
// Unregister all placeholders
|
||||
getPlugin().getPlaceholdersManager().unregisterAll();
|
||||
|
||||
// Close all open panels
|
||||
PanelListenerManager.closeAllPanels();
|
||||
|
||||
@ -54,6 +58,9 @@ public class BentoBoxReloadCommand extends ConfirmableCommand {
|
||||
getPlugin().getLocalesManager().reloadLanguages();
|
||||
user.sendMessage("commands.bentobox.reload.locales-reloaded");
|
||||
|
||||
// Register new default gamemode placeholders
|
||||
getPlugin().getAddonsManager().getGameModeAddons().forEach(getPlugin().getPlaceholdersManager()::registerDefaultPlaceholders);
|
||||
|
||||
// Fire ready event
|
||||
Bukkit.getPluginManager().callEvent(new BentoBoxReadyEvent());
|
||||
});
|
||||
|
@ -1,7 +1,9 @@
|
||||
package world.bentobox.bentobox.hooks.placeholders;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
@ -22,10 +24,15 @@ public class PlaceholderAPIHook extends PlaceholderHook {
|
||||
|
||||
private BentoBoxPlaceholderExpansion bentoboxExpansion;
|
||||
private Map<Addon, AddonPlaceholderExpansion> addonsExpansions;
|
||||
private final Set<String> bentoBoxPlaceholders;
|
||||
private final Map<Addon, Set<String>> addonPlaceholders;
|
||||
|
||||
|
||||
public PlaceholderAPIHook() {
|
||||
super("PlaceholderAPI");
|
||||
this.addonsExpansions = new HashMap<>();
|
||||
this.bentoBoxPlaceholders = new HashSet<>();
|
||||
this.addonPlaceholders = new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -50,6 +57,7 @@ public class PlaceholderAPIHook extends PlaceholderHook {
|
||||
@Override
|
||||
public void registerPlaceholder(@NonNull String placeholder, @NonNull PlaceholderReplacer replacer) {
|
||||
bentoboxExpansion.registerPlaceholder(placeholder, replacer);
|
||||
this.bentoBoxPlaceholders.add(placeholder);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -62,6 +70,7 @@ public class PlaceholderAPIHook extends PlaceholderHook {
|
||||
AddonPlaceholderExpansion addonPlaceholderExpansion = new AddonPlaceholderExpansion(addon);
|
||||
addonPlaceholderExpansion.register();
|
||||
addonsExpansions.put(addon, addonPlaceholderExpansion);
|
||||
this.addonPlaceholders.computeIfAbsent(addon, k -> new HashSet<>()).add(placeholder);
|
||||
}
|
||||
|
||||
addonsExpansions.get(addon).registerPlaceholder(placeholder, replacer);
|
||||
@ -94,11 +103,20 @@ public class PlaceholderAPIHook extends PlaceholderHook {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
@NonNull
|
||||
public String replacePlaceholders(@NonNull Player player, @NonNull String string) {
|
||||
return PlaceholderAPI.setPlaceholders(player, string);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void unregisterAll() {
|
||||
this.bentoBoxPlaceholders.forEach(this::unregisterPlaceholder);
|
||||
this.addonPlaceholders.forEach((addon,list) -> list.forEach(placeholder -> this.unregisterPlaceholder(addon, placeholder)));
|
||||
}
|
||||
}
|
||||
|
@ -68,4 +68,10 @@ public abstract class PlaceholderHook extends Hook {
|
||||
*/
|
||||
@NonNull
|
||||
public abstract String replacePlaceholders(@NonNull Player player, @NonNull String string);
|
||||
|
||||
/**
|
||||
* Unregister all previously registered placeholders
|
||||
* @since 1.15.0
|
||||
*/
|
||||
public abstract void unregisterAll();
|
||||
}
|
||||
|
@ -122,10 +122,15 @@ public class PlaceholdersManager {
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public String replacePlaceholders(@NonNull Player player, @NonNull String string) {
|
||||
Optional<PlaceholderAPIHook> papi = getPlaceholderAPIHook();
|
||||
if (papi.isPresent()) {
|
||||
string = papi.get().replacePlaceholders(player, string);
|
||||
return getPlaceholderAPIHook().map(papi -> papi.replacePlaceholders(player, string)).orElse(string);
|
||||
}
|
||||
return string;
|
||||
|
||||
/**
|
||||
* Unregisters all the placeholders.
|
||||
* @since 1.15.0
|
||||
*/
|
||||
public void unregisterAll() {
|
||||
getPlaceholderAPIHook().ifPresent(hook -> hook.unregisterAll());
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user