Updating Shulker Box Inventory

Discussion in 'Plugin Development' started by ExtremeOrphan, Sep 20, 2019.

Thread Status:
Not open for further replies.
  1. Offline


    Hello! I am trying to make a plugin where you can right click with a shulker box in your hand and it will open the shulker's inventory in a new inventory that mirrors the shulker's contents. However I want it so they can edit the contents and when the close the inventory the shulker's contents will be updated with the current (mirror inventory) contents.

    The event to open the shulker box and put its contents into a new inventory works, however the event (InventoryCloseEvent) to update the inventory isn't being completed, it wont get past the 4th debug message ( p.sendMessage("3"); )

    Here's my relevant code, any and all assistance is appreciated!

    package com.jeremyrpeters.briefcases;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.block.ShulkerBox;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.inventory.InventoryCloseEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.BlockStateMeta;
    import org.bukkit.inventory.meta.ItemMeta;
    public class EventListener implements Listener {
        Main plugin;
        public EventListener (Main instance) {
            plugin = instance;
        public void openBriefcase(PlayerInteractEvent event) {
            Player p = event.getPlayer();
            ItemStack briefcase = event.getItem(); // Player that is right clicked
            ItemMeta meta = briefcase.getItemMeta();
            String name = meta.getDisplayName();
            if (name.equalsIgnoreCase(ChatColor.RED + "Briefcase")) {
                if(briefcase.getItemMeta() instanceof BlockStateMeta) {
                    BlockStateMeta im = (BlockStateMeta) briefcase.getItemMeta();
                    if(im.getBlockState() instanceof ShulkerBox) {
                        ShulkerBox shulker = (ShulkerBox) im.getBlockState();
                        Inventory briefcase_inv = Bukkit.createInventory(null, 27, ChatColor.RED + "Briefcase");
        public void closeBriefcase(InventoryCloseEvent event) {
            Player p = (Player) event.getPlayer();
            ItemStack briefcase = p.getItemInHand();
            if (briefcase.getType().equals(Material.BLACK_SHULKER_BOX)) {
                if (briefcase.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.RED + "Briefcase")) {
                    if(briefcase.getItemMeta() instanceof BlockStateMeta) {
                        BlockStateMeta briefcase_meta = (BlockStateMeta) briefcase.getItemMeta();
                        if(briefcase_meta.getBlockState() instanceof ShulkerBox) {
                            ShulkerBox shulker = (ShulkerBox) briefcase_meta.getBlockState();
                            Inventory currentinv = p.getInventory();
  2. The problem is that the player inventory has 36 slots (maybe even more not sure about the armor slots) but the shulker box only has 27 slots so you can't duplicate the player inventory into the shulker since there is not enough space. Also: in the interactEvent, check if the item has an itemMeta otherwise you'll get tons of errors which also should indicate your main issue. Look into the console and read the stacktrace!!
Thread Status:
Not open for further replies.

Share This Page