Interact and EntityDamage Event! Help!

Discussion in 'Plugin Development' started by Chibbey, Nov 23, 2013.

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

    Chibbey

    Hello, I'm making a kitpvp plugin and there is a class called "Assassin". The class contains the Assassin command and kit stuff. They get full black leather armour with protection 1 and a stone sword and I wanna give them a slime ball that when they hit a player the player gets poison. I'm guessing you use a playerinteract event to see if there hitting with the slime ball and EntityDamage event to give them the poison. I just don't know how. so im guessing checking if a player is hitting with a slimeball you use
    if (event.getPlayer().getItemInHand().equals(Material.SLIME_BALL) {
    }
    or something but im not sure so could you help. If your still confused I need help giving people posion for 5 seconds when a player gets hit by someone with a slimeball. Please help!
     
  2. Offline

    2016mfransen

    what you want to do first is create an event method like so
    Code:java
    1. public class SlimeBallListener implements Listener
    2. {
    3. //this code may not be perfect trying to remember it
    4. @EventHandler
    5. public void onHit(PlayerDamageEvent e)
    6. {
    7. if(e.EntityType = EntityType.SLIME_BALL)
    8. {
    9. //do stuff
    10. }
    11. }
    12. }

    then to register this place this code block on your onenable method in your plugin main class
    Code:java
    1. Bukkit.getPluginManager().registerEvents(new SlimeBallListener(), this);
     
  3. Offline

    Chibbey

    2016mfransen
    Theres no such thing as a playerdamageevent and a slimeball is a material not a entitytype entitytype is a living thing like a player or a slime or zombie. thanks for trying though. Could someone please help!
     
  4. Offline

    Commander9292

    Chibbey use an EntityDamageByEntityEvent and check if both of the Entities are players, else if they are not players return/cancel the event. If they are players get the one that is attacking and make sure they have a slimeball then apply the potion effect to the one being attacked and if you want you can cancel the event so the player does take damage but still gets the potion effect.

    P.S. The one attacking is: e.getDamager(); and the one being attacked is:e.getEntity();
     
  5. Offline

    Chibbey

    Commander9292
    Could you help me I don't really get what your saying. I do I just don't really know the code for it
     
  6. Offline

    rbrick

    Code:java
    1. @EventHandler
    2. public void onHit(EntityDamageByEntityEvent e){
    3. //Tests to see if they are both players
    4. if(e.getDamager() instanceof Player && e.getEntity() instanceof Player){
    5.  
    6. }
    7. }
    8. }

    It would be something like that
     
  7. Offline

    Commander9292

    Chibbey pretty much what rbrick said! If you still don't understand I can help you out.
     
  8. Offline

    rbrick

    sorry for all the editing on my post i keep forgetting which one is the attacker and which one is the attackee(is that correct ahh screw it)
     
Thread Status:
Not open for further replies.

Share This Page