org.spongepowered.api.data.Transaction Java Examples
The following examples show how to use
org.spongepowered.api.data.Transaction.
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: BlockprotectionListener.java From UltimateCore with MIT License | 6 votes |
@Listener public void onBreak(ChangeBlockEvent.Break event) { ModuleConfig config = Modules.BLOCKPROTECTION.get().getConfig().get(); if (!config.get().getNode("protections", "allow-interact-primary").getBoolean()) return; Player p = event.getCause().first(Player.class).orElse(null); boolean modified = false; for (Protection prot : GlobalData.get(BlockprotectionKeys.PROTECTIONS).get()) { //Ignore protection if the player is allowed to modify it if (p != null && prot.getPlayers().contains(p.getUniqueId())) continue; //For each location of the protection, for (Transaction trans : event.getTransactions().stream().filter(trans -> trans.getFinal().getLocation().isPresent() && prot.getLocations().contains(trans.getFinal().getLocation().get())).collect(Collectors.toList())) { modified = true; trans.setValid(false); } //If anything has been cancelled & caused by player, send message if (p != null && modified) { p.sendMessage(prot.getLocktype().getErrorMessage(p, prot)); } } }
Example #2
Source File: EntityResult.java From Prism with MIT License | 6 votes |
@Override public ActionableResult rollback() { DataView entityData = formatEntityData(); Optional<EntitySnapshot> snapshot = Sponge.getRegistry().createBuilder(Builder.class).build(entityData); if (!snapshot.isPresent()) { return ActionableResult.skipped(SkipReason.INVALID); } Optional<Entity> entity = snapshot.get().restore(); if (!entity.isPresent()) { return ActionableResult.skipped(SkipReason.INVALID); } // Don't let it burn to death (again?) entity.get().get(IgniteableData.class).ifPresent(data -> entity.get().offer(data.fireTicks().set(0))); // Heal, it was probably killed. entity.get().get(HealthData.class).ifPresent(data -> entity.get().offer(data.health().set(data.maxHealth().get()))); return ActionableResult.success(new Transaction<>(new SerializableNonExistent(), entity.get())); }
Example #3
Source File: SignListener.java From UltimateCore with MIT License | 6 votes |
@Listener public void onSignDestroy(ChangeBlockEvent.Break event, @Root Player p) { for (Transaction<BlockSnapshot> transaction : event.getTransactions()) { BlockSnapshot snapshot = transaction.getOriginal(); if (snapshot.supports(Keys.SIGN_LINES) && snapshot.getLocation().isPresent()) { List<Text> texts = snapshot.get(Keys.SIGN_LINES).get(); //Checking for sign contents for (UCSign usign : UltimateCore.get().getSignService().get().getRegisteredSigns()) { if (texts.get(0).toPlain().equalsIgnoreCase("[" + usign.getIdentifier() + "]")) { if (!p.hasPermission(usign.getDestroyPermission().get())) { Messages.send(p, "core.nopermissions"); } SignDestroyEvent cevent = new SignDestroyEvent(usign, snapshot.getLocation().get(), Cause.builder().append(UltimateCore.getContainer()).append(p).build(EventContext.builder().build())); Sponge.getEventManager().post(cevent); if (!cevent.isCancelled() && usign.onDestroy(p, event, texts)) { Messages.send(p, "sign.destroy", "%sign%", usign.getIdentifier()); } } } } } }
Example #4
Source File: ExplosionListener.java From Nations with MIT License | 6 votes |
@Listener(order=Order.FIRST, beforeModifications = true) public void onExplosion(ExplosionEvent.Post event) { if (!ConfigHandler.getNode("worlds").getNode(event.getTargetWorld().getName()).getNode("enabled").getBoolean()) { return; } if (event.getTransactions().size() > 100) { event.setCancelled(true); } for (Transaction<BlockSnapshot> transaction : event.getTransactions()) { BlockSnapshot blockSnapshot = transaction.getOriginal(); if (blockSnapshot.getLocation().isPresent() && !DataHandler.getFlag("explosions", blockSnapshot.getLocation().get())) { transaction.setValid(false); } } }
Example #5
Source File: BlacklistListener.java From EssentialCmds with MIT License | 6 votes |
@Listener public void onBreakBlock(ChangeBlockEvent.Break event, @Root Player player) { if (!player.hasPermission("essentialcmds.blacklist.bypass")) { for (Transaction<BlockSnapshot> transaction : event.getTransactions()) { if (Utils.getBlacklistItems().contains(transaction.getOriginal().getState().getType().getId())) { if (Utils.areBlacklistMsgsEnabled()) player.sendMessage(Text.of(TextColors.RED, "The item ", TextColors.GRAY, transaction.getFinal().getState().getType().getId(), TextColors.RED, " has been confiscated as it is blacklisted.")); event.setCancelled(true); } } } }
Example #6
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 #7
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 #8
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 #9
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 #10
Source File: BlacklistListener.java From EssentialCmds with MIT License | 6 votes |
@Listener public void onPlaceBlock(ChangeBlockEvent.Place event, @Root Player player) { if (!player.hasPermission("essentialcmds.blacklist.bypass")) { for (Transaction<BlockSnapshot> transaction : event.getTransactions()) { if (Utils.getBlacklistItems().contains(transaction.getFinal().getState().getType().getId())) { if (Utils.areBlacklistMsgsEnabled()) player.sendMessage(Text.of(TextColors.RED, "The item ", TextColors.GRAY, transaction.getFinal().getState().getType().getId(), TextColors.RED, " has been confiscated as it is blacklisted.")); event.setCancelled(true); } } } }
Example #11
Source File: EventForwarder.java From BlueMap with MIT License | 5 votes |
@Listener(order = Order.POST) @Exclude({ChangeBlockEvent.Post.class, ChangeBlockEvent.Pre.class, ChangeBlockEvent.Modify.class}) public void onBlockChange(ChangeBlockEvent evt) { for (Transaction<BlockSnapshot> tr : evt.getTransactions()) { if(!tr.isValid()) continue; Optional<Location<org.spongepowered.api.world.World>> ow = tr.getFinal().getLocation(); if (ow.isPresent()) { listener.onBlockChange(ow.get().getExtent().getUniqueId(), ow.get().getPosition().toInt()); } } }
Example #12
Source File: BlockListener.java From UltimateCore with MIT License | 5 votes |
@Listener public void onPlace(ChangeBlockEvent.Place event) { ModuleConfig config = Modules.BLACKLIST.get().getConfig().get(); CommentedConfigurationNode hnode = config.get(); for (Transaction<BlockSnapshot> trans : event.getTransactions()) { if (!trans.isValid()) continue; CommentedConfigurationNode node = hnode.getNode("blocks", trans.getFinal().getState().getType().getId()); if (!node.isVirtual() && node.getNode("deny-place").getBoolean()) { trans.setValid(false); } } }
Example #13
Source File: BlockListener.java From UltimateCore with MIT License | 5 votes |
@Listener public void onBreak(ChangeBlockEvent.Break event) { ModuleConfig config = Modules.BLACKLIST.get().getConfig().get(); CommentedConfigurationNode hnode = config.get(); for (Transaction<BlockSnapshot> trans : event.getTransactions()) { if (!trans.isValid()) continue; CommentedConfigurationNode node = hnode.getNode("blocks", trans.getOriginal().getState().getType().getId()); if (!node.isVirtual()) { if (node.getNode("deny-break").getBoolean()) { trans.setValid(false); } } } }
Example #14
Source File: GlobalListener.java From RedProtect with GNU General Public License v3.0 | 5 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onBlockBurnGlobal(ChangeBlockEvent.Modify e) { RedProtect.get().logger.debug(LogLevel.BLOCKS, "GlobalListener - Is onBlockBurnGlobal event"); Transaction<BlockSnapshot> b = e.getTransactions().get(0); if (e.getCause().first(Monster.class).isPresent()) { Region r = RedProtect.get().rm.getTopRegion(b.getOriginal().getLocation().get(), this.getClass().getName()); if (r == null && !RedProtect.get().config.globalFlagsRoot().worlds.get(b.getOriginal().getLocation().get().getExtent().getName()).use_minecart) { e.setCancelled(true); } } }
Example #15
Source File: FlagGui.java From RedProtect with GNU General Public License v3.0 | 5 votes |
@Listener public void onInventoryClick(ClickInventoryEvent event) { if (event.getTargetInventory().getName().get().equals(this.inv.getName().get())) { if (this.editable) { return; } if (event.getTransactions().size() > 0) { Transaction<ItemStackSnapshot> clickTransaction = event.getTransactions().get(0); ItemStack item = clickTransaction.getOriginal().createStack(); if (!RedProtect.get().getVersionHelper().getItemType(item).equals(ItemTypes.NONE) && item.get(Keys.ITEM_LORE).isPresent()) { String flag = item.get(Keys.ITEM_LORE).get().get(1).toPlain().replace("ยง0", ""); if (RedProtect.get().config.getDefFlags().contains(flag)) { if (RedProtect.get().config.configRoot().flags_configuration.change_flag_delay.enable) { if (RedProtect.get().config.configRoot().flags_configuration.change_flag_delay.flags.contains(flag)) { if (!RedProtect.get().changeWait.contains(this.region.getName() + flag)) { applyFlag(flag, item, event); RedProtect.get().getUtil().startFlagChanger(this.region.getName(), flag, this.player); } else { RedProtect.get().lang.sendMessage(player, RedProtect.get().lang.get("gui.needwait.tochange").replace("{seconds}", RedProtect.get().config.configRoot().flags_configuration.change_flag_delay.seconds + "")); event.setCancelled(true); } return; } else { applyFlag(flag, item, event); return; } } else { applyFlag(flag, item, event); return; } } event.setCancelled(true); } } } }
Example #16
Source File: Visualization.java From GriefPrevention with MIT License | 5 votes |
private void removeElementsOutOfRange(ArrayList<Transaction<BlockSnapshot>> elements, int minx, int minz, int maxx, int maxz) { for (int i = 0; i < elements.size(); i++) { Location<World> location = elements.get(i).getFinal().getLocation().get(); if (location.getX() < minx || location.getX() > maxx || location.getZ() < minz || location.getZ() > maxz) { elements.remove(i); } } }
Example #17
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 #18
Source File: Visualization.java From GriefPrevention with MIT License | 5 votes |
public static Visualization fromClick(Location<World> location, int height, VisualizationType visualizationType, Player player, GPPlayerData playerData) { Visualization visualization = new Visualization(visualizationType); BlockSnapshot blockClicked = visualization.snapshotBuilder.from(location).blockState(visualization.cornerMaterial.getDefaultState()).build(); visualization.elements.add(new Transaction<BlockSnapshot>(blockClicked.getLocation().get().createSnapshot(), blockClicked)); if (GriefPreventionPlugin.instance.worldEditProvider != null) { GriefPreventionPlugin.instance.worldEditProvider.sendVisualDrag(player, playerData, location.getBlockPosition()); } return visualization; }
Example #19
Source File: Visualization.java From GriefPrevention with MIT License | 5 votes |
public Visualization(Location<World> lesserBoundaryCorner, Location<World> greaterBoundaryCorner, VisualizationType type) { initBlockVisualTypes(type); this.lesserBoundaryCorner = lesserBoundaryCorner; this.greaterBoundaryCorner = greaterBoundaryCorner; this.type = type; this.snapshotBuilder = Sponge.getGame().getRegistry().createBuilder(BlockSnapshot.Builder.class); this.elements = new ArrayList<Transaction<BlockSnapshot>>(); this.newElements = new ArrayList<>(); this.corners = new ArrayList<>(); }
Example #20
Source File: Visualization.java From GriefPrevention with MIT License | 5 votes |
public Visualization(VisualizationType type) { initBlockVisualTypes(type); this.type = type; this.snapshotBuilder = Sponge.getGame().getRegistry().createBuilder(BlockSnapshot.Builder.class); this.elements = new ArrayList<Transaction<BlockSnapshot>>(); this.newElements = new ArrayList<>(); this.corners = new ArrayList<>(); }
Example #21
Source File: ModifyBlockListener.java From EagleFactions with MIT License | 5 votes |
@Listener public void onBlockModify(ChangeBlockEvent.Modify event) { User user = null; if(event.getCause().containsType(Player.class)) { user = event.getCause().first(Player.class).get(); } else if(event.getCause().containsType(User.class)) { user = event.getCause().first(User.class).get(); } // if(event.getContext().containsKey(EventContextKeys.OWNER) // && event.getContext().get(EventContextKeys.OWNER).isPresent() // && event.getContext().get(EventContextKeys.OWNER).get() instanceof Player) // { // Player player = (Player) event.getContext().get(EventContextKeys.OWNER).get(); if(user != null) { for (Transaction<BlockSnapshot> transaction : event.getTransactions()) { final Optional<Location<World>> optionalLocation = transaction.getFinal().getLocation(); if(optionalLocation.isPresent() && !super.getPlugin().getProtectionManager().canInteractWithBlock(optionalLocation.get(), user, true).hasAccess()) event.setCancelled(true); } } // } }
Example #22
Source File: BlockResult.java From Prism with MIT License | 4 votes |
@Override public ActionableResult rollback() { Optional<Object> optionalOriginal = data.get(DataQueries.OriginalBlock); if (!optionalOriginal.isPresent()) { return ActionableResult.skipped(SkipReason.INVALID); } // Our data is stored with a different structure, so we'll need // a little manual effort to reformat it. DataView finalBlock = ((DataView) optionalOriginal.get()).copy(); // Build World UUID / Vec3 data BlockSnapshot expects Optional<Object> optionalLocation = data.get(DataQueries.Location); if (!optionalLocation.isPresent()) { return ActionableResult.skipped(SkipReason.INVALID_LOCATION); } // Format finalBlock = formatBlockData(finalBlock, optionalLocation.get()); Optional<BlockSnapshot> optionalSnapshot = Sponge.getRegistry().createBuilder(Builder.class).build(finalBlock); if (!optionalSnapshot.isPresent()) { return ActionableResult.skipped(SkipReason.INVALID); } BlockSnapshot snapshot = optionalSnapshot.get(); if (!snapshot.getLocation().isPresent()) { return ActionableResult.skipped(SkipReason.INVALID_LOCATION); } Location<World> location = snapshot.getLocation().get(); // Filter unsafe blocks if (BlockUtil.rejectIllegalApplierBlock(snapshot.getState().getType())) { return ActionableResult.skipped(SkipReason.ILLEGAL_BLOCK); } // Current block in this space. BlockSnapshot original = location.getBlock().snapshotFor(location); // Actually restore! if (!optionalSnapshot.get().restore(true, BlockChangeFlags.NONE)) { return ActionableResult.skipped(SkipReason.UNKNOWN); } // Final block in this space. BlockSnapshot resultingBlock = location.getBlock().snapshotFor(location); return ActionableResult.success(new Transaction<>(original, resultingBlock)); }
Example #23
Source File: BlockResult.java From Prism with MIT License | 4 votes |
@Override public ActionableResult restore() { Optional<Object> optionalFinal = data.get(DataQueries.ReplacementBlock); if (!optionalFinal.isPresent()) { return ActionableResult.skipped(SkipReason.INVALID); } // Our data is stored with a different structure, so we'll need // a little manual effort to reformat it. DataView finalBlock = ((DataView) optionalFinal.get()).copy(); // Build World UUID / Vec3 data BlockSnapshot expects Optional<Object> optionalLocation = data.get(DataQueries.Location); if (!optionalLocation.isPresent()) { return ActionableResult.skipped(SkipReason.INVALID_LOCATION); } // Format finalBlock = formatBlockData(finalBlock, optionalLocation.get()); Optional<BlockSnapshot> optionalSnapshot = Sponge.getRegistry().createBuilder(Builder.class).build(finalBlock); if (!optionalSnapshot.isPresent()) { return ActionableResult.skipped(SkipReason.INVALID); } BlockSnapshot snapshot = optionalSnapshot.get(); if (!snapshot.getLocation().isPresent()) { return ActionableResult.skipped(SkipReason.INVALID_LOCATION); } Location<World> location = snapshot.getLocation().get(); // Filter unsafe blocks if (BlockUtil.rejectIllegalApplierBlock(snapshot.getState().getType())) { return ActionableResult.skipped(SkipReason.ILLEGAL_BLOCK); } // Current block in this space. BlockSnapshot original = location.getBlock().snapshotFor(location); // Actually restore! if (!optionalSnapshot.get().restore(true, BlockChangeFlags.NONE)) { return ActionableResult.skipped(SkipReason.UNKNOWN); } // Final block in this space. BlockSnapshot resultingBlock = location.getBlock().snapshotFor(location); return ActionableResult.success(new Transaction<>(original, resultingBlock)); }
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: ActionableResult.java From Prism with MIT License | 4 votes |
private ActionableResult(@Nullable Transaction<?> transaction) { this.transaction = transaction; this.changeWasApplied = true; this.skipReason = null; }
Example #26
Source File: Visualization.java From GriefPrevention with MIT License | 4 votes |
public List<Transaction<BlockSnapshot>> getVisualElements() { return this.elements; }
Example #27
Source File: Visualization.java From GriefPrevention with MIT License | 4 votes |
private void addClaimElements(int height, Location<World> locality, GPPlayerData playerData) { this.initBlockVisualTypes(type); Location<World> lesser = this.claim.getLesserBoundaryCorner(); Location<World> greater = this.claim.getGreaterBoundaryCorner(); World world = lesser.getExtent(); boolean liquidTransparent = locality.getBlock().getType().getProperty(MatterProperty.class).isPresent() ? false : true; this.smallx = lesser.getBlockX(); this.smally = this.useCuboidVisual() ? lesser.getBlockY() : 0; this.smallz = lesser.getBlockZ(); this.bigx = greater.getBlockX(); this.bigy = this.useCuboidVisual() ? greater.getBlockY() : 0; this.bigz = greater.getBlockZ(); this.minx = this.claim.cuboid ? this.smallx : locality.getBlockX() - 75; this.minz = this.claim.cuboid ? this.smallz : locality.getBlockZ() - 75; this.maxx = this.claim.cuboid ? this.bigx : locality.getBlockX() + 75; this.maxz = this.claim.cuboid ? this.bigz : locality.getBlockZ() + 75; // initialize visualization elements without Y values and real data // that will be added later for only the visualization elements within // visualization range if (this.smallx == this.bigx && this.smally == this.bigy && this.smallz == this.bigz) { BlockSnapshot blockClicked = snapshotBuilder.from(new Location<World>(world, this.smallx, this.smally, this.smallz)).blockState(this.cornerMaterial.getDefaultState()).build(); elements.add(new Transaction<BlockSnapshot>(blockClicked.getLocation().get().createSnapshot(), blockClicked)); return; } // check CUI support if (GriefPreventionPlugin.instance.worldEditProvider != null && playerData != null && GriefPreventionPlugin.instance.worldEditProvider.hasCUISupport(playerData.getPlayerName())) { playerData.showVisualFillers = false; STEP = 0; } if (this.useCuboidVisual()) { this.addVisuals3D(claim, playerData); } else { this.addVisuals2D(claim, height, liquidTransparent); } }
Example #28
Source File: ClaimVisualApplyTask.java From GriefDefender with MIT License | 4 votes |
@Override public void run() { if (!this.player.isOnline()) { this.playerData.revertAllVisuals(); return; } // Only revert active visual if we are not currently creating a claim if (!this.playerData.visualClaimBlocks.isEmpty() && this.playerData.lastShovelLocation == null) { if (this.resetActive) { this.playerData.revertAllVisuals(); } } for (Transaction<BlockSnapshot> transaction : this.visualization.getVisualTransactions()) { this.playerData.queuedVisuals.add(transaction.getFinal()); } if (this.visualization.getClaim() != null) { this.visualization.getClaim().playersWatching.add(this.player.getUniqueId()); } UUID visualUniqueId = null; if (this.visualization.getClaim() == null) { visualUniqueId = UUID.randomUUID(); playerData.tempVisualUniqueId = visualUniqueId; } else { visualUniqueId = this.visualization.getClaim().getUniqueId(); } final List<Transaction<BlockSnapshot>> blockTransactions = this.playerData.visualClaimBlocks.get(visualUniqueId); if (blockTransactions == null) { this.playerData.visualClaimBlocks.put(visualUniqueId, new ArrayList<>(this.visualization.getVisualTransactions())); } else { // support multi layer visuals i.e. water blockTransactions.addAll(this.visualization.getVisualTransactions()); // cancel existing task final Task task = this.playerData.claimVisualRevertTasks.get(visualUniqueId); if (task != null) { task.cancel(); this.playerData.claimVisualRevertTasks.remove(visualUniqueId); } } int seconds = (this.playerData.lastShovelLocation != null && this.visualization.getClaim() == null ? GriefDefenderPlugin.getGlobalConfig().getConfig().visual.createBlockVisualTime : GriefDefenderPlugin.getGlobalConfig().getConfig().visual.claimVisualTime); if (seconds <= 0) { seconds = this.playerData.lastShovelLocation == null ? 60 : 180; } final ClaimVisualRevertTask runnable = new ClaimVisualRevertTask(visualUniqueId, this.player, this.playerData); if (this.playerData.lastShovelLocation != null && this.visualization.getClaim() == null) { this.playerData.createBlockVisualTransactions.put(visualUniqueId, new ArrayList<>(this.visualization.getVisualTransactions())); this.playerData.createBlockVisualRevertRunnables.put(visualUniqueId, runnable); } this.playerData.claimVisualRevertTasks.put(visualUniqueId, Sponge.getGame().getScheduler().createTaskBuilder().delay(seconds, TimeUnit.SECONDS) .execute(runnable).submit(GDBootstrap.getInstance())); }
Example #29
Source File: GDPlayerData.java From GriefDefender with MIT License | 4 votes |
private void revertVisualBlocks(Player player, GDClaim claim, UUID visualUniqueId) { final List<Transaction<BlockSnapshot>> visualTransactions = this.visualClaimBlocks.get(visualUniqueId); if (visualTransactions == null || visualTransactions.isEmpty()) { return; } // Gather create block visuals final List<Transaction<BlockSnapshot>> createBlockVisualTransactions = new ArrayList<>(); for (Runnable runnable : this.createBlockVisualRevertRunnables.values()) { final ClaimVisualRevertTask revertTask = (ClaimVisualRevertTask) runnable; if (revertTask.getVisualUniqueId().equals(visualUniqueId)) { continue; } final List<Transaction<BlockSnapshot>> blockTransactions = this.createBlockVisualTransactions.get(revertTask.getVisualUniqueId()); if (blockTransactions != null) { createBlockVisualTransactions.addAll(blockTransactions); } } for (int i = 0; i < visualTransactions.size(); i++) { BlockSnapshot snapshot = visualTransactions.get(i).getOriginal(); // If original block does not exist, do not send to player final Location<World> location = snapshot.getLocation().orElse(null); if (location != null && (snapshot.getState().getType() != location.getBlockType())) { if (claim != null) { claim.markVisualDirty = true; } continue; } boolean ignoreVisual = false; for (Transaction<BlockSnapshot> createVisualTransaction : createBlockVisualTransactions) { if (createVisualTransaction.getOriginal().getLocation().equals(snapshot.getLocation().get())) { ignoreVisual = true; break; } } if (ignoreVisual) { continue; } player.sendBlockChange(snapshot.getPosition(), snapshot.getState()); } if (claim != null) { claim.playersWatching.remove(this.playerID); } this.claimVisualRevertTasks.remove(visualUniqueId); this.visualClaimBlocks.remove(visualUniqueId); this.createBlockVisualRevertRunnables.remove(visualUniqueId); this.createBlockVisualTransactions.remove(visualUniqueId); }
Example #30
Source File: ActionableResult.java From Prism with MIT License | 2 votes |
/** * Build a successful actionable result. * @param transaction * @return */ public static ActionableResult success(@Nullable Transaction<?> transaction) { return new ActionableResult(transaction); }