Skip to content

Commit

Permalink
Add proximity setting for auto (#1428)
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo Herrera <[email protected]>
  • Loading branch information
Pablete1234 authored Nov 14, 2024
1 parent 96372f1 commit 7397d46
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 26 deletions.
9 changes: 5 additions & 4 deletions core/src/main/java/tc/oc/pgm/PGMConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public final class PGMConfig implements Config {
private final boolean showTabList;
private final boolean resizeTabList;
private final boolean showTabListPing;
private final boolean showProximity;
private final Boolean showProximity;
private final boolean showFireworks;
private final boolean participantsSeeObservers;
private final boolean verboseStats;
Expand Down Expand Up @@ -202,7 +202,8 @@ public final class PGMConfig implements Config {
this.queueJoin = parseBoolean(config.getString("join.queue", "false"));
this.anytimeJoin = parseBoolean(config.getString("join.anytime", "true"));

this.showProximity = parseBoolean(config.getString("ui.proximity", "false"));
var proximityStr = config.getString("ui.proximity", "false");
this.showProximity = proximityStr.equalsIgnoreCase("auto") ? null : parseBoolean(proximityStr);
this.showSideBar = parseBoolean(config.getString("ui.sidebar", "true"));
this.showTabList = parseBoolean(config.getString("ui.tablist", "true"));
this.resizeTabList = parseBoolean(config.getString("ui.tablist-resize", "false"));
Expand Down Expand Up @@ -558,8 +559,8 @@ public boolean shouldQueueJoin() {
}

@Override
public boolean showProximity() {
return showProximity;
public boolean showProximity(boolean relevant) {
return showProximity != null ? showProximity : relevant;
}

@Override
Expand Down
12 changes: 11 additions & 1 deletion core/src/main/java/tc/oc/pgm/api/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,17 @@ public interface Config {
*
* @return If proximity is visible.
*/
boolean showProximity();
default boolean showProximity() {
return showProximity(false);
}

/**
* Gets whether proximity metrics are visible to players.
*
* @param relevant If proximity is currently relevant (ie: an active time limit)
* @return If proximity is visible.
*/
boolean showProximity(boolean relevant);

/**
* Gets whether the side bar is rendered.
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/tc/oc/pgm/core/Core.java
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public String renderCompletion() {
return StringUtils.percentage(this.getCompletion());
}

@Nullable
@NotNull
@Override
public String renderPreciseCompletion() {
return this.leak + "/" + this.leakRequired;
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/tc/oc/pgm/destroyable/Destroyable.java
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ public String renderCompletion() {
return StringUtils.percentage(this.getCompletion());
}

@NotNull
@Override
public String renderPreciseCompletion() {
return this.getBreaks() + "/" + this.getBreaksRequired();
Expand Down
31 changes: 16 additions & 15 deletions core/src/main/java/tc/oc/pgm/goals/ProximityGoal.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import tc.oc.pgm.goals.events.GoalCompleteEvent;
import tc.oc.pgm.goals.events.GoalProximityChangeEvent;
import tc.oc.pgm.goals.events.GoalTouchEvent;
import tc.oc.pgm.timelimit.TimeLimitMatchModule;
import tc.oc.pgm.util.LegacyFormatUtils;
import tc.oc.pgm.util.block.BlockVectors;
import tc.oc.pgm.util.collection.DefaultMapAdapter;
Expand Down Expand Up @@ -91,13 +92,12 @@ public void resetProximity(Competitor team) {
Integer oldProximity = proximity.remove(team);
if (oldProximity != null) {
getMatch()
.callEvent(
new GoalProximityChangeEvent(
this,
team,
null,
distanceFromDistanceSquared(oldProximity),
Double.POSITIVE_INFINITY));
.callEvent(new GoalProximityChangeEvent(
this,
team,
null,
distanceFromDistanceSquared(oldProximity),
Double.POSITIVE_INFINITY));
}
}

Expand Down Expand Up @@ -145,13 +145,12 @@ public boolean updateProximity(ParticipantState player, Location location) {
if (newProximity < oldProximity) {
proximity.put(player.getParty(), newProximity);
getMatch()
.callEvent(
new GoalProximityChangeEvent(
this,
player.getParty(),
location,
distanceFromDistanceSquared(oldProximity),
distanceFromDistanceSquared(newProximity)));
.callEvent(new GoalProximityChangeEvent(
this,
player.getParty(),
location,
distanceFromDistanceSquared(oldProximity),
distanceFromDistanceSquared(newProximity)));
return true;
}
}
Expand All @@ -160,7 +159,9 @@ public boolean updateProximity(ParticipantState player, Location location) {

public boolean shouldShowProximity(@Nullable Competitor team, Party viewer) {
return team != null
&& PGM.get().getConfiguration().showProximity()
&& PGM.get()
.getConfiguration()
.showProximity(match.moduleRequire(TimeLimitMatchModule.class).willUseProximity())
&& isProximityRelevant(team)
&& (viewer == team || viewer.isObserving());
}
Expand Down
19 changes: 18 additions & 1 deletion core/src/main/java/tc/oc/pgm/scoreboard/SidebarMatchModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import tc.oc.pgm.api.player.event.MatchPlayerDeathEvent;
import tc.oc.pgm.blitz.BlitzMatchModule;
import tc.oc.pgm.destroyable.Destroyable;
import tc.oc.pgm.events.CountdownCancelEvent;
import tc.oc.pgm.events.CountdownStartEvent;
import tc.oc.pgm.events.FeatureChangeEvent;
import tc.oc.pgm.events.ListenerScope;
import tc.oc.pgm.events.PlayerJoinMatchEvent;
Expand All @@ -47,6 +49,8 @@
import tc.oc.pgm.score.ScoreMatchModule;
import tc.oc.pgm.spawns.events.ParticipantSpawnEvent;
import tc.oc.pgm.teams.events.TeamRespawnsChangeEvent;
import tc.oc.pgm.timelimit.TimeLimitCountdown;
import tc.oc.pgm.timelimit.TimeLimitMatchModule;
import tc.oc.pgm.util.TimeUtils;
import tc.oc.pgm.util.bukkit.ViaUtils;
import tc.oc.pgm.util.concurrent.RateLimiter;
Expand Down Expand Up @@ -209,11 +213,24 @@ public void goalStatusChange(final GoalStatusChangeEvent event) {

@EventHandler(priority = EventPriority.MONITOR)
public void goalProximityChange(final GoalProximityChangeEvent event) {
if (PGM.get().getConfiguration().showProximity()) {
boolean willUseProx = match.moduleRequire(TimeLimitMatchModule.class).willUseProximity();
if (PGM.get().getConfiguration().showProximity(willUseProx)) {
renderSidebarDebounce();
}
}

@EventHandler(priority = EventPriority.MONITOR)
public void timelimitToggle(final CountdownStartEvent event) {
if (!(event.getCountdown() instanceof TimeLimitCountdown)) return;
renderSidebarDebounce();
}

@EventHandler(priority = EventPriority.MONITOR)
public void timelimitToggle(final CountdownCancelEvent event) {
if (!(event.getCountdown() instanceof TimeLimitCountdown)) return;
renderSidebarDebounce();
}

@EventHandler(priority = EventPriority.MONITOR)
public void goalComplete(final GoalCompleteEvent event) {
renderSidebarDebounce();
Expand Down
8 changes: 8 additions & 0 deletions core/src/main/java/tc/oc/pgm/timelimit/TimeLimit.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import tc.oc.pgm.api.party.Competitor;
import tc.oc.pgm.api.party.VictoryCondition;
import tc.oc.pgm.features.SelfIdentifyingFeatureDefinition;
import tc.oc.pgm.goals.GoalsVictoryCondition;
import tc.oc.pgm.result.ImmediateVictoryCondition;
import tc.oc.pgm.util.collection.RankedSet;

@FeatureInfo(name = "time-limit")
Expand Down Expand Up @@ -68,6 +70,12 @@ public Duration getDuration() {
return result;
}

public boolean isProximityRelevant(boolean includeOvertime) {
return result == null
|| result instanceof GoalsVictoryCondition
|| (includeOvertime && overtime != null && !(result instanceof ImmediateVictoryCondition));
}

public boolean getShow() {
return show;
}
Expand Down
16 changes: 13 additions & 3 deletions core/src/main/java/tc/oc/pgm/timelimit/TimeLimitMatchModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,23 @@

public class TimeLimitMatchModule implements MatchModule {
private final Match match;
private final TimeLimit defaultTimeLimit;
private @Nullable TimeLimit timeLimit;
private @Nullable TimeLimitCountdown countdown;
private @Nullable OvertimeCountdown overtime;
private boolean willUseProximity;
private boolean finished; // If Time limit ended this match

public TimeLimitMatchModule(Match match, @Nullable TimeLimit timeLimit) {
this.match = match;
this.defaultTimeLimit = timeLimit;
this.timeLimit = timeLimit;
this.willUseProximity = timeLimit != null && timeLimit.isProximityRelevant(false);
}

@Override
public void load() {
setTimeLimit(defaultTimeLimit);
TimeLimit defaultTl = timeLimit;
this.timeLimit = null;
setTimeLimit(defaultTl);
}

@Override
Expand All @@ -41,6 +44,10 @@ public void setFinished(boolean finished) {
return this.timeLimit;
}

public boolean willUseProximity() {
return this.willUseProximity;
}

public void setTimeLimit(@Nullable TimeLimit timeLimit) {
if (timeLimit != this.timeLimit) {
match.getLogger().fine("Changing time limit to " + timeLimit);
Expand Down Expand Up @@ -70,6 +77,7 @@ public void start() {

// Match.finish() will cancel this, so we don't have to
if (this.timeLimit != null && match.isRunning()) {
this.willUseProximity = timeLimit.isProximityRelevant(false);
this.countdown = new TimeLimitCountdown(match, this.timeLimit);
this.countdown.start();
}
Expand All @@ -78,12 +86,14 @@ public void start() {
public void startOvertime() {
cancel();
if (this.timeLimit != null && this.timeLimit.getOvertime() != null && match.isRunning()) {
this.willUseProximity = timeLimit.isProximityRelevant(true);
this.overtime = new OvertimeCountdown(match, this.timeLimit);
this.overtime.start();
}
}

public void cancel() {
this.willUseProximity = false;
if (this.countdown != null) {
this.countdown.cancel();
this.countdown = null;
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ ui:
tablist: true # Enable the tab list?
tablist-resize: false # Resize the tab list for 1.7 players? Requires ProtocolLib
ping: false # Should tab list show real ping?
proximity: false # Should the proximity of objectives be visible?
proximity: auto # Should the proximity of objectives be visible?
fireworks: true # Spawn fireworks after objectives are completed?
participants-see-observers: true # Can participants see observers in the tab list?
flag-beams: false # Should everyone see floating wool flag beams?
Expand Down

0 comments on commit 7397d46

Please sign in to comment.