Exporting

This commit is contained in:
dfsek
2020-12-23 23:02:58 -07:00
parent 76afd54d3c
commit 1c316e52a9
4 changed files with 74 additions and 5 deletions

View File

@@ -47,7 +47,6 @@ public class StructureFunction implements Function<Void> {
@Override
public Void apply(Location location, Rotation rotation, int recursions) {
System.out.println("executing structure function");
Vector2 xz = new Vector2(x.apply(location, rotation, recursions).doubleValue(), z.apply(location, rotation, recursions).doubleValue());

View File

@@ -51,9 +51,9 @@ public class ParserTest {
long t = System.nanoTime() - l;
System.out.println("Took " + (double) t / 1000000);
block.apply(null, Rotation.NONE, recursions);
block.apply(null, Rotation.NONE, 0);
block.apply(null, Rotation.NONE, recursions);
block.apply(null, Rotation.NONE, 0);
}
private static class Test1 implements Function<Void> {

View File

@@ -11,7 +11,7 @@ import java.io.IOException;
public class TokenizerTest {
@Test
public void tokens() throws IOException, TokenizerException {
Tokenizer tokenizer = new Tokenizer(IOUtils.toString(getClass().getResourceAsStream("/target/server/plugins/Terra/test.tesf")));
Tokenizer tokenizer = new Tokenizer(IOUtils.toString(getClass().getResourceAsStream("/test.tesf")));
// Actual run
long l = System.nanoTime();

View File

@@ -2,12 +2,21 @@ package com.dfsek.terra.bukkit.command.command.structure;
import com.dfsek.terra.bukkit.command.PlayerCommand;
import com.dfsek.terra.bukkit.structure.WorldEditUtil;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.Sign;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
@@ -19,10 +28,71 @@ public class ExportCommand extends PlayerCommand {
@Override
public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
Location[] l = WorldEditUtil.getSelectionLocations(sender);
/*if(l == null) return true;
if(l == null) return true;
Location l1 = l[0];
Location l2 = l[1];
StringBuilder scriptBuilder = new StringBuilder("id \"" + args[0] + "\";\nnum y = 0;\n");
int centerX = 0;
int centerY = 0;
int centerZ = 0;
for(int x = l1.getBlockX(); x <= l2.getBlockX(); x++) {
for(int y = l1.getBlockY(); y <= l2.getBlockY(); y++) {
for(int z = l1.getBlockZ(); z <= l2.getBlockZ(); z++) {
Block block = new Location(l1.getWorld(), x, y, z).getBlock();
BlockState state = block.getState();
if(state instanceof Sign) {
Sign sign = (Sign) state;
if(sign.getLine(0).equals("[TERRA]") && sign.getLine(1).equals("[CENTER]")) {
centerX = x - l1.getBlockX();
centerY = y - l1.getBlockY();
centerZ = z - l1.getBlockZ();
}
}
}
}
}
for(int x = l1.getBlockX(); x <= l2.getBlockX(); x++) {
for(int y = l1.getBlockY(); y <= l2.getBlockY(); y++) {
for(int z = l1.getBlockZ(); z <= l2.getBlockZ(); z++) {
Block block = new Location(l1.getWorld(), x, y, z).getBlock();
if(block.getType().equals(Material.STRUCTURE_VOID)) continue;
scriptBuilder.append("block(").append(x - l1.getBlockX() - centerX).append(", y + ").append(y - l1.getBlockY() - centerY).append(", ").append(z - l1.getBlockZ() - centerZ).append(", ")
.append("\"");
BlockState state = block.getState();
if(state instanceof Sign) {
Sign sign = (Sign) state;
if(sign.getLine(0).equals("[TERRA]")) {
scriptBuilder.append(Bukkit.createBlockData(sign.getLine(2) + sign.getLine(3)).getAsString(false));
}
} else {
scriptBuilder.append(block.getBlockData().getAsString(false));
}
scriptBuilder.append("\");\n");
}
}
}
File file = new File(getMain().getDataFolder() + File.separator + "export" + File.separator + "structures", args[0] + ".tesf");
try {
file.getParentFile().mkdirs();
file.createNewFile();
} catch(IOException e) {
e.printStackTrace();
}
try(BufferedWriter writer = new BufferedWriter(new FileWriter(file))) {
writer.write(scriptBuilder.toString());
} catch(IOException e) {
e.printStackTrace();
}
/*
Structure structure;
try {
structure = new Structure(l1, l2, args[0]);