SPIGOT-8034: Validate API-set statistic types are correct
This commit is contained in:
parent
a6012a1e0d
commit
f6c49052a8
@ -146,10 +146,19 @@ public enum CraftStatistic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static net.minecraft.stats.Statistic getMaterialStatistic(org.bukkit.Statistic stat, Material material) {
|
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) {
|
if (stat == Statistic.MINE_BLOCK) {
|
||||||
return StatisticList.BLOCK_MINED.get(CraftBlockType.bukkitToMinecraft(material));
|
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) {
|
if (stat == Statistic.CRAFT_ITEM) {
|
||||||
return StatisticList.ITEM_CRAFTED.get(CraftItemType.bukkitToMinecraft(material));
|
return StatisticList.ITEM_CRAFTED.get(CraftItemType.bukkitToMinecraft(material));
|
||||||
}
|
}
|
||||||
@ -165,10 +174,12 @@ public enum CraftStatistic {
|
|||||||
if (stat == Statistic.DROP) {
|
if (stat == Statistic.DROP) {
|
||||||
return StatisticList.ITEM_DROPPED.get(CraftItemType.bukkitToMinecraft(material));
|
return StatisticList.ITEM_DROPPED.get(CraftItemType.bukkitToMinecraft(material));
|
||||||
}
|
}
|
||||||
} catch (ArrayIndexOutOfBoundsException e) {
|
break;
|
||||||
return null;
|
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) {
|
public static net.minecraft.stats.Statistic getEntityStatistic(org.bukkit.Statistic stat, EntityType entity) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user