From e1c522e7a10c7accd65444a31e4e3686b8a65294 Mon Sep 17 00:00:00 2001 From: zontreck Date: Mon, 8 Jan 2024 17:28:47 -0700 Subject: [PATCH] Attempt to fix the Profiles unloading immediately on first join --- build.gradle | 2 ++ gradle.properties | 2 +- .../events/ForgeEventHandlers.java | 4 +-- .../libzontreck/profiles/Profile.java | 28 +++++++++++++++++-- 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index 9fa7e5e..783d07c 100644 --- a/build.gradle +++ b/build.gradle @@ -17,6 +17,7 @@ base { java { withSourcesJar() + withJavadocJar() } configurations { @@ -236,6 +237,7 @@ publishing { mavenJava(MavenPublication) { artifact jar artifact sourcesJar + artifact javadocJar } } repositories { diff --git a/gradle.properties b/gradle.properties index 9261777..c863f5b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -53,7 +53,7 @@ mod_name=Zontreck Library Mod # The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default. mod_license=GPLv3 # The mod version. See https://semver.org/ -mod_version=1.10.010224.1940 +mod_version=1.10.010824.1717 # The group ID for the mod. It is only important when publishing as an artifact to a Maven repository. # This should match the base package used for the mod sources. # See https://maven.apache.org/guides/mini/guide-naming-conventions.html diff --git a/src/main/java/dev/zontreck/libzontreck/events/ForgeEventHandlers.java b/src/main/java/dev/zontreck/libzontreck/events/ForgeEventHandlers.java index db5f5bb..89b9095 100644 --- a/src/main/java/dev/zontreck/libzontreck/events/ForgeEventHandlers.java +++ b/src/main/java/dev/zontreck/libzontreck/events/ForgeEventHandlers.java @@ -55,7 +55,7 @@ public class ForgeEventHandlers { @Override public void run() { // Check player wallet, then send wallet to client - ModMessages.sendToPlayer(new S2CWalletInitialSyncPacket(player.getUUID()), player); + //ModMessages.sendToPlayer(new S2CWalletInitialSyncPacket(player.getUUID()), player); } }, 10); } @@ -73,10 +73,10 @@ public class ForgeEventHandlers { Profile px=null; try { px = Profile.get_profile_of(ev.getEntity().getStringUUID()); + Profile.unload(px); } catch (UserProfileNotYetExistsException e) { e.printStackTrace(); } - Profile.unload(px); } } catch (InvalidSideException e) { throw new RuntimeException(e); diff --git a/src/main/java/dev/zontreck/libzontreck/profiles/Profile.java b/src/main/java/dev/zontreck/libzontreck/profiles/Profile.java index 82a60c5..5df6d63 100644 --- a/src/main/java/dev/zontreck/libzontreck/profiles/Profile.java +++ b/src/main/java/dev/zontreck/libzontreck/profiles/Profile.java @@ -16,6 +16,11 @@ import net.minecraft.nbt.NbtIo; import net.minecraft.server.level.ServerPlayer; import net.minecraftforge.common.MinecraftForge; +/** + * A libZontreck user profile + *

+ * This is used to contain common player data, as well as be capable of serializing the player's data and sending to/from the client. + */ public class Profile { public String username; public String user_id; @@ -78,6 +83,12 @@ public class Profile { } + /** + * Gets, or loads from persistent data, the user's LibZ profile + * @param UUID Player ID + * @return Profile + * @throws UserProfileNotYetExistsException When the profile has not yet been created + */ public static Profile get_profile_of(String UUID) throws UserProfileNotYetExistsException { if(LibZontreck.PROFILES.containsKey(UUID)){ @@ -122,6 +133,11 @@ public class Profile { return new Profile(tag.getString("user"), tag.getString("prefix"), tag.getString("nick"), tag.getString("nickc"), tag.getString("id"), tag.getString("prefixc"), tag.getString("chatc"), tag.getBoolean("flying"), tag.getInt("vaults"), accessor, tag.getInt("deaths"), player, tag.getCompound("misc"), tag.getCompound("data")); } + /** + * Generate a new user profile. + * + * @param player The player to generate the profile for + */ private static void generateNewProfile(ServerPlayer player) { @@ -133,10 +149,10 @@ public class Profile { Profile template = new Profile(player.getName().getString(), "Member", player.getDisplayName().getString(), ChatColor.GREEN, player.getStringUUID(), ChatColor.AQUA, ChatColor.WHITE, false, 0, ace, 0, player, new CompoundTag(), new CompoundTag()); template.commit(); + LibZontreck.PROFILES.put(player.getStringUUID(), template); + MinecraftForge.EVENT_BUS.post(new ProfileCreatedEvent(template)); - - template=null; return; }else { try { @@ -166,6 +182,11 @@ public class Profile { prof=null; } + /** + * Creates a profile if it does not yet exist + * @param play Player + * @return The existing, or new, profile instance. + */ public static Profile factory(ServerPlayer play) { try { @@ -176,6 +197,9 @@ public class Profile { } } + /** + * Save the profile to disk + */ public void commit() { // Save data to FileTree