Skip to content

Commit

Permalink
Fix invalid state when quitting from incorrect world
Browse files Browse the repository at this point in the history
Signed-off-by: Pablete1234 <[email protected]>
  • Loading branch information
Pablete1234 authored and Electroid committed Jan 23, 2021
1 parent 217c044 commit 685c73c
Showing 1 changed file with 10 additions and 21 deletions.
31 changes: 10 additions & 21 deletions core/src/main/java/tc/oc/pgm/listeners/PGMListener.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package tc.oc.pgm.listeners;

import static com.google.common.base.Preconditions.checkNotNull;
import static net.kyori.adventure.text.Component.join;
import static net.kyori.adventure.text.Component.space;
import static net.kyori.adventure.text.Component.text;
import static net.kyori.adventure.text.Component.translatable;
Expand Down Expand Up @@ -126,7 +125,8 @@ public void onPlayerLogin(final PlayerLoginEvent event) {

@EventHandler(priority = EventPriority.LOW)
public void addPlayerOnJoin(final PlayerJoinEvent event) {
if (this.mm.getMatch(event.getWorld()) == null) {
Match match = this.mm.getMatch(event.getWorld());
if (match == null) {
event
.getPlayer()
.kickPlayer(
Expand All @@ -140,7 +140,7 @@ public void addPlayerOnJoin(final PlayerJoinEvent event) {
return;
}

this.mm.getMatch(event.getWorld()).addPlayer(event.getPlayer());
match.addPlayer(event.getPlayer());
}

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
Expand All @@ -153,35 +153,24 @@ public void broadcastJoinMessage(final PlayerJoinEvent event) {
event.setJoinMessage(null);
MatchPlayer player = match.getPlayer(event.getPlayer());
if (player != null) {
if (!vm.isVanished(player.getId())) {
announceJoinOrLeave(player, true, false);
} else {
// Announce actual staff join
announceJoinOrLeave(player, true, true);
}
// Announce actual staff join
announceJoinOrLeave(player, true, vm.isVanished(player.getId()));
}
}
}

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void removePlayerOnDisconnect(PlayerQuitEvent event) {
Match match = this.mm.getMatch(event.getWorld());
if (match == null) return;
MatchPlayer player = this.mm.getPlayer(event.getPlayer());
if (player == null) return;

if (event.getQuitMessage() != null) {
MatchPlayer player = match.getPlayer(event.getPlayer());
if (player != null) {
if (!vm.isVanished(player.getId())) {
announceJoinOrLeave(player, false, false);
} else {
// Announce actual staff quit
announceJoinOrLeave(player, false, true);
}
}
// Announce actual staff quit
announceJoinOrLeave(player, false, vm.isVanished(player.getId()));
event.setQuitMessage(null);
}

match.removePlayer(event.getPlayer());
player.getMatch().removePlayer(event.getPlayer());
}

public static void announceJoinOrLeave(MatchPlayer player, boolean join, boolean staffOnly) {
Expand Down

0 comments on commit 685c73c

Please sign in to comment.