Skip to content

Commit da5f5de

Browse files
committed
Add localization for position parse error messages
1 parent e9aacec commit da5f5de

6 files changed

Lines changed: 32 additions & 5 deletions

File tree

src/main/java/org/mvplugins/multiverse/core/command/MVCommandContexts.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ private ContentFilter parseContentFilter(BukkitCommandExecutionContext context)
116116
}
117117

118118
return destinationsProvider.parseDestination(context.getSender(), destination)
119-
.getOrThrow(failure -> MVInvalidCommandArgument.of(failure.getFailureMessage()));
119+
.getOrThrow(failure ->
120+
new InvalidCommandArgument(failure.getFailureMessage().formatted(context.getIssuer())));
120121
}
121122

122123
private GameRule<?> parseGameRule(BukkitCommandExecutionContext context) {

src/main/java/org/mvplugins/multiverse/core/locale/MVCorei18n.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,11 @@ public enum MVCorei18n implements MessageKeyProvider {
346346
EXCEPTION_MULTIVERSEWORLD_UNLOADPLAYERSINWORLD,
347347
EXCEPTION_MULTIVERSEWORLD_UNLOADERROR,
348348

349+
// multiverse position parse exception
350+
EXCEPTION_POSITIONPARSE_INVALIDDIRECTION,
351+
EXCEPTION_POSITIONPARSE_INVALIDCOORDINATES,
352+
EXCEPTION_POSITIONPARSE_INVALIDNUMBER,
353+
349354
// generic
350355
GENERIC_SUCCESS,
351356
GENERIC_FAILURE,

src/main/java/org/mvplugins/multiverse/core/utils/position/FaceDirection.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
import org.bukkit.Location;
44
import org.jetbrains.annotations.ApiStatus;
55
import org.mvplugins.multiverse.core.exceptions.utils.position.PositionParseException;
6+
import org.mvplugins.multiverse.core.locale.MVCorei18n;
7+
import org.mvplugins.multiverse.core.locale.message.Message;
68
import org.mvplugins.multiverse.core.utils.REPatterns;
79

10+
import static org.mvplugins.multiverse.core.locale.message.MessageReplacement.replace;
11+
812
/**
913
* Represents a direction to face, defined by pitch and yaw.
1014
*
@@ -62,7 +66,8 @@ public static FaceDirection ofLocation(org.bukkit.Location location) {
6266
public static FaceDirection fromString(String directionStr) throws PositionParseException {
6367
String[] parts = REPatterns.COLON.split(directionStr, 2);
6468
if (parts.length != 2) {
65-
throw new PositionParseException("Invalid direction string format: " + directionStr + ". Expected format: <pitch>:<yaw>");
69+
throw new PositionParseException(Message.of(MVCorei18n.EXCEPTION_POSITIONPARSE_INVALIDDIRECTION,
70+
replace("{format}").with(directionStr)));
6671
}
6772
//TODO: Add support for compass directions (N, S, E, W, NE, NW, SE, SW) for yaw
6873
PositionNumber pitch = PositionNumber.fromString(parts[0]);

src/main/java/org/mvplugins/multiverse/core/utils/position/PositionNumber.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
import io.vavr.control.Try;
44
import org.jetbrains.annotations.ApiStatus;
55
import org.mvplugins.multiverse.core.exceptions.utils.position.PositionParseException;
6+
import org.mvplugins.multiverse.core.locale.MVCorei18n;
7+
import org.mvplugins.multiverse.core.locale.message.Message;
8+
9+
import static org.mvplugins.multiverse.core.locale.message.MessageReplacement.replace;
610

711
/**
812
* Represents a number that can be either absolute or relative (prefixed with '~').
@@ -65,7 +69,9 @@ static PositionNumber fromString(String string) throws PositionParseException {
6569

6670
private static double tryParseDouble(String str) throws PositionParseException {
6771
return Try.of(() -> Double.parseDouble(str))
68-
.getOrElseThrow(throwable -> new PositionParseException("Invalid number: " + str));
72+
.getOrElseThrow(throwable -> new PositionParseException(
73+
Message.of(MVCorei18n.EXCEPTION_POSITIONPARSE_INVALIDNUMBER,
74+
replace("{number}").with(str))));
6975
}
7076

7177
/**

src/main/java/org/mvplugins/multiverse/core/utils/position/VectorPosition.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44
import org.bukkit.util.Vector;
55
import org.jetbrains.annotations.ApiStatus;
66
import org.mvplugins.multiverse.core.exceptions.utils.position.PositionParseException;
7+
import org.mvplugins.multiverse.core.locale.MVCorei18n;
8+
import org.mvplugins.multiverse.core.locale.message.Message;
79
import org.mvplugins.multiverse.core.utils.REPatterns;
810

11+
import static org.mvplugins.multiverse.core.locale.message.MessageReplacement.replace;
12+
913
/**
1014
* Represents an x, y, z position in 3D space, with support for absolute and relative coordinates.
1115
*
@@ -81,7 +85,8 @@ public static VectorPosition ofLocation(Location location) {
8185
public static VectorPosition fromString(String coordStr) throws PositionParseException {
8286
String[] parts = REPatterns.COMMA.split(coordStr);
8387
if (parts.length != 3) {
84-
throw new PositionParseException("Invalid coordinates format: " + coordStr + ". Expected format: <x>,<y>,<z>");
88+
throw new PositionParseException(Message.of(MVCorei18n.EXCEPTION_POSITIONPARSE_INVALIDCOORDINATES,
89+
replace("{format}").with(coordStr)));
8590
}
8691
return new VectorPosition(
8792
PositionNumber.fromString(parts[0]),

src/main/resources/multiverse-core_en.properties

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ mv-core.destination.cannon.failurereason.invalidformat=&cCannon destination form
255255
mv-core.destination.exact.failurereason.invalidformat=&cExact destination format is: &6e:worldname:x,y,z:pitch:yaw
256256
mv-core.destination.player.failurereason.playernotfound=&cPlayer '&6{player}&c' does not exist or is not online!
257257
mv-core.destination.shared.failurereason.invalidcoordinatesformat=You must specify a valid coordinate in this format: &6{x},{y},{z}
258-
mv-core.destination.shared.failurereason.invalidnumberformat=&cInvalid number format. {error}
258+
mv-core.destination.shared.failurereason.invalidnumberformat=&cInvalid destination input. {error}
259259
mv-core.destination.shared.failurereason.worldnotfound=&cWorld '&6{world}&c' does not exist or is not loaded!
260260
mv-core.destination.parse.failurereason.invaliddestinationid=Invalid destination id: {id}. Valid destination ids are: {ids}
261261

@@ -327,6 +327,11 @@ mv-core.exception.multiverseworld.unloaddefaultworld=&cYou can't unload the defa
327327
mv-core.exception.multiverseworld.unloadplayersinworld=&cThere are still &6{count}&c player(s) in the world! Use '&6--remove-players&c' flag to your command to teleport all players out of the world.
328328
mv-core.exception.multiverseworld.unloaderror=&cAn unknown error occurred while unloading world: &6{world}&c.\n&cSee console for more details.
329329

330+
# multiverse position parse exception
331+
mv-core.exception.positionparse.invaliddirection=&cInvalid direction string format: {format}. Expected format: <pitch>:<yaw>
332+
mv-core.exception.positionparse.invalidcoordinates=&cInvalid coordinates format: {format}. Expected format: <x>,<y>,<z>
333+
mv-core.exception.positionparse.invalidnumber=&cInvalid number format: {number}. Expects a numeric value.
334+
330335
# generic
331336
mv-core.generic.success=Success!
332337
mv-core.generic.failure=Failed!

0 commit comments

Comments
 (0)