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

93 lines
2.9 KiB
Java
Raw Normal View History

2021-12-27 19:03:08 +00:00
/*
* This file is part of Kenshins Hide and Seek
*
* Copyright (c) 2021 Tyler Murphy.
*
* Kenshins Hide and Seek free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* he Free Software Foundation, either version 3 of the License.
*
* Kenshins Hide and Seek is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
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-12-26 22:58:18 +00:00
import net.tylermurphy.hideAndSeek.game.Board;
import net.tylermurphy.hideAndSeek.game.Game;
import net.tylermurphy.hideAndSeek.util.Status;
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-12-26 22:58:18 +00:00
import java.util.Objects;
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-12-26 22:58:18 +00:00
if(Game.isNotSetup()) {
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-12-26 22:58:18 +00:00
if(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-12-26 22:58:18 +00:00
if(Game.status == Status.STANDBY) {
2021-10-29 23:57:40 +00:00
player.getInventory().clear();
2021-12-26 22:58:18 +00:00
Board.addHider(player);
2021-10-23 00:03:15 +00:00
if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(messagePrefix + message("GAME_JOIN").addPlayer(player));
2021-12-26 22:58:18 +00:00
else Game.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-12-26 22:58:18 +00:00
Board.createLobbyBoard(player);
Board.reloadLobbyBoards();
2021-10-18 02:52:57 +00:00
} else {
2021-12-26 22:58:18 +00:00
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-12-26 22:58:18 +00:00
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);
2021-12-26 22:58:18 +00:00
player.setHealth(Objects.requireNonNull(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
}
}