diff --git a/src/main/java/me/lrxh/practice/commands/user/duels/DuelCommand.java b/src/main/java/me/lrxh/practice/commands/user/duels/DuelCommand.java index 315e9bb..12c2445 100644 --- a/src/main/java/me/lrxh/practice/commands/user/duels/DuelCommand.java +++ b/src/main/java/me/lrxh/practice/commands/user/duels/DuelCommand.java @@ -2,6 +2,7 @@ import co.aikar.commands.BaseCommand; import co.aikar.commands.annotation.*; +import me.lrxh.practice.Practice; import me.lrxh.practice.arena.Arena; import me.lrxh.practice.duel.DuelProcedure; import me.lrxh.practice.duel.DuelRequest; @@ -14,6 +15,7 @@ import me.lrxh.practice.party.Party; import me.lrxh.practice.profile.Profile; import me.lrxh.practice.util.CC; +import me.lrxh.practice.util.PlayerUtil; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -40,6 +42,14 @@ public void execute(Player sender, String targetName) { sender.sendMessage(CC.RED + "You cannot duel a frozen player."); return; } + + if (Practice.getInstance().isReplay()) { + if (PlayerUtil.inReplay(target)) { + sender.sendMessage(CC.RED + "You cannot duel a replaying player."); + return; + } + } + Profile targetProfile = Profile.getByUuid(target.getUniqueId()); // if (sender.getUniqueId().equals(target.getUniqueId())) { // sender.sendMessage(CC.RED + "You cannot duel yourself."); diff --git a/src/main/java/me/lrxh/practice/commands/user/party/PartyCommand.java b/src/main/java/me/lrxh/practice/commands/user/party/PartyCommand.java index 5db567f..e2bdf54 100644 --- a/src/main/java/me/lrxh/practice/commands/user/party/PartyCommand.java +++ b/src/main/java/me/lrxh/practice/commands/user/party/PartyCommand.java @@ -11,6 +11,7 @@ import me.lrxh.practice.profile.Profile; import me.lrxh.practice.profile.ProfileState; import me.lrxh.practice.util.CC; +import me.lrxh.practice.util.PlayerUtil; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -52,7 +53,12 @@ public void create(Player player) { return; } - + if (Practice.getInstance().isReplay()) { + if (PlayerUtil.inReplay(player)) { + player.sendMessage(CC.RED + "You cannot create a party while in replay."); + return; + } + } Profile profile = Profile.getByUuid(player.getUniqueId()); if (profile.getParty() != null) { @@ -66,6 +72,7 @@ public void create(Player player) { return; } + PlayerUtil.setInParty(player, true); profile.setParty(new Party(player)); Practice.getInstance().getHotbar().giveHotbarItems(player); @@ -87,6 +94,7 @@ public void disband(Player player) { player.sendMessage(CC.RED + "You are not the leader of your party."); return; } + PlayerUtil.setInParty(player, false); profile.getParty().disband(); } @@ -210,6 +218,7 @@ public void join(Player player, String playerName) { player.sendMessage(CC.RED + "That party is full and cannot hold anymore players."); return; } + PlayerUtil.setInParty(player, true); party.join(player); } @@ -245,6 +254,7 @@ public void kick(Player player, String playerName) { player.sendMessage(CC.RED + "You cannot kick yourself from your party."); return; } + PlayerUtil.setInParty(target, false); profile.getParty().leave(target, true); } @@ -293,8 +303,10 @@ public void leave(Player player) { } if (profile.getParty().getLeader().equals(player)) { + PlayerUtil.setInParty(player, false); profile.getParty().disband(); } else { + PlayerUtil.setInParty(player, false); profile.getParty().leave(player, false); } } diff --git a/src/main/java/me/lrxh/practice/match/Match.java b/src/main/java/me/lrxh/practice/match/Match.java index 2644cbf..8d8f35d 100644 --- a/src/main/java/me/lrxh/practice/match/Match.java +++ b/src/main/java/me/lrxh/practice/match/Match.java @@ -162,12 +162,13 @@ public void setupPlayer(Player player) { PlayerUtil.reset(player); if (Practice.getInstance().isReplay() && !kit.getGameRules().isBuild()) { - if (!profile.getLastMatchId().isEmpty()) { - if (ReplaySaver.exists(profile.getLastMatchId())) { - ReplaySaver.delete(profile.getLastMatchId()); + if (profile.isReplay()) { + if (ReplaySaver.exists(profile.getUuid().toString())) { + ReplaySaver.delete(profile.getUuid().toString()); } + } else { + profile.setReplay(true); } - profile.setLastMatchId(matchId.toString()); } // Set the player's max damage ticks @@ -190,6 +191,7 @@ public void setupPlayer(Player player) { profile.getMatch().getGamePlayer(player).setKitLoadout(getKit().getKitLoadout()); } } + } public Player getOpponent(UUID playerUUID) { @@ -227,13 +229,19 @@ public void start() { // Setup players for (Player player : getPlayers()) { - if (player != null) { Profile profile = Profile.getByUuid(player.getUniqueId()); profile.setState(ProfileState.FIGHTING); profile.setMatch(this); profile.getDuelRequests().clear(); setupPlayer(player); + if (Practice.getInstance().isReplay()) { + ReplayAPI.getInstance().recordReplay + (profile.getUuid().toString(), getParticipants().stream().flatMap(participant -> participant.getPlayers().stream()) + .filter(gamePlayer -> !gamePlayer.isDisconnected()).map(MatchGamePlayer::getPlayer) + .collect(Collectors.toList())); + + } } } @@ -247,14 +255,6 @@ public void start() { if (kit.getGameRules().isBuild()) { arena.takeSnapshot(); } - - if (Practice.getInstance().isReplay()) { - ReplayAPI.getInstance().recordReplay - (matchId.toString(), getParticipants().stream().flatMap(participant -> participant.getPlayers().stream()) - .filter(gamePlayer -> !gamePlayer.isDisconnected()).map(MatchGamePlayer::getPlayer) - .collect(Collectors.toList())); - - } } public List getPlayers() { @@ -269,9 +269,7 @@ public List getPlayers() { public void end() { - if (Practice.getInstance().isReplay() && !kit.getGameRules().isBuild()) { - ReplayAPI.getInstance().stopReplay(matchId.toString(), true, true); - } + for (Player player : getPlayers()) { if (player != null) { player.setFireTicks(0); @@ -290,7 +288,9 @@ public void end() { if (objective != null) { objective.unregister(); } - profile.setLastMatchId(matchId.toString()); + if (Practice.getInstance().isReplay() && !kit.getGameRules().isBuild()) { + ReplayAPI.getInstance().stopReplay(profile.getUuid().toString(), true, true); + } } } @@ -312,7 +312,7 @@ public void end() { if (msg.contains("%CLICKABLE%")) { ChatComponentBuilder builder = new ChatComponentBuilder(Locale.MATCH_SHOW_REPLAY_RECEIVED_CLICKABLE.format(participant )); - builder.attachToEachPart(ChatHelper.click("/replay play " + matchId)); + builder.attachToEachPart(ChatHelper.click("/replay play " + participant.getUniqueId())); builder.attachToEachPart(ChatHelper.hover(Locale.MATCH_SHOW_REPLAY_HOVER.format(participant))); participant.sendMessage(builder.create()); diff --git a/src/main/java/me/lrxh/practice/party/Party.java b/src/main/java/me/lrxh/practice/party/Party.java index 777b15f..31107ca 100644 --- a/src/main/java/me/lrxh/practice/party/Party.java +++ b/src/main/java/me/lrxh/practice/party/Party.java @@ -7,10 +7,7 @@ import me.lrxh.practice.profile.Profile; import me.lrxh.practice.profile.ProfileState; import me.lrxh.practice.profile.visibility.VisibilityLogic; -import me.lrxh.practice.util.CC; -import me.lrxh.practice.util.ChatComponentBuilder; -import me.lrxh.practice.util.ChatHelper; -import me.lrxh.practice.util.PlaceholderUtil; +import me.lrxh.practice.util.*; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.entity.Player; @@ -159,6 +156,7 @@ public void disband() { for (Player player : getListOfPlayers()) { Profile profile = Profile.getByUuid(player.getUniqueId()); profile.setParty(null); + PlayerUtil.setInParty(player, false); if (profile.getState() == ProfileState.LOBBY || profile.getState() == ProfileState.QUEUEING) { Practice.getInstance().getHotbar().giveHotbarItems(player); diff --git a/src/main/java/me/lrxh/practice/profile/Profile.java b/src/main/java/me/lrxh/practice/profile/Profile.java index 9ed522c..5b41054 100644 --- a/src/main/java/me/lrxh/practice/profile/Profile.java +++ b/src/main/java/me/lrxh/practice/profile/Profile.java @@ -55,7 +55,7 @@ public class Profile { private Cooldown enderpearlCooldown; private Cooldown voteCooldown; private boolean silent = false; - private String lastMatchId = ""; + private boolean replay = false; public Profile(UUID uuid) { this.uuid = uuid; diff --git a/src/main/java/me/lrxh/practice/profile/ProfileListener.java b/src/main/java/me/lrxh/practice/profile/ProfileListener.java index 1678f8b..d52ae63 100644 --- a/src/main/java/me/lrxh/practice/profile/ProfileListener.java +++ b/src/main/java/me/lrxh/practice/profile/ProfileListener.java @@ -42,6 +42,24 @@ public void onSpawnTeleportEvent(SpawnTeleportEvent event) { } } + @EventHandler + public void onPlayerCommand(PlayerCommandPreprocessEvent event) { + Player player = event.getPlayer(); + String command = event.getMessage().split(" ")[0].substring(1); + + if (command.equalsIgnoreCase("msg")) return; + if (command.equalsIgnoreCase("reply")) return; + if (command.equalsIgnoreCase("r")) return; + if (command.equalsIgnoreCase("elo")) return; + + if (Practice.getInstance().isReplay()) { + if (PlayerUtil.inReplay(player)) { + player.sendMessage(CC.RED + "You cannot run commands while in replay mode."); + event.setCancelled(true); + } + } + } + @EventHandler public void onPlayerPickupItemEvent(PlayerPickupItemEvent event) { Profile profile = Profile.getByUuid(event.getPlayer().getUniqueId()); @@ -178,9 +196,9 @@ public void onPlayerQuitEvent(PlayerQuitEvent event) { Profile profile = Profile.getProfiles().get(event.getPlayer().getUniqueId()); if (Practice.getInstance().isReplay()) { - if (!profile.getLastMatchId().isEmpty()) { - if (ReplaySaver.exists(profile.getLastMatchId())) { - ReplaySaver.delete(profile.getLastMatchId()); + if (profile.isReplay()) { + if (ReplaySaver.exists(profile.getUuid().toString())) { + ReplaySaver.delete(profile.getUuid().toString()); } } } diff --git a/src/main/java/me/lrxh/practice/scoreboard/ScoreboardAdapter.java b/src/main/java/me/lrxh/practice/scoreboard/ScoreboardAdapter.java index a1c0514..70a1965 100644 --- a/src/main/java/me/lrxh/practice/scoreboard/ScoreboardAdapter.java +++ b/src/main/java/me/lrxh/practice/scoreboard/ScoreboardAdapter.java @@ -9,6 +9,7 @@ import me.lrxh.practice.profile.ProfileState; import me.lrxh.practice.queue.QueueProfile; import me.lrxh.practice.util.PlaceholderUtil; +import me.lrxh.practice.util.PlayerUtil; import me.lrxh.practice.util.assemble.AssembleAdapter; import org.bukkit.entity.Player; @@ -27,10 +28,14 @@ public List getLines(Player player) { Profile profile = Profile.getByUuid(player.getUniqueId()); if (profile.getState() == ProfileState.LOBBY) { - if (profile.getParty() != null) { return PlaceholderUtil.format(new ArrayList<>(Practice.getInstance().getScoreboardConfig().getStringList("IN-PARTY.LOBBY")), player); } + if (Practice.getInstance().isReplay()) { + if (PlayerUtil.inReplay(player)) { + return PlaceholderUtil.format(new ArrayList<>(Practice.getInstance().getScoreboardConfig().getStringList("REPLAYING")), player); + } + } return PlaceholderUtil.format(new ArrayList<>(Practice.getInstance().getScoreboardConfig().getStringList("LOBBY")), player); } @@ -47,7 +52,6 @@ public List getLines(Player player) { return PlaceholderUtil.format(new ArrayList<>(Practice.getInstance().getScoreboardConfig().getStringList("QUEUE.UNRANKED")), player); } - if (profile.getMatch() != null) { Match match = profile.getMatch(); if (match instanceof BasicTeamMatch && profile.getParty() != null) { @@ -56,6 +60,7 @@ public List getLines(Player player) { if (match instanceof BasicFreeForAllMatch) { return PlaceholderUtil.format(new ArrayList<>(Practice.getInstance().getScoreboardConfig().getStringList("IN-PARTY.IN-FFA-MATCH")), player); } + if (match.getState().equals(MatchState.STARTING_ROUND)) { return PlaceholderUtil.format(new ArrayList<>(Practice.getInstance().getScoreboardConfig().getStringList("MATCH.STARTING")), player); } diff --git a/src/main/java/me/lrxh/practice/util/PlayerUtil.java b/src/main/java/me/lrxh/practice/util/PlayerUtil.java index b3dbd52..9ce1d4a 100644 --- a/src/main/java/me/lrxh/practice/util/PlayerUtil.java +++ b/src/main/java/me/lrxh/practice/util/PlayerUtil.java @@ -54,6 +54,18 @@ public void setLastAttacker(Player victim, Player attacker) { } } + public void setInParty(Player victim, Boolean value) { + victim.setMetadata("inParty", new FixedMetadataValue(Practice.getInstance(), value)); + } + + public Boolean inReplay(Player player) { + if (player.hasMetadata("inReplay")) { + return player.getMetadata("inReplay").get(0).value().equals(true); + } + return false; + } + + public static void setImmune(Player player, int ticks) { player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, ticks, 250)); } diff --git a/src/main/resources/scoreboard.yml b/src/main/resources/scoreboard.yml index c7ed883..7cccc92 100644 --- a/src/main/resources/scoreboard.yml +++ b/src/main/resources/scoreboard.yml @@ -21,6 +21,12 @@ LOBBY: - "" - "server.net" - "&7&m--------------------" +REPLAYING: + - "&7&m--------------------" + - "Replaying Match" + - "" + - "server.net" + - "&7&m--------------------" IN-PARTY: LOBBY: - "&7&m--------------------"