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-18 02:52:57 +00:00
|
|
|
import net.tylermurphy.hideAndSeek.util.Functions;
|
2021-10-11 15:52:56 +00:00
|
|
|
import net.tylermurphy.hideAndSeek.util.ICommand;
|
|
|
|
|
|
|
|
import static net.tylermurphy.hideAndSeek.Store.*;
|
|
|
|
|
|
|
|
public class Join implements ICommand {
|
|
|
|
|
|
|
|
public void execute(CommandSender sender, String[] args) {
|
2021-10-18 02:52:57 +00:00
|
|
|
if(!Functions.setup()) {
|
|
|
|
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-11 21:06:21 +00:00
|
|
|
if(playerList.containsKey(player.getName())){
|
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-11 15:52:56 +00:00
|
|
|
playerList.put(player.getName(), player);
|
2021-10-18 02:52:57 +00:00
|
|
|
if(status.equals("Standby")) {
|
|
|
|
Hider.add(player.getName());
|
|
|
|
HiderTeam.addEntry(player.getName());
|
|
|
|
if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(messagePrefix + sender.getName() + " has joined the HideAndSeek lobby");
|
|
|
|
else Functions.broadcastMessage(messagePrefix + sender.getName() + " has joined the HideAndSeek lobby");
|
|
|
|
player.teleport(new Location(Bukkit.getWorld(lobbyWorld), lobbyPosition.getX(),lobbyPosition.getY(),lobbyPosition.getZ()));
|
|
|
|
player.setGameMode(GameMode.ADVENTURE);
|
|
|
|
} else {
|
|
|
|
Spectator.add(player.getName());
|
|
|
|
SpectatorTeam.addEntry(player.getName());
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
}
|