Skip to content

Commit

Permalink
PlaceholderAPI integration test
Browse files Browse the repository at this point in the history
Implemented PAPI for classic motd
  • Loading branch information
strumswell committed Sep 1, 2020
1 parent b677335 commit 7c0fd99
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
2 changes: 1 addition & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version: X-2020-05-14
description: Change your Serverlist Motd!
load: POSTWORLD
depend: [ProtocolLib]
softdepend: [Vault, BanManager, MaxBans, MultiVerse, Multiverse-Core, Multiverse-Portals, Multiverse-NetherPortals, Multiverse-Inventories, Towny, Essentials]
softdepend: [Vault, PlaceholderAPI, BanManager, MaxBans, MultiVerse, Multiverse-Core, Multiverse-Portals, Multiverse-NetherPortals, Multiverse-Inventories, Towny, Essentials]
main: cloud.bolte.serverlistmotd.Main
commands:
serverlist:
Expand Down
4 changes: 3 additions & 1 deletion src/cloud/bolte/serverlistmotd/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import cloud.bolte.serverlistmotd.events.ProtocolLibImplementation;
import cloud.bolte.serverlistmotd.events.RestrictedModeJoin;
import cloud.bolte.serverlistmotd.util.IO;
import cloud.bolte.serverlistmotd.util.PapiIntegration;
import cloud.bolte.serverlistmotd.util.VaultIntegration;

/*
Expand Down Expand Up @@ -62,8 +63,9 @@ public void onEnable() {
//Register command
this.getCommand("serverlist").setExecutor(new Serverlist());

//Setup Vault for money var
//Setup Vault and Papi
VaultIntegration.setupEconomy();
PapiIntegration.setupIntegration();

//Timer for saving userdata to disk
BukkitScheduler scheduler = getServer().getScheduler();
Expand Down
5 changes: 5 additions & 0 deletions src/cloud/bolte/serverlistmotd/motd/ClassicMotd.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import java.net.InetAddress;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.event.server.ServerListPingEvent;

import cloud.bolte.serverlistmotd.Main;
import cloud.bolte.serverlistmotd.SpigotConfig;
import cloud.bolte.serverlistmotd.util.PapiIntegration;
import cloud.bolte.serverlistmotd.variables.MoneyVariable;
import cloud.bolte.serverlistmotd.variables.PlayerVariable;
import cloud.bolte.serverlistmotd.variables.RandomPlayerVariable;
Expand Down Expand Up @@ -44,6 +46,9 @@ public String formatMotd(String motd, InetAddress ip) {
formattedMotd = formattedMotd
.replace("%player%", PlayerVariable.getNameFromIP(ip))
.replace("%money%", MoneyVariable.getMoney(ip)+"");
formattedMotd = PapiIntegration.replaceVariables(Bukkit.getOfflinePlayer(Main.IP_UUID.get(ip)), formattedMotd);
} else {
formattedMotd = PapiIntegration.replaceVariables(null, formattedMotd);
}
return formattedMotd;
}
Expand Down
28 changes: 28 additions & 0 deletions src/cloud/bolte/serverlistmotd/util/PapiIntegration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package cloud.bolte.serverlistmotd.util;

import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;

import me.clip.placeholderapi.PlaceholderAPI;

public class PapiIntegration {
private static boolean papiIsEnabled = false;

private PapiIntegration() {
throw new IllegalStateException("Utility class");
}

public static void setupIntegration() {
if (Bukkit.getServer().getPluginManager().isPluginEnabled("PlaceholderAPI")) {
System.out.println("[ServerlistMOTD] Hooking into PlaceholderAPI.");
papiIsEnabled = true;
}
}

public static String replaceVariables(OfflinePlayer player, String motd) {
if (papiIsEnabled) {
return PlaceholderAPI.setPlaceholders(player, motd);
}
return motd;
}
}

0 comments on commit 7c0fd99

Please sign in to comment.