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.
- for(x=-1;x<=1;x++){
- for(z=-1;z<=1; z++) {
- if(!(x==0 && z==0))
- {
- Block rBlock = block.getRelative(x,0,z);
- if(rBlock.getTypeId() == 63 || rBlock.getTypeId() == 68)
- IncreaseSignCount(rBlock);
- }
- }
- }
- public void IncreaseSignCount(Block block) {
- 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, invalid number");
- count = 0;
- }
- }
- count++;
- sign.setLine(2,Integer.toString(count));
- //sign.update(); <-- fails
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement