Hi, I wanted to develop a small plugin (my first one) today, but I have some problems with the yaml file. I always get an error message on the server which tells me that the main class could not be found. YAML: Code: name: NoTNT main: com.gmail.bozzchief.NoTNT version: 0.1.1 author: Da Bozz ([email protected]) database: false My package name is com.gmail.bozzchief and the name of the main class is NoTNT. What have I done wrong? Thanks very much for your help!
Code: 2012-04-25 13:50:03 [SEVERE] Could not load 'plugins/NoTNT.jar' in folder 'plugins' org.bukkit.plugin.InvalidPluginException: java.lang.ClassNotFoundException: com.gmail.bozzchief.NoTNT at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:150) at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:305) at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:230) at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:207) at org.bukkit.craftbukkit.CraftServer.<init>(CraftServer.java:183) at net.minecraft.server.ServerConfigurationManager.<init>(ServerConfigurationManager.java:53) at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:156) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:422) at net.minecraft.server.ThreadServerApplication.run(SourceFile:492) Caused by: java.lang.ClassNotFoundException: com.gmail.bozzchief.NoTNT at java.net.URLClassLoader$1.run(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:41) at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:29) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Unknown Source) at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:139) ... 8 more Code: package com.gmail.bozzchief; import java.util.logging.Logger; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.command.CommandSender; import org.bukkit.entity.HumanEntity; import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.inventory.PlayerInventory; import org.bukkit.plugin.java.JavaPlugin; public class NoTNT extends JavaPlugin { Logger log; public void onEnable() { log = this.getLogger(); log.info("NoTNT aktiviert!"); } public void onDisable() { log.info("NoTNT deaktiviert!"); } public void Main(InventoryCloseEvent event) { HumanEntity player = event.getPlayer(); PlayerInventory inventory = player.getInventory(); if (inventory.contains(Material.TNT)) { inventory.remove(Material.TNT); ((CommandSender) player).sendMessage(ChatColor.RED + "Kein TNT in der Creative-Welt erlaubt!"); log.info("TNT-Benutzung von Spieler "+player+" erfolgreich geblockt!"); } } } I hope I did everything right, I'm new to Bukkit plugin coding and am not very experienced in Java. Thanks very much for your help!
Your plugin.yml and Java code look OK (although "Main" is not a good name for an event handler, it shouldn't actually break anything - you also don't register that event handler, but again that wouldn't cause this error). Does your JAR file have this structure: Code: plugin.yml com/gmail/bozzchief/NoTNT.class This depends somewhat on your development environment, but you should have your source layout like: Code: <DEVDIR>/plugin.yml <DEVDIR>/com/gmail/bozzchief/NoTNT.java (Given you say you're new to Bukkit/Java, I'll assume you're not using Maven )
I uploaded a picture of the project folder, I hope it's structured like it should be. I don't use Maven and I use Eclipse. Thanks for your help!
To get your event Main executed you need NoTNT to implement Listener. Write "@EventHandler" one line above the "public void Main ...". Than it gets executed when a player closes its inventory. in German: Spoiler (Move your mouse to the spoiler area to reveal the content) Show Spoiler Hide Spoiler Damit das Event, dass du "main" gennant hast ausgeführt wird, musst du deine Hauptklasse (NoTNT) den Listener implmentieren lassen. Dann kannts du vor dem Methoden-Kopf von "Main" "@EventHandler" schreiben. Dass zeigt Bukkit, dass diese Methode ein EventHandling darstellt, die Art des Events wird über den Parameter, in deinem Fall "InventoryCloseEvent", bekannt gemacht. Ich würde dir aber empfehlen, eine neue Klasse als EventHandler anzulegen. Geh mal in die Bukkit Developer Wiki und les dir die Artikel "Basic Plugin Tutorial" und "The New Event System" durch! Hoffe ich konnte helfen... Cornyfisch
Hmm, looks OK. I suspect this is one of those problems that's blindingly obvious, but I can't see it right now
Well, the project structure doesn't mean anything if you don't select it for exporting it to the jar. So make sure you select it.
Thanks very much everbody for your help! The plugin really works now! P.S.: You probably don't know how happy I am now. Haha, I'm not an absolute beginner in Java, but thanks anyway. EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Well, even really good programmers sometimes forget/overlook something Even though I'm not directly interested in the solution, others who might have the same problem would like to see it so they don't need to ask the same question again
Yeah! it would be really nice if you can post it for the others. I hate it when you found a forum with your problem and then the last post is:".. I fixed the error my self, thanks".
Me too. I attached the Source and the YAML file, I hope it's possible for everyone to download it. Download Source Download YAML