Solved args[0] as a player?

Discussion in 'Plugin Development' started by Rmarmorstein, Dec 10, 2012.

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

    Rmarmorstein

    I want to be able to have staff set another users prefix. The command is /setprefix <user> <Name Color> <preifx>

    Here is my code:

    Code:java
    1. package us.rivertech.ezdonor;
    2.  
    3. import org.bukkit.command.Command;
    4. import org.bukkit.command.CommandExecutor;
    5. import org.bukkit.command.CommandSender;
    6. import org.bukkit.entity.Player;
    7.  
    8. public class SetPrefixExecuter implements CommandExecutor {
    9.  
    10. @Override
    11. public boolean onCommand(CommandSender cdsend, Command cmd1, String label,
    12. String[] args) {
    13. if (label.equalsIgnoreCase("setprefix")){
    14. System.out.println("ezDonor Prefix Changed For: " + args[0] + "To" + args[2]);
    15. ezDonor.chat.setPlayerPrefix((Player)args[0], "&f[" + args[2] + "&f]" + args[1]);
    16. }
    17.  
    18. return false;
    19. }
    20.  
    21. }


    Thanks for the help, i know i am not complete with the code, i just like to take it a step at a time. ;)
     
  2. Offline

    tommycake50

    Bukkit.getPlayer(args[0]);
     
  3. Offline

    ZeusAllMighty11 Retired Staff

    Code:
    package us.rivertech.ezdonor;
     
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
     
    public class SetPrefixExecuter implements CommandExecutor {
     
        @Override
        public boolean onCommand(CommandSender cdsend, Command cmd1, String label,
                String[] args) {
            if (cmd1.getName().equalsIgnoreCase("setprefix")){
                if(sender instanceof Player){
                    
                    if(args.length >= 2){
                        
                        Player target = sender.getServer().getPlayer(args[0]);
                        
                        if(args[0].equalsIgnoreCase(target)){
                        
                            target.setDisplayName(args[1] + target.getDisplayName );
                        
                        }
                    
                    } else {
                    sender.sendMessage(ChatColor.RED + " Incorrect format. /setprefix user prefix ");
                    }
                
                } else {
                sender.sendMessage(ChatColor.RED + " You must be a player to do this! ");
                }
                
            }
     
            return false;
        }
     
    }
    
     
  4. Offline

    Rmarmorstein

    It wants me to change the type of args to player, but i need the args for the prefix?

    fixed thanks
     
  5. Offline

    skipperguy12

    Mark as solved please?
     
Thread Status:
Not open for further replies.

Share This Page