From 64807ce97c566164bf2bb625bc7bc61fe7ff8739 Mon Sep 17 00:00:00 2001 From: aivruu Date: Sat, 28 Dec 2024 14:20:02 -0300 Subject: [PATCH] chore(HomeCommand): remove unnecessary parameters and provide status-code handling for teleporting operation --- .../homes/command/application/HomeCommand.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/plugin/src/main/java/io/github/aivruu/homes/command/application/HomeCommand.java b/plugin/src/main/java/io/github/aivruu/homes/command/application/HomeCommand.java index 87eeb3e..b5d013e 100644 --- a/plugin/src/main/java/io/github/aivruu/homes/command/application/HomeCommand.java +++ b/plugin/src/main/java/io/github/aivruu/homes/command/application/HomeCommand.java @@ -132,11 +132,15 @@ public HomeCommand( .executes(ctx -> { final Player player = (Player) ctx.getSource().getSender(); final MessagesConfigurationModel messages = super.messages.model(); - final boolean wasTeleported = this.playerHomeController.teleportToHome(player, ctx.getArgument("id", String.class)); - if (!wasTeleported) { - player.sendMessage(MiniMessageHelper.parse(messages.unknownHome)); - } else { - player.sendMessage(MiniMessageHelper.parse(messages.teleported)); + final byte teleportStatusCode = this.playerHomeController.teleportToHome(player, ctx.getArgument("id", String.class)); + switch (teleportStatusCode) { + case PlayerHomeController.PLAYER_HOME_DOES_NOT_EXIST -> + player.sendMessage(MiniMessageHelper.parse(messages.unknownHome)); + case PlayerHomeController.PLAYER_HOME_WORLD_IS_NOT_AVAILABLE -> + player.sendMessage(MiniMessageHelper.parse(messages.homeWorldUnavailable)); + case PlayerHomeController.PLAYER_HOME_TELEPORT_VALID -> + player.sendMessage(MiniMessageHelper.parse(messages.teleported)); + default -> player.sendMessage(MiniMessageHelper.parse(messages.playerUnknownInfo)); } return Command.SINGLE_SUCCESS; }) @@ -150,7 +154,7 @@ public HomeCommand( final MessagesConfigurationModel messages = super.messages.model(); final Player player = (Player) ctx.getSource().getSender(); final ValueObjectMutationResult result = this.homePositionUpdater.updatePosition( - player, ctx.getArgument("id", String.class), player.getLocation()); + player, ctx.getArgument("id", String.class)); switch (result.status()) { case ValueObjectMutationResult.MUTATED_STATUS -> player.sendMessage(MiniMessageHelper.parse(messages.locationModified));