1
0

use a better event system

This commit is contained in:
Lee
2024-04-01 12:34:28 +01:00
parent 7c5557abd2
commit ba8423aedd
12 changed files with 232 additions and 95 deletions

View File

@ -23,6 +23,11 @@ import java.util.UUID;
@Getter @Log4j2
public class Account {
/**
* Profile keys.
*/
private static final String playerColorProfileId = "playerColorProfile";
/**
* The UUID of the player.
*/
@ -78,26 +83,6 @@ public class Account {
this.lastLogin = System.currentTimeMillis();
this.save(false); // Save default values
log.info("Created new account for " + this.uuid);
Bukkit.broadcast(Style.getMiniMessage().deserialize(Lang.FIRST_JOIN_MESSAGE.getAsString()
.replace("%player%", player.getName())
));
Aetheria.EXECUTOR.execute(() -> {
// todo: re-code this it's so ugly
DiscordWebhook discordWebhook = new DiscordWebhook(Config.DISCORD_LOG_WEBHOOK.getAsString());
DiscordWebhook.EmbedObject embed = new DiscordWebhook.EmbedObject();
embed.setTitle("New Player Joined");
embed.addField("Name", player.getName(), true);
embed.addField("UUID", uuid.toString(), true);
discordWebhook.addEmbed(embed);
try {
discordWebhook.execute();
} catch (IOException e) {
throw new RuntimeException(e);
}
});
}
this.firstJoin = config.getLong("firstJoin");
@ -106,7 +91,7 @@ public class Account {
this.lastLogin = System.currentTimeMillis(); // Update last login
// Load profiles
this.playerColorProfile = new PlayerColor(this, this.getProfileSection("playerColor"));
this.playerColorProfile = new PlayerColor(this, this.getProfileSection(playerColorProfileId));
//log.info("Loaded account for " + this.uuid);
}
@ -163,16 +148,11 @@ public class Account {
* @param key the key to save the profile under
*/
private void saveProfile(Profile profile, String key) {
key = this.getProfileId(key); // append "Profile" to the key to signify it's a profile
profile.save(config.getConfigurationSection(key) == null ? config.createSection(key) : config.getConfigurationSection(key));
}
private ConfigurationSection getProfileSection(String key) {
return this.config.getConfigurationSection(this.getProfileId(key));
}
private String getProfileId(String key) {
return key + "Profile"; // append "Profile" to the key to signify it's a profile
return this.config.getConfigurationSection(key);
}
@SneakyThrows
@ -181,7 +161,7 @@ public class Account {
this.config.set("lastLogin", this.lastLogin);
if (saveProfiles) {
this.saveProfile(this.playerColorProfile, "playerColor");
this.saveProfile(this.playerColorProfile, playerColorProfileId);
}
this.config.save(this.file);