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


Java HandTypes类代码示例

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


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

示例1: execute

import org.spongepowered.api.data.type.HandTypes; //导入依赖的package包/类
@Override public CommandResult execute(CommandSource commandSource, CommandContext commandContext) throws CommandException {
    if (!(commandSource instanceof Player)) {
        commandSource.sendMessage(Text.of("You need to be in game or specify a player for this command to work."));
        return CommandResult.empty();
    }
    Player plr = (Player)commandSource;
    if(!plr.getItemInHand(HandTypes.MAIN_HAND).isPresent()){
        commandSource.sendMessage(Text.of("You must be holding an item to deposit a key."));
        return CommandResult.empty();
    }
    ItemStack key = plr.getItemInHand(HandTypes.MAIN_HAND).get();
    if(HuskyCrates.instance.crateUtilities.vcFromKey(key) == null){
        commandSource.sendMessage(Text.of(TextColors.RED,"Not a valid key."));
        return CommandResult.empty();
    }
    VirtualCrate virtualCrate = HuskyCrates.instance.crateUtilities.vcFromKey(plr.getItemInHand(HandTypes.MAIN_HAND).get());
    int keyCount = key.getQuantity();
    plr.setItemInHand(HandTypes.MAIN_HAND,null);
    virtualCrate.giveVirtualKeys(plr,keyCount);
    //commandSource.sendMessage(Text.of(TextColors.GREEN,"Successfully deposited " + keyCount + " ", TextSerializers.FORMATTING_CODE.deserialize(virtualCrate.displayName),TextColors.GREEN," Key(s)."));
    commandSource.sendMessage(TextSerializers.FORMATTING_CODE.deserialize(
            virtualCrate.getLangData().formatter(virtualCrate.getLangData().depositSuccess,null,plr,virtualCrate,null,null,keyCount)
    ));
    return CommandResult.success();
}
 
开发者ID:codeHusky,项目名称:HuskyCrates-Sponge,代码行数:26,代码来源:DepositKey.java

示例2: onPlayerLeftClickProtect

import org.spongepowered.api.data.type.HandTypes; //导入依赖的package包/类
@Listener(order=Order.FIRST, beforeModifications = true)
public void onPlayerLeftClickProtect(InteractBlockEvent.Primary.MainHand event, @First Player player)
{
	if (!player.gameMode().get().equals(GameModes.CREATIVE))
		return;

	Optional<Location<World>> optLoc = event.getTargetBlock().getLocation();
	if (!optLoc.isPresent())
		return;

	Optional<List<Shop>> shop = ShopsData.getShops(optLoc.get());
	if (shop.isPresent()) {
		Optional<ItemStack> optItem = player.getItemInHand(HandTypes.MAIN_HAND);

		if (!optItem.isPresent() || (!optItem.get().getItem().equals(ItemTypes.BEDROCK) && !optItem.get().getItem().equals(ItemTypes.REDSTONE) && !optItem.get().getItem().equals(ItemTypes.STICK))) {
			event.setCancelled(true);
		}
	}
}
 
开发者ID:TheoKah,项目名称:CarrotShop,代码行数:20,代码来源:PlayerClickListener.java

示例3: onInteract

import org.spongepowered.api.data.type.HandTypes; //导入依赖的package包/类
@Listener(order=Order.FIRST, beforeModifications = true)
public void onInteract(InteractBlockEvent event, @First Player player)
{
	if (!ConfigHandler.getNode("worlds").getNode(player.getWorld().getName()).getNode("enabled").getBoolean())
	{
		return;
	}
	if (player.hasPermission("nations.admin.bypass.perm.interact"))
	{
		return;
	}
	Optional<ItemStack> optItem = player.getItemInHand(HandTypes.MAIN_HAND);
	if (optItem.isPresent() && (ConfigHandler.isWhitelisted("use", optItem.get().getItem().getId()) || optItem.get().getItem().equals(ItemTypes.GOLDEN_AXE) && ConfigHandler.getNode("others", "enableGoldenAxe").getBoolean(true)))
		return;
	event.getTargetBlock().getLocation().ifPresent(loc -> {
		if (!DataHandler.getPerm("interact", player.getUniqueId(), loc))
		{
			event.setCancelled(true);
			if (loc.getBlockType() != BlockTypes.STANDING_SIGN && loc.getBlockType() != BlockTypes.WALL_SIGN)
				player.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_PERM_INTERACT));
		}
	});
}
 
开发者ID:Arckenver,项目名称:Nations,代码行数:24,代码来源:InteractPermListener.java

示例4: onInteractBlock

