Spawning a "dropped" item

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

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


    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


    Moved to appropriate subforum.
  3. Offline


  4. Offline


    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:
    public void onBlockBreak(BlockBreakEvent event) {
       theblock = event.getBlock();
          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


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


    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


    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


    I'm initializing it with this:
    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

    if(theblock.getType() == Material.MOB_SPAWNER)
  10. Offline


    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


    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:
    SEVERE: Could not load plugins/SpawnerMod.jar in plugins: null
    	at org.bukkit.plugin.SimplePluginManager.loadPlugin(
    	at org.bukkit.plugin.SimplePluginManager.loadPlugins(
    	at org.bukkit.craftbukkit.CraftServer.loadPlugins(
    	at net.minecraft.server.MinecraftServer.e(
    	at net.minecraft.server.MinecraftServer.c(
    	at net.minecraft.server.MinecraftServer.d(
    Caused by: java.lang.reflect.InvocationTargetException
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance(
    	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(
    	at java.lang.reflect.Constructor.newInstance(
    	... 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>(
    	... 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


    It seems to be fine.

    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:
    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


    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:
    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


    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:
    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