diff --git a/paper/src/main/java/io/github/_4drian3d/authmevelocity/paper/AuthMePlaceholders.java b/paper/src/main/java/io/github/_4drian3d/authmevelocity/paper/AuthMePlaceholders.java index 0bbecd3..4799393 100644 --- a/paper/src/main/java/io/github/_4drian3d/authmevelocity/paper/AuthMePlaceholders.java +++ b/paper/src/main/java/io/github/_4drian3d/authmevelocity/paper/AuthMePlaceholders.java @@ -29,7 +29,7 @@ import static io.github.miniplaceholders.api.utils.Components.*; final class AuthMePlaceholders { private AuthMePlaceholders() {} - static Expansion getExpansion(){ + static Expansion getExpansion() { return Expansion.builder("authme") .filter(Player.class) .audiencePlaceholder("is_logged", (aud, queue, ctx) -> diff --git a/velocity/src/main/java/io/github/_4drian3d/authmevelocity/velocity/AuthMeVelocityPlugin.java b/velocity/src/main/java/io/github/_4drian3d/authmevelocity/velocity/AuthMeVelocityPlugin.java index b650115..91d5954 100644 --- a/velocity/src/main/java/io/github/_4drian3d/authmevelocity/velocity/AuthMeVelocityPlugin.java +++ b/velocity/src/main/java/io/github/_4drian3d/authmevelocity/velocity/AuthMeVelocityPlugin.java @@ -64,6 +64,7 @@ import java.util.Set; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import java.util.function.Predicate; +import java.util.function.Supplier; import java.util.stream.Stream; @Plugin( @@ -243,4 +244,10 @@ public final class AuthMeVelocityPlugin implements AuthMeVelocityAPI { logger.info("[DEBUG] {}", msg); } } + + public void logDebug(Supplier msg) { + if (config.get().advanced().debug()) { + logger.info("[DEBUG] {}", msg.get()); + } + } } diff --git a/velocity/src/main/java/io/github/_4drian3d/authmevelocity/velocity/listener/compat/FastLoginListener.java b/velocity/src/main/java/io/github/_4drian3d/authmevelocity/velocity/listener/compat/FastLoginListener.java index 28863c1..b8428c8 100644 --- a/velocity/src/main/java/io/github/_4drian3d/authmevelocity/velocity/listener/compat/FastLoginListener.java +++ b/velocity/src/main/java/io/github/_4drian3d/authmevelocity/velocity/listener/compat/FastLoginListener.java @@ -20,10 +20,13 @@ package io.github._4drian3d.authmevelocity.velocity.listener.compat; import com.github.games647.fastlogin.velocity.event.VelocityFastLoginAutoLoginEvent; import com.google.inject.Inject; import com.velocitypowered.api.event.EventTask; +import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.ProxyServer; import io.github._4drian3d.authmevelocity.velocity.AuthMeVelocityPlugin; import io.github._4drian3d.authmevelocity.velocity.listener.Listener; +import java.util.Optional; + public final class FastLoginListener implements Listener { @Inject private ProxyServer proxy; @@ -38,8 +41,15 @@ public final class FastLoginListener implements Listener { - plugin.logDebug("VelocityFastLoginAutoLoginEvent | Attempt to auto register player"); - proxy.getPlayer(event.getProfile().getName()).ifPresent(plugin::addPlayer); + plugin.logDebug(() -> "VelocityFastLoginAutoLoginEvent | Attempt to auto register player"); + final Optional optionalPlayer = proxy.getPlayer(event.getProfile().getName()); + if (optionalPlayer.isPresent()) { + final Player player = optionalPlayer.get(); + plugin.logDebug(() -> "VelocityFastLoginAutoLoginEvent | Auto registering player " + player.getUsername()); + plugin.addPlayer(player); + } else { + plugin.logDebug(() -> "VelocityFastLoginAutoLoginEvent | Player " + event.getProfile().getName() + " could not be registered"); + } }); } } diff --git a/velocity/src/main/java/io/github/_4drian3d/authmevelocity/velocity/listener/connection/InitialServerListener.java b/velocity/src/main/java/io/github/_4drian3d/authmevelocity/velocity/listener/connection/InitialServerListener.java index 28150fb..241a7cc 100644 --- a/velocity/src/main/java/io/github/_4drian3d/authmevelocity/velocity/listener/connection/InitialServerListener.java +++ b/velocity/src/main/java/io/github/_4drian3d/authmevelocity/velocity/listener/connection/InitialServerListener.java @@ -61,7 +61,7 @@ public final class InitialServerListener implements Listener optionalSV = event.getInitialServer(); if (optionalSV.isPresent() && plugin.isAuthServer(optionalSV.get())) { continuation.resume(); - plugin.logDebug("PlayerChooseInitialServerEvent | Player is in auth server"); + plugin.logDebug(() -> "PlayerChooseInitialServerEvent | " + event.getPlayer().getUsername() + " | Player is in auth server"); return; } @@ -72,7 +72,7 @@ public final class InitialServerListener implements Listener "PlayerChooseInitialServerEvent | " + event.getPlayer().getUsername() + " | Null server"); logger.error("Cannot send the player {} to an auth server", event.getPlayer().getUsername()); } }); diff --git a/velocity/src/main/java/io/github/_4drian3d/authmevelocity/velocity/listener/connection/PostConnectListener.java b/velocity/src/main/java/io/github/_4drian3d/authmevelocity/velocity/listener/connection/PostConnectListener.java index 13ccf26..eab3fd1 100644 --- a/velocity/src/main/java/io/github/_4drian3d/authmevelocity/velocity/listener/connection/PostConnectListener.java +++ b/velocity/src/main/java/io/github/_4drian3d/authmevelocity/velocity/listener/connection/PostConnectListener.java @@ -29,6 +29,7 @@ import com.velocitypowered.api.proxy.server.RegisteredServer; import io.github._4drian3d.authmevelocity.velocity.AuthMeVelocityPlugin; import io.github._4drian3d.authmevelocity.velocity.listener.Listener; +@SuppressWarnings("UnstableApiUsage") public final class PostConnectListener implements Listener { @Inject private AuthMeVelocityPlugin plugin; @@ -46,7 +47,7 @@ public final class PostConnectListener implements Listener "ServerPostConnectEvent | Player "+player.getUsername()+" is logged: " + isLogged); final RegisteredServer server = player.getCurrentServer().map(ServerConnection::getServer).orElse(null); if (server == null) { plugin.logDebug("ServerPostConnectEvent | Player "+player.getUsername()+" is not in a server"); @@ -65,9 +66,9 @@ public final class PostConnectListener implements Listener "ServerPostConnectEvent | " + player.getUsername() + " | Sending LOGIN data"); if (server.sendPluginMessage(AuthMeVelocityPlugin.MODERN_CHANNEL, byteArray)) { - plugin.logDebug("ServerPostConnectEvent | Correctly send data"); + plugin.logDebug(() -> "ServerPostConnectEvent | " + player.getUsername() + " | Correctly send data"); } else { plugin.logDebug("ServerPostConnectEvent | Failed to send data"); } diff --git a/velocity/src/main/java/io/github/_4drian3d/authmevelocity/velocity/listener/connection/PreConnectListener.java b/velocity/src/main/java/io/github/_4drian3d/authmevelocity/velocity/listener/connection/PreConnectListener.java index d055e57..f5c92c4 100644 --- a/velocity/src/main/java/io/github/_4drian3d/authmevelocity/velocity/listener/connection/PreConnectListener.java +++ b/velocity/src/main/java/io/github/_4drian3d/authmevelocity/velocity/listener/connection/PreConnectListener.java @@ -40,14 +40,14 @@ public final class PreConnectListener implements Listener public EventTask executeAsync(final ServerPreConnectEvent event) { return EventTask.withContinuation(continuation -> { if (plugin.isLogged(event.getPlayer())) { - plugin.logDebug("ServerPreConnectEvent | Player already logged"); + plugin.logDebug(() -> "ServerPreConnectEvent | Player " + event.getPlayer().getUsername() + " is already logged"); continuation.resume(); return; } final RegisteredServer server = event.getResult().getServer().orElse(null); if (server == null) { - plugin.logDebug("ServerPreConnectEvent | Null Server"); + plugin.logDebug(() -> "ServerPreConnectEvent | " + event.getPlayer().getUsername() + " | Null Server"); continuation.resume(); return; } diff --git a/velocity/src/main/java/io/github/_4drian3d/authmevelocity/velocity/listener/data/PluginMessageListener.java b/velocity/src/main/java/io/github/_4drian3d/authmevelocity/velocity/listener/data/PluginMessageListener.java index 924f9e7..1e8f948 100644 --- a/velocity/src/main/java/io/github/_4drian3d/authmevelocity/velocity/listener/data/PluginMessageListener.java +++ b/velocity/src/main/java/io/github/_4drian3d/authmevelocity/velocity/listener/data/PluginMessageListener.java @@ -91,26 +91,26 @@ public final class PluginMessageListener implements Listener plugin.logDebug("PluginMessageEvent | Logout type"); if (player != null && plugin.removePlayer(player)){ eventManager.fireAndForget(new ProxyLogoutEvent(player)); - plugin.logDebug("PluginMessageEvent | Player not null"); + plugin.logDebug(() -> "PluginMessageEvent | Player " + name + " not null"); } } case REGISTER -> { plugin.logDebug("PluginMessageEvent | Register"); if (player != null) { eventManager.fireAndForget(new ProxyRegisterEvent(player)); - plugin.logDebug("PluginMessageEvent | Player not null"); + plugin.logDebug(() -> "PluginMessageEvent | Player " + name + " not null"); } } case UNREGISTER -> { plugin.logDebug("PluginMessageEvent | Unregister type"); if (player != null) { - plugin.logDebug("PluginMessageEvent | Player not null"); + plugin.logDebug(() -> "PluginMessageEvent | Player " + name + " not null"); eventManager.fireAndForget(new ProxyUnregisterEvent(player)); } } case FORCE_UNREGISTER -> { eventManager.fireAndForget(new ProxyForcedUnregisterEvent(player)); - plugin.logDebug("PluginMessageEvent | Forced Unregister type"); + plugin.logDebug(() -> "PluginMessageEvent | Forced Unregister type, player " + name); } } @@ -135,6 +135,7 @@ public final class PluginMessageListener implements Listener } if (plugin.config().get().sendOnLogin().isRequirePermission() && !player.hasPermission("authmevelocity.send-on-login")) { + plugin.logDebug(() -> "PluginMessageEvent # createServerConnectionRequest | The player does not have permission " + player.getUsername()); return; } diff --git a/velocity/src/main/java/io/github/_4drian3d/authmevelocity/velocity/listener/input/ChatListener.java b/velocity/src/main/java/io/github/_4drian3d/authmevelocity/velocity/listener/input/ChatListener.java index 5d20f4a..34fd374 100644 --- a/velocity/src/main/java/io/github/_4drian3d/authmevelocity/velocity/listener/input/ChatListener.java +++ b/velocity/src/main/java/io/github/_4drian3d/authmevelocity/velocity/listener/input/ChatListener.java @@ -40,12 +40,12 @@ public final class ChatListener implements Listener { public EventTask executeAsync(final PlayerChatEvent event) { return EventTask.withContinuation(continuation -> { if (plugin.isLogged(event.getPlayer())) { - plugin.logDebug("PlayerChatEvent | Player is already logged"); + plugin.logDebug(() -> "PlayerChatEvent | Player " + event.getPlayer().getUsername() + " is already logged"); continuation.resume(); return; } - plugin.logDebug("PlayerChatEvent | Player is not logged"); + plugin.logDebug(() -> "PlayerChatEvent | Player " + event.getPlayer().getUsername() + " is not logged"); event.setResult(PlayerChatEvent.ChatResult.denied()); continuation.resume(); diff --git a/velocity/src/main/java/io/github/_4drian3d/authmevelocity/velocity/listener/input/CommandListener.java b/velocity/src/main/java/io/github/_4drian3d/authmevelocity/velocity/listener/input/CommandListener.java index 2590428..0e6dd50 100644 --- a/velocity/src/main/java/io/github/_4drian3d/authmevelocity/velocity/listener/input/CommandListener.java +++ b/velocity/src/main/java/io/github/_4drian3d/authmevelocity/velocity/listener/input/CommandListener.java @@ -43,27 +43,27 @@ public final class CommandListener implements Listener { public EventTask executeAsync(final CommandExecuteEvent event) { return EventTask.withContinuation(continuation -> { if (!(event.getCommandSource() instanceof final Player player)) { - plugin.logDebug("CommandExecuteEvent | CommandSource is not a player"); + plugin.logDebug(() -> "CommandExecuteEvent | CommandSource is not a player"); continuation.resume(); return; } if (plugin.isLogged(player)) { - plugin.logDebug("CommandExecuteEvent | Player is already logged"); + plugin.logDebug(() -> "CommandExecuteEvent | Player "+ player.getUsername() +" is already logged"); continuation.resume(); return; } if (plugin.isInAuthServer(player)) { - plugin.logDebug("CommandExecuteEvent | Player is in Auth Server"); + plugin.logDebug(() -> "CommandExecuteEvent | Player "+ player.getUsername() +" is in Auth Server"); final String command = AuthMeUtils.getFirstArgument(event.getCommand()); if (!plugin.config().get().commands().allowedCommands().contains(command)) { - plugin.logDebug("CommandExecuteEvent | Player executed an blocked command"); + plugin.logDebug(() -> "CommandExecuteEvent | Player "+ player.getUsername() +" executed an blocked command"); sendBlockedMessage(player); event.setResult(CommandExecuteEvent.CommandResult.denied()); } } else { - plugin.logDebug("CommandExecuteEven | Player is not in auth server"); + plugin.logDebug(() -> "CommandExecuteEvent | Player "+ player.getUsername() +" is not in auth server"); sendBlockedMessage(player); event.setResult(CommandExecuteEvent.CommandResult.denied()); } diff --git a/velocity/src/main/java/io/github/_4drian3d/authmevelocity/velocity/listener/input/CompletionPacketListener.java b/velocity/src/main/java/io/github/_4drian3d/authmevelocity/velocity/listener/input/CompletionPacketListener.java index 4c7ef68..f46bca5 100644 --- a/velocity/src/main/java/io/github/_4drian3d/authmevelocity/velocity/listener/input/CompletionPacketListener.java +++ b/velocity/src/main/java/io/github/_4drian3d/authmevelocity/velocity/listener/input/CompletionPacketListener.java @@ -46,7 +46,7 @@ public final class CompletionPacketListener implements Listener final Player player = event.getPlayer(); return EventTask.async(() -> { if (plugin.isLogged(player)) { - plugin.logDebug("PacketSendEvent | TabCompleteResponse | Player is already logged"); + plugin.logDebug(() -> "PacketSendEvent | TabCompleteResponse | Player " + player.getUsername() + " is already logged"); return; } responsePacket.getOffers().clear(); diff --git a/velocity/src/main/java/io/github/_4drian3d/authmevelocity/velocity/listener/input/TabCompleteListener.java b/velocity/src/main/java/io/github/_4drian3d/authmevelocity/velocity/listener/input/TabCompleteListener.java index f5e267f..dc7be33 100644 --- a/velocity/src/main/java/io/github/_4drian3d/authmevelocity/velocity/listener/input/TabCompleteListener.java +++ b/velocity/src/main/java/io/github/_4drian3d/authmevelocity/velocity/listener/input/TabCompleteListener.java @@ -40,7 +40,7 @@ public class TabCompleteListener implements Listener { public EventTask executeAsync(final TabCompleteEvent event) { return EventTask.async(() -> { if (plugin.isLogged(event.getPlayer())) { - plugin.logDebug("TabCompleteEvent | Player is already logged"); + plugin.logDebug("TabCompleteEvent | Player " + event.getPlayer().getUsername() + " is already logged"); return; } @@ -51,7 +51,7 @@ public class TabCompleteListener implements Listener { } } - plugin.logDebug("TabCompleteEvent | Not allowed tab-completion"); + plugin.logDebug("TabCompleteEvent | " + event.getPlayer().getUsername() + " | Not allowed tab-completion"); event.getSuggestions().clear(); }); }