mirror of
https://github.com/WiIIiam278/HuskSync.git
synced 2025-12-19 14:59:21 +00:00
fix: item and block stats not syncing, close #362
This commit is contained in:
@@ -35,6 +35,7 @@ import org.bukkit.*;
|
|||||||
import org.bukkit.advancement.AdvancementProgress;
|
import org.bukkit.advancement.AdvancementProgress;
|
||||||
import org.bukkit.attribute.AttributeInstance;
|
import org.bukkit.attribute.AttributeInstance;
|
||||||
import org.bukkit.attribute.AttributeModifier;
|
import org.bukkit.attribute.AttributeModifier;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.inventory.InventoryType;
|
import org.bukkit.event.inventory.InventoryType;
|
||||||
import org.bukkit.inventory.EquipmentSlotGroup;
|
import org.bukkit.inventory.EquipmentSlotGroup;
|
||||||
@@ -452,9 +453,10 @@ public abstract class BukkitData implements Data {
|
|||||||
Registry.STATISTIC.forEach(id -> {
|
Registry.STATISTIC.forEach(id -> {
|
||||||
switch (id.getType()) {
|
switch (id.getType()) {
|
||||||
case UNTYPED -> addStatistic(player, id, generic);
|
case UNTYPED -> addStatistic(player, id, generic);
|
||||||
case BLOCK -> addMaterialStatistic(player, id, blocks, true);
|
// Todo - Future - Use BLOCK and ITEM registries when API stabilizes
|
||||||
case ITEM -> addMaterialStatistic(player, id, items, false);
|
case BLOCK -> addStatistic(player, id, Registry.MATERIAL, blocks);
|
||||||
case ENTITY -> addEntityStatistic(player, id, entities);
|
case ITEM -> addStatistic(player, id, Registry.MATERIAL, items);
|
||||||
|
case ENTITY -> addStatistic(player, id, Registry.ENTITY_TYPE, entities);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return new BukkitData.Statistics(generic, blocks, items, entities);
|
return new BukkitData.Statistics(generic, blocks, items, entities);
|
||||||
@@ -475,30 +477,19 @@ public abstract class BukkitData implements Data {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void addMaterialStatistic(@NotNull Player p, @NotNull Statistic id,
|
private static <R extends Keyed> void addStatistic(@NotNull Player p, @NotNull Statistic id,
|
||||||
@NotNull Map<String, Map<String, Integer>> map, boolean isBlock) {
|
@NotNull Registry<R> registry,
|
||||||
Registry.MATERIAL.forEach(material -> {
|
@NotNull Map<String, Map<String, Integer>> map) {
|
||||||
if ((material.isBlock() && !isBlock) || (material.isItem() && isBlock)) {
|
registry.forEach(i -> {
|
||||||
return;
|
try {
|
||||||
}
|
final int stat = i instanceof Material m ? p.getStatistic(id, m) :
|
||||||
final int stat = p.getStatistic(id, material);
|
(i instanceof EntityType e ? p.getStatistic(id, e) : -1);
|
||||||
if (stat != 0) {
|
if (stat != 0) {
|
||||||
map.compute(id.getKey().getKey(), (k, v) -> v == null ? Maps.newHashMap() : v)
|
map.compute(id.getKey().getKey(), (k, v) -> v == null ? Maps.newHashMap() : v)
|
||||||
.put(material.getKey().getKey(), stat);
|
.put(i.getKey().getKey(), stat);
|
||||||
}
|
System.out.println("Adding stat for " + id.getKey() + ", type: " + i.getKey());
|
||||||
});
|
}
|
||||||
}
|
} catch (IllegalStateException ignored) {
|
||||||
|
|
||||||
private static void addEntityStatistic(@NotNull Player p, @NotNull Statistic id,
|
|
||||||
@NotNull Map<String, Map<String, Integer>> map) {
|
|
||||||
Registry.ENTITY_TYPE.forEach(entity -> {
|
|
||||||
if (!entity.isAlive()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final int stat = p.getStatistic(id, entity);
|
|
||||||
if (stat != 0) {
|
|
||||||
map.compute(id.getKey().getKey(), (k, v) -> v == null ? Maps.newHashMap() : v)
|
|
||||||
.put(entity.getKey().getKey(), stat);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user