ch.njol.skript.lang.SkriptParser.ParseResult Java Examples

The following examples show how to use ch.njol.skript.lang.SkriptParser.ParseResult. 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: EffHealth.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<?>[] vars, final int matchedPattern, final Kleenean isDelayed, final ParseResult parser) {
	damageables = vars[0];
	if (ItemStack.class.isAssignableFrom(damageables.getReturnType())) {
		if (!ChangerUtils.acceptsChange(damageables, ChangeMode.SET, ItemType.class)) {
			Skript.error(damageables + " cannot be changed, thus it cannot be damaged or repaired.");
			return false;
		}
	}
	damage = (Expression<Number>) vars[1];
	heal = (matchedPattern >= 1);
	
	if (vars.length >= 3) dmgCause = (Expression<DamageCause>) vars[2];
	return true;
}
 
Example #2
Source File: EffCancelDrops.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
	cancelItems = parseResult.mark == 0 || parseResult.mark == 1;
	cancelExps = parseResult.mark == 0 || parseResult.mark == 2;
	if (ScriptLoader.isCurrentEvent(BlockBreakEvent.class)) {
		if (cancelItems && !CAN_CANCEL_BLOCK_ITEM_DROPS) {
			Skript.error("Cancelling drops of items in a block break event requires Minecraft 1.12 or newer");
			return false;
		}
	} else if (!ScriptLoader.isCurrentEvent(EntityDeathEvent.class)) {
		Skript.error("The cancel drops effect can't be used outside of a death" +
			(CAN_CANCEL_BLOCK_ITEM_DROPS ? " or block break" : "") + " event");
		return false;
	}
	if (isDelayed.isTrue()) {
		Skript.error("Can't cancel the drops anymore after the event has already passed");
		return false;
	}
	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: ExprBlock.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 parser) {
	if (exprs.length > 0) {
		setExpr(new ConvertedExpression<>(Direction.combine((Expression<? extends Direction>) exprs[0],
				(Expression<? extends Location>) exprs[1]), Block.class,
				new ConverterInfo<>(Location.class, Block.class, new Converter<Location, Block>() {
			@Override
			public Block convert(final Location l) {
				return l.getBlock();
			}
		}, 0)));
		return true;
	} else {
		setExpr(new EventValueExpression<>(Block.class));
		return ((EventValueExpression<Block>) getExpr()).init();
	}
}
 
Example #5
Source File: ExprAmount.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("null")
@Override
public boolean init(final Expression<?>[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parseResult) {
	expr = exprs[0];
	if (expr instanceof Literal)
		return false;
	if (expr.isSingle()) {
		Skript.error("'" + expr.toString(null, false) + "' can only ever have one value at most, thus the 'amount of ...' expression is useless. Use '... exists' instead to find out whether the expression has a value.");
		return false;
	}
	this.recursive = matchedPattern == 1;
	if (recursive && !(expr instanceof Variable<?>)) {
		Skript.error("Getting the recursive size of a list only applies to variables, thus the '" + expr.toString(null, false) + "' expression is useless.");
		return false;
	}
	return true;
}
 
Example #6
Source File: EffReplace.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings({"null"})
@Override
public boolean init(final Expression<?>[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parseResult) {
	haystack =  exprs[1 + matchedPattern % 2];
	replaceString = matchedPattern < 4;
	replaceFirst = matchedPattern > 1 && matchedPattern < 4;
	if (replaceString && !ChangerUtils.acceptsChange(haystack, ChangeMode.SET, String.class)) {
		Skript.error(haystack + " cannot be changed and can thus not have parts replaced.");
		return false;
	}
	if (SkriptConfig.caseSensitive.value() || parseResult.mark == 1) {
		caseSensitive = true;
	}
	needles = exprs[0];
	replacement = exprs[2 - matchedPattern % 2];
	return true;
}
 
Example #7
Source File: ExprAttacked.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean init(final Expression<?>[] vars, final int matchedPattern, final Kleenean isDelayed, final ParseResult parser) {
	if (!ScriptLoader.isCurrentEvent(EntityDamageEvent.class, EntityDeathEvent.class, VehicleDamageEvent.class, VehicleDestroyEvent.class)) {
		Skript.error("The expression 'victim' can only be used in a damage or death event", ErrorQuality.SEMANTIC_ERROR);
		return false;
	}
	final String type = parser.regexes.size() == 0 ? null : parser.regexes.get(0).group();
	if (type == null) {
		this.type = EntityData.fromClass(Entity.class);
	} else {
		final EntityData<?> t = EntityData.parse(type);
		if (t == null) {
			Skript.error("'" + type + "' is not an entity type", ErrorQuality.NOT_AN_EXPRESSION);
			return false;
		}
		this.type = t;
	}
	return true;
}
 
Example #8
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 #9
Source File: ExprLocationFromVector.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
@SuppressWarnings({"unchecked", "null"})
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
	if (exprs.length > 3)
		yawpitch = true;
	vector = (Expression<Vector>) exprs[0];
	world = (Expression<World>) exprs[1];
	if (yawpitch) {
		yaw = (Expression<Number>) exprs[2];
		pitch = (Expression<Number>) exprs[3];
	}
	return true;
}
 
Example #10
Source File: EvtSkript.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean init(final Literal<?>[] args, final int matchedPattern, final ParseResult parser) {
	isStart = matchedPattern == 0;
	if (parser.mark == 0) {
		Skript.warning("Server start/stop events are actually called when Skript is started or stopped. It is thus recommended to use 'on Skript start/stop' instead.");
	}
	return true;
}
 
Example #11
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 #12
Source File: ExprFileTimeAttributes.java    From skUtilities with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] e, int i, Kleenean k, ParseResult p) {
  path = (Expression<String>) e[0];
  ty = p.mark;
  return true;
}
 
