use of org.bukkit.inventory.Inventory in project Glowstone by GlowstoneMC.
the class GlowDispenser method placeInDispenser.
public ItemStack placeInDispenser(ItemStack toPlace) {
Inventory inv = getInventory();
Map<Integer, ItemStack> map = inv.addItem(toPlace);
return map.isEmpty() ? null : map.get(0);
}
use of org.bukkit.inventory.Inventory in project SpaciousLib by anhcraft.
the class InteractItem method interact.
@EventHandler(priority = EventPriority.MONITOR)
public void interact(InventoryClickEvent event) {
Player player = (Player) event.getWhoClicked();
Inventory inventory = _InventoryClickEvent.getInventory(event);
ClickType type = event.getClick();
if (inventory != null && data.containsKey(inventory)) {
event.setCancelled(true);
event.setResult(Event.Result.DENY);
ItemStack item = event.getCurrentItem();
if (item != null && !item.getType().equals(Material.AIR) && data.get(inventory).containsKey(item)) {
HashMap<ItemStack, InteractItemRunnable> items = data.get(inventory);
items.get(item).run(player, item, type, event.getSlot());
data.put(inventory, items);
}
}
}
use of org.bukkit.inventory.Inventory in project Glowstone by GlowstoneMC.
the class RandomItemsContent method fillContainer.
public boolean fillContainer(Random random, DirectionalContainer container, BlockState state, int maxStacks) {
if (state.getBlock().getState() instanceof InventoryHolder) {
Inventory inventory = ((InventoryHolder) state.getBlock().getState()).getInventory();
int size = inventory.getSize();
for (int i = 0; i < maxStacks; i++) {
RandomAmountItem item = getRandomItem(random);
if (item != null) {
for (ItemStack stack : item.getItemStacks(random)) {
// slot can be overriden hence maxStacks can be less than what's expected
inventory.setItem(random.nextInt(size), stack);
}
}
}
} else {
throw new IllegalArgumentException("Bad container type");
}
return true;
}
use of org.bukkit.inventory.Inventory in project Glowstone by GlowstoneMC.
the class InventoryUtilTest method testRandomItem.
@Test
public void testRandomItem() {
Random random = new Random();
Inventory inventory = new GlowInventory(null, InventoryType.CHEST);
assertThat(-1, is(InventoryUtil.getRandomSlot(random, inventory, true)));
assertThat(InventoryUtil.getRandomSlot(random, inventory, false), OrderingComparison.greaterThanOrEqualTo(0));
inventory.setItem(0, new ItemStack(Material.APPLE));
assertThat(0, is(InventoryUtil.getRandomSlot(random, inventory, true)));
inventory.setItem(1, new ItemStack(Material.CARROT_ITEM));
assertThat(InventoryUtil.getRandomSlot(random, inventory, true), OrderingComparison.greaterThanOrEqualTo(0));
}
use of org.bukkit.inventory.Inventory in project Glowstone by GlowstoneMC.
the class HumanEntityStore method load.
// documented at http://minecraft.gamepedia.com/Player.dat_Format
// player data that does not correspond to HumanEntity is in PlayerStore
@Override
public void load(T entity, CompoundTag tag) {
super.load(entity, tag);
if (tag.isInt("XpSeed")) {
entity.setXpSeed(tag.getInt("XpSeed"));
}
if (tag.isInt("playerGameType")) {
GlowServer server = (GlowServer) Bukkit.getServer();
if (!server.getConfig().getBoolean(ServerConfig.Key.FORCE_GAMEMODE)) {
GameMode mode = GameMode.getByValue(tag.getInt("playerGameType"));
if (mode != null) {
entity.setGameMode(mode);
}
} else {
entity.setGameMode(server.getDefaultGameMode());
}
}
if (tag.isInt("SelectedItemSlot")) {
entity.getInventory().setHeldItemSlot(tag.getInt("SelectedItemSlot"));
}
if (tag.isList("Inventory", TagType.COMPOUND)) {
PlayerInventory inventory = entity.getInventory();
List<CompoundTag> items = tag.getCompoundList("Inventory");
inventory.setStorageContents(NbtSerialization.readInventory(items, 0, inventory.getSize() - 5));
inventory.setArmorContents(NbtSerialization.readInventory(items, 100, 4));
inventory.setExtraContents(NbtSerialization.readInventory(items, -106, 1));
}
if (tag.isList("EnderItems", TagType.COMPOUND)) {
Inventory inventory = entity.getEnderChest();
List<CompoundTag> items = tag.getCompoundList("EnderItems");
inventory.setContents(NbtSerialization.readInventory(items, 0, inventory.getSize()));
}
}
Aggregations