• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java PlayerInventory类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: addItem

import org.spongepowered.api.item.inventory.entity.PlayerInventory; //导入依赖的package包/类
public static int addItem(PlayerInventory inventory, ItemStack itemStack, int amount) {

        int overflow = 0;
        int total = amount;

        int availableSpace = getAvailableSpace(inventory, itemStack);
        if (amount > availableSpace) {
            overflow = amount - availableSpace;
            total = availableSpace;
        }

        int maxStackQuantity = itemStack.getMaxStackQuantity();
        ItemStack copy = itemStack.copy();

        while (total > 0) {
            if (total > maxStackQuantity) {
                copy.setQuantity(maxStackQuantity);
                total -= maxStackQuantity;
            } else {
                copy.setQuantity(total);
                total = 0;
            }
            inventory.offer(copy);
        }
        return overflow;
    }
 
开发者ID:Zerthick,项目名称:PlayerShopsRPG,代码行数:27,代码来源:InventoryUtils.java


示例2: removeItem

import org.spongepowered.api.item.inventory.entity.PlayerInventory; //导入依赖的package包/类
public static int removeItem(PlayerInventory inventory, ItemStack itemStack, int amount) {

        int underflow = 0;
        int total = amount;

        int availableItems = getItemCount(inventory, itemStack);
        if (amount > availableItems) {
            underflow = amount - availableItems;
            total = availableItems;
        }

        ItemStack copy = itemStack.copy();
        while (total > 0) {
            if (total > copy.getMaxStackQuantity()) {
                inventory.query(QueryOperationTypes.ITEM_STACK_IGNORE_QUANTITY.of(copy)).poll(copy.getMaxStackQuantity());
                total -= copy.getMaxStackQuantity();
            } else {
                inventory.query(QueryOperationTypes.ITEM_STACK_IGNORE_QUANTITY.of(copy)).poll(total);
                total = 0;
            }
        }
        return underflow;
    }
 
开发者ID:Zerthick,项目名称:PlayerShopsRPG,代码行数:24,代码来源:InventoryUtils.java


示例3: addItem

import org.spongepowered.api.item.inventory.entity.PlayerInventory; //导入依赖的package包/类
public ShopTransactionResult addItem(Player player, ItemStack itemStack, int amount) {

        //Amount Bounds Check
        if (amount < 0) {
            return new ShopTransactionResult(Messages.INVALID_ITEM_ADD_AMOUNT);
        }

        //If the player is not a manager of the shop return a message to the player
        if (!hasManagerPermissions(player)) {
            return new ShopTransactionResult(Messages.YOU_ARE_NOT_A_MANAGER_OF_THIS_SHOP);
        }

        //If the item exists add to it's total to the shopitem and remove it from the player's inventory
        for (ShopItem item : items.values()) {
            if (InventoryUtils.itemStackEqualsIgnoreSize(item.getItemStack(), itemStack)) {

                if ((amount + item.getItemAmount() > item.getItemMaxAmount()) && item.getItemMaxAmount() != -1) {
                    amount = item.getItemMaxAmount() - item.getItemAmount();
                }

                InventoryUtils.removeItem((PlayerInventory) player.getInventory(), itemStack, amount);

                item.setItemAmount(item.getItemAmount() + amount);
                return ShopTransactionResult.SUCCESS;
            }
        }

        return new ShopTransactionResult(Messages.THE_SPECIFIED_ITEM_IS_NOT_IN_THIS_SHOP);
    }
 
开发者ID:Zerthick,项目名称:PlayerShopsRPG,代码行数:30,代码来源:Shop.java


示例4: removeItem

