-
-
Notifications
You must be signed in to change notification settings - Fork 585
Update deprecated PlayerLoginEvent to AsyncPlayerPreLoginEvent #2219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: version/7.0.x
Are you sure you want to change the base?
Conversation
@EventHandler(ignoreCancelled = true) | ||
public void onPlayerLogin(PlayerLoginEvent event) { | ||
Player player = event.getPlayer(); | ||
public void onPlayerLogin(AsyncPlayerPreLoginEvent event) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this retain Spigot compatibility? From memory, that was the early concern with moving to this event
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is compatible with Spigot API. It has been stable for many versions and is still present up to version 1.21.8. This event is safe to use for async pre-login logic that doesn't require access to the Player object.
WorldGuard.getInstance().getProfileCache().put(new Profile(player.getUniqueId(), player.getName()))); | ||
|
||
if (cfg.deopOnJoin) { | ||
player.setOp(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible for the player to perform any actions (eg, send commands) prior to this event being fired?
From memory, this event is fired once everything was loaded, and at least in the past the player had partial capabilities prior to this point. Not sure if that's been resolved with the various new stages in the protocol during login though.
If that's the case, it might actually remove some of the purpose of this config option
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's correct. Moving the deopOnJoin logic to PlayerJoinEvent could introduce a small window in which an OP player could technically execute a privileged command before being deopped. Since AsyncPlayerPreLoginEvent doesn’t provide a Player object, there might not be a clean way to deop earlier without relying on deprecated methods.
Here's a possible workaround that will check if the player is OP when the config is set to de-op on join before they send a command. The issue is that if the player meets both requirements (is both an OP and should be de-opped on join), it will prevent them from sending any commands at all until everything has fully loaded. Because that is a small or even negligible time window, this could be acceptable. I can't think of another way at the moment.
@EventHandler(priority = EventPriority.HIGHEST)
public void onCommand(PlayerCommandPreprocessEvent event) {
Player player = event.getPlayer();
ConfigurationManager cfg = getConfig();
if (player.isOp() && cfg.deopOnJoin) {
event.setCancelled(true);
player.sendMessage(ChatColor.RED + "Please wait until you've fully joined.");
}
}
This PR updates the plugin to replace usage of the deprecated
PlayerLoginEvent
event withAsyncPlayerPreLoginEvent
per issue #2216, following the latest Bukkit API deprecations.