From 4ce0e46b0d2b5730b75fe3cc6bcf736b3d7076ca Mon Sep 17 00:00:00 2001 From: Luca Date: Tue, 23 Nov 2021 16:58:23 +0100 Subject: [PATCH] xdd --- .../commands/spectate/SpectateCommand.java | 47 +++++++++++++++++++ .../bedwars/managers/CommandManager.java | 3 ++ .../scoreboard/ScoreboardProvider.java | 25 ++++++++++ src/main/resources/plugin.yml | 4 +- 4 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 src/main/java/rip/tilly/bedwars/commands/spectate/SpectateCommand.java diff --git a/src/main/java/rip/tilly/bedwars/commands/spectate/SpectateCommand.java b/src/main/java/rip/tilly/bedwars/commands/spectate/SpectateCommand.java new file mode 100644 index 0000000..23429c0 --- /dev/null +++ b/src/main/java/rip/tilly/bedwars/commands/spectate/SpectateCommand.java @@ -0,0 +1,47 @@ +package rip.tilly.bedwars.commands.spectate; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import rip.tilly.bedwars.BedWars; +import rip.tilly.bedwars.game.Game; +import rip.tilly.bedwars.playerdata.PlayerData; +import rip.tilly.bedwars.playerdata.PlayerState; +import rip.tilly.bedwars.utils.CC; + +public class SpectateCommand implements CommandExecutor { + + private final BedWars plugin = BedWars.getInstance(); + + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + Player player = (Player) sender; + PlayerData playerData = this.plugin.getPlayerDataManager().getPlayerData(player.getUniqueId()); + + if (args.length == 0) { + player.sendMessage(CC.translate("&cUsage: /spectate ")); + } else { + if (playerData.getPlayerState() != PlayerState.SPAWN) { + player.sendMessage(CC.translate("&cYou need to be in the spawn to be able use this!")); + return true; + } + + Player target = this.plugin.getServer().getPlayer(args[0]); + if (target == null) { + player.sendMessage(CC.translate("&cError: player not found!")); + return true; + } + + PlayerData targetData = this.plugin.getPlayerDataManager().getPlayerData(target.getUniqueId()); + if (targetData.getPlayerState() != PlayerState.PLAYING) { + player.sendMessage(CC.translate("&cError: that player is not in a game!")); + return true; + } + + Game game = this.plugin.getGameManager().getGame(targetData); + this.plugin.getGameManager().addSpectator(player, playerData, target, game); + } + + return true; + } +} diff --git a/src/main/java/rip/tilly/bedwars/managers/CommandManager.java b/src/main/java/rip/tilly/bedwars/managers/CommandManager.java index ee12c80..be181c1 100644 --- a/src/main/java/rip/tilly/bedwars/managers/CommandManager.java +++ b/src/main/java/rip/tilly/bedwars/managers/CommandManager.java @@ -5,6 +5,7 @@ import rip.tilly.bedwars.commands.arena.ArenaCommand; import rip.tilly.bedwars.commands.level.LevelCommand; import rip.tilly.bedwars.commands.party.PartyCommand; import rip.tilly.bedwars.commands.setspawn.SetSpawnCommand; +import rip.tilly.bedwars.commands.spectate.SpectateCommand; import rip.tilly.bedwars.commands.toggle.ToggleCommand; import rip.tilly.bedwars.commands.xp.XpCommand; @@ -24,5 +25,7 @@ public class CommandManager { this.main.getCommand("p").setExecutor(new PartyCommand()); this.main.getCommand("arena").setExecutor(new ArenaCommand()); this.main.getCommand("toggle").setExecutor(new ToggleCommand()); + this.main.getCommand("spectate").setExecutor(new SpectateCommand()); + this.main.getCommand("spec").setExecutor(new SpectateCommand()); } } diff --git a/src/main/java/rip/tilly/bedwars/providers/scoreboard/ScoreboardProvider.java b/src/main/java/rip/tilly/bedwars/providers/scoreboard/ScoreboardProvider.java index a329b22..485fd79 100644 --- a/src/main/java/rip/tilly/bedwars/providers/scoreboard/ScoreboardProvider.java +++ b/src/main/java/rip/tilly/bedwars/providers/scoreboard/ScoreboardProvider.java @@ -26,6 +26,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Set; import java.util.UUID; +import java.util.stream.Collectors; public class ScoreboardProvider implements BoardAdapter { @@ -243,8 +244,32 @@ public class ScoreboardProvider implements BoardAdapter { private List spectatingScoreboard(PlayerData playerData) { List lines = new ArrayList<>(); + Game game = this.plugin.getGameManager().getSpectatingGame(playerData.getUniqueId()); + GameTeam yourTeam = game.getTeams().get(0); + GameTeam opposingTeam = game.getTeams().get(1); lines.add(CC.scoreboardBar); + lines.add("&fDuration: &d" + game.getDuration()); + lines.add(" "); + if (yourTeam.isHasBed()) { + lines.add("&7[" + yourTeam.getPlayerTeam().getChatColor() + yourTeam.getPlayerTeam().getSmallName() + "&7] &a&l✓ &7(You)"); + } else if (yourTeam.getPlayingPlayers().size() > 0) { + lines.add("&7[" + yourTeam.getPlayerTeam().getChatColor() + yourTeam.getPlayerTeam().getSmallName() + "&7] &f" + yourTeam.getPlayingPlayers().size() + " &7(You)"); + } else { + lines.add("&7[" + yourTeam.getPlayerTeam().getChatColor() + yourTeam.getPlayerTeam().getSmallName() + "&7] &c&l✗ &7(You)"); + } + if (opposingTeam.isHasBed()) { + lines.add("&7[" + opposingTeam.getPlayerTeam().getChatColor() + opposingTeam.getPlayerTeam().getSmallName() + "&7] &a&l✓"); + } else if (opposingTeam.getPlayingPlayers().size() > 0) { + lines.add("&7[" + opposingTeam.getPlayerTeam().getChatColor() + opposingTeam.getPlayerTeam().getSmallName() + "&7] &f" + yourTeam.getPlayingPlayers().size()); + } else { + lines.add("&7[" + opposingTeam.getPlayerTeam().getChatColor() + opposingTeam.getPlayerTeam().getSmallName() + "&7] &c&l✗"); + } + lines.add(" "); + lines.add(yourTeam.getPlayerTeam().getChatColor() + yourTeam.playingPlayers().collect(Collectors.toList()).get(0).getName()); + lines.add("&7VS"); + lines.add(opposingTeam.getPlayerTeam().getChatColor() + opposingTeam.playingPlayers().collect(Collectors.toList()).get(0).getName()); + lines.add("&dtilly.rip"); lines.add(CC.scoreboardBar); return CC.translate(lines); diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 99d053f..173b0c7 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -12,4 +12,6 @@ commands: party: p: arena: - toggle: \ No newline at end of file + toggle: + spectate: + spec: \ No newline at end of file