org.spongepowered.api.block.BlockType Java Examples
The following examples show how to use
org.spongepowered.api.block.BlockType.
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: ItemcanplaceonCommand.java From UltimateCore with MIT License | 6 votes |
@Override public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException { checkIfPlayer(sender); checkPermission(sender, ItemPermissions.UC_ITEM_ITEMCANPLACEON_BASE); Player p = (Player) sender; if (p.getItemInHand(HandTypes.MAIN_HAND).getType().equals(ItemTypes.NONE)) { throw new ErrorMessageException(Messages.getFormatted(p, "item.noiteminhand")); } ItemStack stack = p.getItemInHand(HandTypes.MAIN_HAND); Set<BlockType> types = new HashSet<>(args.<BlockType>getAll("blocktypes")); stack.offer(Keys.PLACEABLE_BLOCKS, types); p.setItemInHand(HandTypes.MAIN_HAND, stack); Text items = Text.joinWith(Text.of(", "), types.stream().map(type -> Text.of(type.getName())).collect(Collectors.toList())); Messages.send(sender, "item.command.itemcanplaceon.success", "%arg%", items); return CommandResult.success(); }
Example #2
Source File: Visualization.java From GriefPrevention with MIT License | 6 votes |
public void addTopLine(World world, int y, BlockType cornerMaterial, BlockType accentMaterial) { BlockSnapshot topVisualBlock1 = snapshotBuilder.from(new Location<World>(world, this.smallx, y, this.bigz)).blockState(cornerMaterial.getDefaultState()).build(); newElements.add(new Transaction<BlockSnapshot>(topVisualBlock1.getLocation().get().createSnapshot(), topVisualBlock1)); this.corners.add(topVisualBlock1.getPosition()); BlockSnapshot topVisualBlock2 = snapshotBuilder.from(new Location<World>(world, this.smallx + 1, y, this.bigz)).blockState(accentMaterial.getDefaultState()).build(); newElements.add(new Transaction<BlockSnapshot>(topVisualBlock2.getLocation().get().createSnapshot(), topVisualBlock2)); BlockSnapshot topVisualBlock3 = snapshotBuilder.from(new Location<World>(world, this.bigx - 1, y, this.bigz)).blockState(accentMaterial.getDefaultState()).build(); newElements.add(new Transaction<BlockSnapshot>(topVisualBlock3.getLocation().get().createSnapshot(), topVisualBlock3)); if (STEP != 0) { for (int x = this.smallx + STEP; x < this.bigx - STEP / 2; x += STEP) { if ((y != 0 && x >= this.smallx && x <= this.bigx) || (x > this.minx && x < this.maxx)) { BlockSnapshot visualBlock = snapshotBuilder.from(new Location<World>(world, x, y, this.bigz)).blockState(accentMaterial.getDefaultState()).build(); newElements.add(new Transaction<BlockSnapshot>(visualBlock.getLocation().get().createSnapshot(), visualBlock)); } } } }
Example #3
Source File: Visualization.java From GriefPrevention with MIT License | 6 votes |
public void addBottomLine(World world, int y, BlockType cornerMaterial, BlockType accentMaterial) { BlockSnapshot bottomVisualBlock1 = this.snapshotBuilder.from(new Location<World>(world, this.smallx + 1, y, this.smallz)).blockState(accentMaterial.getDefaultState()).build(); this.newElements.add(new Transaction<BlockSnapshot>(bottomVisualBlock1.getLocation().get().createSnapshot(), bottomVisualBlock1)); this.corners.add(bottomVisualBlock1.getPosition()); BlockSnapshot bottomVisualBlock2 = this.snapshotBuilder.from(new Location<World>(world, this.bigx - 1, y, this.smallz)).blockState(accentMaterial.getDefaultState()).build(); this.newElements.add(new Transaction<BlockSnapshot>(bottomVisualBlock2.getLocation().get().createSnapshot(), bottomVisualBlock2)); if (STEP != 0) { for (int x = this.smallx + STEP; x < this.bigx - STEP / 2; x += STEP) { if ((y != 0 && x >= this.smallx && x <= this.bigx) || (x > this.minx && x < this.maxx)) { BlockSnapshot visualBlock = this.snapshotBuilder.from(new Location<World>(world, x, y, this.smallz)).blockState(accentMaterial.getDefaultState()).build(); newElements.add(new Transaction<BlockSnapshot>(visualBlock.getLocation().get().createSnapshot(), visualBlock)); } } } }
Example #4
Source File: Visualization.java From GriefPrevention with MIT License | 6 votes |
public void addLeftLine(World world, int y, BlockType cornerMaterial, BlockType accentMaterial) { BlockSnapshot leftVisualBlock1 = snapshotBuilder.from(new Location<World>(world, this.smallx, y, this.smallz)).blockState(cornerMaterial.getDefaultState()).build(); newElements.add(new Transaction<BlockSnapshot>(leftVisualBlock1.getLocation().get().createSnapshot(), leftVisualBlock1)); this.corners.add(leftVisualBlock1.getPosition()); BlockSnapshot leftVisualBlock2 = snapshotBuilder.from(new Location<World>(world, this.smallx, y, this.smallz + 1)).blockState(accentMaterial.getDefaultState()).build(); newElements.add(new Transaction<BlockSnapshot>(leftVisualBlock2.getLocation().get().createSnapshot(), leftVisualBlock2)); BlockSnapshot leftVisualBlock3 = snapshotBuilder.from(new Location<World>(world, this.smallx, y, this.bigz - 1)).blockState(accentMaterial.getDefaultState()).build(); newElements.add(new Transaction<BlockSnapshot>(leftVisualBlock3.getLocation().get().createSnapshot(), leftVisualBlock3)); if (STEP != 0) { for (int z = this.smallz + STEP; z < this.bigz - STEP / 2; z += STEP) { if ((y != 0 && z >= this.smallz && z <= this.bigz) || (z > this.minz && z < this.maxz)) { BlockSnapshot visualBlock = snapshotBuilder.from(new Location<World>(world, this.smallx, y, z)).blockState(accentMaterial.getDefaultState()).build(); newElements.add(new Transaction<BlockSnapshot>(visualBlock.getLocation().get().createSnapshot(), visualBlock)); } } } }
Example #5
Source File: Visualization.java From GriefPrevention with MIT License | 6 votes |
public void addRightLine(World world, int y, BlockType cornerMaterial, BlockType accentMaterial) { BlockSnapshot rightVisualBlock1 = snapshotBuilder.from(new Location<World>(world, this.bigx, y, this.smallz)).blockState(cornerMaterial.getDefaultState()).build(); newElements.add(new Transaction<BlockSnapshot>(rightVisualBlock1.getLocation().get().createSnapshot(), rightVisualBlock1)); this.corners.add(rightVisualBlock1.getPosition()); BlockSnapshot rightVisualBlock2 = snapshotBuilder.from(new Location<World>(world, this.bigx, y, this.smallz + 1)).blockState(accentMaterial.getDefaultState()).build(); newElements.add(new Transaction<BlockSnapshot>(rightVisualBlock2.getLocation().get().createSnapshot(), rightVisualBlock2)); if (STEP != 0) { for (int z = this.smallz + STEP; z < this.bigz - STEP / 2; z += STEP) { if ((y != 0 && z >= this.smallz && z <= this.bigz) || (z > this.minz && z < this.maxz)) { BlockSnapshot visualBlock = snapshotBuilder.from(new Location<World>(world, this.bigx, y, z)).blockState(accentMaterial.getDefaultState()).build(); newElements.add(new Transaction<BlockSnapshot>(visualBlock.getLocation().get().createSnapshot(), visualBlock)); } } } BlockSnapshot rightVisualBlock3 = snapshotBuilder.from(new Location<World>(world, this.bigx, y, this.bigz - 1)).blockState(accentMaterial.getDefaultState()).build(); newElements.add(new Transaction<BlockSnapshot>(rightVisualBlock3.getLocation().get().createSnapshot(), rightVisualBlock3)); BlockSnapshot rightVisualBlock4 = snapshotBuilder.from(new Location<World>(world, this.bigx, y, this.bigz)).blockState(cornerMaterial.getDefaultState()).build(); newElements.add(new Transaction<BlockSnapshot>(rightVisualBlock4.getLocation().get().createSnapshot(), rightVisualBlock4)); this.corners.add(rightVisualBlock4.getPosition()); }
Example #6
Source File: ItemcanbreakCommand.java From UltimateCore with MIT License | 6 votes |
@Override public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException { checkIfPlayer(sender); checkPermission(sender, ItemPermissions.UC_ITEM_ITEMCANBREAK_BASE); Player p = (Player) sender; if (p.getItemInHand(HandTypes.MAIN_HAND).getType().equals(ItemTypes.NONE)) { throw new ErrorMessageException(Messages.getFormatted(p, "item.noiteminhand")); } ItemStack stack = p.getItemInHand(HandTypes.MAIN_HAND); Set<BlockType> types = new HashSet<>(args.<BlockType>getAll("blocktypes")); stack.offer(Keys.BREAKABLE_BLOCK_TYPES, types); p.setItemInHand(HandTypes.MAIN_HAND, stack); Text items = Text.joinWith(Text.of(", "), types.stream().map(type -> Text.of(type.getName())).collect(Collectors.toList())); Messages.send(sender, "item.command.itemcanbreak.success", "%arg%", items); return CommandResult.success(); }
Example #7
Source File: BlockUtil.java From Prism with MIT License | 6 votes |
/** * Get a list of all LIQUID block types. * * @return List<BlockType> */ public static List<BlockType> getLiquidBlockTypes() { List<BlockType> liquids = new ArrayList<>(); Collection<BlockType> types = Sponge.getRegistry().getAllOf(BlockType.class); for (BlockType type : types) { Optional<MatterProperty> property = type.getProperty(MatterProperty.class); if (property.isPresent() && Objects.equals(property.get().getValue(), Matter.LIQUID)) { liquids.add(type); } } // @todo Sponge has not yet implemented the MatterProperties... liquids.add(BlockTypes.LAVA); liquids.add(BlockTypes.FLOWING_LAVA); liquids.add(BlockTypes.WATER); liquids.add(BlockTypes.FLOWING_WATER); return liquids; }
Example #8
Source File: BlockUtil.java From Prism with MIT License | 5 votes |
/** * Reject specific blocks from an applier because they're 99% going to do more harm. * * @param type BlockType * @return */ public static boolean rejectIllegalApplierBlock(BlockType type) { return (type.equals(BlockTypes.FIRE) || type.equals(BlockTypes.TNT) || type.equals(BlockTypes.LAVA) || type.equals(BlockTypes.FLOWING_LAVA)); }
Example #9
Source File: EventUtil.java From Prism with MIT License | 5 votes |
/** * Reject certain events which can only be identified * by the change + cause signature. * * @param a BlockType original * @param b BlockType replacement * @param cause Cause chain from event * @return boolean If should be rejected */ public static boolean rejectBreakEventIdentity(BlockType a, BlockType b, Cause cause) { // Falling blocks if (a.equals(BlockTypes.GRAVEL) && b.equals(BlockTypes.AIR)) { return !cause.first(Player.class).isPresent(); } // Interesting bugs... if (a.equals(BlockTypes.AIR) && b.equals(BlockTypes.AIR)) { return true; } return false; }
Example #10
Source File: EventUtil.java From Prism with MIT License | 5 votes |
/** * Reject certain events which can only be identified * by the change + cause signature. * * @param a BlockType original * @param b BlockType replacement * @param cause Cause chain from event * @return boolean If should be rejected */ public static boolean rejectPlaceEventIdentity(BlockType a, BlockType b, Cause cause) { // Things that eat grass... if (a.equals(BlockTypes.GRASS) && b.equals(BlockTypes.DIRT)) { return cause.first(Living.class).isPresent(); } // Grass-like "Grow" events if (a.equals(BlockTypes.DIRT) && b.equals(BlockTypes.GRASS)) { return cause.first(BlockSnapshot.class).isPresent(); } // If no entity at fault, we don't care about placement that didn't affect anything if (!cause.first(Entity.class).isPresent()) { return (a.equals(BlockTypes.AIR)); } // Natural flow/fire. // Note: This only allows tracking on the source block set by a player using // buckets, or items to set fires. Blocks broken by water, lava or fire are still logged as usual. // Full flow/fire tracking would be hard on the database and is generally unnecessary. if (!cause.first(Player.class).isPresent()) { return (a.equals(BlockTypes.AIR) && (b.equals(BlockTypes.FLOWING_LAVA) || b.equals(BlockTypes.FLOWING_WATER)) || b.equals(BlockTypes.FIRE)); } return false; }
Example #11
Source File: WorldUtil.java From Prism with MIT License | 5 votes |
public static int removeIllegalBlocks(Location<World> location, int radius) { final World world = location.getExtent(); int xMin = location.getBlockX() - radius; int xMax = location.getBlockX() + radius; int zMin = location.getBlockZ() - radius; int zMax = location.getBlockZ() + radius; int yMin = location.getBlockY() - radius; int yMax = location.getBlockY() + radius; // Clamp Y basement if (yMin < 0) { yMin = 0; } // Clamp Y ceiling if (yMax >= world.getDimension().getBuildHeight()) { yMax = world.getDimension().getBuildHeight(); } int changeCount = 0; for (int x = xMin; x <= xMax; x++) { for (int z = zMin; z <= zMax; z++) { for (int y = yMin; y <= yMax; y++) { BlockType existing = world.getBlock(x, y, z).getType(); if (existing.equals(BlockTypes.FIRE) || existing.equals(BlockTypes.TNT)) { world.setBlockType(x, y, z, BlockTypes.AIR); changeCount++; } } } } return changeCount; }
Example #12
Source File: PrismRecord.java From Prism with MIT License | 5 votes |
/** * Save the current record. */ public void save() { DataUtil.writeToDataView(getDataContainer(), DataQueries.Created, new Date()); DataUtil.writeToDataView(getDataContainer(), DataQueries.EventName, getEvent()); DataQuery causeKey = DataQueries.Cause; String causeValue = "environment"; if (getSource() instanceof Player) { causeKey = DataQueries.Player; causeValue = ((Player) getSource()).getUniqueId().toString(); } else if (getSource() instanceof Entity) { causeValue = ((Entity) getSource()).getType().getName(); } DataUtil.writeToDataView(getDataContainer(), causeKey, causeValue); // Source filtered? if (!Prism.getInstance().getFilterList().allowsSource(getSource())) { return; } // Original block filtered? Optional<BlockType> originalBlockType = getDataContainer().getObject(DataQueries.OriginalBlock.then(DataQueries.BlockState).then(DataQueries.BlockType), BlockType.class); if (originalBlockType.map(Prism.getInstance().getFilterList()::allows).orElse(false)) { return; } // Replacement block filtered? Optional<BlockType> replacementBlockType = getDataContainer().getObject(DataQueries.ReplacementBlock.then(DataQueries.BlockState).then(DataQueries.BlockType), BlockType.class); if (replacementBlockType.map(Prism.getInstance().getFilterList()::allows).orElse(false)) { return; } // Queue the finished record for saving RecordingQueue.add(this); }
Example #13
Source File: BlocktypeArgument.java From UltimateCore with MIT License | 5 votes |
@Nullable @Override public BlockType parseValue(CommandSource sender, CommandArgs args) throws ArgumentParseException { String value = args.next(); Optional<BlockType> type = Sponge.getRegistry().getType(CatalogTypes.BLOCK_TYPE, value); if (!type.isPresent()) { throw args.createError(Messages.getFormatted(sender, "item.blocknotfound", "%type%", value)); } return type.get(); }
Example #14
Source File: WorldUtil.java From Prism with MIT License | 5 votes |
/** * Remove a specific block from a given radius around a region. * * @param type BlockType to remove. * @param location Location center * @param radius Integer radius around location * @return integer Count of removals */ public static int removeAroundFromLocation(BlockType type, Location<World> location, int radius) { final World world = location.getExtent(); int xMin = location.getBlockX() - radius; int xMax = location.getBlockX() + radius; int zMin = location.getBlockZ() - radius; int zMax = location.getBlockZ() + radius; int yMin = location.getBlockY() - radius; int yMax = location.getBlockY() + radius; // Clamp Y basement if (yMin < 0) { yMin = 0; } // Clamp Y ceiling if (yMax >= world.getDimension().getBuildHeight()) { yMax = world.getDimension().getBuildHeight(); } int changeCount = 0; for (int x = xMin; x <= xMax; x++) { for (int z = zMin; z <= zMax; z++) { for (int y = yMin; y <= yMax; y++) { if (world.getBlock(x, y, z).getType().equals(type)) { world.setBlockType(x, y, z, BlockTypes.AIR); changeCount++; } } } } return changeCount; }
Example #15
Source File: CommandHelper.java From GriefPrevention with MIT License | 5 votes |
private static boolean validateBlockTarget(String target) { Optional<BlockType> blockType = Sponge.getRegistry().getType(BlockType.class, target); if (blockType.isPresent()) { return true; } Optional<BlockState> blockState = Sponge.getRegistry().getType(BlockState.class, target); if (blockState.isPresent()) { return true; } return false; }
Example #16
Source File: WorldUtil.java From Prism with MIT License | 5 votes |
/** * Drain all liquids from a radius around a given location. * * @param location Location center * @param radius Integer radius around location * @return integer Count of removals */ public static int removeLiquidsAroundLocation(Location<World> location, int radius) { int changeCount = 0; for (BlockType liquid : BlockUtil.getLiquidBlockTypes()) { changeCount = removeAroundFromLocation(liquid, location, radius); } return changeCount; }
Example #17
Source File: PlayerEventHandler.java From GriefPrevention with MIT License | 5 votes |
private GPClaim findNearbyClaim(Player player) { int maxDistance = GriefPreventionPlugin.instance.maxInspectionDistance; BlockRay<World> blockRay = BlockRay.from(player).distanceLimit(maxDistance).build(); GPPlayerData playerData = GriefPreventionPlugin.instance.dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId()); GPClaim claim = null; int count = 0; while (blockRay.hasNext()) { BlockRayHit<World> blockRayHit = blockRay.next(); Location<World> location = blockRayHit.getLocation(); claim = this.dataStore.getClaimAt(location); if (claim != null && !claim.isWilderness() && (playerData.visualBlocks == null || (claim.id != playerData.visualClaimId))) { playerData.lastValidInspectLocation = location; return claim; } BlockType blockType = location.getBlockType(); if (blockType != BlockTypes.AIR && blockType != BlockTypes.TALLGRASS) { break; } count++; } if (count == maxDistance) { GriefPreventionPlugin.sendMessage(player, GriefPreventionPlugin.instance.messageData.claimTooFar.toText()); } else if (claim != null && claim.isWilderness()){ GriefPreventionPlugin.sendMessage(player, GriefPreventionPlugin.instance.messageData.blockNotClaimed.toText()); } return claim; }
Example #18
Source File: Visualization.java From GriefPrevention with MIT License | 5 votes |
public void addCorners(World world, int y, BlockType accentMaterial) { BlockSnapshot corner1 = snapshotBuilder.from(new Location<World>(world, this.smallx, y, this.bigz)).blockState(accentMaterial.getDefaultState()).build(); newElements.add(new Transaction<BlockSnapshot>(corner1.getLocation().get().createSnapshot(), corner1)); BlockSnapshot corner2 = snapshotBuilder.from(new Location<World>(world, this.bigx, y, this.bigz)).blockState(accentMaterial.getDefaultState()).build(); newElements.add(new Transaction<BlockSnapshot>(corner2.getLocation().get().createSnapshot(), corner2)); BlockSnapshot corner3 = snapshotBuilder.from(new Location<World>(world, this.bigx, y, this.smallz)).blockState(accentMaterial.getDefaultState()).build(); newElements.add(new Transaction<BlockSnapshot>(corner3.getLocation().get().createSnapshot(), corner3)); BlockSnapshot corner4 = snapshotBuilder.from(new Location<World>(world, this.smallx, y, this.smallz)).blockState(accentMaterial.getDefaultState()).build(); newElements.add(new Transaction<BlockSnapshot>(corner4.getLocation().get().createSnapshot(), corner4)); }
Example #19
Source File: BlockUtil.java From Prism with MIT License | 5 votes |
/** * Sponge's ChangeBlockEvent.Place covers a lot, but it also includes a lot * we don't want. So here we can setup checks to filter out block combinations. * * @param a BlockType original * @param b BlockType final * @return boolean True if combo should be rejected */ public static boolean rejectPlaceCombination(BlockType a, BlockType b) { return ( // Just basic state changes a.equals(BlockTypes.LIT_FURNACE) || b.equals(BlockTypes.LIT_FURNACE) || a.equals(BlockTypes.LIT_REDSTONE_LAMP) || b.equals(BlockTypes.LIT_REDSTONE_LAMP) || a.equals(BlockTypes.LIT_REDSTONE_ORE) || b.equals(BlockTypes.LIT_REDSTONE_ORE) || a.equals(BlockTypes.UNLIT_REDSTONE_TORCH) || b.equals(BlockTypes.UNLIT_REDSTONE_TORCH) || (a.equals(BlockTypes.POWERED_REPEATER) && b.equals(BlockTypes.UNPOWERED_REPEATER)) || (a.equals(BlockTypes.UNPOWERED_REPEATER) && b.equals(BlockTypes.POWERED_REPEATER)) || (a.equals(BlockTypes.POWERED_COMPARATOR) && b.equals(BlockTypes.UNPOWERED_COMPARATOR)) || (a.equals(BlockTypes.UNPOWERED_COMPARATOR) && b.equals(BlockTypes.POWERED_COMPARATOR)) || // It's all water... (a.equals(BlockTypes.WATER) && b.equals(BlockTypes.FLOWING_WATER)) || (a.equals(BlockTypes.FLOWING_WATER) && b.equals(BlockTypes.WATER)) || // It's all lava.... (a.equals(BlockTypes.LAVA) && b.equals(BlockTypes.FLOWING_LAVA)) || (a.equals(BlockTypes.FLOWING_LAVA) && b.equals(BlockTypes.LAVA)) || // Crap that fell into lava (a.equals(BlockTypes.LAVA) && b.equals(BlockTypes.GRAVEL)) || (a.equals(BlockTypes.FLOWING_LAVA) && b.equals(BlockTypes.GRAVEL)) || (a.equals(BlockTypes.LAVA) && b.equals(BlockTypes.SAND)) || (a.equals(BlockTypes.FLOWING_LAVA) && b.equals(BlockTypes.SAND)) || // It's fire (which didn't burn anything) (a.equals(BlockTypes.FIRE) && b.equals(BlockTypes.AIR)) || // Piston a.equals(BlockTypes.PISTON_EXTENSION) || b.equals(BlockTypes.PISTON_EXTENSION) || a.equals(BlockTypes.PISTON_HEAD) || b.equals(BlockTypes.PISTON_HEAD) || // You can't place air b.equals(BlockTypes.AIR) ); }
Example #20
Source File: BlockTypeFilter.java From Web-API with MIT License | 5 votes |
public BlockTypeFilter(WebHook hook, ConfigurationNode config) { super(hook, config); try { types = config.getList(TypeToken.of(BlockType.class)); } catch (ObjectMappingException e) { e.printStackTrace(); } }
Example #21
Source File: BlockUtil.java From Prism with MIT License | 5 votes |
/** * Sponge's ChangeBlockEvent.Break covers a lot, but it also includes a lot * we don't want. So here we can setup checks to filter out block combinations. * * @param a BlockType original * @param b BlockType final * @return boolean True if combo should be rejected */ public static boolean rejectBreakCombination(BlockType a, BlockType b) { return ( // You can't break these... a.equals(BlockTypes.FIRE) || a.equals(BlockTypes.AIR) || // Note, see "natural flow" comment above. ((a.equals(BlockTypes.FLOWING_WATER) || a.equals(BlockTypes.FLOWING_LAVA)) && b.equals(BlockTypes.AIR)) || // Piston a.equals(BlockTypes.PISTON_EXTENSION) || b.equals(BlockTypes.PISTON_EXTENSION) || a.equals(BlockTypes.PISTON_HEAD) || b.equals(BlockTypes.PISTON_HEAD) ); }
Example #22
Source File: GDPermissionManager.java From GriefDefender with MIT License | 5 votes |
private Set<Context> addBlockContexts(Set<Context> contexts, BlockType block, boolean isSource) { if (NMSUtil.getInstance().isBlockCrops(block)) { if (isSource) { contexts.add(ContextGroups.SOURCE_CROPS); } else { contexts.add(ContextGroups.TARGET_CROPS); } } return contexts; }
Example #23
Source File: CommandHelper.java From GriefDefender with MIT License | 5 votes |
private static boolean validateBlockTarget(String target) { Optional<BlockType> blockType = Sponge.getRegistry().getType(BlockType.class, target); if (blockType.isPresent()) { return true; } Optional<BlockState> blockState = Sponge.getRegistry().getType(BlockState.class, target); if (blockState.isPresent()) { return true; } return false; }
Example #24
Source File: ChangeBlockListener.java From Prism with MIT License | 4 votes |
/** * Listens to the base change block event. * * @param event ChangeBlockEvent */ @Listener(order = Order.POST) public void onChangeBlock(ChangeBlockEvent event) { if (event.getCause().allOf(PluginContainer.class).stream().map(PluginContainer::getId).anyMatch(id -> Prism.getInstance().getConfig().getGeneralCategory().getBlacklist().contains(id))) { // Don't do anything return; } if (event.getCause().first(Player.class).map(Player::getUniqueId).map(Prism.getInstance().getActiveWands()::contains).orElse(false)) { // Cancel and exit event here, not supposed to place/track a block with an active wand. event.setCancelled(true); return; } if (event.getTransactions().isEmpty() || (!Prism.getInstance().getConfig().getEventCategory().isBlockBreak() && !Prism.getInstance().getConfig().getEventCategory().isBlockDecay() && !Prism.getInstance().getConfig().getEventCategory().isBlockGrow() && !Prism.getInstance().getConfig().getEventCategory().isBlockPlace())) { return; } for (Transaction<BlockSnapshot> transaction : event.getTransactions()) { if (!transaction.isValid() || !transaction.getOriginal().getLocation().isPresent()) { continue; } BlockType originalBlockType = transaction.getOriginal().getState().getType(); BlockType finalBlockType = transaction.getFinal().getState().getType(); PrismRecord.EventBuilder eventBuilder = PrismRecord.create() .source(event.getCause()) .blockOriginal(transaction.getOriginal()) .blockReplacement(transaction.getFinal()) .location(transaction.getOriginal().getLocation().get()); if (event instanceof ChangeBlockEvent.Break) { if (!Prism.getInstance().getConfig().getEventCategory().isBlockBreak() || BlockUtil.rejectBreakCombination(originalBlockType, finalBlockType) || EventUtil.rejectBreakEventIdentity(originalBlockType, finalBlockType, event.getCause())) { continue; } eventBuilder .event(PrismEvents.BLOCK_BREAK) .target(originalBlockType.getId().replace("_", " ")) .buildAndSave(); } else if (event instanceof ChangeBlockEvent.Decay) { if (!Prism.getInstance().getConfig().getEventCategory().isBlockDecay()) { continue; } eventBuilder .event(PrismEvents.BLOCK_DECAY) .target(originalBlockType.getId().replace("_", " ")) .buildAndSave(); } else if (event instanceof ChangeBlockEvent.Grow) { if (!Prism.getInstance().getConfig().getEventCategory().isBlockGrow()) { continue; } eventBuilder .event(PrismEvents.BLOCK_GROW) .target(finalBlockType.getId().replace("_", " ")) .buildAndSave(); } else if (event instanceof ChangeBlockEvent.Place) { if (!Prism.getInstance().getConfig().getEventCategory().isBlockPlace() || BlockUtil.rejectPlaceCombination(originalBlockType, finalBlockType) || EventUtil.rejectPlaceEventIdentity(originalBlockType, finalBlockType, event.getCause())) { continue; } eventBuilder .event(PrismEvents.BLOCK_PLACE) .target(finalBlockType.getId().replace("_", " ")) .buildAndSave(); } } }
Example #25
Source File: CommandHandlers.java From RedProtect with GNU General Public License v3.0 | 4 votes |
public static void handletp(CommandSource source, String rname, World world, Player play) { Region region = RedProtect.get().rm.getRegion(rname, world.getName()); if (region == null) { RedProtect.get().lang.sendMessage(source, RedProtect.get().lang.get("cmdmanager.region.doesntexist") + ": " + rname); return; } if (play == null) { if (source instanceof Player && !RedProtect.get().ph.hasRegionPermMember((Player) source, "teleport", region)) { RedProtect.get().lang.sendMessage(source, "no.permission"); return; } } else { if (!RedProtect.get().ph.hasPerm(source, "redprotect.command.admin.teleport")) { RedProtect.get().lang.sendMessage(source, "no.permission"); return; } } Location<World> loc = null; if (region.getTPPoint() != null) { loc = new Location<>(world, region.getTPPoint().getBlockX() + 0.500, region.getTPPoint().getBlockY(), region.getTPPoint().getBlockZ() + 0.500); } else { int limit = world.getBlockMax().getY(); if (world.getDimension().getType().equals(DimensionTypes.NETHER)) { limit = 124; } for (int i = limit; i > 0; i--) { BlockType mat = world.createSnapshot(region.getCenterX(), i, region.getCenterZ()).getState().getType(); BlockType mat1 = world.createSnapshot(region.getCenterX(), i + 1, region.getCenterZ()).getState().getType(); BlockType mat2 = world.createSnapshot(region.getCenterX(), i + 2, region.getCenterZ()).getState().getType(); if (!mat.equals(BlockTypes.LAVA) && !mat.equals(BlockTypes.AIR) && mat1.equals(BlockTypes.AIR) && mat2.equals(BlockTypes.AIR)) { loc = new Location<>(world, region.getCenterX() + 0.500, i + 1, region.getCenterZ() + 0.500); break; } } } if (loc != null) { if (play != null) { play.setLocation(loc); RedProtect.get().lang.sendMessage(play, RedProtect.get().lang.get("cmdmanager.region.teleport") + " " + rname); RedProtect.get().lang.sendMessage(source, RedProtect.get().lang.get("cmdmanager.region.tpother") + " " + rname); } else if (source instanceof Player) { tpWait((Player) source, loc, rname); } } }
Example #26
Source File: RestoreNatureProcessingTask.java From GriefPrevention with MIT License | 4 votes |
private void fillHolesAndTrenches() { ArrayList<BlockType> fillableBlocks = new ArrayList<BlockType>(); fillableBlocks.add(BlockTypes.AIR); fillableBlocks.add(BlockTypes.WATER); fillableBlocks.add(BlockTypes.LAVA); fillableBlocks.add(BlockTypes.TALLGRASS); ArrayList<BlockType> notSuitableForFillBlocks = new ArrayList<BlockType>(); notSuitableForFillBlocks.add(BlockTypes.TALLGRASS); notSuitableForFillBlocks.add(BlockTypes.CACTUS); notSuitableForFillBlocks.add(BlockTypes.WATER); notSuitableForFillBlocks.add(BlockTypes.LAVA); notSuitableForFillBlocks.add(BlockTypes.LOG); notSuitableForFillBlocks.add(BlockTypes.LOG2); boolean changed; do { changed = false; for (int x = 1; x < snapshots.length - 1; x++) { for (int z = 1; z < snapshots[0][0].length - 1; z++) { for (int y = 0; y < snapshots[0].length - 1; y++) { BlockSnapshot block = this.snapshots[x][y][z]; if (!fillableBlocks.contains(block.getState().getType())) { continue; } BlockSnapshot leftBlock = this.snapshots[x + 1][y][z]; BlockSnapshot rightBlock = this.snapshots[x - 1][y][z]; if (!fillableBlocks.contains(leftBlock.getState().getType()) && !fillableBlocks.contains(rightBlock.getState().getType())) { if (!notSuitableForFillBlocks.contains(rightBlock.getState().getType())) { this.snapshots[x][y][z] = block.withState(rightBlock.getState().getType().getDefaultState()); changed = true; } } BlockSnapshot upBlock = this.snapshots[x][y][z + 1]; BlockSnapshot downBlock = this.snapshots[x][y][z - 1]; if (!fillableBlocks.contains(upBlock.getState().getType()) && !fillableBlocks.contains(downBlock.getState().getType())) { if (!notSuitableForFillBlocks.contains(downBlock.getState().getType())) { this.snapshots[x][y][z] = block.withState(downBlock.getState().getType().getDefaultState()); changed = true; } } } } } } while (changed); }
Example #27
Source File: RestoreNatureProcessingTask.java From GriefPrevention with MIT License | 4 votes |
private void removeWallsAndTowers() { List<BlockType> excludedBlocksArray = new ArrayList<BlockType>(); excludedBlocksArray.add(BlockTypes.CACTUS); excludedBlocksArray.add(BlockTypes.TALLGRASS); excludedBlocksArray.add(BlockTypes.RED_MUSHROOM); excludedBlocksArray.add(BlockTypes.BROWN_MUSHROOM); excludedBlocksArray.add(BlockTypes.DEADBUSH); excludedBlocksArray.add(BlockTypes.SAPLING); excludedBlocksArray.add(BlockTypes.YELLOW_FLOWER); excludedBlocksArray.add(BlockTypes.RED_FLOWER); excludedBlocksArray.add(BlockTypes.REEDS); excludedBlocksArray.add(BlockTypes.VINE); excludedBlocksArray.add(BlockTypes.PUMPKIN); excludedBlocksArray.add(BlockTypes.WATERLILY); excludedBlocksArray.add(BlockTypes.LEAVES); boolean changed; do { changed = false; for (int x = 1; x < snapshots.length - 1; x++) { for (int z = 1; z < snapshots[0][0].length - 1; z++) { int thisy = this.highestY(x, z, false); if (excludedBlocksArray.contains(this.snapshots[x][thisy][z].getState().getType())) { continue; } int righty = this.highestY(x + 1, z, false); int lefty = this.highestY(x - 1, z, false); while (lefty < thisy && righty < thisy) { this.snapshots[x][thisy--][z] = this.snapshots[x][thisy--][z].withState(BlockTypes.AIR.getDefaultState()); changed = true; } int upy = this.highestY(x, z + 1, false); int downy = this.highestY(x, z - 1, false); while (upy < thisy && downy < thisy) { this.snapshots[x][thisy--][z] = this.snapshots[x][thisy--][z].withState(BlockTypes.AIR.getDefaultState()); changed = true; } } } } while (changed); }
Example #28
Source File: RestoreNatureProcessingTask.java From GriefPrevention with MIT License | 4 votes |
public RestoreNatureProcessingTask(BlockSnapshot[][][] snapshots, int miny, DimensionType environment, BiomeType biome, Location<World> lesserBoundaryCorner, Location<World> greaterBoundaryCorner, int seaLevel, boolean aggressiveMode, boolean creativeMode, Player player) { this.snapshots = snapshots; this.miny = miny; if (this.miny < 0) { this.miny = 0; } this.environment = environment; this.lesserBoundaryCorner = lesserBoundaryCorner; this.greaterBoundaryCorner = greaterBoundaryCorner; this.biome = biome; this.seaLevel = seaLevel; this.aggressiveMode = aggressiveMode; this.player = player; this.creativeMode = creativeMode; this.notAllowedToHang = new ArrayList<BlockType>(); this.notAllowedToHang.add(BlockTypes.DIRT); this.notAllowedToHang.add(BlockTypes.TALLGRASS); this.notAllowedToHang.add(BlockTypes.SNOW); this.notAllowedToHang.add(BlockTypes.LOG); if (this.aggressiveMode) { this.notAllowedToHang.add(BlockTypes.GRASS); this.notAllowedToHang.add(BlockTypes.STONE); } this.playerBlocks = new ArrayList<BlockType>(); this.playerBlocks.addAll(RestoreNatureProcessingTask.getPlayerBlocks(this.environment, this.biome)); // in aggressive or creative world mode, also treat these blocks as user placed, to be removed // this is helpful in the few cases where griefers intentionally use natural blocks to grief, // like a single-block tower of iron ore or a giant penis constructed with melons if (this.aggressiveMode || this.creativeMode) { this.playerBlocks.add(BlockTypes.IRON_ORE); this.playerBlocks.add(BlockTypes.GOLD_ORE); this.playerBlocks.add(BlockTypes.DIAMOND_ORE); this.playerBlocks.add(BlockTypes.MELON_BLOCK); this.playerBlocks.add(BlockTypes.MELON_STEM); this.playerBlocks.add(BlockTypes.BEDROCK); this.playerBlocks.add(BlockTypes.COAL_ORE); this.playerBlocks.add(BlockTypes.PUMPKIN); this.playerBlocks.add(BlockTypes.PUMPKIN_STEM); } if (this.aggressiveMode) { this.playerBlocks.add(BlockTypes.LEAVES); this.playerBlocks.add(BlockTypes.LOG); this.playerBlocks.add(BlockTypes.LOG2); this.playerBlocks.add(BlockTypes.VINE); } }
Example #29
Source File: BlockTypeFilter.java From Web-API with MIT License | 4 votes |
@Override protected void _writeToConfig(ConfigurationNode node) throws ObjectMappingException { node.getNode("config").setValue(new TypeToken<List<BlockType>>() {}, this.types); }
Example #30
Source File: BlockStateDeserializer.java From Web-API with MIT License | 4 votes |
@Override public BlockState deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { JsonNode root = p.readValueAsTree(); if (root.path("type").isMissingNode()) { throw new IOException("Missing block type"); } String typeStr = root.path("type").isTextual() ? root.path("type").asText() : root.path("type").path("id").asText(); Optional<BlockType> optType = Sponge.getRegistry().getType(BlockType.class, typeStr); if (!optType.isPresent()) { throw new IOException("Invalid block type " + typeStr); } BlockType type = optType.get(); BlockState state = type.getDefaultState(); Collection<BlockTrait<?>> traits = type.getTraits(); if (!root.path("data").isMissingNode()) { Iterator<Map.Entry<String, JsonNode>> it = root.path("data").fields(); while (it.hasNext()) { Map.Entry<String, JsonNode> entry = it.next(); Optional<BlockTrait<?>> optTrait = traits.stream().filter(t -> t.getName().equalsIgnoreCase(entry.getKey()) ).findAny(); if (!optTrait.isPresent()) throw new IOException("Unknown trait '" + entry.getKey() + "'"); BlockTrait trait = optTrait.get(); Object value = null; JsonNode nodeValue = entry.getValue(); if (nodeValue.isBoolean()) { value = nodeValue.asBoolean(); } else if (nodeValue.isInt()) { value = nodeValue.asInt(); } else if (nodeValue.isTextual()) { Collection<?> values = trait.getPossibleValues(); Optional<?> val = values.stream() .filter(v -> v.toString().equalsIgnoreCase(nodeValue.asText())) .findAny(); if (!val.isPresent()) { String allowedValues = values.stream() .map(Object::toString) .collect(Collectors.joining(", ")); throw new IOException("Trait '" + trait.getName() + "' has value '" + nodeValue.asText() + "' but can only have one of: " + allowedValues); } else { value = val.get(); } } Optional<BlockState> newState = state.withTrait(trait, value); if (!newState.isPresent()) throw new IOException("Could not apply trait '" + trait.getName() + " to block state"); state = newState.get(); } } return state; }