Add placeholder variables

This commit is contained in:
games647
2017-01-06 12:54:02 +01:00
parent a430a079c9
commit bc53743c6b
11 changed files with 95 additions and 31 deletions

View File

@ -51,6 +51,12 @@
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<!--PlaceholerAPI -->
<repository>
<id>placeholderapi</id>
<url>http://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
</repositories>
<dependencies>
@ -76,12 +82,26 @@
<version>3.6.5</version>
</dependency>
<dependency>
<groupId>com.github.ProtocolSupport</groupId>
<artifactId>ProtocolSupport</artifactId>
<dependency>
<groupId>com.github.ProtocolSupport</groupId>
<artifactId>ProtocolSupport</artifactId>
<!--4.25.dev-->
<version>a4f060dc46</version>
</dependency>
<version>a4f060dc46</version>
</dependency>
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.6.0</version>
<scope>provided</scope>
<optional>true</optional>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<!--Login Plugins-->
<dependency>
@ -110,10 +130,10 @@
</exclusions>
</dependency>
<dependency>
<groupId>com.github.games647</groupId>
<artifactId>LogIt</artifactId>
<version>9e3581db27</version>
<dependency>
<groupId>com.github.games647</groupId>
<artifactId>LogIt</artifactId>
<version>9e3581db27</version>
<optional>true</optional>
<scope>provided</scope>
<exclusions>
@ -122,7 +142,7 @@
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependency>
<dependency>
<groupId>com.github.RoyalDev</groupId>

View File