import org.spongepowered.api.item.inventory.entity.PlayerInventory; //导入依赖的package包/类
public ShopTransactionResult removeItem(Player player, UUID itemUUID, int amount) {

        //Amount Bounds Check
        if (amount < 0) {
            return new ShopTransactionResult(Messages.INVALID_ITEM_REMOVE_AMOUNT);
        }

        //If the player is not a manager of the shop return a message to the player
        if (!hasManagerPermissions(player)) {
            return new ShopTransactionResult(Messages.YOU_ARE_NOT_A_MANAGER_OF_THIS_SHOP);
        }

        //Bounds Check
        if (items.containsKey(itemUUID)) {
            ShopItem item = items.get(itemUUID);
            if (amount > item.getItemAmount()) {
                amount = item.getItemAmount();
            }

            InventoryUtils.addItem((PlayerInventory) player.getInventory(), item.getItemStack(), amount);

            item.setItemAmount(item.getItemAmount() - amount);
            return ShopTransactionResult.SUCCESS;
        }

        return new ShopTransactionResult(Messages.THE_SPECIFIED_ITEM_IS_NOT_IN_THIS_SHOP);
    }
 
开发者ID:Zerthick,项目名称:PlayerShopsRPG,代码行数:28,代码来源:Shop.java


示例5: toString

import org.spongepowered.api.item.inventory.entity.PlayerInventory; //导入依赖的package包/类
public String toString(boolean unks) {
    if (remAs != null) {
        return "shared/" + remAs;
    }
    if (internal instanceof MainPlayerInventory) {
        return "player/" + ((PlayerInventory) (internal).parent()).getCarrier().get().getUniqueId().toString();
    }
    else if (internal instanceof CarriedInventory) {
        Object o = ((CarriedInventory) internal).getCarrier().orElse(null);
        if (o == null) {
            return "((UNKNOWN INVENTORY TYPE))";
        }
        if (o instanceof Entity) {
            return "entity/" + ((Entity) o).getUniqueId().toString();
        }
        else if (o instanceof TileEntityCarrier) {
            LocatableBlock lb = ((TileEntityCarrier) o).getLocatableBlock();
            return "block/" + new LocationTag(new UtilLocation(lb.getPosition(), lb.getWorld()));
        }
    }
    if (!unks) {
        // TODO: Handle all inventory types somehow???
        throw new RuntimeException("Inventory type not known to the system!");
    }
    else {
        return "((UNKNOWN INVENTORY TYPE))";
    }
}
 
开发者ID:DenizenScript,项目名称:Denizen2Sponge,代码行数:29,代码来源:InventoryTag.java


示例6: giveItems

import org.spongepowered.api.item.inventory.entity.PlayerInventory; //导入依赖的package包/类
public static Clause<Boolean, List<Clause<ItemStack, Integer>>> giveItems(Player player, Collection<ItemStack> stacks, Cause cause) {
  List<Clause<ItemStack, Integer>> transactions = new ArrayList<>(stacks.size());
  List<ItemStackSnapshot> itemBuffer = new ArrayList<>();
  itemBuffer.addAll(stacks.stream().map(ItemStack::createSnapshot).collect(Collectors.toList()));

  PlayerInventory playerInventory = player.getInventory().query(PlayerInventory.class);
  List<Inventory> inventories = new ArrayList<>();
  inventories.add(playerInventory.getHotbar());
  inventories.add(playerInventory.getMain());

  // Loop through replacing empty space with the requested items
  for (Inventory inventory : inventories) {
    List<ItemStackSnapshot> newBuffer = new ArrayList<>();
    for (ItemStackSnapshot snapshot : itemBuffer) {
      ItemStack stack = snapshot.createStack();

      InventoryTransactionResult result = inventory.offer(stack);
      newBuffer.addAll(result.getRejectedItems());

      transactions.add(new Clause<>(stack, stack.getQuantity()));
    }
    itemBuffer = newBuffer;
  }

  // Drop remaining items
  new ItemDropper(player.getLocation()).dropStackSnapshots(itemBuffer, SpawnTypes.PLUGIN);

  return new Clause<>(true, transactions);
}
 
开发者ID:Skelril,项目名称:Skree,代码行数:30,代码来源:MarketImplUtil.java


示例7: getHotbar

import org.spongepowered.api.item.inventory.entity.PlayerInventory; //导入依赖的package包/类
private static Hotbar getHotbar(Player player) {
	return ((PlayerInventory) player.getInventory()).getHotbar();
}
 
开发者ID:AuraDevelopmentTeam,项目名称:InvSync,代码行数:4,代码来源:PlayerSerializer.java


示例8: buyItem

