use of com.gmail.stefvanschiedev.buildinggame.utils.Achievement in project buildinggame by stefvanschie.
the class StatManager method registerStat.
/**
* Registers the stat with the given player, type and value unless the config has the given stat type disabled
*
* @param player the player who obtained the statistic
* @param type the type of statistic
* @param value the value of the statistic
* @since 2.2.0
*/
@Contract("_, null, _ -> fail")
public synchronized void registerStat(OfflinePlayer player, @NotNull StatType type, int value) {
YamlConfiguration config = SettingsManager.getInstance().getConfig();
if (!type.isEnabled(config)) {
return;
}
Stat oldStat = getStat(player, type);
if (oldStat != null)
stats.get(type).remove(oldStat);
if (!stats.containsKey(type))
stats.put(type, Collections.synchronizedList(new ArrayList<>()));
List<Stat> statsByType = stats.get(type);
int size = statsByType.size();
int index = 0;
for (; index <= size; index++) {
if (index == size)
break;
if (statsByType.get(index).getValue() < value)
break;
}
Stat newStat = new Stat(player, value);
statsByType.add(index, newStat);
TopStatHologram.update(type);
if (player.isOnline()) {
Achievement.getAchievements(type).stream().filter(achievement -> !achievement.checkConditions(type, oldStat) && achievement.checkConditions(type, newStat)).forEach(achievement -> achievement.grant(player.getPlayer()));
}
}
Aggregations