Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
weblate committed Nov 20, 2023
2 parents d03bd09 + 7314ccf commit 1f47d86
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 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 @@ -324,6 +324,10 @@ public void run() {
if (Main.getConfigurator().config.getBoolean("tab.enable") && Main.getConfigurator().config.getBoolean("tab.hide-foreign-players")) {
Bukkit.getOnlinePlayers().stream().filter(Main::isPlayerInGame).forEach(p -> Main.getPlayerGameProfile(p).hidePlayer(player));
}

if (Main.isPlayerStatisticsEnabled()) {
Main.getPlayerStatisticsManager().loadStatistic(event.getPlayer().getUniqueId());
}
}

@SuppressWarnings("unchecked")
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;
}

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

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 All @@ -200,7 +215,7 @@ private PlayerStatistic loadYamlStatistic(UUID uuid) {
playerStatistic.setName(player.getName());
}
this.playerStatistic.put(uuid, playerStatistic);
allScores.put(uuid, new AbstractMap.SimpleEntry<>(playerStatistic.getName(), playerStatistic.getScore()));
updateScore(playerStatistic);
return playerStatistic;
}

Expand Down

0 comments on commit 1f47d86

Please sign in to comment.