Skip to content

Commit

Permalink
Merge pull request #31 from BentoBoxWorld/develop
Browse files Browse the repository at this point in the history
Version 1.14.0
  • Loading branch information
tastybento authored Sep 2, 2024
2 parents 78c3223 + 29be67f commit 0a5ae2b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 34 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
<!-- Do not change unless you want different name for local builds. -->
<build.number>-LOCAL</build.number>
<!-- This allows to change between versions. -->
<build.version>1.13.0</build.version>
<build.version>1.14.0</build.version>
<!-- Sonar Cloud -->
<sonar.projectKey>BentoBoxWorld_addon-invSwitcher</sonar.projectKey>
<sonar.organization>bentobox-world</sonar.organization>
Expand Down
74 changes: 41 additions & 33 deletions src/main/java/com/wasteofplastic/invswitcher/Store.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;

import org.bukkit.Bukkit;
Expand All @@ -56,6 +57,7 @@
*
*/
public class Store {
private static final Material[] MAT = Material.values();
private static final CharSequence THE_END = "_the_end";
private static final CharSequence NETHER = "_nether";
private final Database<InventoryStorage> database;
Expand Down Expand Up @@ -247,50 +249,56 @@ public void storeAndSave(Player player, World world) {
store.setEnderChest(overworldName, contents);
}
if (addon.getSettings().isStatistics()) {
saveStats(store, player, overworldName);
saveStats(store, player, overworldName).thenAccept(database::saveObjectAsync);
return;
}
database.saveObjectAsync(store);
}

private void saveStats(InventoryStorage store, Player player, String worldName) {
private CompletableFuture<InventoryStorage> saveStats(InventoryStorage store, Player player, String worldName) {
CompletableFuture<InventoryStorage> result = new CompletableFuture<>();
store.clearStats(worldName);
// Statistics
Arrays.stream(Statistic.values()).forEach(s -> {
Map<Material, Integer> map;
Map<EntityType, Integer> entMap;
switch (s.getType()) {
case BLOCK -> {
map = Arrays.stream(Material.values()).filter(Material::isBlock).filter(m -> !m.isLegacy())
.filter(m -> player.getStatistic(s, m) > 0)
.collect(Collectors.toMap(k -> k, v -> player.getStatistic(s, v)));
if (!map.isEmpty()) {
store.getBlockStats(worldName).put(s, map);
Bukkit.getScheduler().runTaskAsynchronously(addon.getPlugin(), () -> {
Arrays.stream(Statistic.values()).forEach(s -> {
Map<Material, Integer> map;
Map<EntityType, Integer> entMap;
switch (s.getType()) {
case BLOCK -> {
map = Arrays.stream(MAT).filter(Material::isBlock).filter(m -> !m.isLegacy())
.filter(m -> player.getStatistic(s, m) > 0)
.collect(Collectors.toMap(k -> k, v -> player.getStatistic(s, v)));
if (!map.isEmpty()) {
store.getBlockStats(worldName).put(s, map);
}
}
}
case ITEM -> {
map = Arrays.stream(Material.values()).filter(Material::isItem).filter(m -> !m.isLegacy())
.filter(m -> player.getStatistic(s, m) > 0)
.collect(Collectors.toMap(k -> k, v -> player.getStatistic(s, v)));
if (!map.isEmpty()) {
store.getItemStats(worldName).put(s, map);
case ITEM -> {
map = Arrays.stream(MAT).filter(Material::isItem).filter(m -> !m.isLegacy())
.filter(m -> player.getStatistic(s, m) > 0)
.collect(Collectors.toMap(k -> k, v -> player.getStatistic(s, v)));
if (!map.isEmpty()) {
store.getItemStats(worldName).put(s, map);
}
}
}
case ENTITY -> {
entMap = Arrays.stream(EntityType.values()).filter(EntityType::isAlive)
.filter(m -> player.getStatistic(s, m) > 0)
.collect(Collectors.toMap(k -> k, v -> player.getStatistic(s, v)));
if (!entMap.isEmpty()) {
store.getEntityStats(worldName).put(s, entMap);
case ENTITY -> {
entMap = Arrays.stream(EntityType.values()).filter(EntityType::isAlive)
.filter(m -> player.getStatistic(s, m) > 0)
.collect(Collectors.toMap(k -> k, v -> player.getStatistic(s, v)));
if (!entMap.isEmpty()) {
store.getEntityStats(worldName).put(s, entMap);
}
}
}
case UNTYPED -> {
int sc = player.getStatistic(s);
if (sc > 0) {
store.getUntypedStats(worldName).put(s, sc);
case UNTYPED -> {
int sc = player.getStatistic(s);
if (sc > 0) {
store.getUntypedStats(worldName).put(s, sc);
}
}
}
}
}
});
result.complete(store);
});
return result;

}

Expand Down

0 comments on commit 0a5ae2b

Please sign in to comment.