Nooby Dev

Discussion in 'Plugin Development' started by Niknea, Dec 9, 2013.

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

    Niknea

    Hey guys,

    So I'm trying to learn how to code bukkit and I made a really simple plugin, however it doesn't work :(. Can someone please look over it and tell me whats wrong, and please don't give me the answer as I want to learn. Instead tell me why its wrong if possible. Thank you guys soooo much!

    Code:
    package me.niknea.itemfinder;
     
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Event;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.PlayerInventory;
     
    public class Itemfinder {
     
    public void onPlayerJoin(PlayerJoinEvent evt) {
     
    Player player = evt.getPlayer();
     
    PlayerInventory inventory = player.getInventory();
     
    ItemStack itemstack = new ItemStack (Material.STONE, 7);{
     
    if (inventory.contains(itemstack)){
        player.sendMessage("ChatColor.GREEN Seems like you have 7 stone! Yay!");
    }
     
     
            else  {
                player.sendMessage("ChatColor.DARK RED NOO you dont have 7 stone :(");
            }
     
     
     
    }
     
    }
     
    }
     
     
     
     
     
    
     
  2. Offline

    caseif

    You can't just post a class and expect users to tell you what's wrong with it. You need to provide information as to what exactly is wrong. A few generic solutions: is the plugin properly compiled into the JAR? Is the JAR file in the proper directory? Is the plugin.yml valid and in the JAR file?
     
  3. Offline

    Compressions

    Niknea
    1. Since you are listening for an event, the class must implement Listener.
    2. Every listener method must be first prepended with an @EventHandler annotation.
    3. Not your issue, but ChatColor enums must be outside of quotes and concatenated onto the String.
     
  4. Offline

    The_Doctor_123

    Words like that concern me. Do you know Java?
     
  5. Offline

    Niknea

    Yes it's in the proper location, however in the console it gives errors
     
  6. Offline

    caseif

    Those errors being...?
     
  7. Offline

    Niknea

    Yes sir I do.

    I don't really understand #2 and how would I do #1?

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

    Compressions

    Niknea You don't really know Java, do you? Anyways, check out the Bukkit Wiki for help with Listeners.
     
  9. Offline

    Not2EXceL

    I see 5 open and 3 closing brackets. And brackets where they shouldn't be. Do you even know Java?

    And this isnt a plugin. Nor how you'd use events if this is the entirity of the plugin.
     
  10. Offline

    caseif

    To augment to what Compressions said:
    4) You're not registering your events in your onEnable() method. You actually don't even have an onEnable() method for that matter.
    5) You're not extending JavaPlugin, which will most certainly cause your plugin to fail, no questions asked.
    6) You have arbitrary brackets in your code that really shouldn't be there. It won't affect your compiled JAR afaik, but it's a bit annoying to have it in the source.
     
  11. Offline

    Niknea

    Code:
    [19:02:22 ERROR]: Could not load 'plugins\ItemFinder.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidDescriptionException: Invalid plugin.yml
            at org.bukkit.plugin.java.JavaPluginLoader.getPluginDescription(JavaPlug
    inLoader.java:247) ~[craftbukkit.jar:git-Bukkit-1.6.4-R2.0-21-gcf51e92-b2938jnks
    ]
            at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager
    .java:132) [craftbukkit.jar:git-Bukkit-1.6.4-R2.0-21-gcf51e92-b2938jnks]
            at org.bukkit.craftbukkit.v1_7_R1.CraftServer.loadPlugins(CraftServer.ja
    va:255) [craftbukkit.jar:git-Bukkit-1.6.4-R2.0-21-gcf51e92-b2938jnks]
            at org.bukkit.craftbukkit.v1_7_R1.CraftServer.<init>(CraftServer.java:23
    3) [craftbukkit.jar:git-Bukkit-1.6.4-R2.0-21-gcf51e92-b2938jnks]
            at net.minecraft.server.v1_7_R1.PlayerList.<init>(PlayerList.java:63) [c
    raftbukkit.jar:git-Bukkit-1.6.4-R2.0-21-gcf51e92-b2938jnks]
            at net.minecraft.server.v1_7_R1.DedicatedPlayerList.<init>(SourceFile:14
    ) [craftbukkit.jar:git-Bukkit-1.6.4-R2.0-21-gcf51e92-b2938jnks]
            at net.minecraft.server.v1_7_R1.DedicatedServer.init(DedicatedServer.jav
    a:126) [craftbukkit.jar:git-Bukkit-1.6.4-R2.0-21-gcf51e92-b2938jnks]
            at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java
    :420) [craftbukkit.jar:git-Bukkit-1.6.4-R2.0-21-gcf51e92-b2938jnks]
            at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:6
    17) [craftbukkit.jar:git-Bukkit-1.6.4-R2.0-21-gcf51e92-b2938jnks]
    Caused by: java.io.FileNotFoundException: Jar does not contain plugin.yml
            ... 9 more
    [19:02:22 INFO]: Preparing level "world"
    [19:02:22 INFO]: Preparing start region for level 0 (Seed: -8456812395550547487)
     
    [19:02:22 INFO]: Preparing start region for level 1 (Seed: -6328256869492003767)
     
    [19:02:23 INFO]: Preparing spawn area: 71%
    [19:02:23 INFO]: ----- Bukkit Auto Updater -----
    [19:02:23 INFO]: It appears that you're running a Development Build, when you've
    specified in bukkit.yml that you prefer to run Recommended Builds.
    [19:02:23 INFO]: If you would like to be kept informed about new Development Bui
    ld releases, it is recommended that you change 'preferred-channel' in your bukki
    t.yml to 'dev'.
    [19:02:23 INFO]: With that set, you will be told whenever a new version is avail
    able for download, so that you can always keep up to date and secure with the la
    test fixes.
    [19:02:23 INFO]: If you would like to disable this warning, simply set 'suggest-
    channels' to false in bukkit.yml.
    [19:02:23 INFO]: ----- ------------------- -----
    [19:02:24 INFO]: Preparing start region for level 2 (Seed: -6328256869492003767)
     
    [19:02:24 INFO]: Server permissions file permissions.yml is empty, ignoring it
    [19:02:24 INFO]: Done (2.281s)! For help, type "help" or "?"
    >
     
  12. Offline

    The_Doctor_123

    Niknea
    Okay then. Your words sound like you don't know what the difference between Java and a 3rd party API is.

    If you know Java, wouldn't you read the stack trace? And if you are really stumped on it, give it to us?

    EDIT: Your plugin.yml is invalid.

    EDIT #2: Ehh.. yeah, you don't even have a plugin.yml, as ShadyPotato found. :p
     
  13. Offline

    caseif

    Mother fu-
     
    Garris0n, Wolfey, Wingzzz and 4 others like this.
  14. Offline

    maxben34

    You are honestly the first "noob" to ask for an explanation and not an answer. Good job.

    Now for the help: Based off of the stack trace (the error message) you have an invalid or no plugin.yml at all. In order to help you further, please post the plugin.yml here so i can take a look at it.
     
  15. Offline

    caseif

    His plugin.yml is definitely missing; the stack trace shows a FileNotFoundException. An invalid plugin.yml would throw an InvalidConfigurationException.

    EDIT: Assuming you're exporting from Eclipse, just make sure the box next to the plugin.yml file is checked when you export.
     
  16. Offline

    maxben34

    When you make your YML a tip that i know is to actually throw it into eclipse and make it there, then you don't need to refresh the project before you export it and you dont need to make sure that it's there. (As long as you make it from the src folder).

    Niknea
     
  17. Offline

    Wolfey

    This is just too shameful to read, I'm sorry, but please learn Java before trying bukkit, and when you do learn Java, check out simple bukkit tutorials.
     
  18. Offline

    The_Doctor_123

    I have to give him credit for..

    But in the end, I have to agree with you.
     
  19. Offline

    Niknea

    maxben34 ShadyPotato The_Doctor_123

    I didn't export correct and the plugin.yml was missing, however it's exported correctly but it still doesn't work. Here is the error now.
    Code:
    [19:59:36 ERROR]: Could not load 'plugins\ItemFinder.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: java.lang.ClassNotFoundException: me.n
    iknea.ItemFinder.Itemfinder
            at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.j
    ava:184) ~[craftbukkit.jar:git-Bukkit-1.6.4-R2.0-21-gcf51e92-b2938jnks]
            at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.
    java:305) ~[craftbukkit.jar:git-Bukkit-1.6.4-R2.0-21-gcf51e92-b2938jnks]
            at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager
    .java:230) [craftbukkit.jar:git-Bukkit-1.6.4-R2.0-21-gcf51e92-b2938jnks]
            at org.bukkit.craftbukkit.v1_7_R1.CraftServer.loadPlugins(CraftServer.ja
    va:255) [craftbukkit.jar:git-Bukkit-1.6.4-R2.0-21-gcf51e92-b2938jnks]
            at org.bukkit.craftbukkit.v1_7_R1.CraftServer.<init>(CraftServer.java:23
    3) [craftbukkit.jar:git-Bukkit-1.6.4-R2.0-21-gcf51e92-b2938jnks]
            at net.minecraft.server.v1_7_R1.PlayerList.<init>(PlayerList.java:63) [c
    raftbukkit.jar:git-Bukkit-1.6.4-R2.0-21-gcf51e92-b2938jnks]
            at net.minecraft.server.v1_7_R1.DedicatedPlayerList.<init>(SourceFile:14
    ) [craftbukkit.jar:git-Bukkit-1.6.4-R2.0-21-gcf51e92-b2938jnks]
            at net.minecraft.server.v1_7_R1.DedicatedServer.init(DedicatedServer.jav
    a:126) [craftbukkit.jar:git-Bukkit-1.6.4-R2.0-21-gcf51e92-b2938jnks]
            at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java
    :420) [craftbukkit.jar:git-Bukkit-1.6.4-R2.0-21-gcf51e92-b2938jnks]
            at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:6
    17) [craftbukkit.jar:git-Bukkit-1.6.4-R2.0-21-gcf51e92-b2938jnks]
    Caused by: java.lang.ClassNotFoundException: me.niknea.ItemFinder.Itemfinder
            at java.net.URLClassLoader$1.run(Unknown Source) ~[?:1.7.0_45]
            at java.net.URLClassLoader$1.run(Unknown Source) ~[?:1.7.0_45]
            at java.security.AccessController.doPrivileged(Native Method) ~[?:1.7.0_
    45]
            at java.net.URLClassLoader.findClass(Unknown Source) ~[?:1.7.0_45]
            at org.bukkit.plugin.java.PluginClassLoader.findClass0(PluginClassLoader
    .java:80) ~[craftbukkit.jar:git-Bukkit-1.6.4-R2.0-21-gcf51e92-b2938jnks]
            at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.
    java:53) ~[craftbukkit.jar:git-Bukkit-1.6.4-R2.0-21-gcf51e92-b2938jnks]
            at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.7.0_45]
            at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.7.0_45]
            at java.lang.Class.forName0(Native Method) ~[?:1.7.0_45]
            at java.lang.Class.forName(Unknown Source) ~[?:1.7.0_45]
            at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.j
    ava:173) ~[craftbukkit.jar:git-Bukkit-1.6.4-R2.0-21-gcf51e92-b2938jnks]
            ... 9 more
    
    Thanks again for taking the time to help me :)
     
  20. Offline

    The_Doctor_123

    Niknea
    Code:java
    1. org.bukkit.plugin.InvalidPluginException: java.lang.ClassNotFoundException: me.n
    2. iknea.ItemFinder.Itemfinder

    Java is case sensitive.
     
  21. Offline

    Garris0n

    Your package is "me.niknea.itemfinder.ItemFinder", however you put "me.niknea.ItemFinder.ItemFinder" in your plugin.yml. Fix the casing.

    Edit: And I got ninja'd by good ol' doc.
     
  22. Offline

    The_Doctor_123

    Without fail. :D
     
    Dr_Bunsen likes this.
  23. Offline

    Niknea

    Garris0n@The_Doctor_123
    Alright I fixed it however it still doesn't seem to work
    Code:
    [20:16:25 ERROR]: Could not load 'plugins\ItemFinder.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: java.lang.ClassCastException: class me
    .niknea.itemfinder.Itemfinder
            at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.j
    ava:184) ~[craftbukkit.jar:git-Bukkit-1.6.4-R2.0-21-gcf51e92-b2938jnks]
            at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.
    java:305) ~[craftbukkit.jar:git-Bukkit-1.6.4-R2.0-21-gcf51e92-b2938jnks]
            at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager
    .java:230) [craftbukkit.jar:git-Bukkit-1.6.4-R2.0-21-gcf51e92-b2938jnks]
            at org.bukkit.craftbukkit.v1_7_R1.CraftServer.loadPlugins(CraftServer.ja
    va:255) [craftbukkit.jar:git-Bukkit-1.6.4-R2.0-21-gcf51e92-b2938jnks]
            at org.bukkit.craftbukkit.v1_7_R1.CraftServer.<init>(CraftServer.java:23
    3) [craftbukkit.jar:git-Bukkit-1.6.4-R2.0-21-gcf51e92-b2938jnks]
            at net.minecraft.server.v1_7_R1.PlayerList.<init>(PlayerList.java:63) [c
    raftbukkit.jar:git-Bukkit-1.6.4-R2.0-21-gcf51e92-b2938jnks]
            at net.minecraft.server.v1_7_R1.DedicatedPlayerList.<init>(SourceFile:14
    ) [craftbukkit.jar:git-Bukkit-1.6.4-R2.0-21-gcf51e92-b2938jnks]
            at net.minecraft.server.v1_7_R1.DedicatedServer.init(DedicatedServer.jav
    a:126) [craftbukkit.jar:git-Bukkit-1.6.4-R2.0-21-gcf51e92-b2938jnks]
            at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java
    :420) [craftbukkit.jar:git-Bukkit-1.6.4-R2.0-21-gcf51e92-b2938jnks]
            at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:6
    17) [craftbukkit.jar:git-Bukkit-1.6.4-R2.0-21-gcf51e92-b2938jnks]
    Caused by: java.lang.ClassCastException: class me.niknea.itemfinder.Itemfinder
            at java.lang.Class.asSubclass(Unknown Source) ~[?:1.7.0_45]
            at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.j
    ava:174) ~[craftbukkit.jar:git-Bukkit-1.6.4-R2.0-21-gcf51e92-b2938jnks]
            ... 9 more
    
    Also I know how frustrating it must be for you guys trying to explain how to fix such a nooby thing to me, and I am really sorry for that.
     
  24. Offline

    Garris0n

  25. Offline

    Not2EXceL

    Niknea The solutions are in all the previous posts. If you seriously can't find it. Leave these forums, go to oracle's tuts or some youtube series and learn java. Then read bukkit's tutorial on plugins. Then if you have issues you can post them.

    I refuse to help now since you don't even put the effort to learn or figure things out yourself.
     
  26. Offline

    Wolfey

    Once he extends to JavaPlugin, he shouldn't have any more problems with loading in the plugin. I'm sure he learned a ton from this.
     
    Niknea likes this.
  27. Offline

    Not2EXceL

    No but you don't learn anything from people teaching something as simple as this. You have to put effort into solving problems, and then ask for help. He attempted to make a bukkit plugin but didnt include the most essential part? And cant google Bukkit tutorial plugin
     
  28. Offline

    Wolfey

    When I started out and made multiple packages, I made a main class in every single one.

    And if you start learning from youtube or start googling it, then you wont have the right to claim you were self-learned :p
     
  29. Offline

    The_Doctor_123

    Wolfey
    Yep. I learned about 80% of the content I know from Google. Google leading to StackOverFlow and JavaDocs, that is.
     
  30. Offline

    Not2EXceL

    I'm self learned. I read oracle's provided tutorial series as well as their javadocs. Didnt once use a book, external source(as in someone's program, that's not from oracle tut's), or youtube video.
     
Thread Status:
Not open for further replies.

Share This Page