blob: 70ea942b1896086db49de149977ebf0a20c410e9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
package org.bukkit.craftbukkit.inventory;
import net.minecraft.server.PlayerInventory;
import org.bukkit.entity.HumanEntity;
import org.bukkit.inventory.ItemStack;
public class CraftInventoryPlayer extends CraftInventory implements org.bukkit.inventory.PlayerInventory {
public CraftInventoryPlayer(net.minecraft.server.PlayerInventory inventory) {
super(inventory);
}
@Override
public PlayerInventory getInventory() {
return (PlayerInventory) inventory;
}
@Override
public int getSize() {
return super.getSize() - 4;
}
public ItemStack getItemInHand() {
return new CraftItemStack(getInventory().getItemInHand());
}
public void setItemInHand(ItemStack stack) {
setItem(getHeldItemSlot(), stack);
}
public int getHeldItemSlot() {
return getInventory().itemInHandIndex;
}
public ItemStack getHelmet() {
return getItem(getSize() + 3);
}
public ItemStack getChestplate() {
return getItem(getSize() + 2);
}
public ItemStack getLeggings() {
return getItem(getSize() + 1);
}
public ItemStack getBoots() {
return getItem(getSize() + 0);
}
public void setHelmet(ItemStack helmet) {
setItem(getSize() + 3, helmet);
}
public void setChestplate(ItemStack chestplate) {
setItem(getSize() + 2, chestplate);
}
public void setLeggings(ItemStack leggings) {
setItem(getSize() + 1, leggings);
}
public void setBoots(ItemStack boots) {
setItem(getSize() + 0, boots);
}
public ItemStack[] getArmorContents() {
net.minecraft.server.ItemStack[] mcItems = getInventory().getArmorContents();
ItemStack[] ret = new ItemStack[mcItems.length];
for (int i = 0; i < mcItems.length; i++) {
ret[i] = new CraftItemStack(mcItems[i]);
}
return ret;
}
public void setArmorContents(ItemStack[] items) {
int cnt = getSize();
if (items == null) {
items = new ItemStack[4];
}
for (ItemStack item : items) {
if (item == null || item.getTypeId() == 0) {
clear(cnt++);
} else {
setItem(cnt++, item);
}
}
}
public int clear(int id, int data) {
int count = 0;
ItemStack[] items = getContents();
ItemStack[] armor = getArmorContents();
int armorSlot = getSize();
for (int i = 0; i < items.length; i++) {
ItemStack item = items[i];
if (item == null) continue;
if (id > -1 && item.getTypeId() != id) continue;
if (data > -1 && item.getData().getData() != data) continue;
count += item.getAmount();
setItem(i, null);
}
for (ItemStack item : armor) {
if (item == null) continue;
if (id > -1 && item.getTypeId() != id) continue;
if (data > -1 && item.getData().getData() != data) continue;
count += item.getAmount();
setItem(armorSlot++, null);
}
return count;
}
@Override
public HumanEntity getHolder() {
return (HumanEntity) inventory.getOwner();
}
}
|