Hide Player Functionality

Discussion in 'Spigot Plugin Development' started by Bladian, Jun 18, 2015.

  1. Does the hidePlayer(p) command allow for hidden players to break blocks.

    I don't currently have Minecraft installed so I need to ask a question.

    If I hide a player to all players, does the player have the permission to interact with blocks or do I have to do that manually events.

    I'm currently using:

    Code (Text):
    for(Player all : Bukkit.getOnlinePlayers()) {
      all.hidePlayer(p);
     
     
  2. hidePlayer will hide Player(s) p for Player all. They can whatever they want but Player(s) all will not see Player p.
     
    • Winner Winner x 1
  3. Okay thanks! Just what I thought.

    Second question is there any way to check if a player is shown?
     
    • Winner Winner x 1
  4. Going to add one more question.

    Using the player interact event. How can I check if a player clicks a Furnace/Chest/Brewing Stand and then open that same inventory?
     
  5. Get the block the player clicked. If it's a furnace etc, get it's inventory and then open that for the player. It's all in the JavaDocs! :D
     
  6. You cannot get the inventory using the block, and I did check if the block was an instance of the furnace. Unfortunately there is no method with the Block, unfortunately I can't find it whether it be the BlockState or something else.
     
  7. Code (Text):
    if (PlayerInteractevent#getBlock()#getBlockState instanceof Furnace) {
        //do things
    }
    Or something like that. I'm too tired to think about it much - anyways, the point is, digging through the javadocs would answer 80% of the questions in this subforum :)


    and knowing basic java would get another 19%
     
    #9 bo0tzz, Jun 19, 2015
    Last edited: Jun 19, 2015
    • Agree Agree x 2
  8. I saw that at the bottom :p. I know basic Java, I just didn't think that blocks with an inventory would have their own class (which surprised me), so I basically decided to try it like this.

    Code (Text):
    if (action == Action.RIGHT_CLICK_BLOCK || action == Action.RIGHT_CLICK_AIR) {

                    if (p.getItemInHand().getType() == Material.CHEST) {

                        Block block = e.getClickedBlock();

                        if (block instanceof Furnace) {

                            e.setCancelled(true);

                            Furnace furnace = (Furnace) e.getClickedBlock();

                            p.openInventory(furnace.getInventory());

                        } else if (block instanceof BrewingStand) {

                            e.setCancelled(true);

                            BrewingStand brewingStand = (BrewingStand) e.getClickedBlock();

                            p.openInventory(brewingStand.getInventory());

                        } else if (block instanceof Chest) {

                            e.setCancelled(true);

                            Chest chest = (Chest) e.getClickedBlock();

                            p.openInventory(chest.getInventory());
                        }
                    }
                }
    Now this doesn't work and I'm not sure why. The BlockState class doesn't have any methods which return it's inventory. So I might be missing something.
     
  9. Code (Text):
    Furnace furnace = (Furnace) e.getClickedBlock();
    You'll want to use e.getClickedBlock().getBlockState() - That's what you can cast to the Furnace, not the Block itself ;)
     
  10. MAJESTIC FACEPALM

    Lack of sleep is killing me. Thanks, I'm just really tired right now and I'm not able to concentrate.
     
  11. That's alright. I'm pretty sleep deprived as well, I'm actually quite surprised I'm getting this right ;) Good luck with the rest dude, feel free to ask more questions if you need help.
     
  12. Unfortunately that didn't work either. I didn't find the BlockState but I found State.

    Code (Text):
    if (action == Action.RIGHT_CLICK_BLOCK || action == Action.RIGHT_CLICK_AIR) {

                    if (p.getItemInHand().getType() == Material.CHEST) {

                        Block block = (Block) e.getClickedBlock();

                        if (block instanceof Furnace) {

                            p.sendMessage("It works");

                            Furnace furnace = (Furnace) e.getClickedBlock().getState();

                            p.openInventory(furnace.getInventory());

                        } else if (block instanceof BrewingStand) {

                            BrewingStand brewingStand = (BrewingStand) e.getClickedBlock().getState();

                            p.openInventory(brewingStand.getInventory());

                        } else if (block instanceof Chest) {

                            Chest chest = (Chest) e.getClickedBlock().getState();

                            p.openInventory(chest.getInventory());
                        }
                    }
     
  13. sothatsit

    Patron

    You have to check if the BlockState is instanceof Furnace, not if the Block is.

    Code (Text):
    BlockState state = e.getClickedBlock().getState();

    if(state instanceof Furnace) {
        Furnace furnace = (Furnace) state;
    }
     
  14. So does the code you posted now work, or not? If not do some debug and post errors etc

    Nevermind, sothatsit's message hadn't loaded for me.
     
  15. Since it wasn't giving the results I was expecting I tried using a different event:

    Code (Text):
    @EventHandler
        public void onOpen(InventoryOpenEvent e) {

            Player p = (Player) e.getPlayer();

            if (spectate.contains(p)) {

                if (p.getItemInHand().getType() == Material.CHEST) {

                    p.sendMessage("It works!");

                    e.setCancelled(true);

                    Inventory inventory = e.getInventory();

                    p.openInventory(inventory);

                } else {
                    e.setCancelled(true);
                }
            }
        }
    Unfortunately this results in a huge error!

    Code (Text):
       
        at net.minecraft.server.v1_7_R2.EntityPlayer.openFurnace(EntityPlayer.java:685) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.craftbukkit.v1_7_R2.entity.CraftHumanEntity.openInventory(CraftHumanEntity.java:204) ~[spigot.jar:git-Spigot-1387]
        at me.uhc.spectate.EventSpectate.onOpen(EventSpectate.java:119) ~[?:?]
        at sun.reflect.GeneratedMethodAccessor48.invoke(Unknown Source) ~[?:?]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[?:1.6.0_65]
        at java.lang.reflect.Method.invoke(Method.java:597) ~[?:1.6.0_65]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:292) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.plugin.TimedRegisteredListener.callEvent(TimedRegisteredListener.java:30) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.craftbukkit.v1_7_R2.event.CraftEventFactory.callInventoryOpenEvent(CraftEventFactory.java:594) ~[spigot.jar:git-Spigot-1387]
        at net.minecraft.server.v1_7_R2.EntityPlayer.openFurnace(EntityPlayer.java:685) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.craftbukkit.v1_7_R2.entity.CraftHumanEntity.openInventory(CraftHumanEntity.java:204) ~[spigot.jar:git-Spigot-1387]
        at me.uhc.spectate.EventSpectate.onOpen(EventSpectate.java:119) ~[?:?]
        at sun.reflect.GeneratedMethodAccessor48.invoke(Unknown Source) ~[?:?]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[?:1.6.0_65]
        at java.lang.reflect.Method.invoke(Method.java:597) ~[?:1.6.0_65]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:292) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.plugin.TimedRegisteredListener.callEvent(TimedRegisteredListener.java:30) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.craftbukkit.v1_7_R2.event.CraftEventFactory.callInventoryOpenEvent(CraftEventFactory.java:594) ~[spigot.jar:git-Spigot-1387]
        at net.minecraft.server.v1_7_R2.EntityPlayer.openFurnace(EntityPlayer.java:685) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.craftbukkit.v1_7_R2.entity.CraftHumanEntity.openInventory(CraftHumanEntity.java:204) ~[spigot.jar:git-Spigot-1387]
        at me.uhc.spectate.EventSpectate.onOpen(EventSpectate.java:119) ~[?:?]
        at sun.reflect.GeneratedMethodAccessor48.invoke(Unknown Source) ~[?:?]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[?:1.6.0_65]
        at java.lang.reflect.Method.invoke(Method.java:597) ~[?:1.6.0_65]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:292) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.plugin.TimedRegisteredListener.callEvent(TimedRegisteredListener.java:30) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.craftbukkit.v1_7_R2.event.CraftEventFactory.callInventoryOpenEvent(CraftEventFactory.java:594) ~[spigot.jar:git-Spigot-1387]
        at net.minecraft.server.v1_7_R2.EntityPlayer.openFurnace(EntityPlayer.java:685) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.craftbukkit.v1_7_R2.entity.CraftHumanEntity.openInventory(CraftHumanEntity.java:204) ~[spigot.jar:git-Spigot-1387]
        at me.uhc.spectate.EventSpectate.onOpen(EventSpectate.java:119) ~[?:?]
        at sun.reflect.GeneratedMethodAccessor48.invoke(Unknown Source) ~[?:?]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[?:1.6.0_65]
        at java.lang.reflect.Method.invoke(Method.java:597) ~[?:1.6.0_65]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:292) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.plugin.TimedRegisteredListener.callEvent(TimedRegisteredListener.java:30) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.craftbukkit.v1_7_R2.event.CraftEventFactory.callInventoryOpenEvent(CraftEventFactory.java:594) ~[spigot.jar:git-Spigot-1387]
        at net.minecraft.server.v1_7_R2.EntityPlayer.openFurnace(EntityPlayer.java:685) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.craftbukkit.v1_7_R2.entity.CraftHumanEntity.openInventory(CraftHumanEntity.java:204) ~[spigot.jar:git-Spigot-1387]
        at me.uhc.spectate.EventSpectate.onOpen(EventSpectate.java:119) ~[?:?]
        at sun.reflect.GeneratedMethodAccessor48.invoke(Unknown Source) ~[?:?]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[?:1.6.0_65]
        at java.lang.reflect.Method.invoke(Method.java:597) ~[?:1.6.0_65]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:292) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.plugin.TimedRegisteredListener.callEvent(TimedRegisteredListener.java:30) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.craftbukkit.v1_7_R2.event.CraftEventFactory.callInventoryOpenEvent(CraftEventFactory.java:594) ~[spigot.jar:git-Spigot-1387]
        at net.minecraft.server.v1_7_R2.EntityPlayer.openFurnace(EntityPlayer.java:685) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.craftbukkit.v1_7_R2.entity.CraftHumanEntity.openInventory(CraftHumanEntity.java:204) ~[spigot.jar:git-Spigot-1387]
        at me.uhc.spectate.EventSpectate.onOpen(EventSpectate.java:119) ~[?:?]
        at sun.reflect.GeneratedMethodAccessor48.invoke(Unknown Source) ~[?:?]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[?:1.6.0_65]
        at java.lang.reflect.Method.invoke(Method.java:597) ~[?:1.6.0_65]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:292) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.plugin.TimedRegisteredListener.callEvent(TimedRegisteredListener.java:30) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.craftbukkit.v1_7_R2.event.CraftEventFactory.callInventoryOpenEvent(CraftEventFactory.java:594) ~[spigot.jar:git-Spigot-1387]
    Which happens with a furnace. and:

    Code (Text):
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[?:1.6.0_65]
        at java.lang.reflect.Method.invoke(Method.java:597) ~[?:1.6.0_65]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:292) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.plugin.TimedRegisteredListener.callEvent(TimedRegisteredListener.java:30) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.craftbukkit.v1_7_R2.event.CraftEventFactory.callInventoryOpenEvent(CraftEventFactory.java:594) ~[spigot.jar:git-Spigot-1387]
        at net.minecraft.server.v1_7_R2.EntityPlayer.openContainer(EntityPlayer.java:637) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.craftbukkit.v1_7_R2.entity.CraftHumanEntity.openInventory(CraftHumanEntity.java:193) ~[spigot.jar:git-Spigot-1387]
        at me.uhc.spectate.EventSpectate.onOpen(EventSpectate.java:119) ~[?:?]
        at sun.reflect.GeneratedMethodAccessor48.invoke(Unknown Source) ~[?:?]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[?:1.6.0_65]
        at java.lang.reflect.Method.invoke(Method.java:597) ~[?:1.6.0_65]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:292) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.plugin.TimedRegisteredListener.callEvent(TimedRegisteredListener.java:30) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.craftbukkit.v1_7_R2.event.CraftEventFactory.callInventoryOpenEvent(CraftEventFactory.java:594) ~[spigot.jar:git-Spigot-1387]
        at net.minecraft.server.v1_7_R2.EntityPlayer.openContainer(EntityPlayer.java:637) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.craftbukkit.v1_7_R2.entity.CraftHumanEntity.openInventory(CraftHumanEntity.java:193) ~[spigot.jar:git-Spigot-1387]
        at me.uhc.spectate.EventSpectate.onOpen(EventSpectate.java:119) ~[?:?]
        at sun.reflect.GeneratedMethodAccessor48.invoke(Unknown Source) ~[?:?]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[?:1.6.0_65]
        at java.lang.reflect.Method.invoke(Method.java:597) ~[?:1.6.0_65]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:292) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.plugin.TimedRegisteredListener.callEvent(TimedRegisteredListener.java:30) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.craftbukkit.v1_7_R2.event.CraftEventFactory.callInventoryOpenEvent(CraftEventFactory.java:594) ~[spigot.jar:git-Spigot-1387]
        at net.minecraft.server.v1_7_R2.EntityPlayer.openContainer(EntityPlayer.java:637) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.craftbukkit.v1_7_R2.entity.CraftHumanEntity.openInventory(CraftHumanEntity.java:193) ~[spigot.jar:git-Spigot-1387]
        at me.uhc.spectate.EventSpectate.onOpen(EventSpectate.java:119) ~[?:?]
        at sun.reflect.GeneratedMethodAccessor48.invoke(Unknown Source) ~[?:?]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[?:1.6.0_65]
        at java.lang.reflect.Method.invoke(Method.java:597) ~[?:1.6.0_65]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:292) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.plugin.TimedRegisteredListener.callEvent(TimedRegisteredListener.java:30) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.craftbukkit.v1_7_R2.event.CraftEventFactory.callInventoryOpenEvent(CraftEventFactory.java:594) ~[spigot.jar:git-Spigot-1387]
        at net.minecraft.server.v1_7_R2.EntityPlayer.openContainer(EntityPlayer.java:637) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.craftbukkit.v1_7_R2.entity.CraftHumanEntity.openInventory(CraftHumanEntity.java:193) ~[spigot.jar:git-Spigot-1387]
        at me.uhc.spectate.EventSpectate.onOpen(EventSpectate.java:119) ~[?:?]
        at sun.reflect.GeneratedMethodAccessor48.invoke(Unknown Source) ~[?:?]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[?:1.6.0_65]
        at java.lang.reflect.Method.invoke(Method.java:597) ~[?:1.6.0_65]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:292) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.plugin.TimedRegisteredListener.callEvent(TimedRegisteredListener.java:30) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.craftbukkit.v1_7_R2.event.CraftEventFactory.callInventoryOpenEvent(CraftEventFactory.java:594) ~[spigot.jar:git-Spigot-1387]
        at net.minecraft.server.v1_7_R2.EntityPlayer.openContainer(EntityPlayer.java:637) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.craftbukkit.v1_7_R2.entity.CraftHumanEntity.openInventory(CraftHumanEntity.java:193) ~[spigot.jar:git-Spigot-1387]
        at me.uhc.spectate.EventSpectate.onOpen(EventSpectate.java:119) ~[?:?]
        at sun.reflect.GeneratedMethodAccessor48.invoke(Unknown Source) ~[?:?]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[?:1.6.0_65]
        at java.lang.reflect.Method.invoke(Method.java:597) ~[?:1.6.0_65]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:292) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.plugin.TimedRegisteredListener.callEvent(TimedRegisteredListener.java:30) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) ~[spigot.jar:git-Spigot-1387]
        at org.bukkit.craftbukkit.v1_7_R2.event.CraftEventFactory.callInventoryOpenEvent(CraftEventFactory.java:594) ~[spigot.jar:git-Spigot-1387]
    >
     
    Which happens with a chest. Here is the line it creates an infinite loop on.

    p.openInventory(inventory);
     
  16. The event you have chosen to use is the open inventory event... the code you have is forcing open an inventory, which fires a new inventory open event, which opens another inventory, and then another, and so on until you get the crash.

    Imagine this in real life. You open your wallet to grab some money, but the code in the matrix calls another open wallet event to fire. Since opening your wallet will just keep opening the wallet, you just crashed the matrix and die.
     
  17. You actually just mind fucked me. I didn't contemplate that.

    If I think about it now, the only time I need to stop a player from opening an inventory is with a chest. I just want to stop the animation.

    Maybe I can loop through the chest contents and add them to a new inventory. Or maybe I should check if ithe inventory derives from a chest. Not sure which way is more efficient.
     
  18. sothatsit

    Patron

    You are probably better off using the InventoryOpenEvent, but you cant re-open an inventory in the InventoryOpenEvent. As @BillyGalbreath said, this will cause a StackOverflowerException.

    Instead, you can check if the block the inventory is linked to is a Furnace/Brewing Stand/Chest

    You can do this by doing something like:
    Code (Text):
    Inventory inv = e.getInventory();

    if(inv.getHolder() instanceof BlockState) {
        BlockState state = (BlockState) inv.getHolder();
        Block block = state.getBlock();
     
        if(block.getType() == Material.FURNACE) {
            //Inventory is from Furnace
        } else if(block.getType() == Material.BREWING_STAND) {
            //Inventory is from Brewing Stand
        } else if(block.getType() == Material.CHEST) {
            //Inventory is from Chest
        }
    }