SPIGOT-8034: Validate API-set statistic types are correct

This commit is contained in:
md_5 2025-04-13 10:05:35 +10:00
parent a6012a1e0d
commit f6c49052a8
No known key found for this signature in database
GPG Key ID: E8E901AC7C617C11

View File

@ -146,10 +146,19 @@ public enum CraftStatistic {
}
public static net.minecraft.stats.Statistic getMaterialStatistic(org.bukkit.Statistic stat, Material material) {
try {
Type type = stat.getType();
switch (type) {
case BLOCK:
Preconditions.checkArgument(material.isBlock(), "statistic type is BLOCK but got non-block Material, %s", material);
if (stat == Statistic.MINE_BLOCK) {
return StatisticList.BLOCK_MINED.get(CraftBlockType.bukkitToMinecraft(material));
}
break;
case ITEM:
Preconditions.checkArgument(material.isItem(), "statistic type is ITEM but got non-item Material, %s", material);
if (stat == Statistic.CRAFT_ITEM) {
return StatisticList.ITEM_CRAFTED.get(CraftItemType.bukkitToMinecraft(material));
}
@ -165,10 +174,12 @@ public enum CraftStatistic {
if (stat == Statistic.DROP) {
return StatisticList.ITEM_DROPPED.get(CraftItemType.bukkitToMinecraft(material));
}
} catch (ArrayIndexOutOfBoundsException e) {
return null;
break;
default:
throw new IllegalArgumentException("statistic type must be either BLOCK or ITEM, given " + type);
}
return null;
throw new IllegalArgumentException("Unknwon material statistic " + stat);
}
public static net.minecraft.stats.Statistic getEntityStatistic(org.bukkit.Statistic stat, EntityType entity) {