Colors in a custom joinmessage config.

Discussion in 'Plugin Development' started by Specificus, Jan 27, 2014.

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

    Specificus

    Hello everyone. I have a "problem" with my code. I know my code is correct, but i want to change some parts of it.
    Code:java
    1. package no.firkanter;
    2.  
    3. import org.bukkit.plugin.PluginManager;
    4. import org.bukkit.plugin.java.JavaPlugin;
    5.  
    6. public class Main extends JavaPlugin{
    7.  
    8.  
    9.  
    10. public void onEnable() {
    11. getConfig().options().copyDefaults(true);
    12. saveConfig();
    13. PluginManager pm = getServer().getPluginManager();
    14.  
    15. pm.registerEvents(new PlayerListener(this), this);
    16.  
    17. System.out.println("LOC enabled!");
    18. }
    19.  
    20. public void onDisable() {
    21.  
    22.  
    23. System.out.println("LOC disabled!");
    24. }
    25.  
    26. }
    27.  

    Code:java
    1. package no.firkanter;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.entity.Player;
    5. import org.bukkit.event.EventHandler;
    6. import org.bukkit.event.Listener;
    7. import org.bukkit.event.player.PlayerJoinEvent;
    8.  
    9. public class PlayerListener implements Listener{
    10.  
    11. private final Main plugin;
    12.  
    13. public PlayerListener(Main plugin) {
    14. this.plugin = plugin;
    15. }
    16.  
    17. @EventHandler
    18. public void onPLayerJoin(PlayerJoinEvent event) {
    19. Player player = event.getPlayer();
    20. player.sendMessage(ChatColor.GREEN + plugin.getConfig().getString("message"));
    21. }
    22.  
    23. }
    24.  

    Basicly i want there to be different kind of options in the config. Lets say i want to show the message "Hey there!" in yellow, and another day i want "Server is being worked on" in grey another one. I want to change this fast in the config. And by doing this i want to be able to use &1-9 and &a-f Like you know the color codes. In my code i have it so its always green and i dont want to change the code in the plugin everytime im going to change the motd. I know you guys dont like supporting spoonfeeding, but please insert some code just to give an example so i understand.
    Thanks.
     
  2. Offline

    random_username

    Specificus
    Try
    Code:java
    1. player.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("message")));
     
  3. Offline

    Specificus

    Ehm i dont know how that work but it seems like if i try to instert a color code in my config it delete the first word. The config is like this : "message: &9Welcome to the server!" But i doesnt seem to work, it just delete what i wrote and goes back to default. Default it "message: Welcome to the server!" random_username
     
  4. Offline

    ItsLeandro

    Did you try it or not...?
     
  5. Offline

    MrInspector

    Seems like you obviously didn't do it. :p Specificus
     
  6. Offline

    AoH_Ruthless

    Specificus
    Because it is a string with multiple words (whitespace is present), YAML requires you to have single quotation marks.
    Code:
    message: Welcome to the server!
    This is wrong and will delete the first word. Instead, you want to enclose the whole message, like so:
    Code:
    message: 'Welcome to the server!'
     
  7. Offline

    Specificus

    Ehm, im sorry but i dont understand. I tried doing the message like "message: 'Welcome to the server!' But i got alot of errros on the config in console. Maybe use some words that are new-friendly? =) AoH_Ruthless MrInspector random_username
     
  8. Offline

    random_username

    Please post your config.yml :) You need to use YAML format correctly.
     
  9. Offline

    Specificus

    Code:java
    1. message: Velkommen til serveren!
    2.  

    Thats default ^^
    And when i edit it :
    Code:java
    1. message: &9'Velkommen til serveren!'
    2.  

    Ive also tried to use
    Code:java
    1. message: &9Velkommen til serveren!
    2.  

    But that was when it started deleting words.
    random_username
     
  10. Offline

    random_username

    It would be this way :)
    Code:
    message: '&9Velkommen til serveren!'
     
  11. Offline

    Specificus

    Thanks alot guys, i know this wasnt much but it is really good to complete something! Thanks
     
Thread Status:
Not open for further replies.

Share This Page