fix account saving?
This commit is contained in:
@ -50,9 +50,6 @@ public class Aetheria extends JavaPlugin {
|
||||
public void onEnable() {
|
||||
saveDefaultConfig();
|
||||
|
||||
Config.clear();
|
||||
Lang.clear();
|
||||
|
||||
new AccountManager();
|
||||
new EventManager();
|
||||
new CommandManager();
|
||||
|
@ -65,7 +65,7 @@ public class Account {
|
||||
* the account will not be saved this is to prevent unnecessary saving.
|
||||
*/
|
||||
@EqualsAndHashCode.Exclude
|
||||
private int lastHash;
|
||||
private int lastHash = -1;
|
||||
|
||||
/**
|
||||
* The first time the player joined the server.
|
||||
@ -113,8 +113,6 @@ public class Account {
|
||||
this.playerColorProfile = new PlayerColorProfile(this, this.getProfileSection(playerColorProfileId, false));
|
||||
this.voteProfile = new VoteProfile(this, this.getProfileSection(voteProfileId, false));
|
||||
|
||||
this.lastHash = this.hashCode();
|
||||
|
||||
//log.info("Loaded account for " + this.uuid);
|
||||
}
|
||||
|
||||
@ -237,6 +235,7 @@ public class Account {
|
||||
* @return true if the account was saved, false otherwise
|
||||
*/
|
||||
public boolean save() {
|
||||
long before = System.currentTimeMillis();
|
||||
if (this.lastHash == this.hashCode()) {
|
||||
return false; // No changes have been made
|
||||
}
|
||||
@ -255,6 +254,8 @@ public class Account {
|
||||
return false;
|
||||
}
|
||||
this.lastHash = this.hashCode(); // Update the last hash
|
||||
|
||||
log.info("Saved account for {}({}) in {}ms!", this.name, this.uuid, System.currentTimeMillis() - before);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -95,17 +95,12 @@ public class AccountManager extends Manager implements Listener {
|
||||
long before = System.currentTimeMillis(),
|
||||
saved = 0; // The amount of accounts that were saved
|
||||
log.info("Saving accounts...");
|
||||
List<Account> toRemove = new ArrayList<>();
|
||||
for (Account account : ACCOUNTS.values()) {
|
||||
boolean didSave = account.save(); // Save the account
|
||||
if (didSave) {
|
||||
saved++;
|
||||
}
|
||||
if (!account.isOnline()) {
|
||||
toRemove.add(account);
|
||||
}
|
||||
}
|
||||
toRemove.forEach(account -> ACCOUNTS.remove(account.getUuid())); // Unload offline accounts
|
||||
log.info("Saved {}/{} accounts. ({}ms)", saved, ACCOUNTS.size(), System.currentTimeMillis() - before);
|
||||
}
|
||||
|
||||
@ -181,6 +176,8 @@ public class AccountManager extends Manager implements Listener {
|
||||
.replace("%player%", event.getPlayer().getName())
|
||||
.replace("player-color", account.getPlayerColorProfile().getColor().toString())
|
||||
));
|
||||
account.save(); // Save the account
|
||||
ACCOUNTS.remove(account.getUuid());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -3,12 +3,10 @@ package cc.fascinated.vote;
|
||||
import cc.fascinated.account.Account;
|
||||
import cc.fascinated.bot.DiscordBot;
|
||||
import cc.fascinated.bot.DiscordChannel;
|
||||
import cc.fascinated.command.CommandManager;
|
||||
import cc.fascinated.config.Lang;
|
||||
import cc.fascinated.playercolor.PlayerColorProfile;
|
||||
import cc.fascinated.utils.Manager;
|
||||
import cc.fascinated.utils.MessageUtils;
|
||||
import cc.fascinated.vote.command.VoteStatsCommand;
|
||||
import com.vexsoftware.votifier.model.VotifierEvent;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
|
||||
@ -16,10 +14,6 @@ import java.awt.*;
|
||||
|
||||
public class VoteManager extends Manager {
|
||||
|
||||
public VoteManager() {
|
||||
CommandManager.registerCommand(new VoteStatsCommand());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onVote(Account account, VotifierEvent event) {
|
||||
VoteProfile voteProfile = account.getVoteProfile();
|
||||
|
@ -11,17 +11,14 @@ import org.bukkit.configuration.ConfigurationSection;
|
||||
public class VoteProfile extends Profile {
|
||||
|
||||
private int totalVotes;
|
||||
private int voteTokens;
|
||||
|
||||
public VoteProfile(Account account, ConfigurationSection section) {
|
||||
super(account, section);
|
||||
|
||||
if (section == null) {
|
||||
this.totalVotes = 0;
|
||||
this.voteTokens = 0;
|
||||
} else {
|
||||
this.totalVotes = section.getInt("totalVotes");
|
||||
this.voteTokens = section.getInt("voteTokens");
|
||||
}
|
||||
}
|
||||
|
||||
@ -33,12 +30,10 @@ public class VoteProfile extends Profile {
|
||||
*/
|
||||
public void addVote() {
|
||||
this.totalVotes++;
|
||||
this.voteTokens++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(ConfigurationSection section) {
|
||||
section.set("totalVotes", this.totalVotes);
|
||||
section.set("voteTokens", this.voteTokens);
|
||||
}
|
||||
}
|
||||
|
@ -1,22 +0,0 @@
|
||||
package cc.fascinated.vote.command;
|
||||
|
||||
import cc.fascinated.account.Account;
|
||||
import cc.fascinated.command.Command;
|
||||
import cc.fascinated.config.Lang;
|
||||
|
||||
public class VoteStatsCommand extends Command {
|
||||
|
||||
public VoteStatsCommand() {
|
||||
super("votestats");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Account account, String[] args) {
|
||||
for (String line : Lang.VOTE_STATS_COMMAND.getAsStringList()) {
|
||||
account.sendMessage(line
|
||||
.replace("%total-votes%", account.getVoteProfile().getTotalVotes() + "")
|
||||
.replace("%vote-tokens%", account.getVoteProfile().getVoteTokens() + "")
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user