Solved SkipRespawnScreen bug

Discussion in 'Plugin Development' started by Omerrg, Feb 2, 2013.

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

    Omerrg

    Hey guys, im trying to make it that when player is fighting with another player, and one of them die it will broadcast the kill message i want but instead of killing them it will heal them and respawn in the spawn of the world. The problem is that because the if statement that checks if the player get killed is wrong because if the player life is equal to the damage the sword gives it still kill him before there is another attack, my code is here:
    Code:
       
    //All rights of this code reserved to Omerrg and please dont steal it.
    @EventHandler
        public void onDeath(EntityDamageEvent event) {
            if(event instanceof EntityDamageByEntityEvent){
                EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event;
         
            Entity damager = e.getDamager();
            Entity player = event.getEntity();
            if (player instanceof Player && damager instanceof Player) {
                Player p = (Player) player;
                Integer damage = event.getDamage();
                Integer pHealth = p.getHealth();
                if (pHealth - damage <= 0) {
                    Player victim = (Player) e.getEntity();
                    Player damager2 = (Player) e.getDamager();
                    event.setCancelled(true);
                    Bukkit.broadcastMessage(ChatColor.LIGHT_PURPLE + "[P" + ChatColor.GOLD + "K]" +ChatColor.RED + "" + ChatColor.BOLD +damager2.getDisplayName() + ChatColor.DARK_RED + " Just killed " + ChatColor.GRAY + ChatColor.BOLD + victim.getDisplayName());
                    Location loc = p.getWorld().getSpawnLocation();
                    p.teleport(loc);
                    p.getInventory().clear();
                    p.setHealth(20);
                    p.setFoodLevel(17);
                    p.getInventory().setHelmet(null);
                    p.getInventory().setChestplate(null);
                    p.getInventory().setLeggings(null);
                    p.getInventory().setBoots(null);
                    for(PotionEffect effect : p.getActivePotionEffects())
                    {
                        p.removePotionEffect(effect.getType());
             
                    }
                }
     
            }
        }
        }
    bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  2. Offline

    Kazzababe

  3. Offline

    Omerrg

  4. Offline

    przemek3697

    Code:
     
    @EventHandler
    public void onPlayerDead(PlayerDeathEvent e){
     Location loc = e.getEntity().getLocation();
     World world= e.getEntity().getWorld();
     for(ItemStack item : e.getDrops()){
      if(item != null){
       world.dropItemNaturally(loc, item);
      }
    }
    e.getDrops().clear();
    e.getEntity().set........;
    ...
    ...
    Location loc1 = getPlugin().getServer().getWorld("world").getSpawnLocation();
    e.getEntity().teleport(loc1);
    
    This is my code from my testing plugin.
    How can something that does not work write and show error's from the console
     
    Omerrg likes this.
  5. Offline

    Omerrg

    I still can't realize how to do this.. Can someone help?
     
  6. Offline

    Miner_Fil

  7. Offline

    Omerrg

    ?.. Maybe fireblast709 can help me?
     
  8. Offline

    przemek3697

    Write again what you want to do because I do not know how to help you.
    Please you wrote is exactly because they do not know English well
     
  9. Offline

    Omerrg

    I wanted to ask that if someone is getting killed, it will send a costum message and instead of showing the respawn screen it will just tp him to spawn. (after clearing his potions, inventory and armor)
     
  10. Offline

    McCastleWars

    Somewhat a bump. (I want it too except the tp him to spawn but I can adjust that)
     
  11. Offline

    przemek3697

    Code:java
    1.  
    2. @EventHandler
    3. public void onPlayerDeath(PlayerDeathEvent e){
    4. e.setDeathMessage(null);
    5. for(Player p: Bukkit.getServer().getOnlinePlayers()){
    6. p.sendMessage("Player "+e.getEntity().getKiller().getName()+" kill "+e.getEntity().getName());
    7. }
    8. Player p = e.getEntity();
    9. Location loc1 = p.getLocation();
    10. for(ItemStack is : e.getDrops()){
    11. if(is != null){
    12. p.getWorld().dropItemNaturally(loc1, is);
    13. }
    14. }
    15. e.getDrops().clear();
    16. p.setHealth(20);
    17. p.setFireTicks(0);
    18. p.setFoodLevel(20);
    19. p.setLevel(0);
    20. for(PotionEffect pe : p.getActivePotionEffects()){
    21. p.removePotionEffect(pe.getType());
    22. }
    23. p.teleport(p.getWorld().getSpawnLocation());
    24. }
    25.  

    ok?
     
  12. Offline

    Omerrg

    Not working :S
     
  13. Offline

    Comphenix

    Don't do this. Even if this did work, which it doesn't (there's a teleport bug and a NPE), it would still break a lot of plugins that expect or use the respawn event.

    Whenever there's a thread like this (and there's been plenty), there's always someone who posts a half-assed solution that breaks plugins, doesn't cover all the corner-cases and often, though not always, is completely broken from the get-go. I refer you to this thread for an example, or this.

    The method you posted has a ton of limitations, including (from the threads above):
    In any case, use packets. It's the most reliable method:
    Code:java
    1. Packet205ClientCommand packet = new Packet205ClientCommand();
    2. packet.a = 1;
    3. ((CraftPlayer) player).getHandle().playerConnection.a(packet);
     
  14. Offline

    Omerrg

    Nvm, i found another topic that shows it.
    -SOLVED
     
  15. Offline

    lcpvp

    Link to the topic, so that people that have similar problems can maybe find a solution as well.
     
Thread Status:
Not open for further replies.

Share This Page