ch.njol.util.coll.CollectionUtils Java Examples

The following examples show how to use ch.njol.util.coll.CollectionUtils. 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: ExprChestInventory.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected Inventory[] get(Event e) {
    String name = this.name != null ? this.name.getSingle(e) : "Chest";
    Number rows = this.rows != null ? this.rows.getSingle(e) : 3;

    // Shouldn't be null at this point, but empty variables are a thing
    rows = rows == null ? 3 : rows;
    name = name == null ? "Chest" : name;

    int size = rows.intValue() * 9;
    if (size % 9 != 0) {
        size = 27;
    }
    
    // Sanitize inventory size
    if (size < 0) // Negative sizes go and crash stuff deep in NMS code
    	size = 0;
    if (size > 255) // Too big values cause visual weirdness
    	size = 255 * 9; // Plus, REALLY big values will HANG the server
    return CollectionUtils.array(Bukkit.createInventory(null, size, name));
}
 
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: ExprMOTD.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
@Override
@Nullable
public Class<?>[] acceptChange(ChangeMode mode) {
	if (!isDefault) {
		if (ScriptLoader.hasDelayBefore.isTrue()) {
			Skript.error("Can't change the MOTD anymore after the server list ping event has already passed");
			return null;
		}
		switch (mode) {
			case SET:
			case DELETE:
			case RESET:
				return CollectionUtils.array(String.class);
		}
	}
	return null;
}
 
Example #5
Source File: ExprRayfallOffhand.java    From skRayFall with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
@Nullable
public Class<?>[] acceptChange(final ChangeMode mode) {
    switch (mode) {
        case SET:
            return CollectionUtils.array(ItemStack.class);
        case ADD:
        case REMOVE:
        case DELETE:
        case REMOVE_ALL:
        case RESET:
        default:
            return null;
    }
}
 
Example #6
Source File: ExprTime.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
@Override
@Nullable
public Class<?>[] acceptChange(final ChangeMode mode) {
	switch (mode) {
		case ADD:
		case REMOVE:
			return CollectionUtils.array(Timespan.class);
		case SET:
			return CollectionUtils.array(Time.class, Timeperiod.class);
		case DELETE:
		case REMOVE_ALL:
		case RESET:
		default:
			return null;
	}
}
 
Example #7
Source File: SExprYaml.java    From skUtilities with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public Class<?>[] acceptChange(final Changer.ChangeMode mode) {
  if (mode == Changer.ChangeMode.DELETE) {
    return CollectionUtils.array(Object.class);
  }
  switch (ty) {
    case 0: {
      if (mode == Changer.ChangeMode.SET) {
        return CollectionUtils.array(Object.class);
      }
      break;
    }
    case 1:
    case 2:
    case 3:
      if (mode == Changer.ChangeMode.ADD || mode == Changer.ChangeMode.REMOVE) {
        return CollectionUtils.array(Object.class);
      }
      break;
  }
  return null;
}
 
Example #8
Source File: ExprMaxPlayers.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
@Override
@Nullable
public Class<?>[] acceptChange(ChangeMode mode) {
	if (!isReal) {
		if (ScriptLoader.hasDelayBefore.isTrue()) {
			Skript.error("Can't change the fake max players count anymore after the server list ping event has already passed");
			return null;
		}
		switch (mode) {
			case SET:
			case ADD:
			case REMOVE:
			case DELETE:
			case RESET:
				return CollectionUtils.array(Number.class);
		}
	}
	return null;
}
 
Example #9
Source File: ExprHoverList.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
@Override
@Nullable
public Class<?>[] acceptChange(ChangeMode mode) {
	if (ScriptLoader.hasDelayBefore.isTrue()) {
		Skript.error("Can't change the hover list anymore after the server list ping event has already passed");
		return null;
	}
	switch (mode) {
		case SET:
		case ADD:
		case REMOVE:
		case DELETE:
		case RESET:
			return CollectionUtils.array(String[].class, Player[].class);
	}
	return null;
}
 
Example #10
Source File: ExprOnlinePlayersCount.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
@Override
@Nullable
public Class<?>[] acceptChange(ChangeMode mode) {
	if (!isReal) {
		if (ScriptLoader.hasDelayBefore.isTrue()) {
			Skript.error("Can't change the shown online players count anymore after the server list ping event has already passed");
			return null;
		}
		switch (mode) {
			case SET:
			case ADD:
			case REMOVE:
			case DELETE:
			case RESET:
				return CollectionUtils.array(Number.class);
		}
	}
	return null;
}
 
Example #11
Source File: ExprBookAuthor.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 == Changer.ChangeMode.SET || mode == Changer.ChangeMode.RESET || mode == Changer.ChangeMode.DELETE)
		return CollectionUtils.array(String.class);
	return null;
}
 
Example #12
Source File: ExprVectorXYZ.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)
			&& getExpr().isSingle() && Changer.ChangerUtils.acceptsChange(getExpr(), ChangeMode.SET, Vector.class))
		return CollectionUtils.array(Number.class);
	return null;
}
 
