当前位置: 首页>>代码示例>>Java>>正文


Java NamedCause类代码示例

本文整理汇总了Java中org.spongepowered.api.event.cause.NamedCause的典型用法代码示例。如果您正苦于以下问题:Java NamedCause类的具体用法?Java NamedCause怎么用?Java NamedCause使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


NamedCause类属于org.spongepowered.api.event.cause包,在下文中一共展示了NamedCause类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sendChat

import org.spongepowered.api.event.cause.NamedCause; //导入依赖的package包/类
private void sendChat(Player player, Text message) {
    Text rawMessage = Text.of(message);
    MessageChannelEvent.Chat event = SpongeEventFactory.createMessageChannelEventChat(
            Cause.source(player).named(NamedCause.notifier(player)).build(),
            player.getMessageChannel(),
            Optional.of(player.getMessageChannel()),
            new MessageEvent.MessageFormatter(
                    Text.builder(player.getName()).build(), rawMessage
            ),
            rawMessage,
            false
    );
    if (!Sponge.getEventManager().post(event)) {
        MessageEvent.MessageFormatter formatter = event.getFormatter();
        player.getMessageChannel().send(player, chatTemplate.apply(
                ImmutableMap.of(MessageEvent.PARAM_MESSAGE_HEADER, formatter.getHeader(),
                        MessageEvent.PARAM_MESSAGE_BODY, formatter.getBody(),
                        MessageEvent.PARAM_MESSAGE_FOOTER, formatter.getFooter())).build());
    }
}
 
开发者ID:iLefty,项目名称:mcClans,代码行数:21,代码来源:ClanChatCommands.java

示例2: withdraw

import org.spongepowered.api.event.cause.NamedCause; //导入依赖的package包/类
public static boolean withdraw(UUID uuid, double charge) {
    if (charge == 0) {
        return true;
    }

    EconomyService economyService = MCClans.getPlugin().getServiceHelper().economyService;
    Currency currency = MCClans.getPlugin().getServiceHelper().currency;
    Optional<UniqueAccount> accountOpt = economyService.getOrCreateAccount(uuid);
    if (!accountOpt.isPresent()) {
        return false;
    }

    UniqueAccount account = accountOpt.get();
    TransactionResult result = account.withdraw(
            currency,
            BigDecimal.valueOf(charge),
            Cause.of(NamedCause.of("MCClans", MCClans.getPlugin()))
    );
    return (result.getResult().equals(ResultType.SUCCESS));
}
 
开发者ID:iLefty,项目名称:mcClans,代码行数:21,代码来源:EconomyUtils.java

示例3: onInitCore

import org.spongepowered.api.event.cause.NamedCause; //导入依赖的package包/类
@Listener
public void onInitCore(GameInitializationEvent event) {
    SpongeDataManager manager = SpongeDataManager.getInstance();
    manager.registerDataProcessorAndImpl(AuraNodeData.class, ThaumicAuraNodeData.class, ImmutableAuraNodeData.class,
            ImmutableThaumicAuraNodeData.class, new AuraNodeDataProcessor());
    manager.registerDataProcessorAndImpl(WarpData.class, ThaumicWarpData.class, ImmutableWarpData.class, ImmutableThaumicWarpData.class,
            new PlayerWarpDataProcessor());
    CommandManager commandManager = Sponge.getCommandManager();
    CommandSpec discoAuraCmd = CommandSpec.builder()
            .arguments(GenericArguments.none())
            .description(Text.of("Creates a new Aura node and turns it into a disco ball!"))
            .executor((executor, args) -> {
                if (executor instanceof Player) {
                    Entity auraNode = ((Player) executor).getLocation().getExtent().createEntity(ThaumicEntityTypes.AURA_NODE, ((Player) executor).getLocation().getPosition()).get();
                    AuraNodeData nodeData = new ThaumicAuraNodeData(50, Aspects.AER, false, AuraNodeTypes.NORMAL);
                    auraNode.offer(nodeData);

                    auraNode.getWorld().spawnEntity(auraNode, Cause.of(NamedCause.source(this)));
                    this.auraMap.put(auraNode.getWorld().getUniqueId(), auraNode.getUniqueId());
                    return CommandResult.success();
                }
                return CommandResult.empty();
            })
            .build();
    commandManager.register(this, discoAuraCmd, "disco");
}
 
