Console command at action

Discussion in 'Plugin Development' started by Azra666, Sep 27, 2019.

  1. Offline

    Azra666

    hi guys
    I need your help. I'm trying to program a plugin right now
    which triggers a console command in the event of an opponent's death.
    Can you give me a short code example for that? I get the rest alone, I think.
     
  2. Offline

    timtower Moderator Moderator

  3. Offline

    Azra666

    I dont get any further...
    the query works but I can not generate a console command instead of an output
    Code:
    package listeners;
    
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    //import org.bukkit.command.ConsoleCommandSender;
    //import org.bukkit.entity.Player;
    //import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    //import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.PlayerDeathEvent;
    //import org.bukkit.event.player.PlayerJoinEvent;
    //import org.bukkit.inventory.ItemStack;
    //import org.bukkit.inventory.ItemStack;
    //import org.bukkit.inventory.meta.ItemMeta;
    //import org.bukkit.Material;
    //import org.bukkit.command.*;
    //import org.bukkit.inventory.PlayerInventory;
    
    
    public class Head implements Listener {
       
       
    
      @EventHandler
      public void onKill(PlayerDeathEvent e)
      {     
      String killed = e.getEntity().getName();
      String killer = e.getEntity().getKiller().getName();
      e.setDeathMessage( killed + " from " + killer + "killed");
      System.out.println("Death");
      }
       
    }
     
    Last edited by a moderator: Sep 27, 2019
  4. Offline

    timtower Moderator Moderator

    @Azra666 What information are you missing then?
     
  5. Offline

    Azra666

    I want to use the console to give the player an item that killed his opponent...
    but unfortunately I can not do that.
     
  6. Offline

    timtower Moderator Moderator

    What is going wrong then? What are you unable to do?
    And do note that you can give items through code as well.
     
  7. Offline

    Azra666

    I just want an item in the killer's inventory on an enemy's death but everything I've tried so far does not work
    so I wanted to go the easy way over the console. If anyone could show me that, I would be really grateful.
     
  8. Offline

    timtower Moderator Moderator

    @Azra666 What have you tried so far?
     
  9. Offline

    Azra666

    this one was copy and paste and does not work at all

    Code:
    package listeners;
    
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.PlayerDeathEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.Material;
    
    public class Head implements Listener {
       
       
       @EventHandler (priority=EventPriority.NORMAL)
       public void onDeath(PlayerDeathEvent e) {
         if(e.getEntity().getKiller() instanceof Player) {
           Player killer = e.getEntity().getKiller();
           ItemStack Kopf = new ItemStack(Material.STONE_SWORD, 1);
           ItemMeta meta = Kopf.getItemMeta();
           meta.setDisplayName("ยง6"+e.getEntity().getName());
           Kopf.setItemMeta(meta);
           killer.getInventory().addItem(Kopf);
           
         }
         
       }
    }
    the functionality would be exactly what I need
    if it would work

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Sep 27, 2019
  10. Offline

    timtower Moderator Moderator

    @Azra666 killer.updateInventory();
    And if that doesn't work then make sure that the event even fires.
     
  11. Offline

    Azra666

    thank you very much ... the update was the solution.
    :)
     

Share This Page