get the killer that kill the player

Discussion in 'Plugin Development' started by StickyMan, Dec 8, 2012.

  1. Offline

    StickyMan

    Code (Text):
    1.   @EventHandler
    2.   public void onDeath(PlayerDeathEvent e)
    3.   {
    4.       if(e.getEntity() instanceof Player)
    5.       {
    6.           Player p = e.getEntity();
    7.           p.sendMessage("the test work");
    8.           if(e.getEntity().getKiller() instanceof Player)
    9.           {
    10.               Player killer = e.getEntity().getKiller();
    11.           killer.sendMessage("the test work");
    12.           }
    13.       }
    14.   }
    no errors but it dosen't do nothing to the killer or the death player (send message)
     
  2. Go on then.
     
  3. StickyMan
    Code (Text):
    1. @EventHandler
    2.     public void onDeath(PlayerDeathEvent e)
    3.     {
    4.         if(e.getEntity() instanceof Player) // <-- the killed player
    5.         {
    6.             Player p = e.getEntity();
    7.             if(e.getEntity().getKiller() instanceof Player) // <-- The killer player
    8.             {
    9.                 Player killer = e.getEntity().getKiller();
    And if you want to add a potion effect to the killer, do
    Code (Text):
    1. killer.addPotionEffect(new PotionEffect(PotionEffectType.POOP, 1, 200));
     
  4. Offline

    StickyMan

    and i need help with it
     
  5. He literally gave you exactly what you asked for what more do you need help with?
     
  6. Offline

    StickyMan

    Code (Text):
    1.   @EventHandler
    2.   public void onDeath(PlayerDeathEvent e)
    3.   {
    4.       if(e.getEntity() instanceof Player) // <-- the killed player
    5.       {
    6.           Player p = e.getEntity();
    7.           p.sendMessage("the test work");
    8.           if(e.getEntity().getKiller() instanceof Player) // <-- The killer player
    9.           {
    10.               Player killer = e.getEntity().getKiller();
    11.           killer.sendMessage("the test work");
    12.           }
    13.       }
    14.   }
    no errors but still do nothing
     
  7. Your class needs to implement Listener

    "public class xxxxx implements Listener {

    }"
     
  8. Offline

    StickyMan

    nice idea
    but i need more ideas

    thanks in advence
    itay
     
  9. You should start by learning java?
     
    MordorKing78 likes this.
  10. Events also need registering, btw.
     
  11. Main class:
    Code:java
    1.  
    2. public class getkillerplugin extends JavaPlugin{
    3. public void onEnable()
    4. {
    5. PluginManager pm = getServer().getPluginManager();
    6. pm.registerEvents(new listener(this), this);
    7. }
    8. }
    9.  
    10.  

    Listener:
    Code:java
    1.  
    2. public class listener implements Listener {
    3. public getkillerplugin plugin;
    4.  
    5. public listener(getkillerplugin plugin) {
    6. this.plugin = plugin;
    7. }
    8.  
    9.  
    10. @EventHandler
    11. public void onDeath(PlayerDeathEvent e)
    12. {
    13. if(e.getEntity() instanceof Player)
    14. {
    15. Player p = e.getEntity();
    16. p.sendMessage("the test work");
    17. if(e.getEntity().getKiller() instanceof Player)
    18. {
    19. Player killer = e.getEntity().getKiller();
    20. killer.sendMessage("the test work");
    21. }
    22. }
    23. }
    24. }
    25.  


    Should do it. //still editing//
     
    StickyMan likes this.
  12. Offline

    StickyMan

    let's start with that the if you don't have something helping to say don't say it

    can you help me please i am new in develop bukkit plugins
     
  13. What? You think you can do this without learning java? At least read the bukkit wiki. You know why I don't want to help you? Because if I spoon feed you code you're going to come back every day and ask for more, and if you actually learn what you're doing you will figure things out on your own. That's why I urge brord to delete his code..
     
    number1_Master and iZanax like this.
  14. Take a look at the provided code: http://forums.bukkit.org/threads/get-the-killer-that-kill-the-player.114996/#post-1445132

    I can understand why you may not wish to help, but berating the OP doesn't really help the matter. Some people learn by example. I do admit it might be worth learning some simple Java prior to this, however.
     
    tommycake50 and StickyMan like this.
  15. IF he has basic java knowledge, and takes a look at the most simple code i gave him, he should be fine.
    I learned it by example, so i dont think others shouldnt be allowedto
     
  16. Lol
     
  17. Yea, agreed
     
  18. I'll tag you in the post he makes tomorrow.
     
  19. xD Good, ill give him a word doc with heaps of pages explaining the simple thing he needs
     
  20. It's called the bukkit wiki.
     
  21. SHhhhh
     
  22. Offline

    iZanax

    OffTopic:
    This kind of threads happen to appear more often,
    If u got stuck at some point, then it not a problem to ask around here.
    But if u don't even tried or read anything that might help, that is just bad.
    Just use Google and Java Documentation, it helps 9 out of 10 times...
    If u still get stuck, then come here, and ask so precisely as possible,
    To get the fastest and the best answer

    http://docs.oracle.com/javase/7/docs/api/ #Java Documentations
    http://docs.oracle.com/javase/tutorial/ #Java Tutorials
    http://jd.bukkit.org/doxygen/ #Bukkit Documentations
    http://wiki.bukkit.org/Plugin_Tutorial #Bukkit Tutorials
     

Share This Page