- leaderboard: parse M:SS.mmm/H:MM:SS(.mmm), switch TIME sort to long (п.25) - sql: single Hikari pool, non-blocking connect, adaptive init order, settings JSON round-trip (п.27-30) - coop: remove unregister recursion via session-only leave + reentrancy guard (п.24) - jump: perpendicular jitter for diagonal heading, valid safety-fallback on retry exhaustion (п.32-33) - lifecycle: fall threshold relative to course, lead via generated-blocks counter, one-time rewards once (п.35-37) - schematics: catch RuntimeExceptions, validate size, 10MB file limit (п.31) - config merge: preserve block-sequence lists and ignored sections, fix path reversal (п.26) - tests: +31 (score, jump, schematics, config merge) = 72 total
38 lines
1.3 KiB
Java
38 lines
1.3 KiB
Java
package dev.loki.loparkour.schematic.schem;
|
|
|
|
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
|
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
|
|
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats;
|
|
import com.sk89q.worldedit.extent.clipboard.io.ClipboardReader;
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
import java.io.File;
|
|
import java.io.FileInputStream;
|
|
import java.io.IOException;
|
|
|
|
public final class SchemLoader {
|
|
|
|
private static final int MAX_FILE_SIZE = 10 * 1024 * 1024;
|
|
|
|
private SchemLoader() {
|
|
}
|
|
|
|
@NotNull
|
|
public static Clipboard load(@NotNull File file) throws IOException {
|
|
if (file.length() > MAX_FILE_SIZE) {
|
|
throw new IOException("Schematic file too large: " + file.getName());
|
|
}
|
|
final ClipboardFormat format = ClipboardFormats.findByFile(file);
|
|
if (format == null) {
|
|
throw new IOException("Unsupported schematic file: " + file.getName());
|
|
}
|
|
try (FileInputStream in = new FileInputStream(file);
|
|
ClipboardReader reader = format.getReader(in)) {
|
|
final Clipboard clipboard = reader.read();
|
|
if (clipboard == null) {
|
|
throw new IOException("Schematic file returned no clipboard: " + file.getName());
|
|
}
|
|
return clipboard;
|
|
}
|
|
}
|
|
}
|