SteamWar/SpigotCore
Archiviert
13
0

Simplify Argument

Dieser Commit ist enthalten in:
jojo 2020-12-30 14:13:57 +01:00
Ursprung fe8c387df5
Commit 9eb6918594

Datei anzeigen

@ -62,22 +62,13 @@ public class Argument<T> {
return GameMode.ADVENTURE;
}
return null;
}, Objects::nonNull, "creative", "survival", "spectator");
}, Objects::nonNull, GameMode.class);
private static final String[] materialArray = Arrays.stream(Material.values()).map(Enum::name).toArray(String[]::new);
public static final Argument<Material> MATERIAL = new Argument<>(Material::valueOf, Objects::nonNull, materialArray);
private static final String[] particleArray = Arrays.stream(Particle.values()).map(Enum::name).toArray(String[]::new);
public static final Argument<Particle> PARTICLE = new Argument<>(Particle::valueOf, Objects::nonNull, particleArray);
private static final String[] entityArray = Arrays.stream(EntityType.values()).map(Enum::name).toArray(String[]::new);
public static final Argument<EntityType> ENTITY = new Argument<>(EntityType::valueOf, Objects::nonNull, entityArray);
private static final String[] soundArray = Arrays.stream(Sound.values()).map(Enum::name).toArray(String[]::new);
public static final Argument<Sound> SOUND = new Argument<>(Sound::valueOf, Objects::nonNull, soundArray);
private static final String[] soundCategoryArray = Arrays.stream(SoundCategory.values()).map(Enum::name).toArray(String[]::new);
public static final Argument<SoundCategory> SOUND_CATEGORY = new Argument<>(SoundCategory::valueOf, Objects::nonNull, soundCategoryArray);
public static final Argument<Material> MATERIAL = new Argument<>(Material::valueOf, Objects::nonNull, Material.class);
public static final Argument<Particle> PARTICLE = new Argument<>(Particle::valueOf, Objects::nonNull, Particle.class);
public static final Argument<EntityType> ENTITY = new Argument<>(EntityType::valueOf, Objects::nonNull, EntityType.class);
public static final Argument<Sound> SOUND = new Argument<>(Sound::valueOf, Objects::nonNull, Sound.class);
public static final Argument<SoundCategory> SOUND_CATEGORY = new Argument<>(SoundCategory::valueOf, Objects::nonNull, SoundCategory.class);
private Function<String, T> mapper;
private Predicate<T> constraint;
@ -87,6 +78,10 @@ public class Argument<T> {
this(mapper, constraint, s -> tabCompletes);
}
public Argument(Function<String, T> mapper, Predicate<T> constraint, Class<? extends Enum<?>> tabCompletes) {
this(mapper, constraint, s -> Arrays.stream(tabCompletes.getEnumConstants()).map(e -> e.name().toLowerCase()).toArray(String[]::new));
}
public Argument(Function<String, T> mapper, Predicate<T> constraint, Supplier<String[]> tabCompletes) {
this(mapper, constraint, s -> tabCompletes.get());
}