Multiple Classes & Config Colours

Discussion in 'Plugin Development' started by CarlosArias604, Jun 7, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    CarlosArias604

    Hello Bukkit!

    To make this short and sweet here it is. I have put them into two spoilers as I have two questions.

    Multiple Classes Question:
    Show Spoiler

    Basically for my test plugin, In which I put a bit of my knowledge in there for reference.
    It started to look bad a while ago and I wanted to cut it into pieces with multiple classes. The problem being that from what I know(Not Very Much) about multiple classes doesn't work. (I'm going off Bucky's tutorials so I could be doing something stupid)

    Here is my code:
    Main Class - http://www.pastie.org/4048286
    Second Class - http://www.pastie.org/4048288

    If you could help me fix that it would be greatly appreciated! ;)


    Colour With Configs:
    Show Spoiler

    This is with my plugin that I plan to release in a month or two.(When I add more features) Basically it has a good amount of configuring and so to make the chat look better it needs be able to accept colour codes in the config.
    Here is my code that I have come too, It currently doesn't work and I have no idea how to do this!
    What I have been told:
    Show Spoiler

    PHP:
    sender.sendMessage(getConfig().getString("Website").replace("&","ยง"));


    Hopefully you can help me with this! ;)


    Thank you for your time and hopefully you can help me with these! ;)

    -Carlos
     
  2. Offline

    Mitsugaru

    Er, I see you made an object instance of Teleporting... but you don't actually use it?

    Assuming your onCommand method is firing correctly, could you just tack on the following to your else if in there?

    Code:
    else if(commandLabel.equalsIgnoreCase("tp") || commandLabel.equalsIgnoreCase("teleport")){
        return teleObject.OnCommand1(sender, cmd, commandLabel, args);
    }
    and remove the command check in the Teleporting class, since you would have already done it before calling?

    In regards to the second one, this may be a lengthier method... and probably someone that knows RegEx has a better way, but this has served me well enough so far:

    Code:
    /**
        * Colorizes a given string to Bukkit standards
        *
        * http://forums.bukkit.org/threads/methode-to-colorize.69543/#post-1063437
        *
        * @param string
        * @return String with appropriate Bukkit ChatColor in them
        * @author AmberK
        */
        public static String colorizeText(String string)
        {
            /**
            * Colors
            */
            if(string == null)
            {
                return "";
            }
            string = string.replaceAll("&0", "" + ChatColor.BLACK);
            string = string.replaceAll("&1", "" + ChatColor.DARK_BLUE);
            string = string.replaceAll("&2", "" + ChatColor.DARK_GREEN);
            string = string.replaceAll("&3", "" + ChatColor.DARK_AQUA);
            string = string.replaceAll("&4", "" + ChatColor.DARK_RED);
            string = string.replaceAll("&5", "" + ChatColor.DARK_PURPLE);
            string = string.replaceAll("&6", "" + ChatColor.GOLD);
            string = string.replaceAll("&7", "" + ChatColor.GRAY);
            string = string.replaceAll("&8", "" + ChatColor.DARK_GRAY);
            string = string.replaceAll("&9", "" + ChatColor.BLUE);
            string = string.replaceAll("&a", "" + ChatColor.GREEN);
            string = string.replaceAll("&b", "" + ChatColor.AQUA);
            string = string.replaceAll("&c", "" + ChatColor.RED);
            string = string.replaceAll("&d", "" + ChatColor.LIGHT_PURPLE);
            string = string.replaceAll("&e", "" + ChatColor.YELLOW);
            string = string.replaceAll("&f", "" + ChatColor.WHITE);
            /**
            * Formatting
            */
            string = string.replaceAll("&k", "" + ChatColor.MAGIC);
            string = string.replaceAll("&l", "" + ChatColor.BOLD);
            string = string.replaceAll("&m", "" + ChatColor.STRIKETHROUGH);
            string = string.replaceAll("&n", "" + ChatColor.UNDERLINE);
            string = string.replaceAll("&o", "" + ChatColor.ITALIC);
            string = string.replaceAll("&r", "" + ChatColor.RESET);
            return string;
        }
     
  3. Offline

    Njol

    There's a built-in function to convert chat colors:
    Code:
    String messageWithColors = ChatColor.translateAlternateColorCodes('&', message);
     
    Mitsugaru likes this.
  4. Offline

    Mitsugaru

    Well that certainly simplifies things. Nice to know.
     
Thread Status:
Not open for further replies.

Share This Page