mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-12-26 17:18:43 +01:00
Schematic fixes
The 1.13 schematic format uses the `.schem` extension, use that instead Support loading both legacy `.schematic` and `.schem` files for road schematics Fix reading road schematics with an offset
This commit is contained in:
parent
0f8b7cd588
commit
1c9c0d0207
@ -27,7 +27,7 @@ import java.util.UUID;
|
||||
}
|
||||
} else {
|
||||
uuid = UUIDHandler.getUUID(value, null);
|
||||
name = UUIDHandler.getName(uuid);
|
||||
name = uuid == null ? value : UUIDHandler.getName(uuid);
|
||||
name = name == null ? value : name;
|
||||
}
|
||||
if (uuid == null || value.equalsIgnoreCase("-")) {
|
||||
|
@ -64,7 +64,7 @@ import java.util.UUID;
|
||||
MainUtil.sendMessage(player, Captions.SAVE_SUCCESS);
|
||||
List<String> schematics = player.getMeta("plot_schematics");
|
||||
if (schematics != null) {
|
||||
schematics.add(file + ".schematic");
|
||||
schematics.add(file + ".schem");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -31,22 +31,22 @@ public class HybridPlotManager extends ClassicPlotManager {
|
||||
+ File.separator;
|
||||
try {
|
||||
File sideroad =
|
||||
MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), dir + "sideroad.schematic");
|
||||
MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), dir + "sideroad.schem");
|
||||
if (sideroad.exists()) {
|
||||
files.add(new FileBytes(newDir + "sideroad.schematic",
|
||||
files.add(new FileBytes(newDir + "sideroad.schem",
|
||||
Files.readAllBytes(sideroad.toPath())));
|
||||
}
|
||||
File intersection =
|
||||
MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), "intersection.schematic");
|
||||
MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), "intersection.schem");
|
||||
if (intersection.exists()) {
|
||||
files.add(new FileBytes(newDir + "intersection.schematic",
|
||||
files.add(new FileBytes(newDir + "intersection.schem",
|
||||
Files.readAllBytes(intersection.toPath())));
|
||||
}
|
||||
File plot =
|
||||
MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), dir + "plot.schematic");
|
||||
MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), dir + "plot.schem");
|
||||
if (plot.exists()) {
|
||||
files.add(
|
||||
new FileBytes(newDir + "plot.schematic", Files.readAllBytes(plot.toPath())));
|
||||
new FileBytes(newDir + "plot.schem", Files.readAllBytes(plot.toPath())));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
@ -131,15 +131,16 @@ public class HybridPlotWorld extends ClassicPlotWorld {
|
||||
|
||||
public void setupSchematics() throws SchematicHandler.UnsupportedFormatException {
|
||||
this.G_SCH = new HashMap<>();
|
||||
File schematic1File = MainUtil.getFile(PlotSquared.get().IMP.getDirectory(),
|
||||
"schematics/GEN_ROAD_SCHEMATIC/" + this.worldname + "/sideroad.schematic");
|
||||
File schematic2File = MainUtil.getFile(PlotSquared.get().IMP.getDirectory(),
|
||||
"schematics/GEN_ROAD_SCHEMATIC/" + this.worldname + "/intersection.schematic");
|
||||
File schem3File = MainUtil.getFile(PlotSquared.get().IMP.getDirectory(),
|
||||
"schematics/GEN_ROAD_SCHEMATIC/" + this.worldname + "/plot.schematic");
|
||||
File root = MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), "schematics/GEN_ROAD_SCHEMATIC/" + this.worldname);
|
||||
File schematic1File = new File(root, "sideroad.schem");
|
||||
if (!schematic1File.exists()) schematic1File = new File(root, "sideroad.schematic");
|
||||
File schematic2File = new File(root, "intersection.schem");
|
||||
if (!schematic2File.exists()) schematic2File = new File(root, "intersection.schematic");
|
||||
File schematic3File = new File(root, "plot.schem");
|
||||
if (!schematic3File.exists()) schematic3File = new File(root, "plot.schematic");
|
||||
Schematic schematic1 = SchematicHandler.manager.getSchematic(schematic1File);
|
||||
Schematic schematic2 = SchematicHandler.manager.getSchematic(schematic2File);
|
||||
Schematic schematic3 = SchematicHandler.manager.getSchematic(schem3File);
|
||||
Schematic schematic3 = SchematicHandler.manager.getSchematic(schematic3File);
|
||||
int shift = this.ROAD_WIDTH / 2;
|
||||
int oddshift = (this.ROAD_WIDTH & 1) == 0 ? 0 : 1;
|
||||
int minY = Math.min(PLOT_HEIGHT, ROAD_HEIGHT);
|
||||
@ -169,10 +170,11 @@ public class HybridPlotWorld extends ClassicPlotWorld {
|
||||
|
||||
int startY = minY - PLOT_HEIGHT;
|
||||
|
||||
BlockVector3 min = blockArrayClipboard3.getMinimumPoint();
|
||||
for (short x = 0; x < w3; x++) {
|
||||
for (short z = 0; z < l3; z++) {
|
||||
for (short y = 0; y < h3; y++) {
|
||||
BaseBlock id = blockArrayClipboard3.getFullBlock(BlockVector3.at(x, y, z));
|
||||
BaseBlock id = blockArrayClipboard3.getFullBlock(BlockVector3.at(x + min.getBlockX(), y + min.getBlockY(), z + min.getBlockZ()));
|
||||
if (!id.getBlockType().getMaterial().isAir()) {
|
||||
addOverlayBlock((short) (x + shift + oddshift + centerShiftX),
|
||||
(short) (y + startY), (short) (z + shift + oddshift + centerShiftZ),
|
||||
@ -233,10 +235,11 @@ public class HybridPlotWorld extends ClassicPlotWorld {
|
||||
short l2 = (short) d2.getZ();
|
||||
short h2 = (short) d2.getY();
|
||||
int startY = minY - ROAD_HEIGHT;
|
||||
for (short x = 0; x < w1; x++) {
|
||||
for (short z = 0; z < l1; z++) {
|
||||
for (short y = 0; y < h1; y++) {
|
||||
BaseBlock id = blockArrayClipboard1.getFullBlock(BlockVector3.at(x, y, z));
|
||||
BlockVector3 min = blockArrayClipboard2.getMinimumPoint();
|
||||
for (short x = 0; x < w2; x++) {
|
||||
for (short z = 0; z < l2; z++) {
|
||||
for (short y = 0; y < h2; y++) {
|
||||
BaseBlock id = blockArrayClipboard2.getFullBlock(BlockVector3.at(x + min.getBlockX(), y + min.getBlockY(), z + min.getBlockZ()));
|
||||
if (!id.getBlockType().getMaterial().isAir()) {
|
||||
addOverlayBlock((short) (x - shift), (short) (y + startY),
|
||||
(short) (z + shift + oddshift), id, false, h1);
|
||||
@ -246,10 +249,11 @@ public class HybridPlotWorld extends ClassicPlotWorld {
|
||||
}
|
||||
}
|
||||
}
|
||||
min = blockArrayClipboard2.getMinimumPoint();
|
||||
for (short x = 0; x < w2; x++) {
|
||||
for (short z = 0; z < l2; z++) {
|
||||
for (short y = 0; y < h2; y++) {
|
||||
BaseBlock id = blockArrayClipboard2.getFullBlock(BlockVector3.at(x, y, z));
|
||||
BaseBlock id = blockArrayClipboard2.getFullBlock(BlockVector3.at(x + min.getBlockX(), y + min.getBlockY(), z + min.getBlockZ()));
|
||||
if (!id.getBlockType().getMaterial().isAir()) {
|
||||
addOverlayBlock((short) (x - shift), (short) (y + startY),
|
||||
(short) (z - shift), id, false, h2);
|
||||
|
@ -238,13 +238,14 @@ public abstract class HybridUtils {
|
||||
final String dir =
|
||||
"schematics" + File.separator + "GEN_ROAD_SCHEMATIC" + File.separator + plot.getArea()
|
||||
.toString() + File.separator;
|
||||
|
||||
SchematicHandler.manager.getCompoundTag(world, sideRoad, new RunnableVal<CompoundTag>() {
|
||||
@Override public void run(CompoundTag value) {
|
||||
SchematicHandler.manager.save(value, dir + "sideroad.schematic");
|
||||
SchematicHandler.manager.save(value, dir + "sideroad.schem");
|
||||
SchematicHandler.manager
|
||||
.getCompoundTag(world, intersection, new RunnableVal<CompoundTag>() {
|
||||
@Override public void run(CompoundTag value) {
|
||||
SchematicHandler.manager.save(value, dir + "intersection.schematic");
|
||||
SchematicHandler.manager.save(value, dir + "intersection.schem");
|
||||
plotworld.ROAD_SCHEMATIC_ENABLED = true;
|
||||
try {
|
||||
plotworld.setupSchematics();
|
||||
|
@ -1882,7 +1882,7 @@ public class Plot {
|
||||
String name = Plot.this.id + "," + Plot.this.area + ',' + MainUtil
|
||||
.getName(Plot.this.owner);
|
||||
boolean result = SchematicHandler.manager.save(value,
|
||||
Settings.Paths.SCHEMATICS + File.separator + name + ".schematic");
|
||||
Settings.Paths.SCHEMATICS + File.separator + name + ".schem");
|
||||
if (whenDone != null) {
|
||||
whenDone.value = result;
|
||||
TaskManager.runTask(whenDone);
|
||||
|
@ -80,7 +80,7 @@ public abstract class SchematicHandler {
|
||||
TaskManager.runTaskAsync(() -> {
|
||||
MainUtil.sendMessage(null, "&6ID: " + plot.getId());
|
||||
boolean result = SchematicHandler.manager
|
||||
.save(value, directory + File.separator + name + ".schematic");
|
||||
.save(value, directory + File.separator + name + ".schem");
|
||||
if (!result) {
|
||||
MainUtil
|
||||
.sendMessage(null, "&7 - Failed to save &c" + plot.getId());
|
||||
@ -250,10 +250,13 @@ public abstract class SchematicHandler {
|
||||
throw new RuntimeException("Could not create schematic parent directory");
|
||||
}
|
||||
}
|
||||
File file = MainUtil.getFile(PlotSquared.get().IMP.getDirectory(),
|
||||
Settings.Paths.SCHEMATICS + File.separator + name + (name.endsWith(".schem") ?
|
||||
"" :
|
||||
".schematic"));
|
||||
if (!name.endsWith(".schem") && !name.endsWith(".schematic")) {
|
||||
name = name + ".schem";
|
||||
}
|
||||
File file = MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), Settings.Paths.SCHEMATICS + File.separator + name);
|
||||
if (!file.exists()) {
|
||||
file = MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), Settings.Paths.SCHEMATICS + File.separator + name + "atic");
|
||||
}
|
||||
return getSchematic(file);
|
||||
}
|
||||
|
||||
@ -267,7 +270,7 @@ public abstract class SchematicHandler {
|
||||
MainUtil.getFile(PlotSquared.get().IMP.getDirectory(), Settings.Paths.SCHEMATICS);
|
||||
final List<String> names = new ArrayList<>();
|
||||
if (parent.exists()) {
|
||||
final String[] rawNames = parent.list((dir, name) -> name.endsWith(".schematic"));
|
||||
final String[] rawNames = parent.list((dir, name) -> name.endsWith(".schematic") || name.endsWith(".schem"));
|
||||
if (rawNames != null) {
|
||||
final List<String> transformed = Arrays.stream(rawNames)
|
||||
.map(rawName -> rawName.substring(0, rawName.length() - 10))
|
||||
|
Loading…
Reference in New Issue
Block a user