Solved Could not pass event BlockPlaceEvent

Discussion in 'Plugin Development' started by iMarv, Mar 26, 2014.

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

    iMarv

    Hey guys, got a problem with a block place event.
    It happens when I am placing a pumpkin (what I am actually listening for)

    You can find the code in this repo
    I have no idea what the problem could be, the code got no errors. Maybe someone of you got an idea?

    Code:
    E:\Desktop\bukkit lokal>java -Xmx1024M -jar craftbukkit.jar -o true
    15:51:00 [INFORMATION] Starting minecraft server version 1.6.4
    15:51:00 [INFORMATION] Loading properties
    15:51:00 [INFORMATION] Default game type: SURVIVAL
    15:51:00 [INFORMATION] Generating keypair
    15:51:00 [INFORMATION] Starting Minecraft server on *:25565
    15:51:00 [INFORMATION] This server is running CraftBukkit version git-Bukkit-1.6
    .4-R2.0-b2918jnks (MC: 1.6.4) (Implementing API version 1.6.4-R2.0)
    15:51:00 [INFORMATION] [MobStacks] Loading MobStacks v0.1
    15:51:01 [INFORMATION] Preparing level "world"
    15:51:01 [INFORMATION] Preparing start region for level 0 (Seed: -89374434454107
    12745)
    15:51:02 [INFORMATION] Preparing start region for level 1 (Seed: -89374434454107
    12745)
    15:51:02 [INFORMATION] Preparing start region for level 2 (Seed: -89374434454107
    12745)
    15:51:02 [INFORMATION] [MobStacks] Enabling MobStacks v0.1
    15:51:02 [INFORMATION] Server permissions file permissions.yml is empty, ignorin
    g it
    15:51:02 [INFORMATION] Done (1,951s)! For help, type "help" or "?"
    15:51:16 [INFORMATION] iMarv[/127.0.0.1:55262] logged in with entity id 398 at (
    [world] -41.68997801758623, 70.0, -78.54439013256149)
    15:51:21 [SCHWERWIEGEND] Could not pass event BlockPlaceEvent to MobStacks v0.1
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:427)
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:62)
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j
    ava:477)
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:462)
            at org.bukkit.craftbukkit.v1_6_R3.event.CraftEventFactory.callBlockPlace
    Event(CraftEventFactory.java:112)
            at net.minecraft.server.v1_6_R3.ItemBlock.processBlockPlace(ItemBlock.ja
    va:89)
            at net.minecraft.server.v1_6_R3.ItemBlock.interactWith(ItemBlock.java:73
    )
            at net.minecraft.server.v1_6_R3.ItemStack.placeItem(ItemStack.java:79)
            at net.minecraft.server.v1_6_R3.PlayerInteractManager.interact(PlayerInt
    eractManager.java:389)
            at net.minecraft.server.v1_6_R3.PlayerConnection.a(PlayerConnection.java
    :630)
            at net.minecraft.server.v1_6_R3.Packet15Place.handle(SourceFile:58)
            at net.minecraft.server.v1_6_R3.NetworkManager.b(NetworkManager.java:296
    )
            at net.minecraft.server.v1_6_R3.PlayerConnection.e(PlayerConnection.java
    :116)
            at net.minecraft.server.v1_6_R3.ServerConnection.b(SourceFile:37)
            at net.minecraft.server.v1_6_R3.DedicatedServerConnection.b(SourceFile:3
    0)
            at net.minecraft.server.v1_6_R3.MinecraftServer.t(MinecraftServer.java:5
    92)
            at net.minecraft.server.v1_6_R3.DedicatedServer.t(DedicatedServer.java:2
    27)
            at net.minecraft.server.v1_6_R3.MinecraftServer.s(MinecraftServer.java:4
    88)
            at net.minecraft.server.v1_6_R3.MinecraftServer.run(MinecraftServer.java
    :421)
            at net.minecraft.server.v1_6_R3.ThreadServerApplication.run(SourceFile:5
    83)
    Caused by: java.lang.ClassCastException: org.bukkit.craftbukkit.v1_6_R3.block.Cr
    aftBlock cannot be cast to org.bukkit.material.Wool
            at io.github.imarv23.spawning.SheepSpawner.getDyeColor(SheepSpawner.java
    :87)
            at io.github.imarv23.listeners.BlockListener.onBlockPlace(BlockListener.
    java:43)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
    java:57)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
    sorImpl.java:43)
            at java.lang.reflect.Method.invoke(Method.java:606)
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:425)
            ... 19 more
    >
     
  2. Offline

    tommykins20

    You can see from the stack trace you are trying to cast the block being placed to Wool. You must cast Wool from the block.getState()...
    I tried looking through the repo but it appears that the code in the repo does not match the code run in the plugin so I can't tell you exactly where the code is that needs to be changed.
     
  3. Offline

    TheTrixsta

    You're trying to cast wool to a block that's not wool and trying to set its color in your sheep spawner class
     
  4. Offline

    iMarv

    Thank you :)
    TheTrixsta I do not get how it gets to that point tho.
    Before I cast a block to a wool block, the block checked if it is a wool block
     
  5. Offline

    Garris0n

    Yes but Wool extends BlockState, not Block.
     
    TheTrixsta and tommykins20 like this.
  6. Offline

    iMarv

    So, how do I get the color of the wool then?
     
  7. Offline

    tommykins20

    You must get the BlockState of the block then cast that BlockState to Wool.
    Something like this..
    Code:
    Block block = theBlock; //obviously change this :)
    BlockState state = block.getState();
    Wool wool = (Wool) state;
    //or
    Wool wool2 = (Wool) block.getState();
    
     
  8. Offline

    iMarv

    I fixed that one but I am still getting basically the same error.
    You can find the branch here
    Code:
    E:\Desktop\bukkit lokal>java -Xmx1024M -jar craftbukkit.jar -o true
    18:10:46 [INFORMATION] Starting minecraft server version 1.6.4
    18:10:46 [INFORMATION] Loading properties
    18:10:46 [INFORMATION] Default game type: SURVIVAL
    18:10:46 [INFORMATION] Generating keypair
    18:10:46 [INFORMATION] Starting Minecraft server on *:25565
    18:10:47 [INFORMATION] This server is running CraftBukkit version git-Bukkit-1.6
    .4-R2.0-b2918jnks (MC: 1.6.4) (Implementing API version 1.6.4-R2.0)
    18:10:47 [INFORMATION] [MobStacks] Loading MobStacks v0.1
    18:10:47 [INFORMATION] Preparing level "world"
    18:10:47 [INFORMATION] Preparing start region for level 0 (Seed: -89374434454107
    12745)
    18:10:48 [INFORMATION] Preparing start region for level 1 (Seed: -89374434454107
    12745)
    18:10:48 [INFORMATION] Preparing start region for level 2 (Seed: -89374434454107
    12745)
    18:10:49 [INFORMATION] [MobStacks] Enabling MobStacks v0.1
    18:10:49 [INFORMATION] Server permissions file permissions.yml is empty, ignorin
    g it
    18:10:49 [INFORMATION] Done (1,914s)! For help, type "help" or "?"
    18:10:56 [INFORMATION] iMarv[/127.0.0.1:57735] logged in with entity id 377 at (
    [world] -41.68997801758623, 70.0, -78.54439013256149)
    18:11:01 [SCHWERWIEGEND] Could not pass event BlockPlaceEvent to MobStacks v0.1
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:427)
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:62)
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j
    ava:477)
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:462)
            at org.bukkit.craftbukkit.v1_6_R3.event.CraftEventFactory.callBlockPlace
    Event(CraftEventFactory.java:112)
            at net.minecraft.server.v1_6_R3.ItemBlock.processBlockPlace(ItemBlock.ja
    va:89)
            at net.minecraft.server.v1_6_R3.ItemBlock.interactWith(ItemBlock.java:73
    )
            at net.minecraft.server.v1_6_R3.ItemStack.placeItem(ItemStack.java:79)
            at net.minecraft.server.v1_6_R3.PlayerInteractManager.interact(PlayerInt
    eractManager.java:389)
            at net.minecraft.server.v1_6_R3.PlayerConnection.a(PlayerConnection.java
    :630)
            at net.minecraft.server.v1_6_R3.Packet15Place.handle(SourceFile:58)
            at net.minecraft.server.v1_6_R3.NetworkManager.b(NetworkManager.java:296
    )
            at net.minecraft.server.v1_6_R3.PlayerConnection.e(PlayerConnection.java
    :116)
            at net.minecraft.server.v1_6_R3.ServerConnection.b(SourceFile:37)
            at net.minecraft.server.v1_6_R3.DedicatedServerConnection.b(SourceFile:3
    0)
            at net.minecraft.server.v1_6_R3.MinecraftServer.t(MinecraftServer.java:5
    92)
            at net.minecraft.server.v1_6_R3.DedicatedServer.t(DedicatedServer.java:2
    27)
            at net.minecraft.server.v1_6_R3.MinecraftServer.s(MinecraftServer.java:4
    88)
            at net.minecraft.server.v1_6_R3.MinecraftServer.run(MinecraftServer.java
    :421)
            at net.minecraft.server.v1_6_R3.ThreadServerApplication.run(SourceFile:5
    83)
    Caused by: java.lang.ClassCastException: org.bukkit.craftbukkit.v1_6_R3.block.Cr
    aftBlockState cannot be cast to org.bukkit.material.Wool
            at io.github.imarv23.spawning.SheepSpawner.getDyeColor(SheepSpawner.java
    :87)
            at io.github.imarv23.listeners.BlockListener.onBlockPlace(BlockListener.
    java:43)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
    java:57)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
    sorImpl.java:43)
            at java.lang.reflect.Method.invoke(Method.java:606)
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:425)
            ... 19 more
    >
     
  9. Offline

    TheTrixsta


    in SheepSpawner.java on line 87

    Wool w = (Wool) block.getState();

    should be (Bukkit is a little dusty for me right now, its been a while since I wrote a plugin but this should work)

    BlockState w = block.getState();
    if (w instanceof Wool) {
    return ((Wool) w).getColor();
    }

    Edit: Also cast the return ((Wool) w).getColor();
     
  10. Offline

    Garris0n

    Huh, I was tired when I wrote that...

    It extends MaterialData. You get that with BlockState#getData().
     
    iMarv likes this.
  11. Offline

    iMarv

    Thank you Garris0n, now it is working :)
     
Thread Status:
Not open for further replies.

Share This Page