diff --git a/dependency-reduced-pom.xml b/dependency-reduced-pom.xml index 27ad836..c31795f 100644 --- a/dependency-reduced-pom.xml +++ b/dependency-reduced-pom.xml @@ -4,7 +4,7 @@ net.seanomik energeticstorage EnergeticStorage - 0.7.2-SNAPSHOT + 0.7.3-SNAPSHOT clean package diff --git a/pom.xml b/pom.xml index dfd73c2..9955fe2 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ net.seanomik energeticstorage - 0.7.2-SNAPSHOT + 0.7.3-SNAPSHOT jar EnergeticStorage diff --git a/src/main/java/net/seanomik/energeticstorage/objects/ESDrive.java b/src/main/java/net/seanomik/energeticstorage/objects/ESDrive.java index db04635..915d938 100644 --- a/src/main/java/net/seanomik/energeticstorage/objects/ESDrive.java +++ b/src/main/java/net/seanomik/energeticstorage/objects/ESDrive.java @@ -123,14 +123,28 @@ public class ESDrive implements Cloneable, ConfigurationSerializable { } } - public boolean isAvailable(ItemStack item) { - return (Utils.isItemValid(item)) ? getFilledTypes() < Reference.MAX_DRIVE_TYPES && getFilledSpace() < size : getFilledSpace() < size; + public boolean canAddItem(ItemStack item) { + if (Utils.isItemValid(item)) { + // If the item is valid, we're full on types, we have the item in the drive, and we're not full on space, return true. + // else always just cascase down and check if we have space. + if (Utils.containsSimilarItem(new ArrayList<>(items.keySet()), item, true)) { + return getFilledSpace() < size; + } else { + if (getFilledTypes() < Reference.MAX_DRIVE_TYPES) { + return getFilledSpace() < size; + } + + return false; + } + } else { + return getFilledSpace() < size; + } } public boolean addItem(ItemStack item) { item = item.clone(); - if (isAvailable(item)) { + if (canAddItem(item)) { // The item is contained, then update the amount. if (Utils.containsSimilarItem(new ArrayList<>(items.keySet()), item, true)) { int amount = (int) items.values().toArray()[Utils.indexOfSimilarItem(new ArrayList<>(items.keySet()), item)] + item.getAmount(); diff --git a/src/main/java/net/seanomik/energeticstorage/objects/ESSystem.java b/src/main/java/net/seanomik/energeticstorage/objects/ESSystem.java index 6db0672..65f5f55 100644 --- a/src/main/java/net/seanomik/energeticstorage/objects/ESSystem.java +++ b/src/main/java/net/seanomik/energeticstorage/objects/ESSystem.java @@ -1,15 +1,12 @@ package net.seanomik.energeticstorage.objects; import net.seanomik.energeticstorage.utils.Utils; -import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.configuration.serialization.ConfigurationSerializable; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; import org.jetbrains.annotations.NotNull; -import java.io.Serializable; import java.util.*; public class ESSystem implements Cloneable, ConfigurationSerializable { @@ -144,7 +141,7 @@ public class ESSystem implements Cloneable, ConfigurationSerializable { public ESDrive getNextAvailableDrive() { for (ESDrive drive : esDrives) { - if (drive.isAvailable(null)) { + if (drive.canAddItem(null)) { return drive; } } @@ -155,7 +152,9 @@ public class ESSystem implements Cloneable, ConfigurationSerializable { public ESDrive findItemInAvailableDrive(ItemStack item) { for (ESDrive drive : esDrives) { for (ItemStack itemStack : drive.getItems().keySet()) { - if (item.isSimilar(itemStack) && drive.isAvailable(item)) { + // We don't need to check if we can add the item since if its + // added, then i + if (item.isSimilar(itemStack) && drive.canAddItem(null)) { return drive; } } @@ -185,7 +184,7 @@ public class ESSystem implements Cloneable, ConfigurationSerializable { public boolean addItem(ItemStack item) { ESDrive drive = findItemInAvailableDrive(item); - // If we failed to find the item in the next available drive, then find another drive. + // If we failed to find the item in the next available drive, then find another drive to add it to. if (drive == null) { drive = getNextAvailableDrive();