Java Code Examples for ch.njol.skript.classes.Changer.ChangeMode#SET

The following examples show how to use ch.njol.skript.classes.Changer.ChangeMode#SET . 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: ExprColorOf.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
@Override
@Nullable
public Class<?>[] acceptChange(ChangeMode mode) {
	Class<?> returnType = getExpr().getReturnType();
	
	if (FireworkEffect.class.isAssignableFrom(returnType))
		return CollectionUtils.array(Color[].class);
	
	if (mode != ChangeMode.SET && !getExpr().isSingle())
		return null;
	
	if (Entity.class.isAssignableFrom(returnType))
		return CollectionUtils.array(Color.class);
	else if (Block.class.isAssignableFrom(returnType))
		return CollectionUtils.array(Color.class);
	if (ItemType.class.isAssignableFrom(returnType))
		return CollectionUtils.array(Color.class);
	return null;
}
 
Example 2
Source File: ExprTarget.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void change(final Event e, final @Nullable Object[] delta, final ChangeMode mode) {
	if (mode == ChangeMode.SET || mode == ChangeMode.DELETE) {
		final LivingEntity target = delta == null ? null : (LivingEntity) delta[0];
		for (final LivingEntity entity : getExpr().getArray(e)) {
			if (getTime() >= 0 && e instanceof EntityTargetEvent && entity.equals(((EntityTargetEvent) e).getEntity()) && !Delay.isDelayed(e)) {
				((EntityTargetEvent) e).setTarget(target);
			} else {
				if (entity instanceof Creature)
					((Creature) entity).setTarget(target);
			}
		}
	} else {
		super.change(e, delta, mode);
	}
}
 
Example 3
Source File: ExprName.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
@Override
@Nullable
public Class<?>[] acceptChange(ChangeMode mode) {
	if (mode == ChangeMode.DELETE && (type.acceptChange & ~PLAYER) != 0 || mode == ChangeMode.RESET)
		return new Class[0];
	if (mode != ChangeMode.SET)
		return null;
	if ((type.acceptChange & PLAYER) != 0 && Player.class.isAssignableFrom(getExpr().getReturnType())) {
		changeType = PLAYER;
	} else if ((type.acceptChange & INVENTORY) != 0 && Inventory.class.isAssignableFrom(getExpr().getReturnType())) {
		changeType = INVENTORY;
	} else if ((type.acceptChange & ITEM) != 0 && (getExpr().isSingle() && ChangerUtils.acceptsChange(getExpr(), ChangeMode.SET, ItemStack.class, ItemType.class) || Slot.class.isAssignableFrom(getExpr().getReturnType()))) {
		changeType = ITEM;
	} else if ((type.acceptChange & ENTITY) != 0 && Entity.class.isAssignableFrom(getExpr().getReturnType())) {
		if (type == NameType.NAME && Player.class.isAssignableFrom(getExpr().getReturnType())) {
			Skript.error("Can't change the Minecraft name of a player. Change the 'display name' or 'tab list name' instead.");
			return null;
		}
		changeType = ENTITY;
	}
	return changeType == 0 ? null : CollectionUtils.array(String.class);
}
 
Example 4
Source File: ExprGlowing.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
@Nullable
public Class<?>[] acceptChange(final ChangeMode mode) {
	if (mode == ChangeMode.SET || mode == ChangeMode.RESET)
		return new Class[] {Boolean.class};
	return null;
}
 
Example 5
Source File: ExprPassenger.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
@Nullable
public Class<?>[] acceptChange(final ChangeMode mode) {
	if (!isSingle())
		return new Class[] {Entity[].class, EntityData[].class}; // To support more than one entity
	if (mode == ChangeMode.SET)
		return new Class[] {Entity.class, EntityData.class};
	return super.acceptChange(mode);
}
 
Example 6
Source File: ExprBiome.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
@Nullable
public Class<?>[] acceptChange(final ChangeMode mode) {
	if (mode == ChangeMode.SET)
		return new Class[] {Biome.class};
	return super.acceptChange(mode);
}
 
