mirror of
https://github.com/trainerlord/WorldSystem.git
synced 2024-12-02 13:23:21 +01:00
Create PapiExtension.java
This commit is contained in:
parent
255da183d6
commit
b308f0aca9
78
src/main/java/de/butzlabben/world/util/PapiExtension.java
Normal file
78
src/main/java/de/butzlabben/world/util/PapiExtension.java
Normal file
@ -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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user