Greetings everyone, updating one of my plugins, I added an API. This API offers basic features related to the plugin and allows to register a custom object as an eventhandler. These eventhandlers have to implement a few methods. I defined these methods in an Interface: Code:java package demaggo.MegaCreeps.API; import org.bukkit.event.entity.CreatureSpawnEvent;import org.bukkit.event.entity.EntityDeathEvent; import demaggo.MegaCreeps.MegaCreepInstance;import demaggo.MegaCreeps.MegaCreepSetup; public interface MegaCreepsInterface { public void handleDeathEvent(MegaCreepInstance m, EntityDeathEvent e); /** modSetupLevel* modSetup* handleSpawnEvent*/ public int modSetupLevel(CreatureSpawnEvent e, int oldlevel); public MegaCreepSetup modSetup(CreatureSpawnEvent e, MegaCreepSetup oldsetup); public void handleSpawnEvent(MegaCreepInstance m); } I also added the required functions to retrieve the API and so on. Next step: I compiled the plugin, used it in the build path of another plugin and tried to hook it. The class to implement the interface: Code:java public class Megacreepmod implements MegaCreepsInterface The method that supposed to hook the plugin: Code:java private boolean setupMCHook(){ MegaCreepsAPI api=null; Plugin p=getServer().getPluginManager().getPlugin("MegaCreeps"); if (p!=null){ demaggo.MegaCreeps.Main.getAPI().registerModSetupLevel(new Megacreepmod(), "elite");} return api!=null;} I tried multiple ways, but even though it was compiled with the original plugin, I get this error: Code: org.bukkit.plugin.InvalidPluginException: java.lang.NoClassDefFoundError: demaggo/MegaCreeps/API/MegaCreepsInterface at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:184) ~[craftbukkit.jar:git-Spigot-1150] at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:306) ~[craftbukkit.jar:git-Spigot-1150] at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:230) [craftbukkit.jar:git-Spigot-1150] at org.bukkit.craftbukkit.v1_7_R1.CraftServer.loadPlugins(CraftServer.java:259) [craftbukkit.jar:git-Spigot-1150] at net.minecraft.server.v1_7_R1.DedicatedServer.init(DedicatedServer.java:133) [craftbukkit.jar:git-Spigot-1150] at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:420) [craftbukkit.jar:git-Spigot-1150] at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [craftbukkit.jar:git-Spigot-1150] Caused by: java.lang.NoClassDefFoundError: demaggo/MegaCreeps/API/MegaCreepsInterface at java.lang.Class.forName0(Native Method) ~[?:1.7.0_25] at java.lang.Class.forName(Class.java:270) ~[?:1.7.0_25] at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:173) ~[craftbukkit.jar:git-Spigot-1150] ... 6 more Caused by: java.lang.ClassNotFoundException: demaggo.MegaCreeps.API.MegaCreepsInterface at java.net.URLClassLoader$1.run(URLClassLoader.java:366) ~[?:1.7.0_25] at java.net.URLClassLoader$1.run(URLClassLoader.java:355) ~[?:1.7.0_25] at java.security.AccessController.doPrivileged(Native Method) ~[?:1.7.0_25] at java.net.URLClassLoader.findClass(URLClassLoader.java:354) ~[?:1.7.0_25] at org.bukkit.plugin.java.PluginClassLoader.findClass0(PluginClassLoader.java:80) ~[craftbukkit.jar:git-Spigot-1150] at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:53) ~[craftbukkit.jar:git-Spigot-1150] at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[?:1.7.0_25] at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[?:1.7.0_25] at java.lang.Class.forName0(Native Method) ~[?:1.7.0_25] at java.lang.Class.forName(Class.java:270) ~[?:1.7.0_25] at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:173) ~[craftbukkit.jar:git-Spigot-1150] ... 6 more How comes Eclipse has no compilation problems and finds all required classes while the Interface is unknown during runtime?
DeMaggo I didn't look through your code, but I'd just like to point out one minor mistake in your text... You might want to choose your words better.
Whats your plugin yml look like? Or is your "API" even a plugin? Also lol at "public" modifiers in an interface
Not2EXceL Why? It's not weird or anything to put them there... EDIT: I mean, obviously I know every method in an interface is public, but still, alot of programmers put them there.
werter318 Its completely unecessary as interface method declaration is implicitly public and abstract. It's allowed, but its a bad practice. JLS:
werter318 This is my last post. You simply cannot just take out "as a matter of style" from the said context. It changes the entirety of the statement. The JLS addresses the redundancy issue since people do that, but its not something that should be done or practiced according to the Java Language Specifications.
Can we please get to the topic? Why is everyone crying about nonsense? The API is a bonus function in my plugin. You simply pick the main class and call Main.getAPI() for full access, at least I thought so. The hooking plugin never gets loaded because it says it misses a class that should be there since it gets imported, compiled against AND is also there in the actual Main plugin.
DeMaggo If you're using another plugin to access the Main.getAPI() method inside the plugin with the API, you need to add it as a dependency in plugin.yml. (or softdependency depending on what your doing) and it wasn't nonsense. nonsense is xtrollxdudex XD
I added a soft dependency and it worked well. Thumbs up for NathanWolf. If it wasn't for your attitude and spamming, you'd get one as well, Not2EXceL.