當前位置: 首頁>>代碼示例>>Java>>正文


Java Keys類代碼示例

本文整理匯總了Java中org.spongepowered.api.data.key.Keys的典型用法代碼示例。如果您正苦於以下問題:Java Keys類的具體用法?Java Keys怎麽用?Java Keys使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Keys類屬於org.spongepowered.api.data.key包,在下文中一共展示了Keys類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: listRewards

import org.spongepowered.api.data.key.Keys; //導入依賴的package包/類
public void listRewards(Player player, VirtualCrate vc){
    if(!vc.showRewardsOnLeft) return;
    /* Home */
    StateContainer test = new StateContainer();
    Page.PageBuilder rewards = Page.builder();
    rewards.setAutoPaging(true);
    rewards.setTitle(TextSerializers.FORMATTING_CODE.deserialize(vc.displayName + " Rewards"));
    rewards.setEmptyStack(ItemStack.builder()
            .itemType(ItemTypes.STAINED_GLASS_PANE)
            .add(Keys.DYE_COLOR, DyeColors.BLACK)
            .add(Keys.DISPLAY_NAME, Text.of(TextColors.DARK_GRAY, "HuskyCrates")).build());
    for(Object[] e : vc.getItemSet()){
        CrateReward rew = (CrateReward)e[1];
        ItemStack item = rew.getDisplayItem().copy();
        if(vc.showProbability) {
            ArrayList<Text> lore = (ArrayList<Text>) item.getOrElse(Keys.ITEM_LORE, new ArrayList<>());
            lore.add(Text.of());

            lore.add(Text.of(TextColors.GRAY, TextStyles.ITALIC, "Win Probability: " + BigDecimal.valueOf((rew.getChance() / vc.getMaxProb()) * 100d).setScale(1, RoundingMode.HALF_UP).toString() + "%"));
            item.offer(Keys.ITEM_LORE, lore);
        }
        rewards.addElement(new Element(item));
    }
    test.setInitialState(rewards.build("rewards"));
    test.launchFor(player);
}
 
開發者ID:codeHusky,項目名稱:HuskyCrates-Sponge,代碼行數:27,代碼來源:HuskyCrates.java

示例2: getCrateKey

import org.spongepowered.api.data.key.Keys; //導入依賴的package包/類
/***
 * Retrieve the crate item
 * @since 0.10.2
 * @return the ItemStack with the keys.
 */
public ItemStack getCrateKey(int quantity){
    ItemStack key = ItemStack.builder()
            .itemType(keyType)
            .quantity(quantity)
            .add(Keys.DISPLAY_NAME, TextSerializers.FORMATTING_CODE.deserialize(displayName + " Key")).build();
    ArrayList<Text> itemLore = new ArrayList<>();
    itemLore.add(Text.of(TextColors.WHITE, "A key for a ", TextSerializers.FORMATTING_CODE.deserialize(displayName), TextColors.WHITE, "."));
    itemLore.add(Text.of(TextColors.DARK_GRAY, "HuskyCrates"));
    key.offer(Keys.ITEM_LORE, itemLore);
    if(keyDamage != null){
        key = ItemStack.builder().fromContainer(key.toContainer().set(DataQuery.of("UnsafeDamage"),keyDamage)).build();
    }
    String keyUUID = registerKey(quantity);
    if(keyUUID == null){
        HuskyCrates.instance.logger.error("Throwing NullPointerException: Key failed to register.");
        throw new NullPointerException();
    }
    return ItemStack.builder().fromContainer(key.toContainer().set(DataQuery.of("UnsafeData","crateID"),id).set(DataQuery.of("UnsafeData","keyUUID"),keyUUID)).build();//

}
 
開發者ID:codeHusky,項目名稱:HuskyCrates-Sponge,代碼行數:26,代碼來源:VirtualCrate.java

示例3: getCrateWand

import org.spongepowered.api.data.key.Keys; //導入依賴的package包/類
/***
 * Retrieve the crate item
 * @since 1.2.1
 * @return the ItemStack with the keys.
 */
public ItemStack getCrateWand(){
    ItemStack key = ItemStack.builder()
            .itemType(ItemTypes.BLAZE_ROD)
            .add(Keys.DISPLAY_NAME, TextSerializers.FORMATTING_CODE.deserialize(displayName + " Wand")).build();
    ArrayList<Text> itemLore = new ArrayList<>();
    itemLore.add(Text.of(TextColors.WHITE, "A wand for a ", TextSerializers.FORMATTING_CODE.deserialize(displayName), TextColors.WHITE, "."));
    itemLore.add(Text.of(TextColors.DARK_GRAY, "HuskyCrates"));
    key.offer(Keys.ITEM_LORE, itemLore);
    if(keyDamage != null){
        key = ItemStack.builder().fromContainer(key.toContainer().set(DataQuery.of("UnsafeDamage"),keyDamage)).build();
    }

    return ItemStack.builder().fromContainer(key.toContainer().set(DataQuery.of("UnsafeData","crateID"),id)).build();//

}
 
開發者ID:codeHusky,項目名稱:HuskyCrates-Sponge,代碼行數:21,代碼來源:VirtualCrate.java

示例4: makeSpongeStack

import org.spongepowered.api.data.key.Keys; //導入依賴的package包/類
@Override
public ItemStack makeSpongeStack(BaseItemStack baseItemStack) {
    final ItemType itemType = ItemRegistryModule.get().getTypeByInternalId(baseItemStack.getType())
            .orElseThrow(() -> new IllegalStateException("Invalid item type: " + baseItemStack.getType()));
    final LanternItemStack itemStack = new LanternItemStack(itemType, baseItemStack.getAmount());
    final ObjectStore<LanternItemStack> store = ObjectStoreRegistry.get().get(LanternItemStack.class)
            .orElseThrow(() -> new IllegalStateException("Unable to access the LanternItemStack store."));
    final DataView view = DataContainer.createNew(DataView.SafetyMode.NO_DATA_CLONED);
    view.set(DATA_VALUE, baseItemStack.getData());
    store.deserialize(itemStack, view);
    final Map<Integer, Integer> enchantments = baseItemStack.getEnchantments();
    if (!enchantments.isEmpty()) {
        itemStack.offer(Keys.ITEM_ENCHANTMENTS, enchantments.entrySet().stream()
                .map(entry -> {
                    final Enchantment enchantment = EnchantmentRegistryModule.get().getByInternalId(entry.getKey())
                            .orElseThrow(() -> new IllegalStateException("Invalid enchantment type: " + entry.getKey()));
                    return new ItemEnchantment(enchantment, entry.getValue());
                })
                .collect(Collectors.toList()));
    }
    return itemStack;
}
 
開發者ID:LanternPowered,項目名稱:LanternWorldEdit,代碼行數:23,代碼來源:LanternImplAdapter.java

示例5: readFrom

import org.spongepowered.api.data.key.Keys; //導入依賴的package包/類
@Override
public void readFrom(DataView data) {
    super.readFrom(data);

    this.tracker.readFrom(this.world, data);
    this.pickaxeStand = (ArmorStand) this.tracker.get("toolStand");
    this.block.setStand((ArmorStand) this.tracker.get("blockStand"));
    FallingBlock falling = (FallingBlock) this.tracker.get("blockEntity");
    this.block.setEntity(falling, false);
    if (falling != null) {
        // Vanilla serializes this as a byte so we need to set it back to Integer.MIN_VALUE
        falling.offer(Keys.FALL_TIME, Integer.MIN_VALUE);
    }

    this.task.readFrom(data.getView(of("task")).get());
}
 
開發者ID:simon816,項目名稱:Industrialization,代碼行數:17,代碼來源:TurtleEntity.java

示例6: getTime

import org.spongepowered.api.data.key.Keys; //導入依賴的package包/類
private static double getTime(Player player, TimeUnit unit) {
	boolean ticks = unit == null;
	long time = Optional.ofNullable(
			player.get(Keys.STATISTICS).orElseThrow(() -> new IllegalStateException("Player must have statistics!"))
					.get(Statistics.TIME_PLAYED))
			.orElse(0L);
	if (ticks) {
		return time;
	} else {
		double time2 = ((double) time) / 20;
		if (unit == TimeUnit.SECONDS) {
			return time2;
		}
		double value = time2 / TimeUnit.SECONDS.convert(1, unit);
		return value;
	}
}
 
開發者ID:rojo8399,項目名稱:PlaceholderAPI,代碼行數:18,代碼來源:Defaults.java

示例7: setupArmorStand

import org.spongepowered.api.data.key.Keys; //導入依賴的package包/類
private void setupArmorStand(ArmorStand stand, Vector3d rotation) {
    ArmorStandData data = stand.getOrCreate(ArmorStandData.class).get();
    data.set(data.basePlate().set(false));
    data.set(data.marker().set(true));
    stand.offer(data);
    stand.offer(Keys.HAS_GRAVITY, false);
    if (rotation != null) {
        stand.offer(Keys.HEAD_ROTATION, rotation);
    }
    stand.setRotation(Vector3d.ZERO);
    stand.setHelmet(this.pane);
    // EntityArmorStand entStand = (EntityArmorStand) stand;
    // entStand.preventEntitySpawning = false;
    // entStand.width = 0.5F;
    // entStand.height = 1.1F;
    // entStand.noClip = true;
    // AxisAlignedBB bb = entStand.getEntityBoundingBox();
    // entStand.setEntityBoundingBox(new AxisAlignedBB(bb.minX, bb.minY, bb.minZ,
    // bb.minX + 0.5, bb.minY + 0.5, bb.minZ + 0.5));

    stand.tryOffer(Keys.INVISIBLE, true);
}
 
開發者ID:simon816,項目名稱:Industrialization,代碼行數:23,代碼來源:PipeBlock.java

示例8: getCommand

import org.spongepowered.api.data.key.Keys; //導入依賴的package包/類
public static CommandSpec getCommand() {
    return CommandSpec.builder()
        .description(Text.of("Vanish."))
        .permission("bedrock.vanish")
        .executor((source, args) -> {
            if (!(source instanceof Player)) {
                source.sendMessage(Format.error("Only players may use this command."));
                return CommandResult.empty();
            }

            Player player = (Player) source;

            // Flip boolean
            boolean wasVisible = player.get(Keys.INVISIBLE).orElse(false);
            player.offer(Keys.INVISIBLE, !wasVisible);
            player.offer(Keys.INVISIBILITY_IGNORES_COLLISION, true);
            player.offer(Keys.INVISIBILITY_PREVENTS_TARGETING, true);

            source.sendMessage(Format.success("You're now " + (wasVisible ? "" : "in") + "visible"));

            return CommandResult.success();
        }).build();
}
 
開發者ID:prism,項目名稱:Bedrock,代碼行數:24,代碼來源:VanishCommand.java

示例9: connect

import org.spongepowered.api.data.key.Keys; //導入依賴的package包/類
public void connect() {
	Optional<EPlayer> optPlayer = this.getEPlayer();
	if (optPlayer.isPresent()) {
		EPlayer player = optPlayer.get();
		
		if (player.get(Keys.INVISIBLE).orElse(false) != vanish) {
			player.offer(Keys.INVISIBLE, vanish);
		}
		
		this.updateLastActivated();
		this.startTotalTimePlayed();
		this.setLastIp(player.getConnection().getAddress().getAddress());
		
	} else {
		this.plugin.getELogger().warn("Player empty : connect");
	}
	this.afk = false;
}
 
開發者ID:EverCraft,項目名稱:EverEssentials,代碼行數:19,代碼來源:EUserSubject.java

示例10: onPlayerJoin

import org.spongepowered.api.data.key.Keys; //導入依賴的package包/類
@Listener
public void onPlayerJoin(final ClientConnectionEvent.Join event) {
    Player player = event.getTargetEntity();

    // Create/load config
    Bedrock.getPlayerConfigManager().loadPlayer(player);

    // Is brand new?
    if (player.get(Keys.FIRST_DATE_PLAYED).get().equals(player.get(Keys.LAST_DATE_PLAYED).get())) {
        // Force spawn position because vanilla has a "fuzz" radius around spawn
        Location<World> spawn = player.getWorld().getLocation(player.getWorld().getProperties().getSpawnPosition());

        player.setLocation(spawn);

        MessageChannel.TO_ALL.send(Text.of(TextColors.GOLD, "Welcome ", TextColors.LIGHT_PURPLE,
            player.getName(),TextColors.GOLD, " to DHMC!"));
    }
}
 
開發者ID:prism,項目名稱:Bedrock,代碼行數:19,代碼來源:JoinListener.java

示例11: isSignAndShop

import org.spongepowered.api.data.key.Keys; //導入依賴的package包/類
private boolean isSignAndShop(Location<World> loc, Direction dir, boolean wall) {
	if (loc.getRelative(dir).getBlockType() == (wall ? BlockTypes.WALL_SIGN : BlockTypes.STANDING_SIGN)) {
		if (wall) {
			Location<World> sign = loc.getRelative(dir);
			if (sign.supports(Keys.DIRECTION)) {
				Optional<Direction> direction = sign.get(Keys.DIRECTION);
				if (direction.isPresent()) {
					if (direction.get() != dir)
						return false;
				}
			}
		}
		Optional<List<Shop>> shops = ShopsData.getShops(loc.getRelative(dir));
		if (shops.isPresent())
			return true;
	}
	return false;
}
 
開發者ID:TheoKah,項目名稱:CarrotShop,代碼行數:19,代碼來源:BlockBreakListener.java

示例12: trigger

import org.spongepowered.api.data.key.Keys; //導入依賴的package包/類
@Override
public boolean trigger(Player player) {
	if (CarrotShop.getEcoService() != null) {
		UniqueAccount buyerAccount = CarrotShop.getEcoService().getOrCreateAccount(player.getUniqueId()).get();
		TransactionResult result = buyerAccount.withdraw(getCurrency(), BigDecimal.valueOf(price), CarrotShop.getCause());
		if (result.getResult() != ResultType.SUCCESS) {
			player.sendMessage(Text.of(TextColors.DARK_RED, "You don't have enough money!"));
			return false;
		}
		player.sendMessage(Text.of("You healed for ", formatPrice(price)));
	}
	else
		player.sendMessage(Text.of("You healed"));

	player.offer(Keys.HEALTH, player.get(Keys.MAX_HEALTH).get());

	return true;
}
 
開發者ID:TheoKah,項目名稱:CarrotShop,代碼行數:19,代碼來源:Heal.java

示例13: getPistonCause

import org.spongepowered.api.data.key.Keys; //導入依賴的package包/類
private static BlockSnapshot getPistonCause(Cause cause) {
    List<BlockSnapshot> blockCauses = cause.allOf(BlockSnapshot.class);
    for (BlockSnapshot blockCause : blockCauses) {
        BlockType type = blockCause.getState().getType();
        if (type == BlockTypes.PISTON || type == BlockTypes.STICKY_PISTON) {
            return blockCause;
        }
        if (type == BlockTypes.PISTON_EXTENSION
                && blockCause.getState().get(Keys.PISTON_TYPE).get() == PistonTypes.STICKY) {
            // For some reason, when a sticky piston is retracting, the cause is the extension
            // block
            return blockCause;
        }
    }
    return null;
}
 
開發者ID:simon816,項目名稱:Industrialization,代碼行數:17,代碼來源:CustomBlockEventListeners.java

示例14: execute

import org.spongepowered.api.data.key.Keys; //導入依賴的package包/類
@Override
public void execute(CommandQueue queue, CommandEntry entry) {
    ItemTag item = ItemTag.getFor(queue.error, entry.getArgumentObject(queue, 0));
    LocationTag locationTag = LocationTag.getFor(queue.error, entry.getArgumentObject(queue, 1));
    UtilLocation location = locationTag.getInternal();
    if (location.world == null) {
        queue.handleError(entry, "Invalid location with no world in Spawn command!");
        return;
    }
    Entity entity = location.world.createEntity(EntityTypes.ITEM, location.toVector3d());
    entity.offer(Keys.REPRESENTED_ITEM, item.getInternal().createSnapshot());
    location.world.spawnEntity(entity);
    if (queue.shouldShowGood()) {
        queue.outGood("Dropped item " + ColorSet.emphasis + item.debug() + ColorSet.good
                + " at location " + ColorSet.emphasis + locationTag.debug() + ColorSet.good + "!");
    }
}
 
開發者ID:DenizenScript,項目名稱:Denizen2Sponge,代碼行數:18,代碼來源:DropCommand.java

示例15: onBreakBlock

import org.spongepowered.api.data.key.Keys; //導入依賴的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


注:本文中的org.spongepowered.api.data.key.Keys類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。