diff --git a/GCMCPlugin/pom.xml b/GCMCPlugin/pom.xml
index b41c99a..a74b062 100644
--- a/GCMCPlugin/pom.xml
+++ b/GCMCPlugin/pom.xml
@@ -42,7 +42,7 @@
com.google.code.gson
gson
- 2.8.5
+ 2.8.6
diff --git a/GCMCPlugin/src/main/java/io/github/norbipeti/gcmc/Blocks.java b/GCMCPlugin/src/main/java/io/github/norbipeti/gcmc/Blocks.java
index fa8a3e4..37ac043 100644
--- a/GCMCPlugin/src/main/java/io/github/norbipeti/gcmc/Blocks.java
+++ b/GCMCPlugin/src/main/java/io/github/norbipeti/gcmc/Blocks.java
@@ -1,14 +1,11 @@
package io.github.norbipeti.gcmc;
-import lombok.AllArgsConstructor;
import lombok.Data;
import org.bukkit.Location;
-import org.bukkit.Material;
@Data
-@AllArgsConstructor
public class Blocks {
private Location start;
private Location end;
- private Material material;
+ private String material;
}
diff --git a/GCMCPlugin/src/main/java/io/github/norbipeti/gcmc/PluginMain.java b/GCMCPlugin/src/main/java/io/github/norbipeti/gcmc/PluginMain.java
index 33a8bb8..04ac28a 100644
--- a/GCMCPlugin/src/main/java/io/github/norbipeti/gcmc/PluginMain.java
+++ b/GCMCPlugin/src/main/java/io/github/norbipeti/gcmc/PluginMain.java
@@ -1,7 +1,7 @@
package io.github.norbipeti.gcmc;
import com.google.common.io.Files;
-import com.google.gson.Gson;
+import com.google.gson.*;
import lombok.val;
import org.bukkit.Bukkit;
import org.bukkit.Location;
@@ -15,6 +15,7 @@ import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.io.IOException;
+import java.lang.reflect.Type;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
@@ -30,7 +31,7 @@ public class PluginMain extends JavaPlugin {
sender.sendMessage("§cUsage: /export ");
return true;
}
- int[] xyz = new int[6];
+ final int[] xyz = new int[6];
for (int i = 0; i < args.length; i++)
xyz[i] = Integer.parseInt(args[i]);
for (int i = 0; i < 3; i++) {
@@ -42,16 +43,18 @@ public class PluginMain extends JavaPlugin {
}
World world = sender instanceof Player ? ((Player) sender).getWorld() : Bukkit.getWorlds().get(0);
val list = new ArrayList();
- for (int y = xyz[1]; y < xyz[4]; y++) {
- Blocks blocks = new Blocks(null, null, null);
- for (int x = xyz[0]; x < xyz[3]; x++) {
- for (int z = xyz[2]; z < xyz[5]; z++) {
+ for (int y = xyz[1]; y <= xyz[4]; y++) {
+ Blocks blocks = new Blocks();
+ for (int x = xyz[0]; x <= xyz[3]; x++) {
+ for (int z = xyz[2]; z <= xyz[5]; z++) {
Block block = world.getBlockAt(x, y, z);
Material mat = block.getType();
- if (blocks.getMaterial() != mat) {
- if (blocks.getStart() != null)
+ if (!mat.name().equals(blocks.getMaterial())) {
+ if (blocks.getStart() != null) {
list.add(blocks);
- blocks.setMaterial(mat);
+ blocks = new Blocks();
+ }
+ blocks.setMaterial(mat.name());
blocks.setStart(new Location(null, x, y, z));
blocks.setEnd(blocks.getStart());
} else
@@ -60,7 +63,16 @@ public class PluginMain extends JavaPlugin {
}
list.add(blocks);
}
- Gson gson = new Gson();
+ Gson gson = new GsonBuilder().registerTypeAdapter(Location.class, new JsonSerializer() {
+ @Override
+ public JsonElement serialize(Location src, Type typeOfSrc, JsonSerializationContext context) {
+ val jo = new JsonObject();
+ jo.addProperty("x", src.getBlockX() - xyz[0]);
+ jo.addProperty("y", src.getBlockY() - xyz[1]);
+ jo.addProperty("z", src.getBlockZ() - xyz[2]);
+ return jo;
+ }
+ }).create();
try {
Files.write(gson.toJson(list), new File("result.txt"), StandardCharsets.UTF_8);
sender.sendMessage("§bSuccess!");