下面列出了org.bukkit.Material#POWERED_RAIL 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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;
}
}
}
}
}
@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));
}
@EventHandler(ignoreCancelled = true)
public void onPoweredRailPlace(BlockPlaceEvent event) {
if (event.getBlockPlaced().getType() != Material.POWERED_RAIL) {
return;
}
checkForPoweredRail(event.getBlockPlaced().getLocation());
}
@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;
}
}
}
public PoweredRail() {
super(Material.POWERED_RAIL);
}