Is It Me? Or Are Command Arguments Broken?

Discussion in 'Plugin Development' started by eleectricman226, Jun 7, 2014.

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

    eleectricman226

    So, I Am Having a Bit Of Trouble With Arguments. I Have Used Them Before, But Updating To 1.7.9 R3, They Just Don't Work. Did They Change?

    Code I'm Using:

    Code:java
    1. @SuppressWarnings("deprecation")
    2. public boolean onCommand(CommandSender sender, Command command,String label, String[] args) {
    3. Player player = (Player) sender;
    4. if(label.equalsIgnoreCase("currency")){
    5. player.sendMessage(ChatColor.BLUE + "[Currency] " + ChatColor.RED + "You Have " + ChatColor.AQUA + Money.getCurency(player) + ChatColor.DARK_PURPLE + " Titanium!");
    6. }else if(label.equalsIgnoreCase("currency") && args[0].equalsIgnoreCase("give")){
    7. if(args.length < 3){
    8. player.sendMessage(ChatColor.BLUE + "[Currency] " + ChatColor.RED + "Not Enough Args!");
    9. return false;
    10. }else if(Bukkit.getPlayer(args[1]) == null){
    11. player.sendMessage(ChatColor.BLUE + "[Currency] " + ChatColor.RED + "Player Not Online!");
    12. return false;
    13. }else if(args[2].matches("^[a-zA-Z0-9]*$")){
    14. player.sendMessage(ChatColor.BLUE + "[Currency] " + ChatColor.RED + "Invalid Currency Ammount!");
    15. }else{
    16. try {
    17. bf = new BufferedWriter(new FileWriter(new File(getDataFolder() + player.getName())));
    18. } catch (IOException e) {
    19. // TODO Auto-generated catch block
    20. e.printStackTrace();
    21. }
    22. try {
    23. bf.write(args[2]);
    24. } catch (IOException e) {
    25. // TODO Auto-generated catch block
    26. e.printStackTrace();
    27. }
    28. }
    29. }
    30. return false;
    31. }
     
  2. Offline

    HeadGam3z

    Any stack traces?
     
  3. Offline

    L33m4n123

    well you're checking for arguments before even making sure there is one argument. thats one issue. Then the way you built your logic the else if statement will never be called

    Code:
    if (labe.equalsIgnoreCase("currency")) {
      //if the command is currency it goes into this here
    } else if {
     //otherwise here
    }
     
    xTigerRebornx likes this.
Thread Status:
Not open for further replies.

Share This Page