Java Code Examples for org.bukkit.inventory.PlayerInventory

The following examples show how to use org.bukkit.inventory.PlayerInventory. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: AnnihilationPro   Source File: ShopMenuItem.java    License: MIT License 9 votes vote down vote up
@Override
public void onItemClick(ItemClickEvent event)
{
	Player player = event.getPlayer();
	PlayerInventory p = player.getInventory();
	if(p.containsAtLeast(new ItemStack(Material.GOLD_INGOT), cost))
	{
		int total = 0;
		for(ItemStack s : p.all(Material.GOLD_INGOT).values())
		{
			total += s.getAmount();
		}
		p.remove(Material.GOLD_INGOT);
		if(total-cost > 0)
			p.addItem(new ItemStack(Material.GOLD_INGOT,total-cost));
		p.addItem(product);
		player.sendMessage(Lang.PURCHASEDITEM.toString());
	}
	else player.sendMessage(Lang.COULDNOTPURCHASE.toString());
}
 
Example 2
Source Project: uSkyBlock   Source File: PlayerEvents.java    License: GNU General Public License v3.0 7 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL)
public void onClickOnObsidian(final PlayerInteractEvent event) {
    if (!plugin.getWorldManager().isSkyWorld(event.getPlayer().getWorld())) {
        return;
    }
    long now = System.currentTimeMillis();
    Player player = event.getPlayer();
    PlayerInventory inventory = player.getInventory();
    Block block = event.getClickedBlock();
    Long lastClick = obsidianClick.get(player.getUniqueId());
    if (lastClick != null && (lastClick + OBSIDIAN_SPAM) >= now) {
        plugin.notifyPlayer(player, tr("\u00a74You can only convert obsidian once every 10 seconds"));
        return;
    }
    if (Settings.extras_obsidianToLava && plugin.playerIsOnIsland(player)
            && plugin.getWorldManager().isSkyWorld(player.getWorld())
            && event.getAction() == Action.RIGHT_CLICK_BLOCK
            && player.getItemInHand() != null
            && player.getItemInHand().getType() == Material.BUCKET
            && block != null
            && block.getType() == Material.OBSIDIAN
            && !testForObsidian(block)) {
        if (inventory.firstEmpty() != -1) {
            obsidianClick.put(player.getUniqueId(), now);
            player.sendMessage(tr("\u00a7eChanging your obsidian back into lava. Be careful!"));
            inventory.removeItem(new ItemStack(Material.BUCKET, 1));
            inventory.addItem(new ItemStack(Material.LAVA_BUCKET, 1));
            player.updateInventory();
            block.setType(Material.AIR);
            event.setCancelled(true); // Don't execute the click anymore (since that would re-place the lava).
        } else {
            player.sendMessage(tr("\u00a7eYour inventory must have another empty space!"));
        }
    }
}
 
Example 3
private Player mockPlayer(String name, GameMode gameMode) {
    Player mock = mock(Player.class);
    PlayerInventory inv = mock(PlayerInventory.class);
    inv.setContents(new ItemStack[39]);
    inv.setArmorContents(new ItemStack[4]);

    Inventory enderChest = mock(Inventory.class);
    enderChest.setContents(new ItemStack[27]);

    given(mock.getInventory()).willReturn(inv);
    given(mock.getEnderChest()).willReturn(enderChest);
    given(mock.getName()).willReturn(name);
    given(mock.getUniqueId()).willReturn(TestHelper.TEST_UUID);
    given(mock.getGameMode()).willReturn(gameMode);
    AttributeInstance attribute = mock(AttributeInstance.class);
    given(mock.getAttribute(Attribute.GENERIC_MAX_HEALTH)).willReturn(attribute);
    given(attribute.getBaseValue()).willReturn(20.0);

    return mock;
}
 
Example 4
Source Project: BedWars   Source File: MiscUtils.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void giveItemsToPlayer(List<ItemStack> itemStackList, Player player, TeamColor teamColor) {
    for (ItemStack itemStack : itemStackList) {
        final String materialName = itemStack.getType().toString();
        final PlayerInventory playerInventory = player.getInventory();

        if (materialName.contains("HELMET")) {
            playerInventory.setHelmet(Main.applyColor(teamColor, itemStack));
        } else if (materialName.contains("CHESTPLATE")) {
            playerInventory.setChestplate(Main.applyColor(teamColor, itemStack));
        } else if (materialName.contains("LEGGINGS")) {
            playerInventory.setLeggings(Main.applyColor(teamColor, itemStack));
        } else if (materialName.contains("BOOTS")) {
            playerInventory.setBoots(Main.applyColor(teamColor, itemStack));
        } else {
            playerInventory.addItem(Main.applyColor(teamColor, itemStack));
        }
    }
}
 
Example 5
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void processRepair(PlayerPickupItemEvent event) {
  ItemStack pickup = event.getItem().getItemStack();

  if (this.toRepair.contains(pickup.getType())) {
    PlayerInventory inv = event.getPlayer().getInventory();
    for (ItemStack invStack :
        Iterables.concat(
            Arrays.asList(inv.getContents()), Arrays.asList(inv.getArmorContents()))) {
      if (this.canRepair(pickup, invStack)) {
        this.doRepair(event, invStack);
        return;
      }
    }
  }
}
 
Example 6
Source Project: LagMonitor   Source File: GraphListener.java    License: MIT License 6 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onInteract(PlayerInteractEvent clickEvent) {
    Player player = clickEvent.getPlayer();
    PlayerInventory inventory = player.getInventory();

    ItemStack mainHandItem;
    if (mainHandSupported) {
        mainHandItem = inventory.getItemInMainHand();
    } else {
        mainHandItem = inventory.getItemInHand();
    }

    if (isOurGraph(mainHandItem)) {
        inventory.setItemInMainHand(new ItemStack(Material.AIR));
    }
}
 
Example 7
Source Project: BedWars   Source File: MiscUtils.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void giveItemsToPlayer(List<ItemStack> itemStackList, Player player, TeamColor teamColor) {
    for (ItemStack itemStack : itemStackList) {
        final String materialName = itemStack.getType().toString();
        final PlayerInventory playerInventory = player.getInventory();

        if (materialName.contains("HELMET")) {
            playerInventory.setHelmet(Main.applyColor(teamColor, itemStack));
        } else if (materialName.contains("CHESTPLATE")) {
            playerInventory.setChestplate(Main.applyColor(teamColor, itemStack));
        } else if (materialName.contains("LEGGINGS")) {
            playerInventory.setLeggings(Main.applyColor(teamColor, itemStack));
        } else if (materialName.contains("BOOTS")) {
            playerInventory.setBoots(Main.applyColor(teamColor, itemStack));
        } else {
            playerInventory.addItem(Main.applyColor(teamColor, itemStack));
        }
    }
}
 
Example 8
Source Project: TabooLib   Source File: ItemStacker.java    License: MIT License 6 votes vote down vote up
/**
 * 添加并拆分,但不合并
 * 返回值为是否添加完成
 *
 * desc = 快捷栏逆向添加,用于工作台拟真,会忽略 start 参数
 */
public static boolean addItemAndSplit(ItemStack item, Inventory inventory, int start, boolean desc) {
    int size = inventory instanceof PlayerInventory || inventory instanceof CraftingInventory ? 36 : inventory.getSize();
    if (desc) {
        // 8 ~ 0
        for (int i = 8; i >= 0; i--) {
            if (check(item, inventory, i)) {
                return true;
            }
        }
    }
    // 9 ~ 36
    for (int i = desc ? start + 9 : start; i < size; i++) {
        if (check(item, inventory, i)) {
            return true;
        }
    }
    return false;
}
 
Example 9
Source Project: TabooLib   Source File: ItemStacker.java    License: MIT License 6 votes vote down vote up
/**
 * 合并物品,不新增
 */
public static AddResult addItemAndMerge(ItemStack item, Inventory inventory, Integer[] ignore) {
    boolean changed = false;
    int count = item.getAmount();
    int size = inventory instanceof PlayerInventory || inventory instanceof CraftingInventory ? 36 : inventory.getSize();
    for (int i = 0; i < size; i++) {
        if (ArrayUtil.contains(ignore, i)) {
            continue;
        }
        ItemStack inventoryItem = inventory.getItem(i);
        if (!item.isSimilar(inventoryItem)) {
            continue;
        }
        while (count > 0 && inventoryItem.getAmount() < item.getType().getMaxStackSize()) {
            changed = true;
            inventoryItem.setAmount(inventoryItem.getAmount() + 1);
            count--;
        }
        if (count == 0) {
            return new AddResult(count, changed);
        }
    }
    return new AddResult(count, changed);
}
 
Example 10
public void restoreKeptInventory() {
    final List<ItemStack> displaced = new ArrayList<>();
    final PlayerInventory inv = bukkit.getInventory();

    kept.forEach((slot, keptStack) -> {
        final ItemStack invStack = slot.getItem(bukkit);

        if(invStack == null || slot instanceof Slot.Armor) {
            slot.putItem(inv, keptStack);
        } else {
            if(invStack.isSimilar(keptStack)) {
                int n = Math.min(keptStack.getAmount(), invStack.getMaxStackSize() - invStack.getAmount());
                invStack.setAmount(invStack.getAmount() + n);
                keptStack.setAmount(keptStack.getAmount() - n);
            }
            if(keptStack.getAmount() > 0) {
                displaced.add(keptStack);
            }
        }

        for(ItemStack stack : displaced) {
            inv.addItem(stack);
        }
    });
    kept.clear();
}
 
Example 11
public void previewInventory(Player viewer, Inventory realInventory) {
    if(viewer == null) { return; }

    if(realInventory instanceof PlayerInventory) {
        previewPlayerInventory(viewer, (PlayerInventory) realInventory);
    }else {
        Inventory fakeInventory;
        if(realInventory instanceof DoubleChestInventory) {
            if(realInventory.hasCustomName()) {
                fakeInventory = Bukkit.createInventory(viewer, realInventory.getSize(), realInventory.getName());
            } else {
                fakeInventory = Bukkit.createInventory(viewer, realInventory.getSize());
            }
        } else {
            if(realInventory.hasCustomName()) {
                fakeInventory = Bukkit.createInventory(viewer, realInventory.getType(), realInventory.getName());
            } else {
                fakeInventory = Bukkit.createInventory(viewer, realInventory.getType());
            }
        }
        fakeInventory.setContents(realInventory.contents());

        this.showInventoryPreview(viewer, realInventory, fakeInventory);
    }
}
 
Example 12
Source Project: Civs   Source File: CivilianListener.java    License: GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onInventoryMoveEvent(InventoryMoveItemEvent event) {
    if (ConfigManager.getInstance().getAllowSharingCivsItems()) {
        return;
    }
    if (!CVItem.isCivsItem(event.getItem())) {
        return;
    }
    if (!(event.getDestination() instanceof PlayerInventory)) {
        event.setCancelled(true);
        if (!event.getSource().getViewers().isEmpty()) {
            HumanEntity humanEntity = event.getSource().getViewers().get(0);
            humanEntity.sendMessage(Civs.getPrefix() +
                    LocaleManager.getInstance().getTranslationWithPlaceholders((Player) humanEntity,
                            LocaleConstants.PREVENT_CIVS_ITEM_SHARE));
        }
    }
}
 
Example 13
/**
 * Sets the Inventory using an ItemStack array constructed from a JsonObject.
 *
 * @param player The InventoryHolder to which the Inventory will be set
 * @param inv    The reference JsonArray
 * @param format Data format being used; 0 is old, 1 is new
 */
public void setInventory(Player player, JsonObject inv, int format) {
    PlayerInventory inventory = player.getInventory();
    
    ItemStack[] armor = deserializeInventory(inv.getAsJsonArray("armor"), 4, format);
    ItemStack[] inventoryContents = deserializeInventory(inv.getAsJsonArray("inventory"), inventory.getSize(), format);

    inventory.clear();
    if (armor != null) {
    	inventory.setArmorContents(armor);
    }
    
    if (inventoryContents != null) {
    	inventory.setContents(inventoryContents);
    }
   
}
 
Example 14
Source Project: AdditionsAPI   Source File: BlockIgnite.java    License: MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onBlockIgnite(BlockIgniteEvent event) {
	if (event.getPlayer() == null)
		return;
	PlayerInventory inv = event.getPlayer().getInventory();
	ItemStack item = inv.getItemInMainHand();
	if (ItemType.getItemType(item) != ItemType.FLINT_AND_STEEL) {
		item = inv.getItemInOffHand();
		if (ItemType.getItemType(item) != ItemType.FLINT_AND_STEEL)
			return;
	}
	if (AdditionsAPI.isCustomItem(item)) {
		CustomItemBlockIgniteEvent customEvent = new CustomItemBlockIgniteEvent(event, new CustomItemStack(item));
		Bukkit.getServer().getPluginManager().callEvent(customEvent);
	}
}
 
