本文整理汇总了Java中org.spongepowered.api.item.inventory.ItemStack.get方法的典型用法代码示例。如果您正苦于以下问题:Java ItemStack.get方法的具体用法?Java ItemStack.get怎么用?Java ItemStack.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.spongepowered.api.item.inventory.ItemStack
的用法示例。
在下文中一共展示了ItemStack.get方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getItemID
import org.spongepowered.api.item.inventory.ItemStack; //导入方法依赖的package包/类
public String getItemID(ItemStack si) {
if (si.supports(Keys.ITEM_BLOCKSTATE)) {
Optional<BlockState> bs = si.get(Keys.ITEM_BLOCKSTATE);
if (bs.isPresent()) {
return bs.get().getId();
}
}
return si.getItem().getId();
}
示例2: repairInventory
import org.spongepowered.api.item.inventory.ItemStack; //导入方法依赖的package包/类
public static ItemStack repairInventory(final ItemStack stack) {
Optional<Integer> data = stack.get(Keys.ITEM_DURABILITY);
if (data.isPresent()) {
stack.offer(Keys.ITEM_DURABILITY, Integer.MAX_VALUE);
}
return stack;
}
示例3: commandRepair
import org.spongepowered.api.item.inventory.ItemStack; //导入方法依赖的package包/类
private CompletableFuture<Boolean> commandRepair(final EPlayer player) {
Optional<ItemStack> optItem = player.getItemInMainHand();
if (!optItem.isPresent()) {
EAMessages.EMPTY_ITEM_IN_HAND.sendTo(player);
return CompletableFuture.completedFuture(false);
}
ItemStack item = optItem.get();
Optional<Integer> durability = item.get(Keys.ITEM_DURABILITY);
if (!durability.isPresent()) {
EEMessages.REPAIR_HAND_ERROR.sender()
.replace("{item}", EChat.getButtomItem(item, EEMessages.REPAIR_HAND_ITEM_COLOR.getColor()))
.sendTo(player);
return CompletableFuture.completedFuture(false);
}
item.offer(Keys.ITEM_DURABILITY, Integer.MAX_VALUE);
if (item.get(Keys.ITEM_DURABILITY).get() == durability.get()) {
EEMessages.REPAIR_HAND_MAX_DURABILITY.sender()
.replace("{item}", EChat.getButtomItem(item, EEMessages.REPAIR_HAND_ITEM_COLOR.getColor()))
.sendTo(player);
return CompletableFuture.completedFuture(false);
}
player.setItemInMainHand(item);
EEMessages.REPAIR_HAND_PLAYER.sender()
.replace("{item}", EChat.getButtomItem(item, EEMessages.REPAIR_HAND_ITEM_COLOR.getColor()))
.sendTo(player);
return CompletableFuture.completedFuture(true);
}
示例4: getData
import org.spongepowered.api.item.inventory.ItemStack; //导入方法依赖的package包/类
private static DataView getData(ItemStack itemStack) {
Optional<CustomItemData> opData = itemStack.get(CustomItemData.class);
if (opData.isPresent()) {
return opData.get().getData();
}
return null;
}
示例5: execute
import org.spongepowered.api.item.inventory.ItemStack; //导入方法依赖的package包/类
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
if (!(src instanceof Player)) {
src.sendMessage(Text.of(TextColors.RED, "Player only!"));
return CommandResult.success();
}
Player player = (Player) src;
Optional<ItemStack> itemStackOpt = player.getItemInHand(HandTypes.MAIN_HAND);
if (!itemStackOpt.isPresent()) {
player.sendMessage(Text.of(TextColors.RED, "You must hold an item in your hand"));
return CommandResult.success();
}
ItemStack itemStack = itemStackOpt.get();
JSONObject awardData = new JSONObject()
.put("type", "item")
.put("itemType", itemStack.getType().getId())
.put("quantity", itemStack.getQuantity());
Optional<Text> displayNameOpt = itemStack.get(Keys.DISPLAY_NAME);
if (displayNameOpt.isPresent()) {
awardData.put("displayName", TextSerializers.FORMATTING_CODE.serialize(displayNameOpt.get()));
}
Optional<List<Text>> loreOpt = itemStack.get(Keys.ITEM_LORE);
if (loreOpt.isPresent()) {
JSONArray lore = new JSONArray();
for (Text line : loreOpt.get()) {
lore.put(TextSerializers.FORMATTING_CODE.serialize(line));
}
awardData.put("lore", TextSerializers.FORMATTING_CODE.serialize(displayNameOpt.get()));
}
Optional<List<Enchantment>> enchantmentsOpt = itemStack.get(Keys.ITEM_ENCHANTMENTS);
if (enchantmentsOpt.isPresent()) {
JSONArray enchantments = new JSONArray();
for (Enchantment enchant : enchantmentsOpt.get()) {
enchantments.put(new JSONObject()
.put("id", enchant.getType().getId())
.put("level", enchant.getLevel()));
}
awardData.put("enchantments", enchantments);
}
Optional<Integer> durabilityOpt = itemStack.get(Keys.ITEM_DURABILITY);
if (durabilityOpt.isPresent()) {
awardData.put("durability", durabilityOpt.get());
}
Optional<DyeColor> dyeColorOpt = itemStack.get(Keys.DYE_COLOR);
if (dyeColorOpt.isPresent()) {
awardData.put("color", dyeColorOpt.get().getId());
}
Optional<SkullType> skullTypeOpt = itemStack.get(Keys.SKULL_TYPE);
if (skullTypeOpt.isPresent()) {
awardData.put("skullType", skullTypeOpt.get());
}
JSONObject awardBody = new JSONObject()
.put("name", itemStack.get(Keys.DISPLAY_NAME).orElse(Text.of(itemStack.getTranslation().get(Locale.ENGLISH))).toPlain())
.put("description", "Created by the BadgeUp Sponge Client on " + new Date().toString())
.put("data", awardData);
Sponge.getScheduler().createTaskBuilder().execute(new PostAwardRunnable(player, awardBody, this.plugin.getLogger())).async()
.submit(this.plugin);
return CommandResult.success();
}