本文整理汇总了Java中org.spongepowered.api.event.block.ChangeBlockEvent.getTransactions方法的典型用法代码示例。如果您正苦于以下问题:Java ChangeBlockEvent.getTransactions方法的具体用法?Java ChangeBlockEvent.getTransactions怎么用?Java ChangeBlockEvent.getTransactions使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.spongepowered.api.event.block.ChangeBlockEvent
的用法示例。
在下文中一共展示了ChangeBlockEvent.getTransactions方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onBlockBurn
import org.spongepowered.api.event.block.ChangeBlockEvent; //导入方法依赖的package包/类
@Listener
public void onBlockBurn(ChangeBlockEvent event) {
if (event.getCause().root() instanceof Player) {
return;
}
for (Transaction<BlockSnapshot> transaction : event.getTransactions()) {
BlockType finalType = transaction.getFinal().getState().getType();
if (finalType != BlockTypes.FIRE) {
continue;
}
Optional<JungleRaidInstance> optInst = manager.getApplicableZone(transaction.getOriginal().getLocation().get());
if (optInst.isPresent()) {
JungleRaidInstance inst = optInst.get();
if (inst.isFlagEnabled(JungleRaidFlag.NO_FIRE_SPREAD)) {
event.setCancelled(true);
}
break;
}
}
}
示例2: onBlockChange
import org.spongepowered.api.event.block.ChangeBlockEvent; //导入方法依赖的package包/类
@Listener
public void onBlockChange(ChangeBlockEvent event) {
Optional<Player> player = event.getCause().get(NamedCause.SOURCE, Player.class);
for (Transaction<BlockSnapshot> transaction : event.getTransactions()) {
if (manager.getApplicableZone(transaction.getOriginal().getLocation().get()).isPresent()) {
BlockType originalType = transaction.getOriginal().getState().getType();
BlockType finalType = transaction.getFinal().getState().getType();
if (player.isPresent()) {
if (!isAllowedChange(originalType, finalType)) {
event.setCancelled(true);
break;
}
} else {
if (originalType == BlockTypes.LEVER && finalType != BlockTypes.LEVER) {
event.setCancelled(true);
break;
}
}
}
}
}
示例3: onBlockChange
import org.spongepowered.api.event.block.ChangeBlockEvent; //导入方法依赖的package包/类
@Listener
public void onBlockChange(ChangeBlockEvent event) {
// Depends on SpongeForge#550
if (event instanceof ExplosionEvent.Detonate) {
return;
}
Optional<PluginContainer> optPluginContainer = event.getCause().first(PluginContainer.class);
if (optPluginContainer.isPresent()) {
return;
}
for (Transaction<BlockSnapshot> transaction : event.getTransactions()) {
if (manager.getApplicableZone(transaction.getOriginal().getLocation().get()).isPresent()) {
event.setCancelled(true);
break;
}
}
}
示例4: onBlockBurn
import org.spongepowered.api.event.block.ChangeBlockEvent; //导入方法依赖的package包/类
@Listener
public void onBlockBurn(ChangeBlockEvent event) {
boolean isCausedByFire = isCausedbyFire(event);
for (Transaction<BlockSnapshot> transaction : event.getTransactions()) {
BlockType finalType = transaction.getFinal().getState().getType();
if (!isCausedByFire && finalType != BlockTypes.FIRE) {
continue;
}
if (event.getCause().first(PluginContainer.class).isPresent()) {
continue;
}
if (manager.getApplicableZone(transaction.getOriginal().getLocation().get()).isPresent()) {
event.setCancelled(true);
break;
}
}
}
示例5: onBlockChange
import org.spongepowered.api.event.block.ChangeBlockEvent; //导入方法依赖的package包/类
@Listener
public void onBlockChange(ChangeBlockEvent event, @First Player player) {
for (Transaction<BlockSnapshot> block : event.getTransactions()) {
Optional<Location<World>> optLoc = block.getOriginal().getLocation();
if (!optLoc.isPresent()) {
continue;
}
if (check(player, optLoc.get())) {
event.setCancelled(true);
if (event.getCause().root().equals(player)) {
player.sendMessage(Text.of(TextColors.RED, "You can't change blocks here!"));
player.sendMessage(Text.of(TextColors.RED, "[Debug] ", optLoc.get(), " [Cause ", event.getCause(), "]"));
}
break;
}
}
}
示例6: onBuild
import org.spongepowered.api.event.block.ChangeBlockEvent; //导入方法依赖的package包/类
@Listener
public void onBuild(ChangeBlockEvent event, @Root Player player)
{
if (player.hasPermission(this.buildPerm.getId()))
{
return;
}
for (Transaction<BlockSnapshot> transaction : event.getTransactions())
{
if (transaction.getOriginal().getState().getType() == transaction.getFinal().getState().getType())
{
continue;
}
transaction.getOriginal().getLocation().ifPresent(loc -> {
List<Region> regionsAt = manager.getRegionsAt(loc);
if (checkSetting(event, player, regionsAt, () -> null, (s) -> s.build, UNDEFINED) == FALSE)
{
i18n.send(ACTION_BAR, player, NEGATIVE, "You are not allowed to build here.");
return;
}
});
}
}
示例7: onChangeBlock
import org.spongepowered.api.event.block.ChangeBlockEvent; //导入方法依赖的package包/类
public void onChangeBlock(ChangeBlockEvent event) {
List<Transaction<BlockSnapshot>> transactions = event.getTransactions();
Transaction<BlockSnapshot> first = transactions.get(0);
BlockSnapshot original = first.getOriginal();
Optional<World> world = SpongeMain.THIS.getServer().getWorld(original.getWorldUniqueId());
String worldName = world.get().getName();
Location loc = SpongeUtil.getLocation(worldName, original.getPosition());
PlotArea area = loc.getPlotArea();
if (area == null) {
return;
}
Plot plot = area.getPlot(loc);
if (plot == null) {
if (!loc.isPlotArea()) {
return;
}
event.setCancelled(true);
return;
}
event.filter(loc1 -> !SpongeUtil.getLocation(worldName, loc1).isPlotRoad());
}
示例8: onBlockChanged
import org.spongepowered.api.event.block.ChangeBlockEvent; //导入方法依赖的package包/类
@Listener
public void onBlockChanged(ChangeBlockEvent evt) {
for (Transaction<BlockSnapshot> block : evt.getTransactions()) {
BlockChangesScriptEvent event = (BlockChangesScriptEvent) clone();
event.internal = evt;
event.location = new LocationTag(block.getFinal().getLocation().get());
event.new_material = new BlockTypeTag(block.getFinal().getState().getType());
event.old_material = new BlockTypeTag(block.getOriginal().getState().getType());
event.cancelled = evt.isCancelled();
event.run();
evt.setCancelled(event.cancelled);
}
}
示例9: printChangeBlock
import org.spongepowered.api.event.block.ChangeBlockEvent; //导入方法依赖的package包/类
private static void printChangeBlock(PrintStream out, ChangeBlockEvent event) {
for (Transaction<BlockSnapshot> transaction : event.getTransactions()) {
out.println(" At " + transaction.getOriginal().getPosition());
out.println(" " + transaction.getOriginal().getExtendedState() + " changes to "
+ transaction.getFinal().getExtendedState());
}
}
示例10: changeBlock
import org.spongepowered.api.event.block.ChangeBlockEvent; //导入方法依赖的package包/类
@Listener(order = Order.POST)
@Exclude({ChangeBlockEvent.Post.class, ChangeBlockEvent.Pre.class})
public void changeBlock(ChangeBlockEvent event, @Root Player player) {
// Just get the default key provider
EventKeyProvider<Event> keyProvider = resolveKeyProvider(Event.class);
final UUID uuid = player.getUniqueId();
final int increment = 1;
for (Transaction<BlockSnapshot> transaction : event.getTransactions()) {
String key = keyProvider.provide(event);
BlockSnapshot finalBlock = transaction.getFinal();
// Check if the block is a "modifiable" block like a
// redstone-related block so we can filter out crap like leaves
// being changed somehow by the player
//
// Keys.DELAY is for repeaters, Keys.COMPARATOR_TYPE is for
// comparators
if (event instanceof ChangeBlockEvent.Modify
&& !(finalBlock.supports(Keys.POWERED) || finalBlock.supports(Keys.DELAY) || finalBlock.supports(Keys.COMPARATOR_TYPE))) {
continue;
} else if (event instanceof ChangeBlockEvent.Place || event instanceof ChangeBlockEvent.Modify) {
key += ":" + transaction.getFinal().getState().getType().getId();
} else if (event instanceof ChangeBlockEvent.Break) {
key += ":" + transaction.getOriginal().getState().getType().getId();
} else {
continue;
}
BadgeUpEvent newEvent = new BadgeUpEvent(key, uuid, new Modifier(ModifierOperation.INC, increment));
newEvent.addDataEntry("Transaction", transaction);
send(newEvent);
}
}
示例11: onBlockChange
import org.spongepowered.api.event.block.ChangeBlockEvent; //导入方法依赖的package包/类
@Listener
public void onBlockChange(ChangeBlockEvent event, @First Player player) {
for (Transaction<BlockSnapshot> block : event.getTransactions()) {
Optional<Location<World>> optLoc = block.getOriginal().getLocation();
if (optLoc.isPresent() && isApplicable(optLoc.get())) {
boolean preventedFromBuilding = check(player, optLoc.get());
// Block players that are allowed to build, otherwise send the no build message
Text noEditMessage = Text.of(TextColors.RED, "You can't change blocks here!");
if (!preventedFromBuilding) {
if (player.get(Keys.GAME_MODE).orElse(GameModes.SURVIVAL) != GameModes.CREATIVE) {
preventedFromBuilding = true;
noEditMessage = Text.of(TextColors.RED, "You must be in creative mode to edit!");
}
}
if (preventedFromBuilding) {
if (event.getCause().root().equals(player)) {
player.sendMessage(noEditMessage);
}
event.setCancelled(true);
return;
}
}
}
}
示例12: onBlockChange
import org.spongepowered.api.event.block.ChangeBlockEvent; //导入方法依赖的package包/类
@Listener
public void onBlockChange(ChangeBlockEvent event, @First Entity entity) {
if (isApplicable(entity)) {
for (Transaction<BlockSnapshot> transaction : event.getTransactions()) {
if (transaction.getOriginal().getState().getType() != transaction.getFinal().getState().getType()) {
event.setCancelled(true);
break;
}
}
}
}
示例13: onBlockChange
import org.spongepowered.api.event.block.ChangeBlockEvent; //导入方法依赖的package包/类
@Listener
public void onBlockChange(ChangeBlockEvent event, @First Player player) {
if (manager.getApplicableZone(player).isPresent()) {
for (Transaction<BlockSnapshot> block : event.getTransactions()) {
if (block.getOriginal().getState().getType() != BlockTypes.WEB) {
event.setCancelled(true);
return;
}
}
}
}
示例14: onPlayerInteract
import org.spongepowered.api.event.block.ChangeBlockEvent; //导入方法依赖的package包/类
@Listener
public void onPlayerInteract(ChangeBlockEvent event) {
for (Transaction<BlockSnapshot> block : event.getTransactions()) {
BlockSnapshot snapshot = block.getOriginal();
Optional<CursedMineInstance> optInst = manager.getApplicableZone(snapshot);
if (optInst.isPresent() && triggerBlocks.contains(snapshot.getState().getType())) {
optInst.get().activatePumps();
break;
}
}
}
示例15: onChangeBlock
import org.spongepowered.api.event.block.ChangeBlockEvent; //导入方法依赖的package包/类
/**
* Listens to the base change block event.
*
* @param event
*/
@Listener
public void onChangeBlock(final ChangeBlockEvent event) {
Optional<Player> playerCause = event.getCause().first(Player.class);
if (playerCause.isPresent() && Prism.getActiveWands().contains(playerCause.get().getUniqueId())) {
// Cancel and exit event here, not supposed to place/track a block with an active wand.
event.setCancelled(true);
return;
}
for (Transaction<BlockSnapshot> transaction : event.getTransactions()) {
if (!transaction.isValid()) {
continue;
}
PrismRecordEventBuilder record = PrismRecord.create().source(event.getCause());
BlockType original = transaction.getOriginal().getState().getType();
BlockType finalBlock = transaction.getFinal().getState().getType();
if (event instanceof ChangeBlockEvent.Break) {
if (Prism.listening.BREAK &&
!BlockUtil.rejectBreakCombination(original, finalBlock) &&
!EventUtil.rejectBreakEventIdentity(original, finalBlock, event.getCause())) {
record.brokeBlock(transaction).save();
}
}
else if (event instanceof ChangeBlockEvent.Place) {
if (Prism.listening.PLACE &&
!BlockUtil.rejectPlaceCombination(original, finalBlock) &&
!EventUtil.rejectPlaceEventIdentity(original, finalBlock, event.getCause())) {
record.placedBlock(transaction).save();
}
}
else if (event instanceof ChangeBlockEvent.Decay) {
if (Prism.listening.DECAY) {
record.decayedBlock(transaction).save();
}
}
}
}