problem with my plugin

Discussion in 'Plugin Development' started by matter123, Jan 29, 2011.

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

    matter123

    this is my first plugin it compiled without errors but when i test it with craftbukkit 166 i get this error
    Code:
    2011-01-29 10:58:16 [INFO] Starting minecraft server version Beta 1.2_01
    2011-01-29 10:58:16 [INFO] Loading properties
    2011-01-29 10:58:16 [INFO] Starting Minecraft server on *:25565
    2011-01-29 10:58:16 [INFO] Preparing level "world"
    2011-01-29 10:58:16 [INFO] Preparing start region
    Preparing spawn area: 28%
    Preparing spawn area: 61%
    Preparing spawn area: 77%
    Jan 29, 2011 10:58:20 AM org.bukkit.craftbukkit.CraftServer loadPlugins
    SEVERE: while scanning a simple key; could not found expected ':' (Is it up to d
    ate?)
    while scanning a simple key
     in "<reader>", line 3, column 1:
        version 1.00
        ^
    could not found expected ':'
     in "<reader>", line 3, column 13:
    
        ^
    
            at org.yaml.snakeyaml.scanner.ScannerImpl.removePossibleSimpleKey(ScannerImpl.java:456)
            at org.yaml.snakeyaml.scanner.ScannerImpl.fetchStreamEnd(ScannerImpl.java:521)
            at org.yaml.snakeyaml.scanner.ScannerImpl.fetchMoreTokens(ScannerImpl.java:248)
            at org.yaml.snakeyaml.scanner.ScannerImpl.checkToken(ScannerImpl.java:183)
            at org.yaml.snakeyaml.parser.ParserImpl$ParseBlockMappingKey.produce(ParserImpl.java:564)
            at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:163)
            at org.yaml.snakeyaml.parser.ParserImpl.checkEvent(ParserImpl.java:148)
            at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java:228)
            at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:160)
            at org.yaml.snakeyaml.composer.Composer.composeDocument(Composer.java:122)
            at org.yaml.snakeyaml.composer.Composer.getSingleNode(Composer.java:105)
    
            at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:124)
            at org.yaml.snakeyaml.Yaml.load(Yaml.java:264)
            at org.yaml.snakeyaml.Yaml.load(Yaml.java:250)
            at org.bukkit.plugin.PluginDescriptionFile.<init>(PluginDescriptionFile.java:29)
            at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:68)
            at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:117)
            at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:82)
            at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:43)
            at net.minecraft.server.MinecraftServer.e(MinecraftServer.java:153)
            at net.minecraft.server.MinecraftServer.c(MinecraftServer.java:140)
            at net.minecraft.server.MinecraftServer.d(MinecraftServer.java:104)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:181)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:512)
    2011-01-29 10:58:20 [INFO] Done! For help, type "help" or "?"
    what did i do wrong?
     

    Attached Files:

    • src.zip
      File size:
      2.5 KB
      Views:
      7
  2. Offline

    void420

    You need a plugin.yml file in your /src folder.
     
  3. Offline

    eisental


    should be version: 1.00
     
  4. Offline

    matter123

    oh i forgot the plugin.yml in the /src folder it was in the .jar though(note plugin.txt is the same as my plugin.yml renamed for easy uplading)
     

    Attached Files:

  5. Offline

    Mixcoatl

    You're missing a colon in the last key-value pair.
     
  6. Offline

    matter123

    oh thank you
    --- merged: Jan 30, 2011 9:13 PM ---
    ok now it loads without errors but when i test it it bugs out the command i used was /fm.test.test
    Code:
    C:\Documents and Settings\admin-matthew\Desktop\minecraft server>java -Xms512M -
    Xmx1024M -jar bukkit.jar
    2011-01-30 13:09:32 [INFO] Starting minecraft server version Beta 1.2_01
    2011-01-30 13:09:32 [INFO] Loading properties
    2011-01-30 13:09:32 [INFO] Starting Minecraft server on *:25565
    2011-01-30 13:09:32 [INFO] Preparing level "world"
    2011-01-30 13:09:32 [INFO] Preparing start region
    Preparing spawn area: 24%
    Preparing spawn area: 40%
    Preparing spawn area: 61%
    Preparing spawn area: 73%
    Preparing spawn area: 81%
    Preparing spawn area: 97%
    FakeMessage version 1.0 is enabled!
    2011-01-30 13:09:38 [INFO] Done! For help, type "help" or "?"
    138 recipes
    2011-01-30 13:10:01 [INFO] matter123 [/127.0.0.1:3159] logged in with entity id
    115
    Player count: 1
    Jan 30, 2011 1:10:12 PM org.bukkit.plugin.SimplePluginManager callEvent
    SEVERE: Could not pass event PLAYER_COMMAND to FakeMessage
    java.lang.ArrayIndexOutOfBoundsException: 0
            at com.bukkit.matt123.fakemessage.FmPlayerListener.onPlayerCommand(FmPla
    yerListener.java:23)
            at org.bukkit.plugin.java.JavaPluginLoader.callEvent(JavaPluginLoader.ja
    va:138)
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:216)
            at net.minecraft.server.NetServerHandler.c(NetServerHandler.java:554)
            at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:528)
            at net.minecraft.server.Packet3Chat.a(SourceFile:24)
            at net.minecraft.server.NetworkManager.a(SourceFile:232)
            at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:65)
            at net.minecraft.server.NetworkListenThread.a(SourceFile:104)
            at net.minecraft.server.MinecraftServer.h(MinecraftServer.java:265)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:201)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:512)
    2011-01-30 13:10:12 [INFO] matter123 issued server command: fm.test.test
    2011-01-30 13:10:12 [INFO] Unknown console command. Type "help" for help.
     
  7. Offline

    Mixcoatl

    Let's look at the exception:
    Code:
    java.lang.ArrayIndexOutOfBoundsException: 0
            at com.bukkit.matt123.fakemessage.FmPlayerListener.onPlayerCommand(FmPlayerListener.java:23)
    This means that you attempted to access the first element of an array that contained no elements. We know the array contained no elements because the ArrayIndexOutOfBoundsException reports that index 0 was out of bounds.

    Let's look at the code in FmPlayerListener:
    Code:
    String[] split = event.getMessage().split(".");
    Player player =event.getPlayer();
    if (split[0].equalsIgnoreCase("/fm")) { // <-- Line #23
        player.setDisplayName(split[1]);
        event.setPlayer(player);
        event.setMessage(split[2]);
    }
    Based upon the exception and the code at line 23 we must assert that the message contained no characters. We know this because the one-argument split method excludes trailing empty strings from the result. You can read this for yourself here: http://download.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#split(java.lang.String)

    I would suggest changing your code to something like the following:
    Code:
    public void onPlayerCommand(PlayerChatEvent event) {
        final String[] split = event.getMessage().split(".");
        final Player player = event.getPlayer();
        // The length needs to be one more than the
        // highest index into the array you need to
        // access.  Since you use index 0, 1, and 2, you
        // must make certain length is at least 3.
        if (split.length >= 3 && split[0].equalsIgnoreCase("/fm")) {
            player.setDisplayName(split[1]);
            event.setPlayer(player); // Not sure what this will do.
            event.setMessage(split[2]); // Not sure what this will do either.
        }
    }
     
Thread Status:
Not open for further replies.

Share This Page