Skip to content

Commit d06fbf5

Browse files
committed
Fix shulker boxes being able to be stored in shulker boxes (Fixes #56)
1 parent 818e67b commit d06fbf5

5 files changed

Lines changed: 41 additions & 3 deletions

File tree

src/main/java/com/mikedeejay2/simplestack/listeners/InventoryMoveItemListener.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
import com.mikedeejay2.simplestack.Simplestack;
44
import com.mikedeejay2.simplestack.util.CancelUtils;
55
import com.mikedeejay2.simplestack.util.MoveUtils;
6+
import org.bukkit.Location;
7+
import org.bukkit.Material;
8+
import org.bukkit.World;
9+
import org.bukkit.block.Block;
610
import org.bukkit.event.EventHandler;
711
import org.bukkit.event.Listener;
812
import org.bukkit.event.inventory.InventoryMoveItemEvent;
@@ -36,6 +40,14 @@ public void inventoryMoveItemEvent(InventoryMoveItemEvent event)
3640
Inventory toInv = event.getDestination();
3741
InventoryType invType = toInv.getType();
3842
if(invType == InventoryType.BREWING) return;
43+
if(toInv.getLocation() != null && item.getType().toString().endsWith("SHULKER_BOX"))
44+
{
45+
Location location = toInv.getLocation();
46+
World world = location.getWorld();
47+
Block block = world.getBlockAt(location);
48+
Material blockType = block.getType();
49+
if(blockType.toString().endsWith("SHULKER_BOX")) return;
50+
}
3951

4052
boolean cancel = CancelUtils.cancelStackCheck(plugin, item);
4153
if(cancel) return;

src/main/java/com/mikedeejay2/simplestack/listeners/player/InventoryClickListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public void stackEvent(InventoryClickEvent event)
5151

5252
boolean cancel1 = CancelUtils.cancelStackCheck(plugin, itemPickUp);
5353
boolean cancel2 = CancelUtils.cancelStackCheck(plugin, itemPutDown);
54-
boolean cancel3 = CancelUtils.cancelGUICheck(plugin, topInv);
54+
boolean cancel3 = CancelUtils.cancelGUICheck(plugin, topInv, itemPutDown);
5555
if((cancel1 && cancel2) || event.isCancelled() || cancel3)
5656
{
5757
return;

src/main/java/com/mikedeejay2/simplestack/listeners/player/InventoryDragListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public void inventoryDragEvent(InventoryDragEvent event)
4646

4747
ItemStack cursor = event.getOldCursor();
4848
if(CancelUtils.cancelStackCheck(plugin, cursor)) return;
49-
if(CancelUtils.cancelGUICheck(plugin, event.getInventory())) return;
49+
if(CancelUtils.cancelGUICheck(plugin, event.getInventory(), cursor)) return;
5050
GameMode gameMode = player.getGameMode();
5151
if(gameMode == GameMode.SURVIVAL || gameMode == GameMode.ADVENTURE)
5252
{

src/main/java/com/mikedeejay2/simplestack/util/CancelUtils.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
import com.mikedeejay2.simplestack.Simplestack;
44
import com.mikedeejay2.simplestack.config.Config;
55
import com.mikedeejay2.simplestack.config.ListMode;
6+
import org.bukkit.Location;
67
import org.bukkit.Material;
8+
import org.bukkit.World;
9+
import org.bukkit.block.Block;
710
import org.bukkit.entity.Player;
811
import org.bukkit.inventory.*;
912

@@ -116,11 +119,19 @@ public static boolean cancelMoveCheck(Simplestack plugin, ItemStack item, Invent
116119
* @param inv Inventory to check
117120
* @return If inventory should be cancelled
118121
*/
119-
public static boolean cancelGUICheck(Simplestack plugin, Inventory inv)
122+
public static boolean cancelGUICheck(Simplestack plugin, Inventory inv, ItemStack cursorItem)
120123
{
121124
if(inv == null) return true;
122125
if(plugin.getMCVersion()[1] >= 16 && inv instanceof SmithingInventory) return false;
123126
if(inv.getLocation() == null) return true;
127+
if(cursorItem.getType().toString().endsWith("SHULKER_BOX"))
128+
{
129+
Location location = inv.getLocation();
130+
World world = location.getWorld();
131+
Block block = world.getBlockAt(location);
132+
Material blockType = block.getType();
133+
if(blockType.toString().endsWith("SHULKER_BOX")) return true;
134+
}
124135
return false;
125136
}
126137
}

src/main/java/com/mikedeejay2/simplestack/util/ClickUtils.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
import com.mikedeejay2.mikedeejay2lib.util.item.ItemComparison;
44
import com.mikedeejay2.simplestack.Simplestack;
5+
import org.bukkit.Location;
56
import org.bukkit.Material;
7+
import org.bukkit.World;
8+
import org.bukkit.block.Block;
69
import org.bukkit.entity.Player;
710
import org.bukkit.event.inventory.InventoryClickEvent;
811
import org.bukkit.inventory.*;
@@ -362,6 +365,18 @@ else if(toInv instanceof BeaconInventory)
362365
toInv.setItem(0, itemInSlot);
363366
return;
364367
}
368+
else if(itemInSlot.getType().toString().endsWith("SHULKER_BOX") && toInv.getLocation() != null)
369+
{
370+
Location location = toInv.getLocation();
371+
World world = location.getWorld();
372+
Block block = world.getBlockAt(location);
373+
Material blockMat = block.getType();
374+
if(blockMat.toString().endsWith("SHULKER_BOX"))
375+
{
376+
ClickUtils.shiftClickSameInv(plugin, itemInSlot, event, bottomInv);
377+
return;
378+
}
379+
}
365380

366381

367382
if(reverseHotbar)

0 commit comments

Comments
 (0)