C_far

[Spigot] My first plugin V2 - FloorLamp.java

Aug 2nd, 2016
324
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.61 KB | None | 0 0
  1. package fr.c_far.lampfloorauto;
  2.  
  3. import org.bukkit.Material;
  4. import org.bukkit.block.Block;
  5. import org.bukkit.block.BlockFace;
  6.  
  7. public class FloorLamp
  8. {
  9.     private final Material LAMP_ON = Material.REDSTONE_LAMP_ON;
  10.     private final Material LAMP_OFF = Material.REDSTONE_LAMP_OFF;
  11.     private final Material BASE = Material.COBBLE_WALL;
  12.    
  13.     private final int MAX_HEIGHT_FLOOR_LAMP = 6;
  14.    
  15.     public boolean isFloorLamp(Block b)
  16.     {          
  17.         if(!b.getType().equals(BASE)) return false;
  18.        
  19.         Block lamp = getBlockLamp(b);
  20.         Material m = lamp.getType();
  21.        
  22.         if(!(m.equals(LAMP_ON) || m.equals(LAMP_OFF))) return false;
  23.        
  24.         int distance = lamp.getY() - b.getY();
  25.        
  26.         if(distance >= MAX_HEIGHT_FLOOR_LAMP || distance <= 1) return false;
  27.        
  28.         Block fence = b;
  29.        
  30.         for(int i = 1; i < distance; i++)
  31.         {
  32.             fence = fence.getRelative(BlockFace.UP);
  33.             if(!fence.getType().equals(Material.FENCE)) return false;
  34.         }
  35.        
  36.         return true;
  37.     }
  38.    
  39.     public boolean setON(Block b)
  40.     {
  41.         if(!b.getType().equals(BASE)) return false;
  42.  
  43.         getBlockLamp(b).setType(LAMP_ON);
  44.        
  45.         if(LAMP_ON.equals(Material.REDSTONE_LAMP_ON))
  46.         {          
  47.             Block rb = b.getWorld().getHighestBlockAt(b.getLocation());
  48.             rb.setType(Material.REDSTONE_BLOCK);
  49.             rb.setType(Material.AIR);
  50.         }
  51.        
  52.         return true;
  53.     }
  54.    
  55.     public boolean setOFF(Block b)
  56.     {
  57.         if(!b.getType().equals(BASE)) return false;
  58.        
  59.         getBlockLamp(b).setType(LAMP_OFF);
  60.        
  61.         return true;
  62.     }
  63.    
  64.     private Block getBlockLamp(Block b)
  65.     {
  66.         return b.getWorld().getHighestBlockAt(b.getLocation()).getRelative(BlockFace.DOWN);
  67.     }
  68. }
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment