Advertisement
iTzAyhamHD

Untitled

Jun 30th, 2021
887
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.33 KB | None | 0 0
  1. /**
  2.  *   This file is part of Skript.
  3.  *
  4.  *  Skript is free software: you can redistribute it and/or modify
  5.  *  it under the terms of the GNU General Public License as published by
  6.  *  the Free Software Foundation, either version 3 of the License, or
  7.  *  (at your option) any later version.
  8.  *
  9.  *  Skript is distributed in the hope that it will be useful,
  10.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.  *  GNU General Public License for more details.
  13.  *
  14.  *  You should have received a copy of the GNU General Public License
  15.  *  along with Skript.  If not, see <http://www.gnu.org/licenses/>.
  16.  *
  17.  * Copyright Peter Güttinger, SkriptLang team and contributors
  18.  */
  19. package ch.njol.skript.events;
  20.  
  21. import ch.njol.skript.Skript;
  22. import ch.njol.skript.entity.EntityData;
  23. import ch.njol.skript.lang.Literal;
  24. import ch.njol.skript.lang.SkriptEvent;
  25. import ch.njol.skript.lang.SkriptParser.ParseResult;
  26. import ch.njol.skript.log.ErrorQuality;
  27. import ch.njol.skript.registrations.Classes;
  28. import ch.njol.util.StringUtils;
  29. import ch.njol.util.coll.CollectionUtils;
  30. import org.bukkit.entity.Entity;
  31. import org.bukkit.entity.HumanEntity;
  32. import org.bukkit.entity.LivingEntity;
  33. import org.bukkit.event.Event;
  34. import org.bukkit.event.block.BlockEvent;
  35. import org.bukkit.event.block.BlockExplodeEvent;
  36. import org.bukkit.event.entity.EntityDeathEvent;
  37. import org.bukkit.event.entity.EntityExplodeEvent;
  38. import org.bukkit.event.entity.EntitySpawnEvent;
  39. import org.eclipse.jdt.annotation.Nullable;
  40.  
  41. /**
  42.  * @author Peter Güttinger
  43.  */
  44. @SuppressWarnings("unchecked")
  45. public final class EvtExplode extends SkriptEvent {
  46.  
  47.     private final static int ENTITY = 1, BLOCK = 2, ANY = ENTITY | BLOCK;
  48.  
  49.     static {
  50.         Class<? extends Event>[] eventTypes = CollectionUtils.array(EntityExplodeEvent.class, BlockExplodeEvent.class);
  51.  
  52.         Skript.registerEvent("entity/block explode", EvtExplode.class, eventTypes, "[(1¦entity|2¦block)] explo(d(e|ing)|sion)")
  53.                 .description(
  54.                     "Called when an entity (a primed TNT or a creeper) explodes " +
  55.                     "OR Called when a block explodes. (Also triggered by <a href='effects.html#EffExplosion'>create explosion effect</a>)" +
  56.                     " " +
  57.                     "If explosion type is specified only that type of explosion will trigger the event.")
  58.                 .examples("on explode:",
  59.                         "\tbroadcast \"a(n) %explosion type% just exploded.\"",
  60.                         "on block explode:",
  61.  
  62.                         "\tbroadcast \"A block just exploded\"",
  63.                         "on entity explode:",
  64.  
  65.                         "\tbroadcast \"An entity just exploded\"")
  66.                 .since("1.0, INSERT VERSION (block explode)");
  67.     }
  68.    
  69.     @Nullable
  70.     private int type;
  71.    
  72.     @SuppressWarnings("null")
  73.     @Override
  74.     public boolean init(final Literal<?>[] args, final int matchedPattern, final ParseResult parser) {
  75.         type = parser.mark == 0 ? ANY : parser.mark;
  76.         return true;
  77.     }
  78.    
  79.     @SuppressWarnings("null")
  80.     @Override
  81.     public boolean check(final Event e) {
  82.         if (type == ENTITY)
  83.             return e instanceof EntityExplodeEvent ? true : false;
  84.  
  85.         if (type == BLOCK)
  86.             return e instanceof BlockExplodeEvent ? true : false;
  87.  
  88.         else // Any
  89.             return true;
  90.     }
  91.    
  92.     @Override
  93.     public String toString(final @Nullable Event e, final boolean debug) {
  94.         return (type == ENTITY ? "entity" : type == BLOCK ? "block" : "any") + (" explode");
  95.     }
  96.    
  97. }
  98.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement