Solved Dead Glitch

Discussion in 'Plugin Development' started by CheesyFreezy, Feb 16, 2015.

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

    CheesyFreezy

    Hi hi developers,

    I'm making a FFA plugin it's all done except at this part. Sometime (~1/50) the players will be shown like this:
    [​IMG]

    This is the piece of code where the player dies and it health will be set to 20 again:
    Code:
        @SuppressWarnings("deprecation")
        @EventHandler
        public void onPlayerDeath(PlayerDeathEvent event) {
            final Player player = event.getEntity();
            event.setDeathMessage(null);
            event.getDrops().clear();
           
            player.setHealth(20);
           
            Bukkit.getServer().getScheduler().runTaskLater(core, new Runnable() {
                public void run() {
                    player.setFireTicks(0);
                    player.setHealth(20);
                    player.setFoodLevel(20);
                   
                    File file = new File("plugins/GalacticEssentials/", "spawns.yml");
                    YamlConfiguration fileConfig = YamlConfiguration.loadConfiguration(file);
                        
                    double x = fileConfig.getInt(player.getWorld().getName() + ".x");
                    double y = fileConfig.getInt(player.getWorld().getName() + ".y");
                    double z = fileConfig.getInt(player.getWorld().getName() + ".z");
                    double pitch = fileConfig.getInt(player.getWorld().getName() + ".pitch");
                    double yaw = fileConfig.getInt(player.getWorld().getName() + ".yaw");
                   
                    Location loc = player.getLocation();
                    loc.setX(x);
                    loc.setY(y);
                    loc.setZ(z);
                    loc.setPitch((float) pitch);
                    loc.setYaw((float) yaw);
                   
                    player.teleport(loc);
                   
                    player.getInventory().clear();
               }
         }, 2);
    }
    How can i fix this?
     
  2. Offline

    tomudding

    You set the player his health back to 20 while still in the DeathEvent. Make an extra function (or how you call it in java) and do everything from line 7 (code you posted) to line 36 in that function
     
  3. Offline

    Konato_K

    @CheesyFreezy Simply don't "revive" the player in the death event, force the respawn one tick later.
     
    CheesyFreezy likes this.
  4. Offline

    CheesyFreezy

    @tomudding why are you trying to help if you don't even know java?
    @Konato_K, that worked, thanks :p
     
  5. Offline

    Techy4198

    I think that actually you should be able to just cancel the event and set health back to 20.
     
  6. Offline

    Konato_K

    @Techy4198 PlayerDeathEvent is not cancellable.
     
Thread Status:
Not open for further replies.

Share This Page