Cancel command block opening?

Discussion in 'Plugin Development' started by thebigdolphin1, Dec 26, 2012.

Thread Status:
Not open for further replies.
  1. I've tried allsorts, but cant get this to work.
    This works with chests, but not command blocks:
    Code:
        @EventHandler
        public void commandBlockOpen(PlayerInteractEvent event){
            if(event.getAction() == Action.RIGHT_CLICK_BLOCK) {
                if(event.getClickedBlock().getType() == Material.COMMAND) {
                    event.setCancelled(true);
                        event.setCancelled(true);
                        //CODE HERE
                }
            }
        }
     
  2. First, check the Listener (i.e. your code) is valid and registered.
    (implements Listener, registerEvents(listener,plugin)), to eliminate chasing a ghost.

    It is possible that in the development build the event is not being raised for command blocks, or is ignored by it.

    Check if the event is called (using System.out.println("hi") as indication of the event firing into the if statements).
    Try raising the issue on leaky.bukkit.org, as this seems like a lack of functionality on bukkit's part.
     
  3. tehbeard it detects it fine, and runs the code after fine, it just wont cancel opening the command block GUI.
     
  4. Offline

    fireblast709

    try: event.setUseInteractedBlock(Event.Result.DENY);
     
  5. Offline

    5pHiNxX

    hei @thebigdolphin1:
    i found a solution:
    Code:java
    1. @EventHandler
    2. public void onBlockClick(PlayerInteractEvent event){
    3. Player player = event.getPlayer();
    4. if (event.getAction() == RIGHT_CLICK_BLOCK){
    5. if (event.getItemClicked().equals(Material.COMMAND)){
    6. player.closeInventory();
    7. event.setCancelled(true);
    8. }
    9. }
    10. }


    player.closeInventory() closes the CommandBlock "inventory" ;)
     
Thread Status:
Not open for further replies.

Share This Page