Java Code Examples for org.bukkit.Material#POWERED_RAIL

The following examples show how to use org.bukkit.Material#POWERED_RAIL . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConveyorEffect.java    From Civs with GNU General Public License v3.0 6 votes vote down vote up
private void checkForPoweredRail(Region region) {
    Location l = region.getLocation();
    RegionType regionType = (RegionType) ItemManager.getInstance().getItemType(region.getType());
    double radius = regionType.getBuildRadius();
    double x0 = l.getX();
    double y0 = l.getY();
    double z0 = l.getZ();
    outer: for (int x = (int) (x0 - radius); x < x0 + radius; x++) {
        for (int y = (int) (y0 - radius); y < y0 + radius; y++) {
            for (int z = (int) (z0 - radius); z < z0 + radius; z++) {
                Block b = l.getWorld().getBlockAt(x, y, z);
                if (b.getType() == Material.POWERED_RAIL) {
                    Location location = b.getRelative(BlockFace.UP).getLocation();
                    location = Region.idToLocation(Region.blockLocationToString(location));
                    cacheSpawnPoints.put(region, location);
                    break outer;
                }
            }
        }
    }
}
 
Example 2
Source File: ConveyorEffect.java    From Civs with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onPoweredRailBreak(BlockBreakEvent event) {
    if (event.isCancelled() || event.getBlock().getType() != Material.POWERED_RAIL) {
        return;
    }
    Location location = Region.idToLocation(Region.blockLocationToString(event.getBlock().getLocation()));
    ArrayList<Region> regions = new ArrayList<>(RegionManager.getInstance()
            .getRegions(location, 0, false));
    if (regions.isEmpty()) {
        return;
    }
    cacheSpawnPoints.remove(regions.get(0));
}
 
Example 3
Source File: ConveyorEffect.java    From Civs with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onPoweredRailPlace(BlockPlaceEvent event) {
    if (event.getBlockPlaced().getType() != Material.POWERED_RAIL) {
        return;
    }
    checkForPoweredRail(event.getBlockPlaced().getLocation());
}
 
Example 4
Source File: ChestProtectListener.java    From Shopkeepers with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
void onBlockPlace(BlockPlaceEvent event) {
	Block block = event.getBlock();
	Material type = block.getType();
	Player player = event.getPlayer();
	if (Utils.isChest(type)) {
		if (plugin.getProtectedChests().isChestProtected(block, player)) {
			Log.debug("Cancelled placing of chest block by '" + player.getName() + "' at '"
					+ Utils.getLocationString(block) + "': Protected chest nearby");
			event.setCancelled(true);
		}
	} else if (type == Material.HOPPER) {
		if (plugin.getProtectedChests().isProtectedChestAroundHopper(block, player)) {
			Log.debug("Cancelled placing of hopper block by '" + player.getName() + "' at '"
					+ Utils.getLocationString(block) + "': Protected chest nearby");
			event.setCancelled(true);
		}
	} else if (type == Material.RAILS || type == Material.POWERED_RAIL || type == Material.DETECTOR_RAIL || type == Material.ACTIVATOR_RAIL) {
		Block upperBlock = block.getRelative(BlockFace.UP);
		if (Utils.isChest(upperBlock.getType()) && plugin.getProtectedChests().isChestProtected(upperBlock, player)) {
			Log.debug("Cancelled placing of rail block by '" + player.getName() + "' at '"
					+ Utils.getLocationString(block) + "': Protected chest nearby");
			event.setCancelled(true);
			return;
		}
	}
}
 
Example 5
Source File: PoweredRail.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public PoweredRail() {
    super(Material.POWERED_RAIL);
}