Solved Add player in ArrayList on QuitEvent, use it on JoinEvent.

Discussion in 'Spigot Plugin Development' started by J0hny, Jun 23, 2022 at 11:30 PM.

  1. Hello,

    As title says I want to save a player in an Array list on QuitEvent based on a boolean.
    Code (Java):
    @EventHandler
        public void onQuit(PlayerQuitEvent e) {

            Player p = e.getPlayer();
            boolean flight = p.getAllowFlight();

            if (!flight) {
                flightoff.add(p);
            }
        }
    This part of the code works. Now once I use this list (flightoff) on the JoinEvent, it skips to the else part below.
    Code (Java):
    if (OnQuit.flightoff.contains(p)) {
                        p.setAllowFlight(false);
                    } else {
                        if (!(FlyCmd.list.contains(p))) {
                            FlyCmd.list.add(p);
                            p.setAllowFlight(true);
                        }
                    }
    Any ideas why it doesn't keep the player in flightoff list since they Quit until their next Join?
    Yes both events are in different classes and both registered properly in onEnable();

    Cheers,
    iJ0hny.
     
  2. You're trying to store a player object in a list which might not be 'equal' when the player rejoins. Try storing the player's UUID instead as that will remain constant no matter what.
     
    • Winner Winner x 1
  3. That did the job. Cheers!