Add world capability check for setspawn
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Bea 2022-08-11 21:41:59 +02:00
parent 0783505dce
commit 34730ec881
3 changed files with 13 additions and 1 deletions

View File

@ -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());

View File

@ -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"),
;

View File

@ -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%'