I'm working on a plugin to replace IntelliDoors, right now, I have a scheduler working for a right click event on doors, but I can't get the same to work for RedStone activated doors. I've done event.setNewCurrent(15); and this holds the door open, but I can't use event inside the runnable to turn the current back off. Basicly it's this: Code: package com.github.Joshua_Mainer.pcldoors; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockRedstoneEvent; public class RedStoneListener implements Listener { Block doorBlock = null; Block doorBlockTop = null; Block otherDoorTopBlock = null; Block otherDoorBottomBlock = null; Block block = null; Block button = null; private int id; @EventHandler public void onBlockRedstoneChange(BlockRedstoneEvent event) { event.setNewCurrent(15); System.out.print(event.getBlock().getType()); if (event.getBlock().getType() == Material.WOODEN_DOOR) { Block doorBlock = event.getBlock(); if (doorBlock.getRelative(BlockFace.NORTH).getType() == Material.WOODEN_DOOR) { otherDoorBottomBlock = doorBlock.getRelative(BlockFace.NORTH); // player.sendMessage("Door connected North"); } else if (doorBlock.getRelative(BlockFace.SOUTH).getType() == Material.WOODEN_DOOR) { otherDoorBottomBlock = doorBlock.getRelative(BlockFace.SOUTH); // player.sendMessage("Door connected South"); } else if (doorBlock.getRelative(BlockFace.EAST).getType() == Material.WOODEN_DOOR) { otherDoorBottomBlock = doorBlock.getRelative(BlockFace.EAST); // player.sendMessage("Door connected East"); } else if (doorBlock.getRelative(BlockFace.WEST).getType() == Material.WOODEN_DOOR) { otherDoorBottomBlock = doorBlock.getRelative(BlockFace.WEST); // player.sendMessage("Door connected West"); } if (otherDoorBottomBlock != null) { id = Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(PCLDoors.plugin, new Runnable() { public void run() { System.out.print("Delay"); //event.setNewCurrent(0); } }, 60L); } else { // System.out.print("Canceling Task ID: " + id); Bukkit.getServer().getScheduler().cancelTask(id); event.setNewCurrent(0); } otherDoorTopBlock = otherDoorBottomBlock.getRelative(BlockFace.UP); otherDoorTopBlock.setData(flipDoor(otherDoorTopBlock.getData())); otherDoorBottomBlock.setData(flipDoor(otherDoorBottomBlock .getData())); } } private boolean doorIsOpen(byte data) { return (data & 0x4) == 4; } private byte flipDoor(byte data) { return (byte) (doorIsOpen(data) ? data & 0xFFFFFFFB : data | 0x4); } } Eclipse says "Cannot refer to a non-final variable event inside an inner class defined in a different method", which I understand, but not sure how to get around it. I know I can't use event inside the runnable, because the event no longer exists by the time run() runs. Any input on this would be great, I'm more used to PHP/VB.Net then Java, lol.
chance public void onBlockRedstoneChange(BlockRedstoneEvent event) { to public void onBlockRedstoneChange(final BlockRedstoneEvent event) { to fix the problem
I forgot to mention I had tried that as well, but removed it before I posted the code. the System.out.print("delay") prints, but it never turns off the current. this is simply a Button, on the side of a door frame, setting event.setNewCurrent(15) holds the button in, but event.setNewCurrent(0) doesn't seem to do anything.
You can't modify the event object after the event is already complete, it won't affect anything. There's simply no way to make that work.
Hmm... then how should I do this? I must admit this is my first time working with the Bukkit API, and I'm still fairly new to Java (I've done some modifications to a Lineage II, and a Aion game server written in Java, but that's about it...