Tutorial Properly write variables from config!

Discussion in 'Resources' started by TheEnderCrafter9, Aug 29, 2016.

Thread Status:
Not open for further replies.
  1. What If I told you sender.sendMessage(ChatColor.translateAlternateColorCodes('&',plugin.getConfig.getString("Message")) could be shortened to sender.sendMessage(message), without having to worry about rewriting on reload??
    DankCo : 420 memes could save you 420 hours or more on coding.

    Well, that's what this tutorial is for. It's pretty simple.

    Instead of using
    Code:java
    1.  
    2. String mesage = ChatColor.translateAlternateColorCodes('&',plugin.getConfig.getString("Message");
    3.  

    We just use

    Code:java
    1.  
    2. String message() {
    3. plugin.reloadConfig();
    4. return ChatColor.translateAlternateColorCodes('&',plugin.getConfig.getString("Message");
    5. }
    6.  


    What this does is reload and save the config then return the string.
     
    Last edited: Aug 30, 2016
    Zombie_Striker likes this.
  2. Offline

    Zombie_Striker

    @TheEnderCrafter9
    Nice tutorial, though you don't actually shorten anything. All you're doing is inventing a way to make sure the message is "up to date" and shuffling around code.
     
    timtower likes this.
  3. @TheEnderCrafter9 So you want to edit the config EVERY time you want to send a coloured message?!?! Or am I missing something? I prefer my methods of shortening and I rarely even use that. I don't see what people's issue is with just doing ChatColor.COLOR sometimes.

    sender.sendMessage(color("&cThis is a message"));

    Code:
    public String color(String s) {
        return ChatColor.translateAlternateColorCodes('&', s);
    }
     
  4. Offline

    ArsenArsen

    Also why do save then reload? That will just delete changes then load already known and up to date config. Either do one on another.
     
  5. I use both methods, mostly beacuse of the quality of the my code. :')
    Meh why not actually ur right, reloading is not mandatory. I was typing this at 12:15 @ night, so I can say I didn't stay up three days working on this tutorial.

    I don't know why I did the reload trust me I check my code after i find it faulty mostly from the help of others.

    EDIT by Moderator: Looks like someone screwed up again.
     
    Last edited: Aug 30, 2016
Thread Status:
Not open for further replies.

Share This Page