Simple BlockPlaceEvent with a sign

Discussion in 'Plugin Development' started by Torfnase, Mar 2, 2015.

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

    Torfnase

    Hey guys,

    im going to complete my first plugin if i can solve this problem. :)
    Introduction: I was trying to create an event, which reacts if a player places a sign with the first line "[Drill]". It don't have to be a WALL_SIGN, just a simple sign. After that the player should receive a message.

    Code:
    public void onPlayerPlace(BlockPlaceEvent e) {
        Player p = e.getPlayer();
        Block b = e.getBlockPlaced();
        if(b.getType() == Material.SIGN_POST) {
            Sign sign = (Sign)b.getState();
            if(sign.getLine(0).equals("[Drill]")) {
                p.sendMessage(ChatColor.GRAY + "Drill created");
                sign.setLine(1, "Drill aktivated");
            
                Location locSign = sign.getLocation();
            }
        }
    }
    Problem: If i try to place a sign, i get no message.. At first i thought i forget the EventHandler Annotation, but if i add a random one (LOWEST, [...], MONITOR) i received that exception in the console:

    Exception (open)

    [23:48:00 ERROR]: Could not pass event BlockPlaceEvent to DespicableMe v1.0
    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.jav
    a:297) ~[craftbukkit.jar:git-Bukkit-33d5de3]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java
    :62) ~[craftbukkit.jar:git-Bukkit-33d5de3]
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.ja
    va:501) [craftbukkit.jar:git-Bukkit-33d5de3]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.ja
    va:486) [craftbukkit.jar:git-Bukkit-33d5de3]
    at org.bukkit.craftbukkit.v1_8_R1.event.CraftEventFactory.callBlockPlaceE
    vent(CraftEventFactory.java:124) [craftbukkit.jar:git-Bukkit-33d5de3]
    at net.minecraft.server.v1_8_R1.ItemStack.placeItem(ItemStack.java:154) [
    craftbukkit.jar:git-Bukkit-33d5de3]
    at net.minecraft.server.v1_8_R1.PlayerInteractManager.interact(PlayerInte
    ractManager.java:502) [craftbukkit.jar:git-Bukkit-33d5de3]
    at net.minecraft.server.v1_8_R1.PlayerConnection.a(PlayerConnection.java:
    693) [craftbukkit.jar:git-Bukkit-33d5de3]
    at net.minecraft.server.v1_8_R1.PacketPlayInBlockPlace.a(PacketPlayInBloc
    kPlace.java:50) [craftbukkit.jar:git-Bukkit-33d5de3]
    at net.minecraft.server.v1_8_R1.PacketPlayInBlockPlace.a(PacketPlayInBloc
    kPlace.java:80) [craftbukkit.jar:git-Bukkit-33d5de3]
    at net.minecraft.server.v1_8_R1.PacketHandleTask.run(SourceFile:13) [craf
    tbukkit.jar:git-Bukkit-33d5de3]
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?
    :1.8.0_31]
    at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_31]
    at net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:65
    6) [craftbukkit.jar:git-Bukkit-33d5de3]
    at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:28
    4) [craftbukkit.jar:git-Bukkit-33d5de3]
    at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:60
    9) [craftbukkit.jar:git-Bukkit-33d5de3]
    at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:
    517) [craftbukkit.jar:git-Bukkit-33d5de3]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_31]
    Caused by: java.lang.ClassCastException: org.bukkit.craftbukkit.v1_8_R1.block.Cra
    ftBlock cannot be cast to org.bukkit.block.Sign
    at me.torfnase.despicableme.DMEventListener.onPlayerPlace(DMEventListener
    .java:39) ~[?:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_
    31]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_
    31]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.
    8.0_31]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_31]
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.jav
    a:295) ~[craftbukkit.jar:git-Bukkit-33d5de3]
    ... 17 more


    I hope you can help me,
    thanks, Torfnase (peatnose)
     
    Last edited: Mar 4, 2015
  2. Offline

    Aqua

    Sign sign = (Sign) b.getState();
    Or b.getBlockState();
    Forgot which one it was....
    @Torfnase
     
  3. Offline

    Torfnase

    Didn't work, i've tried that before

    @Aqua
     
  4. Offline

    Konato_K

    @Torfnase That works and fixes your problem.

    Anyway, you probably need SignChangeEvent, BlockPlaceEvent will have an empty sign.
     
  5. Offline

    CXdur

    @Torfnase, @Konato_K

    Yeah, he does need to. BlockPlaceEvent will only place the block, and then the sign menu will pop up, when the sign menu is closed the event SignChangeEvent will be called and this is where you can actually do things.
     
  6. Offline

    Torfnase

    That worked, ty guys :)
     
Thread Status:
Not open for further replies.

Share This Page