Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix invalid state when quitting from incorrect world #785

Merged
merged 1 commit into from
Jan 23, 2021
Merged
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
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