Development Assistance Teleport Command is not working

Discussion in 'Plugin Help/Development/Requests' started by Phai_, Aug 6, 2017.

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


    Hello my Tp Command is not working i tryed it ingame no error in Console its one of my first commands.
    public class Tp implements CommandExecutor {
        private Main plugin;
        public Tp(Main plugin) {
               this.plugin = plugin;
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
               Player p = (Player) sender;
               String playerName = p.getName();
               if(p.hasPermission("")) {
                   if(args.length == 0 ) {
                      p.sendMessage(Main.prefix + "§6/Tp <Spieler> zu <Spieler>");
                   } else if(args.length == 1) {
                       Player targetPlayer = Bukkit.getServer().getPlayer(args[0]);
                       String targetName = targetPlayer.getName();
                      Location t1 = targetPlayer.getLocation();
                       p.sendMessage(Main.prefix + "Du wurdest zu" + targetName + " teleportiert.");
               } else {
                   p.sendMessage(Main.prefix + "§cKeine Rechte!");
                      p.playSound(p.getLocation(), org.bukkit.Sound.ANVIL_LAND, 1.0F, 1.0F);
                   if(args.length == 2) {
                       Player von = Bukkit.getServer().getPlayer(args[0]);
                       String fn = von.getName();
                       Player zu = Bukkit.getServer().getPlayer(args[1]);
                       String tn = zu.getName();
                       Location t1 = zu.getLocation();
                       von.sendMessage(Main.prefix + "§4Du wurdest teleportiert");
                       zu.sendMessage(Main.prefix + "§4Du wurdest teleportiert");
                   } else if(args.length >2) {
                       p.sendMessage(Main.prefix + "§cZu viele Argumente");
            return false;
    please help me.
  2. Offline


    1. Have you registered the executor?
    2. Don't blindly cast sender to a player. Consoles and command blocks can send commands, so you need to check if the sender is a player before you cast it.
    3. targetPlayer can be null if the player is not online/ does not exist. Null check targetplayer before you get their name.
    4. The last if statement, for args length == 2, you do not check for the player's permission. You may want to move this into the args length check above.
Thread Status:
Not open for further replies.

Share This Page