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

The following examples show how to use ch.njol.skript.classes.Changer.ChangeMode#DELETE . 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: 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 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: EffChange.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
@Override
	protected void execute(final Event e) {
		final Expression<?> changer = this.changer;
		Object[] delta = changer == null ? null : changer.getArray(e);
		delta = changer == null ? delta : changer.beforeChange(changed, delta);
		if (delta != null && delta.length == 0)
			return;
		if (delta == null && (mode != ChangeMode.DELETE && mode != ChangeMode.RESET))
			return;
		changed.change(e, delta, mode); // Trigger beforeChanged hook
		// REMIND use a random element out of delta if changed only supports changing a single instance
//		changed.change(e, new Changer2<Object>() {
//			@Override
//			public Object change(Object o) {
//				return delta;
//			}
//		}, mode);
	}
 
Example 4
Source File: ExprVelocity.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 || mode == ChangeMode.DELETE || mode == ChangeMode.RESET))
		return CollectionUtils.array(Vector.class);
	return null;
}
 
Example 5
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 6
Source File: ExprTarget.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 (mode == ChangeMode.SET || mode == ChangeMode.DELETE)
		return CollectionUtils.array(LivingEntity.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: ExprEntityTamer.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
@Override
public Class<?>[] acceptChange(ChangeMode mode) {
	if (mode == ChangeMode.SET || mode == ChangeMode.DELETE || mode == ChangeMode.RESET)
		return CollectionUtils.array(OfflinePlayer.class);
	return null;
}
 
Example 9
Source File: ExprHoverList.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("null")
@Override
public void change(Event e, @Nullable Object[] delta, ChangeMode mode) {
	List<PlayerProfile> values = new ArrayList<>();
	if (mode != ChangeMode.DELETE && mode != ChangeMode.RESET) {
		for (Object o : delta) {
			if (o instanceof Player) {
				Player player = ((Player) o);
				values.add(Bukkit.createProfile(player.getUniqueId(), player.getName()));
			} else {
				values.add(Bukkit.createProfile(UUID.randomUUID(), (String) o));
			}
		}
	}

	List<PlayerProfile> sample = ((PaperServerListPingEvent) e).getPlayerSample();
	switch (mode){
		case SET:
			sample.clear();
			sample.addAll(values);
			break;
		case ADD:
			sample.addAll(values);
			break;
		case REMOVE:
			sample.removeAll(values);
			break;
		case DELETE:
		case RESET:
			sample.clear();
	}
}
 
Example 10
Source File: ExprMaxHealth.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(!Skript.isRunningMinecraft(1, 5, 2)) {
		Skript.error("The max health of an entity can only be changed in Minecraft 1.6 and later");
		return null;
	}
	
	if (mode != ChangeMode.DELETE && mode != ChangeMode.REMOVE_ALL)
		return new Class[] {Number.class};
	return null;
}
 
Example 11
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 12
Source File: ExprBed.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.DELETE)
		return new Class[] {Location.class};
	return null;
}
 
Example 13
Source File: ExprYaml.java    From skript-yaml with MIT License 4 votes vote down vote up
@Override
public void change(Event event, Object[] delta, Changer.ChangeMode mode) {
	final String name = this.file.getSingle(event);
	final String path = this.node.getSingle(event);

	if (!SkriptYaml.YAML_STORE.containsKey(name)) {
		SkriptYaml.warn("No yaml by the name '" + name + "' has been loaded");
		return;
	}

	YAMLProcessor config = SkriptYaml.YAML_STORE.get(name);

	if (mode == ChangeMode.DELETE || mode == ChangeMode.RESET) {
		config.removeProperty(path);
		return;
	}

	if (state == YamlState.VALUE) {
		if (mode == ChangeMode.SET)
			config.setProperty(path, parseString(delta[0]));
	} else if (state == YamlState.NODE_KEYS) {
		if (mode == ChangeMode.ADD)
			config.setProperty(path + (delta[0] == null ? "" : "." + delta[0]), null);
			//config.addNode(path + (delta[0] == null ? "" : "." + delta[0]));
		else if (mode == ChangeMode.REMOVE)
			config.removeProperty(path + (delta[0] == null ? "" : "." + delta[0]));
			//config.setProperty(path + (delta[0] == null ? "" : "." + delta[0]), null);
	} else if (state == YamlState.LIST) {
		List<Object> objects = config.getList(path);
		if (mode == ChangeMode.ADD) {
			if (objects == null)
				config.setProperty(path, arrayToList(new LinkedList<Object>(), delta));
			else 
				config.setProperty(path, arrayToList(objects, delta));
		} else if (mode == ChangeMode.REMOVE) {
			for (Object o : delta)
				objects.remove(parseString(o));
		} else if (mode == ChangeMode.SET) {
			if (objects == null) {
				config.setProperty(path, arrayToList(new LinkedList<Object>(), delta));
			} else {
				objects.clear();
				config.setProperty(path, arrayToList(objects, delta));
			}
		}
	}
}