Solved Config

Discussion in 'Plugin Development' started by Ethan Rocks 365, Feb 9, 2016.

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

    Ethan Rocks 365

    Here is my code
    Code:
    package plugin.me.turtles;
    
    import java.util.logging.Logger;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class turtles extends JavaPlugin implements Listener
    {   
        Logger myPluginLogger = Bukkit.getLogger();
        MyConfigManager manager;
        MyConfig WebConfig;
       
        public void onEnable()
        {
            myPluginLogger.info(ChatColor.RED + "=====<WebSiteInfo>=====");
            myPluginLogger.warning(ChatColor.GREEN + "Enabling WebsiteInfo 1.0");
            myPluginLogger.info(ChatColor.RED + "=====<ThanksForUsing>=====");
            manager = new MyConfigManager(this);
            WebConfig = manager.getNewConfig(Config.yml);
           
        
        public void onDisable()
        {
           
        }
       
        public boolean onCommand(CommandSender theSender, Command cmd, String commandLable, String[] args)
        {
            if(commandLable.equalsIgnoreCase("website"))
            {
                Player thePlayer = (Player)theSender;
                thePlayer.sendMessage(ChatColor.GREEN + "Our website is: " + ChatColor.RED + "http://gtanetwork.enjin.com");
            }   
            return true;
        }
    }
    Here is what my config will look like: http://pastebin.com/HGAWFi6n
    What do i need to change the thePlayer.sendMessage(ChatColor.GREEN + "Our website is: " + ChatColor.RED + "http://gtanetwork.enjin.com"); to set the link (gtanetwork.enjin.com) to what is in 'These'? Please Help this is my first config YML
     
  2. Offline

    Xerox262

    getConfig().getString("Website");
     
  3. Offline

    Ethan Rocks 365

    What do i replace with that to still get the "Our WebSite Is:"
     
  4. Offline

    Xerox262

    It returns a string, just concatenate them.
     
  5. Offline

    Ethan Rocks 365

    Thix now where do i put the config because when i load it it opens up and its blank.
    http://imgur.com/bxB3Bjk this is my files. im using eclipse
     
  6. Offline

    Xerox262

    @Ethan Rocks 365 Why're you creating a config manager? Just use saveDefaultConfig(); to save the one from your jar.
     
  7. Offline

    Ethan Rocks 365

    Could you maybe show me how? Im sorry but im new to bukkit and this is my first config
     
  8. Offline

    teej107

  9. Offline

    TechBug2012

    @Ethan Rocks 365
    Forgive me if I'm wrong, but are you using TheBCBroz for tutorials? Your code looks inefficient. Pogostick29dev has some cool tutorials, including some on config files.

    So, what you're trying to do is setting the "gtanetwork" link to a link specified in a config, right? You need to tell the plugin to get the data from the string list inside the config called website. It would look something like this:
    Code:
    thePlayer.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().
                    getString("website")));
    
    This is similar to the example that Pogostick29dev uses in his MOTD plugin tutorial. What you're doing is this:
    ChatColor.translateAlternateColorCodes basically makes sure that the player can specify any color inside the config using &. If you want it to be hardcoded to green, you can do
    Code:
    thePlayer.sendMessage(ChatColor.GREEN + getConfig().
                    getString("website"));
    
    getConfig().getString("website") gets the string called "website", which is set in your config.yml, and it sends the player what is specified under that string.
     
  10. Offline

    Ethan Rocks 365

    @TechBug2012 Thanks. Im actually using Applejuze for tutorials.

    error (open)

    [18:28:53 INFO]: [WebsiteInfo] Enabling WebsiteInfo v1.0
    [18:28:53 INFO]: ºc=====<WebSiteInfo>=====
    [18:28:53 WARN]: ºaEnabling WebsiteInfo 1.0
    [18:28:53 INFO]: ºc=====<ThanksForUsing>=====
    [18:28:53 ERROR]: Error occurred while enabling WebsiteInfo v1.0 (Is it up to da
    te?)
    java.lang.IllegalArgumentException: The embedded resource 'config.yml' cannot be
    found in plugins\WebsiteInfoT1.jar
    at org.bukkit.plugin.java.JavaPlugin.saveResource(JavaPlugin.java:252) ~
    [craftbukkit.jar:git-Bukkit-18fbb24]
    at org.bukkit.plugin.java.JavaPlugin.saveDefaultConfig(JavaPlugin.java:2
    39) ~[craftbukkit.jar:git-Bukkit-18fbb24]
    at plugin.me.turtles.turtles.onEnable(turtles.java:22) ~[?:?]
    at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[c
    raftbukkit.jar:git-Bukkit-18fbb24]
    at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader
    .java:332) [craftbukkit.jar:git-Bukkit-18fbb24]
    at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManage
    r.java:404) [craftbukkit.jar:git-Bukkit-18fbb24]
    at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugin(CraftServer.jav
    a:342) [craftbukkit.jar:git-Bukkit-18fbb24]
    at org.bukkit.craftbukkit.v1_8_R3.CraftServer.enablePlugins(CraftServer.
    java:314) [craftbukkit.jar:git-Bukkit-18fbb24]
    at net.minecraft.server.v1_8_R3.MinecraftServer.s(MinecraftServer.java:4
    06) [craftbukkit.jar:git-Bukkit-18fbb24]
    at net.minecraft.server.v1_8_R3.MinecraftServer.k(MinecraftServer.java:3
    70) [craftbukkit.jar:git-Bukkit-18fbb24]
    at net.minecraft.server.v1_8_R3.MinecraftServer.a(MinecraftServer.java:3
    25) [craftbukkit.jar:git-Bukkit-18fbb24]
    at net.minecraft.server.v1_8_R3.DedicatedServer.init(DedicatedServer.jav
    a:235) [craftbukkit.jar:git-Bukkit-18fbb24]
    at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java
    :504) [craftbukkit.jar:git-Bukkit-18fbb24]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_71]

    Code:
    package plugin.me.turtles;
    
    import java.util.logging.Logger;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class turtles extends JavaPlugin implements Listener
    { 
        Logger myPluginLogger = Bukkit.getLogger();
     
        public void onEnable()
        {
            myPluginLogger.info(ChatColor.RED + "=====<WebSiteInfo>=====");
            myPluginLogger.warning(ChatColor.GREEN + "Enabling WebsiteInfo 1.0");
            myPluginLogger.info(ChatColor.RED + "=====<ThanksForUsing>=====");
            saveDefaultConfig();
            }
      
        public void onDisable()
        {
         
        }
     
        public boolean onCommand(CommandSender theSender, Command cmd, String commandLable, String[] args)
        {
            if(commandLable.equalsIgnoreCase("website"))
            {
                Player thePlayer = (Player)theSender;
                thePlayer.sendMessage(ChatColor.GREEN + getConfig().getString("Website"));
            } 
            return true;
        }
    }
       
    The error and code are above. When i run thats what i get and I get no folder/config at all
    heres what the folder looks like in eclipse http://imgur.com/s64aRlH


    [merged by moderator: please use the Edit button instead of double-posting] <--- If ur still here what merged? O nvm
     
    Last edited: Feb 9, 2016
  11. Offline

    TechBug2012

    java.lang.IllegalArgumentException: The embedded resource 'config.yml' cannot be
    found in plugins\WebsiteInfoT1.jar


    You created your config.yml in the wrong place. It's outside of the plugin. Delete the config.yml that you have, then right click on Name, new file, config.yml. It should be just under or just above your plugin.yml.

    Also, don't cast to (Player) on thePlayer. CommandSender is a Player type, so that (Player) argument is useless.
     
  12. Offline

    Ethan Rocks 365

    Code:
    package plugin.me.turtles;
    import java.util.logging.Logger;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;
    public class turtles extends JavaPlugin implements Listener
    {
        Logger myPluginLogger = Bukkit.getLogger();
        public void onEnable()
        {
            myPluginLogger.info(ChatColor.RED + "=====<WebSiteInfo>=====");
            myPluginLogger.warning(ChatColor.GREEN + "Enabling WebsiteInfo 1.0");
            myPluginLogger.info(ChatColor.RED + "=====<ThanksForUsing>=====");
            saveDefaultConfig();
            }
        public void onDisable()
        {
       
        }
        public boolean onCommand(CommandSender theSender, Command cmd, String commandLable, String[] args)
        {
            if(commandLable.equalsIgnoreCase("website"))
            {
                Player thePlayer = (Player)theSender;
                thePlayer.sendMessage(ChatColor.GREEN + getConfig().getString("Website"));
            }
            return true;
        }
    }
    The config loaded and worked properly. However when i did /website now it came out as null.
    error (open)

    [18:46:27] [Server thread/INFO]: Ethan_Pszanowski issued server command: /website
    [18:46:27] [Server thread/ERROR]: Cannot load plugins\WebsiteInfo\config.yml
    org.bukkit.configuration.InvalidConfigurationException: expected '<document start>', but found BlockMappingStart
    in 'string', line 4, column 1:
    Website: 'http://www.example.com'
    ^

    at org.bukkit.configuration.file.YamlConfiguration.loadFromString(YamlConfiguration.java:57) ~[craftbukkit.jar:git-Bukkit-18fbb24]
    at org.bukkit.configuration.file.FileConfiguration.load(FileConfiguration.java:226) ~[craftbukkit.jar:git-Bukkit-18fbb24]
    at org.bukkit.configuration.file.FileConfiguration.load(FileConfiguration.java:169) ~[craftbukkit.jar:git-Bukkit-18fbb24]
    at org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(YamlConfiguration.java:180) [craftbukkit.jar:git-Bukkit-18fbb24]
    at org.bukkit.plugin.java.JavaPlugin.reloadConfig(JavaPlugin.java:188) [craftbukkit.jar:git-Bukkit-18fbb24]
    at org.bukkit.plugin.java.JavaPlugin.getConfig(JavaPlugin.java:162) [craftbukkit.jar:git-Bukkit-18fbb24]
    at plugin.me.turtles.turtles.onCommand(turtles.java:35) [WebsiteInfoT1.jar:?]
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) [craftbukkit.jar:git-Bukkit-18fbb24]
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:140) [craftbukkit.jar:git-Bukkit-18fbb24]
    at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:620) [craftbukkit.jar:git-Bukkit-18fbb24]
    at net.minecraft.server.v1_8_R3.PlayerConnection.handleCommand(PlayerConnection.java:1106) [craftbukkit.jar:git-Bukkit-18fbb24]
    at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:966) [craftbukkit.jar:git-Bukkit-18fbb24]
    at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(SourceFile:37) [craftbukkit.jar:git-Bukkit-18fbb24]
    at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(SourceFile:9) [craftbukkit.jar:git-Bukkit-18fbb24]
    at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [craftbukkit.jar:git-Bukkit-18fbb24]
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_71]
    at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_71]
    at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [craftbukkit.jar:git-Bukkit-18fbb24]
    at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:673) [craftbukkit.jar:git-Bukkit-18fbb24]
    at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:335) [craftbukkit.jar:git-Bukkit-18fbb24]
    at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:629) [craftbukkit.jar:git-Bukkit-18fbb24]
    at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:537) [craftbukkit.jar:git-Bukkit-18fbb24]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_71]
    Caused by: org.yaml.snakeyaml.parser.ParserException: expected '<document start>', but found BlockMappingStart
    in 'string', line 4, column 1:
    Website: 'http://www.example.com'
    ^

    at org.yaml.snakeyaml.parser.ParserImpl$ParseDocumentStart.produce(ParserImpl.java:225) ~[craftbukkit.jar:git-Bukkit-18fbb24]
    at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:158) ~[craftbukkit.jar:git-Bukkit-18fbb24]
    at org.yaml.snakeyaml.parser.ParserImpl.checkEvent(ParserImpl.java:143) ~[craftbukkit.jar:git-Bukkit-18fbb24]
    at org.yaml.snakeyaml.composer.Composer.getSingleNode(Composer.java:108) ~[craftbukkit.jar:git-Bukkit-18fbb24]
    at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:120) ~[craftbukkit.jar:git-Bukkit-18fbb24]
    at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:450) ~[craftbukkit.jar:git-Bukkit-18fbb24]
    at org.yaml.snakeyaml.Yaml.load(Yaml.java:369) ~[craftbukkit.jar:git-Bukkit-18fbb24]
    at org.bukkit.configuration.file.YamlConfiguration.loadFromString(YamlConfiguration.java:55) ~[craftbukkit.jar:git-Bukkit-18fbb24]
    ... 22 more
    [18:46:27] [Server thread/ERROR]: [WebsiteInfo] Cannot load configuration from jar
    org.bukkit.configuration.InvalidConfigurationException: expected '<document start>', but found BlockMappingStart
    in 'string', line 4, column 1:
    Website: 'http://www.example.com'
    ^

    at org.bukkit.configuration.file.YamlConfiguration.loadFromString(YamlConfiguration.java:57) ~[craftbukkit.jar:git-Bukkit-18fbb24]
    at org.bukkit.plugin.java.JavaPlugin.reloadConfig(JavaPlugin.java:214) [craftbukkit.jar:git-Bukkit-18fbb24]
    at org.bukkit.plugin.java.JavaPlugin.getConfig(JavaPlugin.java:162) [craftbukkit.jar:git-Bukkit-18fbb24]
    at plugin.me.turtles.turtles.onCommand(turtles.java:35) [WebsiteInfoT1.jar:?]
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) [craftbukkit.jar:git-Bukkit-18fbb24]
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:140) [craftbukkit.jar:git-Bukkit-18fbb24]
    at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:620) [craftbukkit.jar:git-Bukkit-18fbb24]
    at net.minecraft.server.v1_8_R3.PlayerConnection.handleCommand(PlayerConnection.java:1106) [craftbukkit.jar:git-Bukkit-18fbb24]
    at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:966) [craftbukkit.jar:git-Bukkit-18fbb24]
    at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(SourceFile:37) [craftbukkit.jar:git-Bukkit-18fbb24]
    at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(SourceFile:9) [craftbukkit.jar:git-Bukkit-18fbb24]
    at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [craftbukkit.jar:git-Bukkit-18fbb24]
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_71]
    at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_71]
    at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [craftbukkit.jar:git-Bukkit-18fbb24]
    at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:673) [craftbukkit.jar:git-Bukkit-18fbb24]
    at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:335) [craftbukkit.jar:git-Bukkit-18fbb24]
    at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:629) [craftbukkit.jar:git-Bukkit-18fbb24]
    at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:537) [craftbukkit.jar:git-Bukkit-18fbb24]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_71]
    Caused by: org.yaml.snakeyaml.parser.ParserException: expected '<document start>', but found BlockMappingStart
    in 'string', line 4, column 1:
    Website: 'http://www.example.com'
    ^

    at org.yaml.snakeyaml.parser.ParserImpl$ParseDocumentStart.produce(ParserImpl.java:225) ~[craftbukkit.jar:git-Bukkit-18fbb24]
    at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:158) ~[craftbukkit.jar:git-Bukkit-18fbb24]
    at org.yaml.snakeyaml.parser.ParserImpl.checkEvent(ParserImpl.java:143) ~[craftbukkit.jar:git-Bukkit-18fbb24]
    at org.yaml.snakeyaml.composer.Composer.getSingleNode(Composer.java:108) ~[craftbukkit.jar:git-Bukkit-18fbb24]
    at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:120) ~[craftbukkit.jar:git-Bukkit-18fbb24]
    at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:450) ~[craftbukkit.jar:git-Bukkit-18fbb24]
    at org.yaml.snakeyaml.Yaml.load(Yaml.java:369) ~[craftbukkit.jar:git-Bukkit-18fbb24]
    at org.bukkit.configuration.file.YamlConfiguration.loadFromString(YamlConfiguration.java:55) ~[craftbukkit.jar:git-Bukkit-18fbb24]
    ... 19 more

     
    Last edited: Feb 9, 2016
  13. Offline

    TechBug2012

    @Ethan Rocks 365 you copied your class as your error :p

    EDIT: nevermind, you fixed it. "Website" in the config is spelled with a capital W. Java is case-sensitive. You need to either change it to a lowercase w in the config or a capital W in your code.
     
    boomboompower likes this.
  14. Offline

    Ethan Rocks 365

    I changed it in the code and got the same error
    So I changed it in the config. Still got the error
     
    Last edited: Feb 9, 2016
  15. Offline

    TechBug2012

    @Ethan Rocks 365 they have to match. Did you also change it in the line thePlayer.sendMessage? Can I see your updated code?
     
  16. Offline

    Ethan Rocks 365

    Code:
    package plugin.me.turtles;
    
    import java.util.logging.Logger;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class turtles extends JavaPlugin implements Listener
    {   
        Logger myPluginLogger = Bukkit.getLogger();
       
        public void onEnable()
        {
            myPluginLogger.info(ChatColor.RED + "=====<WebSiteInfo>=====");
            myPluginLogger.warning(ChatColor.GREEN + "Enabling WebsiteInfo 1.0");
            myPluginLogger.info(ChatColor.RED + "=====<ThanksForUsing>=====");
            saveDefaultConfig();
            }
        
        public void onDisable()
        {
           
        }
       
        public boolean onCommand(CommandSender theSender, Command cmd, String commandLable, String[] args)
        {
            if(commandLable.equalsIgnoreCase("website"))
            {
                Player thePlayer = (Player)theSender;
                thePlayer.sendMessage(ChatColor.RED + ("Our website is") + ChatColor.GREEN + getConfig().getString("Website"));
            }   
            return true;
        }
    }
    Udated config (open)

    This is The config for webinfo v1.0 by EthanRocks365!

    #Put what you want to display when /website is exicuted inside 'these'
    website: 'http://www.example.com'

    That is all for now more comming soon in v1.1


    I gtg for right now but if you can add me on skype or just keep checking back till i mark this solved

    I can still messages but thats my last code sending/updating till tomarrow EDIT: sooooorrrrrryyyyyyy for double post I truly am but I'm tired and frustrated right now
     
    Last edited by a moderator: Feb 10, 2016
  17. Offline

    boomboompower

  18. Offline

    JoaoBM

  19. Offline

    Ethan Rocks 365

    With this exact code its saying
    our website isnull <-- ingame message received after executing /website as a player
    Code:
    package plugin.me.turtles;
    
    import java.util.logging.Logger;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class turtles extends JavaPlugin implements Listener
    {    
        Logger myPluginLogger = Bukkit.getLogger();
        
        public void onEnable()
        {
            myPluginLogger.info(ChatColor.RED + "=====<WebSiteInfo>=====");
            myPluginLogger.warning(ChatColor.GREEN + "Enabling WebsiteInfo 1.0");
            myPluginLogger.info(ChatColor.RED + "=====<ThanksForUsing>=====");
            saveDefaultConfig();
            }
         
        public void onDisable()
        {
            
        }
        
        public boolean onCommand(CommandSender theSender, Command cmd, String commandLable, String[] args)
        {
            if(commandLable.equalsIgnoreCase("website"))
            {
                Player thePlayer = (Player)theSender;
                thePlayer.sendMessage(ChatColor.RED + ("Our website is") + ChatColor.GREEN + getConfig().getString("website"));
            }    
            return true;

    config--> http://pastebin.com/dM2931nh
     
  20. Offline

    mcdorli

    If you write abything other than value declarations inside a co fig, then put a # before it

    Also, what's the name of the config?
     
  21. Offline

    Ethan Rocks 365

    The name of the config is well config

    NVM! I got it to work.
    @Xerox262 @teej107 @TechBug2012 @boomboompower @JoaoBM @mcdorli Thanks for all the help! Turns out I for got some #s in the config.yml :p #FAIL Thanks again

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 10, 2016
Thread Status:
Not open for further replies.

Share This Page