Kick after death

Discussion in 'Plugin Development' started by jersogamer, Dec 15, 2018.

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

    jersogamer

    Hello, first of all, I want to apologize about my english, it is not good.

    I'm developing a plugin wich kicks players afther their death, I know that there are already many plugins that do that stuff, but I'm making mine, because I want to learn, to make them and I want to include something unique to the plugin that any other doesn't have.

    My problem appears when the player dies, because when the player dies my plugin kick them out, but the action of kick them out is ocurring first than their death, so the player doesn't lose their inventory.

    what do I mean?

    Example of my server console:
    [15:40:34 INFO]: jersogamer issued server command: /gamemode creative
    [15:40:34 INFO]: [jersogamer: Set own game mode to Creative Mode]
    [15:40:43 INFO]: jersogamer issued server command: /gamemode survival
    [15:40:43 INFO]: [jersogamer: Set own game mode to Survival Mode]

    //All the part before it's just because I got in creative mode, fly high and then I change my gamemode into survival

    [15:40:45 INFO]: Killed jersogamer - //As you can see here I apperently died
    [15:40:45 INFO]: jersogamer lost connection: Estas muerto jersogamer tienes que esperar 10s para ingresar de nuevo - //Then i lost my connection and the message says " You are dead jersogamer you gotta wait 10 second to log in back
    [15:40:45 INFO]: jersogamer left the game - //This part is so important 'cause here i left the game, it wasn't me, i guess it's the kick from the plugin
    [15:40:45 INFO]: Kicked jersogamer: Estas muerto jersogamer tienes que esperar 10s para ingresar de nuevo
    //Here appears the kick part, when I alredy was kick as you can se in the last part
    [15:40:45 INFO]: jersogamer fell from a high place
    //And HERE appears my death!!!, but i'm not already on the server
    [15:40:45 WARN]: handleDisconnection() called twice
    //I dont understand that jajaja

    Well as you can see all the logs from the console it's backwards!, I guess the players don't lose the inventory because they are kicked out first than die. I hope you understand what I mean

    Code:
    @EventHandler
        public void wDie(PlayerDeathEvent event) {
           
            Player jugador = event.getEntity().getPlayer();
            FileConfiguration config = plugin.getConfig();
            Cooldown cool = new Cooldown(plugin);
            String pathtime = "Player.Muertes."+jugador.getUniqueId()+".cooldown-muerte";
            Nombre = jugador.getName();
            if(jugador != null && jugador.getType().equals(EntityType.PLAYER)) {
                if(!config.contains("Player.Muertes."+jugador.getUniqueId()+".name")) {
                   
                    config.set("Player.Muertes."+jugador.getUniqueId()+".name", jugador.getName());
                    long millis = System.currentTimeMillis(); 
                    config.set(pathtime, millis);
                    plugin.saveConfig();
                   
                   
                   
                    }else {
                       
                    long millis = System.currentTimeMillis(); 
                    config.set(pathtime, millis);
                    plugin.saveConfig();
                   
                                   }   
                }
           
            Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "kick "+Nombre+" Estas muerto "+ Nombre+" tienes que esperar "+ cool.getCooldown(jugador)+" para ingresar de nuevo");
            }
    There are parts in spanish but are just paths for the cooldown in the config. so i guess it is a bug and I dont know how to solve it.

    i dont know how to death first and then get kicked correctly.

    IF SOMEONE DONT UNDERSTAND SOMETHING PLEASE TELL ME, I'LL TRY TO EXPLAIN BETTER
     
  2. @jersogamer

    I suggest you use the Bukkit Scheduler (Bukkit.getScheduler() ) to schedule a delayed task where you kick the player.
     
  3. Offline

    Zombie_Striker

  4. Offline

    jersogamer

    I finally do it, thank you so much both, those advices helped me a lot!!!!

    Here is the final code if someone is interested:

    Code:
    @EventHandler
        public void wDie(final PlayerDeathEvent event) {
            new BukkitRunnable() {
    
                @Override
                public void run() {
                    Player jugador = event.getEntity().getPlayer();
                    FileConfiguration config = plugin.getConfig();
                    Cooldown cool = new Cooldown(plugin);
                    String pathtime = "Player.Muertes."+jugador.getUniqueId()+".cooldown-muerte";
                    Nombre = jugador.getName();
                    if(jugador != null && jugador.getType().equals(EntityType.PLAYER)) {
                        if(!config.contains("Player.Muertes."+jugador.getUniqueId()+".name")) {
                           
                            config.set("Player.Muertes."+jugador.getUniqueId()+".name", jugador.getName());
                            long millis = System.currentTimeMillis(); 
                            config.set(pathtime, millis);
                            plugin.saveConfig();
                           
                           
                           
                            }else {
                               
                            long millis = System.currentTimeMillis(); 
                            config.set(pathtime, millis);
                            plugin.saveConfig();
                           
                                           }   
                        }
               
                    Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "kick "+Nombre+" Estas muerto "+ Nombre+" tienes que esperar "+ cool.getCooldown(jugador)+" para ingresar de nuevo");
                }
    
            }.runTaskLater(this.plugin, 20);
        }
     
    Last edited: Dec 15, 2018
Thread Status:
Not open for further replies.

Share This Page