Example #13
Source File: ExprBurnCookTime.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
@Nullable
public Class<?>[] acceptChange(Changer.ChangeMode mode) {
	if (mode == Changer.ChangeMode.ADD
		|| mode == Changer.ChangeMode.REMOVE
		|| mode == Changer.ChangeMode.SET)
		return CollectionUtils.array(Timespan.class);
	return null;
}
 
Example #14
Source File: ExprNoDamageTicks.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.REMOVE_ALL)
		return null;
	return CollectionUtils.array(Number.class);
}
 
Example #15
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 #16
Source File: ExprVectorNormalize.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
@SuppressWarnings("null")
protected Vector[] get(Event e) {
	Vector v = vector.getSingle(e);
	if (v == null)
		return null;
	return CollectionUtils.array(v.clone().normalize());
}
 
Example #17
Source File: ExprGameMode.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.RESET)
		return CollectionUtils.array(GameMode.class);
	return null;
}
 
Example #18
Source File: ConvertedExpression.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
@Nullable
public <R> Expression<? extends R> getConvertedExpression(final Class<R>... to) {
	if (CollectionUtils.containsSuperclass(to, this.to))
		return (Expression<? extends R>) this;
	return source.getConvertedExpression(to);
}
 
Example #19
Source File: ExprFoodLevel.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.REMOVE_ALL)
		return null;
	return CollectionUtils.array(Number.class);
}
 
Example #20
Source File: ExprServerIcon.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
@Nullable
public Class<?>[] acceptChange(ChangeMode mode) {
	if (isServerPingEvent && !isDefault) {
		if (ScriptLoader.hasDelayBefore.isTrue()) {
			Skript.error("Can't change the server icon anymore after the server list ping event has already passed");
			return null;
		}
		if (mode == ChangeMode.SET || mode == ChangeMode.RESET)
			return CollectionUtils.array(CachedServerIcon.class);
	}
	return null;
}
 
Example #21
Source File: ExprServerIcon.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
@Nullable
public CachedServerIcon[] get(Event e) {
	CachedServerIcon icon = null;
	if ((isServerPingEvent && !isDefault) && PAPER_EVENT_EXISTS)
		icon = ((PaperServerListPingEvent) e).getServerIcon();
	else
		icon = Bukkit.getServerIcon();
	if (icon == null || icon.getData() == null)
		return null;
	return CollectionUtils.array(icon);
}
 
Example #22
Source File: SExprFileAttribute.java    From skUtilities with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public Class<?>[] acceptChange(final Changer.ChangeMode mode) {
  if (mode == Changer.ChangeMode.RESET || mode == Changer.ChangeMode.SET) {
    return CollectionUtils.array(Boolean.class);
  }
  return null;
}
 
Example #23
Source File: ExprLocationVectorOffset.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("null")
@Override
protected Location[] get(Event e) {
	Location l = location.getSingle(e);
	if (l == null)
		return null;
	Location clone = l.clone();
	for (Vector v : vectors.getArray(e))
		clone.add(v);
	return CollectionUtils.array(clone);
}
 
Example #24
Source File: ExpressionList.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
@Nullable
public T getSingle(final Event e) {
	if (!single)
		throw new UnsupportedOperationException();
	for (final int i : CollectionUtils.permutation(expressions.length)) {
		final T t = expressions[i].getSingle(e);
		if (t != null)
			return t;
	}
	return null;
}
 
Example #25
Source File: ExprLocationFromVector.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("null")
@Override
protected Location[] get(Event e) {
	Vector v = vector.getSingle(e);
	World w = world.getSingle(e);
	Number y = yaw != null ? yaw.getSingle(e) : null;
	Number p = pitch != null ? pitch.getSingle(e) : null;
	if (v == null || w == null)
		return null;
	if (y == null || p == null)
		return CollectionUtils.array(v.toLocation(w));
	else
		return CollectionUtils.array(v.toLocation(w, y.floatValue(), p.floatValue()));
}
 
Example #26
Source File: ExprMetadata.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
@Nullable
public Class<?>[] acceptChange(Changer.ChangeMode mode) {
	if (mode == Changer.ChangeMode.DELETE || mode == Changer.ChangeMode.SET)
		return CollectionUtils.array(Object.class);
	return null;
}
 
Example #27
Source File: ExprPlayerViewDistance.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
@Nullable
public Class<?>[] acceptChange(ChangeMode mode) {
	switch (mode) {
		case DELETE:
		case SET:
		case ADD:
		case REMOVE:
		case RESET:
			return CollectionUtils.array(Number.class);
	}
	return null;
}
 
Example #28
Source File: ExprPlayerWeather.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.RESET || mode == ChangeMode.SET)
		return CollectionUtils.array(WeatherType.class);
	return null;
}
 
Example #29
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 #30
Source File: ExprSpawn.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 CollectionUtils.array(Location.class);
	return null;
}