Search in sources :

Example 66 with ChatColor

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();
}
Also used : Matcher(java.util.regex.Matcher) ChatColor(org.bukkit.ChatColor)

Example 67 with ChatColor

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;
}
Also used : HashMap(java.util.HashMap) BlockFace(org.bukkit.block.BlockFace) BarColor(org.bukkit.boss.BarColor) ArrayList(java.util.ArrayList) ParamInfoDouble(me.libraryaddict.disguise.utilities.params.types.base.ParamInfoDouble) TreeSpecies(org.bukkit.TreeSpecies) ParamInfoEulerAngle(me.libraryaddict.disguise.utilities.params.types.custom.ParamInfoEulerAngle) ParamInfoString(me.libraryaddict.disguise.utilities.params.types.base.ParamInfoString) ParamInfoParticle(me.libraryaddict.disguise.utilities.params.types.custom.ParamInfoParticle) WrappedParticle(com.comphenix.protocol.wrappers.WrappedParticle) Particle(org.bukkit.Particle) ParamInfoParticle(me.libraryaddict.disguise.utilities.params.types.custom.ParamInfoParticle) RabbitType(me.libraryaddict.disguise.disguisetypes.RabbitType) ParamInfoFloat(me.libraryaddict.disguise.utilities.params.types.base.ParamInfoFloat) ParamInfoPotionEffect(me.libraryaddict.disguise.utilities.params.types.custom.ParamInfoPotionEffect) ParamInfoItemStackArray(me.libraryaddict.disguise.utilities.params.types.custom.ParamInfoItemStackArray) ParamInfoEnum(me.libraryaddict.disguise.utilities.params.types.ParamInfoEnum) ParamInfoColor(me.libraryaddict.disguise.utilities.params.types.custom.ParamInfoColor) PotionEffectType(org.bukkit.potion.PotionEffectType) ParamInfoSoundGroup(me.libraryaddict.disguise.utilities.params.types.custom.ParamInfoSoundGroup) BarColor(org.bukkit.boss.BarColor) ParamInfoColor(me.libraryaddict.disguise.utilities.params.types.custom.ParamInfoColor) ParamInfoChatColor(me.libraryaddict.disguise.utilities.params.types.custom.ParamInfoChatColor) Color(org.bukkit.Color) ChatColor(org.bukkit.ChatColor) DyeColor(org.bukkit.DyeColor) WrappedParticle(com.comphenix.protocol.wrappers.WrappedParticle) DyeColor(org.bukkit.DyeColor) ParamInfoTime(me.libraryaddict.disguise.utilities.params.types.custom.ParamInfoTime) WrappedGameProfile(com.comphenix.protocol.wrappers.WrappedGameProfile) ParamInfoGameProfile(me.libraryaddict.disguise.utilities.params.types.custom.ParamInfoGameProfile) MainHand(org.bukkit.inventory.MainHand) ParamInfoEulerAngle(me.libraryaddict.disguise.utilities.params.types.custom.ParamInfoEulerAngle) EulerAngle(org.bukkit.util.EulerAngle) ItemStack(org.bukkit.inventory.ItemStack) ParamInfoItemStack(me.libraryaddict.disguise.utilities.params.types.custom.ParamInfoItemStack) ParamInfoChatColor(me.libraryaddict.disguise.utilities.params.types.custom.ParamInfoChatColor) ChatColor(org.bukkit.ChatColor) Art(org.bukkit.Art) GolemCrack(me.libraryaddict.disguise.disguisetypes.GolemCrack) ParamInfoBlockData(me.libraryaddict.disguise.utilities.params.types.custom.ParamInfoBlockData) ParamInfoFloatNullable(me.libraryaddict.disguise.utilities.params.types.base.ParamInfoFloatNullable) BarStyle(org.bukkit.boss.BarStyle) ParamInfoBlockPosition(me.libraryaddict.disguise.utilities.params.types.custom.ParamInfoBlockPosition) BlockData(org.bukkit.block.data.BlockData) ParamInfoBlockData(me.libraryaddict.disguise.utilities.params.types.custom.ParamInfoBlockData) ParamInfoInteger(me.libraryaddict.disguise.utilities.params.types.base.ParamInfoInteger) EntityPose(me.libraryaddict.disguise.disguisetypes.EntityPose) BarStyle(org.bukkit.boss.BarStyle) ParamInfoBlockPosition(me.libraryaddict.disguise.utilities.params.types.custom.ParamInfoBlockPosition) BlockPosition(com.comphenix.protocol.wrappers.BlockPosition) ParamInfoBoolean(me.libraryaddict.disguise.utilities.params.types.base.ParamInfoBoolean) Material(org.bukkit.Material) ParamInfoChatColor(me.libraryaddict.disguise.utilities.params.types.custom.ParamInfoChatColor) ParamInfoString(me.libraryaddict.disguise.utilities.params.types.base.ParamInfoString) PotionEffectType(org.bukkit.potion.PotionEffectType) RabbitType(me.libraryaddict.disguise.disguisetypes.RabbitType) ParamInfoItemStack(me.libraryaddict.disguise.utilities.params.types.custom.ParamInfoItemStack)

Example 68 with ChatColor

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;
}
Also used : DisguisePermissions(me.libraryaddict.disguise.utilities.parser.DisguisePermissions) DisguisePerm(me.libraryaddict.disguise.utilities.parser.DisguisePerm) ArrayList(java.util.ArrayList) ChatColor(org.bukkit.ChatColor) WatcherMethod(me.libraryaddict.disguise.utilities.parser.WatcherMethod) ParamInfo(me.libraryaddict.disguise.utilities.params.ParamInfo)

Example 69 with ChatColor

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());
    }
}
Also used : Method(java.lang.reflect.Method) ChatColor(org.bukkit.ChatColor) LinkedList(java.util.LinkedList)

Example 70 with ChatColor

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());
    }
}
Also used : ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) ChatColor(org.bukkit.ChatColor)

Aggregations

ChatColor (org.bukkit.ChatColor)182 ArrayList (java.util.ArrayList)34 Player (org.bukkit.entity.Player)31 World (org.bukkit.World)12 Team (org.bukkit.scoreboard.Team)11 Matcher (java.util.regex.Matcher)10 ItemStack (org.bukkit.inventory.ItemStack)10 List (java.util.List)9 JSONObject (org.json.simple.JSONObject)9 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)8 DyeColor (org.bukkit.DyeColor)7 Material (org.bukkit.Material)7 ItemMeta (org.bukkit.inventory.meta.ItemMeta)7 HashMap (java.util.HashMap)6 Scoreboard (org.bukkit.scoreboard.Scoreboard)6 IOException (java.io.IOException)4 DecimalFormat (java.text.DecimalFormat)4 UUID (java.util.UUID)4 OfflinePlayer (org.bukkit.OfflinePlayer)4 Score (org.bukkit.scoreboard.Score)4