that one last error you hate...

Discussion in 'Plugin Development' started by fury, Oct 21, 2011.

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

    fury

    I got one last error with my coding:
    Code:java
    1.  
    2.  
    3. package me.fury.plugin
    4.  
    5. import java.util.logging.Logger;
    6.  
    7. import org.bukkit.command.Command;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.configuration.file.FileConfiguration;
    10. import org.bukkit.entity.Player;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12.  
    13.  
    14. public class plugin extends JavaPlugin {
    15. protected static FileConfiguration CONFIG;
    16.  
    17. Logger log = Logger.getLogger("Minecraft");
    18.  
    19. public void onEnable() {
    20. CONFIG = getConfig();
    21. CONFIG.set("your boolean property", true);
    22. CONFIG.set("your string property, "yes"");
    23. CONFIG.set("your int property", 22);
    24.  
    25. boolean bProp = CONFIG.getBoolean("your boolean property", false);
    26. String sProp = CONFIG.getString("your string property", "no");
    27. int iProp = CONFIG.getInt("your int property", 0);
    28.  
    29. log.info("Your plugin has been enabled.");
    30.  
    31. }
    32.  
    33. public void onDisable() {
    34.  
    35. log.info("Your plugin has been disabled.");
    36.  
    37. }
    38. }
    39.  
    40. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    41. if(cmd.getName().equalsIgnoreCase("ignite")){
    42. Player s = (Player)sender;
    43. Player target = s.getWorld().getPlayer(args[0]);
    44. target.setFireTicks(100);
    45. return true;
    46. }
    47. return false;
    48. }
    49. [syntax]
    50. and i'm getting this error:
    51. [syntax=java]
    52. 2011-10-21 22:19:52 [INFO] Starting minecraft server version Beta 1.8.1
    53. 2011-10-21 22:19:52 [INFO] Loading properties
    54. 2011-10-21 22:19:52 [INFO] Starting Minecraft server on *:25565
    55. 2011-10-21 22:19:52 [INFO] This server is running Craftbukkit version git-Bukkit-0.0.0-1131-g86b7fa8-b1337jnks (MC: 1.8.1)
    56. 2011-10-21 22:19:52 [SEVERE] Could not load 'plugins\My First Plugin.jar' in folder 'plugins':
    57. while scanning for the next token
    58. found character '\t' that cannot start any token
    59. in "<reader>", line 37, column 1:
    60. ^
    61.  
    62. at org.yaml.snakeyaml.scanner.ScannerImpl.fetchMoreTokens(ScannerImpl.java:358)
    63. at org.yaml.snakeyaml.scanner.ScannerImpl.peekToken(ScannerImpl.java:202)
    64. at org.yaml.snakeyaml.parser.ParserImpl$ParseDocumentEnd.produce(ParserImpl.java:265)
    65. at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:161)
    66. at org.yaml.snakeyaml.parser.ParserImpl.getEvent(ParserImpl.java:171)
    67. at org.yaml.snakeyaml.composer.Composer.composeDocument(Composer.java:125)
    68. at org.yaml.snakeyaml.composer.Composer.getSingleNode(Composer.java:106)
    69. at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:121)
    70. at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:480)
    71. at org.yaml.snakeyaml.Yaml.load(Yaml.java:411)
    72. at org.bukkit.plugin.PluginDescriptionFile.<init>(PluginDescriptionFile.java:36)
    73. at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:71)
    74. at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:215)
    75. at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:136)
    76. at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:136)
    77. at org.bukkit.craftbukkit.CraftServer.<init>(CraftServer.java:112)
    78. at net.minecraft.server.ServerConfigurationManager.<init>(ServerConfigurationManager.java:52)
    79. at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:136)
    80. at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:348)
    81. at net.minecraft.server.ThreadServerApplication.run(SourceFile:417)
    82. [syntax]
    83. it still starts the server,though. it seems it wants to load my plugin beofre anything else, sence this is the first thing that pops up. If I remove the tab, and try to fix it, it errors out even worse, and it won't start the server at all. i've been at this error for three days, and just can't figure it out!:mad:[/syntax]
     
  2. Offline

    Sagacious_Zed Bukkit Docs

    @fury
    run your plugin.yml through a validator. You have an extra tab in there.

    and bad use of static. you get a frowny face :(

    EDIT:
    and with a quick glance of your code, you can't actually change the default values if your yaml, and have then effect the setting of your plugins.
     
  3. Offline

    thehutch

    also you have set up your configuration wrong change CONFIG.set(); to CONFIG.addDefault and then at the end of your onEnable add this:
    Code:
    CONFIG.options().copyDefaults(true);
    saveConfig();
     
  4. Offline

    fury

    what validator do I use? how do I use a validator?
     
  5. Offline

    Sagacious_Zed Bukkit Docs

  6. Offline

    fury

    I did, fixed all errors, and finally it came out with this(and it won't even start the server):
    Code:
    2011-10-22 19:28:09 [INFO] Starting minecraft server version Beta 1.8.1
    2011-10-22 19:28:09 [INFO] Loading properties
    2011-10-22 19:28:09 [INFO] Starting Minecraft server on *:25565
    2011-10-22 19:28:09 [INFO] This server is running Craftbukkit version git-Bukkit-0.0.0-1131-g86b7fa8-b1337jnks (MC: 1.8.1)
    2011-10-22 19:28:09 [SEVERE] java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Map
    2011-10-22 19:28:09 [SEVERE] 	at org.bukkit.plugin.PluginDescriptionFile.<init>(PluginDescriptionFile.java:36)
    2011-10-22 19:28:09 [SEVERE] 	at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:71)
    2011-10-22 19:28:09 [SEVERE] 	at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:215)
    2011-10-22 19:28:09 [SEVERE] 	at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:136)
    2011-10-22 19:28:09 [SEVERE] 	at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:136)
    2011-10-22 19:28:09 [SEVERE] 	at org.bukkit.craftbukkit.CraftServer.<init>(CraftServer.java:112)
    2011-10-22 19:28:09 [SEVERE] 	at net.minecraft.server.ServerConfigurationManager.<init>(ServerConfigurationManager.java:52)
    2011-10-22 19:28:09 [SEVERE] 	at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:136)
    2011-10-22 19:28:09 [SEVERE] 	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:348)
    2011-10-22 19:28:09 [SEVERE] 	at net.minecraft.server.ThreadServerApplication.run(SourceFile:417)
    2011-10-22 19:28:09 [SEVERE] Unexpected exception
    java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Map
    	at org.bukkit.plugin.PluginDescriptionFile.<init>(PluginDescriptionFile.java:36)
    	at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:71)
    	at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:215)
    	at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:136)
    	at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:136)
    	at org.bukkit.craftbukkit.CraftServer.<init>(CraftServer.java:112)
    	at net.minecraft.server.ServerConfigurationManager.<init>(ServerConfigurationManager.java:52)
    	at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:136)
    	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:348)
    	at net.minecraft.server.ThreadServerApplication.run(SourceFile:417)
    
     
  7. Offline

    Sagacious_Zed Bukkit Docs

    @fury
    your plugin.yml is still wrong. might be valid yaml, but wrong.
     
  8. Offline

    Rahazan

    Well ehm, look at the quotation marks on the second one :<.
     
  9. Offline

    thehutch

    Yh tht might be an error but there is still a problem with your plugin.yml and also he might have changed this because I told him to add config.addDefault()
     
  10. Offline

    Rahazan

    Alright, I would suggest you simply abide by this:

    You simply add a config.yml to your src folder like you have already added the plugin.yml file.
    In this file, you enter the defaults. Remember not to use spaces!

    Put this in your onEnable() method.
    Code:
            getConfig().options().copyDefaults(true);
            getConfig().options().header(
                    "This is how to configure this file:" +
    "bla bla bla bla");
            saveConfig();
    
    To read something from the config.yml use this code.
    Code:
    String sProp = getConfig().getString("your.string.property", "This is a string.")
    Note that the above code will default to "This is a string.". You do not need to have this part after the comma. Oh, and I would never put spaces in these nodes. This -may- be the cause of the error (anyone confirm?).

    If you wish to set a string, you would use this code for example.
    Code:
    getConfig().setString("your.string.property", "This is another string.")
     
  11. Offline

    fury

    how would I do this? I started this project like two weeks ago and I forgot. ^.^

    uuhhh yeah by thee looks of it my code is wrong. somehow.

    *UPDATE*
    so, i have added most of what you guys have said(leaving out what I don't understand), and this is my current source code:
    Code:java
    1.  
    2.  
    3. package me.fury.plugin
    4.  
    5. import java.util.logging.Logger;
    6.  
    7. import org.bukkit.command.Command;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.configuration.file.FileConfiguration;
    10. import org.bukkit.entity.Player;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12.  
    13.  
    14. public class plugin extends JavaPlugin {
    15. protected static FileConfiguration CONFIG;
    16.  
    17. Logger log = Logger.getLogger("Minecraft");
    18.  
    19. public void onEnable() {
    20. CONFIG.addDefault
    21. CONFIG.set("your boolean property", true);
    22. CONFIG.set("your string property", "yes");
    23. CONFIG.set("your int property", 22);
    24.  
    25. boolean bProp = CONFIG.getBoolean("your boolean property", false);
    26. String sProp = CONFIG.getString("your string property", "no");
    27. int iProp = CONFIG.getInt("your int property", 0);
    28. CONFIG.options().copyDefaults(true);
    29. saveConfig();
    30. getConfig().options().copyDefaults(true);
    31. getConfig().options().header("This is how to configure this file:" + "bla bla bla bla");
    32. saveConfig();
    33.  
    34. log.info("Your plugin has been enabled.");
    35.  
    36. }
    37.  
    38. public void onDisable() {
    39.  
    40. log.info("Your plugin has been disabled.");
    41.  
    42. }
    43. }
    44.  
    45. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    46. if(cmd.getName().equalsIgnoreCase("ignite")){
    47. Player s = (Player)sender;
    48. Player target = s.getWorld().getPlayer(args[0]);
    49. target.setFireTicks(100);
    50. return true;
    51. }
    52. return false;
    53. }
    54. [syntax]
    55.  
    56. EDIT by Moderator: merged posts, please use the edit button instead of double posting.[/syntax]
     
    Last edited by a moderator: May 20, 2016
  12. Offline

    Evangon

    :3
    I can't belive anyone didn't think of this:
    YML's can't use tab's. You have to use spaces manually.
     
  13. Offline

    fury

    I did. I kept getting a ton of errors saying that a /t cannot be used to start a token, so I deleted all of my tabs, and replaced them with four spaces.
     
  14. Offline

    thehutch

    also use config.addDefault not config.set otherwise it will overwrite oyur config when you reload it
     
  15. Offline

    Evangon

    /t is tab :confused:
     
  16. Offline

    Rahazan

    Remove these lines and read my above post again. If you wish to add config.yml to your src folder, right click the src folder in eclipse. Click New -> File. And enter config.yml

    In there, you put these lines
    your boolean property: true
    your string property: yes
    your int propery: 22

    I would never put spaces in these, so I would make it. I am not sure if this matters
    YourBooleanProperty: true
    YourStringProperty: yes
    YourIntPropery: 22


    Oh, and remove this line too!
    protected static FileConfiguration CONFIG;

    There is no such thing anymore. It was changed when Craftbukkit 1317 was released (Are you sure you have the latest libraries referenced?) If not, re-download and add.
     
  17. Offline

    thehutch

    Your last comment shocks me as to why you think that was the old config? That is the new config FIleConfiguration is basically the same as YamlConfiguration not much diffence atleast not that I know... So yes it would work although yes he doesnt need the protected static on it.
    Also it doenst matter if you put spaces in the string values therefore both versions were correct.

    Oh and I forgot the add that you really shouldnt create the config.yml in your src folder its bad practice. You should do what I said and it will automatically generate the config with them config values and in order so no need to pre-make one.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 20, 2016
  18. Offline

    Rahazan

    It was suggested by Dinnerbone..

     
  19. Offline

    fury

    eh, OK, I deleted ALL my cofig file stuff for this plugin, because it just sets people on fire. Maybe i will work with a config file later. Anyway, here's what I have now:
    Code:
    
    package me.fury.plugin
    
    import java.util.logging.Logger;
    
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    
    
    public class plugin extends JavaPlugin {
    
        Logger log = Logger.getLogger("Minecraft");
    
        public void onEnable() {
    
        log.info("Your plugin has been enabled.");
    
        }
    
        public void onDisable() {
    
            log.info("Your plugin has been disabled.");
    
        }
    }
    
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
        if(cmd.getName().equalsIgnoreCase("ignite")){
            Player s = (Player)sender;
            Player target = s.getWorld().getPlayer(args[0]);
            target.setFireTicks(100);
            return true;
        }
        return false;
    }
    
    oh crap I forgot to do that when I updated to 1337!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 20, 2016
  20. That will give an error if there sender only types /ignite or if the sender is a console
    Change onCommand to:
    Code:java
    1.  
    2. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    3. if(cmd.getName().equalsIgnoreCase("ignite")){
    4. if (args.length == 0) {
    5. if (sender instanceof Player) {
    6. Player s = (Player)sender;
    7. Player target = s.getWorld().getPlayer(args[0]);
    8. target.setFireTicks(100);
    9. return true;
    10. } else {
    11. sender.sendMessage(ChatColor.RED + "You must be a player");
    12. }
    13. } else {
    14. sender.sendMessage(ChatColor.RED + "Not enough arguments!");
    15. }
    16. }
    17. return false;
    18. }
    19.  
     
  21. Offline

    fury

    ok, now my plugin.yml file looks like this:
    Code:
    
    package me.fury.plugin
    
    import java.util.logging.Logger;
    
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    
    
    public class plugin extends JavaPlugin {
    
        Logger log = Logger.getLogger("Minecraft");
    
        public void onEnable() {
    
        log.info("Your plugin has been enabled.");
    
        }
    
        public void onDisable() {
    
            log.info("Your plugin has been disabled.");
    
        }
    }
    
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
        if(cmd.getName().equalsIgnoreCase("ignite")){
            if (args.length == 0) {
            if (sender instanceof Player) {
            Player s = (Player)sender;
            Player target = s.getWorld().getPlayer(args[0]);
            target.setFireTicks(100);
            return true;
            } else {
               sender.sendMessage(ChatColor.RED + "You must be a player");
            }
            } else {
               sender.sendMessage(ChatColor.RED + "Not enough arguments!");
            }
        }
        return false;
    }
    
    and it still won't work. Any thoughts?
     
  22. Offline

    AinSophAur

    First you want to change:
    Player s = this.getServer.getPlayer(sender.toString());

    then:
    Player target = this.getServer.getPlayer(args[1]);

    I'm assuming you want it to catch /ignite target rather than the person who used the command itself like it is now.

    Or if you want the person who used it to be on fire you skip that step and do s.setFireTicks(100);
     
  23. Offline

    fury

    OK, so my plugin.yml file now looks like this:
    Code:
    
    package me.fury.plugin
    
    import java.util.logging.Logger;
    
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    
    
    public class plugin extends JavaPlugin {
    
        Logger log = Logger.getLogger("Minecraft");
    
        public void onEnable() {
    
        log.info("Your plugin has been enabled.");
    
        }
    
        public void onDisable() {
    
            log.info("Your plugin has been disabled.");
    
        }
    }
    
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
        if(cmd.getName().equalsIgnoreCase("ignite")){
            if (args.length == 0) {
            if (sender instanceof Player) {
            Player s = (Player)sender;
            Player s = this.getServer.getPlayer(sender.toString());
            Player target = this.getServer.getPlayer(args[1]);
            target.setFireTicks(100);
            return true;
            } else {
               sender.sendMessage(ChatColor.RED + "You must be a player");
            }
            } else {
               sender.sendMessage(ChatColor.RED + "Not enough arguments!");
            }
        }
        return false;
    }
    
    did I impliment that right? not sure, havn't really used the args statement before. :/
     
  24. Not quite... Not sure what your trying to do, as I didn't read it. But what you say is this:
    if (commandName is "ignite") {
    if (command has no arguments) {
    Use 2nd argument
    }
    }
    The second argument doesn't exist, nor the first, as you check and see that args.length is only == 0
     
  25. Offline

    fury

    ok first of all, where did your completely awesome signature go? and secondly, what? your saying I remove the line "Use 2nd argument" (and "if(command has no arguments) { )?
     
  26. Offline

    Pinkishu

    try
    if (args.length == 1) {
    instead of
    if (args.length == 0) {
     
  27. Offline

    fury

    still didn't work, but thanks for pointing that line out to me.

    I have verified that the following code segment is making it fail. I took out the bottom part (the boolean property) to test.
    Code:java
    1.  
    2.  
    3. package me.fury.plugin
    4.  
    5. import java.util.logging.Logger;
    6.  
    7. import org.bukkit.command.Command;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.configuration.file.FileConfiguration;
    10. import org.bukkit.entity.Player;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12.  
    13.  
    14. public class plugin extends JavaPlugin {
    15.  
    16. Logger log = Logger.getLogger("Minecraft");
    17.  
    18. public void onEnable() {
    19.  
    20. log.info("Your plugin has been enabled.");
    21.  
    22. }
    23.  
    24. public void onDisable() {
    25.  
    26. log.info("Your plugin has been disabled.");
    27.  
    28. }
    29. }
    30.  


    wait....am I exporting this right? I'm only exporting ONLY exporting my src folder and my plugin.yml file. should I be exporting something with them?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 20, 2016
  28. 1)It only shows up once per page ;)
    2)@Pinkishu knows whats up :p
     
  29. Offline

    Rahazan

    Is anything of the original plugin left?
     
Thread Status:
Not open for further replies.

Share This Page