ch.njol.skript.lang.Expression Java Examples

The following examples show how to use ch.njol.skript.lang.Expression. 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: ExprBlocks.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("null")
@Override
@Nullable
protected Block[] get(final Event e) {
	final Expression<Direction> direction = this.direction;
	if (direction != null && !from.isSingle()) {
		final Location[] ls = (Location[]) from.getArray(e);
		final Direction d = direction.getSingle(e);
		if (ls.length == 0 || d == null)
			return new Block[0];
		final Block[] bs = new Block[ls.length];
		for (int i = 0; i < ls.length; i++) {
			bs[i] = d.getRelative(ls[i]).getBlock();
		}
		return bs;
	}
	final ArrayList<Block> r = new ArrayList<>();
	final Iterator<Block> iter = iterator(e);
	if (iter == null)
		return new Block[0];
	for (final Block b : new IteratorIterable<>(iter))
		r.add(b);
	return r.toArray(new Block[r.size()]);
}
 
Example #2
Source File: CondCanHold.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings({"unchecked", "null"})
@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parser) {
	invis = (Expression<Inventory>) exprs[0];
	items = (Expression<ItemType>) exprs[1];
	if (items instanceof Literal) {
		for (ItemType t : ((Literal<ItemType>) items).getAll()) {
			t = t.getItem();
			if (!(t.isAll() || t.getTypes().size() == 1)) {
				Skript.error("The condition 'can hold' can currently only be used with aliases that start with 'every' or 'all', or only represent one item.", ErrorQuality.SEMANTIC_ERROR);
				return false;
			}
		}
	}
	setNegated(matchedPattern == 1);
	return true;
}
 
Example #3
Source File: ExprEntities.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
	types = (Expression<? extends EntityData<?>>) exprs[0];
	if (matchedPattern % 2 == 0) {
		for (EntityData<?> d : ((Literal<EntityData<?>>) types).getAll()) {
			if (d.isPlural().isFalse() || d.isPlural().isUnknown() && !StringUtils.startsWithIgnoreCase(parseResult.expr, "all"))
				return false;
		}
	}
	isUsingRadius = matchedPattern >= 2;
	if (isUsingRadius) {
		radius = (Expression<Number>) exprs[exprs.length - 2];
		center = (Expression<Location>) exprs[exprs.length - 1];
	} else {
		if (parseResult.mark == 1) {
			chunks = (Expression<Chunk>) exprs[2];
		} else {
			worlds = (Expression<World>) exprs[1];
		}
	}
	if (types instanceof Literal && ((Literal<EntityData<?>>) types).getAll().length == 1)
		returnType = ((Literal<EntityData<?>>) types).getSingle().getType();
	return true;
}
 
Example #4
Source File: Argument.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
private Argument(@Nullable final String name, final @Nullable Expression<? extends T> def, final ClassInfo<T> type, final boolean single, final int index, final boolean optional) {
	this.name = name;
	this.def = def;
	this.type = type;
	this.single = single;
	this.index = index;
	this.optional = optional;
}
 
Example #5
Source File: EffOp.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings({"unchecked", "null"})
@Override
public boolean init(final Expression<?>[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parseResult) {
	players = (Expression<OfflinePlayer>) exprs[0];
	op = !parseResult.expr.substring(0, 2).equalsIgnoreCase("de");
	return true;
}
 
Example #6
Source File: EffRespawn.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings({"unchecked", "null"})
@Override
public boolean init(final Expression<?>[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parseResult) {
	players = (Expression<Player>) exprs[0];
	if (ScriptLoader.isCurrentEvent(PlayerDeathEvent.class) && ScriptLoader.hasDelayBefore.isTrue()) // Then we will internally force you to wait
		hasDelay = true;

	return true;
}
 
Example #7
Source File: ExprTimeState.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean init(final Expression<?>[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parseResult) {
	final Expression<?> expr = exprs[0];
	if (isDelayed == Kleenean.TRUE) {
		Skript.error("Cannot use time states after the event has already passed", ErrorQuality.SEMANTIC_ERROR);
		return false;
	}
	if (!expr.setTime(matchedPattern >= 2 ? 1 : -1)) {
		Skript.error(expr + " does not have a " + (matchedPattern >= 2 ? "future" : "past") + " state", ErrorQuality.SEMANTIC_ERROR);
		return false;
	}
	setExpr(expr);
	return true;
}
 
Example #8
Source File: EffBossBarRemoveFlag.java    From skRayFall with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] exp, int arg1, Kleenean arg2, ParseResult arg3) {
    flag = (Expression<RayFallBarFlag>) exp[0];
    id = (Expression<String>) exp[1];
    return true;
}
 
Example #9
Source File: EffParticlesV1_12.java    From skRayFall with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] exp, int arg1, Kleenean arg2, ParseResult arg3) {
    partNum = (Expression<Number>) exp[0];
    type = (Expression<String>) exp[1];
    location = (Expression<Location>) exp[2];
    xoffset = (Expression<Number>) exp[4];
    yoffset = (Expression<Number>) exp[5];
    zoffset = (Expression<Number>) exp[6];
    player = (Expression<Player>) exp[3];
    return true;
}
 
