Skip to content

Instantly share code, notes, and snippets.

@marvin-bitterlich
Created August 24, 2011 06:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marvin-bitterlich/1167434 to your computer and use it in GitHub Desktop.
Save marvin-bitterlich/1167434 to your computer and use it in GitHub Desktop.
Problem-Code
package en.trudan.ConstructionSites.Data;
import java.io.Serializable;
import org.bukkit.Material;
public class Blockdata implements Serializable{
private static final long serialVersionUID = -7765686518366269441L;
private int blockvalue = 0;
private Byte data = 0x0000;
public Blockdata(){
}
public Blockdata(int blockvalue){
this.blockvalue = blockvalue;
}
public Blockdata(int blockvalue, byte data){
this.blockvalue = blockvalue;
this.data = data;
}
public Blockdata(Material material){
this.blockvalue = material.getId();
}
public Blockdata(Material material, byte data){
this.blockvalue = material.getId();
this.data = data;
}
public void setBlockvalue(int blockvalue) {
this.blockvalue = blockvalue;
}
public int getBlockvalue() {
return blockvalue;
}
public void setData(byte data) {
this.data = data;
}
public byte getData() {
return data;
}
}
package en.trudan.ConstructionSites.Data;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Set;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
public class MaterialStorage implements Serializable {
private static final long serialVersionUID = -2568572539544142880L;
private static HashMap<Blockdata, Integer> ms = null;
@SuppressWarnings("unused")
private boolean inuse = false;
public MaterialStorage() {
ms = new HashMap<Blockdata, Integer>();
}
public void addMaterial(ItemStack is){
if(is != null){
if(is.getData() == null){
if (ms.containsKey(new Blockdata(is.getTypeId()))) {
ms.put(new Blockdata(is.getTypeId()),
ms.get(new Blockdata(is.getTypeId())) + is.getAmount());
}else{
ms.put(new Blockdata(is.getTypeId()),
is.getAmount());
}
}else{
if (ms.containsKey(new Blockdata(is.getTypeId(), is.getData().getData()))) {
ms.put(new Blockdata(is.getTypeId(), is.getData().getData()),
ms.get(new Blockdata(is.getTypeId(), is.getData().getData())) + is.getAmount());
}else{
ms.put(new Blockdata(is.getTypeId(), is.getData().getData()),
is.getAmount());
}
}
}
}
public ItemStack[] getChest() {
ItemStack[] chest = null;
//if(!inuse){
int i = 0;
Set<Blockdata> items = ms.keySet();
chest = new ItemStack[54];
for (Blockdata blockdata : items) {
int amount = ms.get(blockdata);
System.out.println(amount + "|" + blockdata.getBlockvalue());
while (amount != 0) {
if (i < 54) {
if (amount >= 64) {
amount -= 64;
ItemStack is = new ItemStack(blockdata.getBlockvalue(),
64, blockdata.getData(), blockdata.getData());
chest = is;
i++;
} else if (amount >= 1 && amount <= 64) {
ItemStack is = new ItemStack(blockdata.getBlockvalue(),
amount, blockdata.getData(), blockdata.getData());
chest = is;
amount = 0;
i++;
}
}
}
//}
return chest;
}
return chest;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment