Skip to content

Conversation

Woodstop
Copy link

This PR updates the plugin to replace usage of the deprecated PlayerLoginEvent event with AsyncPlayerPreLoginEvent per issue #2216, following the latest Bukkit API deprecations.

@Woodstop Woodstop closed this Jul 19, 2025
@Woodstop Woodstop reopened this Jul 19, 2025
@EventHandler(ignoreCancelled = true)
public void onPlayerLogin(PlayerLoginEvent event) {
Player player = event.getPlayer();
public void onPlayerLogin(AsyncPlayerPreLoginEvent event) {
Copy link
Member

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

Copy link
Author

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);
Copy link
Member

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

Copy link
Author

@Woodstop Woodstop Jul 20, 2025

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.");
        }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants