Java Code Examples for ch.njol.skript.lang.Expression#isSingle()

The following examples show how to use ch.njol.skript.lang.Expression#isSingle() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EffReturn.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public boolean init(final Expression<?>[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parseResult) {
	final ScriptFunction<?> f = Functions.currentFunction;
	if (f == null) {
		Skript.error("The return statement can only be used in a function");
		return false;
	}
	if (!isDelayed.isFalse()) {
		Skript.error("A return statement after a delay is useless, as the calling trigger will resume when the delay starts (and won't get any returned value)");
		return false;
	}
	function = f;
	final ClassInfo<?> rt = function.getReturnType();
	if (rt == null) {
		Skript.error("This function doesn't return any value. Please use 'stop' or 'exit' if you want to stop the function.");
		return false;
	}
	final RetainingLogHandler log = SkriptLogger.startRetainingLog();
	final Expression<?> v;
	try {
		v = exprs[0].getConvertedExpression(rt.getC());
		if (v == null) {
			log.printErrors("This function is declared to return " + rt.getName().withIndefiniteArticle() + ", but " + exprs[0].toString(null, false) + " is not of that type.");
			return false;
		}
		log.printLog();
	} finally {
		log.stop();
	}
	if (f.isSingle() && !v.isSingle()) {
		Skript.error("This function is defined to only return a single " + rt.toString() + ", but this return statement can return multiple values.");
		return false;
	}
	value = v;
	return true;
}
 
Example 2
Source File: ExprItems.java    From Skript with GNU General Public License v3.0 4 votes vote down vote up
@Override
public String toString(final @Nullable Event e, final boolean debug) {
	final Expression<ItemType> types = this.types;
	return (blocks ? "blocks" : "items") + (types != null ? " of type" + (types.isSingle() ? "" : "s") + " " + types.toString(e, debug) : "");
}