@ -27,6 +27,8 @@ import java.util.concurrent.ThreadFactory;
import java.util.logging.Level;
import java.util.logging.Logger;
import me.clip.placeholderapi.PlaceholderAPI;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.command.CommandSender;
@ -49,7 +51,7 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin<Comman
private boolean serverStarted;
//1 minutes should be enough as a timeout for bad internet connection (Server, Client and Mojang)
private final ConcurrentMap<String, BukkitLoginSession> session = FastLoginCore.buildCache(1, -1);
private final ConcurrentMap<String, BukkitLoginSession> loginSession = FastLoginCore.buildCache(1, -1);
@Override
public void onEnable() {
@ -64,7 +66,7 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin<Comman
}
if (getServer().getOnlineMode()) {
//we need to require offline to prevent a session request for a offline player
//we need to require offline to prevent a loginSession request for a offline player
getLogger().severe("Server have to be in offline mode");
setEnabled(false);
return;
@ -110,11 +112,15 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin<Comman
getCommand("premium").setExecutor(new PremiumCommand(this));
getCommand("cracked").setExecutor(new CrackedCommand(this));
getCommand("import-auth").setExecutor(new ImportCommand(core));
if (getServer().getPluginManager().isPluginEnabled("PlaceholderAPI")) {
PlaceholderAPI.registerPlaceholderHook(this, new PremiumPlaceholder(this));
}
}
@Override
public void onDisable() {
session.clear();
loginSession.clear();
if (core != null) {
core.close();
@ -146,10 +152,10 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin<Comman
* Gets a thread-safe map about players which are connecting to the server are being checked to be premium (paid
* account)
*
* @return a thread-safe session map
* @return a thread-safe loginSession map
*/
public ConcurrentMap<String, BukkitLoginSession> getSessions() {
return session;
public ConcurrentMap<String, BukkitLoginSession> getLoginSessions() {
return loginSession;
}
/**

View File

@ -0,0 +1,35 @@
package com.github.games647.fastlogin.bukkit;
import me.clip.placeholderapi.PlaceholderHook;
import org.bukkit.entity.Player;
import org.bukkit.metadata.MetadataValue;
import java.util.List;
public class PremiumPlaceholder extends PlaceholderHook {
private final FastLoginBukkit plugin;
public PremiumPlaceholder(FastLoginBukkit plugin) {
this.plugin = plugin;
}
@Override
public String onPlaceholderRequest(Player player, String variable) {
if (player != null && "fastlogin_status".contains(variable)) {
List<MetadataValue> metadata = player.getMetadata(plugin.getName());
if (metadata == null) {
return "unknown";
}
if (metadata.size() > 0) {
return "premium";
} else {
return "cracked";
}
}
return null;
}
}

View File

@ -58,9 +58,6 @@ public class BungeeCordListener implements PluginMessageListener {
Player checkedPlayer = plugin.getServer().getPlayerExact(playerName);
//fail if target player is blacklisted because already authed or wrong bungeecord id
if (checkedPlayer != null && !checkedPlayer.hasMetadata(plugin.getName())) {
//blacklist this target player for BungeeCord Id brute force attacks
player.setMetadata(plugin.getName(), new FixedMetadataValue(plugin, true));
//bungeecord UUID
long mostSignificantBits = dataInput.readLong();
long leastSignificantBits = dataInput.readLong();
@ -80,7 +77,7 @@ public class BungeeCordListener implements PluginMessageListener {
if ("AUTO_LOGIN".equalsIgnoreCase(subchannel)) {
BukkitLoginSession playerSession = new BukkitLoginSession(playerName, true);
playerSession.setVerified(true);
plugin.getSessions().put(id, playerSession);
plugin.getLoginSessions().put(id, playerSession);
Bukkit.getScheduler().runTaskAsynchronously(plugin, new ForceLoginTask(plugin.getCore(), player));
} else if ("AUTO_REGISTER".equalsIgnoreCase(subchannel)) {
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
@ -90,7 +87,7 @@ public class BungeeCordListener implements PluginMessageListener {
if (authPlugin == null || !authPlugin.isRegistered(playerName)) {
BukkitLoginSession playerSession = new BukkitLoginSession(playerName, false);
playerSession.setVerified(true);
plugin.getSessions().put(id, playerSession);
plugin.getLoginSessions().put(id, playerSession);
new ForceLoginTask(plugin.getCore(), player).run();
}
} catch (Exception ex) {

View File

@ -43,7 +43,7 @@ public class LoginSkinApplyListener implements Listener {
if (plugin.getConfig().getBoolean("forwardSkin")) {
//go through every session, because player.getAddress is null
//loginEvent.getAddress is just a InetAddress not InetSocketAddres, so not unique enough
for (BukkitLoginSession session : plugin.getSessions().values()) {
for (BukkitLoginSession session : plugin.getLoginSessions().values()) {
if (session.getUsername().equals(player.getName())) {
String signature = session.getSkinSignature();
String skinData = session.getEncodedSkinData();

View File

@ -61,7 +61,7 @@ public class NameCheckTask extends JoinManagement<Player, CommandSender, Protoco
byte[] verify = source.getVerifyToken();
BukkitLoginSession playerSession = new BukkitLoginSession(username, serverId, verify, registered, profile);
plugin.getSessions().put(player.getAddress().toString(), playerSession);
plugin.getLoginSessions().put(player.getAddress().toString(), playerSession);
//cancel only if the player has a paid account otherwise login as normal offline player
synchronized (packetEvent.getAsyncMarker().getProcessingLock()) {
packetEvent.setCancelled(true);
@ -71,6 +71,6 @@ public class NameCheckTask extends JoinManagement<Player, CommandSender, Protoco
@Override
public void startCrackedSession(ProtocolLibLoginSource source, PlayerProfile profile, String username) {
BukkitLoginSession loginSession = new BukkitLoginSession(username, profile);
plugin.getSessions().put(player.getAddress().toString(), loginSession);
plugin.getLoginSessions().put(player.getAddress().toString(), loginSession);
}
}

View File

@ -68,7 +68,7 @@ public class StartPacketListener extends PacketAdapter {
String sessionKey = player.getAddress().toString();
//remove old data every time on a new login in order to keep the session only for one person
plugin.getSessions().remove(sessionKey);
plugin.getLoginSessions().remove(sessionKey);
//player.getName() won't work at this state
PacketContainer packet = packetEvent.getPacket();

View File

@ -45,7 +45,7 @@ public class VerifyResponseTask implements Runnable {
@Override
public void run() {
try {
BukkitLoginSession session = plugin.getSessions().get(fromPlayer.getAddress().toString());
BukkitLoginSession session = plugin.getLoginSessions().get(fromPlayer.getAddress().toString());
if (session == null) {
disconnect(plugin.getCore().getMessage("invalid-requst"), true
, "Player {0} tried to send encryption response at invalid state", fromPlayer.getAddress());

View File

@ -36,7 +36,7 @@ public class ProtocolSupportListener extends JoinManagement<Player, CommandSende
InetSocketAddress address = loginStartEvent.getAddress();
//remove old data every time on a new login in order to keep the session only for one person
plugin.getSessions().remove(address.toString());
plugin.getLoginSessions().remove(address.toString());
super.onLogin(username, new ProtocolLoginSource(loginStartEvent));
}
@ -44,7 +44,7 @@ public class ProtocolSupportListener extends JoinManagement<Player, CommandSende
@EventHandler
public void onPropertiesResolve(PlayerPropertiesResolveEvent propertiesResolveEvent) {
InetSocketAddress address = propertiesResolveEvent.getAddress();
BukkitLoginSession session = plugin.getSessions().get(address.toString());
BukkitLoginSession session = plugin.getLoginSessions().get(address.toString());
//skin was resolved -> premium player
if (propertiesResolveEvent.hasProperty("textures") && session != null) {
@ -60,7 +60,7 @@ public class ProtocolSupportListener extends JoinManagement<Player, CommandSende
plugin.getCore().getPendingLogins().put(ip + username, new Object());
BukkitLoginSession playerSession = new BukkitLoginSession(username, null, null, registered, profile);
plugin.getSessions().put(source.getAddress().toString(), playerSession);
plugin.getLoginSessions().put(source.getAddress().toString(), playerSession);
if (plugin.getConfig().getBoolean("premiumUuid")) {
source.getLoginStartEvent().setUseOnlineModeUUID(true);
}
@ -69,6 +69,6 @@ public class ProtocolSupportListener extends JoinManagement<Player, CommandSende
@Override
public void startCrackedSession(ProtocolLoginSource source, PlayerProfile profile, String username) {
BukkitLoginSession loginSession = new BukkitLoginSession(username, profile);
plugin.getSessions().put(source.getAddress().toString(), loginSession);
plugin.getLoginSessions().put(source.getAddress().toString(), loginSession);
}
}

View File

@ -14,6 +14,7 @@ import java.util.logging.Level;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.metadata.FixedMetadataValue;
public class ForceLoginTask extends ForceLoginMangement<Player, CommandSender, BukkitLoginSession, FastLoginBukkit> {
@ -25,7 +26,11 @@ public class ForceLoginTask extends ForceLoginMangement<Player, CommandSender, B
public void run() {
//remove the bungeecord identifier if there is ones
String id = '/' + player.getAddress().getAddress().getHostAddress() + ':' + player.getAddress().getPort();
session = core.getPlugin().getSessions().remove(id);
session = core.getPlugin().getLoginSessions().remove(id);
//blacklist this target player for BungeeCord Id brute force attacks
FastLoginBukkit plugin = core.getPlugin();
player.setMetadata(core.getPlugin().getName(), new FixedMetadataValue(plugin, true));
super.run();
}

View File

@ -18,6 +18,7 @@ softdepend:
# We depend either ProtocolLib or ProtocolSupport
- ProtocolSupport
- ProtocolLib
- PlaceholderAPI
commands:
${project.parent.name}: