Skip to content

Commit

Permalink
Move stats saving reset to async
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Aug 21, 2024
1 parent e9be529 commit 72a1703
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
*/
public class AdvancementListener implements Listener {

private static final Material[] MATS = Material.values();

private final Boxed addon;
private final Advancement netherAdvancement;
private final Advancement netherFortressAdvancement;
Expand Down Expand Up @@ -327,7 +329,8 @@ private void grantAdv(User user, List<String> list) {

private void clearAdv(User user) {
// Clear Statistics
Arrays.stream(Statistic.values()).forEach(s -> resetStats(user, s));
Bukkit.getScheduler().runTaskAsynchronously(addon.getPlugin(),
() -> Arrays.stream(Statistic.values()).forEach(s -> resetStats(user, s)));
// Clear advancements
Iterator<Advancement> it = Bukkit.advancementIterator();
while (it.hasNext()) {
Expand All @@ -340,8 +343,9 @@ private void clearAdv(User user) {

private void resetStats(User user, Statistic s) {
switch(s.getType()) {
case BLOCK -> Arrays.stream(Material.values()).filter(Material::isBlock).forEach(m -> user.getPlayer().setStatistic(s, m, 0));
case ITEM -> Arrays.stream(Material.values()).filter(Material::isItem).forEach(m -> user.getPlayer().setStatistic(s, m, 0));
case BLOCK ->
Arrays.stream(MATS).filter(Material::isBlock).forEach(m -> user.getPlayer().setStatistic(s, m, 0));
case ITEM -> Arrays.stream(MATS).filter(Material::isItem).forEach(m -> user.getPlayer().setStatistic(s, m, 0));
case ENTITY -> Arrays.stream(EntityType.values()).filter(EntityType::isAlive).forEach(m -> user.getPlayer().setStatistic(s, m, 0));
case UNTYPED -> user.getPlayer().setStatistic(s, 0);
}
Expand Down

0 comments on commit 72a1703

Please sign in to comment.