开发者ID:gabizou,项目名称:ThaumicSponge,代码行数:27,代码来源:ThaumicSpongeMod.java

示例4: checkLocationForLobbySign

import org.spongepowered.api.event.cause.NamedCause; //导入依赖的package包/类
private boolean checkLocationForLobbySign(Location3D location) throws IllegalArgumentException {
    checkArgument(location.getWorld().isPresent(), "Location for lobby sign must contain world");
    java.util.Optional<World> world = Sponge.getServer().getWorld(location.getWorld().get());
    if (!world.isPresent()) {
        throw new IllegalArgumentException("Invalid world for lobby sign location");
    }

    Location<World> loc = WorldLocationConverter.of(location);
    if (!getLobbySignMap().containsKey(location)) {
        java.util.Optional<TileEntity> tile = loc.getExtent().getTileEntity(LocationConverter.floor(location));
        if (!tile.isPresent() || tile.get().getType() != TileEntityTypes.SIGN) {
            //TODO: maybe detect which sign type it should be?
            loc.setBlockType(BlockTypes.WALL_SIGN,
                    Cause.of(NamedCause.of("inferno:lobbyCreation", InfernoPlugin.getInstance())));
        }
        return true;
    }
    return false;
}
 
开发者ID:caseif,项目名称:Inferno,代码行数:20,代码来源:InfernoArena.java

示例5: onChangeBlock

import org.spongepowered.api.event.cause.NamedCause; //导入依赖的package包/类
@Listener(order=Order.FIRST)
@IsCancelled(Tristate.UNDEFINED)
public void onChangeBlock(ChangeBlockEvent.Place event) {
	Optional<Player> optPlayer = event.getCause().get(NamedCause.SOURCE, Player.class);
	if (!optPlayer.isPresent()) return;
	
	Player player = optPlayer.get();
	if (!this.players.contains(player.getUniqueId())) return;
	
	event.setCancelled(true);
	
	event.getTransactions().forEach(transaction -> {
		player.sendMessage(Text.of(TextColors.GRAY, TextStyles.BOLD, "============================================"));
		player.sendMessage(Text.of(TextColors.DARK_GREEN, TextStyles.BOLD, "Block Type: ", TextColors.BLUE, TextStyles.RESET, transaction.getOriginal().getState().getId()));
		player.sendMessage(Text.of(TextColors.DARK_GREEN, TextStyles.BOLD, "Block Owner: ", TextColors.BLUE, TextStyles.RESET, transaction.getOriginal().getCreator()));
		player.sendMessage(Text.of(TextColors.DARK_GREEN, TextStyles.BOLD, "Block Notifier: ", TextColors.BLUE, TextStyles.RESET, transaction.getOriginal().getNotifier()));
	});
}
 
开发者ID:EverCraft,项目名称:EverAPI,代码行数:19,代码来源:EAInfo.java

示例6: onInteractBlock

import org.spongepowered.api.event.cause.NamedCause; //导入依赖的package包/类
@Listener(order=Order.FIRST)
@IsCancelled(Tristate.UNDEFINED)
public void onInteractBlock(InteractBlockEvent.Primary event) {
	Optional<Player> optPlayer = event.getCause().get(NamedCause.SOURCE, Player.class);
	if (!optPlayer.isPresent()) return;
	
	Player player = optPlayer.get();
	if (!this.players.contains(player.getUniqueId())) return;
	
	event.setCancelled(true);
	
	player.sendMessage(Text.of(TextColors.GRAY, TextStyles.BOLD, "============================================"));
	player.sendMessage(Text.of(TextColors.DARK_GREEN, TextStyles.BOLD, "Block Type: ", TextColors.BLUE, TextStyles.RESET, event.getTargetBlock().getState().getId()));
	player.sendMessage(Text.of(TextColors.DARK_GREEN, TextStyles.BOLD, "Block Owner: ", TextColors.BLUE, TextStyles.RESET, event.getTargetBlock().getCreator()));
	player.sendMessage(Text.of(TextColors.DARK_GREEN, TextStyles.BOLD, "Block Notifier: ", TextColors.BLUE, TextStyles.RESET, event.getTargetBlock().getNotifier()));
}
 
开发者ID:EverCraft,项目名称:EverAPI,代码行数:17,代码来源:EAInfo.java

