From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: William Blake Galbreath <blake.galbreath@gmail.com>
Date: Thu, 23 May 2019 21:50:37 -0500
Subject: [PATCH] Barrels and enderchests 6 rows


diff --git a/src/main/java/net/minecraft/world/inventory/ChestMenu.java b/src/main/java/net/minecraft/world/inventory/ChestMenu.java
index e9d9245f7efaaeefc8f107b8016a462ce173816a..56dcc1b6ceaad998be62e3b8c125e8f5e833e4c0 100644
--- a/src/main/java/net/minecraft/world/inventory/ChestMenu.java
+++ b/src/main/java/net/minecraft/world/inventory/ChestMenu.java
@@ -67,10 +67,30 @@ public class ChestMenu extends AbstractContainerMenu {
         return new ChestMenu(MenuType.GENERIC_9x6, syncId, playerInventory, 6);
     }
 
+    // Purpur start
+    public static ChestMenu oneRow(int syncId, Inventory playerInventory, Container inventory) {
+        return new ChestMenu(MenuType.GENERIC_9x1, syncId, playerInventory, inventory, 1);
+    }
+
+    public static ChestMenu twoRows(int syncId, Inventory playerInventory, Container inventory) {
+        return new ChestMenu(MenuType.GENERIC_9x2, syncId, playerInventory, inventory, 2);
+    }
+    // Purpur end
+
     public static ChestMenu threeRows(int syncId, Inventory playerInventory, Container inventory) {
         return new ChestMenu(MenuType.GENERIC_9x3, syncId, playerInventory, inventory, 3);
     }
 
+    // Purpur start
+    public static ChestMenu fourRows(int syncId, Inventory playerInventory, Container inventory) {
+        return new ChestMenu(MenuType.GENERIC_9x4, syncId, playerInventory, inventory, 4);
+    }
+
+    public static ChestMenu fiveRows(int syncId, Inventory playerInventory, Container inventory) {
+        return new ChestMenu(MenuType.GENERIC_9x5, syncId, playerInventory, inventory, 5);
+    }
+    // Purpur end
+
     public static ChestMenu sixRows(int syncId, Inventory playerInventory, Container inventory) {
         return new ChestMenu(MenuType.GENERIC_9x6, syncId, playerInventory, inventory, 6);
     }
diff --git a/src/main/java/net/minecraft/world/inventory/PlayerEnderChestContainer.java b/src/main/java/net/minecraft/world/inventory/PlayerEnderChestContainer.java
index 59acb1aab21e2dce0f046942f124b50ac1cb8d0f..a26cb4e4e4e23a06c970ea3c42c1060108708568 100644
--- a/src/main/java/net/minecraft/world/inventory/PlayerEnderChestContainer.java
+++ b/src/main/java/net/minecraft/world/inventory/PlayerEnderChestContainer.java
@@ -29,11 +29,34 @@ public class PlayerEnderChestContainer extends SimpleContainer {
     }
 
     public PlayerEnderChestContainer(Player owner) {
-        super(27);
+        super(net.pl3x.purpur.PurpurConfig.enderChestSixRows ? 54 : 27); // Purpur
         this.owner = owner;
         // CraftBukkit end
     }
 
+    // Purpur start
+    @Override
+    public int getContainerSize() {
+        if (net.pl3x.purpur.PurpurConfig.enderChestSixRows && net.pl3x.purpur.PurpurConfig.enderChestPermissionRows && owner != null && owner.getGameProfile() != null) {
+            org.bukkit.craftbukkit.entity.CraftHumanEntity bukkit = owner.getBukkitEntity();
+            if (bukkit.hasPermission("purpur.enderchest.rows.six")) {
+                return 54;
+            } else if (bukkit.hasPermission("purpur.enderchest.rows.five")) {
+                return 45;
+            } else if (bukkit.hasPermission("purpur.enderchest.rows.four")) {
+                return 36;
+            } else if (bukkit.hasPermission("purpur.enderchest.rows.three")) {
+                return 27;
+            } else if (bukkit.hasPermission("purpur.enderchest.rows.two")) {
+                return 18;
+            } else if (bukkit.hasPermission("purpur.enderchest.rows.one")) {
+                return 9;
+            }
+        }
+        return super.getContainerSize();
+    }
+    // Purpur end
+
     public void setActiveChest(EnderChestBlockEntity blockEntity) {
         this.activeChest = blockEntity;
     }
