Spawning a "dropped" item

Discussion in 'Plugin Development' started by Colecf, Feb 20, 2011.

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

    Colecf

    I'd like for my plugin to spawn a dropped item that the player can pick up. I'm making a plugin that requires a block to be dropped when it normally isn't. How would I do this?
     
  2. Offline

    TnT

    Moved to appropriate subforum.
     
  3. Offline

    cyklo

  4. Offline

    Colecf

    Wait, I didn't put this in plugin development? oops.

    I tried dropitemnaturally and made a plugin, started the server (and the little enabled message for my plugin came up) but when I destroyed the mob spawner (the block I want to appear in breakable form), nothing happened. There wasn't any error message in the console or anything. This is my code for the blockbreak event:
    Code:
    public void onBlockBreak(BlockBreakEvent event) {
       theblock = event.getBlock();
       if(theblock.getTypeId()==52)
       {
          spawner = new ItemStack(52, 1);
          spawnerloc = new Location(theblock.getWorld(), theblock.getX(), theblock.getY(), theblock.getZ());
          theblock.getWorld().dropItemNaturally(spawnerloc, spawner);
       }
    }
    What am I doing wrong?
     
  5. Offline

    flyslasher

    When making spawnerloc you have a ] in your theblock].getWorld().
     
  6. Offline

    Colecf

    Oh, that's not in my actuall code, I just copied and pasted from eclipse and had to edit out all the [COLOR] tags, guess I forgot one.
     
  7. Offline

    cyklo

    The code you pasted works fine, so I assume it's simply not being called. Are you correctly initializing the plugin with the right hooks?
     
  8. Offline

    Colecf

    I'm initializing it with this:
    Code:
    private final SpawnerBlockListener blockListener = new SpawnerBlockListener(this);
    ...
    pm.registerEvent(Event.Type.BLOCK_BREAK, blockListener, Event.Priority.Normal, this);
    Full Source.

    Thanks for helping me with this.[/FONT][/SIZE]
     
  9. Offline

    Edward Hand

    change:
    Code:
    if(theblock.getType() == Material.MOB_SPAWNER)
    to:
    Code:
    if(theblock.getType().equals(Material.MOB_SPAWNER))
     
  10. Offline

    Colecf

    That didn't work.... It still gives nothing back when I destroy the mob spawner.

    Let me put in a debugging statement on the onBlockBreak() event...
    --- merged: Feb 21, 2011 11:47 PM ---
    Nothing happens still, so onBlockBreak() isn't being called. But I guess that's what you guys assumed already....

    Wait, 1 more thing to check.

    Nope, definitely not being called.
     
  11. Offline

    Edward Hand

    Just a stab in the dark, but try moving:

    blockListener = new SpawnerBlockListener(this);

    to onEnable()
     
  12. Offline

    Colecf

    It complains that it can't assign the "final" field to blocklistener when I do that. I'm declaring the variable outside onEnable() though, should I not?

    I'll try compiling it anyways.

    EDIT: I got this error:
    Code:
    SEVERE: Could not load plugins/SpawnerMod.jar in plugins: null
    org.bukkit.plugin.InvalidPluginException
    	at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:78)
    	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:42)
    	at net.minecraft.server.MinecraftServer.e(MinecraftServer.java:156)
    	at net.minecraft.server.MinecraftServer.c(MinecraftServer.java:143)
    	at net.minecraft.server.MinecraftServer.d(MinecraftServer.java:104)
    	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:186)
    	at net.minecraft.server.ThreadServerApplication.run(SourceFile:512)
    Caused by: java.lang.reflect.InvocationTargetException
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    	at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    	at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:76)
    	... 8 more
    Caused by: java.lang.Error: Unresolved compilation problems:
    	The blank final field blockListener may not have been initialized
    	The final field spawnermod.blockListener cannot be assigned
    
    	at usa.colecf.spawnermod.spawnermod.<init>(spawnermod.java:14)
    	... 13 more
    
    And it still doesn't work.

    EDIT2: I changed it to a torch instead of a mob spawner and nothing happens when I destroy it, although I notice a little bit of lag when destroying it.
     
  13. Offline

    Edward Hand

    That error usually means your plugin.yml isn't set up right doesn't it?
     
  14. Offline

    Colecf

    It seems to be fine.

    Code:
    name: SpawnerMod
    main: usa.colecf.spawnermod.spawnermod
    version: 1.0
    It also says this in the error, it doesn't sound like the plugin.yml file but like the change we just made:
    Code:
    The blank final field blockListener may not have been initialized
    The final field spawnermod.blockListener cannot be assigned
     
  15. Offline

    Edward Hand

    I just tried pasting your code into my eclipse (with my earlier getType().equals() modification) and it works perfectly for me.
     
  16. Offline

    Colecf

    Oh wait, I put the new SpawnerBlockListener() after it tried to register an event to it. Changing...

    That didn't work.

    It works for you? Let me update my bukkit and craftbukkit and try again.
     
  17. Offline

    Edward Hand

    Good idea; and note that when you do that you will need to delete the whole:
    Code:
    public spawnermod(PluginLoader pluginLoader, Server instance,
                PluginDescriptionFile desc, File folder, File plugin,
                ClassLoader cLoader) {
            super(pluginLoader, instance, desc, folder, plugin, cLoader);
        }
    part. (It's just how we have to do things now or it will moan)
     
  18. Offline

    Colecf

    After updating it works! How'd that happen? Shouldn't onBlockBreak been around since build 24-something?

    And as another question: After I updated I got this on all of my plugins:
    Code:
    2011-02-21 16:24:42 [WARNING] Using the stupidly long constructor usa.colecf.spawnermod.spawnermod(PluginLoader, Server, PluginDescriptionFile, File, File, ClassLoader) is no longer recommended. Go nag the plugin author of SpawnerMod to remove it! (Nothing is broken, we just like to keep code clean.)
    Can I remove the main: section in my plugin.yml file now? How do I get rid of this message?

    EDIT: Oh looks like you already answered that.
     
Thread Status:
Not open for further replies.

Share This Page