本文整理汇总了Java中org.spongepowered.api.item.inventory.transaction.InventoryTransactionResult类的典型用法代码示例。如果您正苦于以下问题:Java InventoryTransactionResult类的具体用法?Java InventoryTransactionResult怎么用?Java InventoryTransactionResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
InventoryTransactionResult类属于org.spongepowered.api.item.inventory.transaction包,在下文中一共展示了InventoryTransactionResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: give
import org.spongepowered.api.item.inventory.transaction.InventoryTransactionResult; //导入依赖的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();
}
}
}
示例2: peekOffer
import org.spongepowered.api.item.inventory.transaction.InventoryTransactionResult; //导入依赖的package包/类
private PeekedOfferTransactionResult peekOffer(ItemStack stack, Set<Inventory> processed, boolean add) {
PeekedOfferTransactionResult peekResult = null;
final List<SlotTransaction> transactions = new ArrayList<>();
// Loop through the slots
for (AbstractInventory inventory : getChildren()) {
if (!add && processed.contains(inventory)) {
continue;
}
peekResult = inventory.peekOffer(stack);
if (peekResult.isSuccess()) {
final Optional<ItemStack> rejectedItem = peekResult.getRejectedItem();
transactions.addAll(peekResult.getTransactions());
if (!rejectedItem.isPresent()) {
return new PeekedOfferTransactionResult(InventoryTransactionResult.Type.SUCCESS, transactions, null);
}
stack = rejectedItem.get();
}
if (add) {
processed.add(inventory);
}
}
if (peekResult == null) {
return new PeekedOfferTransactionResult(InventoryTransactionResult.Type.FAILURE, ImmutableList.of(), stack);
}
return new PeekedOfferTransactionResult(InventoryTransactionResult.Type.SUCCESS, transactions, peekResult.getRejectedItem().orElse(null));
}
示例3: findLogTool
import org.spongepowered.api.item.inventory.transaction.InventoryTransactionResult; //导入依赖的package包/类
@SuppressWarnings("deprecation")
private void findLogTool(Player player, LookupData logType)
{
ItemStack itemStack = Sponge.getGame().getRegistry().createBuilder(ItemStack.Builder.class).itemType(ItemTypes.BOOK).quantity(1).build();
itemStack.offer(Keys.DISPLAY_NAME, toolName);
itemStack.offer(Keys.ITEM_LORE, asList(i18n.translate(player, NONE, "created by {name}", player.getName())));
itemStack.offer(Keys.ITEM_ENCHANTMENTS, Collections.emptyList());
itemStack.offer(logType);
java.util.Optional<ItemStack> inHand = player.getItemInHand(HandTypes.MAIN_HAND);
player.setItemInHand(HandTypes.MAIN_HAND, itemStack);
if (inHand.isPresent())
{
if (player.getInventory().offer(inHand.get()).getType() != InventoryTransactionResult.Type.SUCCESS)
{
SpawnUtil.spawnItem(inHand.get(), player.getLocation());
}
}
i18n.send(player, POSITIVE, "Received a new Log-Tool!");
}
示例4: execute
import org.spongepowered.api.item.inventory.transaction.InventoryTransactionResult; //导入依赖的package包/类
@Override public CommandResult execute(CommandSource commandSource, CommandContext commandContext) throws CommandException {
if(commandContext.getOne("type").isPresent() && commandSource instanceof Player) {
String type = commandContext.<String>getOne("type").get();
Player player = (Player) commandSource;
VirtualCrate virtualCrate = HuskyCrates.instance.getCrateUtilities().getVirtualCrate(type);
if (virtualCrate == null) {
commandSource.sendMessage(Text.of("Invalid crate id: " + type + ". Please check your config."));
return CommandResult.empty();
}
ItemStack keyItemStack = virtualCrate.getCrateWand();
InventoryTransactionResult.Type mainInventory = player.getInventory().offer(keyItemStack.copy()).getType();
if (!mainInventory.equals(InventoryTransactionResult.Type.SUCCESS)) {
InventoryTransactionResult.Type enderInventory = player.getEnderChestInventory().offer(keyItemStack.copy()).getType();
if(!enderInventory.equals(InventoryTransactionResult.Type.SUCCESS)) {
commandSource.sendMessage(Text.of("Couldn't give wand to " + player.getName() + " because of a full inventory and enderchest"));
HuskyCrates.instance.logger.info("Couldn't give wand to " + player.getName() + " because of a full inventory and enderchest");
}else{
player.sendMessage(Text.of("You have been given a ", TextSerializers.FORMATTING_CODE.deserialize(virtualCrate.displayName) ," wand, but it has been placed in your Ender Chest."));
}
}
}else{
commandSource.sendMessage(Text.of("Usage: /crate wand <id>"));
}
return CommandResult.success();
}
示例5: execute
import org.spongepowered.api.item.inventory.transaction.InventoryTransactionResult; //导入依赖的package包/类
@Override public CommandResult execute(CommandSource commandSource, CommandContext commandContext) throws CommandException {
if(commandContext.getOne("type").isPresent()) {
String type = commandContext.<String>getOne("type").get();
Optional<Player> player = commandContext.getOne("player");
VirtualCrate virtualCrate = HuskyCrates.instance.getCrateUtilities().getVirtualCrate(type);
int quantity = commandContext.getOne("quantity").isPresent() ? commandContext.<Integer>getOne("quantity").get() : 1;
if (virtualCrate == null) {
commandSource.sendMessage(Text.of("Invalid crate id: " + type + ". Please check your config."));
return CommandResult.empty();
}
if (!player.isPresent()) {
commandSource.sendMessage(Text.of("You need to be in game or specify a player for this command to work."));
return CommandResult.empty();
}
ItemStack keyItemStack = virtualCrate.getCrateKey(quantity);
InventoryTransactionResult.Type mainInventory = player.get().getInventory().offer(keyItemStack.copy()).getType();
if (!mainInventory.equals(InventoryTransactionResult.Type.SUCCESS)) {
InventoryTransactionResult.Type enderInventory = player.get().getEnderChestInventory().offer(keyItemStack.copy()).getType();
if (!enderInventory.equals(InventoryTransactionResult.Type.SUCCESS)) {
commandSource.sendMessage(Text.of("Couldn't give key to " + player.get().getName() + " because of a full inventory and enderchest"));
HuskyCrates.instance.logger.info("Couldn't give key to " + player.get().getName() + " because of a full inventory and enderchest");
} else {
if (player.isPresent()) {
player.get().sendMessage(Text.of("You have been given 1 or more ", TextSerializers.FORMATTING_CODE.deserialize(virtualCrate.displayName), " key(s), but some have been placed in your Ender Chest."));
} else {
commandSource.sendMessage(Text.of("You have been given 1 or more ", TextSerializers.FORMATTING_CODE.deserialize(virtualCrate.displayName), " key(s), but some have been placed in your Ender Chest."));
}
}
}
}else{
commandSource.sendMessage(Text.of("Usage: /crate key <id> [player] [count]"));
}
return CommandResult.success();
}
示例6: execute
import org.spongepowered.api.item.inventory.transaction.InventoryTransactionResult; //导入依赖的package包/类
@Override public CommandResult execute(CommandSource commandSource, CommandContext commandContext) throws CommandException {
if(commandContext.getOne("type").isPresent()) {
String type = commandContext.<String>getOne("type").get();
Optional<Player> player = commandContext.getOne("player");
VirtualCrate virtualCrate = HuskyCrates.instance.getCrateUtilities().getVirtualCrate(type);
int quantity = commandContext.getOne("quantity").isPresent() ? commandContext.<Integer>getOne("quantity").get() : 1;
if (virtualCrate == null) {
commandSource.sendMessage(Text.of("Invalid crate id: " + type + ". Please check your config."));
return CommandResult.empty();
}
if (!player.isPresent()) {
commandSource.sendMessage(Text.of("You need to either specify a player or be in game"));
return CommandResult.empty();
}
ItemStack chestItemStack = virtualCrate.getCrateItem(quantity);
InventoryTransactionResult.Type mainInventory = player.get().getInventory().offer(chestItemStack.copy()).getType();
if (!mainInventory.equals(InventoryTransactionResult.Type.SUCCESS)) {
InventoryTransactionResult.Type enderInventory = player.get().getEnderChestInventory().offer(chestItemStack.copy()).getType();
if(!enderInventory.equals(InventoryTransactionResult.Type.SUCCESS)) {
commandSource.sendMessage(Text.of("Couldn't give chest to " + player.get().getName() + " because of a full inventory and enderchest"));
HuskyCrates.instance.logger.info("Couldn't give chest to " + player.get().getName() + " because of a full inventory and enderchest");
}else{
if(player.isPresent()) {
player.get().sendMessage(Text.of("You have been given 1 or more ", TextSerializers.FORMATTING_CODE.deserialize(virtualCrate.displayName) ," crate(s), but some have been placed in your Ender Chest."));
}else{
commandSource.sendMessage(Text.of("You have been given 1 or more ", TextSerializers.FORMATTING_CODE.deserialize(virtualCrate.displayName) ," crate(s), but some have been placed in your Ender Chest."));
}
}
}
}else{
commandSource.sendMessage(Text.of("Usage: /crate chest <id> [player]"));
}
return CommandResult.success();
}
示例7: execute
import org.spongepowered.api.item.inventory.transaction.InventoryTransactionResult; //导入依赖的package包/类
@Override public CommandResult execute(CommandSource commandSource, CommandContext commandContext) throws CommandException {
if(commandContext.getOne("type").isPresent()) {
String type = commandContext.<String>getOne("type").get();
VirtualCrate virtualCrate = HuskyCrates.instance.getCrateUtilities().getVirtualCrate(type);
int quantity = commandContext.getOne("quantity").isPresent() ? commandContext.<Integer>getOne("quantity").get() : 1;
if (virtualCrate == null) {
commandSource.sendMessage(Text.of("Invalid crate id: " + type + ". Please check your config."));
return CommandResult.empty();
}
for(Player player : Sponge.getServer().getOnlinePlayers()) {
ItemStack keyItemStack = virtualCrate.getCrateKey(quantity);
InventoryTransactionResult.Type mainInventory = player.getInventory().offer(keyItemStack.copy()).getType();
if (!mainInventory.equals(InventoryTransactionResult.Type.SUCCESS)) {
InventoryTransactionResult.Type enderInventory = player.getEnderChestInventory().offer(keyItemStack.copy()).getType();
if (!enderInventory.equals(InventoryTransactionResult.Type.SUCCESS)) {
commandSource.sendMessage(Text.of("Couldn't give key to " + player.getName() + " because of a full inventory and enderchest"));
HuskyCrates.instance.logger.info("Couldn't give key to " + player.getName() + " because of a full inventory and enderchest");
} else {
player.sendMessage(Text.of("You have been given 1 or more ", TextSerializers.FORMATTING_CODE.deserialize(virtualCrate.displayName), " key(s), but some have been placed in your Ender Chest."));
}
}
}
}else{
commandSource.sendMessage(Text.of("Usage: /crate keyall <id> [count]"));
}
return CommandResult.success();
}
示例8: giveItem
import org.spongepowered.api.item.inventory.transaction.InventoryTransactionResult; //导入依赖的package包/类
/**
* Ajouter un item dans l'inventaire du joueur
* @param itemstack L'itemstack
*/
public Optional<ItemStack> giveItem(final ItemStack itemstack) {
InventoryTransactionResult transaction = this.getInventory().query(Hotbar.class).offer(itemstack);
if (!transaction.getRejectedItems().isEmpty()) {
transaction = this.getInventory().query(GridInventory.class).offer(transaction.getRejectedItems().iterator().next().createStack());
if (!transaction.getRejectedItems().isEmpty()) {
return Optional.of(transaction.getRejectedItems().iterator().next().createStack());
}
}
return Optional.empty();
}
示例9: equip
import org.spongepowered.api.item.inventory.transaction.InventoryTransactionResult; //导入依赖的package包/类
@Override
default boolean equip(EquipmentType type, @Nullable ItemStack equipment) {
checkNotNull(type, "type");
final Inventory inventory = getInventory().query(Holder.EQUIPMENT_INVENTORY_OPERATION);
if (inventory instanceof EmptyInventory) {
return false;
}
final AbstractSlot slot = (AbstractSlot) inventory.<IEquipmentInventory>first().getSlot(type).orElse(null);
if (slot == null) {
return false;
}
final InventoryTransactionResult result = slot.set(equipment);
return result.getType().equals(InventoryTransactionResult.Type.SUCCESS);
}
示例10: insertRecord
import org.spongepowered.api.item.inventory.transaction.InventoryTransactionResult; //导入依赖的package包/类
@Override
public void insertRecord(ItemStack record) {
checkNotNull(record, "record");
ejectRecord();
checkState(this.inventory.set(record).getType() == InventoryTransactionResult.Type.SUCCESS,
"Invalid record item stack: " + record);
updateBlockState();
}
示例11: peekSet
import org.spongepowered.api.item.inventory.transaction.InventoryTransactionResult; //导入依赖的package包/类
@Override
public PeekedSetTransactionResult peekSet(@Nullable ItemStack stack) {
if (!LanternItemStack.isEmpty(stack) && !isValidItem(stack)) {
return new PeekedSetTransactionResult(InventoryTransactionResult.Type.FAILURE, ImmutableList.of(), stack, null);
}
stack = LanternItemStack.toNullable(stack);
final List<SlotTransaction> transactions = new ArrayList<>();
final ItemStackSnapshot oldItem = LanternItemStack.toSnapshot(this.itemStack);
ItemStack rejectedItem = null;
ItemStack replacedItem = oldItem.isEmpty() ? null : this.itemStack.copy();
ItemStackSnapshot newItem = ItemStackSnapshot.NONE;
if (stack != null) {
final int maxStackSize = Math.min(stack.getMaxStackQuantity(), this.maxStackSize);
final int quantity = stack.getQuantity();
if (quantity > maxStackSize) {
stack = stack.copy();
stack.setQuantity(maxStackSize);
newItem = LanternItemStack.toSnapshot(stack);
// Create the rest stack that was rejected,
// because the inventory doesn't allow so many items
rejectedItem = stack.copy();
rejectedItem.setQuantity(quantity - maxStackSize);
} else {
newItem = LanternItemStack.toSnapshot(stack);
}
}
transactions.add(new SlotTransaction(this, oldItem, newItem));
return new PeekedSetTransactionResult(InventoryTransactionResult.Type.SUCCESS, transactions, rejectedItem, replacedItem);
}
示例12: set
import org.spongepowered.api.item.inventory.transaction.InventoryTransactionResult; //导入依赖的package包/类
private InventoryTransactionResult set(@Nullable ItemStack stack, boolean forced) {
stack = LanternItemStack.toNullable(stack);
boolean fail = false;
if (stack != null) {
if (stack.getQuantity() <= 0) {
stack = null;
} else if (!forced) {
fail = !isValidItem(stack);
}
}
if (fail) {
return InventoryTransactionResult.builder()
.type(InventoryTransactionResult.Type.FAILURE)
.reject(stack)
.build();
}
InventoryTransactionResult.Builder resultBuilder = InventoryTransactionResult.builder()
.type(InventoryTransactionResult.Type.SUCCESS);
if (this.itemStack != null) {
resultBuilder.replace(this.itemStack);
}
if (stack != null) {
stack = stack.copy();
final int maxStackSize = Math.min(stack.getMaxStackQuantity(), this.maxStackSize);
final int quantity = stack.getQuantity();
if (quantity > maxStackSize) {
stack.setQuantity(maxStackSize);
// Create the rest stack that was rejected,
// because the inventory doesn't allow so many items
stack = stack.copy();
stack.setQuantity(quantity - maxStackSize);
resultBuilder.reject(stack);
}
}
this.itemStack = (LanternItemStack) stack;
queueUpdate();
return resultBuilder.build();
}
示例13: asInventoryTransactionBuilder
import org.spongepowered.api.item.inventory.transaction.InventoryTransactionResult; //导入依赖的package包/类
@Override
protected InventoryTransactionResult.Builder asInventoryTransactionBuilder() {
final InventoryTransactionResult.Builder builder = super.asInventoryTransactionBuilder();
if (this.replacedItem != null) {
builder.replace(this.replacedItem);
}
return builder;
}
示例14: PeekedOfferTransactionResult
import org.spongepowered.api.item.inventory.transaction.InventoryTransactionResult; //导入依赖的package包/类
/**
* Constructs a new {@link PeekedOfferTransactionResult}.
*
* @param type The type of the transaction result
* @param transactions The slot transactions that will occur
* @param rejectedItem The rejected item stack, this can occur if the stack doesn't fit the inventory
*/
public PeekedOfferTransactionResult(InventoryTransactionResult.Type type, List<SlotTransaction> transactions,
@Nullable ItemStack rejectedItem) {
super(transactions);
checkNotNull(type, "type");
this.type = type;
this.rejectedItem = rejectedItem;
}
示例15: asInventoryTransactionBuilder
import org.spongepowered.api.item.inventory.transaction.InventoryTransactionResult; //导入依赖的package包/类
protected InventoryTransactionResult.Builder asInventoryTransactionBuilder() {
final InventoryTransactionResult.Builder builder = InventoryTransactionResult.builder();
builder.type(this.type);
if (this.rejectedItem != null) {
builder.reject(this.rejectedItem);
}
return builder;
}