ChatColor Plugin

Discussion in 'Spigot Plugin Development' started by TheMasteredPanda, May 14, 2016.

  1. Hello,

    Ok so I am currently nearing the completion of a TownyColors plugin, this plugin gets the users desired color and sets it as their suffix so that whenever they chat, it will be colored as the color they has chosen from the Available Colors list (This is the only way I can allow auto color chat (like essentials) to be implemented while I am using the TownyChat plugin). But I cannot seem to get the color that the user has selected by executing "/color set <colorhere>" and put it into the command that will be dispatched when the player chooses their command. Anyone able to point me in the right direction?

    My Code:

    Panda ;)
  2. Depends how you'd like it. If you want something like:

    &a&lExample -> ChatColor.GREEN + ChatColor.BOLD + "Example"

    Then you can use:

    translateAlternateColorCodes(char altColorChar, String textToTranslate)
    Translates a string using an alternate color code character into a string that uses the internal ChatColor.COLOR_CODE color code character.

    And if you'd like something like:

    YELLOW or yellow, you can use:

    valueOf(String name)
    Returns the enum constant of the specified enum type with the specified name.
    • Agree Agree x 1
  3. Well I think you all are over thinking this just a little. What you need to do is add another yml file designated to storing player colors when they use the cmd to switch the colors. Then you need an AsyncPlayerChatEvent to check when a player chats and you do something like this...
    public void onChat(AsyncPlayerChatEvent e) {
    Player player = (Player) e.getPlayer;
    e.setMessage(ChatColor.translateAlternateColorCodes('&', configname.getString(player.getName())) + e.getMessage());

    And for setting the config you could do...
    If(cmd.getName().equalsIgnoreCase("color")) {
    If(args.length[] == 1) {
    configname.createSection(player.getName(), args[1]);

    Keep in mind this is entirely off of memory and I'm doing this on an iPad so please understand the code may not be perfect! Hope it helped tho.

  4. Don't think i'm overthinking this tbh. All I want to do is get that argument (which would be the word color i.e. YELLOW or DARK_BLUE) and change that into what we all use in chat (&6, &3, &5) and then set that as their suffix. I think I got most it of down. The only bit I am struggling with is getting the word color, changing that do a &* color. I'll take your suggestion into account though.
    • Agree Agree x 1
  5. Not looking to be in any way professional buddy. And yeah i'll try out this chat event.
    • Useful Useful x 1
  6. Although you may not own a public server or plan to be professional, but you should still stick to code conventions, and keep your code organized. Using a method to simply execute the command for you isn't the best way of solving an issue.
    • Agree Agree x 1
  7. Yeah sure, good point.
  8. Code should be well written even if your not looking to be professional. You may want to be professional someday and be thankful that you got the skill.
    • Agree Agree x 1
  9. Yeah thank you :).
    • Friendly Friendly x 1
  10. You mind explaining this a bit? Tried to look around to see if I could find out what you mean but I can't find anything to relate to

    I'm going to assume this works for other people, but it still isn't getting the color word and setting it as my chatcolor .

    I have updated my repo:
  11. Assuming your colors.yml is the color storing yml for players, your onChat uses get config which I believe is directed to config.yml not colors.yml
  12. Yeah cheers bout that, forgot to change that xD. If I set the color manually it works perfectly . But I am still having problems, still, with getting the args[1] from the command and setting it in the colors.yml file.

    Updated Code:
  13. you were doing getColors().set() which I believe only works if that player is in the config. You need getColors().createSection(p.getName(), args[1])