Resets statistics as well as advancements.

https://github.com/BentoBoxWorld/Boxed/issues/8
Some advancements can be triggered by statistics so those need to be
reset as well.
This commit is contained in:
tastybento 2021-03-13 18:16:02 -08:00
parent 9354382f76
commit 4cc5068bb8
2 changed files with 52 additions and 2 deletions

View File

@ -36,6 +36,11 @@ public class Boxed extends GameModeAddon {
.type(Type.PROTECTION)
.defaultRank(RanksManager.OWNER_RANK)
.build();
public static final Flag ALLOW_MOVE_BOX = new Flag.Builder("ALLOW_MOVE_BOX", Material.COMPOSTER)
.mode(Mode.BASIC)
.type(Type.WORLD_SETTING)
.defaultSetting(true)
.build();
private static final String NETHER = "_nether";
private static final String THE_END = "_the_end";
@ -108,10 +113,16 @@ public class Boxed extends GameModeAddon {
advManager = new AdvancementsManager(this);
// Get delete chunk generator
delChunks = new DeleteGen(this);
// Make flag only applicable to this game mode
// Make flags only applicable to this game mode
MOVE_BOX.setGameModes(Collections.singleton(this));
ALLOW_MOVE_BOX.setGameModes(Collections.singleton(this));
// Register protection flag with BentoBox
getPlugin().getFlagsManager().registerFlag(this, MOVE_BOX);
getPlugin().getFlagsManager().registerFlag(this, ALLOW_MOVE_BOX);
if (ALLOW_MOVE_BOX.isSetForWorld(getOverWorld())) {
getPlugin().getFlagsManager().registerFlag(this, MOVE_BOX);
} else {
getPlugin().getFlagsManager().unregister(MOVE_BOX);
}
}

View File

@ -1,5 +1,6 @@
package world.bentobox.boxed.listeners;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Spliterator;
@ -7,10 +8,13 @@ import java.util.Spliterators;
import java.util.stream.StreamSupport;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.Sound;
import org.bukkit.Statistic;
import org.bukkit.advancement.Advancement;
import org.bukkit.advancement.AdvancementProgress;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -195,7 +199,41 @@ public class AdvancementListener implements Listener {
}
@SuppressWarnings("deprecation")
private void clearAdv(User user) {
// Clear stats
// Statistics
Arrays.stream(Statistic.values()).forEach(s -> {
switch(s.getType()) {
case BLOCK:
for (Material m: Material.values()) {
if (m.isBlock() && !m.isLegacy()) {
user.getPlayer().setStatistic(s, m, 0);
}
}
case ITEM:
for (Material m: Material.values()) {
if (m.isItem() && !m.isLegacy()) {
user.getPlayer().setStatistic(s, m, 0);
}
}
break;
case ENTITY:
for (EntityType en: EntityType.values()) {
if (en.isAlive()) {
user.getPlayer().setStatistic(s, en, 0);
}
}
break;
case UNTYPED:
user.getPlayer().setStatistic(s, 0);
break;
default:
break;
}
});
// Clear advancements
Iterator<Advancement> it = Bukkit.advancementIterator();
while (it.hasNext()) {
@ -203,6 +241,7 @@ public class AdvancementListener implements Listener {
AdvancementProgress p = user.getPlayer().getAdvancementProgress(a);
p.getAwardedCriteria().forEach(p::revokeCriteria);
}
}
/**