SteamWar/BauSystem2.0
Archiviert
12
0

Implement Region.paste

Implement Region.reset
Dieser Commit ist enthalten in:
yoyosource 2021-04-20 12:24:28 +02:00
Ursprung b20fae0499
Commit 09fd349e5d
2 geänderte Dateien mit 40 neuen und 10 gelöschten Zeilen

Datei anzeigen

@ -44,7 +44,7 @@ import org.bukkit.Bukkit;
@UtilityClass @UtilityClass
public class Region_15 { public class Region_15 {
EditSession paste(File file, int x, int y, int z, PasteOptions pasteOptions) { EditSession paste(File file, Point pastePoint, PasteOptions pasteOptions) {
Clipboard clipboard; Clipboard clipboard;
try (ClipboardReader reader = Objects.requireNonNull(ClipboardFormats.findByFile(file)).getReader(new FileInputStream(file))) { try (ClipboardReader reader = Objects.requireNonNull(ClipboardFormats.findByFile(file)).getReader(new FileInputStream(file))) {
clipboard = reader.read(); clipboard = reader.read();
@ -52,16 +52,16 @@ public class Region_15 {
throw new SecurityException("Bausystem schematic not found", e); throw new SecurityException("Bausystem schematic not found", e);
} }
return paste(clipboard, x, y, z, pasteOptions); return paste(clipboard, pastePoint, pasteOptions);
} }
EditSession paste(Clipboard clipboard, int x, int y, int z, PasteOptions pasteOptions) { EditSession paste(Clipboard clipboard, Point pastePoint, PasteOptions pasteOptions) {
try (EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1)) { try (EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorlds().get(0)), -1)) {
changeColor(clipboard, pasteOptions.getColor()); changeColor(clipboard, pasteOptions.getColor());
ClipboardHolder ch = new ClipboardHolder(clipboard); ClipboardHolder ch = new ClipboardHolder(clipboard);
BlockVector3 dimensions = clipboard.getDimensions(); BlockVector3 dimensions = clipboard.getDimensions();
BlockVector3 v = BlockVector3.at(x, y, z); BlockVector3 v = BlockVector3.at(pastePoint.getX(), pastePoint.getY(), pastePoint.getZ());
BlockVector3 offset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin()); BlockVector3 offset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin());
if (pasteOptions.isRotate()) { if (pasteOptions.isRotate()) {
ch.setTransform(new AffineTransform().rotateY(180)); ch.setTransform(new AffineTransform().rotateY(180));

Datei anzeigen

@ -20,12 +20,15 @@
package de.steamwar.bausystem.region; package de.steamwar.bausystem.region;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import de.steamwar.bausystem.region.flags.Flag; import de.steamwar.bausystem.region.flags.Flag;
import de.steamwar.bausystem.region.flags.flagvalues.ColorMode;
import de.steamwar.bausystem.region.flags.flagvalues.TNTMode; import de.steamwar.bausystem.region.flags.flagvalues.TNTMode;
import de.steamwar.bausystem.region.loader.RegionLoader; import de.steamwar.bausystem.region.loader.RegionLoader;
import de.steamwar.bausystem.region.utils.RegionExtensionType; import de.steamwar.bausystem.region.utils.RegionExtensionType;
import de.steamwar.bausystem.region.utils.RegionType; import de.steamwar.bausystem.region.utils.RegionType;
import de.steamwar.bausystem.shared.SizedStack; import de.steamwar.bausystem.shared.SizedStack;
import de.steamwar.core.VersionedCallable;
import de.steamwar.sql.Schematic; import de.steamwar.sql.Schematic;
import lombok.AccessLevel; import lombok.AccessLevel;
import lombok.Getter; import lombok.Getter;
@ -35,6 +38,7 @@ import yapion.hierarchy.types.YAPIONObject;
import yapion.hierarchy.types.YAPIONType; import yapion.hierarchy.types.YAPIONType;
import yapion.hierarchy.types.YAPIONValue; import yapion.hierarchy.types.YAPIONValue;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
@ -340,34 +344,60 @@ public class Region {
} }
public void reset(Schematic schematic, RegionType regionType) throws IOException { public void reset(Schematic schematic, RegionType regionType) throws IOException {
reset(schematic, regionType, RegionExtensionType.NORMAL); reset(schematic, regionType, RegionExtensionType.NORMAL, false);
} }
public void reset(RegionType regionType, RegionExtensionType regionExtensionType) throws IOException { public void reset(RegionType regionType, RegionExtensionType regionExtensionType) throws IOException {
reset(null, regionType, regionExtensionType); reset(null, regionType, regionExtensionType, false);
} }
public void reset(Schematic schematic, RegionType regionType, RegionExtensionType regionExtensionType) throws IOException { public void reset(Schematic schematic, RegionType regionType, RegionExtensionType regionExtensionType, boolean ignoreAir) throws IOException {
if (!hasReset(regionType)) { if (!hasReset(regionType)) {
return; return;
} }
if (regionExtensionType == RegionExtensionType.EXTENSION && !hasExtensionType(regionType)) { if (regionExtensionType == RegionExtensionType.EXTENSION && !hasExtensionType(regionType)) {
regionExtensionType = RegionExtensionType.NORMAL; regionExtensionType = RegionExtensionType.NORMAL;
} }
PasteOptions pasteOptions = new PasteOptions((schematic != null && (schematic.getSchemType().fightType() || schematic.getSchemType().check())), ignoreAir, getPlain(Flag.COLOR, ColorMode.class).getColor(), regionExtensionType == RegionExtensionType.EXTENSION, getMinPoint(regionType, regionExtensionType), getMaxPoint(regionType, regionExtensionType), waterLevel);
switch (regionType) { switch (regionType) {
case BUILD: case BUILD:
System.out.println(schematic + " " + regionType + " " + regionExtensionType + " " + minPointBuild); System.out.println(schematic + " " + prototype.getBuild().getSchematicFile() + " " + regionType + " " + regionExtensionType + " " + minPointBuild);
if (schematic != null) {
paste(schematic.load(), minPointBuild, pasteOptions);
} else {
paste(prototype.getBuild().getSchematicFile(), minPointBuild, pasteOptions);
}
break; break;
case TESTBLOCK: case TESTBLOCK:
System.out.println(schematic + " " + regionType + " " + regionExtensionType + " " + minPointTestblock); System.out.println(schematic + " " + prototype.getBuild().getSchematicFile() + " " + regionType + " " + regionExtensionType + " " + minPointTestblock);
if (schematic != null) {
paste(schematic.load(), minPointTestblock, pasteOptions);
} else {
paste(prototype.getTestblock().getSchematicFile(), minPointTestblock, pasteOptions);
}
break; break;
default: default:
case NORMAL: case NORMAL:
System.out.println(schematic + " " + regionType + " " + regionExtensionType + " " + minPoint); System.out.println(schematic + " " + prototype.getBuild().getSchematicFile() + " " + regionType + " " + regionExtensionType + " " + minPoint);
if (schematic != null) {
paste(schematic.load(), minPoint, pasteOptions);
} else {
paste(prototype.getSchematicFile(), minPoint, pasteOptions);
}
break; break;
} }
} }
private static EditSession paste(File file, Point pastePoint, PasteOptions pasteOptions) {
return VersionedCallable.call(new VersionedCallable<>(() -> Region_15.paste(file, pastePoint, pasteOptions), 15));
}
private static EditSession paste(Clipboard clipboard, Point pastePoint, PasteOptions pasteOptions) {
return VersionedCallable.call(new VersionedCallable<>(() -> Region_15.paste(clipboard, pastePoint, pasteOptions), 15));
}
public boolean isGlobal() { public boolean isGlobal() {
return this == GlobalRegion.getInstance(); return this == GlobalRegion.getInstance();
} }