Example #10
Source File: EffKick.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings({"unchecked", "null"})
@Override
public boolean init(final Expression<?>[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parseResult) {
	players = (Expression<Player>) exprs[0];
	reason = (Expression<String>) exprs[1];
	return true;
}
 
Example #11
Source File: ExprGetHoloLine.java    From skRayFall with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] exp, int arg1, Kleenean arg2, ParseResult arg3) {
    id = (Expression<String>) exp[1];
    line = (Expression<Number>) exp[0];
    return true;
}
 
Example #12
Source File: EffFireworkLaunch.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings({"unchecked", "null"})
@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
	effects = (Expression<FireworkEffect>) exprs[0];
	locations = (Expression<Location>) exprs[1];
	lifetime = (Expression<Number>) exprs[2];
	return true;
}
 
Example #13
Source File: EffEffectLibBleed.java    From skRayFall with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] exp, int arg1, Kleenean arg2, ParseResult arg3) {
    target = exp[0];
    id = (Expression<String>) exp[1];
    return true;
}
 
Example #14
Source File: ExprExperience.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean init(final Expression<?>[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parseResult) {
	if (!ScriptLoader.isCurrentEvent(ExperienceSpawnEvent.class)) {
		Skript.error("The experience expression can only be used in experience spawn events");
		return false;
	}
	return true;
}
 
Example #15
Source File: EffRemovePlayersFromTeam.java    From skRayFall with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] exp, int arg1, Kleenean arg2, ParseResult arg3) {
    player = (Expression<Player>) exp[0];
    team = (Expression<String>) exp[1];
    return true;
}
 
Example #16
Source File: ExprServerIcon.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
	if (!PAPER_EVENT_EXISTS) {
		Skript.error("The server icon expression requires Paper 1.12.2 or newer");
		return false;
	}
	isServerPingEvent = ScriptLoader.isCurrentEvent(PaperServerListPingEvent.class);
	isDefault = (parseResult.mark == 0 && !isServerPingEvent) || parseResult.mark == 1;
	if (!isServerPingEvent && !isDefault) {
		Skript.error("The 'shown' server icon expression can't be used outside of a server list ping event");
		return false;
	}
	return true;
}
 
Example #17
Source File: CondCompare.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public boolean check(final Event e) {
	final Expression<?> third = this.third;
	return first.check(e,
			(Checker<Object>) o1 -> second.check(e,
					(Checker<Object>) o2 -> {
						if (third == null)
							return relation.is(comp != null ? comp.compare(o1, o2) : Comparators.compare(o1, o2));
						return third.check(e,
								(Checker<Object>) o3 -> relation == Relation.NOT_EQUAL ^
										(Relation.GREATER_OR_EQUAL.is(comp != null ? comp.compare(o1, o2) : Comparators.compare(o1, o2))
												&& Relation.SMALLER_OR_EQUAL.is(comp != null ? comp.compare(o1, o3) : Comparators.compare(o1, o3))));
					}), isNegated());
}
 
Example #18
Source File: CondIsInWorld.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings({"unchecked", "null"})
@Override
public boolean init(final Expression<?>[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parseResult) {
	entities = (Expression<Entity>) exprs[0];
	worlds = (Expression<World>) exprs[1];
	setNegated(matchedPattern == 1);
	return true;
}
 
Example #19
Source File: EffActionBarV1_9_4.java    From skRayFall with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] exp, int arg1, Kleenean arg2, ParseResult arg3) {
    player = (Expression<Player>) exp[0];
    text = (Expression<String>) exp[1];

    return true;
}
 
Example #20
Source File: EffCreateTeam.java    From skRayFall with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] exp, int arg1, Kleenean arg2, ParseResult arg3) {
    name = (Expression<String>) exp[0];
    players = (Expression<Player>) exp[1];
    return true;
}
 
Example #21
Source File: CondResourcePack.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings({"unchecked", "null"})
@Override
public boolean init(final Expression<?>[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parseResult) {
	if (!ScriptLoader.isCurrentEvent(PlayerResourcePackStatusEvent.class)) {
		Skript.error("The resource pack condition can't be used outside of a resource pack response event");
		return false;
	}
	states = (Expression<Status>) exprs[0];
	setNegated(matchedPattern == 1);
	return true;
}
 
Example #22
Source File: ExprName.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings({"null", "unchecked"})
@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
	type = NameType.values()[parseResult.mark];
	if (exprs[0] instanceof Variable)
		setExpr(exprs[0].getConvertedExpression(Object.class));
	else
		setExpr(exprs[0]);
	return true;
}
 
Example #23
Source File: CondScriptLoaded.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings({"unchecked"})
@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) {
	scripts = (Expression<String>) exprs[0];
	setNegated(matchedPattern == 1);
	assert ScriptLoader.currentScript != null;
	currentScriptFile = ScriptLoader.currentScript.getFile();
	return true;
}
 
Example #24
Source File: CondIsOnline.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings({"unchecked", "null"})
@Override
public boolean init(final Expression<?>[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parseResult) {
	setExpr((Expression<OfflinePlayer>) exprs[0]);
	setNegated(matchedPattern == 1 ^ parseResult.mark == 1);
	return true;
}
 
Example #25
Source File: ExprAbsorbedBlocks.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
	if (!ScriptLoader.isCurrentEvent(SpongeAbsorbEvent.class)) {
		Skript.error("The 'absorbed blocks' are only usable in sponge absorb events", ErrorQuality.SEMANTIC_ERROR);
		return false;
	}
	return true;
}
 
Example #26
Source File: CondIsOfType.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("null")
@Override
public boolean init(final Expression<?>[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parseResult) {
	what = exprs[0];
	types = exprs[1];
	setNegated(matchedPattern == 1);
	return true;
}
 
Example #27
Source File: CondIsRiding.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings({"unchecked", "null"})
@Override
public boolean init(final Expression<?>[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parseResult) {
	entities = (Expression<Entity>) exprs[0];
	types = (Expression<EntityData<?>>) exprs[1];
	setNegated(matchedPattern == 1);
	return true;
}
 
Example #28
Source File: CondItemInHand.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings({"unchecked", "null"})
@Override
public boolean init(final Expression<?>[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parser) {
	entities = (Expression<LivingEntity>) exprs[0];
	types = (Expression<ItemType>) exprs[1];
	if (Skript.isRunningMinecraft(1, 9)) {
		offTool = (matchedPattern == 2 || matchedPattern == 3 || matchedPattern == 6 || matchedPattern == 7);
		setNegated(matchedPattern >= 4);
	} else {
		offTool = false;
		setNegated(matchedPattern >= 2);
	}
	return true;
}
 
Example #29
Source File: EffCreateCitizen.java    From skRayFall with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] exprs, int arg1, Kleenean arg2, ParseResult arg3) {
    name = (Expression<String>) exprs[0];
    location = Direction.combine((Expression<? extends Direction>) exprs[1],
            (Expression<? extends Location>) exprs[2]);
    type = (Expression<EntityType>) exprs[3];
    return true;
}
 
Example #30
Source File: ExprVectorAngleBetween.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings({"unchecked", "null"})
@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
	first = (Expression<Vector>) exprs[0];
	second = (Expression<Vector>) exprs[1];
	return true;
}