Advertisement
Pickle

Untitled

Jul 10th, 2011
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.59 KB | None | 0 0
  1. package jarvisd.railcounter;
  2.  
  3. import org.bukkit.World;
  4. import org.bukkit.block.Block;
  5. import org.bukkit.block.Sign;
  6. import org.bukkit.event.block.BlockListener;
  7. import org.bukkit.event.block.BlockRedstoneEvent;
  8.  
  9. public class RCBlockRedstoneListener extends BlockListener {
  10.     public static RailCounter plugin;
  11.     public RCBlockRedstoneListener(RailCounter instance)    {
  12.         plugin = instance;
  13.     }
  14.  
  15.     public void onBlockRedstoneChange(BlockRedstoneEvent event) {
  16.         Block block = event.getBlock();
  17.         if (event.getOldCurrent() == 0) {  
  18.                 World world = block.getWorld();
  19.                 int X = block.getX();
  20.                 int Z = block.getZ();
  21.                 int Y = block.getY();
  22.                 //lets look for a sign.
  23.                 IncreaseSignCount(world,X-1,Y,Z);
  24.                 IncreaseSignCount(world,X+1,Y,Z);
  25.                 IncreaseSignCount(world,X,Y,Z-1);
  26.                 IncreaseSignCount(world,X,Y,Z+1);
  27.         }
  28.     }      
  29.    
  30.     public void IncreaseSignCount(World world, int x, int y, int z) {
  31.         Block block = world.getBlockAt(x,y,z);
  32.         if (block.getTypeId() == 63 || block.getTypeId() == 68) {
  33.             Sign sign = (Sign)block.getState();
  34.             String[] lines = sign.getLines();  
  35.              if (lines[0].equalsIgnoreCase("~Counter~")) {
  36.                 int count = 0;
  37.                 if (!lines[2].isEmpty() || lines[2] != null) {
  38.                     try {
  39.                         count = Integer.parseInt(lines[2]);
  40.                     } catch(NumberFormatException e) {
  41.                         System.out.println("Failed to parse sign, invaild number");
  42.                         count = 0;
  43.                     }
  44.                  }
  45.                 count++;
  46.                 sign.setLine(2,String.valueOf(count));
  47.                 try {
  48.                     sign.update();
  49.                 } catch(StackOverflowError e) {
  50.                     System.out.println("fail");
  51.                 }
  52.                 }
  53.             }
  54.         }  
  55.    
  56.    
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement