001 002 public class PlayerInventory extends ItemArray<ji> implements Inventory { 003 private final fy user; 004 005 public PlayerInventory(Player player) { 006 super(player.getUser().an); 007 user = player.getUser(); 008 } 009 010 public void giveItem(int itemId, int amount) { 011 if (amount == -1) { 012 int emptySlot = getEmptySlot(); 013 if (emptySlot == -1) { 014 user.getPlayer().giveItemDrop(itemId, -1); 015 } else { 016 addItem(new Item(itemId, 255, emptySlot)); 017 } 018 return; 019 } 020 021 int temp = amount; 022 do { 023 int amountToAdd = temp >= 64 ? 64 : temp; 024 025 if (hasItem(itemId, 1, 63)) { 026 Item i = getItemFromId(itemId, 63); 027 if (i != null) { 028 if (amountToAdd == 64) { 029 int a = amountToAdd - i.getAmount(); 030 i.setAmount(64); 031 temp -= a; 032 } else if (amountToAdd + i.getAmount() > 64) { 033 int a = amountToAdd + i.getAmount() - 64; 034 i.setAmount(64); 035 temp = a; 036 } else if (amountToAdd + i.getAmount() <= 64) { 037 i.setAmount(amountToAdd + i.getAmount()); 038 temp = 0; 039 } 040 addItem(i); 041 continue; 042 } 043 } 044 045 int emptySlot = getEmptySlot(); 046 if (emptySlot == -1) 047 { 048 break; 049 } 050 051 addItem(new Item(itemId, amountToAdd, emptySlot)); 052 temp -= 64; 053 } while (temp > 0); 054 055 if (temp > 0) { 056 user.getPlayer().giveItemDrop(itemId, temp); 057 } 058 } 059 060 public void update() { 061 user.k(); 062 } 063 064 /** 065 * Returns a String value representing this PlayerInventory 066 * 067 * @return String representation of this PlayerInventory 068 */ 069 @Override 070 public String toString() { 071 return String.format("PlayerInventory[user=%s]", user.getPlayer()); 072 } 073 074 /** 075 * Returns the owner of this PlayerInventory 076 * 077 * @return Player 078 */ 079 public Player getPlayer() { 080 return user.getPlayer(); 081 } 082 083 public String getName() { 084 return container.getName(); 085 } 086 087 public void setName(String value) { 088 container.setName(value); 089 } 090 }