Advertisement
Gamebuster

Untitled

Apr 2nd, 2016
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.38 KB | None | 0 0
  1. package ch.njol.skript.lang;
  2.  
  3. import ch.njol.skript.Skript;
  4. import ch.njol.skript.lang.Debuggable;
  5. import ch.njol.skript.lang.Trigger;
  6. import ch.njol.skript.lang.TriggerSection;
  7. import ch.njol.util.StringUtils;
  8. import java.io.File;
  9. import org.bukkit.event.Event;
  10. import org.eclipse.jdt.annotation.Nullable;
  11.  
  12. public abstract class TriggerItem
  13. implements Debuggable {
  14.     @Nullable
  15.     protected TriggerSection parent = null;
  16.     @Nullable
  17.     private TriggerItem next = null;
  18.     private static final String indent = "  ";
  19.     @Nullable
  20.     private String indentation = null;
  21.  
  22.     protected TriggerItem() {
  23.     }
  24.  
  25.     protected TriggerItem(TriggerSection parent) {
  26.         this.parent = parent;
  27.     }
  28.  
  29.     @Nullable
  30.     protected TriggerItem walk(Event e) {
  31.         if (this.run(e)) {
  32.             this.debug(e, true);
  33.             return this.next;
  34.         }
  35.         this.debug(e, false);
  36.         TriggerSection parent = this.parent;
  37.         return parent == null ? null : parent.getNext();
  38.     }
  39.  
  40.     protected abstract boolean run(Event var1);
  41.  
  42.     public static final boolean walk(TriggerItem start, Event e) {
  43.         block6 : {
  44.             assert (start != null && e != null);
  45.             TriggerItem i = start;
  46.             try {
  47.                 while (i != null) {
  48.                     i = i.walk(e);
  49.                 }
  50.                 return true;
  51.             }
  52.             catch (StackOverflowError err) {
  53.                 Trigger t = start.getTrigger();
  54.                 File sc = t == null ? null : t.getScript();
  55.                 Skript.adminBroadcast("<red>The script '<gold>" + (sc == null ? "<unknown>" : sc.getName()) + "<red>' infinitely (or excessively) repeated itself!");
  56.                 if (Skript.debug()) {
  57.                     err.printStackTrace();
  58.                 }
  59.             }
  60.             catch (Exception ex) {
  61.                 if (ex.getStackTrace().length == 0) break block6;
  62.                 Skript.exception((Throwable)ex, i, new String[0]);
  63.             }
  64.         }
  65.         return false;
  66.     }
  67.  
  68.     public String getIndentation() {
  69.         String ind = this.indentation;
  70.         if (ind == null) {
  71.             int level = 0;
  72.             TriggerItem i = this;
  73.             while ((i = i.parent) != null) {
  74.                 ++level;
  75.             }
  76.             this.indentation = ind = StringUtils.multiply("  ", level);
  77.         }
  78.         return ind;
  79.     }
  80.  
  81.     protected final void debug(Event e, boolean run) {
  82.         if (!Skript.debug()) {
  83.             return;
  84.         }
  85.         Skript.debug(String.valueOf(this.getIndentation()) + (run ? "" : "-") + this.toString(e, true));
  86.     }
  87.  
  88.     @Override
  89.     public final String toString() {
  90.         return this.toString(null, false);
  91.     }
  92.  
  93.     public TriggerItem setParent(@Nullable TriggerSection parent) {
  94.         this.parent = parent;
  95.         return this;
  96.     }
  97.  
  98.     @Nullable
  99.     public final TriggerSection getParent() {
  100.         return this.parent;
  101.     }
  102.  
  103.     @Nullable
  104.     public final Trigger getTrigger() {
  105.         TriggerItem i = this;
  106.         while (i != null && !(i instanceof Trigger)) {
  107.             i = i.getParent();
  108.         }
  109.         return (Trigger)i;
  110.     }
  111.  
  112.     public TriggerItem setNext(@Nullable TriggerItem next) {
  113.         this.next = next;
  114.         return this;
  115.     }
  116.  
  117.     @Nullable
  118.     public TriggerItem getNext() {
  119.         return this.next;
  120.     }
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement