Search in sources :

Example 36 with ChatColor

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

the class Commandgc method run.

@Override
protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception {
    final double tps = ess.getTimer().getAverageTPS();
    final ChatColor color;
    if (tps >= 18.0) {
        color = ChatColor.GREEN;
    } else if (tps >= 15.0) {
        color = ChatColor.YELLOW;
    } else {
        color = ChatColor.RED;
    }
    sender.sendMessage(tl("uptime", DateUtil.formatDateDiff(ManagementFactory.getRuntimeMXBean().getStartTime())));
    sender.sendMessage(tl("tps", "" + color + NumberUtil.formatDouble(tps)));
    sender.sendMessage(tl("gcmax", Runtime.getRuntime().maxMemory() / 1024 / 1024));
    sender.sendMessage(tl("gctotal", Runtime.getRuntime().totalMemory() / 1024 / 1024));
    sender.sendMessage(tl("gcfree", Runtime.getRuntime().freeMemory() / 1024 / 1024));
    final List<World> worlds = server.getWorlds();
    for (final World w : worlds) {
        String worldType = "World";
        switch(w.getEnvironment()) {
            case NETHER:
                worldType = "Nether";
                break;
            case THE_END:
                worldType = "The End";
                break;
        }
        int tileEntities = 0;
        try {
            for (final Chunk chunk : w.getLoadedChunks()) {
                tileEntities += chunk.getTileEntities().length;
            }
        } catch (final java.lang.ClassCastException ex) {
            Bukkit.getLogger().log(Level.SEVERE, "Corrupted chunk data on world " + w, ex);
        }
        sender.sendMessage(tl("gcWorld", worldType, w.getName(), w.getLoadedChunks().length, w.getEntities().size(), tileEntities));
    }
}
Also used : World(org.bukkit.World) Chunk(org.bukkit.Chunk) ChatColor(org.bukkit.ChatColor)

Example 37 with ChatColor

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

the class Settings method _getOperatorColor.

private String _getOperatorColor() {
    final String colorName = config.getString("ops-name-color", null);
    if (colorName == null) {
        return ChatColor.RED.toString();
    } else if (colorName.equalsIgnoreCase("none") || colorName.isEmpty()) {
        return null;
    }
    try {
        return FormatUtil.parseHexColor(colorName);
    } catch (final NumberFormatException ignored) {
    }
    try {
        return ChatColor.valueOf(colorName.toUpperCase(Locale.ENGLISH)).toString();
    } catch (final IllegalArgumentException ignored) {
    }
    final ChatColor lastResort = ChatColor.getByChar(colorName);
    if (lastResort != null) {
        return lastResort.toString();
    }
    return null;
}
Also used : ChatColor(org.bukkit.ChatColor)

Example 38 with ChatColor

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

the class FormatUtil method stripColor.

static String stripColor(final String input, final Set<ChatColor> strip) {
    final StringBuffer builder = new StringBuffer();
    final Matcher matcher = STRIP_ALL_PATTERN.matcher(input);
    searchLoop: while (matcher.find()) {
        final char code = matcher.group(1).toLowerCase(Locale.ROOT).charAt(0);
        for (final ChatColor color : strip) {
            if (color.getChar() == code) {
                matcher.appendReplacement(builder, "");
                continue searchLoop;
            }
        }
        // Don't replace
        matcher.appendReplacement(builder, "$0");
    }
    matcher.appendTail(builder);
    return builder.toString();
}
Also used : Matcher(java.util.regex.Matcher) ChatColor(org.bukkit.ChatColor)

Example 39 with ChatColor

use of org.bukkit.ChatColor in project VoxelGamesLibv2 by VoxelGamesLib.

the class TeamSelectFeature method enable.

@Override
public void enable() {
    // create default teams
    List<String> teamNames = new ArrayList<>();
    teamNames.add("BLUE");
    teamNames.add("RED");
    teamNames.add("GREEN");
    teamNames.add("YELLOW");
    teamNames.add("LIGHT_PURPLE");
    teamNames.add("BLACK");
    List<ChatColor> teamColors = new ArrayList<>();
    teamColors.add(ChatColor.BLUE);
    teamColors.add(ChatColor.RED);
    teamColors.add(ChatColor.GREEN);
    teamColors.add(ChatColor.YELLOW);
    teamColors.add(ChatColor.LIGHT_PURPLE);
    teamColors.add(ChatColor.BLACK);
    for (int i = 0; i < teamCount; i++) {
        teams.add(new Team(teamSize, teamNames.get(i), teamColors.get(i), getPhase().getGame()));
    }
}
Also used : ArrayList(java.util.ArrayList) Team(com.voxelgameslib.voxelgameslib.components.team.Team) ChatColor(org.bukkit.ChatColor)

Example 40 with ChatColor

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

the class FormatUtil method getSupported.

private static EnumSet<ChatColor> getSupported(final IUser user, final String permBase) {
    final EnumSet<ChatColor> supported = EnumSet.noneOf(ChatColor.class);
    if (user.isAuthorized(permBase + ".color")) {
        supported.addAll(COLORS);
    }
    if (user.isAuthorized(permBase + ".format")) {
        supported.addAll(FORMATS);
    }
    if (user.isAuthorized(permBase + ".magic")) {
        supported.addAll(MAGIC);
    }
    for (final ChatColor chatColor : ChatColor.values()) {
        String colorName = chatColor.name();
        if (chatColor == ChatColor.MAGIC) {
            // Bukkit's name doesn't match with vanilla's
            colorName = "obfuscated";
        }
        final String node = permBase + "." + colorName.toLowerCase(Locale.ROOT);
        // Only handle individual colors that are explicitly added or removed.
        if (!user.isPermissionSet(node)) {
            continue;
        }
        if (user.isAuthorized(node)) {
            supported.add(chatColor);
        } else {
            supported.remove(chatColor);
        }
    }
    return supported;
}
Also used : 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