diff --git a/src/org/polymart/mcplugin/Main.java b/src/org/polymart/mcplugin/Main.java index ecc6938..e225e6d 100644 --- a/src/org/polymart/mcplugin/Main.java +++ b/src/org/polymart/mcplugin/Main.java @@ -16,6 +16,7 @@ import org.polymart.mcplugin.api.PolymartAccount; import org.polymart.mcplugin.commands.PolymartCommand; import org.polymart.mcplugin.commands.UpdateCommand; +import org.polymart.mcplugin.hooks.PolymartExpansion; import org.polymart.mcplugin.server.UploadServerInfo; import java.util.*; @@ -39,6 +40,10 @@ public void onEnable(){ UpdateCheck.setup(); UploadServerInfo.setup(); + if (getServer().getPluginManager().getPlugin("PlaceholderAPI") != null){ + new PolymartExpansion(this).register(); + } + this.getCommand("polymart").setExecutor(new PolymartCommand()); this.getCommand("update").setExecutor(new UpdateCommand()); diff --git a/src/org/polymart/mcplugin/actions/UpdateCheck.java b/src/org/polymart/mcplugin/actions/UpdateCheck.java index 082ba8f..90917d2 100644 --- a/src/org/polymart/mcplugin/actions/UpdateCheck.java +++ b/src/org/polymart/mcplugin/actions/UpdateCheck.java @@ -30,6 +30,7 @@ import java.text.SimpleDateFormat; import java.util.*; import java.util.jar.JarFile; +import java.util.stream.Collectors; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import java.util.zip.ZipOutputStream; @@ -373,6 +374,7 @@ public static void checkForUpdatesResponse(JSONWrapper wrapper, Map a.name)); + canDownloadFromPolymart = canDownloadFromPolymart.stream().filter(Objects::nonNull).collect(Collectors.toList()); canDownloadFromPolymart.sort(Comparator.comparing((UpdateInfo a) -> a.name)); untracked.sort(Comparator.comparing((UpdateInfo a) -> a.name)); updateAvailable.sort(Comparator.comparing((UpdateInfo a) -> a.name)); diff --git a/src/org/polymart/mcplugin/hooks/PolymartExpansion.java b/src/org/polymart/mcplugin/hooks/PolymartExpansion.java new file mode 100644 index 0000000..209ab25 --- /dev/null +++ b/src/org/polymart/mcplugin/hooks/PolymartExpansion.java @@ -0,0 +1,78 @@ +package org.polymart.mcplugin.hooks; + +import me.clip.placeholderapi.expansion.PlaceholderExpansion; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.polymart.mcplugin.Main; + +public class PolymartExpansion extends PlaceholderExpansion { + + private final Main plugin; + + public PolymartExpansion(Main plugin) { + this.plugin = plugin; + } + + @Override + public boolean persist() { + return true; + } + + @Override + public @NotNull String getIdentifier() { + return "polymart"; + } + + @Override + public @NotNull String getAuthor() { + return "Polymart"; + } + + @Override + public @NotNull String getVersion() { + return plugin.getServer().getVersion(); + } + + @Override + public @Nullable String onPlaceholderRequest(Player player, @NotNull String params) { + String[] args = params.split("_"); + + if (args.length == 0) { + return null; + } + + switch (args[0].toLowerCase()) { + case "version": + if (args.length != 2) { + return null; + } + Plugin otherPlugin = plugin.getServer().getPluginManager().getPlugin(args[1]); + if (otherPlugin == null) { + return null; + } + return otherPlugin.getDescription().getVersion(); + case "description": + if (args.length != 2) { + return null; + } + Plugin otherPlugin1 = plugin.getServer().getPluginManager().getPlugin(args[1]); + if (otherPlugin1 == null) { + return null; + } + return otherPlugin1.getDescription().getDescription(); + case "author": + if (args.length != 2) { + return null; + } + Plugin otherPlugin2 = plugin.getServer().getPluginManager().getPlugin(args[1]); + if (otherPlugin2 == null) { + return null; + } + return String.join(", ", otherPlugin2.getDescription().getAuthors()); + } + + return null; + } +} diff --git a/src/plugin.yml b/src/plugin.yml index bd21ed3..03f5623 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -5,6 +5,8 @@ api-version: "1.13" author: Polymart website: https://polymart.org load: STARTUP +softdepend: + - PlaceholderAPI commands: polymart: description: Polymart commands