示例7: onInteractEntity

import org.spongepowered.api.event.cause.NamedCause; //导入依赖的package包/类
@Listener(order=Order.FIRST)
@IsCancelled(Tristate.UNDEFINED)
public void onInteractEntity(InteractEntityEvent.Primary event) {
	Optional<Player> optPlayer = event.getCause().get(NamedCause.SOURCE, Player.class);
	if (!optPlayer.isPresent()) return;
	
	Player player = optPlayer.get();
	if (!this.players.contains(player.getUniqueId())) return;
	
	event.setCancelled(true);
	
	player.sendMessage(Text.of(TextColors.GRAY, TextStyles.BOLD, "============================================"));
	player.sendMessage(Text.of(TextColors.DARK_GREEN, TextStyles.BOLD, "Entity Type: ", TextColors.BLUE, TextStyles.RESET, event.getTargetEntity().getType().getId()));
	player.sendMessage(Text.of(TextColors.DARK_GREEN, TextStyles.BOLD, "Entity Owner: ", TextColors.BLUE, TextStyles.RESET, event.getTargetEntity().getCreator()));
	player.sendMessage(Text.of(TextColors.DARK_GREEN, TextStyles.BOLD, "Entity Notifier: ", TextColors.BLUE, TextStyles.RESET, event.getTargetEntity().getNotifier()));
}
 
开发者ID:EverCraft,项目名称:EverAPI,代码行数:17,代码来源:EAInfo.java

示例8: give

import org.spongepowered.api.event.cause.NamedCause; //导入依赖的package包/类
public void give(Player player) {
	this.checkCache();
	for (ItemStackSnapshot iss : itemStacksCache) {
		InventoryTransactionResult result = player.getInventory().offer(iss.createStack());
		for (ItemStackSnapshot is : result.getRejectedItems()) {
			Item item = (Item) player.getLocation().getExtent().createEntity(EntityTypes.ITEM, player.getLocation().getPosition());
			item.offer(Keys.REPRESENTED_ITEM, is.copy());
			player.getWorld().spawnEntity(item, Cause.of(NamedCause.source(player), NamedCause.owner("BetterKits")));
		}
	}

	for (String command : this.getCommands()) {
		try {
			Sponge.getCommandManager().process(Sponge.getServer().getConsole(), command.replace("%name", player.getName()).replace("%uuid", player.getUniqueId().toString()));
		} catch (Throwable e) {
			e.printStackTrace();
		}
	}
}
 
开发者ID:KaiKikuchi,项目名称:BetterKits,代码行数:20,代码来源:Kit.java

示例9: preventExplosion

import org.spongepowered.api.event.cause.NamedCause; //导入依赖的package包/类
private void preventExplosion(ExplosionEvent.Pre event) {
    //"Clone" explosion, as we cannot change the existing one?
    Explosion old = event.getExplosion();
    Explosion newExplosion = Explosion.builder()
            .from(old)
            .shouldBreakBlocks(config.BREAK_BLOCKS)
            .shouldPlaySmoke(config.SHOW_PARTICLES)
            .sourceExplosive(null) //Do not check for a creeper in next Event listener Iteration
            .build();

    //Cancel default event...
    event.setCancelled(true);
    //...but trigger new event
    Cause genericCause = Cause.of(NamedCause.owner(container));
    newExplosion.getWorld().triggerExplosion(newExplosion, genericCause);

    //Remove the creeper (as the default event is canceled);
    ((Creeper) event.getCause().root()).remove();
}
 
开发者ID:Felfio,项目名称:treepers-sponge,代码行数:20,代码来源:Treepers.java

示例10: mountPlayer

import org.spongepowered.api.event.cause.NamedCause; //导入依赖的package包/类
boolean mountPlayer(MountsPlugin plugin)
{
    mountData.clampSpeeds(plugin.config().speeds());

    if (player.getWorld().spawnEntity(vehicle, Cause.source(PLUGIN_SPAWN).named(NamedCause.simulated(player)).build()))
    {
        Sponge.getScheduler().createTaskBuilder()
                .delayTicks(1L)
                .execute(() -> {
                    player.setVehicle(vehicle);
                    vehicle.offer(Keys.PERSISTS, false);
                    vehicle.offer(Keys.DISPLAY_NAME, Text.of(mountData.name()));
                    vehicle.offer(Keys.TAMED_OWNER, Optional.of(player.getUniqueId()));
                    Sponge.getScheduler().createTaskBuilder()
                            .delayTicks(1L)
                            .intervalTicks(1L)
                            .execute(this)
                            .submit(plugin);
                }).submit(plugin);
        Sponge.getEventManager().registerListeners(plugin, this);
        return true;
    }
    return false;
}
 
