You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If a player has a large number of experience levels beyond the threshold of the number of bottles their inventory can hold, the plugin does not function as expected.
Solution
Add a check to see how many free spots are left in the player's inventory and only withdraw the correct number of bottles that can fill their inventory.
The text was updated successfully, but these errors were encountered:
The check being considered exists, but obviously must not be working correctly;
I put the whole method below for easy reference; I think it is related to armor slots and possibility a off-by-one error (yay! /sarcasm).
/** * Calculates the number of free spaces in the player's inventory that can be used to fill with experience bottles. * * @param player the player whose inventory is being checked * @return the number of tallied free spaces for bottles */privateintnumInvFreeSpace(Playerplayer) {
PlayerInventorypi = player.getInventory();
ItemStack[] is = pi.getContents(); //returns array of ItemStacks[] from invinttally = 0;
for (inti = 0; i < pi.getSize(); i++) {
if (is[i] == null || is[i].isSimilar(newItemStack(Material.AIR))) {
tally += 64;
}
}
for (inti = 0; i < pi.getSize(); i++) { // pi = player inventory objectif (is[i] != null && !is[i].isSimilar(newItemStack(Material.AIR))) {
if (is[i].isSimilar(newItemStack(Material.EXP_BOTTLE))) {
tally += 64 - (is[i].getAmount());
}
}
}
returntally;
}
Confirmed the error! (its not off by one)
Using my working version for the changes I still had the error - the update that added the shield slot adds another slot to inventory.
So all I have to do is find a way to make getContents() of inventory ignore the armor slots - there is a method called getStorageContents() that should do the trick, but it the API reference manual didn't seem certain it would always exclude the armor slots.
Problem
If a player has a large number of experience levels beyond the threshold of the number of bottles their inventory can hold, the plugin does not function as expected.
Solution
Add a check to see how many free spots are left in the player's inventory and only withdraw the correct number of bottles that can fill their inventory.
The text was updated successfully, but these errors were encountered: