mirror of
https://github.com/aikar/commands.git
synced 2026-05-31 06:11:55 +00:00
many fixes for color stuff
This commit is contained in:
@@ -632,7 +632,7 @@ public final class ACFUtil {
|
||||
return newLoc;
|
||||
}
|
||||
|
||||
@Nullable public static Enum<?> simpleMatch(Class<? extends Enum<?>> list, String item) {
|
||||
@Nullable public static <E extends Enum<E>> E simpleMatch(Class<? extends Enum<?>> list, String item) {
|
||||
if (item == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -640,7 +640,8 @@ public final class ACFUtil {
|
||||
for (Enum<?> s : list.getEnumConstants()) {
|
||||
String simple = ACFUtil.simplifyString(s.name());
|
||||
if (item.equals(simple)) {
|
||||
return s;
|
||||
//noinspection unchecked
|
||||
return (E) s;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,10 +45,11 @@ public class BukkitCommandCompletions extends CommandCompletions {
|
||||
return normal.collect(Collectors.toList());
|
||||
});
|
||||
registerCompletion("chatcolors", (sender, config, input, c) -> {
|
||||
final Stream<String> normal = Stream.of(ChatColor.values())
|
||||
.filter(color -> color.ordinal() <= 0xF)
|
||||
.map(color -> ACFUtil.simplifyString(color.name()));
|
||||
return normal.collect(Collectors.toList());
|
||||
Stream<ChatColor> colors = Stream.of(ChatColor.values());
|
||||
if ("colorsonly".equalsIgnoreCase(config)) {
|
||||
colors = colors.filter(color -> color.ordinal() <= 0xF);
|
||||
}
|
||||
return colors.map(color -> ACFUtil.simplifyString(color.name())).collect(Collectors.toList());
|
||||
});
|
||||
registerCompletion("worlds", (sender, config, input, c) -> (
|
||||
Bukkit.getWorlds().stream().map(World::getName).collect(Collectors.toList())
|
||||
|
||||
@@ -26,12 +26,17 @@ package co.aikar.commands;
|
||||
import co.aikar.commands.annotation.Optional;
|
||||
import co.aikar.commands.contexts.OnlinePlayer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
public class BukkitCommandContexts extends CommandContexts {
|
||||
|
||||
@@ -76,5 +81,22 @@ public class BukkitCommandContexts extends CommandContexts {
|
||||
}
|
||||
return player;
|
||||
});
|
||||
registerContext(ChatColor.class, c -> {
|
||||
String first = c.popFirstArg();
|
||||
Stream<ChatColor> colors = Stream.of(ChatColor.values());
|
||||
if (c.hasFlag("colorsonly")) {
|
||||
colors = colors.filter(color -> color.ordinal() <= 0xF);
|
||||
}
|
||||
|
||||
ChatColor match = ACFUtil.simpleMatch(ChatColor.class, first);
|
||||
if (match == null) {
|
||||
String valid = colors
|
||||
.map(color -> color + ACFUtil.simplifyString(color.name()))
|
||||
.collect(Collectors.joining("&c, "));
|
||||
|
||||
throw new InvalidCommandArgument("Please specify one of: " + valid);
|
||||
}
|
||||
return match;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user