Example 7
Source File: ExprEventCancelled.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
@Nullable
public Class<?>[] acceptChange(final ChangeMode mode) {
	if (delay != Kleenean.FALSE) {
		Skript.error("Can't cancel the event anymore after it has already passed");
		return null;
	}
	if (mode == ChangeMode.SET || mode == ChangeMode.DELETE)
		return CollectionUtils.array(Boolean.class);
	return null;
}
 
Example 8
Source File: ExprVectorLength.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
@SuppressWarnings("null")
public Class<?>[] acceptChange(ChangeMode mode) {
	if (mode == ChangeMode.ADD || mode == ChangeMode.REMOVE || mode == ChangeMode.SET)
		return CollectionUtils.array(Number.class);
	return null;
}
 
Example 9
Source File: ExprVersionString.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
@Nullable
public Class<?>[] acceptChange(ChangeMode mode) {
	if (ScriptLoader.hasDelayBefore.isTrue()) {
		Skript.error("Can't change the version string anymore after the server list ping event has already passed");
		return null;
	}
	if (mode == ChangeMode.SET)
		return CollectionUtils.array(String.class);
	return null;
}
 
Example 10
Source File: ExprWeather.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
@Nullable
public Class<?>[] acceptChange(final ChangeMode mode) {
	if (mode == ChangeMode.DELETE || mode == ChangeMode.SET)
		return CollectionUtils.array(WeatherType.class);
	return null;
}
 
Example 11
Source File: ExprRespawnLocation.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
@Override
public Class<?>[] acceptChange(Changer.ChangeMode mode) {
	if (mode == ChangeMode.SET)
		return CollectionUtils.array(Location.class);
	return null;
}
 
Example 12
Source File: ExprDifficulty.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
@Nullable
public Class<?>[] acceptChange(ChangeMode mode) {
	if (mode == ChangeMode.SET)
		return CollectionUtils.array(Difficulty.class);
	return null;
}
 
Example 13
Source File: ExprGlidingState.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
@Nullable
public Class<?>[] acceptChange(final ChangeMode mode) {
	if (mode == ChangeMode.SET || mode == ChangeMode.RESET)
		return new Class[] {Boolean.class};
	return null;
}
 
Example 14
Source File: ExprSignText.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
@Nullable
public Class<?>[] acceptChange(final ChangeMode mode) {
	if (mode == ChangeMode.DELETE || mode == ChangeMode.SET)
		return new Class[] {String.class};
	return null;
}
 
Example 15
Source File: ExprWorld.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
@Nullable
public Class<?>[] acceptChange(final Changer.ChangeMode mode) {
	if (mode == ChangeMode.SET)
		return CollectionUtils.array(World.class);
	return null;
}
 
Example 16
Source File: ExprFacing.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
@Nullable
public Class<?>[] acceptChange(final ChangeMode mode) {
	if (!Block.class.isAssignableFrom(getExpr().getReturnType()))
		return null;
	if (mode == ChangeMode.SET)
		return CollectionUtils.array(Direction.class);
	return null;
}
 
Example 17
Source File: ExprProtocolVersion.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
@Nullable
public Class<?>[] acceptChange(ChangeMode mode) {
	if (ScriptLoader.hasDelayBefore.isTrue()) {
		Skript.error("Can't change the protocol version anymore after the server list ping event has already passed");
		return null;
	}
	if (mode == ChangeMode.SET)
		return CollectionUtils.array(Number.class);
	return null;
}
 
Example 18
Source File: ExprShooter.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
@Nullable
public Class<?>[] acceptChange(final ChangeMode mode) {
	if (mode == ChangeMode.SET)
		return new Class[] {LivingEntity.class};
	return super.acceptChange(mode);
}
 
Example 19
Source File: ExprCompassTarget.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
@Nullable
public Class<?>[] acceptChange(final ChangeMode mode) {
	if (mode == ChangeMode.SET || mode == ChangeMode.RESET)
		return new Class[] {Location.class};
	return null;
}
 
Example 20
Source File: Variable.java    From Skript with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Class<?>[] acceptChange(final ChangeMode mode) {
	if (!list && mode == ChangeMode.SET)
		return CollectionUtils.array(Object.class);
	return CollectionUtils.array(Object[].class);
}