Solved Spams death in chat?

Discussion in 'Plugin Development' started by Faith, Jun 30, 2013.

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

    Faith

    I have written a plugin which kills a player on when they touch water but it seems to spam the chat with "Player died" when the plugin takes effect. There is no error in the console, it just spams the same message. Anyone got any idea of how I could fix this? Any help is appreciated.

    [​IMG]
    [​IMG]
     
  2. Offline

    Jake0oo0

  3. Offline

    Faith

    Jake0oo0
    Code:java
    1. package me.faithdev.DeathWater;
    2.  
    3. import org.bukkit.Material;
    4. import org.bukkit.entity.Player;
    5. import org.bukkit.event.EventHandler;
    6. import org.bukkit.event.Listener;
    7. import org.bukkit.event.player.PlayerMoveEvent;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9.  
    10. public class DeathWater extends JavaPlugin implements Listener {
    11.  
    12. public void onEnable() {
    13. getServer().getPluginManager().registerEvents(this, this);
    14. }
    15.  
    16. @EventHandler
    17. public void onPlayerMove(PlayerMoveEvent e) {
    18. Player p = e.getPlayer();
    19.  
    20. if (p.getLocation().getBlock().getType() == Material.WATER
    21. || (p.getLocation().getBlock().getType() == Material.STATIONARY_WATER)) {
    22. p.setHealth(0);
    23. }
    24. }
    25.  
    26. }
    27.  
     
  4. Offline

    Compressions

    Faith While you are on the respawn screen, Bukkit probably thinks that you are still in the water that you died in.
     
  5. Offline

    Shockwave317

    I agree i think it still thinks ur their since ur a entity but a dead invisible one
     
  6. Offline

    Faith

    Shockwave317 Compressions The only way I can think of fixing it is teleporting the player up out of water when they die, can you think of any other way?
     
  7. Offline

    pope_on_dope

    You can use the isDead method for checks.

    edit: this code works, just tested.
    Code:
    @EventHandler
        public void onPlayerMove(PlayerMoveEvent e) {
        Player p = e.getPlayer();
        if(p.isDead() == true)return;
        if (p.getLocation().getBlock().getType() == Material.WATER
        || (p.getLocation().getBlock().getType() == Material.STATIONARY_WATER)) {
        p.setHealth(0);
        }
        }
     
  8. Offline

    CakePvP

    Code:
    @EventHandler
    public void onPlayerMove(PlayerMoveEvent e) {
    Player p = e.getPlayer();
     
    if (p.getLocation().getBlock().getType() == Material.WATER
    || (p.getLocation().getBlock().getType() == Material.STATIONARY_WATER) && p.getHealth() > 0) {
    p.setHealth(0);
    }
    }
    
    Tada!
     
    Faith likes this.
  9. Offline

    Faith

    CakePvP Thanks, appreciate it.
     
  10. Offline

    LittleMonster7_

    Just a tip, heres a better way to register listeners.

    Code:
        @Override
        public void onEnable()
        {
            getServer().getPluginManager().registerEvents(new Listener(){
    // Put listener here.
            }, this);
        }
     
  11. Offline

    Henzz

    LittleMonster7_
    What's the point of making an anonymous class? It's much more organised if you have it in a separate class. :p
     
  12. Offline

    Faith

    This thread was solved hours ago. Please stop commenting.

    Also, Henzz, may I ask where you got that sig picture from? Would love to know.
     
  13. Offline

    Henzz

    Faith
    Made it with Paint.NET, also may want to prefix it since you said it was already solved.
     
Thread Status:
Not open for further replies.

Share This Page