From a46ec5ec73a1f990bb16f8c481e634a4251bfcf2 Mon Sep 17 00:00:00 2001 From: Aria Date: Mon, 27 Feb 2023 23:05:46 -0700 Subject: [PATCH] Mark logged in event as final, add logout event --- gradle.properties | 2 +- .../libzontreck/events/ForgeEventHandlers.java | 16 +++++++++++++++- src/main/resources/META-INF/mods.toml | 2 +- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/gradle.properties b/gradle.properties index a0fc1f1..fa730f1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,5 +5,5 @@ org.gradle.daemon=false mc_version=1.18.2 forge_version=40.2.1 -myversion=1.0.5.0227232249 +myversion=1.0.5.0227232305 parchment_version=2022.11.06 \ No newline at end of file diff --git a/src/main/java/dev/zontreck/libzontreck/events/ForgeEventHandlers.java b/src/main/java/dev/zontreck/libzontreck/events/ForgeEventHandlers.java index 232d95f..38ae4f3 100644 --- a/src/main/java/dev/zontreck/libzontreck/events/ForgeEventHandlers.java +++ b/src/main/java/dev/zontreck/libzontreck/events/ForgeEventHandlers.java @@ -3,6 +3,7 @@ package dev.zontreck.libzontreck.events; import dev.zontreck.libzontreck.LibZontreck; import dev.zontreck.libzontreck.memory.PlayerContainer; import dev.zontreck.libzontreck.profiles.Profile; +import dev.zontreck.libzontreck.profiles.UserProfileNotYetExistsException; import net.minecraft.server.level.ServerPlayer; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent; @@ -34,7 +35,7 @@ public class ForgeEventHandlers { } @SubscribeEvent - public void onPlayerJoin(PlayerEvent.PlayerLoggedInEvent ev) + public void onPlayerJoin(final PlayerEvent.PlayerLoggedInEvent ev) { if(ev.getEntity().level.isClientSide)return; @@ -44,4 +45,17 @@ public class ForgeEventHandlers { MinecraftForge.EVENT_BUS.post(new ProfileLoadedEvent(prof)); } + @SubscribeEvent + public void onLeave(final PlayerEvent.PlayerLoggedOutEvent ev) + { + if(ev.getEntity().level.isClientSide)return; + // Get player profile, send disconnect alert, then commit profile and remove it from memory + Profile px=null; + try { + px = Profile.get_profile_of(ev.getEntity().getStringUUID()); + } catch (UserProfileNotYetExistsException e) { + e.printStackTrace(); + } + Profile.unload(px); + } } diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index d448516..f1d83ea 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -19,7 +19,7 @@ modId="libzontreck" #mandatory # The version number of the mod - there's a few well known ${} variables useable here or just hardcode it # ${file.jarVersion} will substitute the value of the Implementation-Version as read from the mod's JAR file metadata # see the associated build.gradle script for how to populate this completely automatically during a build -version="1.0.5.0227232249" #mandatory +version="1.0.5.0227232305" #mandatory # A display name for the mod displayName="LibZontreck" #mandatory # A URL to query for updates for this mod. See the JSON update specification https://mcforge.readthedocs.io/en/latest/gettingstarted/autoupdate/