import org.spongepowered.api.data.type.HandTypes; //导入依赖的package包/类
@Listener
public void onInteractBlock(InteractBlockEvent event) {
    java.util.Optional<Player> player = event.getCause().first(Player.class);
    if (!player.isPresent()) {
        return;
    }

    // check if the damager is a challenger
    Optional<Challenger> challenger = Main.getMinigame().getChallenger(player.get().getUniqueId());
    if (challenger.isPresent()) { // damager is a challenger
        // check if the round hasn't started yet
        if (!challenger.get().getRound().getLifecycleStage().getId().equals(Main.PLAYING_STAGE_ID)) {
            event.setCancelled(true); // can't break blocks in advance
        }
        // check if they're holding a shovel
        if (!player.get().getItemInHand(HandTypes.MAIN_HAND).isPresent()
                || !Main.SHOVELS.contains(player.get().getItemInHand(HandTypes.MAIN_HAND).get().getItem())) {
            event.setCancelled(true); // can't break blocks without a shovel
        }
    }
}
 
开发者ID:caseif,项目名称:InfernoSpleef,代码行数:22,代码来源:BlockListener.java

示例5: onBreakBlock

import org.spongepowered.api.data.type.HandTypes; //导入依赖的package包/类
@Listener
public void onBreakBlock(ChangeBlockEvent.Break event) {
    java.util.Optional<Player> player = event.getCause().first(Player.class);
    if (!player.isPresent()) {
        return;
    }

    // check if the damager is a challenger
    Optional<Challenger> challenger = Main.getMinigame().getChallenger(player.get().getUniqueId());
    if (challenger.isPresent()) {
        if (player.get().getItemInHand(HandTypes.MAIN_HAND).isPresent()) {
            if (player.get().getItemInHand(HandTypes.MAIN_HAND).get().getValue(Keys.ITEM_DURABILITY).isPresent()) {
                player.get().getItemInHand(HandTypes.MAIN_HAND).get().getValue(Keys.ITEM_DURABILITY).get().set(0);
            }
        }
    }
}
 
开发者ID:caseif,项目名称:InfernoSpleef,代码行数:18,代码来源:BlockListener.java

示例6: tabCompleter

import org.spongepowered.api.data.type.HandTypes; //导入依赖的package包/类
@Override
public Collection<String> tabCompleter(final CommandSource source, final List<String> args) throws CommandException {
	if(source instanceof Player) {
		if (args.size() == 1) {
			Optional<ItemStack> item = ((Player) source).getItemInHand(HandTypes.MAIN_HAND);
			if(item.isPresent()) {
				Optional<List<Text>> lore = item.get().get(Keys.ITEM_LORE);
				if(lore.isPresent()) {
					if(lore.get().size() >= 1) {
						return Arrays.asList("1", String.valueOf(lore.get().size()));
					} else {
						return Arrays.asList("1");
					}
				}
			}
		} else if(args.size() == 2) {
			if(((Player) source).getItemInHand(HandTypes.MAIN_HAND).isPresent()){
				return Arrays.asList("&bHello world");
			}
		}
	}
	return Arrays.asList();
}
 
开发者ID:EverCraft,项目名称:EverEssentials,代码行数:24,代码来源:EEItemLoreSet.java

示例7: commandItemLoreClear

import org.spongepowered.api.data.type.HandTypes; //导入依赖的package包/类
private CompletableFuture<Boolean> commandItemLoreClear(final EPlayer player) {
	if(!player.getItemInHand(HandTypes.MAIN_HAND).isPresent()) {
		EAMessages.EMPTY_ITEM_IN_HAND.sender()
			.prefix(EEMessages.PREFIX)
			.sendTo(player);
		return CompletableFuture.completedFuture(false);
	}
	
	ItemStack item = player.getItemInMainHand().get();
	if(!item.get(Keys.ITEM_LORE).isPresent()) {
		EEMessages.ITEM_LORE_CLEAR_ERROR.sender()
			.replace("{item}", EChat.getButtomItem(item, EEMessages.ITEM_LORE_CLEAR_COLOR.getColor()))
			.sendTo(player);
	}
	
	EEMessages.ITEM_LORE_CLEAR_NAME.sender()
		.replace("{item}", EChat.getButtomItem(item, EEMessages.ITEM_LORE_CLEAR_COLOR.getColor()))
		.sendTo(player);
	
	item.remove(Keys.ITEM_LORE);
	player.setItemInHand(HandTypes.MAIN_HAND, item);
	return CompletableFuture.completedFuture(true);
}
 
