+ * Expansions that do not use the e-cloud and instead register from the dependency should set this to true + * to ensure that your placeholder expansion is not unregistered when the papi reload command is used + */ + public boolean persist() { + return true; + } + + @Override + public @Nullable String onRequest(@Nullable OfflinePlayer player, @NotNull String params) { + String[] parameters = params.split("_"); + AetheriaPlaceholder placeholder = PLACEHOLDERS.get(parameters[0]); + // Attempt to fetch the placeholder with the provided id + if (placeholder == null) { + log.error("Tried to fetch an unregistered placeholder: " + parameters[0]); + return null; + } + // Ensure the correct amount of parameters is provided + if (parameters.length - 1 < placeholder.getRequiredParameterCount()) { + log.error("Invalid placeholders provided for {}, provided = {}, required = {}", + placeholder.getIdentifier(), + parameters.length - 1, + placeholder.getRequiredParameterCount()); + return null; + } + // Trim the placeholder identifier from the parameters before parsing + return placeholder.parse((Player) player, parameters.length > 1 ? Arrays.copyOfRange(parameters, 1, parameters.length) : parameters); + } + } +} \ No newline at end of file diff --git a/src/main/java/cc/fascinated/worldsize/WorldSizeManager.java b/src/main/java/cc/fascinated/worldsize/WorldSizeManager.java index 07b0671..9011e8b 100644 --- a/src/main/java/cc/fascinated/worldsize/WorldSizeManager.java +++ b/src/main/java/cc/fascinated/worldsize/WorldSizeManager.java @@ -2,6 +2,7 @@ package cc.fascinated.worldsize; import cc.fascinated.Aetheria; import cc.fascinated.command.CommandManager; +import cc.fascinated.placeholder.PlaceholderManager; import cc.fascinated.worldsize.impl.WorldSizeCommand; import lombok.Getter; import org.bukkit.Bukkit; @@ -31,6 +32,7 @@ public class WorldSizeManager { public WorldSizeManager() { CommandManager.registerCommand(new WorldSizeCommand()); + PlaceholderManager.registerPlaceholder(new WorldSizePlaceholder()); Aetheria.INSTANCE.getServer().getAsyncScheduler().runAtFixedRate(Aetheria.INSTANCE, (task) -> { calculateTotalWorldSize(); diff --git a/src/main/java/cc/fascinated/worldsize/WorldSizePlaceholder.java b/src/main/java/cc/fascinated/worldsize/WorldSizePlaceholder.java new file mode 100644 index 0000000..e9e8db8 --- /dev/null +++ b/src/main/java/cc/fascinated/worldsize/WorldSizePlaceholder.java @@ -0,0 +1,31 @@ +package cc.fascinated.worldsize; + +import cc.fascinated.placeholder.AetheriaPlaceholder; +import cc.fascinated.utils.FormatterUtils; +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.Nullable; + +public class WorldSizePlaceholder implements AetheriaPlaceholder { + + @Override + public String getIdentifier() { + return "worldsize"; + } + + @Override + public String parse(@Nullable Player player, String[] params) { + World world = Bukkit.getWorld(params[0].replaceAll("-", "_")); + if (world == null) { + return "-1"; + } + long size = WorldSizeManager.getWorldSizes().get(world); + return FormatterUtils.formatBytes(size); + } + + @Override + public int getRequiredParameterCount() { + return 1; + } +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index a1ed6ee..e540806 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,3 +1,9 @@ +influxdb: + url: "http://localhost:8086" + token: "aetheria" + org: "aetheria" + bucket: "aetheria" + help-command: - "&e/help &7- &fShows this help message" - "&e/kill &7- &fKills you" diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index d7ae89c..d26c4f8 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,9 @@ name: Aetheria main: cc.fascinated.Aetheria version: 1.0 +author: Fascinated +depend: + - PlaceholderAPI commands: totaljoins: description: "Shows the total amount of joins"