Fix parsing of placeholder status

Fixes #341
This commit is contained in:
games647
2020-05-14 13:41:32 +02:00
parent 477d3df1dd
commit c58eda983a
5 changed files with 34 additions and 21 deletions

View File

@ -52,6 +52,15 @@ https://ci.codemc.org/job/Games647/job/FastLogin/changes
fastlogin.command.premium.other
fastlogin.command.cracked.other
## Placeholder
This plugin supports `PlaceholderAPI` on `Spigot`. It exports the following variable
`%fastlogin_status%`. In BungeeCord environments, the status of a player will be delivered with a delay after the player
already successful joined the server. This takes about a couple of milliseconds. In this case the value
will be `Unknown`.
Possible values: `Premium`, `Cracked`, `Unknown`
## Requirements
* Plugin:
@ -59,7 +68,7 @@ https://ci.codemc.org/job/Games647/job/FastLogin/changes
* [ProtocolSupport](https://www.spigotmc.org/resources/protocolsupport.7201/)
* [Spigot](https://www.spigotmc.org) 1.8.8+
* Java 8+
* Run Spigot and/or BungeeCord/Waterfall in offline mode (see server.properties or config.yml)
* Run Spigot (or a fork e.g. Paper) and/or BungeeCord (or a fork e.g. Waterfall) in offline mode
* An auth plugin. Supported plugins
### Bukkit/Spigot/Paper

View File

@ -89,8 +89,7 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin<Comman
getCommand("cracked").setExecutor(new CrackedCommand(this));
if (pluginManager.isPluginEnabled("PlaceholderAPI")) {
//prevents NoClassDef errors if it's not available
PremiumPlaceholder.register(this);
new PremiumPlaceholder(this).register();
}
}

View File

@ -1,13 +1,12 @@
package com.github.games647.fastlogin.bukkit;
import me.clip.placeholderapi.PlaceholderAPI;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import org.bukkit.entity.Player;
public class PremiumPlaceholder extends PlaceholderExpansion {
private static final String PLACEHOLDER_VARIABLE = "fastlogin_status";
private static final String PLACEHOLDER_VARIABLE = "status";
private final FastLoginBukkit plugin;
@ -15,27 +14,23 @@ public class PremiumPlaceholder extends PlaceholderExpansion {
this.plugin = plugin;
}
public static void register(FastLoginBukkit plugin) {
PremiumPlaceholder placeholderHook = new PremiumPlaceholder(plugin);
PlaceholderAPI.registerPlaceholderHook(PLACEHOLDER_VARIABLE, placeholderHook);
}
@Override
public String onPlaceholderRequest(Player player, String variable) {
if (player != null && PLACEHOLDER_VARIABLE.equals(variable)) {
return plugin.getStatus(player.getUniqueId()).name();
public String onPlaceholderRequest(Player player, String identifier) {
// player is null if offline
if (player != null && PLACEHOLDER_VARIABLE.equals(identifier)) {
return plugin.getStatus(player.getUniqueId()).getReadableName();
}
return "";
return null;
}
@Override
public String getIdentifier() {
return PLACEHOLDER_VARIABLE;
return plugin.getName();
}
@Override
public String getPlugin() {
public String getRequiredPlugin() {
return plugin.getName();
}
@ -46,6 +41,6 @@ public class PremiumPlaceholder extends PlaceholderExpansion {
@Override
public String getVersion() {
return plugin.getName();
return plugin.getDescription().getVersion();
}
}

View File

@ -2,9 +2,19 @@ package com.github.games647.fastlogin.core;
public enum PremiumStatus {
PREMIUM,
PREMIUM("Premium"),
CRACKED,
CRACKED("Cracked"),
UNKNOWN
UNKNOWN("Unknown");
private final String readableName;
PremiumStatus(String readableName) {
this.readableName = readableName;
}
public String getReadableName() {
return readableName;
}
}

View File

@ -18,7 +18,7 @@ public class RateLimiter {
/**
* Ask if access is allowed. If so register the request.
*
* @return true if allowed
* @return true if allowed - false otherwise without any side effects
*/
public boolean tryAcquire() {
// current time millis is not monotonic - it can jump back depending on user choice or NTP