Confirmation Kit: Yes/No Help

Discussion in 'Plugin Development' started by VinexAx789, Dec 15, 2015.

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

    VinexAx789

    What I want to do is when a player selects a kit that is worth money they get the a message saying Would you like to purchase this kit? Please type: Either Yes or No.

    Code:

    Code:
    @EventHandler
        public void selectkist(InventoryClickEvent event) {
            if (event.getInventory() != null
                    && event.getInventory().getTitle() != null
                    && event.getInventory().getTitle()
                            .equals(kitinventory.getTitle())) {
                if (event.getCurrentItem() != null) {
                    Player player = (Player) event.getWhoClicked();
                    if (players.contains(player)) {
                        if (event.getCurrentItem().getItemMeta().getDisplayName()
                                .toLowerCase().contains("juggernaut")) {
                            if (getConfig().getBoolean(
                                    player.getUniqueId() + ".JuggKit")) {
                                player.sendMessage("§9Now using kit Juggernaut");
                                player.playSound(player.getLocation(),
                                        Sound.IRONGOLEM_HIT, 20, 0);
                                player.playSound(player.getLocation(),
                                        Sound.BLAZE_HIT, 30F, 30F);
                                kitselected.remove(player);
                                kitselected.put(player, "juggernaut");
                                event.setCancelled(true);
                                player.closeInventory();
                                return;
                            }
                            EconomyResponse r = econ1.withdrawPlayer(
                                    player.getName(), 900);
                            if (r.transactionSuccess()) {
                                player.sendMessage(ChatColor.GREEN
                                        + "You have purchased kit Juggernaut!");
                                player.playSound(player.getLocation(),
                                        Sound.LEVEL_UP, 30F, 30F);
                                getConfig().set(player.getUniqueId() + ".JuggKit",
                                        true);
                                saveConfig();
                                kitselected.remove(player);
                                kitselected.put(player, "juggernaut");
                                event.setCancelled(true);
                                player.sendMessage("§9Now using kit Juggernaut");
                                player.playSound(player.getLocation(),
                                        Sound.IRONGOLEM_HIT, 20, 0);
                                player.closeInventory();
                                return;
                            } else {
                                player.sendMessage(ChatColor.RED
                                        + "You do not have enough Credits check /bal §4§l[KIT COST 900 Credits]");
                                return;
                            }
                        }
                    }
                }
            }
        }
    
        @EventHandler
        public void onConfirmation(AsyncPlayerChatEvent e) {
            Player p = e.getPlayer();
            if (confirmationlist.contains(p)) {
                if (e.getMessage().contains("yes")) {
                    if (getConfig().getBoolean(p.getUniqueId() + ".JuggKit")) {
                        p.sendMessage("§9Now using kit Juggernaut");
                        p.playSound(p.getLocation(), Sound.IRONGOLEM_HIT, 20, 0);
                        p.playSound(p.getLocation(), Sound.BLAZE_HIT, 30F, 30F);
                        kitselected.remove(p);
                        kitselected.put(p, "juggernaut");
                        e.setCancelled(true);
                        p.closeInventory();
                        return;
                    }
                    EconomyResponse r = econ1.withdrawPlayer(p.getName(), 900);
                    if (r.transactionSuccess()) {
                        p.sendMessage(ChatColor.GREEN
                                + "You have purchased kit Juggernaut!");
                        p.playSound(p.getLocation(), Sound.LEVEL_UP, 30F, 30F);
                        getConfig().set(p.getUniqueId() + ".JuggKit", true);
                        saveConfig();
                        kitselected.remove(p);
                        kitselected.put(p, "juggernaut");
                        e.setCancelled(true);
                        p.sendMessage("§9Now using kit Juggernaut");
                        p.playSound(p.getLocation(), Sound.IRONGOLEM_HIT, 20, 0);
                        p.closeInventory();
                    } else if (e.getMessage().equalsIgnoreCase("No")) {
                        p.sendMessage(ChatColor.RED
                                + "Purchase failed user said: No");
                    }
    
                }
            }
        }
     
  2. Offline

    Irantwomiles

    @VinexAx789 What exactly is the problem. From just looking at the code I could see one possible error (could be wrong though). In your ChatEvent where you have it to e.getMessage().contains("yes") couldn't I just type yes no in the same line? How would that work.
     
  3. Offline

    VinexAx789

    @Irantwomiles I guess the problem is I'm not too sure how to implement it to work with selectkit method.
     
  4. Offline

    mythbusterma

    @VinexAx789

    Instead, a good way of doing this would be a HashMap consisting of UUIDs and Runnables, put someone in there when they press the button, and check to see if they're in the Map when they type "yes," then run the runnable associated with them. This would allow you to do ask them about anything and have it work.
     
  5. Offline

    teej107

  6. Offline

    Irantwomiles

    never even used it before tbh or even heard of it

    @VinexAx789 Well I hadn't heard of the conversation api like @teej107 said but after watching the first 10 seconds of this video it looks like the perfect thing for what you want to do. Here is the link

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Dec 17, 2015
  7. Offline

    VinexAx789

  8. Offline

    Irantwomiles

    VinexAx789 likes this.
  9. Offline

    VinexAx789

Thread Status:
Not open for further replies.

Share This Page