本文整理汇总了Java中org.spongepowered.api.data.Transaction类的典型用法代码示例。如果您正苦于以下问题:Java Transaction类的具体用法?Java Transaction怎么用?Java Transaction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Transaction类属于org.spongepowered.api.data包,在下文中一共展示了Transaction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onBlockBreak
import org.spongepowered.api.data.Transaction; //导入依赖的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);
}
}
}
}
}
示例2: onBlockPlace
import org.spongepowered.api.data.Transaction; //导入依赖的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;
}
}
}
示例3: onBlockBreak
import org.spongepowered.api.data.Transaction; //导入依赖的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;
}
}
}
示例4: handleOutputClick
import org.spongepowered.api.data.Transaction; //导入依赖的package包/类
private void handleOutputClick(SlotTransaction slotTransaction, Transaction<ItemStackSnapshot> cursorTransaction) {
// Trying to put item in slot
if (slotTransaction.getFinal() != ItemStackSnapshot.NONE) {
if (slotTransaction.getOriginal() != cursorTransaction.getFinal()) {
System.out.println("false positive");
// False positive
return;
}
System.out.println("put item in output");
slotTransaction.setValid(false);
// TODO because Sponge is broken - set custom to original
cursorTransaction.setCustom(cursorTransaction.getOriginal());
return;
}
if (!canTakeOutput()) {
System.out.println("take output before ready");
slotTransaction.setValid(false);
cursorTransaction.setCustom(cursorTransaction.getOriginal());
return;
}
System.out.println("take output");
takeOutput();
}
示例5: addTopLine
import org.spongepowered.api.data.Transaction; //导入依赖的package包/类
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));
}
}
}
}
示例6: addBottomLine
import org.spongepowered.api.data.Transaction; //导入依赖的package包/类
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));
}
}
}
}
示例7: addLeftLine
import org.spongepowered.api.data.Transaction; //导入依赖的package包/类
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));
}
}
}
}
示例8: addRightLine
import org.spongepowered.api.data.Transaction; //导入依赖的package包/类
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());
}
示例9: tryInteract
import org.spongepowered.api.data.Transaction; //导入依赖的package包/类
@Override
public BehaviorResult tryInteract(BehaviorPipeline<Behavior> pipeline, BehaviorContext context) {
final LanternPlayer player = (LanternPlayer) context.requireContext(ContextKeys.PLAYER);
final ItemStack itemStack = context.requireContext(ContextKeys.USED_ITEM_STACK);
final PeekedOfferTransactionResult peekResult = player.getInventory().getEquipment().peekOffer(itemStack.copy());
if (peekResult.isSuccess()) {
final List<SlotTransaction> transactions = new ArrayList<>(peekResult.getTransactions());
final AbstractSlot slot = (AbstractSlot) context.getContext(ContextKeys.USED_SLOT).orElse(null);
if (slot != null) {
transactions.add(new SlotTransaction(
slot, itemStack.createSnapshot(), LanternItemStack.toSnapshot(peekResult.getRejectedItem().orElse(null))));
}
final ChangeInventoryEvent.Equipment event = SpongeEventFactory.createChangeInventoryEventEquipment(
context.getCurrentCause(), player.getInventory(), transactions);
if (event.isCancelled()) {
return BehaviorResult.CONTINUE;
}
event.getTransactions().stream().filter(Transaction::isValid).forEach(slotTransaction ->
slotTransaction.getSlot().set(slotTransaction.getFinal().createStack()));
return BehaviorResult.SUCCESS;
}
return BehaviorResult.CONTINUE;
}
示例10: handleCreativeClick
import org.spongepowered.api.data.Transaction; //导入依赖的package包/类
@Override
public void handleCreativeClick(ClientContainer clientContainer, @Nullable ClientSlot clientSlot, @Nullable ItemStack itemStack) {
final LanternPlayer player = clientContainer.getPlayer();
final CauseStack causeStack = CauseStack.current();
if (clientSlot == null) {
if (itemStack != null) {
causeStack.addContext(EventContextKeys.SPAWN_TYPE, SpawnTypes.DROPPED_ITEM);
LanternEventHelper.handleDroppedItemSpawning(player.getTransform(), itemStack.createSnapshot());
}
} else if (clientSlot instanceof ClientSlot.Slot) {
final AbstractSlot slot = ((ClientSlot.Slot) clientSlot).getSlot();
final PeekedSetTransactionResult result = slot.peekSet(itemStack);
// We do not know the remaining stack in the cursor,
// so just use none as new item
final Transaction<ItemStackSnapshot> cursorTransaction = new Transaction<>(
LanternItemStack.toSnapshot(itemStack), ItemStackSnapshot.NONE);
final ClickInventoryEvent.Creative event = SpongeEventFactory.createClickInventoryEventCreative(
causeStack.getCurrentCause(), cursorTransaction, this.container,
this.container.transformSlots(result.getTransactions()));
finishInventoryEvent(event);
}
}
示例11: finishInventoryEvent
import org.spongepowered.api.data.Transaction; //导入依赖的package包/类
private void finishInventoryEvent(ChangeInventoryEvent event) {
final List<SlotTransaction> slotTransactions = event.getTransactions();
Sponge.getEventManager().post(event);
if (!event.isCancelled()) {
if (!(event instanceof ClickInventoryEvent.Creative) && event instanceof ClickInventoryEvent) {
final Transaction<ItemStackSnapshot> cursorTransaction = ((ClickInventoryEvent) event).getCursorTransaction();
if (cursorTransaction.isValid()) {
setCursorItem(cursorTransaction.getFinal().createStack());
}
}
slotTransactions.stream().filter(Transaction::isValid).forEach(
transaction -> transaction.getSlot().set(transaction.getFinal().createStack()));
if (event instanceof SpawnEntityEvent) {
LanternWorld.finishSpawnEntityEvent((SpawnEntityEvent) event);
}
}
}
示例12: onPlaceBlock
import org.spongepowered.api.data.Transaction; //导入依赖的package包/类
@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);
}
}
}
}
示例13: onBreakBlock
import org.spongepowered.api.data.Transaction; //导入依赖的package包/类
@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);
}
}
}
}
示例14: onBlockBurnGlobal
import org.spongepowered.api.data.Transaction; //导入依赖的package包/类
@Listener(order = Order.FIRST, beforeModifications = true)
public void onBlockBurnGlobal(ChangeBlockEvent.Modify e){
Transaction<BlockSnapshot> b = e.getTransactions().get(0);
Region r = RedProtect.get().rm.getTopRegion(b.getOriginal().getLocation().get());
if (r != null){
return;
}
if (e.getCause().first(Monster.class).isPresent()) {
if (!RedProtect.get().cfgs.getGlobalFlag(b.getOriginal().getLocation().get().getExtent().getName(),"entity-block-damage")){
e.setCancelled(true);
}
}
if (b.getFinal().getState().getType().equals(BlockTypes.FIRE) && !RedProtect.get().cfgs.getGlobalFlag(b.getOriginal().getLocation().get().getExtent().getName(),"fire-block-damage")){
e.setCancelled(true);
}
}
示例15: onBlockBreak
import org.spongepowered.api.data.Transaction; //导入依赖的package包/类
@Listener
public void onBlockBreak(ChangeBlockEvent.Break event, @First(typeFilter = Player.class) Player player) {
if (event.isCancelled()) {
return;
}
IActiveCharacter character = characterService.getCharacter(player.getUniqueId());
for (Transaction<BlockSnapshot> transaction : event.getTransactions()) {
BlockType type = transaction.getFinal().getState().getType();
Double d = experienceService.getMinningExperiences(type);
if (d != null) {
characterService.addExperiences(character, d, ExperienceSource.MINING);
} else {
d = experienceService.getLoggingExperiences(type);
if (d != null) {
characterService.addExperiences(character, d, ExperienceSource.LOGGING);
}
}
}
}