This commit is contained in:
Luca 2021-11-23 16:58:23 +01:00
parent e1fba0573c
commit 4ce0e46b0d
4 changed files with 78 additions and 1 deletions

View File

@ -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 <player>"));
} 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;
}
}

View File

@ -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());
}
}

View File

@ -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<String> spectatingScoreboard(PlayerData playerData) {
List<String> 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);

View File

@ -12,4 +12,6 @@ commands:
party:
p:
arena:
toggle:
toggle:
spectate:
spec: