InventoryClickEvent - Cancelling problem

Discussion in 'Plugin Development' started by JeroenV, Jan 24, 2013.

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

    JeroenV

    Hey,

    I've got a quick question. I'm using an InventoryClickEvent where I check if a the material clicked is equal to the one allowed, that all works. However if I cancel the event when it isn't some strange things happen.

    For some reason when the event is cancelled the required item (if in inv) appears on my cursor, also when I close my inventory the required item pops out of my inventory.

    Here's the code I'm using:

    Code:
        @EventHandler
        public void InvClickEvent(InventoryClickEvent event){
           
            if(event.getView().getType() == InventoryType.CHEST){
                String title = event.getInventory().getTitle();   
               
     
                List<String> FInputMaterials = Main.FInputMaterials;
                List<String> FOutputMaterials = Main.FOutputMaterials;
                List<String> ICustomItemNames = Main.ICustomItemNames;
                List<String> OCustomItemNames = Main.OCustomItemNames;
                List<String> Buildings = Main.Buildings;
               
                if(title.contains("Storage")){
                   
                }
                   
                if(title.contains("Input")){
                String Buildingname = title.replace(" Input:","");
     
               
                if(Buildings.contains(Buildingname)){
                   
                int pos = Buildings.indexOf(Buildingname);
                final String[] InputMatsplt = FInputMaterials.get(pos).split(",");
                final String[] Icustomitemsplt = ICustomItemNames.get(pos).split(",");
               
                int min = 1;
               
                if(InputMatsplt.length == 1){
                min--;   
                }
               
                for(int i=0;i<=(Math.floor(InputMatsplt.length/2)-min);i++){
               
                Material mat = Material.getMaterial(InputMatsplt[i]);
                String custom_name = Icustomitemsplt[i];
             
                    if(event.getCurrentItem().getType() == mat){
                       
                      if(!custom_name.equalsIgnoreCase("nothing")){
                      if(event.getCurrentItem().getItemMeta().getDisplayName() != null){
                      if(!custom_name.equalsIgnoreCase(event.getCursor().getItemMeta().getDisplayName())){
                        event.setCancelled(true);   
                      }
                      return;
                      }
                      else{
                          event.setCancelled(true);   
                        return; 
                      }
                    }
                    }
                    else{
                        event.setCancelled(true);   
                        return;
                    }
               
                }   
                }
                }
    -snip-
    
     
  2. Offline

    fireblast709

    JeroenV besides cancelling, use event.setResult(Event.Result.DENY);
     
Thread Status:
Not open for further replies.

Share This Page