Get the new and the old location when a Piston move a Block

Discussion in 'Plugin Development' started by Eistee², Aug 14, 2012.

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

    Eistee²

    Hello,
    My plugin give exp/money for breaking/placing blocks and when the place a block he wont give exp because I save his location but my problem is when a player move the block with a Piston he will give exp again.

    My ask is , how can I get the new and the old location of a block when he gets moved by a piston?
     
  2. Offline

    tr4st

  3. Offline

    Eistee²

    I will try this , thanks :)
     
  4. Offline

    sd5

    And with getDirection() you can indirectly get where the block came from.
     
  5. Offline

    Eistee²

    Hm I always get this error message and I dont know why ...
    Code:
    14:41:06 [SCHWERWIEGEND] Error occurred while enabling MineBuilder v1.4 (Is it u
    p to date?)
    org.bukkit.plugin.IllegalPluginAccessException: Unable to find handler list for
    event org.bukkit.event.block.BlockEvent
            at org.bukkit.plugin.SimplePluginManager.getRegistrationClass(SimplePlug
    inManager.java:564)
            at org.bukkit.plugin.SimplePluginManager.getRegistrationClass(SimplePlug
    inManager.java:562)
            at org.bukkit.plugin.SimplePluginManager.registerEvents(SimplePluginMana
    ger.java:508)
            at me.eistee2.minebuilder.MineBuilder.onEnable(MineBuilder.java:116)
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:217)
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader
    .java:365)
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManage
    r.java:381)
            at org.bukkit.craftbukkit.CraftServer.loadPlugin(CraftServer.java:265)
            at org.bukkit.craftbukkit.CraftServer.enablePlugins(CraftServer.java:247
    )
            at org.bukkit.craftbukkit.CraftServer.reload(CraftServer.java:567)
            at org.bukkit.Bukkit.reload(Bukkit.java:183)
            at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:
    21)
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:16
    8)
            at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:4
    92)
            at org.bukkit.craftbukkit.CraftServer.dispatchServerCommand(CraftServer.
    java:488)
            at net.minecraft.server.DedicatedServer.ah(DedicatedServer.java:248)
            at net.minecraft.server.DedicatedServer.q(DedicatedServer.java:213)
            at net.minecraft.server.MinecraftServer.p(MinecraftServer.java:474)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:406)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:539)
    My code on enable :
    Code:
    pistonMoveBlockEvent pistonMove = new pistonMoveBlockEvent();
     
    Bukkit.getServer().getPluginManager().registerEvents(pistonMove, this);
    My code in pistonMoveBlockEvent:
    Code:
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockPistonEvent;
     
    public class pistonMoveBlockEvent implements Listener{
     
        @EventHandler(priority = EventPriority.NORMAL)
        private void pistonMove(BlockPistonEvent event)
        {
            System.out.println(event.getDirection());
        }
     
    }
    EDIT: With BlockPistonExtendEvent work it fine .... only BlockPistonEvent throws this exception ...
     
  6. Offline

    tr4st

    You want to get the direction out of the Block, so you have to call it with event.getBlock().getDirection().
    And the priority is not needed if EventPriority.NORMAL.
    You shouldn't use the PistonBlockEvent instead of the BlockPistonRetractEvent and BlockPistonExtendEvent, just forget about the PistonBlockEvent.
     
    Eistee² likes this.
Thread Status:
Not open for further replies.

Share This Page