fix(DiscordRPC): NPE on shutdown (#4723)

This commit is contained in:
Tobias Nett 2021-05-28 22:05:51 +02:00 committed by GitHub
parent 20aeb826ff
commit f8022aeee2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -71,20 +71,22 @@ public void postBegin() {
@Override
public void shutdown() {
if (delayManager.hasPeriodicAction(player.getClientEntity(), UPDATE_PARTY_SIZE_ID)) {
delayManager.cancelPeriodicAction(player.getClientEntity(), UPDATE_PARTY_SIZE_ID);
if (player != null) {
EntityRef client = player.getClientEntity();
if (delayManager != null && delayManager.hasPeriodicAction(client, UPDATE_PARTY_SIZE_ID)) {
delayManager.cancelPeriodicAction(client, UPDATE_PARTY_SIZE_ID);
}
}
DiscordRPCSubSystem.reset();
DiscordRPCSubSystem.setState("In Main Menu");
DiscordRPCSubSystem.setStartTimestamp(null);
}
@ReceiveEvent
public void onPlayerInitialized(LocalPlayerInitializedEvent event, EntityRef player) {
public void onPlayerInitialized(LocalPlayerInitializedEvent event, EntityRef localPlayer) {
/* Adds the periodic action when the player is hosting or playing online to update party size */
if (networkSystem.getMode() != NetworkMode.NONE) {
delayManager.addPeriodicAction(player, UPDATE_PARTY_SIZE_ID, 0, UPDATE_PARTY_SIZE_PERIOD);
delayManager.addPeriodicAction(localPlayer, UPDATE_PARTY_SIZE_ID, 0, UPDATE_PARTY_SIZE_PERIOD);
}
}