Permalink
Browse files

Prevent CraftBook putting shulker boxes inside shulker boxes

  • Loading branch information...
me4502 committed Aug 30, 2018
1 parent 785c083 commit 93cc92cd6606669d51d96501de142b8119b89065
@@ -3,6 +3,7 @@
import org.bukkit.block.Block;
import org.bukkit.block.BrewingStand;
import org.bukkit.block.Furnace;
import org.bukkit.block.ShulkerBox;
import org.bukkit.entity.Player;
import org.bukkit.inventory.BrewerInventory;
import org.bukkit.inventory.EquipmentSlot;
@@ -15,6 +16,7 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.function.IntFunction;
/**
* Class for utilities that include adding items to a furnace based on if it is a fuel or not, and adding items to a chest. Also will include methdos for checking contents and removing.
@@ -28,7 +30,7 @@
* @param stacks The stacks to add to the inventory.
* @return The stacks that could not be added.
*/
public static ArrayList<ItemStack> addItemsToInventory(InventoryHolder container, ItemStack ... stacks) {
public static List<ItemStack> addItemsToInventory(InventoryHolder container, ItemStack ... stacks) {
return addItemsToInventory(container, true, stacks);
}
@@ -39,14 +41,19 @@
* @param stacks The stacks to add to the inventory.
* @return The stacks that could not be added.
*/
public static ArrayList<ItemStack> addItemsToInventory(InventoryHolder container, boolean update, ItemStack ... stacks) {
public static List<ItemStack> addItemsToInventory(InventoryHolder container, boolean update, ItemStack ... stacks) {
if(container instanceof Furnace) {
return addItemsToFurnace((Furnace) container, stacks);
} else if(container instanceof BrewingStand) {
return addItemsToBrewingStand((BrewingStand) container, stacks);
} else { //Basic inventories like chests, dispensers, storage carts, etc.
ArrayList<ItemStack> leftovers = new ArrayList<>(container.getInventory().addItem(stacks).values());
List<ItemStack> leftovers = new ArrayList<>();
if (container instanceof ShulkerBox) {
Arrays.stream(stacks).filter(item -> ItemUtil.isShulkerBox(item.getType())).forEach(leftovers::add);
stacks = Arrays.stream(stacks).filter(item -> !ItemUtil.isShulkerBox(item.getType())).toArray(ItemStack[]::new);
}
leftovers.addAll(container.getInventory().addItem(stacks).values());
//if(container instanceof BlockState && update)
// ((BlockState) container).update();
return leftovers;
@@ -60,9 +67,9 @@
* @param stacks The stacks to add to the inventory.
* @return The stacks that could not be added.
*/
public static ArrayList<ItemStack> addItemsToFurnace(Furnace furnace, ItemStack ... stacks) {
public static List<ItemStack> addItemsToFurnace(Furnace furnace, ItemStack ... stacks) {
ArrayList<ItemStack> leftovers = new ArrayList<>();
List<ItemStack> leftovers = new ArrayList<>();
for(ItemStack stack : stacks) {
@@ -97,9 +104,9 @@
* @param stacks The stacks to add to the inventory.
* @return The stacks that could not be added.
*/
public static ArrayList<ItemStack> addItemsToBrewingStand(BrewingStand brewingStand, ItemStack ... stacks) {
public static List<ItemStack> addItemsToBrewingStand(BrewingStand brewingStand, ItemStack ... stacks) {
ArrayList<ItemStack> leftovers = new ArrayList<>();
List<ItemStack> leftovers = new ArrayList<>();
for(ItemStack stack : stacks) {
@@ -1060,4 +1060,29 @@ public static DyeColor getStainedColor(Material material) {
return DyeColor.WHITE;
}
}
public static boolean isShulkerBox(Material type) {
switch (type) {
case SHULKER_BOX:
case BLACK_SHULKER_BOX:
case BLUE_SHULKER_BOX:
case BROWN_SHULKER_BOX:
case CYAN_SHULKER_BOX:
case GRAY_SHULKER_BOX:
case GREEN_SHULKER_BOX:
case LIGHT_BLUE_SHULKER_BOX:
case LIGHT_GRAY_SHULKER_BOX:
case LIME_SHULKER_BOX:
case MAGENTA_SHULKER_BOX:
case ORANGE_SHULKER_BOX:
case PINK_SHULKER_BOX:
case PURPLE_SHULKER_BOX:
case RED_SHULKER_BOX:
case WHITE_SHULKER_BOX:
case YELLOW_SHULKER_BOX:
return true;
default:
return false;
}
}
}

0 comments on commit 93cc92c

Please sign in to comment.