Skip to content

Commit

Permalink
Improved replay system now requiring custom version of AdvancedReplay
Browse files Browse the repository at this point in the history
  • Loading branch information
Devlrxxh committed Apr 6, 2024
1 parent f31cfb0 commit d37d120
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand All @@ -66,6 +72,7 @@ public void create(Player player) {
return;
}

PlayerUtil.setInParty(player, true);
profile.setParty(new Party(player));

Practice.getInstance().getHotbar().giveHotbarItems(player);
Expand All @@ -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();
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
}
Expand Down
36 changes: 18 additions & 18 deletions src/main/java/me/lrxh/practice/match/Match.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -190,6 +191,7 @@ public void setupPlayer(Player player) {
profile.getMatch().getGamePlayer(player).setKitLoadout(getKit().getKitLoadout());
}
}

}

public Player getOpponent(UUID playerUUID) {
Expand Down Expand Up @@ -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()));

}
}
}

Expand All @@ -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<Player> getPlayers() {
Expand All @@ -269,9 +269,7 @@ public List<Player> 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);
Expand All @@ -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);
}
}
}

Expand All @@ -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());
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/me/lrxh/practice/party/Party.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/me/lrxh/practice/profile/Profile.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 21 additions & 3 deletions src/main/java/me/lrxh/practice/profile/ProfileListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -27,10 +28,14 @@ public List<String> 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);
}

Expand All @@ -47,7 +52,6 @@ public List<String> 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) {
Expand All @@ -56,6 +60,7 @@ public List<String> 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);
}
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/me/lrxh/practice/util/PlayerUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/scoreboard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ LOBBY:
- "<silent>"
- "<theme>server.net"
- "&7&m--------------------"
REPLAYING:
- "&7&m--------------------"
- "<theme>Replaying Match"
- "<silent>"
- "<theme>server.net"
- "&7&m--------------------"
IN-PARTY:
LOBBY:
- "&7&m--------------------"
Expand Down

0 comments on commit d37d120

Please sign in to comment.