Skip to content

Commit 69854db

Browse files
ydal251dordsor21
andauthored
Implement Translatable Schematic Commands (#3141)
Co-authored-by: dordsor21 <dordsor21@gmail.com>
1 parent cb54cb5 commit 69854db

2 files changed

Lines changed: 31 additions & 44 deletions

File tree

worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java

Lines changed: 25 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.fastasyncworldedit.core.event.extent.ActorSaveClipboardEvent;
2525
import com.fastasyncworldedit.core.extent.clipboard.MultiClipboardHolder;
2626
import com.fastasyncworldedit.core.extent.clipboard.URIClipboardHolder;
27+
import com.fastasyncworldedit.core.internal.exception.FaweException;
2728
import com.fastasyncworldedit.core.math.transform.MutatingOperationTransformHolder;
2829
import com.fastasyncworldedit.core.util.MainUtil;
2930
import com.google.common.collect.Multimap;
@@ -576,15 +577,20 @@ public void save(
576577
ClipboardHolder holder = session.getClipboard();
577578

578579
SchematicSaveTask task = new SchematicSaveTask(actor, f, dir, format, holder, overwrite);
579-
AsyncCommandBuilder.wrap(task, actor)
580-
.registerWithSupervisor(worldEdit.getSupervisor(), "Saving schematic " + filename)
581-
.setDelayMessage(Caption.of("worldedit.schematic.save.saving"))
582-
.onSuccess(filename + " saved" + (overwrite ? " (overwriting previous file)." : "."), null)
583-
.onFailure(
584-
Caption.of("worldedit.schematic.failed-to-save"),
585-
worldEdit.getPlatformManager().getPlatformCommandManager().getExceptionConverter()
586-
)
587-
.buildAndExec(worldEdit.getExecutorService());
580+
AsyncCommandBuilder
581+
.wrap(task, actor)
582+
.registerWithSupervisor(worldEdit.getSupervisor(), "Saving schematic " + filename)
583+
.setDelayMessage(Caption.of("worldedit.schematic.save.saving"))
584+
.onSuccess(
585+
overwrite
586+
? Caption.of("fawe.worldedit.schematic.schematic.overwritten")
587+
: Caption.of("fawe.worldedit.schematic.schematic.saved", filename), null
588+
)
589+
.onFailure(
590+
Caption.of("worldedit.schematic.failed-to-save"),
591+
worldEdit.getPlatformManager().getPlatformCommandManager().getExceptionConverter()
592+
)
593+
.buildAndExec(worldEdit.getExecutorService());
588594
}
589595

590596
@Command(
@@ -1001,14 +1007,8 @@ public Void call() throws Exception {
10011007
int limit = actor.getLimit().SCHEM_FILE_NUM_LIMIT;
10021008

10031009
if (numFiles >= limit) {
1004-
TextComponent noSlotsErr = TextComponent.of( //TODO - to be moved into captions/translatablecomponents
1005-
String.format(
1006-
"You have " + numFiles + "/" + limit + " saved schematics. Delete some to save this one!",
1007-
TextColor.RED
1008-
));
10091010
LOGGER.info(actor.getName() + " failed to save " + file.getCanonicalPath() + " - too many schematics!");
1010-
throw new WorldEditException(noSlotsErr) {
1011-
};
1011+
throw new FaweException(Caption.of("fawe.error.schematic.over.limit", numFiles, limit));
10121012
}
10131013
}
10141014
//FAWE end
@@ -1034,9 +1034,7 @@ public Void call() throws Exception {
10341034
closer.close(); // release the new .schem file so that its size can be measured
10351035
double filesizeKb = Files.size(Paths.get(file.getAbsolutePath())) / 1000.0;
10361036

1037-
TextComponent filesizeNotif = TextComponent.of( //TODO - to be moved into captions/translatablecomponents
1038-
SCHEMATIC_NAME + " size: " + String.format("%.1f", filesizeKb) + "kb", TextColor.GRAY);
1039-
actor.print(filesizeNotif);
1037+
actor.print(Caption.of("fawe.worldedit.schematic.schematic.size", SCHEMATIC_NAME, String.format("%.1f", filesizeKb)));
10401038

10411039
if (checkFilesize) {
10421040

@@ -1049,42 +1047,25 @@ public Void call() throws Exception {
10491047

10501048
if ((curKb) > allocatedKb) {
10511049
file.delete();
1052-
TextComponent notEnoughKbErr = TextComponent.of(
1053-
//TODO - to be moved into captions/translatablecomponents
1054-
"You're about to be at " + String.format("%.1f", curKb) + "kb of schematics. ("
1055-
+ String.format(
1056-
"%dkb",
1057-
allocatedKb
1058-
) + " available) Delete some first to save this one!",
1059-
TextColor.RED
1060-
);
10611050
LOGGER.info(actor.getName() + " failed to save " + SCHEMATIC_NAME + " - not enough space!");
1062-
throw new WorldEditException(notEnoughKbErr) {
1063-
};
1051+
throw new FaweException(Caption.of(
1052+
"fawe.error.schematic.over.disk.limit",
1053+
String.format("%.1f", curKb),
1054+
String.format("%dkb", allocatedKb)
1055+
));
10641056
}
10651057
if (overwrite) {
10661058
new File(curFilepath).delete();
10671059
file.renameTo(new File(curFilepath));
10681060
} else {
10691061
numFiles++;
10701062
}
1071-
TextComponent kbRemainingNotif = TextComponent.of(
1072-
//TODO - to be moved into captions/translatablecomponents
1073-
"You have " + String.format("%.1f", (allocatedKb - curKb)) + "kb left for schematics.",
1074-
TextColor.GRAY
1075-
);
1076-
actor.print(kbRemainingNotif);
1063+
1064+
actor.print(Caption.of("fawe.worldedit.schematic.schematic.disk.space", String.format("%.1f", (allocatedKb - curKb))));
10771065
}
10781066

10791067
if (Settings.settings().PATHS.PER_PLAYER_SCHEMATICS && actor.getLimit().SCHEM_FILE_NUM_LIMIT > -1) {
1080-
1081-
TextComponent slotsRemainingNotif = TextComponent.of(
1082-
//TODO - to be moved into captions/translatablecomponents
1083-
"You have " + (actor.getLimit().SCHEM_FILE_NUM_LIMIT - numFiles)
1084-
+ " schematic file slots left.",
1085-
TextColor.GRAY
1086-
);
1087-
actor.print(slotsRemainingNotif);
1068+
actor.print(Caption.of("fawe.worldedit.schematic.schematic.slots.free", (actor.getLimit().SCHEM_FILE_NUM_LIMIT - numFiles)));
10881069
}
10891070
LOGGER.info(actor.getName() + " saved " + file.getCanonicalPath());
10901071
} else {

worldedit-core/src/main/resources/lang/strings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,12 @@
6868
"fawe.worldedit.schematic.schematic.move.failed": "{0} no moved: {1}",
6969
"fawe.worldedit.schematic.schematic.loaded": "{0} loaded. Paste it with //paste",
7070
"fawe.worldedit.schematic.schematic.saved": "{0} saved.",
71+
"fawe.worldedit.schematic.schematic.overwritten": "{0} saved (overwriting previous file).",
7172
"fawe.worldedit.schematic.schematic.none": "No files found.",
7273
"fawe.worldedit.schematic.schematic.load-failure": "File could not be read or it does not exist: {0}. If you are specifying a format, you may not be specifying the correct one. Sponge schematic v2 and v3 both use the .schem file extension. To allow FAWE to select the format, do not specify one. If you are using a litematica schematic, it is not supported!",
74+
"fawe.worldedit.schematic.schematic.size": "{0} size: {1}kb",
75+
"fawe.worldedit.schematic.schematic.disk.space": "You have {0}kb left for schematics.",
76+
"fawe.worldedit.schematic.schematic.slots.free": "You have {0} schematic file slots left.",
7377
"fawe.worldedit.clipboard.clipboard.uri.not.found": "You do not have {0} loaded",
7478
"fawe.worldedit.clipboard.clipboard.cleared": "Clipboard cleared",
7579
"fawe.worldedit.clipboard.clipboard.invalid.format": "Unknown clipboard format: {0}",
@@ -125,6 +129,8 @@
125129
"fawe.error.input-parser-exception": "Invalid empty string instead of boolean.",
126130
"fawe.error.invalid-boolean": "Invalid boolean {0}",
127131
"fawe.error.schematic.not.found": "Schematic {0} not found.",
132+
"fawe.error.schematic.over.count.limit": "You have {0}/{1} saved schematics. Delete some to save this one!",
133+
"fawe.error.schematic.over.disk.limit": "You're about to be at {0}kb of schematics ({1} available). Delete some first to save this one!",
128134
"fawe.error.parse.invalid-dangling-character": "Invalid dangling character {0}.",
129135
"fawe.error.parse.unknown-mask": "Unknown mask: {0}, See: {1}",
130136
"fawe.error.parse.unknown-pattern": "Unknown pattern: {0}, See: {1}",

0 commit comments

Comments
 (0)