World border info

Discussion in 'Spigot Plugin Development' started by suitinacow, Jul 5, 2015.

  1. So I'm trying to make a random teleport plugin and I need to check my world border coordinations for each of my worlds so i can calculate a position to random teleport inside the borders.. do you guys know a way to get that information out of the world border plugin for each world?
     
  2. you can use the getWorldBorder() in the world class. And that returns all the data about the world border. And to get all the worlds, you use Bukkit.getWorlds()
     
  3. my code looks something like this:
    Code (Text):
    if(cmd.getName().equalsIgnoreCase("rtp")){
                if(player instanceof Player){
                    getWorldBorder().Bukkit.getWorld(args[0]);
                   
                }
                return true;
            }
    it gives me an error asking me to make a method for getWorldBorder.
     
  4. the getWorldBorder() method is in the world class, so you first need to get the world and then call the getWorldBorder()
     
  5. yeah i realized that right after i posted it.. i assume there is more than one piece of information in here so how do i store it so i can calculate the random position to teleport the player?
     
  6. You create a world border variable and set it to the getWorldBorder() and then you can just change the world border from that variable
     
  7. Im not sure i follow when you say "world border variable"
     
  8. To get the location you just use the getSize and devide it by 2 and remove it from the center location, and then you have the minimum location that you can teleport people from and then the maximum location would be the size devided by 2 and add it to the center
    so you can do like for the x
    Code (Text):
    double x = minLocation.getX() + random.nextInt(worldBorder.getSize());
    random would be the random class, and you can then just do it for the z.
    With world border variable I mean
    Code (Text):
    WorldBorder worldBorder = getWorldBorder
    and getWorldBorder would be getting the world border
     
  9. Code (Text):
                    WorldBorder wB = Bukkit.getServer().getWorld(args[0]).getWorldBorder();
                    WorldBorder minLocation = ((wB.getSize())/2) - wB.getCenter();
                    WorldBorder maxLocation = ((wB.getSize()/2)) + wB.getCenter();
                    double x = minLocation.getX() + r1.nextInt((int) wB.getSize());
                    double z = minLocation.getZ() + r1.nextInt((int) wB.getSize());
                    double x1 = maxLocation.getX() + r1.nextInt((int) wB.getSize());
                    double z1 = maxLocation.getZ() + r1.nextInt((int) wB.getSize());
    does this seem right?
     
  10. the max location and x1 and z1 is not necessary, and to get the y you just use the getHighestBlockYAt(x,z); in the world class and then add 1 to it, and there you got the location.
     
  11. Sorry i made another thread.. Wasn't sure if you were still here..

    I'm getting errors for this
    Code (Text):
    WorldBorder minLocation = ((wB.getSize())/2) - wB.getCenter();
    And why dont i need the maxLocation? you told me i need minlocation and maxlocation
     
  12. the max location was a mistake from me, and you use the - token, you don't do that, you just do wb.getCenter().substract(x,y,z) and for the x y and z all just use the wb.getSize() / 2
     
  13. I'm sorry but can you try rephrasing that I just cant understand what your trying to explain to me.. are you saying that i should do this:

    Code (Text):
                    WorldBorder wB = Bukkit.getServer().getWorld(args[0]).getWorldBorder();
                    double x = wB.getSize()/2;
                    double y = wB.getSize()/2;
                    double z = wB.getSize()/2;
                    WorldBorder minLocation = (WorldBorder) wB.getCenter().subtract(x,y,z);
     
  14. yes that's what you should do to get the minimum location, but it could be that the size is from the center to the edge, instead what I think that it is is that it's from edge to edge. So if it's from the center to the edge then you don't need to do that divide by 2
     
  15. so i would divide by 2 and add random number
     
  16. you just use this
    double x = minLocation.getX() + r1.nextInt((int) wB.getSize());
    double z = minLocation.getZ() + r1.nextInt((int) wB.getSize());
    to get the x and z and use the getHighestBlockYAt(x,z); in the world class to get the x y and z to where you want the player to teleport to
     
  17. But that doesnt make sense because i already made double x and z before i made minLocation
     
  18. then you just change the variable names
     
  19. Code (Text):
    if(cmd.getName().equalsIgnoreCase("rtp")){
                if(player instanceof Player){
                    WorldBorder wB = Bukkit.getServer().getWorld(args[0]).getWorldBorder();
                    WorldBorder center = (WorldBorder) wB.getCenter();
                    int one = r1.nextInt((int) wB.getSize());
                    int two = (r1.nextInt((int) wB.getSize()))*-1;  
                    int chance = r1.nextInt(5);
                    int y = 0;
                    if(chance == 0){
                        ((Location) center).subtract(one,y,one);
                    }
                    if(chance == 1){
                        ((Location) center).add(one,y,one);
                    }
                    if(chance == 2){
                        ((Location) center).subtract(two,y,two);
                    }
                    if(chance == 3){
                        ((Location) center).add(two,y,two);
                    }
                    player.teleport((Location) center);
                }
                return true;
            }
     
  20. You don't cast center to WorldBorder, center is a location. center needs to be a location instead of a worldBorder