misc(debug): Improved Plugin Messaging Listener debug mode

This commit is contained in:
Adrian 2023-12-07 11:52:47 -05:00
parent 2df0a8b8a4
commit 52b0dca96a
No known key found for this signature in database
GPG Key ID: FB8EF84DCE1BE452
2 changed files with 21 additions and 7 deletions

View File

@ -239,13 +239,13 @@ public final class AuthMeVelocityPlugin implements AuthMeVelocityAPI {
return config.get().authServers().contains(server);
}
public void logDebug(String msg) {
public void logDebug(final String msg) {
if (config.get().advanced().debug()) {
logger.info("[DEBUG] {}", msg);
}
}
public void logDebug(Supplier<String> msg) {
public void logDebug(final Supplier<String> msg) {
if (config.get().advanced().debug()) {
logger.info("[DEBUG] {}", msg.get());
}

View File

@ -57,11 +57,7 @@ public final class PluginMessageListener implements Listener<PluginMessageEvent>
@Override
public EventTask executeAsync(final PluginMessageEvent event) {
return EventTask.async(() -> {
final boolean cancelled = !event.getResult().isAllowed()
|| !(event.getSource() instanceof ServerConnection)
|| !(event.getIdentifier().equals(AuthMeVelocityPlugin.MODERN_CHANNEL)
|| event.getIdentifier().equals(AuthMeVelocityPlugin.LEGACY_CHANNEL));
if (cancelled) {
if (notAllowedEvent(event)) {
plugin.logDebug("PluginMessageEvent | Not allowed");
return;
}
@ -117,6 +113,24 @@ public final class PluginMessageListener implements Listener<PluginMessageEvent>
});
}
private boolean notAllowedEvent(PluginMessageEvent event) {
if (!event.getResult().isAllowed()) {
plugin.logDebug("PluginMessageEvent | Result not allowed");
return true;
}
if (!(event.getSource() instanceof ServerConnection)) {
plugin.logDebug("PluginMessageEvent | Not ServerConnection");
return true;
}
final var identifier = event.getIdentifier();
if (!(identifier.equals(AuthMeVelocityPlugin.MODERN_CHANNEL)
|| identifier.equals(AuthMeVelocityPlugin.LEGACY_CHANNEL))) {
plugin.logDebug("PluginMessageEvent | Not AuthMeVelocity Identifier");
return true;
}
return false;
}
private void createServerConnectionRequest(final Player player, final ServerConnection connection){
final RegisteredServer loginServer = player.getCurrentServer().orElse(connection).getServer();