i need to fix inventory...

This commit is contained in:
ScriptCat 2025-07-29 00:01:31 +03:00
parent a01fd21660
commit 4d222bae85
6 changed files with 20 additions and 13 deletions

View File

@ -42,7 +42,7 @@ public class ItemLoad
private static short getCount(NBTTagCompound tag)
{
short count = 0;
short count = 1;
if (tag.hasKey("count"))
{
count = tag.getShort("count");
@ -53,9 +53,9 @@ public class ItemLoad
private static short getDurability(NBTTagCompound tag)
{
short durability = 0;
if (tag.hasKey("durability"))
if (tag.hasKey("damage"))
{
durability = tag.getShort("durability");
durability = tag.getShort("damage");
}
return durability;
}

View File

@ -26,9 +26,14 @@ public class ItemNBT
private static void setBasic(ItemStack item, NBTTagCompound tag)
{
tag.setShort("count", (short)item.getAmount());
tag.setInt("id", item.getTypeId());
tag.setShort("durability", item.getDurability());
short count = (short)item.getAmount();
if (count != 1) { tag.setShort("count", count); }
int id = item.getTypeId();
if (id != 0) { tag.setInt("id", item.getTypeId()); }
short damage = item.getDurability();
if (damage != 0) { tag.setShort("damage", item.getDurability()); }
}
private static void setMetaTag(ItemStack item, NBTTagCompound baseTag)

View File

@ -23,12 +23,15 @@ public class AddCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String s, String[] strings) {
Player player = (Player) sender;
Player player;
if (sender == null) {
if (Bukkit.getOnlinePlayers().length == 0) { return true; }
player = Bukkit.getOnlinePlayers()[0];
}
else {
player = (Player) sender;
}
Material[] values = Material.values();
int id = values[ThreadLocalRandom.current().nextInt(values.length)].getId();

View File

@ -50,7 +50,7 @@ public class InventoryUtil
Player player = (Player) event.getWhoClicked();
if (!nameCurrentItem.isEmpty())
if (nameCurrentItem != null)
{
if (nameCurrentItem.equals(this.nameArrowRight)) {
PagesManager pagesManager = this.cacheManager.load(player);

View File

@ -15,6 +15,6 @@ public class InventoryItems
public synchronized void renderPage(PagesManager pagesManager, Inventory inventory)
{
List<ItemStack> array = InventoryItemsUtil.getArrayToRender(pagesManager, items_slots);
InventoryItemsUtil.renderList(array, inventory);
InventoryItemsUtil.renderList(array, inventory, this.items_slots);
}
}

View File

@ -19,15 +19,13 @@ public class InventoryItemsUtil
int start_item = getStartItemIndex(current_page, items_slots);
int end_item = getEndItemIndex(current_page, items_slots, items_count);
System.out.print("\nStart " + start_item + " End " + end_item);
return Arrays.asList(items).subList(start_item, end_item);
}
public synchronized static void renderList(List<ItemStack> array, Inventory inventory)
public synchronized static void renderList(List<ItemStack> array, Inventory inventory, int items_slots)
{
for (ItemStack item : array) {
System.out.println("\nitem " + item.toString());
inventory.addItem(item);
}
}
@ -40,6 +38,7 @@ public class InventoryItemsUtil
private synchronized static int getEndItemIndex(int current_page, int items_slots, int items_count)
{
int literly_end_page = (current_page + 1) * items_slots;
System.out.println("Cur page " + current_page + " Items Slots " + items_slots + " Items Count " + items_count + " Lit End Page " + literly_end_page);
if (literly_end_page < items_count) { return literly_end_page; }