Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static class WSWCRData {
- private final HashMap<World, List<Chunk>> worldChunks;
- private WSWCRData(HashMap<World, List<Chunk>> worldChunks) {
- this.worldChunks = worldChunks;
- }
- public static WSWCRData create(CommandSender sender, CommandLogger logger, CommandArgs args, int argOffset) {
- String arg = args.getString(argOffset);
- if (arg == null) {
- if (sender instanceof Player) {
- World world = ((Player) sender).getWorld();
- HashMap<World, List<Chunk>> chunks = new HashMap<World, List<Chunk>>(1);
- chunks.put(world, Arrays.asList(world.getLoadedChunks()));
- return new WSWCRData(chunks);
- }
- else {
- HashMap<World, List<Chunk>> chunks = new HashMap<World, List<Chunk>>(8);
- for (World world : Bukkit.getWorlds()) {
- chunks.put(world, Arrays.asList(world.getLoadedChunks()));
- }
- return new WSWCRData(chunks);
- }
- }
- else if (arg.equalsIgnoreCase("ws")) {
- HashMap<World, List<Chunk>> chunks = new HashMap<World, List<Chunk>>(8);
- for (World world : Bukkit.getWorlds()) {
- chunks.put(world, Arrays.asList(world.getLoadedChunks()));
- }
- return new WSWCRData(chunks);
- }
- else if (arg.equalsIgnoreCase("w")) {
- World world = args.getWorld(argOffset + 1);
- if (world == null) {
- if ((args.getArgsLength() - argOffset) >= 2) {
- logger.logPrefix("That world doesnt exist or isnt loaded");
- return null;
- }
- else {
- if (sender instanceof Player) {
- world = ((Player) sender).getWorld();
- }
- else {
- logger.logPrefix("Youre not a player and you havent provided a world name!");
- return null;
- }
- }
- HashMap<World, List<Chunk>> chunks = new HashMap<World, List<Chunk>>(1);
- chunks.put(world, Arrays.asList(world.getLoadedChunks()));
- return new WSWCRData(chunks);
- }
- }
- else if (arg.equalsIgnoreCase("c")) {
- if ((args.getArgsLength() - argOffset) >= 4) {
- World world = args.getWorld(argOffset + 1);
- if (world == null) {
- if (sender instanceof Player) {
- world = ((Player) sender).getWorld();
- }
- else {
- logger.logTranslatePrefix("Youre not a player and you havent provided a world name after the 'c'!");
- return null;
- }
- }
- Integer x = args.getInteger(argOffset + 2);
- if (logger.nullCheckPrefix(x, "Error with the chunk X coordinate: its not a number")) {
- return null;
- }
- Integer z = args.getInteger(argOffset + 2);
- if (logger.nullCheckPrefix(z, "Error with the chunk Z coordinate: its not a number")) {
- return null;
- }
- HashMap<World, List<Chunk>> chunks = new HashMap<World, List<Chunk>>(1);
- ArrayList<Chunk> chunkList = new ArrayList<Chunk>(1);
- chunkList.add(world.getChunkAt(x, z));
- chunks.put(world, chunkList);
- return new WSWCRData(chunks);
- }
- else if ((args.getArgsLength() - argOffset) >= 3) {
- World world;
- if (sender instanceof Player) {
- world = ((Player) sender).getWorld();
- }
- else {
- logger.logTranslatePrefix("Youre not a player and you havent provided a world name after the 'c'!");
- return null;
- }
- Integer x = args.getInteger(argOffset + 2);
- if (logger.nullCheckPrefix(x, "Error with the chunk X coordinate: its not a number")) {
- return null;
- }
- Integer z = args.getInteger(argOffset + 2);
- if (logger.nullCheckPrefix(z, "Error with the chunk Z coordinate: its not a number")) {
- return null;
- }
- HashMap<World, List<Chunk>> chunks = new HashMap<World, List<Chunk>>(1);
- ArrayList<Chunk> chunkList = new ArrayList<Chunk>(1);
- chunkList.add(world.getChunkAt(x, z));
- chunks.put(world, chunkList);
- return new WSWCRData(chunks);
- }
- }
- else if (arg.equalsIgnoreCase("r")) {
- World world;
- Integer radius = null;
- Integer centerX = null;
- Integer centerZ = null;
- if ((args.getArgsLength() - argOffset) >= 3) {
- world = args.getWorld(argOffset + 1);
- if (world == null) {
- if (sender instanceof Player) {
- world = ((Player) sender).getWorld();
- }
- else {
- logger.logTranslatePrefix("Youre not a player and you havent provided a world name after the 'r'!");
- return null;
- }
- }
- radius = args.getInteger(argOffset + 2);
- }
- else if ((args.getArgsLength() - argOffset) >= 2) {
- if (sender instanceof Player) {
- world = ((Player) sender).getWorld();
- }
- else {
- logger.logTranslatePrefix("Youre not a player and you havent provided a world name after the 'r'!");
- return null;
- }
- radius = args.getInteger(argOffset + 1);
- }
- else if ((args.getArgsLength() - argOffset) >= 5) {
- centerX = args.getInteger(argOffset + 3);
- if (logger.nullCheckPrefix(centerX, "Error with the chunk X coordinate: it isnt a number")) {
- return null;
- }
- centerZ = args.getInteger(argOffset + 4);
- if (logger.nullCheckPrefix(centerZ, "Error with the chunk Z coordinate: it isnt a number")) {
- return null;
- }
- }
- else {
- if (sender instanceof Player) {
- Chunk chunk = ((Player) sender).getLocation().getChunk();
- centerX = chunk.getX();
- centerZ = chunk.getZ();
- }
- logger.logPrefix("You havent provided a radius or world after the 'r'!");
- return null;
- }
- if (logger.nullCheckPrefix(radius, "Error with the radius: it isnt a number")) {
- return null;
- }
- if (logger.nullCheckPrefix(centerX, "Error with the chunk X coordinate: it isnt a number")) {
- return null;
- }
- if (logger.nullCheckPrefix(centerZ, "Error with the chunk Z coordinate: it isnt a number")) {
- return null;
- }
- int diameter = (radius * 2) + 1;
- ArrayList<Chunk> chunks = new ArrayList<Chunk>(diameter * diameter);
- for (int x = centerX - radius, endX = centerX + radius; x <= endX; x++) {
- for (int z = centerZ - radius, endZ = centerZ + radius; z <= endZ; z++) {
- chunks.add(world.getChunkAt(x, z));
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement