geforkt von Mirrors/Paper
Updated CraftInventory to make use of the proper generics in the Inventory interface.
Updated loads of return values to now return actual Craft* objects. Added a shitton of constructors to CraftItemStack so you can now finally properly make your ItemStacks.
Dieser Commit ist enthalten in:
Ursprung
0c492912de
Commit
80a59397cb
@ -84,12 +84,12 @@ public class CraftInventory implements org.bukkit.inventory.Inventory {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashMap<Integer, ItemStack> all(int materialId) {
|
public HashMap<Integer, CraftItemStack> all(int materialId) {
|
||||||
HashMap<Integer, ItemStack> slots = new HashMap<Integer, ItemStack>();
|
HashMap<Integer, CraftItemStack> slots = new HashMap<Integer, CraftItemStack>();
|
||||||
|
|
||||||
ItemStack[] inventory = getContents();
|
CraftItemStack[] inventory = getContents();
|
||||||
for (int i = 0; i < inventory.length; i++) {
|
for (int i = 0; i < inventory.length; i++) {
|
||||||
ItemStack item = inventory[i];
|
CraftItemStack item = inventory[i];
|
||||||
if (item.getTypeId() == materialId) {
|
if (item.getTypeId() == materialId) {
|
||||||
slots.put( i, item );
|
slots.put( i, item );
|
||||||
}
|
}
|
||||||
@ -97,24 +97,24 @@ public class CraftInventory implements org.bukkit.inventory.Inventory {
|
|||||||
return slots;
|
return slots;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashMap<Integer, ItemStack> all(Material material) {
|
public HashMap<Integer, CraftItemStack> all(Material material) {
|
||||||
return all(material.getId());
|
return all(material.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashMap<Integer, ItemStack> all(ItemStack item) {
|
public HashMap<Integer, CraftItemStack> all(ItemStack item) {
|
||||||
HashMap<Integer, ItemStack> slots = new HashMap<Integer, ItemStack>();
|
HashMap<Integer, CraftItemStack> slots = new HashMap<Integer, CraftItemStack>();
|
||||||
|
|
||||||
ItemStack[] inventory = getContents();
|
CraftItemStack[] inventory = getContents();
|
||||||
for (int i = 0; i < inventory.length; i++) {
|
for (int i = 0; i < inventory.length; i++) {
|
||||||
if (item.equals(inventory[i])) {
|
if (item.equals(inventory[i])) {
|
||||||
slots.put( i, item );
|
slots.put( i, inventory[i] );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return slots;
|
return slots;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int first(int materialId) {
|
public int first(int materialId) {
|
||||||
ItemStack[] inventory = getContents();
|
CraftItemStack[] inventory = getContents();
|
||||||
for (int i = 0; i < inventory.length; i++) {
|
for (int i = 0; i < inventory.length; i++) {
|
||||||
if (inventory[i].getTypeId() == materialId) {
|
if (inventory[i].getTypeId() == materialId) {
|
||||||
return i;
|
return i;
|
||||||
@ -128,7 +128,7 @@ public class CraftInventory implements org.bukkit.inventory.Inventory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int first(ItemStack item) {
|
public int first(ItemStack item) {
|
||||||
ItemStack[] inventory = getContents();
|
CraftItemStack[] inventory = getContents();
|
||||||
for (int i = 0; i < inventory.length; i++) {
|
for (int i = 0; i < inventory.length; i++) {
|
||||||
if (item.equals(inventory[i])) {
|
if (item.equals(inventory[i])) {
|
||||||
return i;
|
return i;
|
||||||
@ -142,9 +142,9 @@ public class CraftInventory implements org.bukkit.inventory.Inventory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int firstPartial(int materialId) {
|
public int firstPartial(int materialId) {
|
||||||
ItemStack[] inventory = getContents();
|
CraftItemStack[] inventory = getContents();
|
||||||
for (int i = 0; i < inventory.length; i++) {
|
for (int i = 0; i < inventory.length; i++) {
|
||||||
ItemStack item = inventory[i];
|
CraftItemStack item = inventory[i];
|
||||||
if (item != null && item.getTypeId() == materialId && item.getAmount() < item.getMaxStackSize()) {
|
if (item != null && item.getTypeId() == materialId && item.getAmount() < item.getMaxStackSize()) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
@ -161,7 +161,7 @@ public class CraftInventory implements org.bukkit.inventory.Inventory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public HashMap<Integer, ItemStack> addItem(ItemStack... items) {
|
public HashMap<Integer, ItemStack> addItem(ItemStack... items) {
|
||||||
HashMap<Integer,ItemStack> leftover = new HashMap<Integer,ItemStack>();
|
HashMap<Integer, ItemStack> leftover = new HashMap<Integer, ItemStack>();
|
||||||
|
|
||||||
/* TODO: some optimization
|
/* TODO: some optimization
|
||||||
* - Create a 'firstPartial' with a 'fromIndex'
|
* - Create a 'firstPartial' with a 'fromIndex'
|
||||||
@ -187,7 +187,7 @@ public class CraftInventory implements org.bukkit.inventory.Inventory {
|
|||||||
} else {
|
} else {
|
||||||
// More than a single stack!
|
// More than a single stack!
|
||||||
if (item.getAmount() > getMaxItemStack()) {
|
if (item.getAmount() > getMaxItemStack()) {
|
||||||
setItem( firstFree, new ItemStack(item.getTypeId(), getMaxItemStack()));
|
setItem( firstFree, new CraftItemStack(item.getTypeId(), getMaxItemStack()));
|
||||||
item.setAmount(item.getAmount() - getMaxItemStack());
|
item.setAmount(item.getAmount() - getMaxItemStack());
|
||||||
} else {
|
} else {
|
||||||
// Just store it
|
// Just store it
|
||||||
@ -197,7 +197,7 @@ public class CraftInventory implements org.bukkit.inventory.Inventory {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// So, apparently it might only partially fit, well lets do just that
|
// So, apparently it might only partially fit, well lets do just that
|
||||||
ItemStack partialItem = getItem(firstPartial);
|
CraftItemStack partialItem = getItem(firstPartial);
|
||||||
|
|
||||||
int amount = item.getAmount();
|
int amount = item.getAmount();
|
||||||
int partialAmount = partialItem.getAmount();
|
int partialAmount = partialItem.getAmount();
|
||||||
|
@ -62,9 +62,9 @@ public class CraftInventoryPlayer extends CraftInventory implements PlayerInvent
|
|||||||
setItem( getSize() + 3, boots );
|
setItem( getSize() + 3, boots );
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack[] getArmorContents() {
|
public CraftItemStack[] getArmorContents() {
|
||||||
net.minecraft.server.ItemStack[] mcItems = getInventory().getArmorContents();
|
net.minecraft.server.ItemStack[] mcItems = getInventory().getArmorContents();
|
||||||
ItemStack[] ret = new ItemStack[mcItems.length];
|
CraftItemStack[] ret = new CraftItemStack[mcItems.length];
|
||||||
|
|
||||||
for (int i = 0; i < mcItems.length; i++ ) {
|
for (int i = 0; i < mcItems.length; i++ ) {
|
||||||
ret[i] = new CraftItemStack(mcItems[i]);
|
ret[i] = new CraftItemStack(mcItems[i]);
|
||||||
|
@ -7,11 +7,47 @@ public class CraftItemStack extends ItemStack {
|
|||||||
protected net.minecraft.server.ItemStack item;
|
protected net.minecraft.server.ItemStack item;
|
||||||
|
|
||||||
public CraftItemStack(net.minecraft.server.ItemStack item) {
|
public CraftItemStack(net.minecraft.server.ItemStack item) {
|
||||||
super(item != null ? item.c : 0, item != null ? item.a : 0,
|
super(
|
||||||
(byte)(item != null ? item.d : 0));
|
item != null ? item.c : 0,
|
||||||
|
item != null ? item.a : 0,
|
||||||
|
(byte)(item != null ? item.d : 0)
|
||||||
|
);
|
||||||
this.item = item;
|
this.item = item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 'Overwritten' constructors from ItemStack, yay for Java sucking */
|
||||||
|
public CraftItemStack(final int type) {
|
||||||
|
this(type, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CraftItemStack(final Material type) {
|
||||||
|
this(type, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CraftItemStack(final int type, final int amount) {
|
||||||
|
this(type, amount, (byte) 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CraftItemStack(final Material type, final int amount) {
|
||||||
|
this(type.getId(), amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CraftItemStack(final int type, final int amount, final byte damage) {
|
||||||
|
this(type, amount, damage, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CraftItemStack(final Material type, final int amount, final byte damage) {
|
||||||
|
this(type.getId(), amount, damage);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CraftItemStack(final Material type, final int amount, final byte damage, final Byte data) {
|
||||||
|
this(type.getId(), amount, damage, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CraftItemStack(int type, int amount, byte damage, Byte data) {
|
||||||
|
this(new net.minecraft.server.ItemStack(type, amount, data != null ? data : damage));
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Unsure if we have to sync before each of these calls the values in 'item'
|
* Unsure if we have to sync before each of these calls the values in 'item'
|
||||||
* are all public.
|
* are all public.
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren