|
@@ -1,24 +1,42 @@
|
|
|
package me.lethunderhawk.storeMore.abstraction.item;
|
|
package me.lethunderhawk.storeMore.abstraction.item;
|
|
|
|
|
|
|
|
|
|
+import me.lethunderhawk.storeMore.itemManipulation.ItemData;
|
|
|
import me.lethunderhawk.storeMore.itemManipulation.ItemOptions;
|
|
import me.lethunderhawk.storeMore.itemManipulation.ItemOptions;
|
|
|
import me.lethunderhawk.storeMore.itemManipulation.LoreDesigner;
|
|
import me.lethunderhawk.storeMore.itemManipulation.LoreDesigner;
|
|
|
|
|
+import me.lethunderhawk.storeMore.itemManipulation.StringIntPair;
|
|
|
|
|
+import net.kyori.adventure.text.Component;
|
|
|
import net.kyori.adventure.text.format.NamedTextColor;
|
|
import net.kyori.adventure.text.format.NamedTextColor;
|
|
|
import org.bukkit.Material;
|
|
import org.bukkit.Material;
|
|
|
|
|
+import org.bukkit.entity.Item;
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
import org.bukkit.inventory.meta.ItemMeta;
|
|
import org.bukkit.inventory.meta.ItemMeta;
|
|
|
|
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+
|
|
|
public final class ItemStorage {
|
|
public final class ItemStorage {
|
|
|
|
|
+ public static final int maxStorageTypes = 7;
|
|
|
|
|
+ public static final int typeBytesUsage = 8;
|
|
|
|
|
+ public final ItemStoragePair[] pairs = new ItemStoragePair[maxStorageTypes];
|
|
|
private final Material baseMaterial;
|
|
private final Material baseMaterial;
|
|
|
private final CAPACITY max_capacity;
|
|
private final CAPACITY max_capacity;
|
|
|
- public final ItemStoragePair[] pairs = new ItemStoragePair[7];
|
|
|
|
|
|
|
|
|
|
public ItemStorage(Material basematerial, CAPACITY max_capacity) {
|
|
public ItemStorage(Material basematerial, CAPACITY max_capacity) {
|
|
|
this.baseMaterial = basematerial;
|
|
this.baseMaterial = basematerial;
|
|
|
this.max_capacity = max_capacity;
|
|
this.max_capacity = max_capacity;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public ItemStorage(Material basematerial, CAPACITY max_capacity, List<ItemStoragePair> pairs) {
|
|
|
|
|
+ this.baseMaterial = basematerial;
|
|
|
|
|
+ this.max_capacity = max_capacity;
|
|
|
|
|
+ for(int i = 0; i < pairs.toArray().length; i++){
|
|
|
|
|
+ if(pairs.get(i) == null || i >= maxStorageTypes) continue;
|
|
|
|
|
+ this.pairs[i] = pairs.get(i);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Deprecated
|
|
@Deprecated
|
|
|
- public ItemStorage withStorage(ItemStoragePair pair){
|
|
|
|
|
|
|
+ public ItemStorage withFirstStorageSlot(ItemStoragePair pair){
|
|
|
pairs[0] = pair;
|
|
pairs[0] = pair;
|
|
|
return this;
|
|
return this;
|
|
|
}
|
|
}
|
|
@@ -27,6 +45,7 @@ public final class ItemStorage {
|
|
|
int cummulative = 0;
|
|
int cummulative = 0;
|
|
|
for(ItemStoragePair pair : pairs){
|
|
for(ItemStoragePair pair : pairs){
|
|
|
if(pair == null) continue;
|
|
if(pair == null) continue;
|
|
|
|
|
+ cummulative += typeBytesUsage;
|
|
|
cummulative += pair.getAmount();
|
|
cummulative += pair.getAmount();
|
|
|
}
|
|
}
|
|
|
return cummulative;
|
|
return cummulative;
|
|
@@ -37,33 +56,61 @@ public final class ItemStorage {
|
|
|
ItemOptions options = new ItemOptions(baseMaterial);
|
|
ItemOptions options = new ItemOptions(baseMaterial);
|
|
|
options.setAmount(1)
|
|
options.setAmount(1)
|
|
|
.setName(LoreDesigner.createSingle("<gold>" + max_capacity.getName() + " Item Cell "))
|
|
.setName(LoreDesigner.createSingle("<gold>" + max_capacity.getName() + " Item Cell "))
|
|
|
- .setLore(LoreDesigner.createLore("Current usage: " + getCurrentUsage() + "/" + max_capacity.getCap() + "<br>Currently holding: <br><br>", NamedTextColor.GOLD))
|
|
|
|
|
.setMaxStackSize(1)
|
|
.setMaxStackSize(1)
|
|
|
.setItemStorage(this);
|
|
.setItemStorage(this);
|
|
|
|
|
+
|
|
|
return options;
|
|
return options;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public ItemStack buildItem(){
|
|
public ItemStack buildItem(){
|
|
|
ItemOptions options = getItemOptions();
|
|
ItemOptions options = getItemOptions();
|
|
|
|
|
+ options.setLore(buildLore());
|
|
|
|
|
+ return options.buildItemStack();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public List<Component> buildLore(){
|
|
|
|
|
+ List<Component> lore = new ArrayList<>(LoreDesigner.createLore("Current usage: " + getCurrentUsage() + "/" + max_capacity.getCap() + "<br>Currently holding: <br><br>", NamedTextColor.GOLD));
|
|
|
|
|
|
|
|
for(ItemStoragePair pair : pairs){
|
|
for(ItemStoragePair pair : pairs){
|
|
|
- options.getLore().add(
|
|
|
|
|
- LoreDesigner.createSingle("- " + (pair == null ? "Empty" : pair.getMaterial().toString() + " x" + pair.getAmount()))
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ lore.add(
|
|
|
|
|
+ LoreDesigner.createSingle("- " + (pair == null ? "Empty" : pair.getMaterial().toString() + " x" + pair.getAmount())
|
|
|
|
|
+ ));
|
|
|
}
|
|
}
|
|
|
|
|
+ return lore;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- return options.buildItemStack();
|
|
|
|
|
|
|
+ public String getMaxCapacity() {
|
|
|
|
|
+ return max_capacity.toString();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public void writeIntoItem(ItemStack itemStack){
|
|
|
|
|
- ItemOptions options = getItemOptions();
|
|
|
|
|
|
|
+ public static CAPACITY getCapacity(ItemStack item){
|
|
|
|
|
+ return CAPACITY.valueOf(ItemData.getString(item, ItemOptions.storage_size, CAPACITY.ONE_K.toString()));
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- for(ItemStoragePair pair : pairs){
|
|
|
|
|
- options.getLore().add(
|
|
|
|
|
- LoreDesigner.createSingle("- " + (pair == null ? "Empty" : pair.getMaterial().toString() + " x" + pair.getAmount()))
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ public static int getCurrentUsage(ItemStack item){
|
|
|
|
|
+ List<StringIntPair> pairs = ItemData.getIntsStartingWith(item, ItemOptions.storagePrefix);
|
|
|
|
|
+ int usage = 0;
|
|
|
|
|
+ for(StringIntPair pair : pairs){
|
|
|
|
|
+ usage += typeBytesUsage;
|
|
|
|
|
+ usage += pair.amount();
|
|
|
}
|
|
}
|
|
|
- ItemMeta meta = options.buildItemStack().getItemMeta();
|
|
|
|
|
- itemStack.setItemMeta(meta);
|
|
|
|
|
|
|
+ return usage;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public static List<ItemStoragePair> getStoredItems(ItemStack item){
|
|
|
|
|
+ List<StringIntPair> stringPairs = ItemData.getIntsStartingWith(item, ItemOptions.storagePrefix);
|
|
|
|
|
+ List<ItemStoragePair> pairs = new ArrayList<>();
|
|
|
|
|
+ if(stringPairs == null) return pairs;
|
|
|
|
|
+ for(StringIntPair pair : stringPairs){
|
|
|
|
|
+ ItemStoragePair realPair = new ItemStoragePair(Material.valueOf(pair.item().replace(ItemOptions.storagePrefix, "").toUpperCase()), pair.amount());
|
|
|
|
|
+ pairs.add(realPair);
|
|
|
|
|
+ }
|
|
|
|
|
+ return pairs;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public static ItemStorage getStorageFrom(ItemStack item){
|
|
|
|
|
+ CAPACITY capacity = getCapacity(item);
|
|
|
|
|
+ List<ItemStoragePair> pairs = getStoredItems(item);
|
|
|
|
|
+ return new ItemStorage(item.getType(), capacity, pairs);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|