Example #13
Source File: ExprLastSpawnedEntity.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) {
	if (parseResult.mark == 2) // It's just to make an extra expression for item only
		type = EntityData.fromClass(Item.class);
	else 
		type = ((Literal<EntityData<?>>) exprs[0]).getSingle();
	from = parseResult.mark;
	return true;
}
 
Example #14
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 #15
Source File: EffShoot.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) {
	types = (Expression<EntityData<?>>) exprs[matchedPattern];
	shooters = exprs[1 - matchedPattern];
	velocity = (Expression<Number>) exprs[2];
	direction = (Expression<Direction>) exprs[3];
	return true;
}
 
Example #16
Source File: ExprDistance.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<?>[] vars, final int matchedPattern, final Kleenean isDelayed, final ParseResult parseResult) {
	loc1 = (Expression<Location>) vars[0];
	loc2 = (Expression<Location>) vars[1];
	return true;
}
 
Example #17
Source File: ExprFireworkEffect.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) {
	flicker = parseResult.mark == 2 || parseResult.mark > 3;
	trail = parseResult.mark >= 3;
	hasFade = matchedPattern == 1;
	type = (Expression<FireworkEffect.Type>) exprs[0];
	color = (Expression<Color>) exprs[1];
	if (hasFade)
		fade = (Expression<Color>) exprs[2];
	return true;
}
 
Example #18
Source File: EffPlaySound.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
@SuppressWarnings({"unchecked", "null"})
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
	sounds = (Expression<String>) exprs[0];
	if (SOUND_CATEGORIES_EXIST) {
		category = (Expression<SoundCategory>) exprs[1];
		volume = (Expression<Number>) exprs[2];
		pitch = (Expression<Number>) exprs[3];
		if (matchedPattern == 0) {
			locations = (Expression<Location>) exprs[4];
			players = (Expression<Player>) exprs[5];
		} else {
			players = (Expression<Player>) exprs[4];
			locations = (Expression<Location>) exprs[5];
		}
	} else {
		volume = (Expression<Number>) exprs[1];
		pitch = (Expression<Number>) exprs[2];
		if (matchedPattern == 0) {
			locations = (Expression<Location>) exprs[3];
			players = (Expression<Player>) exprs[4];
		} else {
			players = (Expression<Player>) exprs[3];
			locations = (Expression<Location>) exprs[4];
		}
	}
	return true;
}
 
Example #19
Source File: EvtClick.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean init(final Literal<?>[] args, final int matchedPattern, final ParseResult parser) {
	click = parser.mark == 0 ? ANY : parser.mark;
	types = args[matchedPattern];
	if (types != null && !ItemType.class.isAssignableFrom(types.getReturnType())) {
		if (click == LEFT) {
			Skript.error("A leftclick on an entity is an attack and thus not covered by the 'click' event, but the 'damage' event.", ErrorQuality.SEMANTIC_ERROR);
			return false;
		} else if (click == ANY) {
			Skript.warning("A leftclick on an entity is an attack and thus not covered by the 'click' event, but the 'damage' event. Change this event to a rightclick to disable this warning message.");
		}
	}
	tools = (Literal<ItemType>) args[1 - matchedPattern];
	return true;
}
 
