Delete src/main/java/de/lasertag/player/PlayerDataManager.java via Git Manager GUI
This commit is contained in:
@@ -1,73 +0,0 @@
|
||||
package de.lasertag.player;
|
||||
|
||||
import de.lasertag.LasertagPlugin;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
public class PlayerDataManager {
|
||||
|
||||
private final LasertagPlugin plugin;
|
||||
private final Map<UUID, PlayerStats> map = new HashMap<>();
|
||||
private File file;
|
||||
private FileConfiguration cfg;
|
||||
|
||||
public PlayerDataManager(LasertagPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
load();
|
||||
}
|
||||
|
||||
public PlayerStats getStats(UUID uuid) {
|
||||
return map.computeIfAbsent(uuid, PlayerStats::new);
|
||||
}
|
||||
|
||||
public List<PlayerStats> getTopByScore(int limit) {
|
||||
List<PlayerStats> list = new ArrayList<>(map.values());
|
||||
list.sort((a, b) -> Integer.compare(b.getTotalScore(), a.getTotalScore()));
|
||||
return list.subList(0, Math.min(limit, list.size()));
|
||||
}
|
||||
|
||||
private void load() {
|
||||
file = new File(plugin.getDataFolder(), "stats.yml");
|
||||
if (!file.exists()) {
|
||||
try { plugin.getDataFolder().mkdirs(); file.createNewFile(); }
|
||||
catch (IOException ex) { ex.printStackTrace(); return; }
|
||||
}
|
||||
cfg = YamlConfiguration.loadConfiguration(file);
|
||||
ConfigurationSection root = cfg.getConfigurationSection("players");
|
||||
if (root == null) return;
|
||||
for (String key : root.getKeys(false)) {
|
||||
UUID uuid = UUID.fromString(key);
|
||||
PlayerStats s = new PlayerStats(uuid);
|
||||
String p = "players." + key + ".";
|
||||
s.setName(cfg.getString(p + "name", "Unknown"));
|
||||
s.addKills(cfg.getInt(p + "kills"));
|
||||
s.addDeaths(cfg.getInt(p + "deaths"));
|
||||
s.addScore(cfg.getInt(p + "score"));
|
||||
s.addGames(cfg.getInt(p + "games"));
|
||||
s.setBestStreak(cfg.getInt(p + "best-streak"));
|
||||
s.addBaseAttacks(cfg.getInt(p + "base-attacks"));
|
||||
map.put(uuid, s);
|
||||
}
|
||||
}
|
||||
|
||||
public void saveAll() {
|
||||
cfg.set("players", null);
|
||||
for (Map.Entry<UUID, PlayerStats> e : map.entrySet()) {
|
||||
PlayerStats s = e.getValue();
|
||||
String p = "players." + e.getKey() + ".";
|
||||
cfg.set(p + "name", s.getName());
|
||||
cfg.set(p + "kills", s.getTotalKills());
|
||||
cfg.set(p + "deaths", s.getTotalDeaths());
|
||||
cfg.set(p + "score", s.getTotalScore());
|
||||
cfg.set(p + "games", s.getGamesPlayed());
|
||||
cfg.set(p + "best-streak", s.getBestStreak());
|
||||
cfg.set(p + "base-attacks",s.getTotalBaseAttacks());
|
||||
}
|
||||
try { cfg.save(file); } catch (IOException ex) { ex.printStackTrace(); }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user