Solved InventoryOpenEvent

Discussion in 'Plugin Development' started by BrickBoy55, Apr 17, 2015.

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


    I'm having trouble with the inventory open event. I've tried debugging, but the event isn't even registering.

        public void onInventoryOpen(InventoryOpenEvent event) {
            if (event.getInventory().equals(InventoryType.CHEST) ||
                event.getInventory().equals(InventoryType.FURNACE) ||
                event.getInventory().equals(InventoryType.CRAFTING) ||
                event.getInventory().equals(InventoryType.ENCHANTING) ||
                event.getInventory().equals(InventoryType.BREWING) ||
                event.getInventory().equals(InventoryType.ENDER_CHEST) ||
                event.getInventory().equals(InventoryType.HOPPER)) {
                HumanEntity player = event.getPlayer();
                int radius = 25;
                Location loc = player.getLocation();
                for (int x = (int) (loc.getX() - radius); x < loc.getX() + radius; x++) {
                    for (int y = (int) (loc.getY() - radius); y < loc.getY() + radius; y++) {
                        for (int z = (int) (loc.getZ() - radius); z < loc.getZ() + radius; z++) {
                            Block block = player.getWorld().getBlockAt(x, y, z);
                            if (block.getState() instanceof Sign) {
                                Sign sign = (Sign) block.getState();
                                if (sign.getLine(1).equals("§8[§9Protected§8]")) {
                                    if (!player.getName().equals(ChatColor.stripColor(sign.getLine(2)))) {
                                        player.sendMessage(prefix + "You cannot use that in " + ChatColor.stripColor(sign.getLine(2)) + "'s land!");
    Before you ask me:

    Yes, my events are registered.

    Help is appreciated!
  2. Offline


    If you're trying to detect when a player opens their inventory, I don't think that event will do it. One way that you could do it though would be to remove all "Taking inventory" achievements from players, listening for the achievement event, cancelling it, and then adding all the inventory open code in that event. The one downside is that players will not be able to have the "Taking inventory" achievement with that work-around.
  3. Offline



    Theres got to be an easier way though.

    EDIT: The debugging now gets to #1


    Oh yeah, I found a major fail in my code (I was getting the inventory name, not the type), also the debug four message spammed my server into crash, so I have no status whether it works right now or not.

    Issue resolved itself.

    Solution: Needed to get the inventory type, not the name.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 12, 2016
Thread Status:
Not open for further replies.

Share This Page