Skip to content

Commit

Permalink
Improved end message
Browse files Browse the repository at this point in the history
  • Loading branch information
Devlrxxh committed Apr 7, 2024
1 parent 7080aee commit eb026cf
Show file tree
Hide file tree
Showing 9 changed files with 158 additions and 119 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,4 @@
</plugins>
</build>

</project>
</project>
2 changes: 2 additions & 0 deletions src/main/java/me/lrxh/practice/Locale.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public enum Locale {
MATCH_SHOW_REPLAY("MATCH.REPLAY.SHOW_REPLAY"),
MATCH_SHOW_REPLAY_HOVER("MATCH.REPLAY.RECEIVED_HOVER"),
MATCH_SHOW_REPLAY_RECEIVED_CLICKABLE("MATCH.REPLAY.RECEIVED_CLICKABLE"),
REMATCH_SHOW_REPLAY_HOVER("MATCH.REMATCH.RECEIVED_HOVER"),
REMATCH_SHOW_REPLAY_RECEIVED_CLICKABLE("MATCH.REMATCH.RECEIVED_CLICKABLE"),
MATCH_START_TIMER("MATCH.START_TIMER"),
MATCH_RESPAWN_TIMER("MATCH.RESPAWN_TIMER"),
MATCH_RESPAWNED("MATCH.RESPAWNED"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public class Selection {
private static final String SELECTION_METADATA_KEY = "CLAIM_SELECTION";



static {
SELECTION_WAND = new ItemBuilder(Material.GOLD_AXE)
.name("&6Selection Wand")
Expand Down
48 changes: 17 additions & 31 deletions src/main/java/me/lrxh/practice/match/Match.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,20 @@ public static void cleanup() {
}
}

public static ChatComponentBuilder[] getTeamAsComponent(GameParticipant<MatchGamePlayer> participants) {
List<ChatComponentBuilder> chatComponentBuilders = new ArrayList<>();

for (MatchGamePlayer matchGamePlayer : participants.getPlayers()) {
ChatComponentBuilder current = new ChatComponentBuilder(
Locale.MATCH_CLICK_TO_VIEW_NAME.format(matchGamePlayer.getUsername()))
.attachToEachPart(ChatHelper.hover(Locale.MATCH_CLICK_TO_VIEW_HOVER.format(matchGamePlayer.getUsername())))
.attachToEachPart(ChatHelper.click("/viewinv " + matchGamePlayer.getUuid().toString()));
chatComponentBuilders.add(current);
}
return chatComponentBuilders.toArray(new ChatComponentBuilder[0]);
}


public static int getInFightsCount(Queue queue) {
int i = 0;

Expand Down Expand Up @@ -305,25 +319,6 @@ public void end() {
arena.setActive(false);
}

for (Player participant : getPlayers()) {
if (participant != null && participant.isOnline()) {
if (Practice.getInstance().isReplay() && !kit.getGameRules().isBuild()) {
for (String msg : Locale.MATCH_SHOW_REPLAY.formatLines(participant)) {
if (msg.contains("%CLICKABLE%")) {
ChatComponentBuilder builder = new ChatComponentBuilder(Locale.MATCH_SHOW_REPLAY_RECEIVED_CLICKABLE.format(participant
));
builder.attachToEachPart(ChatHelper.click("/replay play " + participant.getUniqueId()));
builder.attachToEachPart(ChatHelper.hover(Locale.MATCH_SHOW_REPLAY_HOVER.format(participant)));

participant.sendMessage(builder.create());
} else {
participant.sendMessage(msg);
}
}
}
}
}

Practice.getInstance().getCache().getMatches().remove(this);
}

Expand Down Expand Up @@ -375,29 +370,20 @@ public void onRoundEnd() {
MatchSnapshot.getSnapshots().put(snapshot.getUuid(), snapshot);
}

List<BaseComponent[]> endingMessages = generateEndComponents();

// Send ending messages to game participants
for (GameParticipant<MatchGamePlayer> gameParticipant : getParticipants()) {
for (MatchGamePlayer gamePlayer : gameParticipant.getPlayers()) {
if (!gamePlayer.isDisconnected()) {
Player player = gamePlayer.getPlayer();

if (player != null) {
for (BaseComponent[] components : endingMessages) {
player.sendMessage(components);
}
}
sendEndMessage(player);
}
}
}

// Send ending messages to spectators
for (Player player : getSpectatorsAsPlayers()) {
for (BaseComponent[] components : endingMessages) {
player.sendMessage(components);
}

sendEndMessage(player);
removeSpectator(player);
}
}
Expand Down Expand Up @@ -800,7 +786,7 @@ protected List<Player> getSpectatorsAsPlayers() {
return players;
}

public abstract List<BaseComponent[]> generateEndComponents();
public abstract void sendEndMessage(Player player);


public void sendDeathMessage(Player dead, Player killer, boolean finalKill) {
Expand Down
77 changes: 49 additions & 28 deletions src/main/java/me/lrxh/practice/match/impl/BasicFreeForAllMatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
import me.lrxh.practice.util.ChatComponentBuilder;
import me.lrxh.practice.util.InventoryUtil;
import me.lrxh.practice.util.PlayerUtil;
import net.md_5.bungee.api.chat.BaseComponent;
import org.bukkit.Color;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class BasicFreeForAllMatch extends Match {
Expand Down Expand Up @@ -157,37 +157,58 @@ public void addSpectator(Player spectator, Player target) {
}

@Override
public List<BaseComponent[]> generateEndComponents() {
List<BaseComponent[]> componentsList = new ArrayList<>();

for (String line : Locale.MATCH_END_DETAILS.formatLines()) {
if (line.equalsIgnoreCase("%INVENTORIES%")) {
List<GameParticipant<MatchGamePlayer>> participants = new ArrayList<>(this.participants);
participants.remove(winningParticipant);


BaseComponent[] winners = generateInventoriesComponents(
Locale.MATCH_END_WINNER_INVENTORY.format(""), winningParticipant);

BaseComponent[] losers = generateInventoriesComponents(
Locale.MATCH_END_LOSER_INVENTORY.format(participants.size() > 1 ? "s" : ""), participants);

componentsList.add(winners);
componentsList.add(losers);

continue;
}

if (line.equalsIgnoreCase("%ELO_CHANGES%")) {
continue;
public void sendEndMessage(Player player) {
List<String> formattedStrings = new ArrayList<>(Locale.MATCH_END_DETAILS.formatLines());
for (String string : formattedStrings) {
if (string.equalsIgnoreCase("%INVENTORIES%")) {
ChatComponentBuilder winner = new ChatComponentBuilder(Locale.MATCH_END_WINNER_INVENTORY
.format(player));

PlayerUtil.sendMessage(player, Collections.singletonList(winner).toArray(new ChatComponentBuilder[0]), getTeamAsComponent(winningParticipant),
getTeamAsComponent(winningParticipant));

} else if (string.equalsIgnoreCase("%ENDMESSAGE%")) {
formattedStrings.remove(string);
} else if (string.equalsIgnoreCase("%ELO_CHANGES%")) {
formattedStrings.remove(string);
} else {
player.sendMessage(CC.translate(string));
}

componentsList.add(new ChatComponentBuilder("").parse(line).create());
}

return componentsList;
}

// @Override
// public List<BaseComponent[]> generateEndComponents(Player player) {
// List<BaseComponent[]> componentsList = new ArrayList<>();
//
// for (String line : Locale.MATCH_END_DETAILS.formatLines()) {
// if (line.equalsIgnoreCase("%INVENTORIES%")) {
// List<GameParticipant<MatchGamePlayer>> participants = new ArrayList<>(this.participants);
// participants.remove(winningParticipant);
//
//
// BaseComponent[] winners = generateInventoriesComponents(
// Locale.MATCH_END_WINNER_INVENTORY.format(""), winningParticipant);
//
// BaseComponent[] losers = generateInventoriesComponents(
// Locale.MATCH_END_LOSER_INVENTORY.format(participants.size() > 1 ? "s" : ""), participants);
//
// componentsList.add(winners);
// componentsList.add(losers);
//
// continue;
// }
//
// if (line.equalsIgnoreCase("%ELO_CHANGES%")) {
// continue;
// }
//
// componentsList.add(new ChatComponentBuilder("").parse(line).create());
// }
//
// return componentsList;
// }

public int getRemainingTeams() {
int remaining = 0;

Expand Down
92 changes: 45 additions & 47 deletions src/main/java/me/lrxh/practice/match/impl/BasicTeamMatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,18 @@
import me.lrxh.practice.profile.Profile;
import me.lrxh.practice.profile.meta.ProfileRematchData;
import me.lrxh.practice.queue.Queue;
import me.lrxh.practice.util.CC;
import me.lrxh.practice.util.ChatComponentBuilder;
import me.lrxh.practice.util.ChatHelper;
import me.lrxh.practice.util.PlayerUtil;
import me.lrxh.practice.util.elo.EloUtil;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import java.util.*;

@Getter
public class BasicTeamMatch extends Match {
Expand Down Expand Up @@ -253,42 +251,46 @@ public void addSpectator(Player spectator, Player target) {
}

@Override
public List<BaseComponent[]> generateEndComponents() {
List<BaseComponent[]> componentsList = new ArrayList<>();

for (String line : Locale.MATCH_END_DETAILS.formatLines()) {
if (line.equalsIgnoreCase("%INVENTORIES%")) {
BaseComponent[] winners = generateInventoriesComponents(
Locale.MATCH_END_WINNER_INVENTORY.format(participantA.getPlayers().size() == 1 ? "" : "s"),
winningParticipant);

BaseComponent[] losers = generateInventoriesComponents(
Locale.MATCH_END_LOSER_INVENTORY.format(participantB.getPlayers().size() == 1 ? "" : "s"),
losingParticipant);

if (participantA.getPlayers().size() == 1 && participantB.getPlayers().size() == 1) {
ChatComponentBuilder builder = new ChatComponentBuilder("");

for (BaseComponent component : winners) {
builder.append((TextComponent) component);
}

builder.append(new ChatComponentBuilder("&7 | ").create());

for (BaseComponent component : losers) {
builder.append((TextComponent) component);
}

componentsList.add(builder.create());
public void sendEndMessage(Player player) {
List<String> formattedStrings = new ArrayList<>(Locale.MATCH_END_DETAILS.formatLines());
for (String string : formattedStrings) {
if (string.equalsIgnoreCase("%INVENTORIES%")) {
ChatComponentBuilder winner = new ChatComponentBuilder(Locale.MATCH_END_WINNER_INVENTORY
.format(player));

ChatComponentBuilder separator = new ChatComponentBuilder("&7 | ");

ChatComponentBuilder loser = new ChatComponentBuilder(Locale.MATCH_END_LOSER_INVENTORY
.format(player));

PlayerUtil.sendMessage(player,
Collections.singletonList(winner).toArray(new ChatComponentBuilder[0]),
getTeamAsComponent(winningParticipant),
Collections.singletonList(separator).toArray(new ChatComponentBuilder[0]),
Collections.singletonList(loser).toArray(new ChatComponentBuilder[0]),
getTeamAsComponent(losingParticipant));

} else if (string.equalsIgnoreCase("%ENDMESSAGE%")) {
ChatComponentBuilder replay = new ChatComponentBuilder(Locale.MATCH_SHOW_REPLAY_RECEIVED_CLICKABLE.format(player));
replay.attachToEachPart(ChatHelper.click("/replay play " + player.getUniqueId()));
replay.attachToEachPart(ChatHelper.hover(Locale.MATCH_SHOW_REPLAY_HOVER.format(player)));

ChatComponentBuilder rematch = new ChatComponentBuilder(Locale.REMATCH_SHOW_REPLAY_RECEIVED_CLICKABLE.format(player));
rematch.attachToEachPart(ChatHelper.click("/rematch " + player.getName()));
rematch.attachToEachPart(ChatHelper.hover(Locale.REMATCH_SHOW_REPLAY_HOVER.format(player)));


if (Practice.getInstance().isReplay() && !kit.getGameRules().isBuild()) {
PlayerUtil.sendMessage(player,
Collections.singletonList(replay).toArray(new ChatComponentBuilder[0]),
Collections.singletonList(rematch).toArray(new ChatComponentBuilder[0]));
} else {
componentsList.add(winners);
componentsList.add(losers);
}
PlayerUtil.sendMessage(player,
Collections.singletonList(rematch).toArray(new ChatComponentBuilder[0]));

continue;
}
}

if (line.equalsIgnoreCase("%ELO_CHANGES%")) {
} else if (string.equalsIgnoreCase("%ELO_CHANGES%")) {
if (participantA.getPlayers().size() == 1 && participantB.getPlayers().size() == 1 && ranked) {
List<String> sectionLines = Locale.MATCH_ELO_CHANGES.formatLines(
winningParticipant.getConjoinedNames(),
Expand All @@ -298,19 +300,15 @@ public List<BaseComponent[]> generateEndComponents() {
(losingParticipant.getLeader().getEloMod()),
(losingParticipant.getLeader().getElo() - losingParticipant.getLeader().getEloMod())
);

for (String sectionLine : sectionLines) {
componentsList.add(new ChatComponentBuilder("").parse(sectionLine).create());
player.sendMessage(CC.translate(sectionLine));
}
}

continue;
} else {
player.sendMessage(CC.translate(string));
}

componentsList.add(new ChatComponentBuilder("").parse(line).create());
}

return componentsList;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class ProfileRematchData {
private final UUID target;
private final Kit kit;
private final long timestamp;
private Arena arena;
private final Arena arena;
private boolean sent;
private boolean receive;
private boolean cancelled;
Expand All @@ -41,6 +41,7 @@ public ProfileRematchData(UUID key, UUID sender, UUID target, Kit kit) {
this.target = target;
this.kit = kit;
this.timestamp = System.currentTimeMillis();
this.arena = Arena.getRandomArena(kit);
}

public void request() {
Expand Down Expand Up @@ -80,7 +81,7 @@ public void request() {
BaseComponent[] lineComponents = new ChatComponentBuilder("")
.parse(line)
.attachToEachPart(ChatHelper.hover(Locale.REMATCH_RECEIVED_REQUEST_HOVER.format(target)))
.attachToEachPart(ChatHelper.click("/rematch"))
.attachToEachPart(ChatHelper.click("/rematch " + sender.getName()))
.create();

components.add(lineComponents);
Expand Down
Loading

0 comments on commit eb026cf

Please sign in to comment.