From bfaf390463f1950226873bb3e04262b4e70aac09 Mon Sep 17 00:00:00 2001 From: games647 Date: Thu, 12 May 2016 20:11:56 +0200 Subject: [PATCH] Fixed bungeecord detection for older Spigot builds --- CHANGELOG.md | 2 ++ .../fastlogin/bukkit/FastLoginBukkit.java | 21 ++++++++++++++++--- .../fastlogin/bukkit/ForceLoginTask.java | 6 +++--- .../fastlogin/bukkit/PlayerProfile.java | 2 +- .../bukkit/listener/BukkitJoinListener.java | 2 +- .../fastlogin/bungee/MojangApiConnector.java | 2 ++ .../fastlogin/bungee/PlayerProfile.java | 2 +- 7 files changed, 28 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a95bb94f..2561ee28 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ ######1.1 * Make the configuration options also work under BungeeCord (premiumUUID, forwardSkin) +* Catch configuration loading exception if it's not spigot build +* Fix config loading for older PaperSpigot builds ######1.0 diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java index 93d0b2c8..7d97f1c1 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/FastLoginBukkit.java @@ -3,6 +3,7 @@ package com.github.games647.fastlogin.bukkit; import com.comphenix.protocol.AsynchronousManager; import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.ProtocolManager; +import com.comphenix.protocol.reflect.FuzzyReflection; import com.comphenix.protocol.utility.SafeCacheBuilder; import com.github.games647.fastlogin.bukkit.commands.CrackedCommand; import com.github.games647.fastlogin.bukkit.commands.PremiumCommand; @@ -16,6 +17,7 @@ import com.google.common.cache.CacheLoader; import com.google.common.reflect.ClassPath; import java.io.IOException; +import java.lang.reflect.Method; import java.security.KeyPair; import java.sql.SQLException; import java.util.UUID; @@ -25,6 +27,7 @@ import java.util.logging.Level; import org.apache.commons.lang.RandomStringUtils; import org.bukkit.Bukkit; +import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; @@ -32,7 +35,7 @@ import org.bukkit.plugin.java.JavaPlugin; * This plugin checks if a player has a paid account and if so tries to skip offline mode authentication. */ public class FastLoginBukkit extends JavaPlugin { - + private static final int WORKER_THREADS = 5; public static UUID parseId(String withoutDashes) { @@ -46,7 +49,6 @@ public class FastLoginBukkit extends JavaPlugin { //provide a immutable key pair to be thread safe | used for encrypting and decrypting traffic private final KeyPair keyPair = EncryptionUtil.generateKeyPair(); - private boolean bungeeCord; private Storage storage; @@ -79,7 +81,20 @@ public class FastLoginBukkit extends JavaPlugin { return; } - bungeeCord = Bukkit.spigot().getConfig().getBoolean("settings.bungeecord"); + try { + if (Bukkit.spigot().getConfig().isBoolean("settings.bungeecord")) { + bungeeCord = Bukkit.spigot().getConfig().getBoolean("settings.bungeecord"); + } else { + Method getConfigMethod = FuzzyReflection.fromObject(getServer().spigot(), true) + .getMethodByName("getSpigotConfig"); + getConfigMethod.setAccessible(true); + YamlConfiguration spigotConfig = (YamlConfiguration) getConfigMethod.invoke(getServer().spigot()); + bungeeCord = spigotConfig.getBoolean("settings.bungeecord"); + } + } catch (Exception | NoSuchMethodError ex) { + getLogger().warning("Cannot check bungeecord support. You use a non-spigot build"); + } + boolean hookFound = registerHooks(); if (bungeeCord) { getLogger().info("BungeeCord setting detected. No auth plugin is required"); diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/ForceLoginTask.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/ForceLoginTask.java index e593a019..b419d611 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/ForceLoginTask.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/ForceLoginTask.java @@ -30,15 +30,14 @@ public class ForceLoginTask implements Runnable { return; } - //remove the bungeecord identifier + //remove the bungeecord identifier if there is ones String id = '/' + player.getAddress().getAddress().getHostAddress() + ':' + player.getAddress().getPort(); PlayerSession session = plugin.getSessions().get(id); //blacklist this target player for BungeeCord Id brute force attacks player.setMetadata(plugin.getName(), new FixedMetadataValue(plugin, true)); - //check if it's the same player as we checked before - final BukkitAuthPlugin authPlugin = plugin.getAuthPlugin(); + BukkitAuthPlugin authPlugin = plugin.getAuthPlugin(); Storage storage = plugin.getStorage(); PlayerProfile playerProfile = null; @@ -53,6 +52,7 @@ public class ForceLoginTask implements Runnable { playerProfile.setPremium(false); storage.save(playerProfile); } + //check if it's the same player as we checked before } else if (player.getName().equals(session.getUsername())) { //premium player if (authPlugin == null) { diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/PlayerProfile.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/PlayerProfile.java index f23d0701..b7de0de2 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/PlayerProfile.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/PlayerProfile.java @@ -68,7 +68,7 @@ public class PlayerProfile { this.lastIp = lastIp; } - public long getLastLogin() { + public synchronized long getLastLogin() { return lastLogin; } diff --git a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/BukkitJoinListener.java b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/BukkitJoinListener.java index c2c26002..a249be27 100644 --- a/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/BukkitJoinListener.java +++ b/bukkit/src/main/java/com/github/games647/fastlogin/bukkit/listener/BukkitJoinListener.java @@ -19,7 +19,7 @@ import org.bukkit.event.player.PlayerQuitEvent; */ public class BukkitJoinListener implements Listener { - private static final long DELAY_LOGIN = 1 * 20L / 2; + private static final long DELAY_LOGIN = 20L / 2; protected final FastLoginBukkit plugin; diff --git a/bungee/src/main/java/com/github/games647/fastlogin/bungee/MojangApiConnector.java b/bungee/src/main/java/com/github/games647/fastlogin/bungee/MojangApiConnector.java index 477877f9..7d55b15b 100644 --- a/bungee/src/main/java/com/github/games647/fastlogin/bungee/MojangApiConnector.java +++ b/bungee/src/main/java/com/github/games647/fastlogin/bungee/MojangApiConnector.java @@ -1,6 +1,7 @@ package com.github.games647.fastlogin.bungee; import com.google.gson.Gson; + import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; @@ -9,6 +10,7 @@ import java.net.URL; import java.util.UUID; import java.util.logging.Level; import java.util.regex.Pattern; + import net.md_5.bungee.BungeeCord; public class MojangApiConnector { diff --git a/bungee/src/main/java/com/github/games647/fastlogin/bungee/PlayerProfile.java b/bungee/src/main/java/com/github/games647/fastlogin/bungee/PlayerProfile.java index 65d67d28..af578218 100644 --- a/bungee/src/main/java/com/github/games647/fastlogin/bungee/PlayerProfile.java +++ b/bungee/src/main/java/com/github/games647/fastlogin/bungee/PlayerProfile.java @@ -68,7 +68,7 @@ public class PlayerProfile { this.lastIp = lastIp; } - public long getLastLogin() { + public synchronized long getLastLogin() { return lastLogin; }