Solved How do I check if an my event was completed? (Read post to understand)

Discussion in 'Plugin Development' started by MCnumi, Jun 22, 2016.

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

    MCnumi

    So I'm looking to check and see if my InventoryClickEvent event (which is inside another class) has been completed in order to continue the code in my command class, how would I do that?

    Here is my command class:
    Command (open)

    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            Player p = (Player) sender;
            String xp = ChatColor.DARK_GRAY + "[" + ChatColor.GREEN + ChatColor.BOLD + "XPBasics" + ChatColor.DARK_GRAY + "] ";
            Random generator = new Random();
            int rannum = generator.nextInt(50);
            int amount = 0;
            if(cmd.getName().equalsIgnoreCase("XPslots")) {
                if(sender instanceof Player) {
                    if(sender.hasPermission("XPBasics.slots")) {
                        try
                        {
                            amount = Integer.parseInt(args[0]);
                        }catch (Exception ex)
                        {
                            p.sendMessage(xp + ChatColor.GRAY + "You must enter a number!");
                            return true;
                        }
                        p.openInventory(ConfirmationInventory.myInventory);


    Here is my EventHandler/Listener class:
    Event (open)

    Code:
        public static Inventory myInventory = Bukkit.createInventory(null, 9,
                "Confirmation");
    
        static {
            myInventory.setItem(0, new ItemStack(Material.DIAMOND_BLOCK, 1,
                    (byte) 5));
            myInventory.setItem(8, new ItemStack(Material.REDSTONE_BLOCK, 1,
                    (byte) 14));
    
        }
    
        @EventHandler
        public static void onInventoryClick(InventoryClickEvent event) {
            Player player = (Player) event.getWhoClicked();
    
            ItemStack clicked = event.getCurrentItem();
            Inventory inventory = event.getInventory();
    
            if (inventory.getName().equals(myInventory.getName())) {
    
                if (clicked.getType() == Material.DIAMOND_BLOCK) {
              
                    event.setCancelled(true);
    
                    player.closeInventory();
                } else if (clicked.getType() == (Material.REDSTONE_BLOCK)) {
                    player.sendMessage(ChatColor.DARK_GRAY + "[" + ChatColor.GREEN
                            + ChatColor.BOLD + "XPBasics" + ChatColor.DARK_GRAY
                            + "] " + "Command Cancelled");
                }
            }
        }


    So in a nutshell, I want it to see if the player clicked on the diamond block, if so, return to the command and continue as normal, and if he clicked on the redstone it would stop the command.

    Thanks.
     
  2. Offline

    MadMaxCookie

    use List or hashmap.
     
  3. Offline

    567legodude

    Can't you just create a method with the things you want to happen after the event?
    Then when the event happens, just call the method of things you want to happen after.
    (Assuming the inventory can only be opened by using the command)
     
  4. Offline

    MCnumi

    Never mind. Fixed, please lock.
     
    Last edited: Jun 22, 2016
  5. Offline

    Lordloss

    @MCnumi please edit your thread and mark as solved.
     
Thread Status:
Not open for further replies.

Share This Page