2021-10-11 15:52:56 +00:00
|
|
|
package net.tylermurphy.hideAndSeek.command;
|
|
|
|
|
|
|
|
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-11 15:52:56 +00:00
|
|
|
|
2021-10-21 00:14:01 +00:00
|
|
|
import static net.tylermurphy.hideAndSeek.Config.*;
|
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-18 02:52:57 +00:00
|
|
|
sender.sendMessage(errorPrefix + "Game is not setup. Run /hs setup to see what you needed to do");
|
2021-10-11 15:52:56 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
Player player = Bukkit.getServer().getPlayer(sender.getName());
|
|
|
|
if(player == null) {
|
|
|
|
sender.sendMessage(errorPrefix + "An internal error has occured");
|
|
|
|
return;
|
|
|
|
}
|
2021-10-21 00:14:01 +00:00
|
|
|
if(Main.plugin.board.isPlayer(player)){
|
2021-10-18 02:52:57 +00:00
|
|
|
sender.sendMessage(errorPrefix + "You are already in the lobby/game");
|
2021-10-11 21:06:21 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-10-21 00:14:01 +00:00
|
|
|
|
|
|
|
if(Main.plugin.status.equals("Standby")) {
|
|
|
|
Main.plugin.board.addHider(player);
|
2021-10-18 02:52:57 +00:00
|
|
|
if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(messagePrefix + sender.getName() + " has joined the HideAndSeek lobby");
|
2021-10-21 00:14:01 +00:00
|
|
|
else Util.broadcastMessage(messagePrefix + sender.getName() + " has joined the HideAndSeek lobby");
|
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-21 01:37:38 +00:00
|
|
|
Main.plugin.board.reloadLobbyBoards();
|
2021-10-18 02:52:57 +00:00
|
|
|
} else {
|
2021-10-21 00:14:01 +00:00
|
|
|
Main.plugin.board.addSeeker(player);
|
2021-10-18 02:52:57 +00:00
|
|
|
player.sendMessage(messagePrefix + "You have joined mid game and became a spectator");
|
|
|
|
player.setGameMode(GameMode.SPECTATOR);
|
|
|
|
player.teleport(new Location(Bukkit.getWorld("hideandseek_"+spawnWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ()));
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
}
|