Colours?

Discussion in 'Plugin Development' started by Sean0402, Aug 27, 2014.

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

    Sean0402

    Hello how do I make it so in the config you can do colours? Say the message is the default as I put.. And I want them to use colours. So they can customize it.

    code:

    Code:java
    1. package me.Sean0402.HidePlugin;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.event.EventHandler;
    7. import org.bukkit.event.Listener;
    8. import org.bukkit.event.player.PlayerCommandPreprocessEvent;
    9. import org.bukkit.plugin.java.JavaPlugin;
    10.  
    11. public class HidePlugin extends JavaPlugin implements Listener {
    12.  
    13. private boolean Message = this.getConfig().getBoolean("Message");
    14.  
    15. public void onEnable(){
    16. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    17. getServer().getLogger().info("HidePlugin Now Enabled! Created By Sean0402");
    18. getConfig().options().copyDefaults(true);
    19. saveConfig();
    20. }
    21.  
    22. public void onDisable(){
    23. getServer().getLogger().info("HidePlugin Now Enabled! Created By Sean0402");
    24. }
    25.  
    26. @EventHandler
    27. public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event)
    28. {
    29. Player p = event.getPlayer();
    30. if ((event.getMessage().startsWith("/?")) && (!event.getPlayer().isOp()))
    31. {
    32. p.sendMessage(getConfig().getString("Message"));
    33. event.setCancelled(true);
    34. }
    35. else if ((event.getMessage().startsWith("/bukkit")) && (event.getPlayer().isOp()))
    36. {
    37. event.setCancelled(true);
    38. p.sendMessage(getConfig().getString("Message"));
    39. }
    40. else if ((event.getMessage().startsWith("/pl")) && (event.getPlayer().isOp()))
    41. {
    42. event.setCancelled(true);
    43. p.sendMessage(getConfig().getString("Message"));
    44. }
    45. }
    46. }
    47.  
     
  2. Offline

    FerusGrim

  3. Offline

    _Cookie_

    After you use .getString("Your.Awesome.Config.File").replaceAll("&1", ChatColor.DARK_BLUE + "");
     
  4. Offline

    Sean0402

    _Cookie_ How would I do it for more than 1? And the .replaceAll keeps saying to rename is to replace or replaceFirst then if I do them it says rename it to the old one..
     
  5. Offline

    FerusGrim

    Just as an example of usage. Say you have a config file.

    Code:
    some:
        text: '&7Hello! My name is &2FerusGrim!'
    You could then translate those symbols:
    Code:java
    1. public void someMethod() {
    2. getLogger().info(ChatColor.translateAlternateColorCodes('&', getConfig().getString("some.text")));
    3. }
     
  6. Offline

    LordVakar

    _Cookie_
    Wat even?
    *cough* there is a method as FerusGrim explained, why would you do that?
    This is the second time I've said this to you but go think about what you have just posted ;3
     
  7. Offline

    _Cookie_

    LordVakar That is how I do it, I wasn't aware of that method, so there is no need to be a dick about it.
     
  8. Offline

    BillyGalbreath

    You should really have a read through the API docs, then. Familiarize yourself with it, and you can do anything. ;)
     
  9. Offline

    Sean0402

    I'm having problems with it still.. Giving me errors when I change the code and put's it back to it's original code.

    Code:java
    1. package me.Sean0402.HidePlugin;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.event.EventHandler;
    7. import org.bukkit.event.Listener;
    8. import org.bukkit.event.player.PlayerCommandPreprocessEvent;
    9. import org.bukkit.plugin.java.JavaPlugin;
    10.  
    11. public class HidePlugin extends JavaPlugin implements Listener {
    12.  
    13. private boolean Message = this.getConfig().getBoolean("Message");
    14.  
    15. public void onEnable(){
    16. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    17. getServer().getLogger().info("HidePlugin Now Enabled! Created By Sean0402");
    18. getConfig().options().copyDefaults();
    19. saveConfig();
    20. }
    21.  
    22. public void onDisable(){
    23. getServer().getLogger().info("HidePlugin Now Enabled! Created By Sean0402");
    24. }
    25.  
    26. @EventHandler
    27. public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event)
    28. {
    29. Player p = event.getPlayer();
    30. if ((event.getMessage().startsWith("/?")) && (!event.getPlayer().isOp()))
    31. {
    32. getLogger().info(ChatColor.translateAlternateColorCodes('&', getConfig().getString("Message")));
    33. p.sendMessage(getConfig().getString("Message"));
    34. event.setCancelled(true);
    35. }
    36. else if ((event.getMessage().startsWith("/bukkit")) && (event.getPlayer().isOp()))
    37. {
    38. getLogger().info(ChatColor.translateAlternateColorCodes('&', getConfig().getString("Message")));
    39. p.sendMessage(getConfig().getString("Message"));
    40. event.setCancelled(true);
    41. }
    42. else if ((event.getMessage().startsWith("/pl")) && (event.getPlayer().isOp()))
    43. {
    44. getLogger().info(ChatColor.translateAlternateColorCodes('&', getConfig().getString("Message")));
    45. p.sendMessage(getConfig().getString("Message"));
    46. event.setCancelled(true);
    47. }
    48. }
    49. }
    50.  
     
  10. Offline

    LordVakar

    Well now you know, before giving people bad information and bad java coding conventions (in another thread), you should learn it yourself.
    Also, @OP, you're getting a string message that probably doesn't exist in the config everytime.
     
  11. Offline

    FerusGrim

    Sean0402
    Could you explain what this error is?
     
  12. Offline

    Sean0402

    FerusGrim when I try to edit the config it goes back to what I had it before I edited it?
     
  13. Offline

    FerusGrim

    LordVakar
    Really, he's just trying to help. :)
    Let us not discourage people who enjoy helping others, because of a mistake.

    _Cookie_
    The JavaDocs can be quite fun to explore. I sometimes look at the methods inside of it just to give me ideas of things to make! Why don't you browse through it? You may have some fun, and learn a thing or two at the same time.
     
  14. Offline

    LordVakar

    FerusGrim Sean0402
    Error is probably getString("Message") doesn't exist and he does it everytime.

    EDIT:
    FerusGrim
    I realize he's trying to help, but giving away bad information every time is terrible, it makes other people learn java incorrectly.
     
  15. Offline

    ChipDev

    By the way... The way you used for "StartsWith" could mean someone could type "/plugz"
     
  16. Offline

    FerusGrim

    I really couldn't tell you off-hand what the issue is, without looking a bit more. But, for now, try replacing:
    Code:java
    1. getConfig().options().copyDefaults();

    with:
    Code:java
    1. saveDefaultConfig();
     
  17. Offline

    Sean0402

  18. Offline

    FerusGrim

    I don't really disagree. But someone is more likely to take your advice if you give it to them in a way where you don't come off as a jerk. :p
     
  19. Offline

    Sean0402

    FerusGrim It's not copying my default config. so the "Message" string won't be there?
     
Thread Status:
Not open for further replies.

Share This Page