Skip to content

Commit

Permalink
Merge branch 'version/7.2.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
me4502 committed Jan 6, 2024
2 parents 173fb45 + 3295242 commit 64bcf66
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package com.sk89q.worldedit.extent.clipboard.io;

import com.sk89q.worldedit.util.formatting.text.Component;

/**
* Raised when a known exception occurs during schematic load.
*/
public final class SchematicLoadException extends RuntimeException {

private final Component message;

public SchematicLoadException(Component message) {
this.message = message;
}

/**
* Get the message of this exception as a rich text component.
*
* @return The rich message
*/
public Component getRichMessage() {
return this.message;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import com.sk89q.worldedit.extent.clipboard.io.sponge.SpongeSchematicV1Reader;
import com.sk89q.worldedit.extent.clipboard.io.sponge.SpongeSchematicV2Reader;
import com.sk89q.worldedit.internal.Constants;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;

import java.io.IOException;
import java.util.OptionalInt;
Expand Down Expand Up @@ -56,7 +58,7 @@ public Clipboard read() throws IOException {
return switch (version) {
case 1 -> SpongeSchematicV1Reader.doRead(schematicTag.toLinTag());
case 2 -> SpongeSchematicV2Reader.doRead(schematicTag.toLinTag());
default -> throw new IllegalStateException("Unsupported schematic version: " + version);
default -> throw new SchematicLoadException(TranslatableComponent.of("worldedit.schematic.load.unsupported-version", TextComponent.of(version)));
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.sk89q.worldedit.command.tool.InvalidToolBindException;
import com.sk89q.worldedit.extension.input.DisallowedUsageException;
import com.sk89q.worldedit.extension.input.NoMatchException;
import com.sk89q.worldedit.extent.clipboard.io.SchematicLoadException;
import com.sk89q.worldedit.internal.expression.ExpressionException;
import com.sk89q.worldedit.regions.RegionOperationException;
import com.sk89q.worldedit.util.formatting.text.Component;
Expand Down Expand Up @@ -183,6 +184,11 @@ public void convert(FileSelectionAbortedException e) throws CommandException {
throw newCommandException(TranslatableComponent.of("worldedit.error.file-aborted"), e);
}

@ExceptionMatch
public void convert(SchematicLoadException e) throws CommandException {
throw newCommandException(e.getRichMessage(), e);
}

@ExceptionMatch
public void convert(WorldEditException e) throws CommandException {
throw newCommandException(e.getRichMessage(), e);
Expand Down
1 change: 1 addition & 0 deletions worldedit-core/src/main/resources/lang/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
"worldedit.schematic.load.does-not-exist": "Schematic {0} does not exist!",
"worldedit.schematic.load.loading": "(Please wait... loading schematic.)",
"worldedit.schematic.load.still-loading": "(Please wait... still loading schematic.)",
"worldedit.schematic.load.unsupported-version": "This schematic version is currently not supported. Version: {0}.",
"worldedit.schematic.save.already-exists": "That schematic already exists. Use the -f flag to overwrite it.",
"worldedit.schematic.save.failed-directory": "Could not create folder for schematics!",
"worldedit.schematic.save.saving": "(Please wait... saving schematic.)",
Expand Down

0 comments on commit 64bcf66

Please sign in to comment.