mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2026-11-28 03:25:36 +00:00
Improve debug logging for Hytale login handling
This commit is contained in:
3 files changed
+59
-10
No files matched your search
@@ -43,6 +43,7 @@ import net.kyori.adventure.text.format.TextColor;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
import net.luckperms.api.util.Tristate;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -124,9 +125,11 @@ public class HytaleSenderFactory extends SenderFactory<LPHytalePlugin, IMessageR
|
||||
|
||||
if (sender instanceof CommandSender commandSender) {
|
||||
CommandManager.get().handleCommand(commandSender, command).join();
|
||||
return;
|
||||
}
|
||||
if (sender instanceof PlayerRef playerRef) {
|
||||
CommandManager.get().handleCommand(playerRef, command).join();
|
||||
return;
|
||||
}
|
||||
|
||||
throw new AssertionError();
|
||||
@@ -138,36 +141,41 @@ public class HytaleSenderFactory extends SenderFactory<LPHytalePlugin, IMessageR
|
||||
}
|
||||
|
||||
public static Message toHytaleMessage(Component component) {
|
||||
if (!(component instanceof TextComponent text)) {
|
||||
Message message;
|
||||
if (component instanceof TextComponent text) {
|
||||
message = Message.raw(text.content());
|
||||
} else {
|
||||
throw new UnsupportedOperationException("Unsupported component type: " + component.getClass());
|
||||
}
|
||||
|
||||
Message message = Message.raw(text.content());
|
||||
|
||||
TextColor color = text.color();
|
||||
TextColor color = component.color();
|
||||
if (color != null) {
|
||||
message.color(color.asHexString());
|
||||
}
|
||||
|
||||
TextDecoration.State bold = text.decoration(TextDecoration.BOLD);
|
||||
TextDecoration.State bold = component.decoration(TextDecoration.BOLD);
|
||||
if (bold != TextDecoration.State.NOT_SET) {
|
||||
message.bold(bold == TextDecoration.State.TRUE);
|
||||
}
|
||||
|
||||
TextDecoration.State italic = text.decoration(TextDecoration.ITALIC);
|
||||
TextDecoration.State italic = component.decoration(TextDecoration.ITALIC);
|
||||
if (italic != TextDecoration.State.NOT_SET) {
|
||||
message.italic(italic == TextDecoration.State.TRUE);
|
||||
}
|
||||
|
||||
ClickEvent clickEvent = text.clickEvent();
|
||||
ClickEvent clickEvent = component.clickEvent();
|
||||
if (clickEvent != null && clickEvent.action() == ClickEvent.Action.OPEN_URL) {
|
||||
message.link(clickEvent.value());
|
||||
}
|
||||
|
||||
message.insertAll(text.children().stream()
|
||||
List<Message> children = component.children().stream()
|
||||
.map(HytaleSenderFactory::toHytaleMessage)
|
||||
.toList()
|
||||
);
|
||||
.toList();
|
||||
|
||||
if (!children.isEmpty()) {
|
||||
message.insertAll(children);
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
}
|
||||
+31
@@ -27,6 +27,7 @@ package me.lucko.luckperms.hytale.listeners;
|
||||
|
||||
import com.hypixel.hytale.event.EventPriority;
|
||||
import com.hypixel.hytale.event.EventRegistry;
|
||||
import com.hypixel.hytale.server.core.event.events.player.PlayerConnectEvent;
|
||||
import com.hypixel.hytale.server.core.event.events.player.PlayerDisconnectEvent;
|
||||
import com.hypixel.hytale.server.core.event.events.player.PlayerSetupConnectEvent;
|
||||
import com.hypixel.hytale.server.core.universe.PlayerRef;
|
||||
@@ -57,6 +58,7 @@ public class HytaleConnectionListener extends AbstractConnectionListener {
|
||||
public void register(EventRegistry registry) {
|
||||
registry.register(EventPriority.EARLY, PlayerSetupConnectEvent.class, this::onPlayerPreLogin);
|
||||
registry.register(EventPriority.LAST, PlayerSetupConnectEvent.class, this::onPlayerPreLoginMonitor);
|
||||
registry.register(EventPriority.NORMAL, PlayerConnectEvent.class, this::onPlayerPostLogin);
|
||||
registry.register(EventPriority.LAST, PlayerDisconnectEvent.class, this::onPlayerQuit);
|
||||
}
|
||||
|
||||
@@ -118,6 +120,35 @@ public class HytaleConnectionListener extends AbstractConnectionListener {
|
||||
}
|
||||
}
|
||||
|
||||
private void onPlayerPostLogin(PlayerConnectEvent e) {
|
||||
/* Called when the player starts logging into the server.
|
||||
At this point, the users data should be present and loaded. */
|
||||
|
||||
PlayerRef player = e.getPlayerRef();
|
||||
|
||||
if (this.plugin.getConfiguration().get(ConfigKeys.DEBUG_LOGINS)) {
|
||||
this.plugin.getLogger().info("Processing post-login for " + player.getUuid() + " - " + player.getUsername());
|
||||
}
|
||||
|
||||
final User user = this.plugin.getUserManager().getIfLoaded(player.getUuid());
|
||||
if (user != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!getUniqueConnections().contains(player.getUuid())) {
|
||||
this.plugin.getLogger().warn("User " + player.getUuid() + " - " + player.getUsername() +
|
||||
" doesn't have data pre-loaded, they have never been processed during pre-login in this session." +
|
||||
" - denying login.");
|
||||
} else {
|
||||
this.plugin.getLogger().warn("User " + player.getUuid() + " - " + player.getUsername() +
|
||||
" doesn't currently have data pre-loaded, but they have been processed before in this session." +
|
||||
" - denying login.");
|
||||
}
|
||||
|
||||
Component reason = TranslationManager.render(Message.LOADING_STATE_ERROR.build(), player.getLanguage());
|
||||
player.getPacketHandler().disconnect(PlainTextComponentSerializer.plainText().serialize(reason));
|
||||
}
|
||||
|
||||
private void onPlayerQuit(PlayerDisconnectEvent e) {
|
||||
final PlayerRef player = e.getPlayerRef();
|
||||
handleDisconnect(player.getUuid());
|
||||
|
||||
+10
@@ -41,6 +41,7 @@ import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class LuckPermsPermissionProvider implements PermissionProvider {
|
||||
private static final String PERMISSION_PROVIDER_NAME = "LuckPerms";
|
||||
@@ -53,6 +54,8 @@ public class LuckPermsPermissionProvider implements PermissionProvider {
|
||||
private final PlayerVirtualGroupsMap playerVirtualGroupsMap;
|
||||
/** Whether to delegate operations on groups/users not managed by LuckPerms to the built-in Hytale provider */
|
||||
private final boolean delegateToHytaleProvider;
|
||||
/** A set of UUIDs of users who have been delegated to the Hytale provider */
|
||||
private final Set<UUID> delegatedUsers = ConcurrentHashMap.newKeySet();
|
||||
|
||||
public LuckPermsPermissionProvider(LPHytalePlugin plugin, HytalePermissionsProvider hytaleProvider, PlayerVirtualGroupsMap playerVirtualGroupsMap) {
|
||||
this.plugin = plugin;
|
||||
@@ -76,6 +79,9 @@ public class LuckPermsPermissionProvider implements PermissionProvider {
|
||||
if (user != null) {
|
||||
return new LuckPermsPermissionsSet(user);
|
||||
} else if (this.delegateToHytaleProvider) {
|
||||
if (this.delegatedUsers.add(userUniqueId)) {
|
||||
this.plugin.getLogger().warn("LuckPerms does not have permissions data loaded for user '" + userUniqueId + "', so their checks will be delegated to the Hytale provider.");
|
||||
}
|
||||
return this.hytaleProvider.getUserPermissions(userUniqueId);
|
||||
} else {
|
||||
return Set.of();
|
||||
@@ -111,6 +117,10 @@ public class LuckPermsPermissionProvider implements PermissionProvider {
|
||||
return groups;
|
||||
|
||||
} else if (this.delegateToHytaleProvider) {
|
||||
if (this.delegatedUsers.add(userUniqueId)) {
|
||||
this.plugin.getLogger().warn("LuckPerms does not have permissions data loaded for user '" + userUniqueId + "', so their checks will be delegated to the Hytale provider.");
|
||||
}
|
||||
|
||||
Set<String> groups = new HashSet<>(virtualGroups);
|
||||
groups.addAll(this.hytaleProvider.getGroupsForUser(userUniqueId));
|
||||
return groups;
|
||||
|
||||
Reference in new issue
Block a user