开发者ID:EverCraft,项目名称:EverEssentials,代码行数:24,代码来源:EEItemLoreClear.java

示例8: tabCompleter

import org.spongepowered.api.data.type.HandTypes; //导入依赖的package包/类
@Override
public Collection<String> tabCompleter(final CommandSource source, final List<String> args) throws CommandException {
	if (args.size() == 1 && source instanceof Player) {
		Optional<ItemStack> item = ((Player) source).getItemInHand(HandTypes.MAIN_HAND);
		if(item.isPresent()) {
			Optional<List<Text>> lore = item.get().get(Keys.ITEM_LORE);
			if(lore.isPresent()) {
				if(lore.get().size() >= 1) {
					return Arrays.asList("1", String.valueOf(lore.get().size()));
				} else {
					return Arrays.asList("1");
				}
			}
		}
	}
	return Arrays.asList();
}
 
开发者ID:EverCraft,项目名称:EverEssentials,代码行数:18,代码来源:EEItemLoreRemove.java

示例9: commandItemLoreAdd

import org.spongepowered.api.data.type.HandTypes; //导入依赖的package包/类
private CompletableFuture<Boolean> commandItemLoreAdd(final EPlayer player, final String name) {
	if(!player.getItemInHand(HandTypes.MAIN_HAND).isPresent()) {
		EAMessages.EMPTY_ITEM_IN_HAND.sender()
			.prefix(EEMessages.PREFIX)
			.sendTo(player);
		return CompletableFuture.completedFuture(false);
	}
	
	ItemStack item = player.getItemInHand(HandTypes.MAIN_HAND).get();
	List<Text> lore = new ArrayList<Text>();
	if(item.get(Keys.ITEM_LORE).isPresent()){
		lore = item.get(Keys.ITEM_LORE).get();
	}
	lore.add(EChat.of(name));
	item.offer(Keys.ITEM_LORE, lore);
	EEMessages.ITEM_LORE_ADD_LORE.sender()
		.replace("{item}", EChat.getButtomItem(item, EEMessages.ITEM_LORE_ADD_COLOR.getColor()))
		.sendTo(player);
	item.offer(Keys.ITEM_LORE, lore);
	player.setItemInHand(HandTypes.MAIN_HAND, item);
	return CompletableFuture.completedFuture(true);
}
 
开发者ID:EverCraft,项目名称:EverEssentials,代码行数:23,代码来源:EEItemLoreAdd.java

示例10: handleEvent

import org.spongepowered.api.data.type.HandTypes; //导入依赖的package包/类
@Override
protected void handleEvent(EntityProtocolUpdateContext context, EntityEvent event) {
    if (event instanceof DamagedEntityEvent) {
        context.sendToAll(() -> new MessagePlayOutEntityAnimation(getRootEntityId(), 1));
    } else if (event instanceof SwingHandEntityEvent) {
        final HandType handType = ((SwingHandEntityEvent) event).getHandType();
        if (handType == HandTypes.MAIN_HAND) {
            context.sendToAllExceptSelf(() -> new MessagePlayOutEntityAnimation(getRootEntityId(), 0));
        } else if (handType == HandTypes.OFF_HAND) {
            context.sendToAllExceptSelf(() -> new MessagePlayOutEntityAnimation(getRootEntityId(), 3));
        } else {
            super.handleEvent(context, event);
        }
    } else {
        super.handleEvent(context, event);
    }
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:18,代码来源:LivingEntityProtocol.java

示例11: decode

import org.spongepowered.api.data.type.HandTypes; //导入依赖的package包/类
@Override
public MessagePlayInUseEntity decode(CodecContext context, ByteBuffer buf) throws CodecException {
    final int entityId = buf.readVarInt();
    final int action = buf.readVarInt();
    if (action == 1) {
        return new MessagePlayInUseEntity.Attack(entityId);
    } else if (action == 0 || action == 2) {
        Vector3d position = null;
        if (action == 2) {
            final double x = buf.readFloat();
            final double y = buf.readFloat();
            final double z = buf.readFloat();
            position = new Vector3d(x, y, z);
        }
        final HandType hand = buf.readVarInt() == 0 ? HandTypes.MAIN_HAND : HandTypes.OFF_HAND;
        return new MessagePlayInUseEntity.Interact(entityId, hand, position);
    } else {
        throw new DecoderException("Received a UseEntity message with a unknown action: " + action);
    }
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:21,代码来源:CodecPlayInUseEntity.java

示例12: execute

import org.spongepowered.api.data.type.HandTypes; //导入依赖的package包/类
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	if (src instanceof Player)
	{
		Player player = (Player) src;

		if (player.getItemInHand(HandTypes.MAIN_HAND).isPresent())
		{
			ItemStack itemInHand = player.getItemInHand(HandTypes.MAIN_HAND).get();
			player.sendMessage(Text.of(TextColors.GOLD, "The name of the item in your hand is: ", TextColors.GRAY, itemInHand.getTranslation().get()));
			player.sendMessage(Text.of(TextColors.GOLD, "The ID of the item in your hand is: ", TextColors.GRAY, itemInHand.getItem().getId()));
			player.sendMessage(Text.of(TextColors.GOLD, "The meta of the item in your hand is: ", TextColors.GRAY, itemInHand.toContainer().get(DataQuery.of("UnsafeDamage")).get().toString()));
		}
		else
		{
			player.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You must hold an item."));
		}
	}
	else
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You must be an in-game player to use this command."));
	}

	return CommandResult.success();
}
 
