From 34730ec8811f9cf78bb4dc2bfb5c640bc672f20b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beatrice=20Dellac=C3=A0?= Date: Thu, 11 Aug 2022 21:41:59 +0200 Subject: [PATCH] Add world capability check for setspawn --- .../commands/uhccommands/SetSpawnCommand.java | 12 +++++++++++- .../utils/configuration/LocalizedMessage.java | 1 + src/main/resources/lang.yml | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/wtf/beatrice/uhccore/commands/uhccommands/SetSpawnCommand.java b/src/main/java/wtf/beatrice/uhccore/commands/uhccommands/SetSpawnCommand.java index e39eb26..b4725df 100644 --- a/src/main/java/wtf/beatrice/uhccore/commands/uhccommands/SetSpawnCommand.java +++ b/src/main/java/wtf/beatrice/uhccore/commands/uhccommands/SetSpawnCommand.java @@ -1,12 +1,14 @@ package wtf.beatrice.uhccore.commands.uhccommands; import wtf.beatrice.uhccore.utils.Cache; +import wtf.beatrice.uhccore.utils.MessageUtils; import wtf.beatrice.uhccore.utils.configuration.ConfigEntry; import wtf.beatrice.uhccore.utils.configuration.FileUtils; import org.bukkit.Location; import org.bukkit.command.CommandSender; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; +import wtf.beatrice.uhccore.utils.configuration.LocalizedMessage; public class SetSpawnCommand { @@ -16,9 +18,17 @@ public class SetSpawnCommand Player player = (Player) sender; Location playerLoc = player.getLocation(); + String worldName = playerLoc.getWorld().getName(); + + if(!Cache.lobbyWorlds.contains(worldName)) + { + MessageUtils.sendLocalizedMessage(sender, LocalizedMessage.ERROR_NOT_IN_LOBBY_WORLD); + return; + } + Cache.spawn = playerLoc; YamlConfiguration config = FileUtils.FileType.CONFIG_YAML.yaml; - config.set(ConfigEntry.SPAWN_WORLD.path, playerLoc.getWorld().getName()); + config.set(ConfigEntry.SPAWN_WORLD.path, worldName); config.set(ConfigEntry.SPAWN_X.path, playerLoc.getX()); config.set(ConfigEntry.SPAWN_Y.path, playerLoc.getY()); config.set(ConfigEntry.SPAWN_Z.path, playerLoc.getZ()); diff --git a/src/main/java/wtf/beatrice/uhccore/utils/configuration/LocalizedMessage.java b/src/main/java/wtf/beatrice/uhccore/utils/configuration/LocalizedMessage.java index e999ed3..d8e2e59 100644 --- a/src/main/java/wtf/beatrice/uhccore/utils/configuration/LocalizedMessage.java +++ b/src/main/java/wtf/beatrice/uhccore/utils/configuration/LocalizedMessage.java @@ -9,6 +9,7 @@ public enum LocalizedMessage { ERROR_CONSOLE_ACCESS_BLOCKED("error.console_access_blocked"), ERROR_SERVER_NOT_SET_UP("error.server_not_set_up"), + ERROR_NOT_IN_LOBBY_WORLD("error.not_in_lobby_world"), ; diff --git a/src/main/resources/lang.yml b/src/main/resources/lang.yml index 1d7040c..5b92076 100644 --- a/src/main/resources/lang.yml +++ b/src/main/resources/lang.yml @@ -2,5 +2,6 @@ error: console_access: '&eWarning! You are accessing the plugin command from console.' console_access_blocked: '&cSorry, but this command is not available via console.' server_not_set_up: '&cThis server has no been set up!' + not_in_lobby_world: '&cYou can only do this in lobby worlds!' info: '&bThis is a colored and localized message!' player_position: '&bYour position is: &e%pos%' \ No newline at end of file