Solved Change block behind sign

Discussion in 'Plugin Help/Development/Requests' started by poepdrolify, May 27, 2015.

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

    poepdrolify

    So, I have this code, and suddenly it won't work. Can someone please help me? I want to change the block behind a sign when there is a certain text on line 1 of the sign...

    Code:
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.block.BlockFace;
    import org.bukkit.block.Sign;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.SignChangeEvent;
    import org.bukkit.material.Attachable;
    import org.bukkit.material.MaterialData;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin implements Listener {
       
        @Override
        public void onEnable() {
            getServer().getPluginManager().registerEvents(this, this);
        }
       
        @EventHandler
        public void onSignChange(SignChangeEvent e) {
            Sign sign = (Sign) e.getBlock();
            Block block = getAttachedBlock(e.getBlock());
            block.setType(Material.STONE);
        }
       
        public static Block getAttachedBlock(Block b) {
            MaterialData m = b.getState().getData();
            BlockFace face = BlockFace.DOWN;
            if (m instanceof Attachable) {
                face = ((Attachable) m).getAttachedFace();
            }
            return b.getRelative(face);
        }
       
    }
    
     
  2. Offline

    Zombie_Striker

    Does it show any errors? Did you debug? Did anything change since this worked?
     
  3. Offline

    poepdrolify

    @Zombie_Striker No, it doesn't show any errors, and it never workt. I also tried block place event but that didn't work as well.
     
  4. Offline

    Zombie_Striker

  5. Offline

    poepdrolify

  6. Offline

    AdamQpzm

    @poepdrolify Put println() statements at various points in your code to see which parts execute. Is there any reason that the method you've created is a public static method?
     
  7. Offline

    poepdrolify

    @AdamQpzm No, it isn't. But, when I want to use it in other classes...

    @AdamQpzm @Zombie_Striker Ok, so now I have this error:

    Code:
    [15:52:43 ERROR]: Could not pass event BlockPlaceEvent to Signs v1.0.0
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:305) ~[spigot.jar:git-Spigot-870264a-0a645a2]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:62) ~[spigot.jar:git-Spigot-870264a-0a645a2]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j
    ava:502) [spigot.jar:git-Spigot-870264a-0a645a2]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:487) [spigot.jar:git-Spigot-870264a-0a645a2]
            at org.bukkit.craftbukkit.v1_8_R2.event.CraftEventFactory.callBlockPlace
    Event(CraftEventFactory.java:126) [spigot.jar:git-Spigot-870264a-0a645a2]
            at net.minecraft.server.v1_8_R2.ItemStack.placeItem(ItemStack.java:157)
    [spigot.jar:git-Spigot-870264a-0a645a2]
            at net.minecraft.server.v1_8_R2.PlayerInteractManager.interact(PlayerInt
    eractManager.java:503) [spigot.jar:git-Spigot-870264a-0a645a2]
            at net.minecraft.server.v1_8_R2.PlayerConnection.a(PlayerConnection.java
    :740) [spigot.jar:git-Spigot-870264a-0a645a2]
            at net.minecraft.server.v1_8_R2.PacketPlayInBlockPlace.a(PacketPlayInBlo
    ckPlace.java:52) [spigot.jar:git-Spigot-870264a-0a645a2]
            at net.minecraft.server.v1_8_R2.PacketPlayInBlockPlace.a(PacketPlayInBlo
    ckPlace.java:1) [spigot.jar:git-Spigot-870264a-0a645a2]
            at net.minecraft.server.v1_8_R2.PlayerConnectionUtils$1.run(SourceFile:1
    3) [spigot.jar:git-Spigot-870264a-0a645a2]
            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_R2.SystemUtils.a(SourceFile:60) [spigot.jar
    :git-Spigot-870264a-0a645a2]
            at net.minecraft.server.v1_8_R2.MinecraftServer.A(MinecraftServer.java:7
    12) [spigot.jar:git-Spigot-870264a-0a645a2]
            at net.minecraft.server.v1_8_R2.DedicatedServer.A(DedicatedServer.java:3
    68) [spigot.jar:git-Spigot-870264a-0a645a2]
            at net.minecraft.server.v1_8_R2.MinecraftServer.z(MinecraftServer.java:6
    51) [spigot.jar:git-Spigot-870264a-0a645a2]
            at net.minecraft.server.v1_8_R2.MinecraftServer.run(MinecraftServer.java
    :554) [spigot.jar:git-Spigot-870264a-0a645a2]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_31]
    Caused by: java.lang.ClassCastException: org.bukkit.craftbukkit.v1_8_R2.block.Cr
    aftBlock cannot be cast to org.bukkit.block.Sign
            at me.poepdrolify.signs.Main.onSignChange(Main.java:25) ~[?:?]
            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.ja
    va:301) ~[spigot.jar:git-Spigot-870264a-0a645a2]
            ... 18 more
    >
     
    Last edited by a moderator: May 28, 2015
  8. Offline

    Agentleader1

    Code:
    Sign sign = (Sign) block.getState();
     
  9. Offline

    poepdrolify

Thread Status:
Not open for further replies.

Share This Page