diff --git a/src/main/java/de/butzlabben/world/util/PapiExtension.java b/src/main/java/de/butzlabben/world/util/PapiExtension.java index a61cab1..a3d1f9e 100644 --- a/src/main/java/de/butzlabben/world/util/PapiExtension.java +++ b/src/main/java/de/butzlabben/world/util/PapiExtension.java @@ -10,7 +10,10 @@ import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.World; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; +import java.util.ArrayList; +import java.util.List; import java.util.Objects; public class PapiExtension extends PlaceholderExpansion { @@ -18,26 +21,45 @@ public class PapiExtension extends PlaceholderExpansion { private final WorldSystem worldSystem = WorldSystem.getInstance(); @Override - public String getIdentifier() { + public @NotNull String getIdentifier() { return "worldsystem"; } @Override - public String getAuthor() { + public @NotNull String getAuthor() { return "Butzlabben"; } @Override - public String getVersion() { + public @NotNull String getVersion() { return worldSystem.getDescription().getVersion(); } @Override public String onRequest(OfflinePlayer p, String params) { DependenceConfig config = new DependenceConfig(p); + + String[] args = params.split("_"); + if (args.length == 3 && args[0].equalsIgnoreCase("world") + && args[1].equalsIgnoreCase("member")){ + + Player playerOnline = p.getPlayer(); + if(playerOnline == null) return "none"; + WorldConfig wc = WorldConfig.getWorldConfig(playerOnline.getWorld().getName()); + List members = new ArrayList<>(wc.getMembersWithNames().values()); + int member; + try { + member = Integer.parseInt(args[2]); + } catch (NumberFormatException e){ + throw new IllegalArgumentException("No placeholder named\"" + getIdentifier() + "_" + params + "\" is known"); + } + + return members.get(member); + } switch (params) { case "has_world": return new DependenceConfig(p).hasWorld() + ""; +// @@ -48,16 +69,16 @@ public String onRequest(OfflinePlayer p, String params) { case "is_creator": WorldPlayer player = new WorldPlayer(Objects.requireNonNull(Bukkit.getPlayer(p.getUniqueId()))); if (!player.isOnSystemWorld()) @@ -48,16 +70,16 @@ public class PapiExtension extends PlaceholderExpansion { return "none"; else return config.getWorldname(); - case "world_of_player_loaded": + case "world_loaded": if (!config.hasWorld()) return "none"; - return SystemWorld.getSystemWorld(config.getWorldname()).isLoaded() + ""; + return Objects.requireNonNull(SystemWorld.getSystemWorld(config.getWorldname()).isLoaded() + ""; case "pretty_world_name": if (!p.isOnline()) { if (!config.hasWorld()) { Player p1 = p.getPlayer(); if (p1 != null && p1.isOnline()) - return p1.getLocation().getWorld().getName(); + return Objects.requireNonNull(p1.getLocation().getWorld().getName(); return "none"; } return config.getOwner().getName();