本文整理了Java中org.bukkit.inventory.Inventory
类的一些代码示例,展示了Inventory
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Inventory
类的具体详情如下:
包路径:org.bukkit.inventory.Inventory
类名称:Inventory
[英]Interface to the various inventories. Behavior relating to Material#AIR is unspecified.
[中]与各种库存的接口。未指定与材料#空气有关的行为。
代码示例来源:origin: GlowstoneMC/Glowstone
@Override
public boolean dispense() {
GlowBlock block = getBlock();
int dispenseSlot = getDispenseSlot();
if (dispenseSlot < 0) {
block.getWorld().playEffect(block.getLocation(), Effect.CLICK1, 0);
return false;
}
ItemStack origItems = getInventory().getItem(dispenseSlot);
DispenseBehavior behavior = getDispenseBehavior(origItems.getType());
ItemStack result = behavior.dispense(block, origItems);
getInventory().setItem(dispenseSlot, result);
return true;
}
代码示例来源:origin: Bukkit/Bukkit
public InventoryHolder getLeftSide() {
return inventory.getLeftSide().getHolder();
}
代码示例来源:origin: GlowstoneMC/Glowstone
private ItemStack getFirstItem(ContainerEntity container) {
Inventory inventory = container.getInventory();
for (int i = 0; i < inventory.getSize(); i++) {
if (inventory.getItem(i) == null || inventory.getItem(i).getType() == null) {
continue;
}
return inventory.getItem(i);
}
return null;
}
代码示例来源:origin: GlowstoneMC/Glowstone
/**
* Get a random slot index in an Inventory.
*
* @param random a Random instance
* @param inventory the inventory
* @param ignoreEmpty whether to skip empty items in the inventory
* @return the index of a random slot in the inventory, -1 if no possible slot was found
*/
public static int getRandomSlot(Random random, Inventory inventory, boolean ignoreEmpty) {
if (!ignoreEmpty) {
return random.nextInt(inventory.getSize());
}
List<Integer> notEmpty = new ArrayList<>();
for (int i = 0; i < inventory.getSize(); i++) {
if (!isEmpty(inventory.getItem(i))) {
notEmpty.add(i);
}
}
if (notEmpty.isEmpty()) {
return -1;
}
return notEmpty.get(random.nextInt(notEmpty.size()));
}
代码示例来源:origin: GlowstoneMC/Glowstone
@Override
public void load(GlowMinecart entity, CompoundTag tag) {
super.load(entity, tag);
if (entity instanceof InventoryHolder) {
Inventory inventory = ((InventoryHolder) entity).getInventory();
if (inventory != null) {
tag.readCompoundList("Items",
items -> inventory.setContents(NbtSerialization.readInventory(
items, 0, inventory.getSize())));
}
}
// todo
}
代码示例来源:origin: TheBusyBiscuit/Slimefun4
if (CSCoreLib.getLib().getProtectionManager().canAccessChest(p.getUniqueId(), b, true)) {
if (Slimefun.hasUnlocked(p, SlimefunItems.JUICER, true)) {
Dispenser disp = (Dispenser) b.getRelative(BlockFace.DOWN).getState();
Inventory inv = disp.getInventory();
for (ItemStack current: inv.getContents()) {
for (ItemStack convert: RecipeType.getRecipeInputs(machine)) {
if (convert != null && SlimefunManager.isItemSimiliar(current, convert, true)) {
ItemStack adding = RecipeType.getRecipeOutput(machine, convert);
if (InvUtils.fits(inv, adding)) {
ItemStack removing = current.clone();
removing.setAmount(1);
inv.removeItem(removing);
inv.addItem(adding);
p.getWorld().playSound(b.getLocation(), Sound.ENTITY_PLAYER_SPLASH, 1F, 1F);
p.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, Material.HAY_BLOCK);
代码示例来源:origin: io.github.bedwarsrel/BedwarsRel-Common
@SuppressWarnings("deprecation")
public static void openCategorySelection(Player p, Game g) {
List<MerchantCategory> cats = g.getOrderedItemShopCategories();
int nom = (cats.size() % 9 == 0) ? 9 : (cats.size() % 9);
int size = (cats.size() + (9 - nom)) + 9;
Inventory inv = Bukkit.createInventory(p, size, BedwarsRel._l(p, "ingame.shop.name"));
for (MerchantCategory cat : cats) {
if (p != null && !p.hasPermission(cat.getPermission())) {
continue;
}
ItemStack is = new ItemStack(cat.getMaterial(), 1);
ItemMeta im = is.getItemMeta();
if (Utils.isColorable(is)) {
is.setDurability(g.getPlayerTeam(p).getColor().getDyeColor().getWoolData());
}
im.setDisplayName(cat.getName());
im.setLore(cat.getLores());
is.setItemMeta(im);
inv.addItem(is);
}
ItemStack snow = new ItemStack(Material.SNOW_BALL, 1);
ItemMeta snowMeta = snow.getItemMeta();
snowMeta.setDisplayName(BedwarsRel._l(p, "ingame.shop.newshop"));
snowMeta.setLore(new ArrayList<String>());
snow.setItemMeta(snowMeta);
inv.setItem(size - 5, snow);
p.openInventory(inv);
}
代码示例来源:origin: io.github.bedwarsrel/BedwarsRel-Common
public void openSpectatorCompass(Player player) {
if (!this.isSpectator(player)) {
return;
}
int teamplayers = this.getTeamPlayers().size();
int nom = (teamplayers % 9 == 0) ? 9 : (teamplayers % 9);
int size = teamplayers + (9 - nom);
Inventory compass = Bukkit
.createInventory(null, size, BedwarsRel._l(player, "ingame.spectator"));
for (Team t : this.getTeams().values()) {
for (Player p : t.getPlayers()) {
ItemStack head = new ItemStack(Material.SKULL_ITEM, 1, (short) 3);
SkullMeta meta = (SkullMeta) head.getItemMeta();
meta.setDisplayName(t.getChatColor() + p.getDisplayName());
meta.setLore(Arrays.asList(t.getChatColor() + t.getDisplayName()));
meta.setOwner(p.getName());
head.setItemMeta(meta);
compass.addItem(head);
}
}
player.openInventory(compass);
}
代码示例来源:origin: eccentricdevotion/TARDIS
@EventHandler(ignoreCancelled = true)
public void onSonicMenuClose(InventoryCloseEvent event) {
Inventory inv = event.getInventory();
String title = inv.getTitle();
if (!title.equals(ChatColor.DARK_RED + "Sonic Prefs Menu")) {
return;
}
ItemStack sonic = inv.getItem(18);
if (sonic != null) {
Player p = (Player) event.getPlayer();
Location loc = p.getLocation();
loc.getWorld().dropItemNaturally(loc, sonic);
inv.setItem(18, new ItemStack(Material.AIR));
}
}
}
代码示例来源:origin: eccentricdevotion/TARDIS
@EventHandler
public void onWallMenuOpen(InventoryOpenEvent event) {
String name = event.getInventory().getTitle();
if (name.equals(ChatColor.DARK_RED + "TARDIS Wall Menu") || name.equals(ChatColor.DARK_RED + "TARDIS Floor Menu")) {
Player p = (Player) event.getPlayer();
scroll.put(p.getUniqueId(), 0);
}
}
代码示例来源:origin: eccentricdevotion/TARDIS
private void saveCurrentStorage(Inventory inv, String column, Player p) {
// loop through inventory contents and remove any items that are not disks or circuits
for (int i = 27; i < 54; i++) {
ItemStack is = inv.getItem(i);
if (is != null) {
if (!onlythese.contains(is.getType())) {
p.getLocation().getWorld().dropItemNaturally(p.getLocation(), is);
inv.setItem(i, new ItemStack(Material.AIR));
}
}
}
String serialized = TARDISSerializeInventory.itemStacksToString(inv.getContents());
HashMap<String, Object> set = new HashMap<>();
set.put(column, serialized);
HashMap<String, Object> where = new HashMap<>();
where.put("uuid", p.getUniqueId().toString());
new QueryFactory(plugin).doUpdate("storage", set, where);
}
代码示例来源:origin: io.github.bedwarsrel/BedwarsRel-Common
private void openBuyInventory(MerchantCategory category, Player player, Game game) {
List<VillagerTrade> offers = category.getOffers();
int sizeCategories = this.getCategoriesSize(player);
int sizeItems = offers.size();
int invSize = this.getBuyInventorySize(sizeCategories, sizeItems);
player.playSound(player.getLocation(), SoundMachine.get("CLICK", "UI_BUTTON_CLICK"),
Float.valueOf("1.0"), Float.valueOf("1.0"));
this.currentCategory = category;
Inventory buyInventory = Bukkit
.createInventory(player, invSize, BedwarsRel._l(player, "ingame.shop.name"));
this.addCategoriesToInventory(buyInventory, player, game);
for (int i = 0; i < offers.size(); i++) {
VillagerTrade trade = offers.get(i);
if (trade.getItem1().getType() == Material.AIR
&& trade.getRewardItem().getType() == Material.AIR) {
continue;
}
int slot = (this.getInventorySize(sizeCategories)) + i;
ItemStack tradeStack = this.toItemStack(trade, player, game);
buyInventory.setItem(slot, tradeStack);
}
player.openInventory(buyInventory);
}
代码示例来源:origin: eccentricdevotion/TARDIS
private void setPlay(Inventory inv, String str) {
ItemStack play = inv.getItem(15);
ItemMeta save = play.getItemMeta();
save.setLore(Collections.singletonList(str));
play.setItemMeta(save);
}
代码示例来源:origin: jiongjionger/NeverLag
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onBlockDispense(BlockDispenseEvent e) {
if (!cm.isAntiNegativeItemDupe) {
return;
}
Inventory content = null;
if (e.getBlock().getState() instanceof InventoryHolder) {
content = ((InventoryHolder) e.getBlock().getState()).getInventory();
}
if (content == null || content.getSize() == 0) {
return;
}
for (ItemStack item : content.getContents()) {
if (item != null && item.getType() != Material.AIR) {
if (item.getAmount() <= 0) {
item.setType(Material.AIR);
}
}
}
}
代码示例来源:origin: GlowstoneMC/Glowstone
if (view.getTopInventory().getType() != InventoryType.CRAFTING || viewSlot >= view
.getTopInventory().getSize()
|| ((GlowInventory) view.getTopInventory()).getSlot(viewSlot).getType()
!= SlotType.RESULT) {
ItemStack newCursor = cursor.clone();
Map<Integer, ItemStack> newSlots = new HashMap<>();
int perSlot = right ? 1 : cursor.getAmount() / slots.size();
for (int dragSlot : slots) {
ItemStack oldItem = view.getItem(dragSlot);
if (InventoryUtil.isEmpty(oldItem) || cursor.isSimilar(oldItem)) {
Inventory dragInv = dragSlot < top.getSize() ? top : bottom;
int oldItemAmount = InventoryUtil.itemOrEmpty(oldItem).getAmount();
int slot = event.getSlot();
player.getSession().send(new SetWindowSlotMessage(player.getOpenWindowId(),
slot, event.getInventory().getItem(slot)));
player.getSession().send(new SetWindowSlotMessage(-1, -1, player.getItemOnCursor()));
return true;
代码示例来源:origin: catageek/ByteCart
static private BookFile create(Inventory inventory, ItemStack mystack, int index, boolean binary, String name) {
if (mystack == null || ! mystack.getType().equals(Material.WRITTEN_BOOK)) {
mystack = new ItemStack(Material.WRITTEN_BOOK);
}
final BookMeta mybook = (BookMeta) Bukkit.getServer().getItemFactory().getItemMeta(Material.WRITTEN_BOOK);
if (name != null) {
final String myauthor = prefix + "." + name;
mybook.setAuthor(myauthor);
}
else {
mybook.setAuthor(prefix);
}
mystack.setItemMeta(mybook);
inventory.setItem(index, mystack);
return new BookFile(inventory, index, binary);
}
代码示例来源:origin: FunnyGuilds/FunnyGuilds
public void fillEmpty(final Material material) {
Validate.notNull(material, "Material cannot be NULL!");
for (int i = 0; i < inv.getSize(); i++) {
if (inv.getItem(i) == null) {
inv.setItem(i, new ItemStack(material, 1, (short) 15));
}
}
}
代码示例来源:origin: gvlfm78/BukkitOldCombatMechanics
@EventHandler(priority = EventPriority.HIGHEST)
public void onInventoryClick(InventoryClickEvent e){
if(!(e.getWhoClicked() instanceof Player)) return;
Player player = (Player) e.getWhoClicked();
if(!isEnabled(player.getWorld())) return;
if(player.getGameMode() == GameMode.CREATIVE) return;
InventoryType type = e.getInventory().getType(); // Only if they're in their inventory, not chests etc.
if(type != InventoryType.CRAFTING && type != InventoryType.PLAYER) return;
ItemStack cursor = e.getCursor();
ItemStack currentItem = e.getCurrentItem();
if((cursor != null && cursor.getType() != Material.ELYTRA) && (currentItem != null && currentItem.getType() != Material.ELYTRA)){
return;
}
if(e.getSlot() == 38 || e.getClick() == ClickType.SHIFT_LEFT || e.getClick() == ClickType.SHIFT_RIGHT){
e.setCancelled(true);
}
}
代码示例来源:origin: eccentricdevotion/TARDIS
private List<String> getSizeLore(Inventory inv) {
ItemStack is = inv.getItem(18);
ItemMeta im = is.getItemMeta();
return im.getLore();
}
}
代码示例来源:origin: eccentricdevotion/TARDIS
@EventHandler(ignoreCancelled = true)
public void onLazarusClose(InventoryCloseEvent event) {
String name = event.getInventory().getTitle();
UUID uuid = event.getPlayer().getUniqueId();
if (name.equals(ChatColor.DARK_RED + "Genetic Manipulator") && !plugin.getTrackerKeeper().getGeneticManipulation().contains(uuid)) {
Block b = plugin.getTrackerKeeper().getLazarus().get(event.getPlayer().getUniqueId());
if (b.getRelative(BlockFace.SOUTH).getType().equals(Material.COBBLESTONE_WALL)) {
b.getRelative(BlockFace.SOUTH).setType(Material.AIR);
b.getRelative(BlockFace.SOUTH).getRelative(BlockFace.UP).setType(Material.AIR);
}
untrack(uuid);
}
}
内容来源于网络,如有侵权,请联系作者删除!