本文整理汇总了Java中org.spongepowered.api.block.BlockSnapshot类的典型用法代码示例。如果您正苦于以下问题:Java BlockSnapshot类的具体用法?Java BlockSnapshot怎么用?Java BlockSnapshot使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BlockSnapshot类属于org.spongepowered.api.block包,在下文中一共展示了BlockSnapshot类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onChangeBlockEvent
import org.spongepowered.api.block.BlockSnapshot; //导入依赖的package包/类
@Listener
public void onChangeBlockEvent(ChangeBlockEvent.Break e, @First Player player) {
if (plugin.getMainConfig().isUseSigns()) {
if (player.hasPermission("minecraftmarket.signs")) {
if (e.getTransactions().size() > 0) {
BlockSnapshot blockSnapshot = e.getTransactions().get(0).getOriginal();
Optional<Location<World>> optionalLocation = blockSnapshot.getLocation();
if (optionalLocation.isPresent()) {
if (plugin.getSignsConfig().getDonorSignFor(optionalLocation.get()) != null) {
if (plugin.getSignsConfig().removeDonorSign(optionalLocation.get())) {
player.sendMessage(Colors.color(I18n.tl("prefix") + " " + I18n.tl("sign_removed")));
plugin.getSignsTask().updateSigns();
}
}
}
}
}
}
}
示例2: onLiquidFlow
import org.spongepowered.api.block.BlockSnapshot; //导入依赖的package包/类
@Listener(order = Order.POST)
public void onLiquidFlow(ChangeBlockEvent.Pre e) {
if (e.getLocations().isEmpty()) return;
Location<World> loc = e.getLocations().get(0);
BlockSnapshot snapshot = loc.getExtent().createSnapshot(loc.getBlockPosition());
Optional<MatterProperty> matter = snapshot.getState().getProperty(MatterProperty.class);
if (matter.isPresent() && matter.get().getValue() == Matter.LIQUID) {
String name = "Water";
BlockType type = snapshot.getState().getType();
if (type == BlockTypes.LAVA || type == BlockTypes.FLOWING_LAVA)
name = "Lava";
db.addToQueue(new BlockQueueEntry(snapshot, ActionType.FLOW, name, new Date().getTime()));
}
}
示例3: onBlockPrimaryInteract
import org.spongepowered.api.block.BlockSnapshot; //导入依赖的package包/类
@Listener
public void onBlockPrimaryInteract(InteractBlockEvent.Primary.MainHand e, @First Player p) {
if (!plugin.getInspectManager().isInspector(p))
return;
e.setCancelled(true);
BlockSnapshot block = e.getTargetBlock();
if (block == null || !block.getLocation().isPresent())
return;
Location<World> loc = block.getLocation().get();
p.sendMessage(Text.of(TextColors.BLUE, "Querying database, please wait..."));
Sponge.getScheduler().createAsyncExecutor(plugin).execute(() -> {
plugin.getInspectManager().inspect(p, block.getWorldUniqueId(), loc.getBlockPosition()); });
}
示例4: onBlockSecondaryInteract
import org.spongepowered.api.block.BlockSnapshot; //导入依赖的package包/类
@Listener
public void onBlockSecondaryInteract(InteractBlockEvent.Secondary.MainHand e, @First Player p) {
if (!plugin.getInspectManager().isInspector(p))
return;
//TODO: Figure out why shearing sheep causes weird shit to happen
e.setCancelled(true);
BlockSnapshot block = e.getTargetBlock();
if (block == null || !block.getLocation().isPresent())
return;
Location<World> loc = block.getLocation().get();
p.sendMessage(Text.of(TextColors.BLUE, "Querying database, please wait..."));
if (loc.getTileEntity().isPresent() && loc.getTileEntity().get() instanceof TileEntityCarrier) {
Sponge.getScheduler().createAsyncExecutor(plugin).execute(() -> {
plugin.getInspectManager().inspectContainer(p, block.getWorldUniqueId(), loc.getBlockPosition()); });
} else {
Sponge.getScheduler().createAsyncExecutor(plugin).execute(() -> {
plugin.getInspectManager().inspect(p, block.getWorldUniqueId(), loc.getBlockPosition().add(e.getTargetSide().asBlockOffset())); });
}
}
示例5: onEitherClick
import org.spongepowered.api.block.BlockSnapshot; //导入依赖的package包/类
@Listener
public void onEitherClick(final InteractBlockEvent event, @First Player player) {
if (player.hasPermission("safeguard.mod")) {
return;
}
// Ignore clicks in the air
if (event.getTargetBlock().equals(BlockSnapshot.NONE) || !event.getTargetBlock().getLocation().isPresent()) {
return;
}
if (!event.getTargetBlock().getState().getType().equals(BlockTypes.DRAGON_EGG)) {
return;
}
if (!SafeGuard.getZoneManager().allows(player, changeFlag, event.getTargetBlock().getLocation().get())) {
player.sendMessage(Format.error("Sorry, this zone doesn't allow you to do that."));
event.setCancelled(true);
}
}
示例6: onOpenInventory
import org.spongepowered.api.block.BlockSnapshot; //导入依赖的package包/类
@Listener
public void onOpenInventory(final InteractBlockEvent.Secondary event, @First Player player) {
Optional<TileEntity> entity = event.getTargetBlock().getLocation().get().getTileEntity();
if (!entity.isPresent()) {
return;
}
// Ignore clicks in the air
if (event.getTargetBlock().equals(BlockSnapshot.NONE) || !event.getTargetBlock().getLocation().isPresent()) {
return;
}
if (player.hasPermission("safeguard.mod")) {
return;
}
if (!SafeGuard.getZoneManager().allows(player, useFlag, event.getTargetBlock().getLocation().get())) {
player.sendMessage(Format.error("Sorry, this zone doesn't allow you to do that."));
event.setCancelled(true);
}
}
示例7: onUse
import org.spongepowered.api.block.BlockSnapshot; //导入依赖的package包/类
@Listener
public void onUse(final InteractBlockEvent.Secondary event, @First Player player) {
// Ignore clicks in the air
if (event.getTargetBlock().equals(BlockSnapshot.NONE) || !event.getTargetBlock().getLocation().isPresent()) {
return;
}
try {
if (!player.hasPermission("keys.mod") && !Keys.getStorageAdapter().allowsAccess(player, event.getTargetBlock().getLocation().get())) {
player.sendMessage(Format.error("You may not interact with this locked location."));
event.setCancelled(true);
}
listLockOwner(player, event.getTargetBlock().getLocation().get());
} catch (SQLException e) {
player.sendMessage(Format.error("Storage error. Details have been logged."));
e.printStackTrace();
}
}
示例8: onPunchBlock
import org.spongepowered.api.block.BlockSnapshot; //导入依赖的package包/类
@Listener
public void onPunchBlock(final InteractBlockEvent.Primary event, @First Player player) {
// Ignore clicks in the air
if (event.getTargetBlock().equals(BlockSnapshot.NONE) || !event.getTargetBlock().getLocation().isPresent()) {
return;
}
Optional<InteractionHandler> optional = Keys.getInteractionHandler(player);
if (!optional.isPresent()) {
return;
}
optional.get().handle(player, event.getTargetBlock().getLocation().get());
Keys.removeInteractionHandler(player);
}
示例9: onBlockBreak
import org.spongepowered.api.block.BlockSnapshot; //导入依赖的package包/类
@Listener(order = Order.LAST)
public void onBlockBreak(ChangeBlockEvent.Break event) {
for (Transaction<BlockSnapshot> blockSnapshotTransaction : event.getTransactions()) {
final BlockSnapshot original = blockSnapshotTransaction.getOriginal();
if (original.getState().getType() == BlockTypes.STANDING_SIGN
|| original.getState().getType() == BlockTypes.WALL_SIGN) {
if (original.getLocation().isPresent()) {
final Location3D location3D = WorldLocationConverter.of(original.getLocation().get());
// iterate all arenas of all minigames to see if sign is registered
//TODO: This is more expensive than it needs to be.
// We should maintain a global index of registered signs.
if (InfernoCore.getMinigames().values().stream()
.filter(minigame -> minigame.getArenas().stream()
.filter(arena -> arena.getLobbySignAt(location3D).isPresent()).count() > 0)
.count() > 0) {
event.setCancelled(true);
}
}
}
}
}
示例10: checkBlockChange
import org.spongepowered.api.block.BlockSnapshot; //导入依赖的package包/类
public static void checkBlockChange(BlockSnapshot block) {
Optional<Location<World>> loc = block.getLocation();
if (!loc.isPresent()) {
return;
}
List<Arena> arenas = checkChangeAtLocation(WorldLocationConverter.of(loc.get()));
for (Arena arena : arenas) {
try {
((InfernoRollbackAgent) ((InfernoArena) arena).getRollbackAgent()).logBlockChange(block);
} catch (IOException | SQLException ex) {
throw new RuntimeException("Failed to log block mutation event for rollback in arena "
+ arena.getDisplayName(), ex);
}
}
}
示例11: onBlockPlace
import org.spongepowered.api.block.BlockSnapshot; //导入依赖的package包/类
@Listener
public void onBlockPlace(ChangeBlockEvent.Place event, @Root Player player) {
List<Transaction<BlockSnapshot>> transactions = event.getTransactions();
for (Transaction<BlockSnapshot> transaction : transactions) {
BlockSnapshot snapshot = transaction.getFinal();
BlockState blockState = snapshot.getState();
String blockTypeId = blockState.getType().getId();
String blockStateId = blockState.getId();
PermHandler ph = PermHandler.getInstance();
if (!ph.checkPerm(player, "protectionperms.block.place." + blockTypeId,
"protectionperms.block.place." + blockStateId)) {
event.setCancelled(true);
player.sendMessage(ChatTypes.ACTION_BAR,
Text.of(TextColors.RED, "You don't have permission to place " + blockState.getName() + '!'));
break;
}
}
}
示例12: onBlockBreak
import org.spongepowered.api.block.BlockSnapshot; //导入依赖的package包/类
@Listener
public void onBlockBreak(ChangeBlockEvent.Break event, @Root Player player) {
List<Transaction<BlockSnapshot>> transactions = event.getTransactions();
for (Transaction<BlockSnapshot> transaction : transactions) {
BlockSnapshot snapshot = transaction.getOriginal();
BlockState blockState = snapshot.getState();
String blockTypeId = blockState.getType().getId();
String blockStateId = blockState.getId();
PermHandler ph = PermHandler.getInstance();
if (!ph.checkPerm(player, "protectionperms.block.break." + blockTypeId,
"protectionperms.block.break." + blockStateId)) {
event.setCancelled(true);
player.sendMessage(ChatTypes.ACTION_BAR,
Text.of(TextColors.RED, "You don't have permission to break " + blockState.getName() + '!'));
break;
}
}
}
示例13: handleInteraction
import org.spongepowered.api.block.BlockSnapshot; //导入依赖的package包/类
@Override
public boolean handleInteraction(Player player, Location<World> location, BlockSnapshot blockState) {
final Optional<Lock> optionalLock = Latch.getLockManager().getLock(location);
//Check to see if another lock is present
if (!optionalLock.isPresent()) {
player.sendMessage(Text.of(TextColors.RED, "There is no lock there."));
return false;
}
Lock lock = optionalLock.get();
//Check to make sure they're the owner
if (!lock.isOwnerOrBypassing(player.getUniqueId()) && !Latch.getLockManager().isBypassing(player.getUniqueId())) {
player.sendMessage(Text.of(TextColors.RED, "You're not the owner of this lock."));
return false;
}
Latch.getLockManager().deleteLock(location, true);
player.sendMessage(
Text.of(TextColors.DARK_GREEN, "You have deleted this ", TextColors.GRAY, lock.getLockedObject(), TextColors.DARK_GREEN, " lock."));
return true;
}
示例14: getDoubleBlockLocation
import org.spongepowered.api.block.BlockSnapshot; //导入依赖的package包/类
/**
* Compare block with surrounding blocks - returning one with the same type if they're associated using CONNECTED_DIRECTIONS or PORTION_TYPE data
*
* @param block The BlockSnapshot of the block we're checking for a double of
* @return The potential location of a double block
*/
public static Optional<Location<World>> getDoubleBlockLocation(BlockSnapshot block) {
if (block != BlockSnapshot.NONE && block.getLocation().isPresent()) {
//Get all directions we need to evaluate -- doors don't have CONNECTED_DIRECTIONS just PORTION_TYPEs
Set<Direction> directionsToInvestigate = block.get(Keys.CONNECTED_DIRECTIONS).isPresent() ? new HashSet<>(block.get(Keys.CONNECTED_DIRECTIONS).get()) : new HashSet<>();
block.getLocation().get().getExtent().getTileEntity(block.getLocation().get().getBlockPosition())
.ifPresent(tileEntity1 -> directionsToInvestigate.addAll(tileEntity1.get(Keys.CONNECTED_DIRECTIONS).orElse(ImmutableSet.of())));
block.get(Keys.PORTION_TYPE)
.map(p -> p == PortionTypes.BOTTOM ? directionsToInvestigate.add(Direction.UP) : directionsToInvestigate.add(Direction.DOWN));
for (Direction direction : directionsToInvestigate) {
if (block.getLocation().get().getBlockRelative(direction).getBlock().getType() == block.getState().getType()) {
return Optional.of(block.getLocation().get().getBlockRelative(direction));
}
}
}
return Optional.empty();
}
示例15: addTarget
import org.spongepowered.api.block.BlockSnapshot; //导入依赖的package包/类
public void addTarget(BlockSnapshot pistonBlock, EnhancedCustomBlock block, BlockData blockData,
Vector3i blockPos) {
Direction pistonFacing = pistonBlock.getState().get(Keys.DIRECTION).get();
boolean isRetracting;
if (pistonBlock.getState().getType() == BlockTypes.PISTON_EXTENSION) {
// Followed up from sticky piston - retraction has cause of the piston extension
// See CustomBlockEventListeners#getPistonCause
isRetracting = true;
} else {
isRetracting = pistonBlock.getState().get(Keys.EXTENDED).get();
}
Vector3i destPos;
if (isRetracting) {
destPos = blockPos.sub(pistonFacing.asBlockOffset());
} else {
destPos = blockPos.add(pistonFacing.asBlockOffset());
}
this.locations.put(destPos, new Tuple<>(blockPos, new ImmutablePair<>(block, blockData)));
}