Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Enable or Disabling Damage Events

Comments in 'Plugin Development' started by Anton Magsino, Jun 20, 2015.

  1. Anton Magsino
    Offline

    Anton Magsino Active Member

    Joined:
    Jan 17, 2014
    Posts:
    58
    Minecraft User:
    MinecrafterPH
    Is there a way to enable or disable damage events from a config? (e.g Disable fall damage and enable other damage events) Thanks!
  2. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    use EntityDamageEvent and EntityDamageByEntityEvent and $entity->getLastDamageCause() and $event->setCamcelled()
  3. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    The point is CONFIG.
    Parsing config:
    PHP:
    foreach($this->getConfig ()->get("disabled") as $type) {
      if(
    defined ($name EntityDamageEvent::class . "::CAUSE_" strtoupper($type))) $this->disabled [constant($name)] = true;
    }
    Event handler:
    PHP:
    if(isset($this->disabled[$event->getCause()])) $event->setCancelled();
    Warning: this method is very hacky. Don't use it unless you know what you're doing.

Share This Page

Advertisement