import org.spongepowered.api.item.inventory.entity.PlayerInventory; //导入依赖的package包/类
public ShopTransactionResult buyItem(Player player, UUID itemUUID, int amount) {

        //Amount Bounds Check
        if (amount < 0) {
            return new ShopTransactionResult(Messages.INVALID_ITEM_BUY_AMOUNT);
        }

        //Bounds Check
        if (items.containsKey(itemUUID)) {
            ShopItem item = items.get(itemUUID);

            //Check if the shop does not buy this item
            if (item.getItemBuyPrice() == -1) {
                return new ShopTransactionResult(Messages.processDropins(Messages.SHOP_DOES_NOT_BUY_ITEM,
                        ImmutableMap.of(Messages.DROPIN_SHOP_NAME, getName(), Messages.DROPIN_ITEM_NAME,
                                InventoryUtils.getItemNamePlain(item.getItemStack()))));
            }

            //Check if the shop has enough room otherwise only buy as much as we can hold
            if ((amount + item.getItemAmount() > item.getItemMaxAmount()) && item.getItemMaxAmount() != -1) {
                amount = item.getItemMaxAmount() - item.getItemAmount();
            }

            //Check if the player has enough of the item in their inventory to sell
            if (InventoryUtils.getItemCount((PlayerInventory) player.getInventory(), item.getItemStack()) < amount) {
                return new ShopTransactionResult(Messages.processDropins(Messages.PLAYER_DOES_NOT_HAVE_ENOUGH_ITEM,
                        ImmutableMap.of(Messages.DROPIN_ITEM_AMOUNT, String.valueOf(amount), Messages.DROPIN_ITEM_NAME, InventoryUtils.getItemNamePlain(item.getItemStack()))));
            }

            //Transfer the funds from the shop's account to the player's account if it doesn't have unlimited money
            EconManager manager = EconManager.getInstance();
            Optional<UniqueAccount> playerAccountOptional = manager.getOrCreateAccount(player.getUniqueId());
            Optional<UniqueAccount> shopAccountOptional = manager.getOrCreateAccount(getUUID());

            if (playerAccountOptional.isPresent() && shopAccountOptional.isPresent()) {

                TransactionResult result;

                if (unlimitedMoney) {
                    result = playerAccountOptional.get().deposit(getShopCurrency(),
                            BigDecimal.valueOf(amount * item.getItemBuyPrice()),
                            Sponge.getCauseStackManager().getCurrentCause());
                } else {
                    result = shopAccountOptional.get().transfer(playerAccountOptional.get(),
                            getShopCurrency(), BigDecimal.valueOf(amount * item.getItemBuyPrice()),
                            Sponge.getCauseStackManager().getCurrentCause());
                }
                if (result.getResult() == ResultType.SUCCESS) {
                    item.setItemAmount(item.getItemAmount() + amount);
                    InventoryUtils.removeItem((PlayerInventory) player.getInventory(), item.getItemStack(), amount);
                    return ShopTransactionResult.SUCCESS;
                } else {
                    return new ShopTransactionResult(Messages.processDropins(Messages.SHOP_DOES_NOT_HAVE_ENOUGH_FUNDS,
                            ImmutableMap.of(Messages.DROPIN_SHOP_NAME, getName())));
                }
            }
        }

        return new ShopTransactionResult(Messages.THE_SPECIFIED_ITEM_IS_NOT_IN_THIS_SHOP);
    }
 
开发者ID:Zerthick,项目名称:PlayerShopsRPG,代码行数:61,代码来源:Shop.java


示例9: sellItem

