Vault probelm (command plugin)

Discussion in 'Plugin Development' started by 6zero, Sep 6, 2019.

  1. Offline

    6zero

    Code:
        public static Economy econ = Balance.econ;
        public static EconomyResponse r;
    
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    
            Player p = (Player) sender;
    
            if (args[0].equalsIgnoreCase("add")) {
                if (sender instanceof Player) {
    
                    Player target = Bukkit.getPlayer(args[1]);
                    int balance = (int) econ.getBalance(target);
                    r = econ.depositPlayer(p.getPlayer(), balance);
    
                    p.sendMessage(ChatColor.GREEN + "Dodatles" + balance);
    
                }
    
            }
    
            return true;
        }
    }
     
  2. Offline

    timtower Moderator Moderator

    @6zero And what is the issue?
     
  3. Offline

    KarimAKL

    @6zero
    1. You are not checking "args" length before you try to get something from it.
    2. You are not checking if "target" is null before using it.
    Do you have any other problems?
     
  4. Offline

    6zero

    i have problem with this:
    Code:
    Player target = Bukkit.getPlayer(args[1]);
    The method getPlayer(String) from the type Bukkit is deprecated

    Code:
        if (sender instanceof Player) {
                Player p = (Player) sender;
    
                if (cmd.getName().equalsIgnoreCase("add")) {
                    if (args.length == 3) {
                        try {
    
                            Player target = Bukkit.getPlayer(args[0]);
                            int deposit = Integer.parseInt(args[1]);
                           
                            if(target != null ) {
                                econ.depositPlayer(target, deposit);
                                p.sendMessage("tykurwp");
                               
                            }
    
                           
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
    
                    }
                }
            }
    
            return true;
    
        }
    }
    
    }
     
    Last edited: Sep 7, 2019
  5. Offline

    timtower Moderator Moderator

    @6zero Just ignore it, nothing wrong with the method.
     
  6. Offline

    6zero

    But it doesn't work, I don't have a bug in the console, but if I write "/ add" nothing happens
     
  7. Offline

    timtower Moderator Moderator

    @6zero And what command are you calling then? Having a space as command doesn't work.
     
  8. Offline

    KarimAKL

    @6zero Deprecated doesn't mean there's anything wrong with it, and there's no other way to get the player from the name, just ignore it as @timtower said before.
    What is your desired command? "/add (player)" or "/something add (player)"?
     

Share This Page