Search in sources :

Example 21 with ChatColor

use of org.bukkit.ChatColor in project Essentials by EssentialsX.

the class User method getNick.

public String getNick(final boolean longnick, final boolean withPrefix, final boolean withSuffix) {
    final StringBuilder prefix = new StringBuilder();
    String nickname;
    String suffix = "";
    final String nick = getNickname();
    if (ess.getSettings().isCommandDisabled("nick") || nick == null || nick.isEmpty() || nick.equals(getName())) {
        nickname = getName();
    } else if (nick.equalsIgnoreCase(getName())) {
        nickname = nick;
    } else {
        nickname = FormatUtil.replaceFormat(ess.getSettings().getNicknamePrefix()) + nick;
        suffix = "§r";
    }
    if (this.getBase().isOp()) {
        try {
            final ChatColor opPrefix = ess.getSettings().getOperatorColor();
            if (opPrefix != null && opPrefix.toString().length() > 0) {
                prefix.insert(0, opPrefix.toString());
                suffix = "§r";
            }
        } catch (Exception e) {
        }
    }
    if (ess.getSettings().addPrefixSuffix()) {
        // These two extra toggles are not documented, because they are mostly redundant #EasterEgg
        if (withPrefix || !ess.getSettings().disablePrefix()) {
            final String ptext = ess.getPermissionsHandler().getPrefix(base).replace('&', '§');
            prefix.insert(0, ptext);
            suffix = "§r";
        }
        if (withSuffix || !ess.getSettings().disableSuffix()) {
            final String stext = ess.getPermissionsHandler().getSuffix(base).replace('&', '§');
            suffix = stext + "§r";
            suffix = suffix.replace("§f§f", "§f").replace("§f§r", "§r").replace("§r§r", "§r");
        }
    }
    final String strPrefix = prefix.toString();
    String output = strPrefix + nickname + suffix;
    if (!longnick && output.length() > 16) {
        output = strPrefix + nickname;
    }
    if (!longnick && output.length() > 16) {
        output = FormatUtil.lastCode(strPrefix) + nickname;
    }
    if (!longnick && output.length() > 16) {
        output = FormatUtil.lastCode(strPrefix) + nickname.substring(0, 14);
    }
    if (output.charAt(output.length() - 1) == '§') {
        output = output.substring(0, output.length() - 1);
    }
    return output;
}
Also used : ChatColor(org.bukkit.ChatColor) MaxMoneyException(net.ess3.api.MaxMoneyException)

Example 22 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 23 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)

Example 24 with ChatColor

use of org.bukkit.ChatColor in project MagicPlugin by elBukkit.

the class Wand method convertToHTML.

protected static String convertToHTML(String line) {
    int tagCount = 1;
    line = "<span style=\"color:white\">" + line;
    for (ChatColor c : ChatColor.values()) {
        tagCount += StringUtils.countMatches(line, c.toString());
        String replaceStyle = "";
        if (c == ChatColor.ITALIC) {
            replaceStyle = "font-style: italic";
        } else if (c == ChatColor.BOLD) {
            replaceStyle = "font-weight: bold";
        } else if (c == ChatColor.UNDERLINE) {
            replaceStyle = "text-decoration: underline";
        } else {
            String color = c.name().toLowerCase().replace("_", "");
            if (c == ChatColor.LIGHT_PURPLE) {
                color = "mediumpurple";
            }
            replaceStyle = "color:" + color;
        }
        line = line.replace(c.toString(), "<span style=\"" + replaceStyle + "\">");
    }
    for (int i = 0; i < tagCount; i++) {
        line += "</span>";
    }
    return line;
}
Also used : ChatColor(org.bukkit.ChatColor)

Example 25 with ChatColor

use of org.bukkit.ChatColor in project MagicPlugin by elBukkit.

the class MageCommandExecutor method onMageAttribute.

