Attempt to fix the Profiles unloading immediately on first join

This commit is contained in:
zontreck 2024-01-08 17:28:47 -07:00
parent 5ad671cc73
commit e1c522e7a1
4 changed files with 31 additions and 5 deletions

View file

@ -17,6 +17,7 @@ base {
java { java {
withSourcesJar() withSourcesJar()
withJavadocJar()
} }
configurations { configurations {
@ -236,6 +237,7 @@ publishing {
mavenJava(MavenPublication) { mavenJava(MavenPublication) {
artifact jar artifact jar
artifact sourcesJar artifact sourcesJar
artifact javadocJar
} }
} }
repositories { repositories {

View file

@ -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. # The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=GPLv3 mod_license=GPLv3
# The mod version. See https://semver.org/ # 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. # 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. # This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html # See https://maven.apache.org/guides/mini/guide-naming-conventions.html

View file

@ -55,7 +55,7 @@ public class ForgeEventHandlers {
@Override @Override
public void run() { public void run() {
// Check player wallet, then send wallet to client // Check player wallet, then send wallet to client
ModMessages.sendToPlayer(new S2CWalletInitialSyncPacket(player.getUUID()), player); //ModMessages.sendToPlayer(new S2CWalletInitialSyncPacket(player.getUUID()), player);
} }
}, 10); }, 10);
} }
@ -73,10 +73,10 @@ public class ForgeEventHandlers {
Profile px=null; Profile px=null;
try { try {
px = Profile.get_profile_of(ev.getEntity().getStringUUID()); px = Profile.get_profile_of(ev.getEntity().getStringUUID());
Profile.unload(px);
} catch (UserProfileNotYetExistsException e) { } catch (UserProfileNotYetExistsException e) {
e.printStackTrace(); e.printStackTrace();
} }
Profile.unload(px);
} }
} catch (InvalidSideException e) { } catch (InvalidSideException e) {
throw new RuntimeException(e); throw new RuntimeException(e);

View file

@ -16,6 +16,11 @@ import net.minecraft.nbt.NbtIo;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
/**
* A libZontreck user profile
*<p></p>
* 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 class Profile {
public String username; public String username;
public String user_id; 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 public static Profile get_profile_of(String UUID) throws UserProfileNotYetExistsException
{ {
if(LibZontreck.PROFILES.containsKey(UUID)){ 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")); 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) 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()); 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(); template.commit();
LibZontreck.PROFILES.put(player.getStringUUID(), template);
MinecraftForge.EVENT_BUS.post(new ProfileCreatedEvent(template)); MinecraftForge.EVENT_BUS.post(new ProfileCreatedEvent(template));
template=null;
return; return;
}else { }else {
try { try {
@ -166,6 +182,11 @@ public class Profile {
prof=null; 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) public static Profile factory(ServerPlayer play)
{ {
try { try {
@ -176,6 +197,9 @@ public class Profile {
} }
} }
/**
* Save the profile to disk
*/
public void commit() public void commit()
{ {
// Save data to FileTree // Save data to FileTree