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