Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.52 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.     public void onBlockRedstoneChange(BlockRedstoneEvent event) {
  15.         Block block = event.getBlock();
  16.         if (event.getOldCurrent() == 0) {  
  17.                 World world = block.getWorld();
  18.                 int X = block.getX();
  19.                 int Z = block.getZ();
  20.                 int Y = block.getY();
  21.                 //lets look for a sign.
  22.                 for(x=-1;x<=1;x++){
  23.                     for(z=-1;z<=1; z++) {
  24.                 if(!(x==0 && z==0))
  25.                 {
  26.                 Block rBlock = block.getRelative(x,0,z);
  27.                 if(rBlock.getTypeId() == 63 || rBlock.getTypeId() == 68)
  28.                 IncreaseSignCount(rBlock);
  29.                 }
  30.         }
  31.     }      
  32.    
  33.     public void IncreaseSignCount(Block block) {
  34.         if (block.getTypeId() == 63 || block.getTypeId() == 68) {
  35.             Sign sign = (Sign)block.getState();
  36.             String[] lines = sign.getLines();  
  37.              if (lines[0].equalsIgnoreCase("~Counter~")) {
  38.                 int count = 0;
  39.                 if (!lines[2].isEmpty() || lines[2] != null) {
  40.                     try {
  41.                         count = Integer.parseInt(lines[2]);
  42.                     } catch(NumberFormatException e) {
  43.                         System.out.println("Failed to parse sign, invalid number");
  44.                         count = 0;
  45.                     }
  46.                  }
  47.                 count++;
  48.                 sign.setLine(2,Integer.toString(count));
  49.                 //sign.update(); <-- fails
  50.             }
  51.         }  
  52.     }
  53.    
  54.    
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement