Java Code Examples for ch.njol.skript.ScriptLoader#isCurrentEvent()

The following examples show how to use ch.njol.skript.ScriptLoader#isCurrentEvent() . 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: ExprFurnaceSlot.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings({"unchecked", "null"})
@Override
public boolean init(final Expression<?>[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parseResult) {
	isEvent = matchedPattern == 0;
	slot = parseResult.mark;
	if (isEvent && slot == RESULT && !ScriptLoader.isCurrentEvent(FurnaceSmeltEvent.class)) {
		Skript.error("Cannot use 'result slot' outside a fuel smelt event.");
		return false;
	} else if (isEvent && slot == FUEL && !ScriptLoader.isCurrentEvent(FurnaceBurnEvent.class)) {
		Skript.error("Cannot use 'fuel slot' outside a fuel burn event.");
		return false;
	}
	if (!isEvent)
		setExpr((Expression<Block>) exprs[0]);
	return true;
}
 
Example 2
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 3
Source File: ExprChatRecipients.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(AsyncPlayerChatEvent.class))) {
		Skript.error("Cannot use chat recipients expression outside of a chat event", ErrorQuality.SEMANTIC_ERROR);
		return false;
	}
	return true;
}
 
Example 4
Source File: ExprAttacker.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean init(final Expression<?>[] vars, final int matchedPattern, final Kleenean isDelayed, final ParseResult parser) {
	if (!ScriptLoader.isCurrentEvent(EntityDamageByEntityEvent.class, EntityDeathEvent.class, VehicleDamageEvent.class, VehicleDestroyEvent.class)) {
		Skript.error("Cannot use 'attacker' outside of a damage/death/destroy event", ErrorQuality.SEMANTIC_ERROR);
		return false;
	}
	return true;
}
 
Example 5
Source File: ExprRespawnLocation.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(PlayerRespawnEvent.class)) {
		Skript.error("The expression 'respawn location' may only be used in the respawn event", ErrorQuality.SEMANTIC_ERROR);
		return false;
	}
	return true;
}
 
Example 6
Source File: ExprMe.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(EffectCommandEvent.class)) {
		return false;
	}
	return true;
}
 
Example 7
Source File: ExprDrops.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(EntityDeathEvent.class)) {
		Skript.error("The expression 'drops' can only be used in death events", ErrorQuality.SEMANTIC_ERROR);
		return false;
	}
	return true;
}
 
Example 8
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 9
Source File: ExprVersionString.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(ServerListPingEvent.class)) {
		Skript.error("The version string expression requires Paper 1.12.2 or newer");
		return false;
	} else if (!(PAPER_EVENT_EXISTS && ScriptLoader.isCurrentEvent(PaperServerListPingEvent.class))) {
		Skript.error("The version string expression can't be used outside of a server list ping event");
		return false;
	}
	return true;
}
 
Example 10
Source File: ExprHotbarButton.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 parser) {
	if (!ScriptLoader.isCurrentEvent(InventoryClickEvent.class)) {
		Skript.error("The 'hotbar button' expression may only be used in an inventory click event.");
		return false;
	}
	return true;
}
 
Example 11
Source File: ExprAffectedEntities.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 parser) {
	if (!ScriptLoader.isCurrentEvent(AreaEffectCloudApplyEvent.class)) {
		Skript.error("The 'affected entities' expression may only be used in an area cloud effect event.");
		return false;
	}
	return true;
}
 
Example 12
Source File: SimpleExpression.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
protected final boolean setTime(final int time, final Expression<?> mustbeDefaultVar, final Class<? extends Event>... applicableEvents) {
	if (ScriptLoader.hasDelayBefore == Kleenean.TRUE && time != 0) {
		Skript.error("Can't use time states after the event has already passed");
		return false;
	}
	if (!mustbeDefaultVar.isDefault())
		return false;
	for (final Class<? extends Event> e : applicableEvents) {
		if (ScriptLoader.isCurrentEvent(e)) {
			this.time = time;
			return true;
		}
	}
	return false;
}
 
Example 13
Source File: ExprCmdCooldownInfo.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, SkriptParser.ParseResult parseResult) {
	pattern = matchedPattern;
	if (!ScriptLoader.isCurrentEvent(ScriptCommandEvent.class)) {
		Skript.error("The " + getExpressionName() + " expression can only be used within a command", ErrorQuality.SEMANTIC_ERROR);
		return false;
	}
	return true;
}
 
Example 14
Source File: ExprHoverList.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 hover list expression requires Paper 1.12.2 or newer");
		return false;
	} else if (!ScriptLoader.isCurrentEvent(PaperServerListPingEvent.class)) {
		Skript.error("The hover list expression can't be used outside of a server list ping event");
		return false;
	}
	return true;
}
 
Example 15
Source File: EffHidePlayerFromServerList.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) {
	boolean isServerPingEvent = ScriptLoader.isCurrentEvent(ServerListPingEvent.class) ||
			(PAPER_EVENT_EXISTS && ScriptLoader.isCurrentEvent(PaperServerListPingEvent.class));
	if (!isServerPingEvent) {
		Skript.error("The hide player from server list effect can't be used outside of a server list ping event");
		return false;
	} else if (isDelayed == Kleenean.TRUE) {
		Skript.error("Can't hide players from the server list anymore after the server list ping event has already passed");
		return false;
	}
	players = (Expression<Player>) exprs[0];
	return true;
}
 
Example 16
Source File: ExprBurnCookTime.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, SkriptParser.ParseResult parseResult) {
	cookTime = parseResult.mark == 1;
	isEvent = matchedPattern == 0;
	if (isEvent && !ScriptLoader.isCurrentEvent(FurnaceBurnEvent.class)) {
		Skript.error("Cannot use 'burning time' outside a fuel burn event.");
		return false;
	}
	if (!isEvent)
		setExpr((Expression<? extends Block>) exprs[0]);
	return true;
}
 
Example 17
Source File: ExprMessage.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) {
	type = MessageType.values()[matchedPattern];
	if (!ScriptLoader.isCurrentEvent(type.events)) {
		Skript.error("The " + type.name + " message can only be used in a " + type.name + " event", ErrorQuality.SEMANTIC_ERROR);
		return false;
	}
	return true;
}
 
Example 18
Source File: ExprDamage.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(EntityDamageEvent.class, VehicleDamageEvent.class)) {
		Skript.error("The expression 'damage' may only be used in damage events", ErrorQuality.SEMANTIC_ERROR);
		return false;
	}
	delay = isDelayed;
	return true;
}
 
Example 19
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 20
Source File: SimpleExpressionFork.java    From skript-yaml with MIT License 5 votes vote down vote up
protected final boolean setTime(final int time, final Expression<?> mustbeDefaultVar, final Class<? extends Event>... applicableEvents) {
	if (ScriptLoader.hasDelayBefore == Kleenean.TRUE && time != 0) {
		Skript.error("Can't use time states after the event has already passed");
		return false;
	}
	if (!mustbeDefaultVar.isDefault())
		return false;
	for (final Class<? extends Event> e : applicableEvents) {
		if (ScriptLoader.isCurrentEvent(e)) {
			this.time = time;
			return true;
		}
	}
	return false;
}