feat: basic placeholderapi support
This commit is contained in:
parent
14d2ecb778
commit
99bb977a19
3 changed files with 78 additions and 2 deletions
|
@ -14,6 +14,7 @@ import net.artelnatif.nicko.i18n.LocaleManager;
|
||||||
import net.artelnatif.nicko.impl.Internals;
|
import net.artelnatif.nicko.impl.Internals;
|
||||||
import net.artelnatif.nicko.impl.InternalsProvider;
|
import net.artelnatif.nicko.impl.InternalsProvider;
|
||||||
import net.artelnatif.nicko.mojang.MojangAPI;
|
import net.artelnatif.nicko.mojang.MojangAPI;
|
||||||
|
import net.artelnatif.nicko.placeholder.PlaceHolderHook;
|
||||||
import net.artelnatif.nicko.pluginchannel.PluginMessageHandler;
|
import net.artelnatif.nicko.pluginchannel.PluginMessageHandler;
|
||||||
import net.artelnatif.nicko.storage.PlayerDataStore;
|
import net.artelnatif.nicko.storage.PlayerDataStore;
|
||||||
import net.artelnatif.nicko.utils.ServerUtils;
|
import net.artelnatif.nicko.utils.ServerUtils;
|
||||||
|
@ -71,9 +72,12 @@ public class NickoBukkit extends JavaPlugin {
|
||||||
getLogger().warning("Failed to open persistence, data will NOT be saved!");
|
getLogger().warning("Failed to open persistence, data will NOT be saved!");
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerUtils.checkSpigotBungeeCordHook();
|
new PlaceHolderHook(this).hook();
|
||||||
|
|
||||||
|
final ServerUtils serverUtils = new ServerUtils(this);
|
||||||
|
serverUtils.checkSpigotBungeeCordHook();
|
||||||
if (nickoConfiguration.isBungeecordEnabled()) {
|
if (nickoConfiguration.isBungeecordEnabled()) {
|
||||||
if (ServerUtils.checkBungeeCordHook()) {
|
if (serverUtils.checkBungeeCordHook()) {
|
||||||
getLogger().info("Enabling BungeeCord support...");
|
getLogger().info("Enabling BungeeCord support...");
|
||||||
getServer().getMessenger().registerIncomingPluginChannel(this, NickoBungee.NICKO_PLUGIN_CHANNEL_UPDATE, new PluginMessageHandler());
|
getServer().getMessenger().registerIncomingPluginChannel(this, NickoBungee.NICKO_PLUGIN_CHANNEL_UPDATE, new PluginMessageHandler());
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
package net.artelnatif.nicko.placeholder;
|
||||||
|
|
||||||
|
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||||
|
import net.artelnatif.nicko.NickoBukkit;
|
||||||
|
import net.artelnatif.nicko.disguise.NickoProfile;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class NickoExpension extends PlaceholderExpansion {
|
||||||
|
|
||||||
|
private final NickoBukkit instance;
|
||||||
|
|
||||||
|
public NickoExpension(NickoBukkit instance) {
|
||||||
|
this.instance = instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull String getIdentifier() {
|
||||||
|
return "nicko";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull String getAuthor() {
|
||||||
|
return "Aro";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull String getVersion() {
|
||||||
|
return "1.0.0";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable String onPlaceholderRequest(Player player, @NotNull String params) {
|
||||||
|
Optional<NickoProfile> optionalProfile = instance.getDataStore().getData(player.getUniqueId());
|
||||||
|
if (optionalProfile.isPresent()) {
|
||||||
|
final NickoProfile profile = optionalProfile.get();
|
||||||
|
return switch (params) {
|
||||||
|
case "name" -> profile.getName();
|
||||||
|
case "skin" -> profile.getSkin();
|
||||||
|
case "locale" -> profile.getLocale().getName();
|
||||||
|
case "bungeecord" -> String.valueOf(profile.isBungeecordTransfer());
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
instance.getLogger().severe("Couldn't satisfy request for placeholder " + params + ". This is a bug!");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package net.artelnatif.nicko.placeholder;
|
||||||
|
|
||||||
|
import net.artelnatif.nicko.NickoBukkit;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
|
public class PlaceHolderHook {
|
||||||
|
private final NickoBukkit instance;
|
||||||
|
|
||||||
|
public PlaceHolderHook(NickoBukkit instance) {
|
||||||
|
this.instance = instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hook() {
|
||||||
|
instance.getLogger().info("Checking support for PlaceHolderAPI...");
|
||||||
|
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
||||||
|
new NickoExpension(instance).register();
|
||||||
|
instance.getLogger().info("Hooked into PlaceHolderAPI!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue