PlaceholderAPI hook
This commit is contained in:
parent
e0bf35284c
commit
731c6477a5
14
pom.xml
14
pom.xml
@ -623,6 +623,12 @@
|
||||
<url>https://s01.oss.sonatype.org/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
|
||||
<!-- Placeholder API Repo -->
|
||||
<repository>
|
||||
<id>placeholderapi-repo</id>
|
||||
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
|
||||
</repository>
|
||||
|
||||
<!-- Multiverse Repo -->
|
||||
<repository>
|
||||
<id>onarandombox-repo-releases</id>
|
||||
@ -1038,6 +1044,14 @@
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!-- Placeholder API -->
|
||||
<dependency>
|
||||
<groupId>me.clip</groupId>
|
||||
<artifactId>placeholderapi</artifactId>
|
||||
<version>2.11.6</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- EssentialsX plugin -->
|
||||
<dependency>
|
||||
<groupId>net.essentialsx</groupId>
|
||||
|
||||
@ -53,6 +53,9 @@ public class ServerListener implements Listener {
|
||||
} else if ("ProtocolLib".equalsIgnoreCase(pluginName)) {
|
||||
protocolLibService.disable();
|
||||
logger.warning("ProtocolLib has been disabled, unhooking packet adapters!");
|
||||
} else if ("PlaceholderAPI".equalsIgnoreCase(pluginName)) {
|
||||
pluginHookService.unhookPlaceholderApi();
|
||||
logger.info("PlaceholderAPI has been disabled: unhooking placeholders");
|
||||
}
|
||||
}
|
||||
|
||||
@ -74,6 +77,8 @@ public class ServerListener implements Listener {
|
||||
spawnLoader.loadCmiSpawn();
|
||||
} else if ("ProtocolLib".equalsIgnoreCase(pluginName)) {
|
||||
protocolLibService.setup();
|
||||
} else if ("PlaceholderAPI".equalsIgnoreCase(pluginName)) {
|
||||
pluginHookService.tryHookToPlaceholderApi();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,7 +37,7 @@ public class GeoIpService {
|
||||
private volatile boolean downloading;
|
||||
|
||||
@Inject
|
||||
GeoIpService(@DataFolder File dataFolder){
|
||||
GeoIpService(@DataFolder File dataFolder) {
|
||||
this.dataFile = dataFolder.toPath().resolve(DATABASE_FILE);
|
||||
|
||||
// Fires download of recent data or the initialization of the look up service
|
||||
|
||||
@ -6,6 +6,8 @@ import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MVWorldManager;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.output.ConsoleLoggerFactory;
|
||||
import fr.xephi.authme.service.hook.papi.AuthMeExpansion;
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -26,6 +28,8 @@ public class PluginHookService {
|
||||
private Essentials essentials;
|
||||
private Plugin cmi;
|
||||
private MultiverseCore multiverse;
|
||||
private PlaceholderAPIPlugin placeholderApi;
|
||||
private AuthMeExpansion authMeExpansion;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@ -38,6 +42,7 @@ public class PluginHookService {
|
||||
tryHookToEssentials();
|
||||
tryHookToCmi();
|
||||
tryHookToMultiverse();
|
||||
tryHookToPlaceholderApi();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -133,6 +138,20 @@ public class PluginHookService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to create a hook into PlaceholderAPI.
|
||||
*/
|
||||
public void tryHookToPlaceholderApi() {
|
||||
try {
|
||||
placeholderApi = getPlugin(pluginManager, "PlaceholderAPI", PlaceholderAPIPlugin.class);
|
||||
authMeExpansion = new AuthMeExpansion();
|
||||
authMeExpansion.register();
|
||||
} catch (Exception | NoClassDefFoundError ignored) {
|
||||
placeholderApi = null;
|
||||
authMeExpansion = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to create a hook into CMI.
|
||||
*/
|
||||
@ -180,6 +199,16 @@ public class PluginHookService {
|
||||
multiverse = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unhooks from PlaceholderAPI.
|
||||
*/
|
||||
public void unhookPlaceholderApi() {
|
||||
if (placeholderApi != null) {
|
||||
authMeExpansion.unregister();
|
||||
placeholderApi = null;
|
||||
}
|
||||
}
|
||||
|
||||
// ------
|
||||
// Helpers
|
||||
// ------
|
||||
|
||||
@ -0,0 +1,71 @@
|
||||
package fr.xephi.authme.service.hook.papi;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.api.v3.AuthMeApi;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.HooksSettings;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* AuthMe PlaceholderAPI expansion class.
|
||||
* @author Kobe 8
|
||||
*/
|
||||
public class AuthMeExpansion extends PlaceholderExpansion {
|
||||
private final Settings settings = AuthMe.settings;
|
||||
private final AuthMeApi authMeApi = AuthMeApi.getInstance();
|
||||
@Override
|
||||
public @NotNull String getIdentifier() {
|
||||
return "authme";
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getAuthor() {
|
||||
return "HaHaWTH";
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getVersion() {
|
||||
return AuthMe.getPluginVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean persist() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String onRequest(OfflinePlayer player, @NotNull String params) {
|
||||
if (!settings.getProperty(HooksSettings.PLACEHOLDER_API)) return null;
|
||||
if (params.equalsIgnoreCase("version")) {
|
||||
return getVersion();
|
||||
}
|
||||
if (params.equalsIgnoreCase("is_registered")) {
|
||||
if (player != null) {
|
||||
Player onlinePlayer = player.getPlayer();
|
||||
if (onlinePlayer != null) {
|
||||
return String.valueOf(authMeApi.isRegistered(onlinePlayer.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (params.equalsIgnoreCase("is_authenticated")) {
|
||||
if (player != null) {
|
||||
Player onlinePlayer = player.getPlayer();
|
||||
if (onlinePlayer != null) {
|
||||
return String.valueOf(authMeApi.isAuthenticated(onlinePlayer));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (params.equalsIgnoreCase("last_login_time")) {
|
||||
if (player != null) {
|
||||
Player onlinePlayer = player.getPlayer();
|
||||
if (onlinePlayer != null) {
|
||||
return authMeApi.getLastLoginTime(onlinePlayer.getName()).toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -15,6 +15,10 @@ public final class HooksSettings implements SettingsHolder {
|
||||
public static final Property<Boolean> MULTIVERSE =
|
||||
newProperty("Hooks.multiverse", true);
|
||||
|
||||
@Comment("Do we need to hook with PlaceholderAPI for AuthMe placeholders?")
|
||||
public static final Property<Boolean> PLACEHOLDER_API =
|
||||
newProperty("Hooks.placeholderapi", true);
|
||||
|
||||
@Comment("Do we need to hook with BungeeCord?")
|
||||
public static final Property<Boolean> BUNGEECORD =
|
||||
newProperty("Hooks.bungeecord", false);
|
||||
|
||||
@ -21,7 +21,7 @@ public final class PluginSettings implements SettingsHolder {
|
||||
|
||||
@Comment({
|
||||
"Send i18n messages to player based on their client settings, this option will override `settings.messagesLanguage`",
|
||||
"(Requires Protocollib or Packetevents)",
|
||||
"(Requires ProtocolLib)",
|
||||
"This will not affect language of AuthMe help command."
|
||||
})
|
||||
public static final Property<Boolean> I18N_MESSAGES =
|
||||
|
||||
@ -20,6 +20,7 @@ softdepend:
|
||||
- EssentialsSpawn
|
||||
- ProtocolLib
|
||||
- floodgate
|
||||
- PlaceholderAPI
|
||||
commands:
|
||||
authme:
|
||||
description: AuthMe op commands
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user