Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. public class RandomSpawnManager {
  2.  
  3.     private final RandomSpawn plugin;
  4.     private final Logger logger;
  5.     private final Random random;
  6.     private final HashMap<UUID, List<Location<World>>> spawns;
  7.     private int min, max;
  8.  
  9.     RandomSpawnManager(RandomSpawn plugin) {
  10.         this.plugin = plugin;
  11.         this.logger = plugin.getLogger();
  12.         this.random = new Random();
  13.         this.spawns = new HashMap<>();
  14.     }
  15.  
  16.     void init(ConfigurationLoader<CommentedConfigurationNode> localLoader) {
  17.         try {
  18.             ConfigurationOptions options = ConfigurationOptions.defaults()
  19.                     .setShouldCopyDefaults(true);
  20.             CommentedConfigurationNode node = localLoader.load(options);
  21.             this.min = (int) node.getNode("spawnArea", "min").getValue(1500);
  22.             this.max = (int) node.getNode("spawnArea", "max").getValue(3000);
  23.             localLoader.save(node);
  24.         } catch (IOException e) {
  25.             this.logger.warn("Error saving default config!", e);
  26.         }
  27.     }
  28.  
  29.     public void generationSpawnLocations(Player p) {
  30.         List<Location<World>> locs = new ArrayList<>();
  31.  
  32.         for (int i = 0; i < 3; i++) {
  33.             Location<World> loc = this.getRandomLocation(p.getWorld());
  34.             locs.add(loc);
  35.             this.logger.info("loc: " + loc.getBlockX() + ", " + loc.getBlockY() + ", " + loc.getBlockZ());
  36.         }
  37.  
  38.         this.spawns.put(p.getUniqueId(), locs);
  39.         this.logger.info("p.setLocationSafely(loc)" + p.setLocationSafely(locs.get(0)));
  40.     }
  41.  
  42.     public void toSpawn(Player p, int index) {
  43.         this.logger.info("p: " + p.getName() + ", index: " + index);
  44.         Location<World> location = this.spawns.get(p.getUniqueId()).get(index);
  45.         this.logger.info("p.setLocationSafely(loc)" + p.setLocationSafely(location));
  46.     }
  47.  
  48.     private Location<World> getRandomLocation(World world) {
  49.         int x = this.random.nextBoolean() ? this.random.nextInt(max + 1 - min) + min : -(this.random.nextInt(max + 1 - min) + min);
  50.         int z = this.random.nextBoolean() ? this.random.nextInt(max + 1 - min) + min : -(this.random.nextInt(max + 1 - min) + min);
  51.         return new Location<>(world, x, 90, z);
  52.     }
  53.  
  54.     public Map<UUID, List<Location<World>>> getSpawns() {
  55.         return this.spawns;
  56.     }
  57. }