Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/src/main/java/tc/oc/pgm/flag/state/Carried.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public void tickRunning() {
}

if (!isFlag(carrier.getInventory().getHelmet())) {
this.dropFlag();
if (isCurrent()) this.dropFlag();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i find it somewhat concerning that tickRunning as a whole is called if its not the current state, how is this happening?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure but this isn't the only place we guard dropFlag like this; we also do so in onEvent (InventoryClickEvent event) in Carried but with an additional guard of delegating it to a ScheduledExecutorService only for MatchPhase.RUNNING.

Looking at usages of tickRunning, it's called only if the match is running in BaseState and the rest of the usages are just supers in classes extending BaseState.

}

Expand Down
9 changes: 8 additions & 1 deletion core/src/main/java/tc/oc/pgm/flag/state/Respawning.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextColor;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.Nullable;
import tc.oc.pgm.api.party.Party;
import tc.oc.pgm.flag.Flag;
Expand Down Expand Up @@ -54,7 +55,8 @@ protected Duration getDuration() {
public void enterState() {
super.enterState();

if (Duration.ZERO.equals(respawnTime)) return;
if (Duration.ZERO.equals(respawnTime) || !this.flag.getMatch().isRunning()) return;

// Respawn is delayed
String postName = this.post.getPostName();

Expand Down Expand Up @@ -84,6 +86,11 @@ protected void respawn(Component message) {
this.flag.transition(new Returned(this.flag, this.post, this.respawnTo));
}

@Override
protected boolean canSeeParticles(Player player) {
return !this.flag.getMatch().isFinished();
}

@Override
protected void tickSeconds(long seconds) {
super.tickSeconds(seconds);
Expand Down
24 changes: 11 additions & 13 deletions core/src/main/java/tc/oc/pgm/goals/TouchableGoal.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import tc.oc.pgm.goals.events.GoalCompleteEvent;
import tc.oc.pgm.goals.events.GoalTouchEvent;
import tc.oc.pgm.spawns.events.ParticipantDespawnEvent;
import tc.oc.pgm.util.Audience;

/**
* A {@link Goal} that may be 'touched' by players, meaning the player has made some tangible
Expand Down Expand Up @@ -189,19 +188,18 @@ public boolean shouldShowTouched(@Nullable Competitor team, Party viewer) {
protected void sendTouchMessage(@Nullable ParticipantState toucher, boolean includeToucher) {
if (!hasShowOption(ShowOption.SHOW_MESSAGES)) return;

Component message = getTouchMessage(toucher, false);
Audience.console().sendMessage(message);

if (shouldShowTouched(toucher.getParty())) {
if (showEnemyTouches())
ChatManager.broadcastMessage(
message, viewer -> toucher == null || !toucher.isPlayer(viewer));
else
ChatManager.broadcastPartyMessage(
message, toucher.getParty(), viewer -> toucher == null || !toucher.isPlayer(viewer));
}

if (toucher != null) {
Component message = getTouchMessage(toucher, false);

if (shouldShowTouched(toucher.getParty())) {
if (showEnemyTouches()) {
ChatManager.broadcastMessage(message, viewer -> !toucher.isPlayer(viewer));
} else {
ChatManager.broadcastPartyMessage(
message, toucher.getParty(), viewer -> !toucher.isPlayer(viewer));
}
}

if (includeToucher) {
toucher.sendMessage(getTouchMessage(toucher, true));
}
Expand Down
44 changes: 24 additions & 20 deletions core/src/main/java/tc/oc/pgm/listeners/MatchAnnouncer.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,28 @@ public void onMatchBegin(final MatchStartEvent event) {
@EventHandler(priority = EventPriority.MONITOR)
public void onMatchEnd(final MatchFinishEvent event) {
final Match match = event.getMatch();
final Collection<Competitor> winners = event.getWinners();
final boolean singleWinner = winners.size() == 1;

Component title;
if (winners.isEmpty()) {
title = translatable("broadcast.gameOver");
} else if (singleWinner) {
title = translatable(
Iterables.getOnlyElement(winners).isNamePlural()
? "broadcast.gameOver.teamWinners"
: "broadcast.gameOver.teamWinner",
TextFormatter.nameList(winners, NameStyle.FANCY, NamedTextColor.WHITE));
} else {
// 2 or more winners, show "Tied!" as the title
title = translatable("broadcast.gameOver.tied", NamedTextColor.YELLOW);
}

// broadcast match finish message
// Broadcast match finish titles to participants
for (MatchPlayer viewer : match.getPlayers()) {
Component title = null, subtitle = empty();
final Collection<Competitor> winners = event.getWinners();
final boolean singleWinner = winners.size() == 1;
if (winners.isEmpty()) {
title = translatable("broadcast.gameOver");
} else {
if (singleWinner) {
title = translatable(
Iterables.getOnlyElement(winners).isNamePlural()
? "broadcast.gameOver.teamWinners"
: "broadcast.gameOver.teamWinner",
TextFormatter.nameList(winners, NameStyle.FANCY, NamedTextColor.WHITE));
}
Component subtitle = empty();

if (!winners.isEmpty()) {
// Use stream here instead of #contains to avoid unchecked cast
if (winners.stream().anyMatch(w -> w == viewer.getParty())) {
// Winner
Expand All @@ -98,10 +103,7 @@ public void onMatchEnd(final MatchFinishEvent event) {
}
}

if (title == null) {
// 2 or more winners, show "Tied!" as the title
title = translatable("broadcast.gameOver.tied", NamedTextColor.YELLOW);

if (subtitle == empty()) {
// If 2 or 3 winners we show the winners as the subtitle
if (winners.size() <= 3) {
subtitle = TextFormatter.nameList(winners, NameStyle.FANCY, NamedTextColor.WHITE);
Expand All @@ -111,10 +113,12 @@ public void onMatchEnd(final MatchFinishEvent event) {
final Title.Times titleTimes = Title.Times.times(Duration.ZERO, fromTicks(40), fromTicks(40));
viewer.showTitle(title(title, subtitle, titleTimes));

viewer.sendMessage(title);

if (viewer.getParty() instanceof Competitor || !singleWinner) viewer.sendMessage(subtitle);
}

// Broadcast match finish message to the match
// This includes console
match.sendMessage(title);
}

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
Expand Down