EventDamageEvent

Discussion in 'Spigot Plugin Development' started by Lmperatoreq, Aug 17, 2018.

  1. Hello, I'm doing the game MurderMystery.

    I need an event so that when a player shoots a bow and gets into the player something happens, but I have an eventdamageevent disabled, help
     
  2. Create own Event. Call it when EntityDamageEvent comes.
     
  3. I do not know much about events, do you code the event?
     
  4. You make event in one class. Here's example of one:
    And remember setCancelled(true) didn't stop from doing rest of event :)
    Code (Text):

    public class onGuiClose extends Event { //sometimes implements Cancellable
       
       private static final HandlerList handlers = new HandlerList(); //You mast have these handlers
       private Player player;
       private GUI gui;
       private Inventory inv;
       
       

       public onGuiClose(Player p, GUI gui) {
           this.player = p;
           this.gui = gui;
           this.inv = this.gui.getInv();
       }
       

       public GUI getGui() {
           return gui;
       }

       public Inventory getInv() {
           return inv;
       }

       public Player getPlayer() {
           return player;
       }

       @Override
       public HandlerList getHandlers() { //You must have this too
           return handlers;
       }
           
       public static HandlerList getHandlerList() { //And these
           return handlers;
       }

    }
     
    And it's just a class. Make sure you have constructor with object that you want ex. Player, How much damage was dealed, Entity whoDealt etc.

    Now when EntityDamageEvent comes:

    Code (Text):

    @EventHandler
    public void onDmg(EntityDamageEvent e) {
    MyEvent event = new MyEvent(Here you put object from EntityDamageEvent to constructor);
    Bukkit.getPluginManager().callEvent(event);
    }
     
    I think I help a little bit :)
     
  5. joehot200

    Supporter

    Just to clarify, even if players can't be damaged due to a plugin, the EntityDamageEvent is still thrown - it would just be cancelled by a plugin.

    Also, you may wish to use the EntityDamageByEntityEvent to get the arrow and the shooter.
     
  6. I usage EntityDamageByEntityEvent, and..?
     
  7. I understood about the event, but it's not very clear what my own event should look like, can you do it?
     
  8. On constructor you put objecxt that you want just i soiad :) Entity ent, int DamageDealt, etc. on making event in EntityDamageEvent you make:
    MyEvent event = new MyEvent(e.getEntity, e.getDamage(), e....);
     
  9. joehot200

    Supporter

    Code (Java):

    @EventHandler
    public void onMyAwesomeEvent(EntityDamageByEntityEvent e){
        Entity e = e.getEntity(); //Entity hit
        Entity a = e.getDamager(); //Attacker, which will be an Arrow if hit by an arrow
    }
     
     
  10. Omg, im understand this, But this does not work because of the disabled entitydamageevent

    I need it to work with disabled EntityDamageEvent
     
  11. do you have in onEnable function Bukkit.getPluginManager().registerEvents(this, this); ?
    But EntityDamageEvent isn't EntityDamageByEntityEvent
     
  12. What exacly do you mean with "disabled"?
     
  13. joehot200

    Supporter

    The event being cancelled does not mean that it doesn't fire.
     
  14. My events is registereds
     
  15. e.setCancelled(true);
     
  16. @EventHandler(ignoreCancelled = false) Set the priority to highest and try to uncancel it :p
     
  17. Thx this is work!
     
    • Agree Agree x 1