use of org.bukkit.ChatColor in project Essentials by drtshock.
the class FormatUtil method unformatString.
public static String unformatString(String message, final EnumSet<ChatColor> supported, boolean rgb) {
if (message == null) {
return null;
}
final StringBuffer rgbBuilder = new StringBuffer();
final Matcher rgbMatcher = STRIP_RGB_PATTERN.matcher(message);
while (rgbMatcher.find()) {
final String code = rgbMatcher.group(1).replace(String.valueOf(ChatColor.COLOR_CHAR), "");
if (rgb) {
rgbMatcher.appendReplacement(rgbBuilder, "&#" + code);
continue;
}
rgbMatcher.appendReplacement(rgbBuilder, "");
}
rgbMatcher.appendTail(rgbBuilder);
// arreter de parler
message = rgbBuilder.toString();
// Legacy Colors
final StringBuffer builder = new StringBuffer();
final Matcher matcher = STRIP_ALL_PATTERN.matcher(message);
searchLoop: while (matcher.find()) {
final char code = matcher.group(1).toLowerCase(Locale.ROOT).charAt(0);
for (final ChatColor color : supported) {
if (color.getChar() == code) {
matcher.appendReplacement(builder, "&" + code);
continue searchLoop;
}
}
matcher.appendReplacement(builder, "");
}
matcher.appendTail(builder);
return builder.toString();
}
use of org.bukkit.ChatColor in project LibsDisguises by libraryaddict.
the class ParamInfoTypes method getParamInfos.
/**
* Constructor values are listed here for continuity
*/
public List<ParamInfo> getParamInfos() {
List<ParamInfo> paramInfos = new ArrayList<>();
// Register enum types
// paramInfos.add(new ParamInfoEnum(AnimalColor.class, "Animal Color",
// "View all the colors you can use for an animal color"));
paramInfos.add(new ParamInfoEnum(Art.class, "Art", "View all the paintings you can use for a painting disguise"));
paramInfos.add(new ParamInfoEnum(Horse.Color.class, "Horse Color", "View all the colors you can use for a horses color"));
paramInfos.add(new ParamInfoEnum(Villager.Profession.class, "Villager Profession", "View all the professions you can set on a Villager and Zombie Villager"));
if (NmsVersion.v1_14.isSupported()) {
paramInfos.add(new ParamInfoEnum(Villager.Type.class, "Villager Biome", "View all the biomes you can set on a Villager and Zombie Villager"));
}
paramInfos.add(new ParamInfoEnum(BlockFace.class, "Direction", "Direction (North, East, South, West, Up, Down)", "View the directions usable on player setSleeping and shulker direction", Arrays.copyOf(BlockFace.values(), 6)));
paramInfos.add(new ParamInfoEnum(RabbitType.class, "Rabbit Type", "View the kinds of rabbits you can turn into"));
paramInfos.add(new ParamInfoEnum(TreeSpecies.class, "Tree Species", "View the different types of tree species"));
paramInfos.add(new ParamInfoEnum(MainHand.class, "Main Hand", "Set the main hand for an entity"));
paramInfos.add(new ParamInfoEnum(Llama.Color.class, "Llama Color", "View all the colors you can use for a llama color"));
paramInfos.add(new ParamInfoEnum(Parrot.Variant.class, "Parrot Variant", "View the different colors a parrot can be"));
if (NmsVersion.v1_13.isSupported()) {
paramInfos.add(new ParamInfoParticle(WrappedParticle.class, "Particle", "The different particles of Minecraft", Particle.values(), getMaterials()));
paramInfos.add(new ParamInfoEnum(TropicalFish.Pattern.class, "Pattern", "Patterns of a tropical fish"));
paramInfos.add(new ParamInfoBlockData(BlockData.class, "BlockData", "The block data states, barrel[facing=north,open=false] as example", getMaterials()));
} else {
paramInfos.add(new ParamInfoEnum(Particle.class, "Particle", "The different particles of Minecraft"));
}
paramInfos.add(new ParamInfoEnum(DyeColor.class, "DyeColor", "Dye colors of many different colors"));
paramInfos.add(new ParamInfoEnum(Horse.Style.class, "Horse Style", "Horse style which is the patterns on the horse"));
if (NmsVersion.v1_14.isSupported()) {
paramInfos.add(new ParamInfoEnum(EntityPose.class, "EntityPose", "The pose the entity should strike"));
paramInfos.add(new ParamInfoEnum(Cat.Type.class, "Cat Type", "The type of cat"));
paramInfos.add(new ParamInfoEnum(Fox.Type.class, "Fox Type", "The type of fox"));
paramInfos.add(new ParamInfoEnum(Panda.Gene.class, "Panda Gene", "The panda gene type"));
paramInfos.add(new ParamInfoEnum(MushroomCow.Variant.class, "Mushroom Cow Variant", "The different variants for mushroom cows"));
if (NmsVersion.v1_17.isSupported()) {
paramInfos.add(new ParamInfoEnum(Axolotl.Variant.class, "Axolotl Variant", "The variant of Axolotl"));
}
} else {
paramInfos.add(new ParamInfoEnum(Ocelot.Type.class, "Ocelot Type", "The type of ocelot"));
}
paramInfos.add(new ParamInfoEnum(DisguiseConfig.NotifyBar.class, "NotifyBar", "Where the disguised indicator should appear"));
paramInfos.add(new ParamInfoEnum(BarColor.class, "BarColor", "The color of the boss bar"));
paramInfos.add(new ParamInfoEnum(BarStyle.class, "BarStyle", "The style of the boss bar"));
// Register custom types
paramInfos.add(new ParamInfoEulerAngle(EulerAngle.class, "Euler Angle", "Euler Angle (X,Y,Z)", "Set the X,Y,Z directions on an armorstand"));
paramInfos.add(new ParamInfoColor(Color.class, "Color", "Colors that can also be defined through RGB", getColors()));
paramInfos.add(new ParamInfoEnum(Material.class, "Material", "A material used for blocks and items", getMaterials()));
paramInfos.add(new ParamInfoItemStack(ItemStack.class, "ItemStack", "ItemStack (Material,Amount?,Glow?)", "An ItemStack compromised of Material,Amount,Glow. Only requires Material", getMaterials()));
paramInfos.add(new ParamInfoItemStackArray(ItemStack[].class, "ItemStack[]", "Four ItemStacks (Material:Amount?:Glow?,Material:Amount?:Glow?..)", "Four ItemStacks separated by a comma", getMaterials()));
paramInfos.add(new ParamInfoPotionEffect(PotionEffectType.class, "Potion Effect", "View all the potion effects you can add", getPotions()));
paramInfos.add(new ParamInfoBlockPosition(BlockPosition.class, "Block Position", "Block Position (num,num,num)", "Three numbers separated by a ,"));
paramInfos.add(new ParamInfoGameProfile(WrappedGameProfile.class, "GameProfile", "Get the gameprofile here https://sessionserver.mojang" + ".com/session/minecraft/profile/PLAYER_UUID_GOES_HERE?unsigned=false"));
paramInfos.add(new ParamInfoTime(long.class, "Expiry Time", "Set how long the disguise lasts, <Num><Time><Num>... where <Time> is (s/sec)(m/min)(h/hour)(d/day) " + "etc. 30m20secs = 30 minutes, 20 seconds"));
paramInfos.add(new ParamInfoChatColor(ChatColor.class, "ChatColor", "A chat color"));
paramInfos.add(new ParamInfoEnum(GolemCrack.class, "Golem Cracked", "The stage a golem has been cracked"));
// Register base types
Map<String, Object> booleanMap = new HashMap<>();
booleanMap.put("true", true);
booleanMap.put("false", false);
paramInfos.add(new ParamInfoBoolean("Boolean", "True/False", "True or False", booleanMap));
paramInfos.add(new ParamInfoString(String.class, "Text", "A line of text"));
paramInfos.add(new ParamInfoInteger("Number", "A whole number without decimals"));
paramInfos.add(new ParamInfoFloat("Number.0", "A number which can have decimal places"));
paramInfos.add(new ParamInfoFloatNullable("Number.0", "A number which can have decimal places or be null"));
paramInfos.add(new ParamInfoDouble("Number.0", "A number which can have decimal places"));
paramInfos.add(new ParamInfoSoundGroup());
return paramInfos;
}
use of org.bukkit.ChatColor in project LibsDisguises by libraryaddict.
the class DisguiseHelpCommand method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
for (String node : getCommandNames().values()) {
DisguisePermissions perms = DisguiseParser.getPermissions(sender, node);
if (!perms.hasPermissions()) {
continue;
}
if (args.length == 0) {
sendCommandUsage(sender, null);
return true;
} else {
ParamInfo help = null;
for (ParamInfo s : ParamInfoManager.getParamInfos()) {
String name = s.getName().replaceAll(" ", "");
if (args[0].equalsIgnoreCase(name) || args[0].equalsIgnoreCase(name + "s")) {
help = s;
break;
}
}
if (help != null) {
if (help.hasValues() && help.canTranslateValues()) {
LibsMsg.DHELP_HELP4.send(sender, help.getName(), StringUtils.join(help.getEnums(""), LibsMsg.DHELP_HELP4_SEPERATOR.get()));
} else {
if (!help.getName().equals(help.getDescriptiveName())) {
LibsMsg.DHELP_HELP6.send(sender, help.getName(), help.getDescriptiveName(), help.getDescription());
} else {
LibsMsg.DHELP_HELP5.send(sender, help.getName(), help.getDescription());
}
}
return true;
}
DisguisePerm type = DisguiseParser.getDisguisePerm(args[0]);
if (type == null) {
LibsMsg.DHELP_CANTFIND.send(sender, args[0]);
return true;
}
if (!perms.isAllowedDisguise(type)) {
LibsMsg.NO_PERM_DISGUISE.send(sender);
return true;
}
ArrayList<String> methods = new ArrayList<>();
Class watcher = type.getWatcherClass();
int ignored = 0;
try {
for (WatcherMethod method : ParamInfoManager.getDisguiseWatcherMethods(watcher)) {
if (!method.isUsable(type.getType())) {
continue;
}
if (args.length < 2 || !args[1].equalsIgnoreCase(LibsMsg.DHELP_SHOW.get())) {
if (!perms.isAllowedDisguise(type, Collections.singleton(method.getName().toLowerCase(Locale.ENGLISH)))) {
ignored++;
continue;
}
}
ParamInfo info = ParamInfoManager.getParamInfo(method);
int value = ParamInfoManager.getValue(method);
ChatColor methodColor = ChatColor.YELLOW;
if (value == 1) {
methodColor = ChatColor.AQUA;
} else if (value == 2) {
methodColor = ChatColor.GRAY;
}
String str = TranslateType.DISGUISE_OPTIONS.get(method.getName()) + ChatColor.DARK_RED + "(" + ChatColor.GREEN + info.getName() + ChatColor.DARK_RED + ")";
methods.add(methodColor + str);
}
} catch (Exception ex) {
ex.printStackTrace();
}
if (methods.isEmpty()) {
methods.add(LibsMsg.DHELP_NO_OPTIONS.get());
}
LibsMsg.DHELP_OPTIONS.send(sender, ChatColor.DARK_RED + type.toReadable(), StringUtils.join(methods, ChatColor.DARK_RED + ", "));
if (ignored > 0) {
LibsMsg.NO_PERMS_USE_OPTIONS.send(sender, ignored);
}
return true;
}
}
LibsMsg.NO_PERM.send(sender);
return true;
}
use of org.bukkit.ChatColor in project DiscordSRV by Scarsz.
the class CommandHelp method help.
/**
* Send help specific for the given commands
* @param sender
* @param commands
*/
private static void help(CommandSender sender, List<String> commands) {
ChatColor titleColor = ChatColor.RESET, commandColor = ChatColor.RESET;
while (disallowedChatColorCharacters.contains(titleColor)) titleColor = ChatColor.values()[ThreadLocalRandom.current().nextInt(ChatColor.values().length - 1)];
while (disallowedChatColorCharacters.contains(commandColor) || commandColor == titleColor) commandColor = ChatColor.values()[ThreadLocalRandom.current().nextInt(ChatColor.values().length - 1)];
List<Method> commandMethods = new LinkedList<>();
for (String commandName : commands) commandMethods.add(DiscordSRV.getPlugin().getCommandManager().getCommands().get(commandName));
MessageUtil.sendMessage(sender, ChatColor.DARK_GRAY + "===================[ " + titleColor + "DiscordSRV" + ChatColor.DARK_GRAY + " ]===================");
for (Method commandMethod : commandMethods) {
Command commandAnnotation = commandMethod.getAnnotation(Command.class);
// make sure sender has permission to run the commands before showing them permissions for it
if (!GamePermissionUtil.hasPermission(sender, commandAnnotation.permission()))
continue;
MessageUtil.sendMessage(sender, ChatColor.GRAY + "- " + commandColor + "/discord " + String.join("/", commandAnnotation.commandNames()));
MessageUtil.sendMessage(sender, " " + ChatColor.ITALIC + commandAnnotation.helpMessage());
if (!commandAnnotation.usageExample().equals(""))
MessageUtil.sendMessage(sender, " " + ChatColor.GRAY + ChatColor.ITALIC + "ex. /discord " + commandAnnotation.usageExample());
}
}
use of org.bukkit.ChatColor in project DiscordSRV by Scarsz.
the class CommandHelp method help.
private static void help(CommandSender sender) {
ChatColor titleColor = ChatColor.RESET, commandColor = ChatColor.RESET;
while (disallowedChatColorCharacters.contains(titleColor)) titleColor = ChatColor.values()[ThreadLocalRandom.current().nextInt(ChatColor.values().length)];
while (disallowedChatColorCharacters.contains(commandColor) || commandColor == titleColor) commandColor = ChatColor.values()[ThreadLocalRandom.current().nextInt(ChatColor.values().length)];
List<Method> commandMethods = new ArrayList<>();
for (Method method : DiscordSRV.getPlugin().getCommandManager().getCommands().values()) if (!commandMethods.contains(method))
commandMethods.add(method);
MessageUtil.sendMessage(sender, ChatColor.DARK_GRAY + "================[ " + titleColor + "DiscordSRV" + ChatColor.DARK_GRAY + " ]================");
for (Method commandMethod : commandMethods) {
Command commandAnnotation = commandMethod.getAnnotation(Command.class);
// make sure sender has permission to run the commands before showing them permissions for it
if (!GamePermissionUtil.hasPermission(sender, commandAnnotation.permission()))
continue;
MessageUtil.sendMessage(sender, ChatColor.GRAY + "- " + commandColor + "/discord " + String.join("/", commandAnnotation.commandNames()));
MessageUtil.sendMessage(sender, " " + ChatColor.ITALIC + commandAnnotation.helpMessage());
if (!commandAnnotation.usageExample().equals(""))
MessageUtil.sendMessage(sender, " " + ChatColor.GRAY + ChatColor.ITALIC + "ex. /discord " + commandAnnotation.usageExample());
}
}
Aggregations