Skip to content

Commit

Permalink
attempted fix of double implosion
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Martin committed Jun 8, 2024
1 parent eea0c7c commit 7cc0dc0
Showing 1 changed file with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

public class Session implements ISession {
protected final IMatchmaker matchmaker;
Expand All @@ -32,8 +33,8 @@ public class Session implements ISession {
protected Set<UUID> previousPlayers;
protected IRankedMCLoader mcLoader;
protected final Settings settings;
protected boolean ended = false;
protected boolean frozen = false;
protected AtomicBoolean ended = new AtomicBoolean(false);
protected AtomicBoolean frozen = new AtomicBoolean(false);

public Session(IMatchmaker matchmaker, Settings settings) {
this.matchmaker = matchmaker;
Expand All @@ -50,7 +51,7 @@ public Settings settings() {
}

public boolean ended() {
return this.ended;
return this.ended.get();
}

public IMatchmaker matchmaker() {
Expand All @@ -75,7 +76,7 @@ public int size() {
}

public boolean frozen() {
return this.frozen;
return this.frozen.get();
}

public Map<UUID, IMatchPlayer> players() {
Expand Down Expand Up @@ -105,7 +106,7 @@ public void start(IRankedMCLoader mcLoader) throws AlreadyBoundException {
((RankedMCLoader) mcLoader).connect(this);
this.mcLoader = mcLoader;

if(this.settings.shouldFreeze()) this.frozen = true;
if(this.settings.shouldFreeze()) this.frozen.set(true);
}

public PlayerConnectable.Request join(IMatchPlayer matchPlayer) {
Expand All @@ -117,7 +118,7 @@ public PlayerConnectable.Request join(IMatchPlayer matchPlayer) {
return request;
}

if(this.frozen) {
if(this.frozen.get()) {
result.complete(ConnectionResult.failed(Component.text("This session is already active and not accepting new players!")));
return request;
}
Expand Down Expand Up @@ -147,12 +148,12 @@ public PlayerConnectable.Request join(IMatchPlayer matchPlayer) {
}

public void leave(IPlayer player) {
if(this.ended.get()) return;

this.players.remove(player.uuid());

this.recordLeavingPlayer(player.uuid());

if(this.ended) return;

if(settings.quittersLose()) {
Optional<IMatchPlayer> matchPlayer = this.matchmaker.matchPlayer(player);
matchPlayer.ifPresent(mp -> mp.gameRank().computer().compute(List.of(), List.of(mp), matchmaker, this));
Expand Down Expand Up @@ -188,7 +189,7 @@ public void implode(String reason) {
}

public void end(List<UUID> winners, List<UUID> losers, boolean unlock) {
this.ended = true;
this.ended.set(true);

((Matchmaker) this.matchmaker).remove(this);

Expand Down Expand Up @@ -233,7 +234,7 @@ public void end(List<UUID> winners, List<UUID> losers) {
}

public void endTied(boolean unlock) {
this.ended = true;
this.ended.set(true);

((Matchmaker) this.matchmaker).remove(this);

Expand Down

0 comments on commit 7cc0dc0

Please sign in to comment.