Create a new event and add a few fields to existing events

This commit is contained in:
Aria 2023-03-05 15:53:56 -07:00
parent 957b65ebb3
commit ede19b0572
8 changed files with 61 additions and 11 deletions

View file

@ -10,7 +10,9 @@ import dev.zontreck.libzontreck.LibZontreck;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.libzontreck.events.ProfileCreatedEvent;
import dev.zontreck.libzontreck.events.ProfileUnloadedEvent;
import dev.zontreck.libzontreck.events.ProfileUnloadingEvent;
import dev.zontreck.libzontreck.util.FileTreeDatastore;
import dev.zontreck.libzontreck.util.ServerUtilities;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtIo;
import net.minecraft.server.level.ServerPlayer;
@ -26,6 +28,8 @@ public class Profile {
public String chat_color;
public Boolean flying;
public int available_vaults;
public int deaths;
public ServerPlayer player;
private File accessor;
@ -44,7 +48,7 @@ public class Profile {
}
}
public Profile(String username, String prefix, String nickname, String name_color, String ID, String prefix_color, String chat_color, Boolean isFlying, int vaults, File vaultFile) {
public Profile(String username, String prefix, String nickname, String name_color, String ID, String prefix_color, String chat_color, Boolean isFlying, int vaults, File vaultFile, int deathCount, ServerPlayer player) {
this.username = username;
this.prefix = prefix;
this.nickname = nickname;
@ -54,6 +58,8 @@ public class Profile {
this.chat_color = chat_color;
this.flying=isFlying;
this.available_vaults=vaults;
this.deaths=deathCount;
this.player=player;
this.accessor = vaultFile;
@ -72,7 +78,7 @@ public class Profile {
// Load profile data
File ace = userProfile.resolve("profile.nbt").toFile();
try {
Profile actual = load(NbtIo.read(ace), ace);
Profile actual = load(NbtIo.read(ace), ace, ServerUtilities.getPlayerByID(UUID));
LibZontreck.PROFILES.put(UUID, actual);
return actual;
} catch (IOException e) {
@ -94,9 +100,9 @@ public class Profile {
}
}
private static Profile load(CompoundTag tag, File accessor)
private static Profile load(CompoundTag tag, File accessor, ServerPlayer player)
{
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);
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);
}
private static void generateNewProfile(ServerPlayer player)
@ -107,7 +113,7 @@ public class Profile {
{
// Load profile data
File ace = userProfile.resolve("profile.nbt").toFile();
Profile template = new Profile(player.getName().getString(), "Member", player.getDisplayName().getString(), ChatColor.GREEN, player.getStringUUID(), ChatColor.AQUA, ChatColor.WHITE, false, 0, ace);
Profile template = new Profile(player.getName().getString(), "Member", player.getDisplayName().getString(), ChatColor.GREEN, player.getStringUUID(), ChatColor.AQUA, ChatColor.WHITE, false, 0, ace, 0, player);
template.commit();
@ -129,6 +135,10 @@ public class Profile {
@Override
public void finalize()
{
if(MinecraftForge.EVENT_BUS.post(new ProfileUnloadingEvent(this, player)))
{
commit();
}
LibZontreck.LOGGER.info("Profile is unloaded for "+username);
MinecraftForge.EVENT_BUS.post(new ProfileUnloadedEvent(user_id));
}
@ -162,6 +172,7 @@ public class Profile {
serial.putString("chatc", chat_color);
serial.putBoolean("flying", flying);
serial.putInt("vaults", available_vaults);
serial.putInt("deaths", deaths);