Update docs, bump version, add methods to get exception types

This commit is contained in:
William278 committed 2023-05-07 16:16:55 +01:00
1 parent 9ad75f1814
commit 4c21a930ef
7 files changed
+162 -40

No files matched your search

@@ -25,23 +25,15 @@ import org.jetbrains.annotations.NotNull;
public class TeleportationException extends IllegalStateException {
public TeleportationException(@NotNull Type error) {
super("Error during teleport operation: " + error.name());
}
private final Type type;
public enum Type {
TELEPORTER_NOT_FOUND,
TARGET_NOT_FOUND,
ALREADY_WARMING_UP,
ECONOMY_ACTION_FAILED,
WARMUP_ALREADY_MOVING,
WORLD_NOT_FOUND,
ILLEGAL_TARGET_COORDINATES,
CANNOT_TELEPORT_TO_SELF
public TeleportationException(@NotNull Type type) {
super("Error executing teleport: " + type.name());
this.type = type;
}
public void displayMessage(@NotNull CommandUser user, @NotNull HuskHomes plugin, @NotNull String... args) {
switch (Type.valueOf(getMessage().split(": ")[1])) {
switch (type) {
case TELEPORTER_NOT_FOUND, TARGET_NOT_FOUND -> plugin.getLocales()
.getLocale("error_player_not_found", args)
.ifPresent(user::sendMessage);
@@ -62,4 +54,25 @@ public class TeleportationException extends IllegalStateException {
.ifPresent(user::sendMessage);
}
}
@NotNull
@SuppressWarnings("unused")
public Type getType() {
return type;
}
/**
* The types of teleportation errors
*/
public enum Type {
TELEPORTER_NOT_FOUND,
TARGET_NOT_FOUND,
ALREADY_WARMING_UP,
ECONOMY_ACTION_FAILED,
WARMUP_ALREADY_MOVING,
WORLD_NOT_FOUND,
ILLEGAL_TARGET_COORDINATES,
CANNOT_TELEPORT_TO_SELF
}
}
@@ -26,15 +26,15 @@ import org.jetbrains.annotations.NotNull;
public class ValidationException extends IllegalArgumentException {
private final Type error;
private final Type type;
public ValidationException(@NotNull ValidationException.Type error) {
super("Error validating position: " + error.name());
this.error = error;
public ValidationException(@NotNull ValidationException.Type type) {
super("Error validating SavedPosition: " + type.name());
this.type = type;
}
public void dispatchHomeError(@NotNull CommandUser viewer, boolean other, @NotNull HuskHomes plugin, @NotNull String... args) {
switch (error) {
switch (type) {
case NOT_FOUND -> plugin.getLocales()
.getLocale(other ? "error_home_invalid_other" : "error_home_invalid", args)
.ifPresent(viewer::sendMessage);
@@ -44,6 +44,9 @@ public class ValidationException extends IllegalArgumentException {
case NAME_INVALID -> plugin.getLocales()
.getLocale("error_home_name_characters", args)
.ifPresent(viewer::sendMessage);
case DESCRIPTION_INVALID -> plugin.getLocales()
.getLocale("error_home_description_characters", args)
.ifPresent(viewer::sendMessage);
case NOT_ENOUGH_HOME_SLOTS, REACHED_MAX_HOMES -> plugin.getLocales()
.getLocale("error_set_home_maximum_homes", Integer.toString(plugin.getManager().homes()
.getMaxHomes(viewer instanceof OnlineUser user ? user : null)))
@@ -52,14 +55,11 @@ public class ValidationException extends IllegalArgumentException {
.getLocale("error_edit_home_maximum_public_homes", Integer.toString(plugin.getManager().homes()
.getMaxPublicHomes(viewer instanceof OnlineUser user ? user : null)))
.ifPresent(viewer::sendMessage);
case DESCRIPTION_INVALID -> plugin.getLocales()
.getLocale("error_home_description_characters", args)
.ifPresent(viewer::sendMessage);
}
}
public void dispatchWarpError(@NotNull CommandUser viewer, @NotNull HuskHomes plugin, @NotNull String... args) {
switch (error) {
switch (type) {
case NOT_FOUND -> plugin.getLocales()
.getLocale("error_warp_invalid", args)
.ifPresent(viewer::sendMessage);
@@ -75,6 +75,15 @@ public class ValidationException extends IllegalArgumentException {
}
}
@NotNull
@SuppressWarnings("unused")
public Type getType() {
return type;
}
/**
* The type of validation error
*/
public enum Type {
NOT_FOUND,
NAME_TAKEN,