Solved Event not trigger :c

Discussion in 'Plugin Development' started by BoBsmil3Y, Jan 5, 2019.

  1. Offline

    BoBsmil3Y

    Hello all,

    That my first post, and first try to make a Java plugin !

    I want to recreated a trade plugin to train and use it on my server. So I have this code :
    Code:
    import org.bukkit.*;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.inventory.InventoryClickEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    
    public class CommandMenu implements CommandExecutor, Listener {
    
        private int moneyTradep1 = 0;
        private int maxTradableMoney = 100000;
    
        @Override
        public boolean onCommand(CommandSender commandSender, Command command, String label, String[] args) {
    
            if(label.equals("meow")){
    
                if(args.length == 0){
                    if(commandSender instanceof Player){
                        final Player player = (Player)commandSender;
                        final World world = player.getWorld();
                        Inventory menup1 = Bukkit.createInventory(null, 54,"§8Trades");
    
                        world.playSound(player.getLocation(), Sound.ENTITY_CAT_AMBIENT, 1.0F,1.0F);
    
                        menup1.setItem(4, setSeparator());
                        menup1.setItem(13, setSeparator());
                        menup1.setItem(22, setSeparator());
                        menup1.setItem(31, setSeparator());
                        menup1.setItem(40, setSeparator());
                        menup1.setItem(49, setSeparator());
    
                        menup1.setItem(45, setRemMoney());
                        menup1.setItem(46, setAddMoney());
    
    
                        player.openInventory(menup1);
    
                    }
                } else {
                    commandSender.sendMessage(ChatColor.RED + "Votre commande à trop d'arguments");
                }
    
                return true;
            }
    
            return false;
        }
    
    
        @EventHandler
        public void onInventoryClick(InventoryClickEvent event){
            Inventory inv = event.getInventory();
            Player player = (Player) event.getWhoClicked();
            ItemStack item = event.getCurrentItem();
            final World world = player.getWorld();
    
            if(item == null) return;
    
            // If menu trades
            if(inv.getName().equalsIgnoreCase("§8Trades")){
    
                event.setCancelled(true);
    
                switch(item.getType()){
    
                    case GREEN_STAINED_GLASS_PANE:
                        world.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1.0F,1.0F);
                        if (moneyTradep1 >= maxTradableMoney){
                            world.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_HURT, 1.0F,1.0F);
                            player.sendMessage("Tu ne peux pas mettre plus d'argent! Le maximum est " + maxTradableMoney);
                        } else{
                            moneyTradep1 += 1000;
                        }
                        break;
    
                    case RED_STAINED_GLASS_PANE:
                        world.playSound(player.getLocation(), Sound.BLOCK_ANVIL_PLACE, 1.0F,1.0F);
                        if (moneyTradep1 > 1000){
                            moneyTradep1 -= 1000;
                        } else {
                            world.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_HURT, 1.0F,1.0F);
                            player.sendMessage("Il n'y a pas d'argent ! Tu ne peux en retirer plus !");
                        }
                        break;
                    default:
                        world.playSound(player.getLocation(), Sound.ENTITY_VILLAGER_HURT, 1.0F,1.0F);
                        player.sendMessage("Tu ne peux pas prendre ces blocs !");
                        break;
                } //End switch
    
            }//End if inv is trade menu
    
        }//End method
    
    
        public ItemStack setSeparator(){
            ItemStack it = new ItemStack(Material.GRAY_STAINED_GLASS_PANE, 1);
            ItemMeta itM = it.getItemMeta();
            itM.setDisplayName(" ");
            it.setItemMeta(itM);
            return it;
        }
    
        public ItemStack setAddMoney(){
            ItemStack it = new ItemStack(Material.LIME_STAINED_GLASS_PANE, 1);
            ItemMeta itM = it.getItemMeta();
            itM.setDisplayName("§a+ 1000$");
            it.setItemMeta(itM);
            return it;
        }
        public ItemStack setRemMoney(){
            ItemStack it = new ItemStack(Material.RED_STAINED_GLASS_PANE, 1);
            ItemMeta itM = it.getItemMeta();
            itM.setDisplayName("§c- 1000$");
            it.setItemMeta(itM);
            return it;
        }
    }
    
    and the event doesn't work ... I don't have idea concerning why it's not trigger ...

    If you can help me, I will appreciate any idea !

    Cordialy,
    BoBsmil3Y
     
  2. Offline

    timtower Ninja on the waves Moderator

  3. Offline

    BoBsmil3Y

    probably not :c

    And it's work :rolleyes: Thanks !

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jan 5, 2019

Share This Page