Skip to content

Commit

Permalink
Add support for WorldEdit 7.3 and v3 schematics
Browse files Browse the repository at this point in the history
  • Loading branch information
PseudoKnight committed Mar 10, 2024
1 parent 14b2687 commit 7690d99
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 35 deletions.
4 changes: 2 additions & 2 deletions CHWorldEdit/pom.xml
Expand Up @@ -10,13 +10,13 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>CHWorldEdit</artifactId>
<version>3.2.2</version>
<version>3.2.3</version>

<dependencies>
<dependency>
<groupId>io.github.jbaero</groupId>
<artifactId>SKCompat</artifactId>
<version>3.2.2</version>
<version>3.2.3</version>
</dependency>
</dependencies>

Expand Down
4 changes: 2 additions & 2 deletions CHWorldGuard/pom.xml
Expand Up @@ -10,13 +10,13 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>CHWorldGuard</artifactId>
<version>3.2.2</version>
<version>3.2.3</version>

<dependencies>
<dependency>
<groupId>io.github.jbaero</groupId>
<artifactId>SKCompat</artifactId>
<version>3.2.2</version>
<version>3.2.3</version>
</dependency>
</dependencies>

Expand Down
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -9,12 +9,12 @@ See **[CHRegionChange](https://github.com/PseudoKnight/CHRegionChange)** for a W

### Latest

**[SKCompat 3.2.2](https://github.com/jb-aero/SKCompat/releases/tag/v3.2.2)** (CommandHelper 3.3.5, Spigot 1.16.5 - 1.20.1, WorldEdit 7.2.x, WorldGuard 7.0.x)
**[SKCompat 3.2.3](https://github.com/jb-aero/SKCompat/releases/tag/v3.2.3)** (CommandHelper 3.3.5, Spigot 1.16.5 - 1.20.4, WorldEdit 7.2 - 7.3, WorldGuard 7.0)

### Legacy

**[SKCompat 3.1.4](https://github.com/jb-aero/SKCompat/releases/tag/v3.1.4)** (CommandHelper 3.3.4 - 3.3.5, Spigot 1.13.2 - 1.19.4, WorldEdit 7.0.x - 7.2.x, WorldGuard 7.0.x)
**[SKCompat 2.1.1](https://github.com/jb-aero/SKCompat/releases/tag/v2.1.1)** (CommandHelper 3.3.2, Spigot 1.7.10 - 1.12.2, WorldEdit/WorldGuard 6.x)
**[SKCompat 3.1.4](https://github.com/jb-aero/SKCompat/releases/tag/v3.1.4)** (CommandHelper 3.3.4 - 3.3.5, Spigot 1.13.2 - 1.19.4, WorldEdit 7.0 - 7.2, WorldGuard 7.0)
**[SKCompat 2.1.1](https://github.com/jb-aero/SKCompat/releases/tag/v2.1.1)** (CommandHelper 3.3.2, Spigot 1.7.10 - 1.12.2, WorldEdit/WorldGuard 6)

## Documentation

Expand Down
4 changes: 2 additions & 2 deletions SKCompat-bundle/pom.xml
Expand Up @@ -10,7 +10,7 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>SKCompat</artifactId>
<version>3.2.2</version>
<version>3.2.3</version>

<repositories>
<repository>
Expand All @@ -33,7 +33,7 @@
<dependency>
<groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit-bukkit</artifactId>
<version>7.2.14</version>
<version>7.3.0</version>
</dependency>
<dependency>
<groupId>com.sk89q.worldguard</groupId>
Expand Down
Expand Up @@ -12,9 +12,7 @@
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.extent.clipboard.io.BuiltInClipboardFormat;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardReader;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardWriter;
import com.sk89q.worldedit.extent.clipboard.io.*;
import com.sk89q.worldedit.function.operation.ForwardExtentCopy;
import com.sk89q.worldedit.function.operation.Operation;
import com.sk89q.worldedit.function.operation.Operations;
Expand All @@ -40,8 +38,7 @@ public class SKClipboard {
public static void Copy(MCCommandSender sender, MCLocation loc, boolean entities, boolean biomes, Target t) {
Actor user = SKWorldEdit.GetActor(sender, t);
LocalSession session = SKWorldEdit.GetLocalSession(user);
EditSession editSession = SKWorldEdit.GetEditSession(user, false);
try {
try (EditSession editSession = SKWorldEdit.GetEditSession(user, false)) {
Region region = session.getSelection();
BlockArrayClipboard clipboard = new BlockArrayClipboard(region);
BlockVector3 pos = session.getPlacementPosition(user);
Expand Down Expand Up @@ -73,18 +70,15 @@ public static void Load(MCCommandSender sender, String filename, Target t) {
} catch (Exception fne) {
throw new CREFormatException(fne.getMessage(), t);
}
ClipboardFormat format = ClipboardFormats.findByFile(f);
if(format == null) {
throw new CREIOException("Schematic format could not be detected.", t);
}

try (Closer closer = Closer.create()) {
FileInputStream fis = closer.register(new FileInputStream(f));
BufferedInputStream bis = closer.register(new BufferedInputStream(fis));
ClipboardReader reader;
if (f.getName().endsWith(".schem")) {
reader = closer.register(BuiltInClipboardFormat.SPONGE_SCHEMATIC.getReader(bis));
} else {
// legacy schematic format
reader = closer.register(BuiltInClipboardFormat.MCEDIT_SCHEMATIC.getReader(bis));
}

ClipboardReader reader = closer.register(format.getReader(bis));
Clipboard clipboard = reader.read();
session.setClipboard(new ClipboardHolder(clipboard));
} catch (IOException e) {
Expand Down Expand Up @@ -118,7 +112,13 @@ public static void Save(MCCommandSender sender, String filename, Target t) {
f.createNewFile();
FileOutputStream fos = closer.register(new FileOutputStream(f));
BufferedOutputStream bos = closer.register(new BufferedOutputStream(fos));
ClipboardWriter writer = closer.register(BuiltInClipboardFormat.SPONGE_SCHEMATIC.getWriter(bos));
ClipboardWriter writer;
try {
writer = closer.register(BuiltInClipboardFormat.SPONGE_V3_SCHEMATIC.getWriter(bos));
} catch(NoSuchFieldError ex) {
// prior to 7.3.0
writer = closer.register(BuiltInClipboardFormat.SPONGE_SCHEMATIC.getWriter(bos));
}
writer.write(clipboard);
} catch (IOException e) {
throw new CREIOException("Schematic could not read or it does not exist: " + e.getMessage(), t);
Expand Down Expand Up @@ -148,7 +148,6 @@ public static void Paste(MCCommandSender sender, boolean airless, boolean biomes

Actor user = SKWorldEdit.GetActor(sender, t);
LocalSession session = SKWorldEdit.GetLocalSession(user);
EditSession editSession = SKWorldEdit.GetEditSession(user, fastMode);

ClipboardHolder holder;
try {
Expand All @@ -171,15 +170,14 @@ public static void Paste(MCCommandSender sender, boolean airless, boolean biomes
}
}

Operation operation = holder
.createPaste(editSession)
.to(to)
.ignoreAirBlocks(airless)
.copyEntities(entities)
.copyBiomes(biomes)
.build();

try {
try (EditSession editSession = SKWorldEdit.GetEditSession(user, fastMode)) {
Operation operation = holder
.createPaste(editSession)
.to(to)
.ignoreAirBlocks(airless)
.copyEntities(entities)
.copyBiomes(biomes)
.build();
Operations.completeLegacy(operation);
if (select) {
BlockVector3 clipboardOffset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin());
Expand All @@ -192,8 +190,6 @@ public static void Paste(MCCommandSender sender, boolean airless, boolean biomes
}
} catch (Exception e) {
throw new CRERangeException("Attempted to change more blocks than allowed.", t);
} finally {
editSession.close();
}

}
Expand Down

0 comments on commit 7690d99

Please sign in to comment.