diff --git a/src/main/java/net/minecraft/world/level/block/EnderChestBlock.java b/src/main/java/net/minecraft/world/level/block/EnderChestBlock.java
index 7e45c97acce83a9fe8ada486e9fcdafe58769736..e3c84ad3fad4ee479bb00b7dc02a2502f2088984 100644
--- a/src/main/java/net/minecraft/world/level/block/EnderChestBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/EnderChestBlock.java
@@ -86,6 +86,27 @@ public class EnderChestBlock extends AbstractChestBlock<EnderChestBlockEntity> i
                 EnderChestBlockEntity enderChestBlockEntity = (EnderChestBlockEntity)blockEntity;
                 playerEnderChestContainer.setActiveChest(enderChestBlockEntity);
                 player.openMenu(new SimpleMenuProvider((syncId, inventory, playerx) -> {
+                    // Purpur start
+                    if (net.pl3x.purpur.PurpurConfig.enderChestSixRows) {
+                        if (net.pl3x.purpur.PurpurConfig.enderChestPermissionRows) {
+                            org.bukkit.craftbukkit.entity.CraftHumanEntity bukkitPlayer = player.getBukkitEntity();
+                            if (bukkitPlayer.hasPermission("purpur.enderchest.rows.six")) {
+                                return ChestMenu.sixRows(syncId, inventory, playerEnderChestContainer);
+                            } else if (bukkitPlayer.hasPermission("purpur.enderchest.rows.five")) {
+                                return ChestMenu.fiveRows(syncId, inventory, playerEnderChestContainer);
+                            } else if (bukkitPlayer.hasPermission("purpur.enderchest.rows.four")) {
+                                return ChestMenu.fourRows(syncId, inventory, playerEnderChestContainer);
+                            } else if (bukkitPlayer.hasPermission("purpur.enderchest.rows.three")) {
+                                return ChestMenu.threeRows(syncId, inventory, playerEnderChestContainer);
+                            } else if (bukkitPlayer.hasPermission("purpur.enderchest.rows.two")) {
+                                return ChestMenu.twoRows(syncId, inventory, playerEnderChestContainer);
+                            } else if (bukkitPlayer.hasPermission("purpur.enderchest.rows.one")) {
+                                return ChestMenu.oneRow(syncId, inventory, playerEnderChestContainer);
+                            }
+                        }
+                        return ChestMenu.sixRows(syncId, inventory, playerEnderChestContainer);
+                    }
+                    // Purpur end
                     return ChestMenu.threeRows(syncId, inventory, playerEnderChestContainer);
                 }, CONTAINER_TITLE));
                 player.awardStat(Stats.OPEN_ENDERCHEST);
