From b308f0aca925558a58a57344c915e38fe0adec50 Mon Sep 17 00:00:00 2001 From: CrazyCloudCraft | Argantiu <95505222+CrazyCloudCraft@users.noreply.github.com> Date: Wed, 12 Oct 2022 08:25:20 +0200 Subject: [PATCH] Create PapiExtension.java --- .../butzlabben/world/util/PapiExtension.java | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 src/main/java/de/butzlabben/world/util/PapiExtension.java diff --git a/src/main/java/de/butzlabben/world/util/PapiExtension.java b/src/main/java/de/butzlabben/world/util/PapiExtension.java new file mode 100644 index 0000000..4ecd42d --- /dev/null +++ b/src/main/java/de/butzlabben/world/util/PapiExtension.java @@ -0,0 +1,78 @@ +package de.butzlabben.world.util; + +import de.butzlabben.world.WorldSystem; +import de.butzlabben.world.config.DependenceConfig; +import de.butzlabben.world.config.WorldConfig; +import de.butzlabben.world.wrapper.SystemWorld; +import de.butzlabben.world.wrapper.WorldPlayer; +import me.clip.placeholderapi.expansion.PlaceholderExpansion; +import me.clip.placeholderapi.PlaceholderAPI; +import org.bukkit.Bukkit; +import org.bukkit.OfflinePlayer; +import org.bukkit.World; +import org.bukkit.entity.Player; + +import java.util.Objects; + +public class PapiExtension extends PlaceholderExpansion { + + private final WorldSystem worldSystem = WorldSystem.getInstance(); + + @Override + public String getIdentifier() { + return "worldsystem"; + } + + @Override + public String getAuthor() { + return "Butzlabben"; + } + + @Override + public String getVersion() { + return worldSystem.getDescription().getVersion(); + } + + @Override + public String onRequest(OfflinePlayer p, String params) { + DependenceConfig config = new DependenceConfig(p); + switch (params) { + case "has_world": + String has_world = "%worldsystem_has_world%"; + has_world = PlaceholderAPI.setPlaceholders(event.getPlayer(), has_world); + event.setJoinMessage(joinText); + return new DependenceConfig(p).hasWorld() + ""; + case "is_creator": + WorldPlayer player = new WorldPlayer(Objects.requireNonNull(Bukkit.getPlayer(p.getUniqueId()))); + if (!player.isOnSystemWorld()) + return "false"; + return player.isOwnerofWorld() + ""; + case "world_name_of_player": + if (!config.hasWorld()) + return "none"; + else + return config.getWorldname(); + case "world_of_player_loaded": + if (!config.hasWorld()) + return "none"; + return 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 "none"; + } + return config.getOwner().getName(); + } else { + World world = ((Player) p).getWorld(); + if (WorldConfig.exists(world.getName())) + return WorldConfig.getWorldConfig(world.getName()).getOwnerName(); + return world.getName(); + } + default: + throw new IllegalArgumentException("No placeholder named\"" + getIdentifier() + "_" + params + "\" is known"); + } + } +}