import org.spongepowered.api.item.inventory.entity.PlayerInventory; //导入依赖的package包/类
public ShopTransactionResult sellItem(Player player, UUID itemUUID, int amount) {

        //Amount Bounds Check
        if (amount < 0) {
            return new ShopTransactionResult(Messages.INVALID_ITEM_SELL_AMOUNT);
        }

        //Bounds Check
        if (items.containsKey(itemUUID)) {
            ShopItem item = items.get(itemUUID);

            //Check if the shop does not sell this item
            if (item.getItemSellPrice() == -1) {
                return new ShopTransactionResult(Messages.processDropins(Messages.SHOP_DOES_NOT_SELL_ITEM,
                        ImmutableMap.of(Messages.DROPIN_SHOP_NAME, getName(), Messages.DROPIN_ITEM_NAME,
                                InventoryUtils.getItemNamePlain(item.getItemStack()))));
            }

            //Check if the player has enough room otherwise only sell as much as they can hold
            int availableSpace = InventoryUtils.getAvailableSpace((PlayerInventory) player.getInventory(), item.getItemStack());
            if (availableSpace < amount) {
                amount = availableSpace;
            }

            //Check if the shop has enough of the item in their inventory to sell
            if ((item.getItemAmount() < amount) && !unlimitedStock) {
                return new ShopTransactionResult(Messages.processDropins(Messages.SHOP_DOES_NOT_HAVE_ENOUGH_ITEM,
                        ImmutableMap.of(Messages.DROPIN_SHOP_NAME, getName(), Messages.DROPIN_ITEM_AMOUNT, String.valueOf(amount)
                                , Messages.DROPIN_ITEM_NAME, InventoryUtils.getItemNamePlain(item.getItemStack()))));
            }

            //Transfer the funds from the player's account to the shop's account
            EconManager manager = EconManager.getInstance();
            Optional<UniqueAccount> playerAccountOptional = manager.getOrCreateAccount(player.getUniqueId());
            Optional<UniqueAccount> shopAccountOptional = manager.getOrCreateAccount(getUUID());

            if (playerAccountOptional.isPresent() && shopAccountOptional.isPresent()) {

                TransactionResult result;

                if (unlimitedMoney) {
                    result = playerAccountOptional.get().withdraw(getShopCurrency(),
                            BigDecimal.valueOf(amount * item.getItemSellPrice()),
                            Sponge.getCauseStackManager().getCurrentCause());
                } else {
                    result = playerAccountOptional.get().transfer(shopAccountOptional.get(),
                            getShopCurrency(), BigDecimal.valueOf(amount * item.getItemSellPrice()),
                            Sponge.getCauseStackManager().getCurrentCause());
                }
                if (result.getResult() == ResultType.SUCCESS) {
                    if (!unlimitedStock) {
                        item.setItemAmount(item.getItemAmount() - amount);
                    }
                    InventoryUtils.addItem((PlayerInventory) player.getInventory(), item.getItemStack(), amount);
                    return ShopTransactionResult.SUCCESS;
                } else {
                    return new ShopTransactionResult(Messages.YOU_DON_T_HAVE_ENOUGH_FUNDS);
                }
            }
        }

        return new ShopTransactionResult(Messages.THE_SPECIFIED_ITEM_IS_NOT_IN_THIS_SHOP);
    }
 
开发者ID:Zerthick,项目名称:PlayerShopsRPG,代码行数:64,代码来源:Shop.java


示例10: execute

