Advertisement
bobmarley12345

idek

Apr 23rd, 2021
961
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.73 KB | None | 0 0
  1. public static class WSWCRData {
  2.     private final HashMap<World, List<Chunk>> worldChunks;
  3.     private WSWCRData(HashMap<World, List<Chunk>> worldChunks) {
  4.         this.worldChunks = worldChunks;
  5.     }
  6.     public static WSWCRData create(CommandSender sender, CommandLogger logger, CommandArgs args, int argOffset) {
  7.         String arg = args.getString(argOffset);
  8.         if (arg == null) {
  9.             if (sender instanceof Player) {
  10.                 World world = ((Player) sender).getWorld();
  11.                 HashMap<World, List<Chunk>> chunks = new HashMap<World, List<Chunk>>(1);
  12.                 chunks.put(world, Arrays.asList(world.getLoadedChunks()));
  13.                 return new WSWCRData(chunks);
  14.             }
  15.             else {
  16.                 HashMap<World, List<Chunk>> chunks = new HashMap<World, List<Chunk>>(8);
  17.                 for (World world : Bukkit.getWorlds()) {
  18.                     chunks.put(world, Arrays.asList(world.getLoadedChunks()));
  19.                 }
  20.                 return new WSWCRData(chunks);
  21.             }
  22.         }
  23.         else if (arg.equalsIgnoreCase("ws")) {
  24.             HashMap<World, List<Chunk>> chunks = new HashMap<World, List<Chunk>>(8);
  25.             for (World world : Bukkit.getWorlds()) {
  26.                 chunks.put(world, Arrays.asList(world.getLoadedChunks()));
  27.             }
  28.             return new WSWCRData(chunks);
  29.         }
  30.         else if (arg.equalsIgnoreCase("w")) {
  31.             World world = args.getWorld(argOffset + 1);
  32.             if (world == null) {
  33.                 if ((args.getArgsLength() - argOffset) >= 2) {
  34.                     logger.logPrefix("That world doesnt exist or isnt loaded");
  35.                     return null;
  36.                 }
  37.                 else {
  38.                     if (sender instanceof Player) {
  39.                         world = ((Player) sender).getWorld();
  40.                     }
  41.                     else {
  42.                         logger.logPrefix("Youre not a player and you havent provided a world name!");
  43.                         return null;
  44.                     }
  45.                 }
  46.                 HashMap<World, List<Chunk>> chunks = new HashMap<World, List<Chunk>>(1);
  47.                 chunks.put(world, Arrays.asList(world.getLoadedChunks()));
  48.                 return new WSWCRData(chunks);
  49.             }
  50.         }
  51.         else if (arg.equalsIgnoreCase("c")) {
  52.             if ((args.getArgsLength() - argOffset) >= 4) {
  53.                 World world = args.getWorld(argOffset + 1);
  54.                 if (world == null) {
  55.                     if (sender instanceof Player) {
  56.                         world = ((Player) sender).getWorld();
  57.                     }
  58.                     else {
  59.                         logger.logTranslatePrefix("Youre not a player and you havent provided a world name after the 'c'!");
  60.                         return null;
  61.                     }
  62.                 }
  63.                 Integer x = args.getInteger(argOffset + 2);
  64.                 if (logger.nullCheckPrefix(x, "Error with the chunk X coordinate: its not a number")) {
  65.                     return null;
  66.                 }
  67.                 Integer z = args.getInteger(argOffset + 2);
  68.                 if (logger.nullCheckPrefix(z, "Error with the chunk Z coordinate: its not a number")) {
  69.                     return null;
  70.                 }
  71.                 HashMap<World, List<Chunk>> chunks = new HashMap<World, List<Chunk>>(1);
  72.                 ArrayList<Chunk> chunkList = new ArrayList<Chunk>(1);
  73.                 chunkList.add(world.getChunkAt(x, z));
  74.                 chunks.put(world, chunkList);
  75.                 return new WSWCRData(chunks);
  76.             }
  77.             else if ((args.getArgsLength() - argOffset) >= 3) {
  78.                 World world;
  79.                 if (sender instanceof Player) {
  80.                     world = ((Player) sender).getWorld();
  81.                 }
  82.                 else {
  83.                     logger.logTranslatePrefix("Youre not a player and you havent provided a world name after the 'c'!");
  84.                     return null;
  85.                 }
  86.                 Integer x = args.getInteger(argOffset + 2);
  87.                 if (logger.nullCheckPrefix(x, "Error with the chunk X coordinate: its not a number")) {
  88.                     return null;
  89.                 }
  90.                 Integer z = args.getInteger(argOffset + 2);
  91.                 if (logger.nullCheckPrefix(z, "Error with the chunk Z coordinate: its not a number")) {
  92.                     return null;
  93.                 }
  94.                 HashMap<World, List<Chunk>> chunks = new HashMap<World, List<Chunk>>(1);
  95.                 ArrayList<Chunk> chunkList = new ArrayList<Chunk>(1);
  96.                 chunkList.add(world.getChunkAt(x, z));
  97.                 chunks.put(world, chunkList);
  98.                 return new WSWCRData(chunks);
  99.             }
  100.         }
  101.         else if (arg.equalsIgnoreCase("r")) {
  102.             World world;
  103.             Integer radius = null;
  104.             Integer centerX = null;
  105.             Integer centerZ = null;
  106.             if ((args.getArgsLength() - argOffset) >= 3) {
  107.                 world = args.getWorld(argOffset + 1);
  108.                 if (world == null) {
  109.                     if (sender instanceof Player) {
  110.                         world = ((Player) sender).getWorld();
  111.                     }
  112.                     else {
  113.                         logger.logTranslatePrefix("Youre not a player and you havent provided a world name after the 'r'!");
  114.                         return null;
  115.                     }
  116.                 }
  117.                 radius = args.getInteger(argOffset + 2);
  118.             }
  119.             else if ((args.getArgsLength() - argOffset) >= 2) {
  120.                 if (sender instanceof Player) {
  121.                     world = ((Player) sender).getWorld();
  122.                 }
  123.                 else {
  124.                     logger.logTranslatePrefix("Youre not a player and you havent provided a world name after the 'r'!");
  125.                     return null;
  126.                 }
  127.                 radius = args.getInteger(argOffset + 1);
  128.             }
  129.             else if ((args.getArgsLength() - argOffset) >= 5) {
  130.                 centerX = args.getInteger(argOffset + 3);
  131.                 if (logger.nullCheckPrefix(centerX, "Error with the chunk X coordinate: it isnt a number")) {
  132.                     return null;
  133.                 }
  134.                 centerZ = args.getInteger(argOffset + 4);
  135.                 if (logger.nullCheckPrefix(centerZ, "Error with the chunk Z coordinate: it isnt a number")) {
  136.                     return null;
  137.                 }
  138.             }
  139.             else {
  140.                 if (sender instanceof Player) {
  141.                     Chunk chunk = ((Player) sender).getLocation().getChunk();
  142.                     centerX = chunk.getX();
  143.                     centerZ = chunk.getZ();
  144.                 }
  145.                 logger.logPrefix("You havent provided a radius or world after the 'r'!");
  146.                 return null;
  147.             }
  148.             if (logger.nullCheckPrefix(radius, "Error with the radius: it isnt a number")) {
  149.                 return null;
  150.             }
  151.             if (logger.nullCheckPrefix(centerX, "Error with the chunk X coordinate: it isnt a number")) {
  152.                 return null;
  153.             }
  154.             if (logger.nullCheckPrefix(centerZ, "Error with the chunk Z coordinate: it isnt a number")) {
  155.                 return null;
  156.             }
  157.             int diameter = (radius * 2) + 1;
  158.             ArrayList<Chunk> chunks = new ArrayList<Chunk>(diameter * diameter);
  159.             for (int x = centerX - radius, endX = centerX + radius; x <= endX; x++) {
  160.                 for (int z = centerZ - radius, endZ = centerZ + radius; z <= endZ; z++) {
  161.                     chunks.add(world.getChunkAt(x, z));
  162.                 }
  163.             }
  164.         }
  165.     }
  166. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement