Compass Tracker in Teams

Discussion in 'Plugin Development' started by Skrarity, Jan 24, 2015.

Thread Status:
Not open for further replies.
  1. So I have two Problems.
    1. My Code isn't working! (lol idk y)
    2. I have to add something

    So at the end of this Thread you can see the code dont worry.
    To my first problem; I dont know, if I am entering ("/track") it should track if i have 15 levels , than they should remove it. The Tracker should show the nearest Player in the map (online Player*)

    To the second: I want to make Teams of 2 (I dont have any arraylist yet) and i d be able to add every single player to a arraylist with his team partner , but i just want that I can't track my team member (But because other players are in other teams i just can't choose one player who won't get tracked)
    :S I dont know how is should do it

    SRY FOR MY BAD ENGLISH
    EDIT = The "if target = null" thing should check if there isn't a player online to track / a player who isnt in your team is offline)

    Here the code (Ignore the Strings
    Code:
      
        @Override
        public boolean onCommand(CommandSender cs, Command cmd, String label,String[] args) {
            if(!(cs instanceof Player)) {
                cs.sendMessage(mcrotxt + "Du kannst diesen Befehl nur als Spieler aussenden!");
              
            }
            Player p = (Player)cs;
          
            //Track
            Player target = getNearestPlayer(p);
            if(target == null) {
                p.sendMessage(ChatColor.GRAY + "[" + ChatColor.RED + "Mcro" + ChatColor.GRAY + "] Kein Spieler kann getracked werden!");
            }
          
      
            if(p.getLevel() < 15){
                    p.sendMessage(ChatColor.GRAY + "[" + ChatColor.RED + "Mcro" + ChatColor.GRAY + "] Du hast nicht genĂ¼gend XP!");
                        }
          
            p.sendMessage(mcrotxt + "Dein Kompass zeigt auf " + ChatColor.RED + getNearestPlayer(p).getName());
            p.setLevel(-15);
            p.sendMessage(mcrotxt + "Du hast dabei 15 Level verloren!");
            p.sendMessage(mcrotxt + getNearestPlayer(p).getName() + "'s Koordinaten sind: ");
            p.sendMessage(X + getNearestPlayer(p).getLocation().getBlockX() + " " + Y + getNearestPlayer(p).getLocation().getBlockY() + " " + Z + getNearestPlayer(p).getLocation().getBlockZ());
            p.setCompassTarget(getNearestPlayer(p).getLocation());
          
          
            return true;
        }
      
        public Player getNearestPlayer(Player p ) {
          
            double distance = Double.MAX_VALUE;
            Player target = null;  
          
            for(Entity entity : p.getNearbyEntities(8000,8000,8000)) {
                if(entity instanceof Player) {
                  
                    double dis = p.getLocation().distance(entity.getLocation());
                  
                    if(dis < distance) {
                        distance = dis;
                        target = (Player) entity;
                    }
                  
                }
              
            }
            return target;
        }
     
Thread Status:
Not open for further replies.

Share This Page