Migrate SLF4J logging (Fixes #177)

This commit is contained in:
games647 committed 2017-09-29 16:54:29 +02:00
1 parent 1f917f3a8d
commit dce44295d0
20 files changed
+99 -78

No files matched your search

@@ -27,6 +27,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.plugin.messaging.PluginMessageRecipient;
import org.slf4j.Logger;
/**
* This plugin checks if a player has a paid account and if so tries to skip offline mode authentication.
@@ -35,6 +36,7 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin<Comman
//provide a immutable key pair to be thread safe | used for encrypting and decrypting traffic
private final KeyPair keyPair = EncryptionUtil.generateKeyPair();
private final Logger logger = CommonUtil.createLoggerFromJDK(getLogger());
private boolean bungeeCord;
private FastLoginCore<Player, CommandSender, FastLoginBukkit> core;
@@ -52,12 +54,12 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin<Comman
} catch (ClassNotFoundException notFoundEx) {
//ignore server has no bungee support
} catch (Exception ex) {
getLogger().log(Level.WARNING, "Cannot check bungeecord support. You use a non-spigot build", ex);
logger.warn("Cannot check bungeecord support. You use a non-spigot build", ex);
}
if (getServer().getOnlineMode()) {
//we need to require offline to prevent a loginSession request for a offline player
getLogger().severe("Server have to be in offline mode");
logger.error("Server have to be in offline mode");
setEnabled(false);
return;
}
@@ -85,8 +87,7 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin<Comman
getServer().getPluginManager().registerEvents(new LoginSkinApplyListener(this), this);
} else {
getLogger().warning("Either ProtocolLib or ProtocolSupport have to be installed "
+ "if you don't use BungeeCord");
logger.warn("Either ProtocolLib or ProtocolSupport have to be installed if you don't use BungeeCord");
}
}
@@ -127,7 +128,7 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin<Comman
} else {
Player firstPlayer = Iterables.getFirst(getServer().getOnlinePlayers(), null);
if (firstPlayer == null) {
getLogger().info("No player online to send a plugin message to the proxy");
logger.info("No player online to send a plugin message to the proxy");
return;
}
@@ -187,6 +188,11 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin<Comman
sender.sendPluginMessage(this, getName(), dataOutput.toByteArray());
}
@Override
public Logger getLog() {
return logger;
}
@Override
public void sendMessage(CommandSender receiver, String message) {
receiver.sendMessage(message);
@@ -200,6 +206,6 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin<Comman
@Override
public MojangApiConnector makeApiConnector(List<String> addresses, int requests, List<HostAndPort> proxies) {
return new MojangApiBukkit(getLogger(), addresses, requests, proxies);
return new MojangApiBukkit(getLog(), addresses, requests, proxies);
}
}
@@ -13,14 +13,14 @@ import java.net.InetSocketAddress;
import java.net.URLEncoder;
import java.util.Collection;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.slf4j.Logger;
public class MojangApiBukkit extends MojangApiConnector {
//mojang api check to prove a player is logged in minecraft and made a join server request
private static final String HAS_JOINED_URL = "https://sessionserver.mojang.com/session/minecraft/hasJoined?" +
"username=%s&serverId=%s";
"username=%s&serverId=%s&ip=%s";
public MojangApiBukkit(Logger logger, Collection<String> localAddresses, int rateLimit
, List<HostAndPort> proxies) {
@@ -31,11 +31,9 @@ public class MojangApiBukkit extends MojangApiConnector {
public boolean hasJoinedServer(LoginSession session, String serverId, InetSocketAddress ip) {
BukkitLoginSession playerSession = (BukkitLoginSession) session;
String url = String.format(HAS_JOINED_URL, playerSession.getUsername(), serverId);
try {
if (ip != null) {
url += "&ip=" + URLEncoder.encode(ip.getAddress().getHostAddress(), "UTF-8");
}
String encodedIp = URLEncoder.encode(ip.getAddress().getHostAddress(), "UTF-8");
String url = String.format(HAS_JOINED_URL, playerSession.getUsername(), serverId, encodedIp);
HttpURLConnection conn = getConnection(url);
@@ -55,7 +53,7 @@ public class MojangApiBukkit extends MojangApiConnector {
}
} catch (Exception ex) {
//catch not only io-exceptions also parse and NPE on unexpected json format
logger.log(Level.WARNING, "Failed to verify session", ex);
logger.warn("Failed to verify session", ex);
}
//this connection doesn't need to be closed. So can make use of keep alive in java
@@ -14,7 +14,6 @@ import java.nio.file.Path;
import java.util.Collections;
import java.util.Set;
import java.util.UUID;
import java.util.logging.Level;
import java.util.stream.Collectors;
import org.bukkit.Bukkit;
@@ -48,20 +47,19 @@ public class BungeeListener implements PluginMessageListener {
ByteArrayDataInput dataInput = ByteStreams.newDataInput(message);
String subChannel = dataInput.readUTF();
plugin.getLogger().log(Level.FINEST, "Received plugin message for sub channel {0} from {1}"
, new Object[]{subChannel, player});
plugin.getLog().debug("Received plugin message for sub channel {} from {}", subChannel, player);
String playerName = dataInput.readUTF();
//check if the player is still online or disconnected
Player checkedPlayer = plugin.getServer().getPlayerExact(playerName);
Player checkedPlayer = Bukkit.getPlayerExact(playerName);
//fail if target player is blacklisted because already authenticated or wrong bungeecord id
if (checkedPlayer != null && !checkedPlayer.hasMetadata(plugin.getName())) {
//bungeecord UUID
long mostSignificantBits = dataInput.readLong();
long leastSignificantBits = dataInput.readLong();
UUID sourceId = new UUID(mostSignificantBits, leastSignificantBits);
plugin.getLogger().log(Level.FINEST, "Received proxy id {0} from {1}", new Object[]{sourceId, player});
plugin.getLog().debug("Received proxy id {} from {}", sourceId, player);
//fail if BungeeCord support is disabled (id = null)
if (proxyIds.contains(sourceId)) {
@@ -90,7 +88,7 @@ public class BungeeListener implements PluginMessageListener {
new ForceLoginTask(plugin.getCore(), player).run();
}
} catch (Exception ex) {
plugin.getLogger().log(Level.SEVERE, "Failed to query isRegistered", ex);
plugin.getLog().error("Failed to query isRegistered", ex);
}
});
}
@@ -108,9 +106,9 @@ public class BungeeListener implements PluginMessageListener {
.map(UUID::fromString)
.collect(Collectors.toSet());
} catch (IOException ex) {
plugin.getLogger().log(Level.SEVERE, "Failed to create file for Proxy whitelist", ex);
plugin.getLog().error("Failed to create file for Proxy whitelist", ex);
} catch (Exception ex) {
plugin.getLogger().log(Level.SEVERE, "Failed to retrieve proxy Id. Disabling BungeeCord support", ex);
plugin.getLog().error("Failed to retrieve proxy Id. Disabling BungeeCord support", ex);
}
return Collections.emptySet();
@@ -11,7 +11,6 @@ import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
import com.github.games647.fastlogin.core.mojang.SkinProperties;
import java.lang.reflect.InvocationTargetException;
import java.util.logging.Level;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@@ -65,7 +64,7 @@ public class LoginSkinApplyListener implements Listener {
try {
MethodUtils.invokeMethod(map, "put", new Object[]{"textures", skin.getHandle()});
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
plugin.getLogger().log(Level.SEVERE, "Error setting premium skin", ex);
plugin.getLog().error("Error setting premium skin", ex);
}
}
}
@@ -8,7 +8,6 @@ import com.github.games647.fastlogin.core.PlayerProfile;
import com.github.games647.fastlogin.core.shared.JoinManagement;
import java.util.Random;
import java.util.logging.Level;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@@ -50,7 +49,7 @@ public class NameCheckTask extends JoinManagement<Player, CommandSender, Protoco
try {
source.setOnlineMode();
} catch (Exception ex) {
plugin.getLogger().log(Level.SEVERE, "Cannot send encryption packet. Falling back to cracked login", ex);
plugin.getLog().error("Cannot send encryption packet. Falling back to cracked login", ex);
return;
}
@@ -8,7 +8,6 @@ import com.comphenix.protocol.events.PacketEvent;
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
import java.security.SecureRandom;
import java.util.logging.Level;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
@@ -77,7 +76,7 @@ public class ProtocolLibListener extends PacketAdapter {
PacketContainer packet = packetEvent.getPacket();
String username = packet.getGameProfiles().read(0).getName();
plugin.getLogger().log(Level.FINER, "GameProfile {0} with {1} connecting", new Object[]{sessionKey, username});
plugin.getLog().trace("GameProfile {} with {} connecting", sessionKey, username);
packetEvent.getAsyncMarker().incrementProcessingDelay();
Runnable nameCheckTask = new NameCheckTask(plugin, packetEvent, random, player, username);
@@ -20,7 +20,6 @@ import java.security.PrivateKey;
import java.security.PublicKey;
import java.util.Arrays;
import java.util.UUID;
import java.util.logging.Level;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
@@ -97,7 +96,7 @@ public class VerifyResponseTask implements Runnable {
String username = session.getUsername();
if (plugin.getCore().getApiConnector().hasJoinedServer(session, serverId, player.getAddress())) {
plugin.getLogger().log(Level.INFO, "GameProfile {0} has a verified premium account", username);
plugin.getLog().info("GameProfile {} has a verified premium account", username);
session.setVerified(true);
setPremiumUUID(session.getUuid());
@@ -117,7 +116,7 @@ public class VerifyResponseTask implements Runnable {
//https://github.com/bergerkiller/CraftSource/blob/master/net.minecraft.server/NetworkManager.java#L69
FieldUtils.writeField(networkManager, "spoofedUUID", premiumUUID, true);
} catch (Exception exc) {
plugin.getLogger().log(Level.SEVERE, "Error setting premium uuid", exc);
plugin.getLog().error("Error setting premium uuid", exc);
}
}
}
@@ -172,9 +171,9 @@ public class VerifyResponseTask implements Runnable {
private void disconnect(String kickReason, boolean debug, String logMessage, Object... arguments) {
if (debug) {
plugin.getLogger().log(Level.FINE, logMessage, arguments);
plugin.getLog().debug(logMessage, arguments);
} else {
plugin.getLogger().log(Level.SEVERE, logMessage, arguments);
plugin.getLog().error(logMessage, arguments);
}
kickPlayer(plugin.getCore().getMessage(kickReason));
@@ -192,7 +191,7 @@ public class VerifyResponseTask implements Runnable {
//tell the server that we want to close the connection
player.kickPlayer("Disconnect");
} catch (InvocationTargetException ex) {
plugin.getLogger().log(Level.SEVERE, "Error sending kick packet", ex);
plugin.getLog().error("Error sending kick packet", ex);
}
}
@@ -210,7 +209,7 @@ public class VerifyResponseTask implements Runnable {
//we don't want to handle our own packets so ignore filters
protocolManager.recieveClientPacket(player, startPacket, false);
} catch (InvocationTargetException | IllegalAccessException ex) {
plugin.getLogger().log(Level.WARNING, "Failed to fake a new start packet", ex);
plugin.getLog().warn("Failed to fake a new start packet", ex);
//cancel the event in order to prevent the server receiving an invalid packet
kickPlayer(plugin.getCore().getMessage("error-kick"));
}
@@ -11,7 +11,6 @@ import com.github.games647.fastlogin.core.hooks.AuthPlugin;
import com.google.common.collect.Lists;
import java.util.List;
import java.util.logging.Level;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
@@ -28,9 +27,9 @@ public class DelayedAuthHook implements Runnable {
public void run() {
boolean hookFound = plugin.getCore().getAuthPluginHook() != null || registerHooks();
if (plugin.isBungeeCord()) {
plugin.getLogger().info("BungeeCord setting detected. No auth plugin is required");
plugin.getLog().info("BungeeCord setting detected. No auth plugin is required");
} else if (!hookFound) {
plugin.getLogger().warning("No auth plugin were found by this plugin "
plugin.getLog().warn("No auth plugin were found by this plugin "
+ "(other plugins could hook into this after the initialization of this plugin)"
+ "and BungeeCord is deactivated. "
+ "Either one or both of the checks have to pass in order to use this plugin");
@@ -53,20 +52,20 @@ public class DelayedAuthHook implements Runnable {
for (Class<? extends AuthPlugin<Player>> clazz : supportedHooks) {
String pluginName = clazz.getSimpleName().replace("Hook", "");
//uses only member classes which uses AuthPlugin interface (skip interfaces)
if (Bukkit.getServer().getPluginManager().isPluginEnabled(pluginName)) {
if (Bukkit.getPluginManager().isPluginEnabled(pluginName)) {
//check only for enabled plugins. A single plugin could be disabled by plugin managers
authPluginHook = clazz.newInstance();
plugin.getLogger().log(Level.INFO, "Hooking into auth plugin: {0}", pluginName);
plugin.getLog().info("Hooking into auth plugin: {}", pluginName);
break;
}
}
} catch (InstantiationException | IllegalAccessException ex) {
plugin.getLogger().log(Level.SEVERE, "Couldn't load the integration class", ex);
plugin.getLog().error("Couldn't load the integration class", ex);
}
if (authPluginHook == null) {
//run this check for exceptions (errors) and not found plugins
plugin.getLogger().warning("No support offline Auth plugin found. ");
plugin.getLog().warn("No support offline Auth plugin found. ");
return false;
}
@@ -9,7 +9,6 @@ import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import java.util.concurrent.ExecutionException;
import java.util.logging.Level;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
@@ -56,7 +55,7 @@ public class ForceLoginTask extends ForceLoginManagement<Player, CommandSender,
//the player-list isn't thread-safe
return Bukkit.getScheduler().callSyncMethod(core.getPlugin(), player::isOnline).get();
} catch (InterruptedException | ExecutionException ex) {
core.getPlugin().getLogger().log(Level.SEVERE, "Failed to perform thread-safe online check", ex);
core.getPlugin().getLog().error("Failed to perform thread-safe online check", ex);
return false;
}
}