diff --git a/common/src/main/java/net/william278/huskhomes/command/SetHomeCommand.java b/common/src/main/java/net/william278/huskhomes/command/SetHomeCommand.java index 1fa3888b..9fd3a55d 100644 --- a/common/src/main/java/net/william278/huskhomes/command/SetHomeCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/SetHomeCommand.java @@ -105,6 +105,11 @@ public class SetHomeCommand extends CommandBase { } yield plugin.getLocales().getLocale("set_home_success", setResult.savedPosition().get().meta.name); } + case SUCCESS_OVERWRITTEN -> { + assert setResult.savedPosition().isPresent(); + yield plugin.getLocales().getLocale("edit_home_update_location", + setResult.savedPosition().get().meta.name); + } case FAILED_DUPLICATE -> plugin.getLocales().getLocale("error_home_name_taken"); case FAILED_NAME_LENGTH -> plugin.getLocales().getLocale("error_home_name_length"); case FAILED_NAME_CHARACTERS -> plugin.getLocales().getLocale("error_home_name_characters"); diff --git a/common/src/main/java/net/william278/huskhomes/command/SetWarpCommand.java b/common/src/main/java/net/william278/huskhomes/command/SetWarpCommand.java index 53c809f7..f5f3f408 100644 --- a/common/src/main/java/net/william278/huskhomes/command/SetWarpCommand.java +++ b/common/src/main/java/net/william278/huskhomes/command/SetWarpCommand.java @@ -31,6 +31,11 @@ public class SetWarpCommand extends CommandBase { yield plugin.getLocales().getLocale("set_warp_success", setResult.savedPosition().get().meta.name); } + case SUCCESS_OVERWRITTEN -> { + assert setResult.savedPosition().isPresent(); + yield plugin.getLocales().getLocale("edit_warp_update_location", + setResult.savedPosition().get().meta.name); + } case FAILED_DUPLICATE -> plugin.getLocales().getLocale("error_warp_name_taken"); case FAILED_NAME_LENGTH -> plugin.getLocales().getLocale("error_warp_name_length"); case FAILED_NAME_CHARACTERS -> plugin.getLocales().getLocale("error_warp_name_characters"); diff --git a/common/src/main/java/net/william278/huskhomes/position/SavedPositionManager.java b/common/src/main/java/net/william278/huskhomes/position/SavedPositionManager.java index 2175d890..19956710 100644 --- a/common/src/main/java/net/william278/huskhomes/position/SavedPositionManager.java +++ b/common/src/main/java/net/william278/huskhomes/position/SavedPositionManager.java @@ -6,6 +6,7 @@ import net.william278.huskhomes.event.EventDispatcher; import net.william278.huskhomes.hook.MapHook; import net.william278.huskhomes.player.User; import net.william278.huskhomes.util.RegexUtil; +import net.william278.huskhomes.config.Settings; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -14,7 +15,7 @@ import java.util.Optional; import java.util.concurrent.CompletableFuture; /** - * Cross-platform manager for validating homes and warps and updating them as neccessary + * Cross-platform manager for validating homes and warps and updating them as necessary */ public class SavedPositionManager { @@ -108,7 +109,7 @@ public class SavedPositionManager { if (mapHook != null && existingHome.isPublic) { mapHook.updateHome(existingHome); } - return new SaveResult(SaveResult.ResultType.SUCCESS, Optional.of(existingHome)); + return new SaveResult(SaveResult.ResultType.SUCCESS_OVERWRITTEN, Optional.of(existingHome)); } return new SaveResult(SaveResult.ResultType.FAILED_EVENT_CANCELLED, Optional.empty()); }).join(); @@ -279,7 +280,7 @@ public class SavedPositionManager { if (mapHook != null) { mapHook.updateWarp(existingWarp); } - return new SaveResult(SaveResult.ResultType.SUCCESS, Optional.of(existingWarp)); + return new SaveResult(SaveResult.ResultType.SUCCESS_OVERWRITTEN, Optional.of(existingWarp)); } return new SaveResult(SaveResult.ResultType.FAILED_EVENT_CANCELLED, Optional.empty()); }).join(); @@ -422,8 +423,22 @@ public class SavedPositionManager { */ SUCCESS(true), + /** + * A home or warp was attempted to be set, but one already exists with the same name (for the user in the + * case of homes), so the existing position was updated instead. + *

+ * + * @implNote This will only fire if the {@link Settings#overwriteExistingHomesWarps} config value is + * set to {@code true} + */ + SUCCESS_OVERWRITTEN(true), + /** * The position was not set; one by this name has already been set (for the user in the case of homes) + *

+ * + * @implNote This will only fire if the {@link Settings#overwriteExistingHomesWarps} config value is + * set to {@code false} */ FAILED_DUPLICATE(false),