Skip to content

Commit

Permalink
Use Registry instead of Enums
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Nov 25, 2024
1 parent 736114b commit 2bc3b2c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
6 changes: 0 additions & 6 deletions src/main/java/com/wasteofplastic/invswitcher/InvSwitcher.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package com.wasteofplastic.invswitcher;


import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.World;

import com.wasteofplastic.invswitcher.listeners.PlayerListener;
Expand All @@ -26,9 +23,6 @@
*/
public class InvSwitcher extends Addon {

protected static final List<Material> MAT = Arrays.stream(Material.values())
.filter(m -> !m.name().startsWith("LEGACY")).toList();

private Store store;

private Settings settings;
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/com/wasteofplastic/invswitcher/Store.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.Registry;
import org.bukkit.Statistic;
import org.bukkit.World;
import org.bukkit.advancement.Advancement;
Expand Down Expand Up @@ -275,26 +276,26 @@ private CompletableFuture<InventoryStorage> saveStats(InventoryStorage store, Pl

private void saveStatistics(CompletableFuture<InventoryStorage> result, InventoryStorage store, Player player,
String worldName) {
Arrays.stream(Statistic.values()).forEach(s -> {
Registry.STATISTIC.forEach(s -> {
Map<Material, Integer> map;
Map<EntityType, Integer> entMap;
switch (s.getType()) {
case BLOCK -> {
map = InvSwitcher.MAT.stream().filter(Material::isBlock).filter(m -> player.getStatistic(s, m) > 0)
map = Registry.MATERIAL.stream().filter(Material::isBlock).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 = InvSwitcher.MAT.stream().filter(Material::isItem).filter(m -> player.getStatistic(s, m) > 0)
map = Registry.MATERIAL.stream().filter(Material::isItem).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)
entMap = Registry.ENTITY_TYPE.stream().filter(EntityType::isAlive)
.filter(m -> player.getStatistic(s, m) > 0)
.collect(Collectors.toMap(k -> k, v -> player.getStatistic(s, v)));
if (!entMap.isEmpty()) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/addon.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: InvSwitcher
main: com.wasteofplastic.invswitcher.InvSwitcher
version: ${version}${build.number}
api-version: 2.7.1
api-version: 3.0.0

authors: tastybento

Expand Down

0 comments on commit 2bc3b2c

Please sign in to comment.