Persist scores between server launches
This commit is contained in:
2
TODO.md
2
TODO.md
@@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
| ID | Status | Title |
|
| ID | Status | Title |
|
||||||
|:-----:|:--------:|:------|
|
|:-----:|:--------:|:------|
|
||||||
| SK-01 | Ready | Save scores between server launches. |
|
| SK-01 | Done | Save scores between server launches. |
|
||||||
| SK-02 | Ready | Allow tracking scores by bucket. An admin or other plugin should be able to create types of scores with named other than points. { id: "Bread", singular: "loaf", plural: "loaves", initialValue: 0 } Each player's score will be tracked in a bucket by id. Players may be all switched to a bucket or individually switched. |\
|
| SK-02 | Ready | Allow tracking scores by bucket. An admin or other plugin should be able to create types of scores with named other than points. { id: "Bread", singular: "loaf", plural: "loaves", initialValue: 0 } Each player's score will be tracked in a bucket by id. Players may be all switched to a bucket or individually switched. |\
|
||||||
| SK-03 | Ready | Add optional score reporting to buckets with these four values. { id: "Bread", singular: "loaf", plural: "loaves", initialValue: 0, reporting:"admin|global|player|none" } admin means ops/admin only, global means everyone on the server, player means only tell the player, and none means don't report changes.
|
| SK-03 | Ready | Add optional score reporting to buckets with these four values. { id: "Bread", singular: "loaf", plural: "loaves", initialValue: 0, reporting:"admin|global|player|none" } admin means ops/admin only, global means everyone on the server, player means only tell the player, and none means don't report changes.
|
||||||
| SK-04 | Ready | Tell a player when their bucket changes. Something like "You are now tracking ${id}. You have ${score} ${plural or singular depending in score}." |
|
| SK-04 | Ready | Tell a player when their bucket changes. Something like "You are now tracking ${id}. You have ${score} ${plural or singular depending in score}." |
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ along with ScoreKeeper. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
|
|||||||
|
|
||||||
package com.majinnaibu.minecraft.plugins.scorekeeper;
|
package com.majinnaibu.minecraft.plugins.scorekeeper;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
@@ -31,6 +33,7 @@ import net.kyori.adventure.text.Component;
|
|||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
@@ -44,8 +47,15 @@ public class ScoreKeeperPlugin extends JavaPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
// TODO: save score data to file
|
YamlConfiguration scores = new YamlConfiguration();
|
||||||
logWarning("Unable to save scores to file. This feature is not implemented yet.");
|
for (var entry : _playerScores.entrySet()) {
|
||||||
|
scores.set(entry.getKey().toString(), entry.getValue());
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
scores.save(new File(getDataFolder(), "scores.yml"));
|
||||||
|
} catch (IOException ex) {
|
||||||
|
logError(ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -56,8 +66,17 @@ public class ScoreKeeperPlugin extends JavaPlugin {
|
|||||||
getCommand("score-reset").setExecutor(new ScoreResetCommand(this));
|
getCommand("score-reset").setExecutor(new ScoreResetCommand(this));
|
||||||
getCommand("score-archive").setExecutor(new ScoreArchiveCommand(this));
|
getCommand("score-archive").setExecutor(new ScoreArchiveCommand(this));
|
||||||
|
|
||||||
// TODO: load score data from file
|
File scoreFile = new File(getDataFolder(), "scores.yml");
|
||||||
logWarning("Unable to load scores from file. This feature is not " + "implemented yet.");
|
if (scoreFile.isFile()) {
|
||||||
|
YamlConfiguration scores = YamlConfiguration.loadConfiguration(scoreFile);
|
||||||
|
for (String key : scores.getKeys(false)) {
|
||||||
|
try {
|
||||||
|
_playerScores.put(UUID.fromString(key), scores.getInt(key));
|
||||||
|
} catch (IllegalArgumentException ex) {
|
||||||
|
logWarning("Ignoring score with invalid player UUID: " + key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
logInfo(
|
logInfo(
|
||||||
getPluginMeta().getName() + " version " + getPluginMeta().getVersion() + " is enabled.");
|
getPluginMeta().getName() + " version " + getPluginMeta().getVersion() + " is enabled.");
|
||||||
|
|||||||
Reference in New Issue
Block a user