Example #20
Source File: ExprStringCase.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) {
	expr = (Expression<String>) exprs[0];
	if (matchedPattern <= 1) { // Basic Case Change 
		casemode = (parseResult.mark == 0) ? 1 : 2;
	} else if (matchedPattern == 2) { // Basic Case Change 
		casemode = 1;
	} else if (matchedPattern <= 4) { // Proper Case 
		type = 1;
		if (parseResult.mark != 0)
			casemode = 3;
	} else if (matchedPattern <= 6) { // Camel Case 
		type = 2;
		if (parseResult.mark != 0)
			casemode = 3;
	} else if (matchedPattern <= 8) { // Pascal Case 
		type = 3;
		if (parseResult.mark != 0)
			casemode = 3;
	} else if (matchedPattern <= 10) { // Snake Case 
		type = 4;
		if (parseResult.mark != 0)
			casemode = (parseResult.mark == 1) ? 2 : 1;
	} else if (matchedPattern <= 12) { // Kebab Case 
		type = 5;
		if (parseResult.mark != 0)
			casemode = (parseResult.mark == 1) ? 2 : 1;
	}
	return true;
}
 
Example #21
Source File: CondCanSee.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) {
	if (matchedPattern == 1 || matchedPattern == 3) {
		players = (Expression<Player>) exprs[0];
		targetPlayers = (Expression<Player>) exprs[1];
	} else {
		players = (Expression<Player>) exprs[1];
		targetPlayers = (Expression<Player>) exprs[0];
	}
	setNegated(matchedPattern > 1 ^ parseResult.mark == 1);
	return true;
}
 
Example #22
Source File: SExprEditLine.java    From skUtilities with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] e, int i, Kleenean k, ParseResult p) {
  line = (Expression<Number>) e[i];
  path = (Expression<String>) e[1 - i];
  return true;
}
 
Example #23
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 #24
Source File: SExprFileAttribute.java    From skUtilities with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] e, int i, Kleenean k, ParseResult p) {
  path = (Expression<String>) e[0];
  ty = p.mark;
  return true;
}
 
Example #25
Source File: ExprTarget.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) {
	type = exprs[matchedPattern] == null ? null : (EntityData<?>) exprs[matchedPattern].getSingle(null);
	setExpr((Expression<? extends LivingEntity>) exprs[1 - matchedPattern]);
	return true;
}
 
Example #26
Source File: EffBan.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings({"null", "unchecked"})
@Override
public boolean init(final Expression<?>[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parseResult) {
	players = exprs[0];
	reason = exprs.length > 1 ? (Expression<String>) exprs[1] : null;
	expires = exprs.length > 1 ? (Expression<Timespan>) exprs[2] : null;
	ban = matchedPattern % 2 == 0;
	ipBan = matchedPattern >= 2;
	return true;
}
 
Example #27
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 #28
Source File: EntityData.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("null")
@Override
public final boolean init(final Expression<?>[] exprs, final int matchedPattern, final Kleenean isDelayed, final ParseResult parseResult) {
	this.matchedPattern = matchedPattern;
	// plural bits (0x3): 0 = singular, 1 = plural, 2 = unknown
	final int pluralBits = parseResult.mark & 0x3;
	this.plural = pluralBits == 1 ? Kleenean.TRUE : pluralBits == 0 ? Kleenean.FALSE : Kleenean.UNKNOWN;
	// age bits (0xC): 0 = unknown, 4 = baby, 8 = adult
	final int ageBits = parseResult.mark & 0xC;
	this.baby = ageBits == 4 ? Kleenean.TRUE : ageBits == 8 ? Kleenean.FALSE : Kleenean.UNKNOWN;
	return init(Arrays.copyOf(exprs, exprs.length, Literal[].class), matchedPattern, parseResult);
}
 
Example #29
Source File: EffChargeCreeper.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) {
	entities = (Expression<LivingEntity>) exprs[0];
	charge = parseResult.mark != 1;
	return true;
}
 
Example #30
Source File: ExprScript.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 Config script = ScriptLoader.currentScript;
	if (script == null) {
		assert false;
		return false;
	}
	String name = script.getFileName();
	if (name.contains("."))
		name = "" + name.substring(0, name.lastIndexOf('.'));
	this.name = name;
	return true;
}