Skip to content

Commit

Permalink
Fix more possible NPE
Browse files Browse the repository at this point in the history
  • Loading branch information
thecatcore committed Aug 12, 2020
1 parent a5ee0ca commit 77f72db
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ minecraft_version=1.16.1
yarn_mappings=1.16.1+build.21
loader_version=0.9.0+build.204
# Mod Properties
mod_version=1.1.4
mod_version=1.1.5
maven_group=fr.catcore
archives_base_name=deacoudre
# Dependencies
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/fr/catcore/deacoudre/game/DeACoudreActive.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public static void open(GameWorld gameWorld, DeACoudreMap map, DeACoudreConfig c

builder.on(OfferPlayerListener.EVENT, player -> JoinResult.ok());
builder.on(PlayerAddListener.EVENT, active::addPlayer);
builder.on(PlayerRemoveListener.EVENT, active::eliminatePlayer);

builder.on(GameTickListener.EVENT, active::tick);

Expand Down Expand Up @@ -165,10 +166,16 @@ private void eliminatePlayer(ServerPlayerEntity player) {

this.spawnSpectator(player);
PlayerRef eliminated = PlayerRef.of(player);
this.nextJumper = nextPlayer(true);
for (PlayerRef playerRef : this.participants) {
if (playerRef == eliminated) {
eliminated = playerRef;
break;
}
}
this.participants.remove(eliminated);
this.lifeMap.remove(eliminated);
this.blockStateMap.remove(eliminated);
this.nextJumper = nextPlayer(true);
}

private void broadcastMessage(Text message) {
Expand All @@ -188,6 +195,10 @@ private void spawnSpectator(ServerPlayerEntity player) {
}

private void tick() {
if (this.nextJumper == null) {
this.nextJumper = nextPlayer(true);
return;
}
this.ticks++;
this.updateExperienceBar();
this.scoreboard.tick();
Expand Down Expand Up @@ -328,6 +339,7 @@ public PlayerRef nextPlayer(boolean newTurn) {
}
if (next == this.nextJumper && !this.ignoreWinState) {
DeACoudre.LOGGER.warn("next is equals to nextJumper, something might be wrong!");
return null;
}
return next;
}
Expand Down

0 comments on commit 77f72db

Please sign in to comment.