import org.spongepowered.api.item.inventory.entity.PlayerInventory; //导入依赖的package包/类
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
	if (!(src instanceof Player)) {
		src.sendMessage(Messages.get("OnlyPlayersCanRunThis"));
		return CommandResult.empty();
	}
	
	final String kitName = args.<String>getOne("kit").get();
	final Kit kit = instance.getKit(kitName);
	if (kit == null) {
		src.sendMessage(Messages.get("KitNotFound"));
		return CommandResult.empty();
	}
	
	Player player = (Player) src;
	PlayerData pd = instance.getPlayersData().get(player.getUniqueId());
	if (pd == null) {
		pd = new PlayerData(player.getUniqueId());
	}
	
	final String lcName = kit.getName().toLowerCase();
	Integer pendingKitAmount = pd.getPendingKits().get(lcName);
	if ((pendingKitAmount == null || pendingKitAmount <= 0) && !player.hasPermission("betterkits.allkits") && !player.hasPermission("betterkits.kit."+lcName)) {
		player.sendMessage(Messages.get("NotAllowedToUseThisKit"));
		return CommandResult.empty();
	}
	
	Integer time = pd.getCooldownKits().get(lcName);
	if (time != null && CommonUtils.epoch() - time < kit.getCooldown() && !player.hasPermission("betterkits.bypasscooldown.allkits") && !player.hasPermission("betterkits.bypasscooldown.kit."+lcName)) {
		player.sendMessage(Messages.get("WaitKitCooldown", "remaining", CommonUtils.timeToString(kit.getCooldown() - (CommonUtils.epoch() - time)), "total", CommonUtils.timeToString(kit.getCooldown())));
		return CommandResult.empty();
	}
	
	int freeSlots = Utils.freeSlots(((PlayerInventory) player.getInventory().query(PlayerInventory.class)).getMain().slots());
	int kitSlots = Utils.usedSlots(kit.getChestInventory().slots());
	if (freeSlots < kitSlots && !this.alertedPlayers.add(player.getUniqueId())) {
		player.sendMessage(Messages.get("KitItemsDropWarning", "kitname", kit.getName(), "kitslots", kitSlots+"", "freeslots", freeSlots+""));
		return CommandResult.empty();
	}
	
	pd.getCooldownKits().put(lcName, CommonUtils.epoch());
	if (pendingKitAmount != null) {
		if (pendingKitAmount > 1) {
			pd.getPendingKits().put(lcName, pendingKitAmount-1);
		} else {
			pd.getPendingKits().remove(lcName);
		}
	}
	
	instance.getPlayersData().put(player.getUniqueId(), pd);
	
	try {
		instance.saveData();
		kit.give(player);
		player.sendMessage(Messages.get("YouReceivedKit", "name", kit.getName()));
	} catch (Exception e) {
		src.sendMessage(Text.of(TextColors.RED, "An error occurred while saving data."));
		e.printStackTrace();
	}
	
	return CommandResult.success();
}
 
开发者ID:KaiKikuchi,项目名称:BetterKits,代码行数:63,代码来源:KitCommand.java


示例11: tryToStart

import org.spongepowered.api.item.inventory.entity.PlayerInventory; //导入依赖的package包/类
public void tryToStart() {
  BigDecimal coffersNeeded = getCoffersNeeded();

  if (coffersNeeded.compareTo(BigDecimal.ZERO) >= 0) {
    MessageChannel channel = getPlayerMessageChannel(PlayerClassifier.SPECTATOR);
    channel.send(Text.of(TextColors.RED, "Your party doesn't have a high enough coffer risk!"));
    channel.send(Text.of(TextColors.RED, "At least ", coffersNeeded, " more coffers must be risked."));
    return;
  }

  Optional<PlayerStateService> optService = Sponge.getServiceManager().provide(PlayerStateService.class);
  for (Player player : getPlayers(PlayerClassifier.PARTICIPANT)) {
    if (optService.isPresent()) {
      PlayerStateService service = optService.get();
      try {
        service.storeInventory(player);
        service.releaseInventory(player);

        player.getInventory().clear();
      } catch (InventoryStorageStateException e) {
        e.printStackTrace();
        player.sendMessage(Text.of(TextColors.RED, "An error occurred while saving your inventory, contact an admin!"));
        return;
      }
    } else {
      if (player.getInventory().query(PlayerInventory.class, EquipmentInventory.class).size() > 0) {
        getPlayerMessageChannel(PlayerClassifier.SPECTATOR).send(
            Text.of(TextColors.RED, "All players inventories must be empty.")
        );
        return;
      }
    }
  }

  readyPlayers();
  calculateLootSplit();
  startTime = System.currentTimeMillis(); // Reset tryToStart clock
  populateChest();                        // Add content
  runLavaChance();
  setFloodStartTime();
}
 
开发者ID:Skelril,项目名称:Skree,代码行数:42,代码来源:GoldRushInstance.java


示例12: getItemCount

import org.spongepowered.api.item.inventory.entity.PlayerInventory; //导入依赖的package包/类
public static int getItemCount(PlayerInventory inventory, ItemStack itemStack) {

        ItemStack copy = itemStack.copy();

        return inventory.query(QueryOperationTypes.ITEM_STACK_IGNORE_QUANTITY.of(copy)).totalItems();
    }
 
开发者ID:Zerthick,项目名称:PlayerShopsRPG,代码行数:7,代码来源:InventoryUtils.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java OptimisticReturnFilters类代码示例发布时间:2022-05-23
下一篇:
Java SimplePdfExporterConfiguration类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap