diff options
author | Tyler Murphy <tylermurphy534@gmail.com> | 2021-12-30 12:17:32 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-30 12:17:32 -0500 |
commit | 31d60d7d23715aa3f063241c0c420ea0b0bf003b (patch) | |
tree | ca43ffa540d9629f6f0faf2ab3d5e5941db0f352 /src/main/java/net/tylermurphy/hideAndSeek/command/Start.java | |
parent | Merge pull request #16 from tylermurphy534/1.3.2 (diff) | |
parent | 1.3.3 rc5 (diff) | |
download | kenshinshideandseek-31d60d7d23715aa3f063241c0c420ea0b0bf003b.tar.gz kenshinshideandseek-31d60d7d23715aa3f063241c0c420ea0b0bf003b.tar.bz2 kenshinshideandseek-31d60d7d23715aa3f063241c0c420ea0b0bf003b.zip |
Merge pull request #20 from tylermurphy534/1.3.3
1.3.3
Diffstat (limited to 'src/main/java/net/tylermurphy/hideAndSeek/command/Start.java')
-rw-r--r-- | src/main/java/net/tylermurphy/hideAndSeek/command/Start.java | 137 |
1 files changed, 36 insertions, 101 deletions
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java index 05565da..b82e3b5 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java @@ -1,140 +1,75 @@ +/* + * 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 version 3. + * + * 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/>. + * + */ + package net.tylermurphy.hideAndSeek.command; + import static net.tylermurphy.hideAndSeek.configuration.Localization.*; -import org.bukkit.Bukkit; -import org.bukkit.GameMode; -import org.bukkit.Location; -import org.bukkit.Material; +import net.tylermurphy.hideAndSeek.game.Board; +import net.tylermurphy.hideAndSeek.game.Game; +import net.tylermurphy.hideAndSeek.util.Status; import org.bukkit.command.CommandSender; -import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.inventory.meta.PotionMeta; -import org.bukkit.potion.PotionData; -import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; -import org.bukkit.potion.PotionType; -import net.md_5.bungee.api.ChatColor; import net.tylermurphy.hideAndSeek.Main; -import net.tylermurphy.hideAndSeek.events.Glow; -import net.tylermurphy.hideAndSeek.events.Taunt; -import net.tylermurphy.hideAndSeek.events.Worldborder; -import net.tylermurphy.hideAndSeek.util.Util; import static net.tylermurphy.hideAndSeek.configuration.Config.*; -import java.util.ArrayList; -import java.util.List; +import java.util.Optional; import java.util.Random; public class Start implements ICommand { public void execute(CommandSender sender, String[] args) { - if(!Util.isSetup()) { + if(Game.isNotSetup()) { sender.sendMessage(errorPrefix + message("GAME_SETUP")); return; } - if(!Main.plugin.status.equals("Standby")) { + if(Game.status != Status.STANDBY) { sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); return; } - if(!Main.plugin.board.isPlayer(sender)) { + if(!Board.isPlayer(sender)) { sender.sendMessage(errorPrefix + message("GAME_NOT_INGAME")); return; } - if(Main.plugin.board.size() < minPlayers) { + if(Board.size() < minPlayers) { sender.sendMessage(errorPrefix + message("START_MIN_PLAYERS").addAmount(minPlayers)); return; } - if(Bukkit.getServer().getWorld("hideandseek_"+spawnWorld) != null) { - Main.plugin.worldLoader.rollback(); - } else { - Main.plugin.worldLoader.loadMap(); - } String seekerName; if(args.length < 1) { - seekerName = Main.plugin.board.getPlayers().stream().skip(new Random().nextInt(Main.plugin.board.size())).findFirst().get().getName(); + Optional<Player> rand = Board.getPlayers().stream().skip(new Random().nextInt(Board.size())).findFirst(); + if(!rand.isPresent()){ + Main.plugin.getLogger().warning("Failed to select random seeker."); + return; + } + seekerName = rand.get().getName(); } else { seekerName = args[0]; } - Player seeker = Main.plugin.board.getPlayer(seekerName); + Player seeker = Board.getPlayer(seekerName); if(seeker == null) { sender.sendMessage(errorPrefix + message("START_INVALID_NAME").addPlayer(seekerName)); return; } - Main.plugin.board.reload(); - for(Player temp : Main.plugin.board.getPlayers()) { - if(temp.getName().equals(seeker.getName())) - continue; - Main.plugin.board.addHider(temp); - } - Main.plugin.board.addSeeker(seeker); - currentWorldborderSize = worldborderSize; - for(Player player : Main.plugin.board.getPlayers()) { - player.getInventory().clear(); - player.setGameMode(GameMode.ADVENTURE); - player.teleport(new Location(Bukkit.getWorld("hideandseek_"+spawnWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ())); - for(PotionEffect effect : player.getActivePotionEffects()){ - player.removePotionEffect(effect.getType()); - } - } - for(Player player : Main.plugin.board.getSeekers()) { - player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS,1000000,127,false,false)); - player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW,1000000,127,false,false)); - player.sendTitle(ChatColor.RED + "" + ChatColor.BOLD + "SEEKER", ChatColor.WHITE + message("SEEKERS_SUBTITLE").toString(), 10, 70, 20); - } - for(Player player : Main.plugin.board.getHiders()) { - player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED,1000000,5,false,false)); - player.sendTitle(ChatColor.GOLD + "" + ChatColor.BOLD + "HIDER", ChatColor.WHITE + message("HIDERS_SUBTITLE").toString(), 10, 70, 20); - } - Worldborder.resetWorldborder("hideandseek_"+spawnWorld); - for(Player player : Main.plugin.board.getPlayers()){ - Main.plugin.board.createGameBoard(player); - } - Main.plugin.board.reloadGameBoards(); - Main.plugin.status = "Starting"; - int temp = Main.plugin.gameId; - Util.broadcastMessage(messagePrefix + message("START_COUNTDOWN").addAmount(30)); - Util.sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(20), Main.plugin.gameId, 20 * 10); - Util.sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(10), Main.plugin.gameId, 20 * 20); - Util.sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(5), Main.plugin.gameId, 20 * 25); - Util.sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(3), Main.plugin.gameId, 20 * 27); - Util.sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(2), Main.plugin.gameId, 20 * 28); - Util.sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(1), Main.plugin.gameId, 20 * 29); - Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, new Runnable() { - public void run() { - if(temp != Main.plugin.gameId) return; - Util.broadcastMessage(messagePrefix + message("START")); - Main.plugin.status = "Playing"; - for(Player player : Main.plugin.board.getPlayers()) { - Util.resetPlayer(player); - } - Main.plugin.worldborder = null; - Main.plugin.taunt = null; - Main.plugin.glow = null; - - if(worldborderEnabled) { - Main.plugin.worldborder = new Worldborder(Main.plugin.gameId); - Main.plugin.worldborder.schedule(); - } - - if(tauntEnabled) { - Main.plugin.taunt = new Taunt(Main.plugin.gameId); - Main.plugin.taunt.schedule(); - } - - if (glowEnabled) { - Main.plugin.glow = new Glow(Main.plugin.gameId); - } - - if(gameLength > 0) { - Main.plugin.timeLeft = gameLength; - } - } - }, 20 * 30); - + Game.start(seeker); } public String getLabel() { |