Skip to content

Commit

Permalink
go back to snapshot, updated takenaka, added #getStatistic method to API
Browse files Browse the repository at this point in the history
  • Loading branch information
Misat11 committed Oct 16, 2023
1 parent 714e6c9 commit 33b8883
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,13 @@
import java.util.UUID;

public interface PlayerStatisticsManager {

PlayerStatistic getStatistic(UUID uuid);

List<LeaderboardEntry> getLeaderboard(int count);

/**
* @see #getStatistic(UUID)
*/
PlayerStatistic loadStatistic(UUID uuid);
}
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
plugins {
id 'org.screamingsandals.plugin-builder' version '1.0.84' apply false
id 'me.kcra.takenaka.accessor' version '1.0.0' apply false
id 'me.kcra.takenaka.accessor' version '1.0.4-SNAPSHOT' apply false
id 'com.github.gmazzo.buildconfig' version '3.0.0' apply false
}

allprojects {
group = 'org.screamingsandals.bedwars'
version = '0.2.30'
version = '0.2.31-SNAPSHOT'
}

if (version.toString().endsWith('-SNAPSHOT')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,19 @@ public PlayerStatistic getStatistic(OfflinePlayer player) {
return null;
}

if (!this.playerStatistic.containsKey(player.getUniqueId())) {
return this.loadStatistic(player.getUniqueId());
return getStatistic(player.getUniqueId());
}

public PlayerStatistic getStatistic(UUID uuid) {
if (uuid == null) {
return null;
}

if (!this.playerStatistic.containsKey(uuid)) {
return this.loadStatistic(uuid);
}

return this.playerStatistic.get(player.getUniqueId());
return this.playerStatistic.get(uuid);
}

public void initialize() {
Expand Down Expand Up @@ -191,6 +199,13 @@ private PlayerStatistic loadYamlStatistic(UUID uuid) {
return playerStatistic;
}

if (!this.fileDatabase.isConfigurationSection("data." + uuid.toString())) {
Main.getInstance().getLogger().warning("Statistics of player with UUID " + uuid + " are not properly saved and the plugin cannot load them!");
PlayerStatistic playerStatistic = new PlayerStatistic(uuid);
this.playerStatistic.put(uuid, playerStatistic);
return playerStatistic;
}

HashMap<String, Object> deserialize = new HashMap<>();
deserialize.putAll(this.fileDatabase.getConfigurationSection("data." + uuid.toString()).getValues(false));
PlayerStatistic playerStatistic = new PlayerStatistic(deserialize);
Expand Down

0 comments on commit 33b8883

Please sign in to comment.