Why is this happening?

Discussion in 'Plugin Development' started by MCaeolus, Aug 22, 2014.

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

    MCaeolus

    Ok, so i'm working on a plugin that will drop (spawner) that was mined (exact type). I have it working where it will drop the exact type, but it will drop the block if I break it with my hand in creative. If I try to use a silk touch pickaxe, it doesn't break, and displays an error in console:

    Error in console:
    Code:
    [21:51:55] [Server thread/ERROR]: Could not pass event BlockBreakEvent to silkTouchSpawners v1.0
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:294) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:501) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:486) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.PlayerInteractManager.breakBlock(PlayerInteractManager.java:263) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.PlayerInteractManager.dig(PlayerInteractManager.java:118) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.PlayerConnection.a(PlayerConnection.java:537) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.PacketPlayInBlockDig.a(SourceFile:53) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.PacketPlayInBlockDig.handle(SourceFile:8) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.NetworkManager.a(NetworkManager.java:157) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.ServerConnection.c(SourceFile:134) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:667) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:258) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:558) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:469) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    Caused by: java.lang.ClassCastException: org.bukkit.craftbukkit.v1_7_R4.block.CraftCreatureSpawner cannot be cast to org.bukkit.inventory.ItemStack
        at com.choas1010.silkTouchSpawners.Main.onBlockBreak(Main.java:31) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:292) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        ... 15 more
    [21:51:56] [Server thread/ERROR]: Could not pass event BlockBreakEvent to silkTouchSpawners v1.0
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:294) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:501) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:486) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.PlayerInteractManager.breakBlock(PlayerInteractManager.java:263) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.PlayerInteractManager.dig(PlayerInteractManager.java:118) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.PlayerConnection.a(PlayerConnection.java:537) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.PacketPlayInBlockDig.a(SourceFile:53) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.PacketPlayInBlockDig.handle(SourceFile:8) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.NetworkManager.a(NetworkManager.java:157) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.ServerConnection.c(SourceFile:134) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:667) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:258) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:558) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:469) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    Caused by: java.lang.ClassCastException: org.bukkit.craftbukkit.v1_7_R4.block.CraftCreatureSpawner cannot be cast to org.bukkit.inventory.ItemStack
        at com.choas1010.silkTouchSpawners.Main.onBlockBreak(Main.java:31) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:292) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        ... 15 more
    [21:51:56] [Server thread/ERROR]: Could not pass event BlockBreakEvent to silkTouchSpawners v1.0
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:294) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:501) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:486) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.PlayerInteractManager.breakBlock(PlayerInteractManager.java:263) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.PlayerInteractManager.dig(PlayerInteractManager.java:118) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.PlayerConnection.a(PlayerConnection.java:537) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.PacketPlayInBlockDig.a(SourceFile:53) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.PacketPlayInBlockDig.handle(SourceFile:8) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.NetworkManager.a(NetworkManager.java:157) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.ServerConnection.c(SourceFile:134) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:667) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:258) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:558) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:469) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    Caused by: java.lang.ClassCastException: org.bukkit.craftbukkit.v1_7_R4.block.CraftCreatureSpawner cannot be cast to org.bukkit.inventory.ItemStack
        at com.choas1010.silkTouchSpawners.Main.onBlockBreak(Main.java:31) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:292) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        ... 15 more
    [21:51:56] [Server thread/ERROR]: Could not pass event BlockBreakEvent to silkTouchSpawners v1.0
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:294) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:501) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:486) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.PlayerInteractManager.breakBlock(PlayerInteractManager.java:263) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.PlayerInteractManager.dig(PlayerInteractManager.java:118) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.PlayerConnection.a(PlayerConnection.java:537) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.PacketPlayInBlockDig.a(SourceFile:53) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.PacketPlayInBlockDig.handle(SourceFile:8) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.NetworkManager.a(NetworkManager.java:157) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.ServerConnection.c(SourceFile:134) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:667) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:258) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:558) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:469) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    Caused by: java.lang.ClassCastException: org.bukkit.craftbukkit.v1_7_R4.block.CraftCreatureSpawner cannot be cast to org.bukkit.inventory.ItemStack
        at com.choas1010.silkTouchSpawners.Main.onBlockBreak(Main.java:31) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:292) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
        ... 15 more
    
    My code:

    Code:java
    1. public class Main extends JavaPlugin implements Listener{
    2.  
    3. public void onEnable(){
    4.  
    5. this.getServer().getPluginManager().registerEvents(this, this);
    6. getLogger().info("Enabled.");
    7.  
    8. }
    9.  
    10. @EventHandler
    11. public void onBlockBreak(BlockBreakEvent e) {
    12. Player player = e.getPlayer();
    13.  
    14. if(player.hasPermission("silktouch.spawner")) {
    15. if (player.getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) {
    16.  
    17. if(e.getBlock().getType() == Material.MOB_SPAWNER) {
    18. e.setCancelled(true);
    19. ItemStack s = (ItemStack)e.getBlock().getState();
    20. e.getBlock().setType(Material.AIR);
    21. e.getBlock().getWorld().dropItemNaturally(e.getBlock().getLocation(), new ItemStack(s));
    22. }
    23. }
    24. }
    25. }
    26. }


    Also, if you couldn't tell, i'm somewhat new to Java coding.
     
  2. Offline

    Gerov

    MCaeolus Well, which line is line 31?
     
  3. Offline

    MOMOTHEREAL

    By reading the stacktraces, you are casting a wrong import of CreatureSpawner to ItemStack. You might of used
    Code:
    import org.bukkit.craftbukkit.v1_7_R4.block.CraftCreatureSpawner;
    but you need to use this rather:
    Code:
    import org.bukkit.block.CreatureSpawner;
     
  4. Offline

    Gerov

    MCaeolus Oh oh oh, wait, why did you cast ItemStack to blockstate?
     
  5. Offline

    reider45

    You can't cast an itemstack to a blockstate
    Code:java
    1. ItemStack s = (ItemStack)e.getBlock().getState();


    So instead of casting it as an ItemStack, cast it as a BlockState
     
  6. Offline

    MCaeolus


    I think it may have changed CreatureSpawner to ItemStack ._. Because of
    e.getBlock().getWorld().dropItemNaturally(e.getBlock().getLocation(), newCreatureSpawner(s));
    How would I get it to drop CreatureSpawner instead of trying to use an ItemStack?
     
Thread Status:
Not open for further replies.

Share This Page