Paper/paper-server/src/test/java/org/bukkit/StatisticsAndAchievementsTest.java
CraftBukkit/Spigot 43702a9e10 Update to Minecraft 1.18-pre5
By: md_5 <git@md-5.net>
2021-11-22 09:00:00 +11:00

58 lines
2.6 KiB
Java

package org.bukkit;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import com.google.common.collect.HashMultiset;
import net.minecraft.core.IRegistry;
import net.minecraft.stats.StatisticWrapper;
import net.minecraft.world.entity.EntityTypes;
import org.bukkit.craftbukkit.CraftStatistic;
import org.bukkit.entity.EntityType;
import org.bukkit.support.AbstractTestingBase;
import org.junit.Test;
public class StatisticsAndAchievementsTest extends AbstractTestingBase {
@Test
@SuppressWarnings("unchecked")
public void verifyEntityMapping() throws Throwable {
for (Statistic statistic : Statistic.values()) {
if (statistic.getType() == Statistic.Type.ENTITY) {
for (EntityType entity : EntityType.values()) {
if (entity.getName() != null) {
assertNotNull(statistic + " missing for " + entity, CraftStatistic.getEntityStatistic(statistic, entity));
}
}
}
}
}
@Test
@SuppressWarnings("unchecked")
public void verifyStatisticMapping() throws Throwable {
HashMultiset<Statistic> statistics = HashMultiset.create();
for (StatisticWrapper wrapper : IRegistry.STAT_TYPE) {
for (Object child : wrapper.getRegistry()) {
net.minecraft.stats.Statistic<?> statistic = wrapper.get(child);
String message = String.format("org.bukkit.Statistic is missing: '%s'", statistic);
Statistic subject = CraftStatistic.getBukkitStatistic(statistic);
assertThat(message, subject, is(not(nullValue())));
if (wrapper.getRegistry() == IRegistry.BLOCK || wrapper.getRegistry() == IRegistry.ITEM) {
assertNotNull("Material type map missing for " + wrapper.getRegistry().getKey(child), CraftStatistic.getMaterialFromStatistic(statistic));
} else if (wrapper.getRegistry() == IRegistry.ENTITY_TYPE) {
assertNotNull("Entity type map missing for " + EntityTypes.getKey((EntityTypes<?>) child), CraftStatistic.getEntityTypeFromStatistic((net.minecraft.stats.Statistic<EntityTypes<?>>) statistic));
}
statistics.add(subject);
}
}
for (Statistic statistic : Statistic.values()) {
String message = String.format("org.bukkit.Statistic.%s does not have a corresponding minecraft statistic", statistic.name());
assertThat(message, statistics.remove(statistic, statistics.count(statistic)), is(greaterThan(0)));
}
}
}