Unriding A player?

Discussion in 'Plugin Development' started by billofbong, Dec 17, 2011.

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

    billofbong

    Right, what I want is to unride the player that I previously rode. Here's what I got so far:

    Code:
        public void onEnable() {
            getCommand("ride").setExecutor(new CommandExecutor() {
    
                public boolean onCommand(CommandSender cs, Command cmnd, String alias, String[] args) {
                   if(args.length == 1) {
                   Player target = getServer().getPlayer(args[0]);
                   if(target != null) {
                    Player sender = (Player)cs;
                    Entity senderEntity = (Entity)sender;
                    target.setPassenger(senderEntity);
                   }
                   else{
                    cs.sendMessage(ChatColor.RED + "Player not found!");
                   }
                   } else {
                    cs.sendMessage(ChatColor.RED + "Usage: /ride <player>");
                    return false;
                   }
    
      
                    return true;
                }
            });
    
            getCommand("unride").setExecutor(new CommandExecutor() {
    
                public boolean onCommand(CommandSender cs, Command cmnd, String alias, String[] args) {
                   if(args.length == 1) {
                   Player target = getServer().getPlayer(args[0]);
                     if(target != null) {
                       target.setPassenger(null);
                       cs.sendMessage(ChatColor.GREEN + "Unrode player!");
                     }
                   else{
                       cs.sendMessage(ChatColor.RED + "Player not found!");
                     }
                     }
                   else {
                    cs.sendMessage(ChatColor.RED + "Usage: /unride <player>");
                    return false;
                   }
     
                    return true;
                }
            });
            System.out.println(this + " is now enabled!");
        }
    Thanks,

    Billofbong :D
     
  2. Offline

    billofbong

    OH THANKS!

    But one more thing:

    How would I eject without an argument of a player?

    I've got this, but it doesn't work:

    Code:
            getCommand("unride").setExecutor(new CommandExecutor() {
    
                public boolean onCommand(CommandSender cs, Command cmnd, String alias, String[] args) {
                   if(args.length == 0) {
                   Player send = (Player)cs;
                   if(send.getVehicle() instanceof Player) {
                   Player target = (Player) send.getVehicle();
                   target.eject();
                   cs.sendMessage(ChatColor.GREEN + "Unrode player!");
    
                   }
                   else{
                       cs.sendMessage("You are not riding on a player!");
                   }
     
                   }
                   else {
                    cs.sendMessage(ChatColor.RED + "Usage: /unride");
                    return false;
                   }
     
                    return true;
                }
            });
     
  3. Offline

    md_5

    @billofbong
    Code:
    target.eject(target.getPassenger());
     
Thread Status:
Not open for further replies.

Share This Page