Example 15
Source Project: AdditionsAPI   Source File: EntityDamage.java    License: MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onEntityDamage(EntityDamageEvent event) {
	if (event.isCancelled())
		return;

	DamageCause cause = event.getCause();
	Entity damagee = event.getEntity();
	EntityType damageeType = damagee.getType();
	// PlayerCustomArmorDamageEvent
	if (damageeType == EntityType.PLAYER) {
		Player player = (Player) damagee;
		PlayerInventory inv = player.getInventory();
		for (ItemStack armor : inv.getArmorContents())
			// TODO: Speed up
			if (armor != null && armor.getType() != Material.AIR && AdditionsAPI.isCustomItem(armor)
					&& new CustomItemStack(armor).getCustomItem() instanceof CustomArmor
					&& new CustomItemStack(armor).getCustomItem()
							.getDurabilityMechanics() instanceof ArmorDurability) {
				CustomArmor cArmor = (CustomArmor) new CustomItemStack(armor).getCustomItem();
				Bukkit.getServer().getPluginManager().callEvent(new PlayerCustomArmorDamageEvent(player, armor,
						cArmor, cause, (float) event.getDamage(), armor.containsEnchantment(Enchantment.THORNS)));
			}
	}
}
 
Example 16
Source Project: StaffPlus   Source File: JavaUtils.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Gets the slot of the given item through iteration.
 * 
 * @param player The inventory to iterate through.
 * @param item The ItemStack to check for.
 * @return The found slot in the inventory.
 */
public static int getItemSlot(PlayerInventory inventory, ItemStack item)
{
	int slot = 0;
	ItemStack[] contents = inventory.getContents();
	
	for(int i = 0; i < contents.length; i++)
	{
		ItemStack current = contents[i];
		
		if(current == null)
		{
			continue;
		}
		
		if(current.equals(item))
		{
			slot = i;
			break;
		}
	}
	
	return slot;
}
 
Example 17
Source Project: CS-CoreLib   Source File: InvUtils.java    License: GNU General Public License v3.0 6 votes vote down vote up
public static boolean fits(Inventory inv, ItemStack item) {
	Inventory inv2 = null;
	int size = inv.getSize();
	if (inv instanceof PlayerInventory) {
		size = 36;
		inv2 = Bukkit.createInventory(null, size);
	}
	else if (inv.getSize() % 9 == 0) {
		inv2 = Bukkit.createInventory(null, size);
	}
	else {
		inv2 = Bukkit.createInventory(null, inv.getType());
	}
	for (int i = 0; i < size; i++) {
		inv2.setItem(i, inv.getItem(i));
	}
	return inv2.addItem(item).isEmpty();
}
 
Example 18
Source Project: LagMonitor   Source File: GraphListener.java    License: MIT License 6 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onInteract(PlayerInteractEvent clickEvent) {
    Player player = clickEvent.getPlayer();
    PlayerInventory inventory = player.getInventory();

    ItemStack mainHandItem;
    if (mainHandSupported) {
        mainHandItem = inventory.getItemInMainHand();
    } else {
        mainHandItem = inventory.getItemInHand();
    }

    if (isOurGraph(mainHandItem)) {
        inventory.setItemInMainHand(new ItemStack(Material.AIR));
    }
}
 
Example 19
/**
 * Sets the Inventory using an ItemStack array constructed from a JsonObject.
 *
 * @param player The InventoryHolder to which the Inventory will be set
 * @param inv    The reference JsonArray
 * @param format Data format being used; 0 is old, 1 is new
 */
public void setInventory(Player player, JsonObject inv, int format) {
    PlayerInventory inventory = player.getInventory();
    
    ItemStack[] armor = deserializeInventory(inv.getAsJsonArray("armor"), 4, format);
    ItemStack[] inventoryContents = deserializeInventory(inv.getAsJsonArray("inventory"), inventory.getSize(), format);

    inventory.clear();
    if (armor != null) {
    	inventory.setArmorContents(armor);
    }
    
    if (inventoryContents != null) {
    	inventory.setContents(inventoryContents);
    }
   
}
 
Example 20
private Player mockPlayer(String name, GameMode gameMode) {
    Player mock = mock(Player.class);
    PlayerInventory inv = mock(PlayerInventory.class);
    inv.setContents(new ItemStack[39]);
    inv.setArmorContents(new ItemStack[4]);

    Inventory enderChest = mock(Inventory.class);
    enderChest.setContents(new ItemStack[27]);

    given(mock.getInventory()).willReturn(inv);
    given(mock.getEnderChest()).willReturn(enderChest);
    given(mock.getName()).willReturn(name);
    given(mock.getUniqueId()).willReturn(TestHelper.TEST_UUID);
    given(mock.getGameMode()).willReturn(gameMode);
    AttributeInstance attribute = mock(AttributeInstance.class);
    given(mock.getAttribute(Attribute.GENERIC_MAX_HEALTH)).willReturn(attribute);
    given(attribute.getBaseValue()).willReturn(20.0);

    return mock;
}
 
Example 21
Source Project: CardinalPGM   Source File: ArmorKeep.java    License: MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPgmSpawn(CardinalSpawnEvent event) {
    Player player = event.getPlayer();
    PlayerInventory inventory = player.getInventory();
    if (helmet.containsKey(player)) {
        if (helmet.get(player) != null) {
            inventory.setHelmet(helmet.get(player));
        }
    }
    if (chestplate.containsKey(player)) {
        if (chestplate.get(player) != null) {
            inventory.setChestplate(chestplate.get(player));
        }
    }
    if (leggings.containsKey(player)) {
        if (leggings.get(player) != null) {
            inventory.setLeggings(leggings.get(player));
        }
    }
    if (boots.containsKey(player)) {
        if (boots.get(player) != null) {
            inventory.setBoots(boots.get(player));
        }
    }
}
 
Example 22
Source Project: BedwarsRel   Source File: NewItemShop.java    License: GNU General Public License v3.0 6 votes vote down vote up
private boolean hasEnoughRessource(Player player, VillagerTrade trade) {
  ItemStack item1 = trade.getItem1();
  ItemStack item2 = trade.getItem2();
  PlayerInventory inventory = player.getInventory();

  if (item2 != null) {
    if (!inventory.contains(item1.getType(), item1.getAmount())
        || !inventory.contains(item2.getType(), item2.getAmount())) {
      return false;
    }
  } else {
    if (!inventory.contains(item1.getType(), item1.getAmount())) {
      return false;
    }
  }

  return true;
}
 
Example 23
Source Project: ArmorStandTools   Source File: Main.java    License: MIT License 6 votes vote down vote up
void restoreInventory(Player p) {
    removeAllTools(p);
    UUID uuid = p.getUniqueId();
    ItemStack[] savedInv = savedInventories.get(uuid);
    if(savedInv == null) return;
    PlayerInventory plrInv = p.getInventory();
    ItemStack[] newItems = plrInv.getContents().clone();
    plrInv.setContents(savedInv);
    savedInventories.remove(uuid);
    for(ItemStack i : newItems) {
        if(i == null) continue;
        HashMap<Integer, ItemStack> couldntFit = plrInv.addItem(i);
        for (ItemStack is : couldntFit.values()) {
            p.getWorld().dropItem(p.getLocation(), is);
        }
    }
    p.sendMessage(ChatColor.GREEN + Config.invReturned);
}
 
Example 24
Source Project: RedProtect   Source File: Compat19.java    License: GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onPlayerMove(PlayerMoveEvent e) {
    Player p = e.getPlayer();

    // Glide options
    if (!p.hasPermission("redprotect.bypass.glide")) {
        if (!RedProtect.get().config.globalFlagsRoot().worlds.get(p.getWorld().getName()).player_glide.allow_elytra) {
            ItemStack item = p.getInventory().getChestplate();
            if (item != null && item.getType().equals(Material.ELYTRA)) {
                PlayerInventory inv = p.getInventory();
                inv.setChestplate(new ItemStack(Material.AIR));
                if (inv.firstEmpty() == -1) {
                    p.getWorld().dropItem(p.getLocation(), item);
                } else {
                    inv.setItem(inv.firstEmpty(), item);
                }
                p.playSound(p.getLocation(), Sound.ENTITY_ITEM_PICKUP, 10, 1);
                RedProtect.get().lang.sendMessage(p, "globallistener.elytra.cantequip");
            }
        }
    }
}
 
Example 25
Source Project: UHC   Source File: ClearInventoryAction.java    License: MIT License 6 votes vote down vote up
@Override
protected void run(Player player) {
    final PlayerInventory inv = player.getInventory();

    // clear main inventory
    contents = inv.getContents();
    inv.clear();

    // clear armour slots
    armourContents = inv.getArmorContents();
    inv.setArmorContents(null);

    // clear if they have something on their cursour currently
    onCursor = player.getItemOnCursor();
    player.setItemOnCursor(new ItemStack(Material.AIR));

    // if they have a crafting inventory open clear items from it too
    // stops storing items in crafting slots bypassing clear inventories
    final InventoryView openInventory = player.getOpenInventory();
    if (openInventory.getType() == InventoryType.CRAFTING) {
        crafting = Optional.of(openInventory.getTopInventory().getContents());
        openInventory.getTopInventory().clear();
    } else {
        crafting = Optional.absent();
    }
}
 
Example 26
Source Project: PGM   Source File: Observing.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void onEvent(InventoryClickEvent event) {
  super.onEvent(event);

  if (!(event.getClickedInventory() instanceof PlayerInventory) || event.getCursor() == null)
    return;

  ItemStack item = event.getCursor();
  if (BAD_TYPES.contains(item.getType()) || item.getData() instanceof Door) {
    event.setCancelled(true);
  }
}
 
Example 27
public void previewInventory(Player viewer, Inventory realInventory) {
  if (viewer == null) {
    return;
  }

  if (realInventory instanceof PlayerInventory) {
    previewPlayerInventory(viewer, (PlayerInventory) realInventory);
  } else {
    Inventory fakeInventory;
    if (realInventory instanceof DoubleChestInventory) {
      if (realInventory.hasCustomName()) {
        fakeInventory =
            Bukkit.createInventory(viewer, realInventory.getSize(), realInventory.getName());
      } else {
        fakeInventory = Bukkit.createInventory(viewer, realInventory.getSize());
      }
    } else {
      if (realInventory.hasCustomName()) {
        fakeInventory =
            Bukkit.createInventory(viewer, realInventory.getType(), realInventory.getName());
      } else {
        fakeInventory = Bukkit.createInventory(viewer, realInventory.getType());
      }
    }
    fakeInventory.setContents(realInventory.getContents());

    this.showInventoryPreview(viewer, realInventory, fakeInventory);
  }
}
 
Example 28
Source Project: PGM   Source File: ScoreMatchModule.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
private double redeemItems(ScoreBox box, PlayerInventory inventory) {
  ItemStack[] notArmor = inventory.getContents();
  ItemStack[] armor = inventory.getArmorContents();

  double points = redeemItems(box, notArmor) + redeemItems(box, armor);

  if (points != 0) {
    inventory.setContents(notArmor);
    inventory.setArmorContents(armor);
  }

  return points;
}
 
Example 29
Source Project: BedWars   Source File: GamePlayer.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
public void clean() {
    PlayerInventory inv = this.player.getInventory();
    inv.setArmorContents(new ItemStack[4]);
    inv.setContents(new ItemStack[]{});

    this.player.setAllowFlight(false);
    this.player.setFlying(false);
    this.player.setExp(0.0F);
    this.player.setLevel(0);
    this.player.setSneaking(false);
    this.player.setSprinting(false);
    this.player.setFoodLevel(20);
    this.player.setSaturation(10);
    this.player.setExhaustion(0);
    this.player.setMaxHealth(20D);
    this.player.setHealth(this.player.getMaxHealth());
    this.player.setFireTicks(0);
    this.player.setGameMode(GameMode.SURVIVAL);

    if (this.player.isInsideVehicle()) {
        this.player.leaveVehicle();
    }

    for (PotionEffect e : this.player.getActivePotionEffects()) {
        this.player.removePotionEffect(e.getType());
    }

    this.player.updateInventory();
}
 
Example 30
Source Project: UHC   Source File: ClearInventoryAction.java    License: MIT License 5 votes vote down vote up
@Override
protected void revert(Player player) {
    final PlayerInventory inv = player.getInventory();

    inv.setContents(contents);
    inv.setArmorContents(armourContents);
    player.setItemOnCursor(onCursor);

    if (crafting.isPresent()) {
        // add back to main inventory instead of the crafting slots
        inv.addItem(crafting.get());
    }
}