Solved Quit events

Discussion in 'Spigot Plugin Development' started by leoyt185owner, Aug 2, 2018.

  1. I want to run a command when the server stops o crashes, i've tried to use PlayerKickEvent and PlayerQuitEvent but it seems that only work when they get disconnected by itselfs
     
  2. Choco

    Moderator

    When the server stops or crashes, no commands are dispatched at all. The server's shutting down... it can't dispatch any commands. What exactly are you trying to do?
     
    • Agree Agree x 1
  3. Run the code in your onDisable method.
     
  4. I'm trying to clear the inv when the servers stops or crashes
     
  5. I'm going to try it
     
  6. Code (Text):
      public void onDisable(){
    }
      @EventHandler
          public void AlKickear(PlayerQuitEvent event){
          for (Player all : Bukkit.getOnlinePlayers())
          {
            all.getInventory().clear();
            clearArmor(all);
          }
      }
    It is right like this?
     
  7. If this were to be put on a server, and one player woulf leave, everyones inventory would be wiped.
    Code (Text):
      public void onDisable(){
          for (Player all : Bukkit.getOnlinePlayers())
          {
            all.getInventory().clear();
            clearArmor(all);
          }
      }
    Here you go.
     
  8. Thanks, now works!