enebo / Purugin

Ruby Minecraft Plugin support on top of bukkit
238 stars 32 forks source link

java.lang.NullPointerException for event(:player_inventory) #49

Closed MangelMaxime closed 10 years ago

MangelMaxime commented 10 years ago

Hi,

I would like to use the following event :player_inventory but when I tried to load my plugin using this event with the following code :

class InventoryManagement
    include Purugin::Plugin
    description 'Inventory Management', 0.1

    def on_enable
        puts 'Hello inventory'
        event(:player_inventory) do |e|
            puts 'hi'
        end
    end

    def on_disbale
        puts 'Bye inventory'
    end

end

I get a java NullPointException on the line 7 which is the following :

event(:player_inventory) do |e| 

Here is the full trace :

Error occurred (in the plugin loader) while enabling Inventory Management v0.1 (Is it up to date?)
java.lang.NullPointerException
    at org.bukkit.plugin.java.JavaPluginLoader.createRegisteredListeners(org/bukkit/plugin/java/JavaPluginLoader.java:404) ~[craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at org.purugin.RubyPluginLoader.createRegisteredListeners(org/purugin/RubyPluginLoader.java:66) ~[?:?]
    at org.bukkit.plugin.SimplePluginManager.registerEvents(org/bukkit/plugin/SimplePluginManager.java:506) ~[craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at java.lang.reflect.Method.invoke(java/lang/reflect/Method.java:606) ~[?:1.7.0_51]
    at RUBY.event(file:/Volumes/Data/Developpement/Minecraft/bukkit/purugin/plugins/purugin-0.7.1-bukkit-1.7.2-R0.2.jar!/purugin/event.rb:212) ~[?:?]
    at RUBY.on_enable(/Volumes/Data/Developpement/Minecraft/bukkit/purugin/plugins/InventoryManagement.rb:7) ~[?:?]
    at RUBY.onEnable(file:/Volumes/Data/Developpement/Minecraft/bukkit/purugin/plugins/purugin-0.7.1-bukkit-1.7.2-R0.2.jar!/purugin/plugin.rb:142) ~[?:?]
    at InventoryManagement_1469695719.onEnable(InventoryManagement_1469695719.gen:13) ~[?:?]
    at InventoryManagement_1469695719.onEnable(InventoryManagement_1469695719.gen:13) ~[?:?]
    at org.purugin.RubyPluginLoader.enablePlugin(org/purugin/RubyPluginLoader.java:49) ~[?:?]
    at org.bukkit.plugin.SimplePluginManager.enablePlugin(org/bukkit/plugin/SimplePluginManager.java:384) ~[craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at java.lang.reflect.Method.invoke(java/lang/reflect/Method.java:606) ~[?:1.7.0_51]
    at RUBY.onEnable(jar:file:/Volumes/Data/Developpement/Minecraft/bukkit/purugin/plugins/purugin-0.7.1-bukkit-1.7.2-R0.2.jar!/purugin.rb:71) ~[?:?]
    at org.jruby.RubyHash.each(org/jruby/RubyHash.java:1339) ~[jruby-complete-1.7.11.jar:?]
    at RUBY.onEnable(jar:file:/Volumes/Data/Developpement/Minecraft/bukkit/purugin/plugins/purugin-0.7.1-bukkit-1.7.2-R0.2.jar!/purugin.rb:71) ~[?:?]
    at org.purugin.PuruginPlugin.onEnable(org/purugin/PuruginPlugin.java:30) [purugin-0.7.1-bukkit-1.7.2-R0.2.jar:?]
    at org.bukkit.plugin.java.JavaPlugin.setEnabled(org/bukkit/plugin/java/JavaPlugin.java:218) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(org/bukkit/plugin/java/JavaPluginLoader.java:457) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at org.bukkit.plugin.SimplePluginManager.enablePlugin(org/bukkit/plugin/SimplePluginManager.java:384) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at org.bukkit.craftbukkit.v1_7_R1.CraftServer.loadPlugin(org/bukkit/craftbukkit/v1_7_R1/CraftServer.java:298) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at org.bukkit.craftbukkit.v1_7_R1.CraftServer.enablePlugins(org/bukkit/craftbukkit/v1_7_R1/CraftServer.java:280) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at org.bukkit.craftbukkit.v1_7_R1.CraftServer.reload(org/bukkit/craftbukkit/v1_7_R1/CraftServer.java:630) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at org.bukkit.Bukkit.reload(org/bukkit/Bukkit.java:279) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at org.bukkit.command.defaults.ReloadCommand.execute(org/bukkit/command/defaults/ReloadCommand.java:23) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at org.bukkit.command.SimpleCommandMap.dispatch(org/bukkit/command/SimpleCommandMap.java:196) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at org.bukkit.craftbukkit.v1_7_R1.CraftServer.dispatchCommand(org/bukkit/craftbukkit/v1_7_R1/CraftServer.java:542) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at org.bukkit.craftbukkit.v1_7_R1.CraftServer.dispatchServerCommand(org/bukkit/craftbukkit/v1_7_R1/CraftServer.java:529) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.DedicatedServer.aw(net/minecraft/server/v1_7_R1/DedicatedServer.java:286) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.DedicatedServer.u(net/minecraft/server/v1_7_R1/DedicatedServer.java:251) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.MinecraftServer.t(net/minecraft/server/v1_7_R1/MinecraftServer.java:545) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.MinecraftServer.run(net/minecraft/server/v1_7_R1/MinecraftServer.java:457) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) ~[craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(net/minecraft/server/v1_7_R1/SourceFile:617) [craftbukkit-1.7.2-R0.2.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]

For information, I have tried severals other PlayerEvent and they work without problems. So I don't really understand why this is happening for this one.

enebo commented 10 years ago

This is really mysterious...However, I just noticed this event has been deprecated:

/**
 * Represents a player related inventory event; note that this event never
 * actually did anything
 *
 * @deprecated Use {@link InventoryClickEvent} or {@link InventoryOpenEvent}
 *     instead, or one of the other inventory events in {@link
 *     org.bukkit.event.inventory}.
 */

I did try those events and they work fine. So I might remove player_inventory from Purugin since it is going away anyways and just punt on this.

MangelMaxime commented 10 years ago

Ok. But the problem is that InventoryOpenEvent is not fired when a player open his on inventory by pressing the 'E' key by default.

How ever this fact is not your concern. Thanks for the answer.

enebo commented 10 years ago

Ah yeah hopefully Bukkit ends up fixing that otherwise this deprecation is not so nice...

MangelMaxime commented 10 years ago

Yes that sure. But as far as I remember this event have never been fired by the player inventory.