Solved Random location in WE selection

Discussion in 'Plugin Development' started by Awesomebanana2002, Jul 27, 2015.

Thread Status:
Not open for further replies.
  1. Dear,
    I've been working on a survival games plugin, and I've been started to implementing supply drops, but I don't have a clew how I can get a random location in a Selection of an arena.
    Please help :D
     
  2. Offline

    mine-care

    @Awesomebanana2002 please show us what you have tried so far. Also umm do you have the two diagonal locations to define the arena or you have all the locations?
     
  3. @mine-care I found a way to loop through the x and z of a WorldEdit selection, but I dont know how to pick a random x and z :/ This is what I have so far:
    Code:
        public static Location getRandomLocation(Selection s) {
            Random r = new Random();
           
            Vector min = s.getNativeMinimumPoint();
            Vector max = s.getNativeMaximumPoint();
           
            for(int x = min.getBlockX(); x <= max.getBlockX(); x++) {
                for(int z = min.getBlockZ(); z <= max.getBlockZ(); z++) {
                   
                }
            }
           
            return null;
        }
    Nevermind.. I fixed it at my own. Here is the code for everyone who's wondering:

    Code:
        public static Location getRandomLocation(Selection s) {
            Random r = new Random();
           
            Vector min = s.getNativeMinimumPoint();
            Vector max = s.getNativeMaximumPoint();
           
            int x = r.nextInt(max.getBlockX() - min.getBlockX()) + min.getBlockX();
            int z = r.nextInt(max.getBlockZ() - min.getBlockZ()) + min.getBlockZ();
            int y = s.getWorld().getHighestBlockYAt((int) x, (int) z);
           
            return new Location(s.getWorld(), x, y, z);
        }
    <Edited by bwfcwalshy: Merged posts, please use the edit button rather than double posting.>
     
    Last edited by a moderator: Jul 28, 2015
Thread Status:
Not open for further replies.

Share This Page