Skip to content

Commit 71a127b

Browse files
Clean up PAPI placeholders (#176)
* Clean up PAPI placeholders * Update placeholders.md * Update placeholders.md
1 parent a4aa41c commit 71a127b

71 files changed

Lines changed: 412 additions & 1659 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

API/src/main/java/dev/lrxh/api/match/ITeamFightMatch.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
public interface ITeamFightMatch extends IMatch {
1010
List<IParticipant> getParticipants();
1111

12-
IMatchTeam getTeamA();
12+
IMatchTeam getRedTeam();
1313

14-
IMatchTeam getTeamB();
14+
IMatchTeam getBlueTeam();
1515

1616
IMatchTeam getWinner();
1717

API/src/main/java/dev/lrxh/api/match/participant/IParticipant.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ public interface IParticipant {
5656

5757
String getHitsDifferenceUncolored(IParticipant otherParticipant);
5858

59+
IMatch getMatch();
60+
5961
void reset();
6062

6163
void toggleFreeze();
@@ -66,4 +68,5 @@ public interface IParticipant {
6668

6769
void resetCombo();
6870

71+
6972
}

Plugin/src/main/java/dev/lrxh/neptune/game/match/MatchService.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ public void startMatch(Participant playerRed, Participant playerBlue, Kit kit, V
4545
playerBlue.setColor(ParticipantColor.BLUE);
4646

4747
SoloFightMatch match = new SoloFightMatch(arena, kit, duel, Arrays.asList(playerRed, playerBlue), playerRed, playerBlue, rounds);
48+
playerRed.setMatch(match);
49+
playerBlue.setMatch(match);
4850
MatchReadyEvent event = new MatchReadyEvent(match);
4951
Bukkit.getPluginManager().callEvent(event);
5052
if (event.isCancelled()) {
@@ -69,7 +71,9 @@ public void startMatch(MatchTeam teamA, MatchTeam teamB, Kit kit, VirtualArena a
6971
participants.addAll(teamB.participants());
7072

7173
TeamFightMatch match = new TeamFightMatch(arena, kit, participants, teamA, teamB);
72-
74+
for (Participant participant : participants) {
75+
participant.setMatch(match);
76+
}
7377
MatchReadyEvent event = new MatchReadyEvent(match);
7478
Bukkit.getPluginManager().callEvent(event);
7579
if (event.isCancelled()) {
@@ -108,11 +112,6 @@ public void startMatch(IMatch match, Player redPlayer, Player bluePlayer) {
108112
return;
109113
}
110114

111-
List<Participant> participants = new ArrayList<>();
112-
for (IParticipant participant : match.getParticipants()) {
113-
participants.add((Participant) participant);
114-
}
115-
116115
ArenaService.get().copyFrom(match.getArena()).createDuplicate().thenAccept(virtualArena ->{
117116
Match neptuneMatch = new SoloFightMatch(
118117
virtualArena,

Plugin/src/main/java/dev/lrxh/neptune/game/match/impl/participant/Participant.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public class Participant implements IParticipant {
4444
private boolean frozen = false;
4545
private boolean bedBroken;
4646
private Time time;
47+
private Match match;
4748

4849
// ELO CHANGES
4950
private int eloChange = 0;
@@ -206,7 +207,7 @@ public void handleHit(Participant opponent) {
206207
Match match = API.getProfile(playerUUID).getMatch();
207208
if (match.getKit().is(KitRule.BOXING)) {
208209
if (match instanceof TeamFightMatch teamFightMatch
209-
? hits >= teamFightMatch.getTeamA().getParticipants().size() * 100
210+
? hits >= teamFightMatch.getRedTeam().getParticipants().size() * 100
210211
: hits >= 100) {
211212
opponent.setDeathCause(getLastAttacker() != null ? DeathCause.KILL : DeathCause.DIED);
212213
match.onDeath(opponent);

Plugin/src/main/java/dev/lrxh/neptune/game/match/impl/team/TeamFightMatch.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,30 +35,30 @@
3535
@Setter
3636
public class TeamFightMatch extends Match implements ITeamFightMatch {
3737

38-
private final MatchTeam teamA;
39-
private final MatchTeam teamB;
38+
private final MatchTeam redTeam;
39+
private final MatchTeam blueTeam;
4040

4141
public TeamFightMatch(VirtualArena arena, Kit kit, List<Participant> participants,
42-
MatchTeam teamA, MatchTeam teamB) {
42+
MatchTeam redTeam, MatchTeam blueTeam) {
4343
super(MatchState.STARTING, arena, kit, participants, 1, 1, true, false);
44-
this.teamA = teamA;
45-
this.teamB = teamB;
44+
this.redTeam = redTeam;
45+
this.blueTeam = blueTeam;
4646
}
4747

4848
public MatchTeam getParticipantTeam(Participant participant) {
49-
return teamA.participants().contains(participant) ? teamA : teamB;
49+
return redTeam.participants().contains(participant) ? redTeam : blueTeam;
5050
}
5151

5252
public IMatchTeam getParticipantTeam(IParticipant participant) {
5353
return getParticipantTeam((Participant) participant);
5454
}
5555

5656
public IMatchTeam getWinner() {
57-
return teamA.isLoser() ? teamB : teamA;
57+
return redTeam.isLoser() ? blueTeam : redTeam;
5858
}
5959

6060
public IMatchTeam getLoser() {
61-
return teamA.isLoser() ? teamA : teamB;
61+
return redTeam.isLoser() ? redTeam : blueTeam;
6262
}
6363

6464
@Override
@@ -71,7 +71,7 @@ public void win(Participant winner) {
7171
@Override
7272
public void end(Participant loser) {
7373
setState(MatchState.ENDING);
74-
MatchTeam winnerTeam = teamA.isLoser() ? teamB : teamA;
74+
MatchTeam winnerTeam = redTeam.isLoser() ? blueTeam : redTeam;
7575
MatchTeam loserTeam = getParticipantTeam(loser);
7676

7777

@@ -89,8 +89,8 @@ public void end(Participant loser) {
8989

9090
@Override
9191
public void sendEndMessage() {
92-
MatchTeam winnerTeam = teamA.isLoser() ? teamB : teamA;
93-
MatchTeam loserTeam = teamA.isLoser() ? teamA : teamB;
92+
MatchTeam winnerTeam = redTeam.isLoser() ? blueTeam : redTeam;
93+
MatchTeam loserTeam = redTeam.isLoser() ? redTeam : blueTeam;
9494

9595
forEachParticipant(participant ->
9696
MessagesLocale.MATCH_END_DETAILS_TEAM.send(participant.getPlayerUUID(), TagResolver.resolver(

Plugin/src/main/java/dev/lrxh/neptune/providers/placeholder/PlaceholderManager.java

Lines changed: 9 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -15,69 +15,15 @@ public PlaceholderManager() {
1515
this.placeholders = new ArrayList<>();
1616

1717
placeholders.addAll(Arrays.asList(
18-
new PingPlaceholder(),
19-
new InMatchPlaceholder(),
20-
new QueuedPlaceholder(),
21-
new WinsPlaceholder(),
22-
new LossesPlaceholder(),
23-
new KillsPlaceholder(),
24-
new DeathsPlaceholder(),
25-
new MaxPingPlaceholder(),
26-
new CurrentStreakPlaceholder(),
27-
new BestStreakPlaceholder(),
18+
new GlobalPlaceholders(),
19+
new KitPlaceholders(),
2820
new LastKitPlaceholder(),
29-
new ColorPlaceholder(),
30-
new KitDivisionPlaceholder(),
31-
new KitWinsPlaceholder(),
32-
new KitLossesPlaceholder(),
33-
new KitKillsPlaceholder(),
34-
new KitDeathsPlaceholder(),
35-
new KitCurrentStreakPlaceholder(),
36-
new KitBestStreakPlaceholder(),
3721
new LeaderboardPlaceholder(),
38-
new KitInMatchPlaceholder(),
39-
new KitQueuedPlaceholder(),
40-
new WinRatePlaceholder(),
41-
new OpponentPlaceholder(),
42-
new OpponentPingPlaceholder(),
43-
new ComboPlaceholder(),
44-
new OpponentComboPlaceholder(),
45-
new HitsPlaceholder(),
46-
new OpponentHitsPlaceholder(),
47-
new HitDifferencePlaceholder(),
48-
new TimePlaceholder(),
49-
new KitPlaceholder(),
50-
new ArenaPlaceholder(),
51-
new MaxPointsPlaceholder(),
52-
new PointsPlaceholder(),
53-
new OpponentPointsPlaceholder(),
54-
new BedBrokenPlaceholder(),
55-
new OpponentBedBrokenPlaceholder(),
56-
new PlayerRedNamePlaceholder(),
57-
new PlayerBlueNamePlaceholder(),
58-
new PlayerRedPingPlaceholder(),
59-
new PlayerBluePingPlaceholder(),
60-
new RedBedBrokenPlaceholder(),
61-
new BlueBedBrokenPlaceholder(),
62-
new AlivePlaceholder(),
63-
new OpponentAlivePlaceholder(),
64-
new MaxPlaceholder(),
65-
new OpponentMaxPlaceholder(),
66-
new InQueuePlaceholder(),
67-
new IsTeamMatchPlaceholder(),
68-
new KitEloPlaceholder(),
69-
new DivisionPlaceholder(),
70-
new EloPlaceholder(),
71-
new LeaderPlaceholder(),
72-
new SizePlaceholder(),
73-
new RedAlivePlaceholder(),
74-
new BlueAlivePlaceholder(),
75-
new RedMaxPlaceholder(),
76-
new BlueMaxPlaceholder(),
77-
new LossesPlaceholder(),
78-
new PartyMaxPlaceholder(),
22+
new MatchPlaceholders(),
23+
new PartyPlaceholders(),
24+
new PlayerPlaceholders(),
7925
new RecentMatchPlaceholder(),
80-
new StatePlaceholder()
26+
new TimePlaceholder()
8127
));
8228
}
8329

@@ -90,7 +36,9 @@ public static PlaceholderManager get() {
9036
public String parse(OfflinePlayer player, String text) {
9137
for (PAPIPlaceholder placeholder : placeholders) {
9238
if (placeholder.match(text)) {
93-
text = placeholder.parse(player, text);
39+
String parsed = placeholder.parse(player, text);
40+
if (parsed == null) continue;
41+
text = parsed;
9442
}
9543
}
9644
return text;

Plugin/src/main/java/dev/lrxh/neptune/providers/placeholder/PlaceholderUtil.java

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ public TagResolver getPlaceholders(Player player) {
4848
QueueEntry queue = QueueService.get().get(profile.getPlayerUUID());
4949
placeholders = TagResolver.resolver(placeholders, getSettingsResolvers(profile),
5050
Placeholder.parsed("division", globalStats.getDivision().getDisplayName()),
51-
Placeholder.parsed("kill-effect", profile.getSettingData().getKillEffect().getDisplayName()),
52-
Placeholder.parsed("kill-message", profile.getSettingData().getKillMessagePackage().getDisplayName()),
5351
Placeholder.unparsed("max-ping", String.valueOf(profile.getSettingData().getMaxPing())),
5452
Placeholder.unparsed("wins", String.valueOf(globalStats.getWins())),
5553
Placeholder.unparsed("losses", String.valueOf(globalStats.getLosses())),
@@ -98,6 +96,7 @@ else if (profile.hasState(ProfileState.IN_GAME, ProfileState.IN_SPECTATOR) && ma
9896
);
9997
}
10098
if (match != null) {
99+
kit = match.getKit();
101100
Participant participant = match.getParticipant(player);
102101
placeholders = TagResolver.resolver(placeholders,
103102
Placeholder.parsed("arena", match.getArena().getDisplayName()),
@@ -106,12 +105,6 @@ else if (profile.hasState(ProfileState.IN_GAME, ProfileState.IN_SPECTATOR) && ma
106105
Placeholder.unparsed("round", String.valueOf(match.getCurrentRound())),
107106
Placeholder.unparsed("time", match.getTime().formatTime())
108107
);
109-
if (kit.is(KitRule.BED_WARS) && participant != null) {
110-
placeholders = TagResolver.resolver(placeholders,
111-
Placeholder.unparsed("bed-broken", participant.isBedBroken() ? "&a✔" : "&c1"),
112-
Placeholder.unparsed("opponent-bed-broken", participant.getOpponent().isBedBroken() ? "&a✔" : "&c1")
113-
);
114-
}
115108
if (match instanceof SoloFightMatch sfm) {
116109
Participant red = sfm.getRedParticipant();
117110
Participant blue = sfm.getBlueParticipant();
@@ -120,8 +113,6 @@ else if (profile.hasState(ProfileState.IN_GAME, ProfileState.IN_SPECTATOR) && ma
120113
placeholders = TagResolver.resolver(placeholders,
121114
Placeholder.parsed("bed-broken", participant.getBedMessage()),
122115
Placeholder.parsed("opponent-bed-broken", opponent.getBedMessage()),
123-
Placeholder.parsed("red-bed-broken", red.getBedMessage()),
124-
Placeholder.parsed("blue-bed-broken", blue.getBedMessage()),
125116
Placeholder.parsed("opponent-combo", opponent.getComboMessage()),
126117
Placeholder.unparsed("combo", participant.getComboMessage()),
127118
Placeholder.unparsed("longest-combo", String.valueOf(participant.getLongestCombo())),
@@ -132,37 +123,45 @@ else if (profile.hasState(ProfileState.IN_GAME, ProfileState.IN_SPECTATOR) && ma
132123
Placeholder.unparsed("opponent-longest-combo", String.valueOf(opponent.getLongestCombo())),
133124
Placeholder.unparsed("opponent-hits", String.valueOf(opponent.getHits())),
134125
Placeholder.unparsed("opponent-hit-difference", String.valueOf(opponent.getHitsDifference(participant))),
135-
Placeholder.unparsed("opponent-points", String.valueOf(opponent.getPoints()))
126+
Placeholder.unparsed("opponent-points", String.valueOf(opponent.getPoints())),
127+
Placeholder.unparsed("opponent-elo", String.valueOf(opponent.getProfile().getGameData().getGlobalStats().getElo())),
128+
Placeholder.unparsed("opponent-kit-elo", String.valueOf(opponent.getProfile().getGameData().get(kit).getElo()))
136129
);
137130
if (opponent.getPlayer() != null) placeholders = TagResolver.resolver(placeholders,
138131
Placeholder.unparsed("opponent-ping", String.valueOf(opponent.getPlayer().getPing())));
139132
}
140133
placeholders = TagResolver.resolver(placeholders,
141134
Placeholder.parsed("red-combo", red.getComboMessage()),
142135
Placeholder.parsed("blue-combo", blue.getComboMessage()),
136+
Placeholder.parsed("red-elo", String.valueOf(red.getProfile().getGameData().getGlobalStats().getElo())),
137+
Placeholder.parsed("blue-elo", String.valueOf(blue.getProfile().getGameData().getGlobalStats().getElo())),
138+
Placeholder.parsed("red-kit-elo", String.valueOf(red.getProfile().getGameData().get(kit).getElo())),
139+
Placeholder.parsed("blue-elo", String.valueOf(blue.getProfile().getGameData().get(kit).getElo())),
143140
Placeholder.parsed("red-bed-broken", red.getBedMessage()),
144141
Placeholder.parsed("blue-bed-broken", blue.getBedMessage()),
145142
Placeholder.unparsed("red-name", red.getName()),
146143
Placeholder.unparsed("red-longest-combo", String.valueOf(red.getLongestCombo())),
147144
Placeholder.unparsed("red-hits", String.valueOf(red.getHits())),
148145
Placeholder.unparsed("red-hit-difference", red.getHitsDifference(sfm.getBlueParticipant())),
149146
Placeholder.unparsed("red-points", String.valueOf(red.getPoints())),
150-
Placeholder.unparsed("red-ping", String.valueOf(red.getPlayer().getPing())),
151147
Placeholder.unparsed("blue-name", blue.getName()),
152148
Placeholder.unparsed("blue-longest-combo", String.valueOf(blue.getLongestCombo())),
153149
Placeholder.unparsed("blue-hits", String.valueOf(blue.getHits())),
154150
Placeholder.unparsed("blue-hit-difference", blue.getHitsDifference(sfm.getRedParticipant())),
155-
Placeholder.unparsed("blue-points", String.valueOf(blue.getPoints())),
156-
Placeholder.unparsed("blue-ping", String.valueOf(blue.getPlayer().getPing()))
151+
Placeholder.unparsed("blue-points", String.valueOf(blue.getPoints()))
152+
);
153+
if (kit.is(KitRule.BED_WARS) && participant != null) placeholders = TagResolver.resolver(placeholders,
154+
Placeholder.parsed("bed-broken", participant.getBedMessage()),
155+
Placeholder.parsed("opponent-bed-broken", participant.getOpponent().getBedMessage())
157156
);
158157
if (red.getPlayer() != null) placeholders = TagResolver.resolver(placeholders,
159158
Placeholder.unparsed("red-ping", String.valueOf(red.getPlayer().getPing())));
160159
if (blue.getPlayer() != null) placeholders = TagResolver.resolver(placeholders,
161160
Placeholder.unparsed("blue-ping", String.valueOf(blue.getPlayer().getPing())));
162161
}
163162
if (match instanceof TeamFightMatch tfm) {
164-
MatchTeam red = tfm.getTeamA();
165-
MatchTeam blue = tfm.getTeamB();
163+
MatchTeam red = tfm.getRedTeam();
164+
MatchTeam blue = tfm.getBlueTeam();
166165
if (participant != null) {
167166
MatchTeam team = tfm.getParticipantTeam(participant);
168167
MatchTeam opponent = team.getOpponentTeam();

Plugin/src/main/java/dev/lrxh/neptune/providers/placeholder/impl/AlivePlaceholder.java

Lines changed: 0 additions & 29 deletions
This file was deleted.

Plugin/src/main/java/dev/lrxh/neptune/providers/placeholder/impl/ArenaPlaceholder.java

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)