diff --git a/src/main/java/net/minecraft/world/level/block/entity/BarrelBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/BarrelBlockEntity.java
index f494063ead9c6303fb3ca880aba2a877ae8d83ab..3b027111ed933856ae86ad5f62aac744021f8880 100644
--- a/src/main/java/net/minecraft/world/level/block/entity/BarrelBlockEntity.java
+++ b/src/main/java/net/minecraft/world/level/block/entity/BarrelBlockEntity.java
@@ -68,7 +68,7 @@ public class BarrelBlockEntity extends RandomizableContainerBlockEntity {
 
     public BarrelBlockEntity(BlockPos pos, BlockState state) {
         super(BlockEntityType.BARREL, pos, state);
-        this.items = NonNullList.withSize(27, ItemStack.EMPTY);
+        this.items = NonNullList.withSize(net.pl3x.purpur.PurpurConfig.barrelSixRows ? 54 : 27, ItemStack.EMPTY); // Purpur
         this.openersCounter = new ContainerOpenersCounter() {
             @Override
             protected void onOpen(Level world, BlockPos pos, BlockState state) {
@@ -120,7 +120,7 @@ public class BarrelBlockEntity extends RandomizableContainerBlockEntity {
 
     @Override
     public int getContainerSize() {
-        return 27;
+        return net.pl3x.purpur.PurpurConfig.barrelSixRows ? 54 : 27; // Purpur
     }
 
     @Override
@@ -140,6 +140,7 @@ public class BarrelBlockEntity extends RandomizableContainerBlockEntity {
 
     @Override
     protected AbstractContainerMenu createMenu(int syncId, Inventory playerInventory) {
+        if (net.pl3x.purpur.PurpurConfig.barrelSixRows) return ChestMenu.sixRows(syncId, playerInventory, (Container) this); // Purpur
         return ChestMenu.threeRows(syncId, playerInventory, (Container) this);
     }
 
diff --git a/src/main/java/net/pl3x/purpur/PurpurConfig.java b/src/main/java/net/pl3x/purpur/PurpurConfig.java
index 7e1938263ecb02c7d2a1fc3dff7aa35b958c6113..d7ed125553530e28644f5fb9c09f7a06eb79199a 100644
--- a/src/main/java/net/pl3x/purpur/PurpurConfig.java
+++ b/src/main/java/net/pl3x/purpur/PurpurConfig.java
@@ -174,4 +174,23 @@ public class PurpurConfig {
         }
         if (!co.aikar.timings.TimingsManager.hiddenConfigs.contains("server-ip")) co.aikar.timings.TimingsManager.hiddenConfigs.add("server-ip");
     }
+
+    public static boolean barrelSixRows = false;
+    public static boolean enderChestSixRows = false;
+    public static boolean enderChestPermissionRows = false;
+    private static void blockSettings() {
+        if (version < 3) {
+            boolean oldValue = getBoolean("settings.barrel.packed-barrels", true);
+            set("settings.blocks.barrel.six-rows", oldValue);
+            set("settings.packed-barrels", null);
+            oldValue = getBoolean("settings.large-ender-chests", true);
+            set("settings.blocks.ender_chest.six-rows", oldValue);
+            set("settings.large-ender-chests", null);
+        }
+        barrelSixRows = getBoolean("settings.blocks.barrel.six-rows", barrelSixRows);
+        org.bukkit.event.inventory.InventoryType.BARREL.setDefaultSize(barrelSixRows ? 54 : 27);
+        enderChestSixRows = getBoolean("settings.blocks.ender_chest.six-rows", enderChestSixRows);
+        org.bukkit.event.inventory.InventoryType.ENDER_CHEST.setDefaultSize(enderChestSixRows ? 54 : 27);
+        enderChestPermissionRows = getBoolean("settings.blocks.ender_chest.use-permissions-for-rows", enderChestPermissionRows);
+    }
 }
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftContainer.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftContainer.java
index 99d52dc4a3619200e8eb864e8ed8f4a6e469b443..613a0bcb4268f5d3256a871d47ae079ba5d92525 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftContainer.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftContainer.java
@@ -165,8 +165,12 @@ public class CraftContainer extends AbstractContainerMenu {
             case PLAYER:
             case CHEST:
             case ENDER_CHEST:
+                // Purpur start
+                this.delegate = new ChestMenu(net.pl3x.purpur.PurpurConfig.enderChestSixRows ? MenuType.GENERIC_9x6 : MenuType.GENERIC_9x3, windowId, bottom, top, top.getContainerSize() / 9);
+                break;
             case BARREL:
-                this.delegate = new ChestMenu(MenuType.GENERIC_9x3, windowId, bottom, top, top.getContainerSize() / 9);
+                this.delegate = new ChestMenu(net.pl3x.purpur.PurpurConfig.barrelSixRows ? MenuType.GENERIC_9x6 : MenuType.GENERIC_9x3, windowId, bottom, top, top.getContainerSize() / 9);
+                // Purpur end
                 break;
             case DISPENSER:
             case DROPPER:
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java
index 396a4ae3d5a829eda78ef98561333aea300aa722..91478d614a56d1ac371187515d4c92b2a373b65c 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftInventory.java
@@ -81,7 +81,7 @@ public class CraftInventory implements Inventory {
 
     @Override
     public void setContents(ItemStack[] items) {
-        if (this.getSize() < items.length) {
+        if (false && this.getSize() < items.length) { // Purpur
             throw new IllegalArgumentException("Invalid inventory size; expected " + this.getSize() + " or less");
         }
 