public boolean onMageAttribute(CommandSender sender, Player player, String[] args) {
    Mage mage = controller.getMage(player);
    Set<String> internalAttributes = api.getController().getInternalAttributes();
    Set<String> attributes = api.getController().getAttributes();
    if (attributes.isEmpty()) {
        sender.sendMessage(ChatColor.RED + "No attributes configured, see attributes.yml");
        return true;
    }
    if (args.length == 0) {
        sender.sendMessage(ChatColor.GOLD + "Attributes for: " + ChatColor.AQUA + player.getName());
        List<String> attributeList = new ArrayList<>(attributes);
        Collections.sort(attributeList);
        for (String key : attributeList) {
            ChatColor attributeType = internalAttributes.contains(key) ? ChatColor.DARK_AQUA : ChatColor.GRAY;
            Double value = mage.getAttribute(key);
            String valueDescription = value == null ? ChatColor.RED + "(not set)" : ChatColor.AQUA + Double.toString(value);
            sender.sendMessage(attributeType + key + ChatColor.BLUE + " = " + valueDescription);
        }
        return true;
    }
    String key = args[0];
    if (!attributes.contains(key)) {
        sender.sendMessage(ChatColor.RED + "Unknown attribute: " + ChatColor.YELLOW + key);
        return true;
    }
    if (args.length == 1) {
        Double value = mage.getAttribute(key);
        String valueDescription = value == null ? ChatColor.RED + "(not set)" : ChatColor.AQUA + Double.toString(value);
        sender.sendMessage(ChatColor.AQUA + player.getName() + " has " + ChatColor.DARK_AQUA + key + ChatColor.BLUE + " of " + valueDescription);
        return true;
    }
    MageClass activeClass = mage.getActiveClass();
    CasterProperties attributeProperties = mage.getProperties();
    if (activeClass != null && attributeProperties.getAttribute(key) == null) {
        attributeProperties = activeClass;
    }
    String value = args[1];
    for (int i = 2; i < args.length; i++) {
        value = value + " " + args[i];
    }
    if (value.equals("-")) {
        Double oldValue = attributeProperties.getAttribute(key);
        attributeProperties.setAttribute(key, null);
        String valueDescription = oldValue == null ? ChatColor.RED + "(not set)" : ChatColor.AQUA + Double.toString(oldValue);
        sender.sendMessage(ChatColor.BLUE + "Removed attribute " + ChatColor.DARK_AQUA + key + ChatColor.BLUE + ", was " + valueDescription);
        return true;
    }
    double transformed = Double.NaN;
    try {
        transformed = Double.parseDouble(value);
    } catch (Exception ex) {
        EquationTransform transform = EquationStore.getInstance().getTransform(value);
        if (transform.getException() == null) {
            Double property = attributeProperties.getAttribute(key);
            if (property == null || Double.isNaN(property)) {
                property = 0.0;
            }
            transform.setVariable("x", property);
            transformed = transform.get();
        }
    }
    if (Double.isNaN(transformed)) {
        sender.sendMessage(ChatColor.RED + "Could not set " + ChatColor.YELLOW + key + ChatColor.RED + " to " + ChatColor.YELLOW + value);
        return true;
    }
    attributeProperties.setAttribute(key, transformed);
    sender.sendMessage(ChatColor.GOLD + "Set " + ChatColor.DARK_AQUA + key + ChatColor.GOLD + " to " + ChatColor.AQUA + transformed + ChatColor.GOLD + " for " + ChatColor.DARK_AQUA + player.getDisplayName());
    return true;
}
Also used : CasterProperties(com.elmakers.mine.bukkit.api.magic.CasterProperties) EquationTransform(de.slikey.effectlib.math.EquationTransform) MageClass(com.elmakers.mine.bukkit.api.magic.MageClass) ArrayList(java.util.ArrayList) Mage(com.elmakers.mine.bukkit.api.magic.Mage) ChatColor(org.bukkit.ChatColor)

Aggregations

ChatColor (org.bukkit.ChatColor)128 ArrayList (java.util.ArrayList)23 Player (org.bukkit.entity.Player)17 Matcher (java.util.regex.Matcher)9 World (org.bukkit.World)9 JSONObject (org.json.simple.JSONObject)9 ItemStack (org.bukkit.inventory.ItemStack)8 DyeColor (org.bukkit.DyeColor)7 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)7 ItemMeta (org.bukkit.inventory.meta.ItemMeta)7 Material (org.bukkit.Material)6 Team (org.bukkit.scoreboard.Team)6 Method (java.lang.reflect.Method)5 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 LinkedList (java.util.LinkedList)4 Mage (com.elmakers.mine.bukkit.api.magic.Mage)3 List (java.util.List)3 UUID (java.util.UUID)3 Scoreboard (org.bukkit.scoreboard.Scoreboard)3