Cancel GUI open

Discussion in 'Plugin Development' started by 567legodude, Oct 29, 2014.

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

    567legodude

    I am trying to prevent players from being able to open command blocks, but I have not had any luck. Can someone provide some code that works to cancel the event.

    This is what I tried to cancel the command block from opening:
    Code:java
    1. @EventHandler
    2. public void onInteract(PlayerInteractEvent event) {
    3. Player player = event.getPlayer();
    4.  
    5. if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
    6. Block block = event.getClickedBlock();
    7. if (block.getType() == Material.COMMAND) {
    8. event.setCancelled(true);
    9. player.sendMessage("You can't open command blocks.");
    10. }
    11. }
    12. }

    For some reason, the message will display, but it will still open the command block GUI, who knows how to cancel this.

    I found that this will work with other things such as brewing stands, but anyone know why I can't get the command block to cancel?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 14, 2016
  2. Offline

    drpk

    567legodude hm, you may want to use InventoryOpenEvent and check the InventoryType, instead. I think that may work.

    EDIT: nevermind, you can't check if the InventoryType is a command block AFAIK
     
  3. Offline

    567legodude

    drpk There is only Inventory types for Anvil, Beacon, Brewing, Chest, Crafting, Creative, Dispenser, Dropper, Enchanting, Ender_Chest, Furnace, Hopper, Merchant, Player, and Workbench. So there is no way for me to tell if it is a command block. Another thing is that a command block does not trigger the InventoryOpenEvent.
     
  4. try
    Code:java
    1. player.closeInventory();
     
  5. Offline

    Abs0rbed

    Is the point just to prevent players from seeing what command is inside the block? Because they shouldn't be able to edit them anyway, because you need creative and op
     
Thread Status:
Not open for further replies.

Share This Page