Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,15 @@ public Material getTerminalBlockType() {
public boolean isNetworkContainerBlock(Material material) {
return material == Material.CHEST
|| material == Material.TRAPPED_CHEST
|| material == Material.COPPER_CHEST
|| material == Material.BARREL
|| material == Material.EXPOSED_COPPER_CHEST
|| material == Material.WEATHERED_COPPER_CHEST
|| material == Material.OXIDIZED_COPPER_CHEST
|| material == Material.WAXED_COPPER_CHEST
|| material == Material.WAXED_EXPOSED_COPPER_CHEST
|| material == Material.WAXED_WEATHERED_COPPER_CHEST
|| material == Material.WAXED_OXIDIZED_COPPER_CHEST
|| material == getTerminalBlockType();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.block.Chest;
import org.bukkit.block.Container;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
Expand Down Expand Up @@ -772,11 +773,11 @@ public synchronized int purgeAllNetworksForSeasonReset() {

private void clearNetworkChestContents(Network network) {
for (Location location : network.getChestLocations()) {
if (!(location.getBlock().getState() instanceof Chest chest)) {
if (!(location.getBlock().getState() instanceof Container container)) {
continue;
}
chest.getInventory().clear();
chest.update();
container.getInventory().clear();
container.update();
}
}

Expand Down
22 changes: 9 additions & 13 deletions src/main/java/com/dermoha/networkstorage/storage/Network.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.dermoha.networkstorage.stats.PlayerStat;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Chest;
import org.bukkit.block.Container;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
Expand Down Expand Up @@ -190,9 +190,8 @@ public Map<ItemStack, Integer> getNetworkItems() {

Map<ItemStack, Integer> networkItems = new HashMap<>();
for (Location chestLoc : chestLocations) {
if (chestLoc.getBlock().getState() instanceof Chest) {
Chest chest = (Chest) chestLoc.getBlock().getState();
for (ItemStack item : chest.getInventory().getContents()) {
if (chestLoc.getBlock().getState() instanceof Container container) {
for (ItemStack item : container.getInventory().getContents()) {
if (item != null && item.getType() != Material.AIR) {
addToNetworkMap(networkItems, item);
}
Expand Down Expand Up @@ -228,9 +227,8 @@ public ItemStack removeFromNetwork(ItemStack itemToRemove, int amount) {

for (Location chestLoc : chestLocations) {
if (remaining <= 0) break;
if (chestLoc.getBlock().getState() instanceof Chest) {
Chest chest = (Chest) chestLoc.getBlock().getState();
Inventory inv = chest.getInventory();
if (chestLoc.getBlock().getState() instanceof Container container) {
Inventory inv = container.getInventory();
for (int i = 0; i < inv.getSize() && remaining > 0; i++) {
ItemStack item = inv.getItem(i);
if (item != null && item.isSimilar(itemToRemove)) {
Expand All @@ -256,9 +254,8 @@ public ItemStack addToNetwork(ItemStack itemToAdd) {
ItemStack remaining = itemToAdd.clone();
for (Location chestLoc : chestLocations) {
if (remaining.getAmount() <= 0) break;
if (chestLoc.getBlock().getState() instanceof Chest) {
Chest chest = (Chest) chestLoc.getBlock().getState();
HashMap<Integer, ItemStack> result = chest.getInventory().addItem(remaining);
if (chestLoc.getBlock().getState() instanceof Container container) {
HashMap<Integer, ItemStack> result = container.getInventory().addItem(remaining);
if (result.isEmpty()) {
remaining = null;
break;
Expand All @@ -275,9 +272,8 @@ public double getCapacityPercent() {
int totalSlots = 0;
int usedSlots = 0;
for (Location chestLoc : chestLocations) {
if (chestLoc.getBlock().getState() instanceof Chest) {
Chest chest = (Chest) chestLoc.getBlock().getState();
Inventory inv = chest.getInventory();
if (chestLoc.getBlock().getState() instanceof Container container) {
Inventory inv = container.getInventory();
totalSlots += inv.getSize();
for (ItemStack item : inv.getContents()) {
if (item != null && item.getType() != Material.AIR) {
Expand Down