Minecraft world importer for Gamecraft.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.0KB

  1. package io.github.norbipeti.gcmc;
  2. import com.google.common.io.Files;
  3. import com.google.gson.Gson;
  4. import lombok.val;
  5. import org.bukkit.Bukkit;
  6. import org.bukkit.Location;
  7. import org.bukkit.Material;
  8. import org.bukkit.World;
  9. import org.bukkit.block.Block;
  10. import org.bukkit.command.Command;
  11. import org.bukkit.command.CommandSender;
  12. import org.bukkit.entity.Player;
  13. import org.bukkit.plugin.java.JavaPlugin;
  14. import java.io.File;
  15. import java.io.IOException;
  16. import java.nio.charset.StandardCharsets;
  17. import java.util.ArrayList;
  18. public class PluginMain extends JavaPlugin {
  19. @Override
  20. public void onEnable() {
  21. }
  22. @Override
  23. public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
  24. if (args.length < 6) {
  25. sender.sendMessage("§cUsage: /export <x1> <y1> <z1> <x2> <y2> <z2>");
  26. return true;
  27. }
  28. int[] xyz = new int[6];
  29. for (int i = 0; i < args.length; i++)
  30. xyz[i] = Integer.parseInt(args[i]);
  31. for (int i = 0; i < 3; i++) {
  32. if (xyz[i] >= xyz[i + 3]) {
  33. int tmp = xyz[i];
  34. xyz[i] = xyz[i + 3];
  35. xyz[i + 3] = tmp;
  36. }
  37. }
  38. World world = sender instanceof Player ? ((Player) sender).getWorld() : Bukkit.getWorlds().get(0);
  39. val list = new ArrayList<Blocks>();
  40. for (int y = xyz[1]; y < xyz[4]; y++) {
  41. Blocks blocks = new Blocks(null, null, null);
  42. for (int x = xyz[0]; x < xyz[3]; x++) {
  43. for (int z = xyz[2]; z < xyz[5]; z++) {
  44. Block block = world.getBlockAt(x, y, z);
  45. Material mat = block.getType();
  46. if (blocks.getMaterial() != mat) {
  47. if (blocks.getStart() != null)
  48. list.add(blocks);
  49. blocks.setMaterial(mat);
  50. blocks.setStart(new Location(null, x, y, z));
  51. blocks.setEnd(blocks.getStart());
  52. } else
  53. blocks.setEnd(new Location(null, x, y, z));
  54. }
  55. }
  56. list.add(blocks);
  57. }
  58. Gson gson = new Gson();
  59. try {
  60. Files.write(gson.toJson(list), new File("result.txt"), StandardCharsets.UTF_8);
  61. sender.sendMessage("§bSuccess!");
  62. } catch (IOException e) {
  63. e.printStackTrace();
  64. sender.sendMessage("§cAn error occurred.");
  65. }
  66. return true;
  67. }
  68. }