Skip to content

Commit

Permalink
Resets statistics as well as advancements.
Browse files Browse the repository at this point in the history
#8
Some advancements can be triggered by statistics so those need to be
reset as well.
  • Loading branch information
tastybento committed Mar 14, 2021
1 parent 9354382 commit 4cc5068
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/main/java/world/bentobox/boxed/Boxed.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -108,10 +113,16 @@ public void onEnable(){
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);
}

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package world.bentobox.boxed.listeners;

import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Spliterator;
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;
Expand Down Expand Up @@ -195,14 +199,49 @@ private void grantAdv(User user, List<String> list) {

}

@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()) {
Advancement a = it.next();
AdvancementProgress p = user.getPlayer().getAdvancementProgress(a);
p.getAwardedCriteria().forEach(p::revokeCriteria);
}

}

/**
Expand Down

0 comments on commit 4cc5068

Please sign in to comment.