开发者ID:dags-,项目名称:Mounts,代码行数:25,代码来源:Mount.java

示例11: onItemDrop

import org.spongepowered.api.event.cause.NamedCause; //导入依赖的package包/类
@Listener
public void onItemDrop(DropItemEvent.Destruct event, @Named(NamedCause.SOURCE) BlockSpawnCause spawnCause) {
  BlockSnapshot blockSnapshot = spawnCause.getBlockSnapshot();

  Optional<Location<World>> optLocation = blockSnapshot.getLocation();
  if (!optLocation.isPresent()) {
    return;
  }

  Location<World> loc = optLocation.get();
  if (!markedOrePoints.remove(loc)) {
    return;
  }

  event.getEntities().clear();
}
 
开发者ID:Skelril,项目名称:Skree,代码行数:17,代码来源:BuildWorldWrapper.java

示例12: onItemDrop

import org.spongepowered.api.event.cause.NamedCause; //导入依赖的package包/类
@Listener
public void onItemDrop(DropItemEvent.Destruct event, @Named(NamedCause.SOURCE) BlockSpawnCause spawnCause) {
  if (event.getCause().containsType(Player.class)) {
    return;
  }

  BlockSnapshot blockSnapshot = spawnCause.getBlockSnapshot();

  Optional<Location<World>> optLocation = blockSnapshot.getLocation();
  if (!optLocation.isPresent()) {
    return;
  }

  Location<World> location = optLocation.get();
  while (true) {
    location = location.add(0, -1, 0);
    if (location.getBlockType() != BlockTypes.CACTUS) {
      break;
    }
    location.setBlockType(BlockTypes.AIR, Cause.source(SkreePlugin.container()).build());
  }
}
 
开发者ID:Skelril,项目名称:Skree,代码行数:23,代码来源:AntiCactusFarmListener.java

示例13: onBlockChange

import org.spongepowered.api.event.cause.NamedCause; //导入依赖的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;
        }
      }
    }
  }
}
 
开发者ID:Skelril,项目名称:Skree,代码行数:22,代码来源:GoldRushListener.java

示例14: onEntityDrop

import org.spongepowered.api.event.cause.NamedCause; //导入依赖的package包/类
@Listener
public void onEntityDrop(DropItemEvent.Destruct event, @Named(NamedCause.SOURCE) EntitySpawnCause spawnCause) {
  Entity entity = spawnCause.getEntity();
  if (!(entity instanceof Animal)) {
    return;
  }

  Optional<TheButcherShopInstance> optInst = manager.getApplicableZone(entity);
  if (!optInst.isPresent()) {
    return;
  }

  event.getEntities().clear();

  Item item = (Item) entity.getLocation().createEntity(EntityTypes.ITEM);
  item.offer(Keys.REPRESENTED_ITEM, newItemStack("skree:unpackaged_meat").createSnapshot());

  event.getEntities().add(item);
}
 
开发者ID:Skelril,项目名称:Skree,代码行数:20,代码来源:TheButcherShopListener.java

示例15: onBlockPlace

import org.spongepowered.api.event.cause.NamedCause; //导入依赖的package包/类
@Listener
public void onBlockPlace(ChangeBlockEvent.Place event, @Named(NamedCause.SOURCE) Player player) {
  Optional<CursedMineInstance> optInst = manager.getApplicableZone(player);
  if (!optInst.isPresent()) {
    return;
  }

  for (Transaction<BlockSnapshot> transaction : event.getTransactions()) {
    BlockType originalType = transaction.getFinal().getState().getType();
    BlockType finalType = transaction.getFinal().getState().getType();

    if (isRedstoneTransition(originalType, finalType)) {
      continue;
    }

    event.setCancelled(true);
    break;
  }
}
 
开发者ID:Skelril,项目名称:Skree,代码行数:20,代码来源:CursedMineListener.java


注:本文中的org.spongepowered.api.event.cause.NamedCause类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。