Config help

Discussion in 'Plugin Development' started by glassbillen, Apr 6, 2014.

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

    glassbillen

    I need help with making my config support color codes (the same as essentials use's) And 2 variables that translates %s% To: sender.getName() and %r% to targetPlayer.getName(), but it just getting error and still not working. here is the part of my code that i need help with:
    Code:java
    1. @Override
    2. public void onEnable() {
    3. getLogger().info("EmotionCraft has been enabled!");
    4. File file = new File(getDataFolder() + File.separator + "config.yml");
    5.  
    6. if (!file.exists()) {
    7. this.getLogger().info("Generating Config.yml...");
    8.  
    9. this.getConfig().addDefault("Link For Variables:", "dev.bukkit.org/bukkit-plugins/EmotionCraft/");
    10.  
    11. ChatColor.translateAlternateColorCodes('&', message);
    12. String Sender = (String) getConfig().get("HugReciever");
    13. Sender = Sender.replaceAll("%s", sender.getName());
    14. String Reciever = (String) getConfig().get("HugSender");
    15. Reciever = Reciever.replaceAll("%r", targetPlayer.getName());
    16. this.getConfig().addDefault("HugReciever", "&cYou have been huged by %s%");
    17. this.getConfig().addDefault("HugSender", "%r% &chuged");
    18. this.getConfig().addDefault("KissReciever", "&cYou have been kissed by %s%");
    19. this.getConfig().addDefault("KissSender", "%r% &ckissed");
    20. this.getConfig().addDefault("SorryReciever", "%s% &cis sorry!");
    21. this.getConfig().addDefault("SorrySender", "%r% &capologized!");
    22. this.getConfig().addDefault("MakeOutReciever", "%s% &ctried to make out with you!");
    23. this.getConfig().addDefault("MakeOutSender", "&cYou made out with %r%");
    24. this.getConfig().addDefault("ComfortReciever", "%s% &ctrying to comfort you!");
    25. this.getConfig().addDefault("ComfortSender", "%r% &cmust be happy now :)");
    26. this.getConfig().addDefault("SlapReciever", "%s% &cslaped you!");
    27. this.getConfig().addDefault("SlapSender", "%r% &cslaped!");
    28. this.getConfig().options().copyDefaults(true);
    29. this.saveConfig();
    30. this.getLogger().info("Generated Config.yml complete!");
    31.  
    32. }
    33. }
    34.  


    bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  2. Offline

    StaticJava

    I recommend for the senders and receivers, to just use %s% and %r%.

    This is how you would replace %s% with the sender:

    Code:java
    1. String Sender = (String) getConfig().get("HugReciever");
    2. Sender = Sender.replaceAll("%s", sender.getName());


    This is how you would replace %r% with the receiver:

    Code:java
    1. String Reciever = (String) getConfig().get("HugSender");
    2. Receiver = Reciever.replaceAll("%r", targetPlayer.getName());


    As for color codes, try this:

    Code:java
    1. String message = "&aPretend I got this from the &cconfig."
    2. message = message.replace('&', '§');
     
  3. Offline

    glassbillen

    HMM the pretend i got this from the config should i remove the old color thing and paste this in on enable only? And the other (%s% and that, do i need to do as that on every config string (EX: ComfortReciever?)
     
  4. Offline

    StaticJava

    Wherever you want to get color codes from the config, just use my replaceAll method. The %s% goes on every sender, and %r% goes to all receivers.
     
  5. Offline

    glassbillen

    StaticJava i dont understand, have i done right?:
    Code:java
    1. @Override
    2. public void onEnable() {
    3. getLogger().info("EmotionCraft has been enabled!");
    4. File file = new File(getDataFolder() + File.separator + "config.yml");
    5.  
    6. if (!file.exists()) {
    7. this.getLogger().info("Generating Config.yml...");
    8.  
    9. this.getConfig().addDefault("Link For Variables:", "dev.bukkit.org/bukkit-plugins/EmotionCraft/");
    10.  
    11. String Sender = (String) getConfig().get("HugReciever");
    12. Sender = Sender.replaceAll("%s", sender.getName());
    13. Sender = Sender.replace('&', '§');
    14. String Reciever = (String) getConfig().get("HugSender");
    15. Reciever = Reciever.replaceAll("%r", targetPlayer.getName());
    16. Reciever = Reciever.replace('&', '§');
    17. this.getConfig().addDefault("HugReciever", "&cYou have been huged by _Sender_");
    18. this.getConfig().addDefault("HugSender", "_Reciever_ &chuged");
    19. this.getConfig().addDefault("KissReciever", "&cYou have been kissed by _Sender_");
    20. this.getConfig().addDefault("KissSender", "_Reciever_ &ckissed");
    21. this.getConfig().addDefault("SorryReciever", "_Sender_ &cis sorry!");
    22. this.getConfig().addDefault("SorrySender", "_Reciever_ &capologized!");
    23. this.getConfig().addDefault("MakeOutReciever", "_Sender_ &ctried to make out with you!");
    24. this.getConfig().addDefault("MakeOutSender", "&cYou made out with _Reciever_");
    25. this.getConfig().addDefault("ComfortReciever", "_Sender_ &ctrying to comfort you!");
    26. this.getConfig().addDefault("ComfortSender", "_Reciever_ &cmust be happy now :)");
    27. this.getConfig().addDefault("SlapReciever", "_Sender_ &cslaped you!");
    28. this.getConfig().addDefault("SlapSender", "_Reciever_ &cslaped!");
    29. this.getConfig().options().copyDefaults(true);
    30. this.saveConfig();
    31. this.getLogger().info("Generated Config.yml complete!");
    32.  
    33. }
    34. }
    35.  
     
  6. Offline

    StaticJava


    Almost. First off, you don't need to cast String to the config. Use getString for that. Why not use Bukkit's config methods? Instead of making a file, just make the config.yml in your IDE, and all these defaults manually?
     
  7. Offline

    glassbillen

    1. thanks, 2. config.yml, saaay what? i think i should do as this, well how do you think i should solve this problem? can you make me a TuT?
     
  8. Offline

    glassbillen

    BUMP, still needs help, and for the new code, i have updated the desc for this topic, so yeah!

    Someone that can help :(

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  9. Offline

    iPoke111

    glassbillen
    message = message.replaceAll('&', '§');
    Don't use this, use message = ChatColor.translateAlternateColorCodes('&', message);
     
  10. Offline

    glassbillen

    ok done, i updated my code there up, btw BUMP still need help
     
  11. Offline

    glassbillen

  12. Offline

    StaticJava

    What is the error, if there is an error? What are you having trouble with? Also, iPoke111, you can use my way as well. It is much shorter and easier.
     
  13. Offline

    glassbillen

    Really its Is (plugin name) Up to top? thing. and when i use the command the line is empty empty row, and no config create's
     
Thread Status:
Not open for further replies.

Share This Page