开发者ID:hsyyid,项目名称:EssentialCmds,代码行数:26,代码来源:ItemInfoExecutor.java

示例13: execute

import org.spongepowered.api.data.type.HandTypes; //导入依赖的package包/类
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	Player target = ctx.<Player> getOne("target").get();

	if (src instanceof Player)
	{
		Player player = (Player) src;

		if (target.getItemInHand(HandTypes.MAIN_HAND).isPresent())
		{
			player.getInventory().offer(target.getItemInHand(HandTypes.MAIN_HAND).get());
			target.setItemInHand(HandTypes.MAIN_HAND, null);
			player.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Took " + target.getName() + "'s held item."));
		}
		else
		{
			player.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Target is not holding anything!"));
		}
	}
	else
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You must be an in-game player to take other players items!"));
	}

	return CommandResult.success();
}
 
开发者ID:hsyyid,项目名称:EssentialCmds,代码行数:27,代码来源:TakeExecutor.java

示例14: execute

import org.spongepowered.api.data.type.HandTypes; //导入依赖的package包/类
@Nonnull
@Override
public CommandResult execute(@Nonnull CommandSource src, @Nonnull CommandContext args)
        throws CommandException {

    SurvivalGame survivalGame = (SurvivalGame) getOrThrow(args, CommandKeys.SURVIVAL_GAME);

    if (!(src instanceof Player)) {
        throw new CommandException(Text.of("Only players can execute this command"));
    }

    Player player = (Player) src;
    ItemStack itemStack = getOrThrow(player.getItemInHand(HandTypes.MAIN_HAND), "item");

    survivalGame.getConfig().getItemConfig().getItems().add(itemStack.createSnapshot());

    sendSuccess(src, "Item added", itemStack.getItem().getName());
    return CommandResult.success();
}
 
开发者ID:m0pt0pmatt,项目名称:SurvivalGames,代码行数:20,代码来源:AddItemInHandCommand.java

示例15: canInteract

import org.spongepowered.api.data.type.HandTypes; //导入依赖的package包/类
private boolean canInteract(Player p, Region r){
	boolean claimRps = RedProtect.get().cfgs.getGlobalFlag(p.getWorld().getName(),"deny-item-usage","allow-on-claimed-rps");
	boolean wilderness = RedProtect.get().cfgs.getGlobalFlag(p.getWorld().getName(),"deny-item-usage","allow-on-wilderness");
	
	ItemType item = ItemTypes.NONE;
	if (p.getItemInHand(HandTypes.MAIN_HAND).isPresent()){
		item = p.getItemInHand(HandTypes.MAIN_HAND).get().getItem();
       } else if (p.getItemInHand(HandTypes.OFF_HAND).isPresent()){
       	item = p.getItemInHand(HandTypes.OFF_HAND).get().getItem();
       }
	
	//deny item usage		
   	if (!RedProtect.get().ph.hasPerm(p, "RedProtect.get().bypass") && !item.equals(ItemTypes.NONE) && RedProtect.get().cfgs.getGlobalFlagList(p.getWorld().getName(),"deny-item-usage","items").contains(item.getType().getName())){
   		if (r != null && ((!claimRps && r.canBuild(p)) || (claimRps && !r.canBuild(p)))){
   			RPLang.sendMessage(p, "playerlistener.region.cantuse");
   			return false;
   		}
   		if (r == null && !wilderness){
   			RPLang.sendMessage(p, "playerlistener.region.cantuse");
   			return false;
   		}
       }
   	return true;
}
 
开发者ID:FabioZumbi12,项目名称:RedProtect,代码行数:25,代码来源:RPGlobalListener.java


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