Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package jarvisd.railcounter;
- import org.bukkit.World;
- import org.bukkit.block.Block;
- import org.bukkit.block.Sign;
- import org.bukkit.event.block.BlockListener;
- import org.bukkit.event.block.BlockRedstoneEvent;
- public class RCBlockRedstoneListener extends BlockListener {
- public static RailCounter plugin;
- public RCBlockRedstoneListener(RailCounter instance) {
- plugin = instance;
- }
- public void onBlockRedstoneChange(BlockRedstoneEvent event) {
- Block block = event.getBlock();
- if (event.getOldCurrent() == 0) {
- World world = block.getWorld();
- int X = block.getX();
- int Z = block.getZ();
- int Y = block.getY();
- //lets look for a sign.
- IncreaseSignCount(world,X-1,Y,Z);
- IncreaseSignCount(world,X+1,Y,Z);
- IncreaseSignCount(world,X,Y,Z-1);
- IncreaseSignCount(world,X,Y,Z+1);
- }
- }
- public void IncreaseSignCount(World world, int x, int y, int z) {
- Block block = world.getBlockAt(x,y,z);
- if (block.getTypeId() == 63 || block.getTypeId() == 68) {
- Sign sign = (Sign)block.getState();
- String[] lines = sign.getLines();
- if (lines[0].equalsIgnoreCase("~Counter~")) {
- int count = 0;
- if (!lines[2].isEmpty() || lines[2] != null) {
- try {
- count = Integer.parseInt(lines[2]);
- } catch(NumberFormatException e) {
- System.out.println("Failed to parse sign, invaild number");
- count = 0;
- }
- }
- count++;
- sign.setLine(2,String.valueOf(count));
- try {
- sign.update();
- } catch(StackOverflowError e) {
- System.out.println("fail");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement