kenshinshideandseek/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java

71 lines
2.2 KiB
Java
Raw Normal View History

2021-10-11 15:52:56 +00:00
package net.tylermurphy.hideAndSeek.command;
2021-10-23 00:03:15 +00:00
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
2021-10-11 15:52:56 +00:00
import org.bukkit.Bukkit;
2021-10-18 02:52:57 +00:00
import org.bukkit.GameMode;
2021-10-11 15:52:56 +00:00
import org.bukkit.Location;
2021-10-18 02:52:57 +00:00
import org.bukkit.attribute.Attribute;
2021-10-11 15:52:56 +00:00
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
2021-10-21 00:14:01 +00:00
import net.tylermurphy.hideAndSeek.Main;
import net.tylermurphy.hideAndSeek.util.Util;
2021-10-23 00:03:15 +00:00
import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
2021-10-11 15:52:56 +00:00
public class Join implements ICommand {
public void execute(CommandSender sender, String[] args) {
2021-10-21 00:14:01 +00:00
if(!Util.isSetup()) {
2021-10-23 00:03:15 +00:00
sender.sendMessage(errorPrefix + message("GAME_SETUP"));
2021-10-11 15:52:56 +00:00
return;
}
Player player = Bukkit.getServer().getPlayer(sender.getName());
if(player == null) {
2021-10-23 00:03:15 +00:00
sender.sendMessage(errorPrefix + message("COMMAND_ERROR"));
2021-10-11 15:52:56 +00:00
return;
}
2021-10-21 00:14:01 +00:00
if(Main.plugin.board.isPlayer(player)){
2021-10-23 00:03:15 +00:00
sender.sendMessage(errorPrefix + message("GAME_INGAME"));
2021-10-11 21:06:21 +00:00
return;
}
2021-10-29 23:57:40 +00:00
2021-10-31 15:25:27 +00:00
join(player);
}
public static void join(Player player){
2021-10-21 00:14:01 +00:00
if(Main.plugin.status.equals("Standby")) {
2021-10-29 23:57:40 +00:00
player.getInventory().clear();
2021-10-21 00:14:01 +00:00
Main.plugin.board.addHider(player);
2021-10-23 00:03:15 +00:00
if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(messagePrefix + message("GAME_JOIN").addPlayer(player));
else Util.broadcastMessage(messagePrefix + message("GAME_JOIN").addPlayer(player));
2021-10-18 02:52:57 +00:00
player.teleport(new Location(Bukkit.getWorld(lobbyWorld), lobbyPosition.getX(),lobbyPosition.getY(),lobbyPosition.getZ()));
player.setGameMode(GameMode.ADVENTURE);
2021-10-29 23:57:40 +00:00
Main.plugin.board.createLobbyBoard(player);
2021-10-21 01:37:38 +00:00
Main.plugin.board.reloadLobbyBoards();
2021-10-18 02:52:57 +00:00
} else {
2021-10-29 23:57:40 +00:00
Main.plugin.board.addSpectator(player);
2021-10-23 00:03:15 +00:00
player.sendMessage(messagePrefix + message("GAME_JOIN_SPECTATOR"));
2021-10-18 02:52:57 +00:00
player.setGameMode(GameMode.SPECTATOR);
2021-10-29 23:57:40 +00:00
Main.plugin.board.createGameBoard(player);
2021-10-18 02:52:57 +00:00
player.teleport(new Location(Bukkit.getWorld("hideandseek_"+spawnWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ()));
}
2021-10-31 15:25:27 +00:00
2021-10-18 02:52:57 +00:00
player.setFoodLevel(20);
player.setHealth(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getBaseValue());
2021-10-11 15:52:56 +00:00
}
public String getLabel() {
2021-10-11 21:06:21 +00:00
return "join";
2021-10-11 15:52:56 +00:00
}
public String getUsage() {
2021-10-11 21:06:21 +00:00
return "";
2021-10-11 15:52:56 +00:00
}
public String getDescription() {
2021-10-11 21:06:21 +00:00
return "Joins the lobby if game is set to manual join/leave";
2021-10-11 15:52:56 +00:00
}
}