Need help with a plugin idea

Discussion in 'Plugin Development' started by CantBeCharged, Jan 10, 2015.

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


    Hey, I thought of a cool idea. So, basically your name just changes a color within x amount of blocks. But i've been having trouble checking if someones within x blocks and getting a list of those players. Any ideas?
  2. Offline


    @CantBeCharged Location#distance(Location)

    EDIT: Wait you only want distance for x?
  3. Offline


    for(Player p : Bukkit.getServer().getOnlinePlayers()){
         Location l = p.getLocation();
         if(l.distance(LOCATION_TO_DISTANCE_FROM) > 10){
              //DO STUFF
  4. Offline


    Hey, I never heard of l#distance, and the docs don't really make it clear.. DO you know how to use it?
  5. Offline


  6. Offline


    "uses a costly square-root function"
    Not sure if I should really use this?
  7. Offline


    Depends how many players you are doing per second. I honestly think this should be removed from the javadoc because it is very misleading considering most modern processors can do this within nanoseconds. If you aren't running this in a repeating task running every tick or in an event like PlayerMoveEvent you are perfectly fine using the distance method.

    If however you are not actually telling the player this value, and only comparing it against another, you can avoid the square root call by using distanceSquared(), which does not perform the square root computation. This saves you a tiny amount of time but further reduces your plugin's footprint and I would recommend it where possible. All you have to do is square the constant you're comparing it against. So, if you are checking if someone is less than 16 blocks away, check if distanceSquared() is less than 16 * 16 (256 but the compiler does this for you anyways).
  8. Offline


            Player[] players = Bukkit.getOnlinePlayers();
            double radiusSquared = radius*radius;
            for (int i = 0; i < players.length; i++) {
                if(players[i].getLocation().distanceSquared(location) <= radiusSquared){
    Like this?

    Also would you know how to use Tag Api?
  9. Offline



    Their documentation is pretty self explanatory, what's the issue you're having?
  10. Offline


  11. Offline


  12. Offline


    Yes. TagApi is not iTag.

    I've decided not to use iTag..

    I need to find out a way to change a players name, only for a specific player.
    Ex: There's Johnny, Thomas, and Bob. Johnny sees Thomas as Tom, but Bobby sees Thomas as Tommy.
    How would I do this? I don't think its actually possible.
Thread Status:
Not open for further replies.

Share This Page