Solved Help with configs!

Discussion in 'Plugin Development' started by JMSPTGammer, Feb 18, 2014.

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

    JMSPTGammer

    Hey! I'me making a MOTD like plugin and i'm getting an error!

    Here are my classes and config.yml:

    Core:
    Code:java
    1. package me.r0xoW.welcomer;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.plugin.PluginDescriptionFile;
    6. import org.bukkit.plugin.java.JavaPlugin;
    7.  
    8. public class Core extends JavaPlugin {
    9.  
    10. public static Core plugin;
    11. public final Logger logger = Logger.getLogger("Minecraft");
    12.  
    13. @Override
    14. public void onEnable() {
    15. PluginDescriptionFile pdffile = this.getDescription();
    16. this.logger.info(pdffile.getName() + " has been enabled!");
    17. getCommand("sbmsg").setExecutor(new Commands());
    18. getCommand("snpm").setExecutor(new Commands());
    19. getCommand("spm").setExecutor(new Commands());
    20. ConfigurationAPI.getConfig(this, "config.yml");
    21. ConfigurationAPI.saveConfig(this, "config.yml");
    22. this.getServer().getPluginManager().registerEvents(new PlayerJoinListener(), this);
    23. }
    24.  
    25. @Override
    26. public void onDisable() {
    27. PluginDescriptionFile pdffile = this.getDescription();
    28. this.logger.info(pdffile.getName() + " has been disabled!");
    29. ConfigurationAPI.getConfig(this, "config.yml");
    30. ConfigurationAPI.saveConfig(this, "config.yml");
    31. }
    32. }


    Listener:
    Code:java
    1. package me.r0xoW.welcomer;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.configuration.file.FileConfiguration;
    5. import org.bukkit.event.EventHandler;
    6. import org.bukkit.event.Listener;
    7. import org.bukkit.event.player.PlayerLoginEvent;
    8.  
    9. public class PlayerJoinListener implements Listener {
    10.  
    11. @EventHandler
    12. public void onPlayerLogin(final PlayerLoginEvent e) {
    13. Core.plugin.getServer().getScheduler().scheduleSyncDelayedTask(Core.plugin, new Runnable(){
    14.  
    15. @Override
    16. public void run() {
    17. if(e.getPlayer().hasPlayedBefore()) {
    18. FileConfiguration fc = ConfigurationAPI.getConfig(Core.plugin, "config.yml");
    19. e.getPlayer().sendMessage(fc.getString("PrivateMessage").replaceAll("&c", ChatColor.RED + "").replaceAll("&0", ChatColor.BLACK + "").replaceAll("&1", ChatColor.DARK_BLUE + "").replaceAll("&2", ChatColor.DARK_GREEN + "").replaceAll("&3", ChatColor.DARK_AQUA + "").replaceAll("&4", ChatColor.DARK_RED + "").replaceAll("&5", ChatColor.DARK_PURPLE + "").replaceAll("&6", ChatColor.GOLD + "").replaceAll("&7", ChatColor.GRAY + "").replaceAll("&8", ChatColor.DARK_GRAY + "").replaceAll("&9", ChatColor.BLUE + "").replaceAll("&a", ChatColor.GREEN + "").replaceAll("&b", ChatColor.AQUA + "").replaceAll("&d", ChatColor.LIGHT_PURPLE + "").replaceAll("&e", ChatColor.YELLOW + "").replaceAll("&f", ChatColor.WHITE + "").replaceAll("&k", ChatColor.MAGIC + "").replaceAll("&o", ChatColor.ITALIC + "").replaceAll("&l", ChatColor.BOLD + "").replaceAll("m", ChatColor.STRIKETHROUGH + "").replaceAll("&n", ChatColor.UNDERLINE + "").replaceAll("&r", ChatColor.RESET + ""));
    20. } else {
    21. FileConfiguration fc = ConfigurationAPI.getConfig(Core.plugin, "config.yml");
    22. e.getPlayer().sendMessage(fc.getString("PrivateMessageNew").replaceAll("&c", ChatColor.RED + "").replaceAll("&0", ChatColor.BLACK + "").replaceAll("&1", ChatColor.DARK_BLUE + "").replaceAll("&2", ChatColor.DARK_GREEN + "").replaceAll("&3", ChatColor.DARK_AQUA + "").replaceAll("&4", ChatColor.DARK_RED + "").replaceAll("&5", ChatColor.DARK_PURPLE + "").replaceAll("&6", ChatColor.GOLD + "").replaceAll("&7", ChatColor.GRAY + "").replaceAll("&8", ChatColor.DARK_GRAY + "").replaceAll("&9", ChatColor.BLUE + "").replaceAll("&a", ChatColor.GREEN + "").replaceAll("&b", ChatColor.AQUA + "").replaceAll("&d", ChatColor.LIGHT_PURPLE + "").replaceAll("&e", ChatColor.YELLOW + "").replaceAll("&f", ChatColor.WHITE + "").replaceAll("&k", ChatColor.MAGIC + "").replaceAll("&o", ChatColor.ITALIC + "").replaceAll("&l", ChatColor.BOLD + "").replaceAll("m", ChatColor.STRIKETHROUGH + "").replaceAll("&n", ChatColor.UNDERLINE + "").replaceAll("&r", ChatColor.RESET + ""));
    23. Core.plugin.getServer().broadcastMessage(fc.getString("GlobalMessage").replaceAll("&c", ChatColor.RED + "").replaceAll("&0", ChatColor.BLACK + "").replaceAll("&1", ChatColor.DARK_BLUE + "").replaceAll("&2", ChatColor.DARK_GREEN + "").replaceAll("&3", ChatColor.DARK_AQUA + "").replaceAll("&4", ChatColor.DARK_RED + "").replaceAll("&5", ChatColor.DARK_PURPLE + "").replaceAll("&6", ChatColor.GOLD + "").replaceAll("&7", ChatColor.GRAY + "").replaceAll("&8", ChatColor.DARK_GRAY + "").replaceAll("&9", ChatColor.BLUE + "").replaceAll("&a", ChatColor.GREEN + "").replaceAll("&b", ChatColor.AQUA + "").replaceAll("&d", ChatColor.LIGHT_PURPLE + "").replaceAll("&e", ChatColor.YELLOW + "").replaceAll("&f", ChatColor.WHITE + "").replaceAll("&k", ChatColor.MAGIC + "").replaceAll("&o", ChatColor.ITALIC + "").replaceAll("&l", ChatColor.BOLD + "").replaceAll("m", ChatColor.STRIKETHROUGH + "").replaceAll("&u", ChatColor.UNDERLINE + "").replaceAll("&r", ChatColor.RESET + "").replaceAll("%player%", e.getPlayer() + ""));
    24.  
    25. }
    26. }
    27. }, 20);
    28. }
    29. }
    30.  


    ConfigAPI:
    Code:java
    1. package me.r0xoW.welcomer;
    2.  
    3. import java.io.File;
    4. import java.io.IOException;
    5. import java.io.InputStream;
    6. import java.util.logging.Level;
    7.  
    8. import org.bukkit.configuration.file.FileConfiguration;
    9. import org.bukkit.configuration.file.YamlConfiguration;
    10. import org.bukkit.plugin.java.JavaPlugin;
    11.  
    12. public class ConfigurationAPI {
    13. static File f = null;
    14. static FileConfiguration fc = null;
    15.  
    16. public static void reloadConfig(JavaPlugin plugin, String string) {
    17. if (f == null) {
    18. f = new File(plugin.getDataFolder(), string);
    19. }
    20.  
    21. fc = YamlConfiguration.loadConfiguration(f);
    22.  
    23. InputStream defConfigStream = plugin.getResource(string);
    24. if (defConfigStream != null) {
    25. YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
    26. fc.setDefaults(defConfig);
    27. }
    28. }
    29.  
    30. public static FileConfiguration getConfig(JavaPlugin plugin, String string) {
    31. if (fc == null) {
    32. reloadConfig(plugin, string);
    33. }
    34. return fc;
    35. }
    36.  
    37. public static void saveConfig(JavaPlugin plugin, String string) {
    38. if (fc == null || f == null) {
    39. Core.plugin.logger.severe("Could not save the file " + string + " beacuse is does not exist!");
    40. return;
    41. }
    42. try {
    43. getConfig(plugin, string).save(f);
    44. } catch (IOException ex) {
    45. Core.plugin.logger.log(Level.SEVERE, "Error: Could not save config to " + f, ex);
    46. }
    47. }
    48.  
    49. public static void saveDefaultsConfig(JavaPlugin plugin, String string) {
    50. if (f == null) {
    51. f = new File(plugin.getDataFolder(), string);
    52. }
    53.  
    54. if (!f.exists()) {
    55. plugin.saveResource(string, false);
    56. }
    57. }
    58. }
    59.  


    Config.yml:
    Code:
    #Welcome to the Welcomer config!
    #I've made this a User Friendly config so you can take the most out of this plugin!
     
    #This is the Global Message: whenever a players joins the server for the first time, it broadcasts this message.
    GlobalMessage: &d Welcome &6 %player% &d to the server!
     
    #This is the Private Message for new players: whenever a new player joins the server for the first time, it sends this private message to him.
    PrivateMessageNew: &d Welcome to the server! &a I hope you enjoy playing here!
     
    #This is the Private Message for regular players: whenever a player enters the game, it sends this private message to him.
    PrivateMessage: &a Welcome back to the server!
     
    #Color codes guide:
    #&0 - Black
    #&1 - Dark Blue
    #&2 - Dark Green
    #&3 - Dark Aqua
    #&4 - Dark Red
    #&5 - Dark Purple
    #&6 - Gold
    #&7 - Gray
    #&8 - Dark Gray
    #&9 - Blue
    #&a - Green
    #&b - Aqua
    #&c - Red
    #&d - Light Purple
    #&e - Yellow
    #&f - White
    #&u - Underlined
    #&i - Italic
    #&l - Bold
    #&k - Magic
    #&m - Strikethrough
    #&r - Reset
     
    #And %player% replaces with the player name!
    The error i'm getting:
    Code:
    [20:20:11] [Server thread/INFO]: [Welcomer] Enabling Welcomer v1.0
    [20:20:11] [Server thread/INFO]: Welcomer has been enabled!
    [20:20:11] [Server thread/ERROR]: Cannot load configuration from stream
    org.bukkit.configuration.InvalidConfigurationException: found duplicate anchor d; first occurence
    in "<string>", line 5, column 16:
        GlobalMessage: &d Welcome &6 %player% &d to the ...
                      ^
    second occurence
    in "<string>", line 8, column 20:
        PrivateMessageNew: &d Welcome to the server! &a I h ...
                          ^
     
        at org.bukkit.configuration.file.YamlConfiguration.loadFromString(YamlConfiguration.java:55) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at org.bukkit.configuration.file.FileConfiguration.load(FileConfiguration.java:149) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(YamlConfiguration.java:204) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at me.r0xoW.welcomer.ConfigurationAPI.reloadConfig(ConfigurationAPI.java:25) [Welcomer.jar:?]
        at me.r0xoW.welcomer.ConfigurationAPI.getConfig(ConfigurationAPI.java:32) [Welcomer.jar:?]
        at me.r0xoW.welcomer.Core.onEnable(Core.java:20) [Welcomer.jar:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:218) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:457) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:384) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at org.bukkit.craftbukkit.v1_7_R1.CraftServer.loadPlugin(CraftServer.java:298) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at org.bukkit.craftbukkit.v1_7_R1.CraftServer.enablePlugins(CraftServer.java:280) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.m(MinecraftServer.java:342) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.g(MinecraftServer.java:319) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.a(MinecraftServer.java:275) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at net.minecraft.server.v1_7_R1.DedicatedServer.init(DedicatedServer.java:175) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:424) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    Caused by: org.yaml.snakeyaml.composer.ComposerException: found duplicate anchor d; first occurence; second occurence
        at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:150) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java:237) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:160) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at org.yaml.snakeyaml.composer.Composer.composeDocument(Composer.java:123) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at org.yaml.snakeyaml.composer.Composer.getSingleNode(Composer.java:106) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:121) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:480) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at org.yaml.snakeyaml.Yaml.load(Yaml.java:399) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at org.bukkit.configuration.file.YamlConfiguration.loadFromString(YamlConfiguration.java:53) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        ... 16 more
    [20:20:11] [Server thread/INFO]: Server permissions file permissions.yml is empty, ignoring it
    [20:20:11] [Server thread/INFO]: Done (1,327s)! For help, type "help" or "?"
    Any help?

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

    xTrollxDudex

    JMSPTGammer
    YAML format error. Fix your config.

    Try putting apostrohes around the text.
     
    Jaker232 likes this.
  3. Offline

    Jaker232

    You can format your YAML correctly with this tool.
     
  4. Offline

    JMSPTGammer

    I don't understand why can't i use the symbol '&'...​
     
  5. Offline

    Arcoz


    ^ Do what xTrollxDudex said

    GlobalMessage: &d Welcome &6 %player% &d to the server!

    This is how you want it:
    GlobalMessage: '&d Welcome &6 %player% &d to the server!'
     
Thread Status:
Not open for further replies.

Share This Page