package com.btk5h.skriptmirror.skript.custom;

import org.bukkit.event.Event;

import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;

public class CustomSyntaxExpression extends SimpleExpression<Object> {
  private Expression<?> source;
  private Event realEvent;

  public CustomSyntaxExpression(Expression<?> source, Event realEvent) {
    this.source = source;
    this.realEvent = realEvent;
  }

  public static CustomSyntaxExpression wrap(Expression<?> source, Event realEvent) {
    if (source instanceof CustomSyntaxExpression) {
      return (CustomSyntaxExpression) source;
    }
    return new CustomSyntaxExpression(source, realEvent);
  }

  @Override
  protected Object[] get(Event e) {
    return source.getAll(realEvent);
  }

  @Override
  public boolean isSingle() {
    return source.isSingle();
  }

  @Override
  public Class<?> getReturnType() {
    return source.getReturnType();
  }

  @Override
  public String toString(Event e, boolean debug) {
    return source.toString(realEvent, debug);
  }

  @Override
  public Expression<?> getSource() {
    return source;
  }

  @Override
  public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) {
    throw new UnsupportedOperationException();
  }
}

@@ -802,32 +802,65 @@
  e) %7B%0A    return
+ source == null ? new Object%5B0%5D :
  source.getAll(r
@@ -919,32 +919,50 @@
 e() %7B%0A    return
+ source == null %7C%7C
  source.isSingle
@@ -1020,32 +1020,64 @@
 e() %7B%0A    return
+ source == null ? Object.class :
  source.getRetur
@@ -1159,24 +1159,46 @@
 %7B%0A    return
+ source == null ? %22%22 :
  source.toSt

Fix NPE with nullable expressions in custom syntax