本文整理汇总了Java中org.bukkit.inventory.Inventory.getSize方法的典型用法代码示例。如果您正苦于以下问题:Java Inventory.getSize方法的具体用法?Java Inventory.getSize怎么用?Java Inventory.getSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bukkit.inventory.Inventory
的用法示例。
在下文中一共展示了Inventory.getSize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fromBase64
import org.bukkit.inventory.Inventory; //导入方法依赖的package包/类
/**
*
* A method to get an {@link Inventory} from an encoded, Base64, string.
*
* <p />
*
* Special thanks to Comphenix in the Bukkit forums or also known
* as aadnk on GitHub.
*
* <a href="https://gist.github.com/aadnk/8138186">Original Source</a>
*
* @param data Base64 string of data containing an inventory.
* @return Inventory created from the Base64 string.
* @throws IOException
*/
public static Inventory fromBase64(String data) throws IOException {
try {
ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(data));
BukkitObjectInputStream dataInput = new BukkitObjectInputStream(inputStream);
Inventory inventory = Bukkit.getServer().createInventory(null, dataInput.readInt(),"Vault");
for (int i = 0; i < inventory.getSize(); i++) {
inventory.setItem(i, (ItemStack) dataInput.readObject());
}
dataInput.close();
return inventory;
} catch (ClassNotFoundException e) {
throw new IOException("Unable to decode class type.", e);
}
}
示例2: registerContainer
import org.bukkit.inventory.Inventory; //导入方法依赖的package包/类
private void registerContainer(Inventory inv) {
// When a chest (or other block inventory) is accessed, check if it's a wool chest
Boolean isWoolChest = this.chests.get(inv);
if(isWoolChest == null) {
// If we haven't seen this chest yet, check it for wool
isWoolChest = this.containsObjectiveWool(inv);
this.chests.put(inv, isWoolChest);
if(isWoolChest) {
// If it is a wool chest, take a snapshot of the wools
Map<Integer, ItemStack> contents = new HashMap<>();
this.woolChests.put(inv, contents);
for(int slot = 0; slot < inv.getSize(); ++slot) {
ItemStack stack = inv.getItem(slot);
if(stack != null && this.isObjectiveWool(stack)) {
contents.put(slot, stack.clone());
}
}
}
}
}
示例3: takeItem
import org.bukkit.inventory.Inventory; //导入方法依赖的package包/类
public static boolean takeItem(Inventory inv, ItemStack item, int takeAmount) {
Set<Integer> removeSlots = new HashSet<>(takeAmount);
for (int i = 0; i < inv.getSize(); i++) {
ItemStack elemItem = inv.getItem(i);
if (elemItem == null || elemItem.getType() == Material.AIR
|| !elemItem.isSimilar(item))
continue;
int amount = elemItem.getAmount();
if (takeAmount > amount) {
takeAmount -= amount;
removeSlots.add(i);
} else {
if (takeAmount < amount) {
elemItem.setAmount(amount - takeAmount);
} else {
removeSlots.add(i);
}
removeSlots.forEach(inv::clear);
return true;
}
}
return false;
}
示例4: onClickGUI
import org.bukkit.inventory.Inventory; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onClickGUI(InventoryClickEvent e) {
Inventory inv = e.getInventory();
if (inv == null) {
return;
}
if (i18n.tr("title").equals(inv.getTitle())) {
e.setCancelled(true);
}
if (e.getWhoClicked() instanceof Player) {
Player p = (Player) e.getWhoClicked();
int slot = e.getRawSlot();
if (slot < 0 || slot > inv.getSize()) {
return;
}
GUISortPing guiSortPing = GUISortPingHolder.get(p);
if (guiSortPing != null) {
if (slot == 44) {
p.openInventory(guiSortPing.getPreviousPage());
} else if (slot == 53) {
p.openInventory(guiSortPing.getNextPage());
}
}
}
}
示例5: limitWorkbenches
import org.bukkit.inventory.Inventory; //导入方法依赖的package包/类
private void limitWorkbenches(Player player) {
boolean workbench = false;
Inventory inventory = player.getInventory();
for (int slot = 0; slot < inventory.getSize(); ++slot) {
ItemStack item = inventory.getItem(slot);
if (item != null && item.getType().equals(Material.WORKBENCH)) {
if (workbench) {
inventory.setItem(slot, null);
} else {
workbench = true;
item.setAmount(1);
//TODO: Ensure that the amount of workbenches in the inventory updates on the client
}
}
}
}
示例6: fillInventoryWithWool
import org.bukkit.inventory.Inventory; //导入方法依赖的package包/类
private void fillInventoryWithWool(Inventory inventory, DyeColor dyeColor) {
Wool wool = new Wool(dyeColor);
for (int i = 0; i < inventory.getSize(); i++) {
inventory.setItem(i, new ItemStack(wool.getItemType(), 1, (short) 0, wool.getData()));
}
}
示例7: decodeInventory
import org.bukkit.inventory.Inventory; //导入方法依赖的package包/类
public static Inventory decodeInventory(byte[] buf, String title) {
try (ByteArrayInputStream inputStream = new ByteArrayInputStream(buf)) {
try (BukkitObjectInputStream dataInput = new BukkitObjectInputStream(inputStream)) {
Inventory inventory = Bukkit.getServer().createInventory(null, dataInput.readInt(), title);
for (int i = 0; i < inventory.getSize(); i++) {
inventory.setItem(i, (ItemStack) dataInput.readObject());
}
return inventory;
}
} catch (ClassNotFoundException | IOException e) {
throw new RuntimeException(e);
}
}
示例8: reroll
import org.bukkit.inventory.Inventory; //导入方法依赖的package包/类
private void reroll(Inventory inv) {
for (int k = 0; k < inv.getSize(); k++) {
ItemStack item = inv.getItem(k);
if (item != null) {
inv.setItem(k, reroll(item));
}
}
}
示例9: getAmount
import org.bukkit.inventory.Inventory; //导入方法依赖的package包/类
public static int getAmount(Inventory inventory, ItemStack item) {
int amount = 0;
for (int i = 0; i < inventory.getSize(); i++) {
if (inventory.getItem(i) != null &&
inventory.getItem(i).getType() != Material.AIR &&
inventory.getItem(i).isSimilar(item)) {
amount += inventory.getItem(i).getAmount();
}
}
return amount;
}
示例10: showInventoryPreview
import org.bukkit.inventory.Inventory; //导入方法依赖的package包/类
protected void showInventoryPreview(Player viewer, Inventory realInventory, Inventory fakeInventory) {
if(viewer == null) return;
View view = views.get(viewer);
if(view != null && view.watched.equals(realInventory) && view.preview.getSize() == fakeInventory.getSize()) {
view.preview.setContents(fakeInventory.contents());
} else {
view = new View(realInventory, fakeInventory);
views.put(viewer, view);
viewer.openInventory(fakeInventory);
}
}
示例11: contents
import org.bukkit.inventory.Inventory; //导入方法依赖的package包/类
public static Stream<ItemStack> contents(Inventory inventory) {
// Do this without calling getContents(), because it create a temp array
final Stream.Builder<ItemStack> builder = Stream.builder();
for(int i = 0; i < inventory.getSize(); i++) {
final ItemStack item = inventory.getItem(i);
if(!ItemUtils.isNothing(item)) {
builder.add(item);
}
}
return builder.build();
}
示例12: open
import org.bukkit.inventory.Inventory; //导入方法依赖的package包/类
public void open(HumanEntity human) {
Inventory topInv = human.getOpenInventory().getTopInventory();
Inventory newInv = createInventory();
if (topInv != null && topInv.getTitle().equals(data.title())
&& topInv.getSize() == data.size()) {
topInv.setContents(newInv.getContents());
if (human instanceof Player) {
((Player) human).updateInventory();
}
} else {
human.openInventory(newInv);
}
GUI_MAP.put(human.getName(), this);
}
示例13: isEmpty
import org.bukkit.inventory.Inventory; //导入方法依赖的package包/类
public static boolean isEmpty(Inventory inventory) {
for (int i = 0; i < inventory.getSize(); i++) {
ItemStack item = inventory.getItem(i);
if (item != null && item.getType() != Material.AIR)
return false;
}
return true;
}
示例14: hasSpace
import org.bukkit.inventory.Inventory; //导入方法依赖的package包/类
public static int hasSpace(Inventory inv, ItemStack item) {
int space = 0;
for (int i = 0; i < inv.getSize(); i++) {
ItemStack element = inv.getItem(i);
if (element == null || element.getType() == Material.AIR) {
space += item.getMaxStackSize();
} else if (element.isSimilar(item)) {
space += item.getMaxStackSize() - element.getAmount();
}
}
return space;
}
示例15: InventoryToString
import org.bukkit.inventory.Inventory; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
public static String InventoryToString (Inventory invInventory)
{
String serialization = invInventory.getSize() + ";";
for (int i = 0; i < invInventory.getSize(); i++)
{
ItemStack is = invInventory.getItem(i);
if (is != null)
{
String serializedItemStack = new String();
String isType = String.valueOf(is.getType().getId());
serializedItemStack += "[email protected]" + isType;
if (is.getDurability() != 0)
{
String isDurability = String.valueOf(is.getDurability());
serializedItemStack += ":[email protected]" + isDurability;
}
if (is.getAmount() != 1)
{
String isAmount = String.valueOf(is.getAmount());
serializedItemStack += ":[email protected]" + isAmount;
}
Map<Enchantment,Integer> isEnch = is.getEnchantments();
if (isEnch.size() > 0)
{
for (Entry<Enchantment,Integer> ench : isEnch.entrySet())
{
serializedItemStack += ":[email protected]" + ench.getKey().getId() + "@" + ench.getValue();
}
}
serialization += i + "#" + serializedItemStack + ";";
}
}
return serialization;
}