Listener unregs on disable automaticly?

Discussion in 'Plugin Development' started by PreFiXAUT, Nov 29, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    PreFiXAUT

    Hello everybody, I'm trying to finish off my (probably) last Plugin, but there's something weird going on.
    I'm trying to use as much Events as possible in Key-Features (to make an "API" kinda), and some Stuff I need to trigger when the Plugin shut's down (saving stuff etc.). Stuff like that is happening in these Events because they are kinda important, but they dont trigger.

    Is Bukkit shutting down the Listener itself before it's calling the Pluigins onDisable() Method or am I doin something wrong? :confused:

    Thanks in advance
     
  2. Offline

    timtower Administrator Administrator Moderator

    PreFiXAUT Probably not, but we can't help without code.
     
  3. Offline

    PreFiXAUT

    Alright -> onDisable()
    Show Spoiler

    Code:java
    1. @Override
    2. public void onDisable() {
    3. try {
    4. Main.checkDBFiles();
    5. if (dbg()) info("Clearing Lobbies ...");
    6. Lobbies.clearLobbys(); // Triggers
    7. Lobbies.updateAll();
    8. if (dbg()) info("Lobbies cleared.");
    9. if (dbg()) info("Saving Databases ...");
    10. Register.lobbies.saveToFile();
    11. Register.players.saveToFile();
    12. Register.points.saveToFile();
    13. Register.stations.saveToFile();
    14. Register.leavers.saveToFile();
    15. if(dbg()) info("Databases saved.");
    16. info("has shutdown successfully!");
    17. } catch (Exception e) {
    18. e.printStackTrace();
    19. return;
    20. }
    21. }


    clearLobbies()
    Show Spoiler

    Code:java
    1. public static void clearLobbys() {
    2. List<Lobby> lobs = Register.lobbies.getData();
    3. if (lobs == null) return;
    4. for (Lobby l : lobs) {
    5. LobbyPlayers pl = Register.getPlayers(l);
    6. if (pl == null) pl = new LobbyPlayers(l.getId());
    7. for (Player p : pl.getPlayers()) {
    8. System.out.println(p); // Triggers
    9. Lobbies.leaveLobby(p, l, LeaveType.KICK); // Triggers
    10. }
    11. pl.setUuids(new ArrayList<UUID>());
    12. l.setPlayercount(0);
    13. Register.overrideLobby(l);
    14. Register.overridePlayers(pl);
    15. }
    16. updateAll();
    17. }


    EventListener
    Show Spoiler

    Code:java
    1. @EventHandler(priority = EventPriority.LOWEST)
    2. public void onPlayerLeave(PlayerLeaveLobbyEvent e) {
    3. System.out.println(e); // Doesn't trigger
    4. if (e.isCancelled()) {
    5. if (ConfigManager.debugOn()) Main.info("Leave cancelled.");
    6. return;
    7. }
    8. Lobby l = e.getLobby();
    9. LobbyPlayers pl = Register.getPlayers(l);
    10. if (!pl.getPlayers().contains(e.getPlayer())) return; // Doesn't return
    11. pl.removePlayer(e.getPlayer());
    12. l.setPlayercount(l.getPlayerCount()-1);
    13. l.update();
    14. Register.overridePlayers(pl);
    15. Register.overrideLobby(l);
    16. switch (e.getCause()) {
    17. case DISCONNECT:
    18. break;
    19. case KICK_PREMIUM: Main.msg(e.getPlayer(), Message.LEAVE_PREMIUM_KICK);
    20. break;
    21. case LEFT: Main.msg(e.getPlayer(), Message.LEAVE_LEFT);
    22. break;
    23. case KICK: Main.msg(e.getPlayer(), Message.LEAVE_KICK);
    24. break;
    25. case CUSTOM: e.getPlayer().sendMessage(e.getMessage());
    26. break;
    27. default:
    28. break;
    29. } // No Message but I'm triggering it with KICK
    30. if (ConfigManager.debugOn()) Main.info(e.getPlayer().getName() + "(" + e.getPlayer().getUniqueId() + ") left " + e.getLobby().getId());
    31. }

     
  4. Offline

    timtower Administrator Administrator Moderator

    PreFiXAUT Could be wrong here, but aren't players disconnected after the plugins are disabled?
     
  5. Offline

    PreFiXAUT

    Nope, since I'm only reloading the Server. When it stops/reloads it has to kick every Player out of a Lobby
     
  6. Offline

    timtower Administrator Administrator Moderator

    Isn't that happening then? Are you sure that it isn't in your leaveLobby method?
     
  7. Offline

    PreFiXAUT

    Well it's just calling the Event with the given parameters
     
  8. Offline

    timtower Administrator Administrator Moderator

    LeaveLobby is an event? Could you post the code for that method?
     
  9. Offline

    PreFiXAUT

    It's just a shortcut
    Show Spoiler

    Code:java
    1. public static void leaveLobby(Player player, Lobby lobby, LeaveType cause, String message) {
    2. PlayerLeaveLobbyEvent e = new PlayerLeaveLobbyEvent(player, lobby, cause, message);
    3. System.out.println("leaveLobby" + e); // Debug message - Triggers
    4. Bukkit.getPluginManager().callEvent(e);
    5. }

     
  10. Offline

    timtower Administrator Administrator Moderator

    PreFiXAUT Calling an event doesn't mean taking actions with it.
    You still have to kick yourself
     
  11. Offline

    PreFiXAUT

    I'm doing it :confused:

    How the entire thing works now: onDisable() calls clearLobbies() so all Lobbies are empty when the Plugin disables. clearLobbies() loops through every Lobby, get's the Players which are in it and calls the leaveLobby() with each Player in it. leaveLobby() is just a shortcut to call the PlayerLeaveLobbyEvent() which takes care to remove the Player from the Lobby.
     
  12. Offline

    timtower Administrator Administrator Moderator

    PreFiXAUT But calling an event doesn't perform the kick.
     
  13. Offline

    PreFiXAUT

    ?? It does. The Event has all needed Parameters for it. The Player, the Lobby he leaves, the Reason and optional the Message which will only be send when the Reason is "CUSTOM". IDK where your problem is.

    This Event is also called when I issue a Command and this works fine.
     
  14. Offline

    timtower Administrator Administrator Moderator

    PreFiXAUT That the event is called doesn't mean that it will also take actions.
    That is something the developer needs to do as far as I know.
     
  15. Offline

    PreFiXAUT

    It is done! Check the EventListener in the 2nd post of mine
     
  16. Offline

    PreFiXAUT

Thread Status:
Not open for further replies.

Share This Page