Skip to content

Commit

Permalink
misc(debug): Improved Plugin Messaging Listener debug mode
Browse files Browse the repository at this point in the history
  • Loading branch information
4drian3d committed Dec 7, 2023
1 parent 2df0a8b commit 52b0dca
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,13 @@ public boolean isAuthServer(@NotNull String server){
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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,7 @@ public void register() {
@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;
}
Expand Down Expand Up @@ -117,6 +113,24 @@ public EventTask executeAsync(final PluginMessageEvent event) {
});
}

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();

Expand Down

0 comments on commit 52b0dca

Please sign in to comment.