@Subscribe public void onBlockPlace(PlayerPlaceBlockEvent event) { Player player = event.getEntity(); World world = player.getWorld(); String worldname = world.getName(); org.spongepowered.api.world.Location blockLoc = event.getLocation(); final Location loc = SpongeUtil.getLocation(worldname, blockLoc); final Plot plot = MainUtil.getPlot(loc); if (plot != null) { if (blockLoc.getY() == 0) { event.setCancelled(true); return; } final PlotPlayer pp = SpongeUtil.getPlayer(player); if (!plot.hasOwner()) { if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_UNOWNED)) { return; } MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_UNOWNED); event.setCancelled(true); return; } else if (!plot.isAdded(pp.getUUID())) { final Flag destroy = FlagManager.getPlotFlag(plot, "place"); BlockState state = blockLoc.getBlock(); if ((destroy != null) && ((HashSet<PlotBlock>) destroy.getValue()) .contains(SpongeMain.THIS.getPlotBlock(state))) { return; } if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) { return; } MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_OTHER); event.setCancelled(true); } else if (Settings.DONE_RESTRICTS_BUILDING && plot.getSettings().flags.containsKey("done")) { if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) { MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER); event.setCancelled(true); return; } } return; } final PlotPlayer pp = SpongeUtil.getPlayer(player); if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_ROAD)) { return; } if (MainUtil.isPlotArea(loc)) { MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_ROAD); event.setCancelled(true); } }
/** * Gets whether or not the block at this location is a sign. * * @param block The location to check * @return If it is a sign */ public static boolean isSign(Location<?> block) { return isSign(block.getBlock()); }
@Override public boolean triggerMechanic(Location block, Sign sign, Human human, Boolean forceState) { if (!SignUtil.getTextRaw(sign, 1).equals("[Door]")) { Direction back = SignUtil.getTextRaw(sign, 1).equals("[Door Up]") ? Direction.UP : Direction.DOWN; Location baseBlock = block.getRelative(back); Location otherSide = getOtherEnd(block, back, maximumLength); if (otherSide == null) { if (human instanceof CommandSource) ((CommandSource) human).sendMessage(Texts.builder("Missing other end!").build()); return true; } Location otherBase = otherSide.getRelative(back.getOpposite()); if (!baseBlock.getBlock().equals(otherBase.getBlock())) { if (human instanceof CommandSource) ((CommandSource) human) .sendMessage(Texts.builder("Both ends must be the same material!").build()); return true; } int leftBlocks = 0, rightBlocks = 0; // Default to 0. Single width bridge is the default. Location left = baseBlock.getRelative(SignUtil.getLeft(block)); Location right = baseBlock.getRelative(SignUtil.getRight(block)); // Calculate left distance Location otherLeft = otherBase.getRelative(SignUtil.getLeft(block)); while (true) { if (leftBlocks >= maximumWidth) break; if (left.getBlock().equals(baseBlock.getBlock()) && otherLeft.getBlock().equals(baseBlock.getBlock())) { leftBlocks++; left = left.getRelative(SignUtil.getLeft(block)); otherLeft = otherLeft.getRelative(SignUtil.getLeft(block)); } else { break; } } // Calculate right distance Location otherRight = otherBase.getRelative(SignUtil.getRight(block)); while (true) { if (rightBlocks >= maximumWidth) break; if (right.getBlock().equals(baseBlock.getBlock()) && otherRight.getBlock().equals(baseBlock.getBlock())) { rightBlocks++; right = right.getRelative(SignUtil.getRight(block)); otherRight = otherRight.getRelative(SignUtil.getRight(block)); } else { break; } } baseBlock = baseBlock.getRelative(back); BlockState type = block.getRelative(back).getBlock(); if (baseBlock.getBlock().equals(type) && (forceState == null || !forceState)) type = BlockTypes.AIR.getDefaultState(); while (baseBlock.getBlockY() != otherSide.getBlockY() + (back == Direction.UP ? -1 : 1)) { baseBlock.setBlock(type); left = baseBlock.getRelative(SignUtil.getLeft(block)); for (int i = 0; i < leftBlocks; i++) { left.setBlock(type); left = left.getRelative(SignUtil.getLeft(block)); } right = baseBlock.getRelative(SignUtil.getRight(block)); for (int i = 0; i < rightBlocks; i++) { right.setBlock(type); right = right.getRelative(SignUtil.getRight(block)); } baseBlock = baseBlock.getRelative(back); } } else { if (human instanceof CommandSource) ((CommandSource) human) .sendMessage(Texts.builder("Door not activatable from here!").build()); return false; } return true; }