#962: Make PotionEffectType implement Keyed

This commit is contained in:
coll1234567 2021-11-28 11:49:42 +11:00 committed by md_5
parent 806bb02c17
commit af8a8b708c
No known key found for this signature in database
GPG Key ID: E8E901AC7C617C11
2 changed files with 34 additions and 1 deletions

View File

@ -8,7 +8,7 @@ public class CraftPotionEffectType extends PotionEffectType {
private final MobEffectList handle; private final MobEffectList handle;
public CraftPotionEffectType(MobEffectList handle) { public CraftPotionEffectType(MobEffectList handle) {
super(MobEffectList.getId(handle)); super(MobEffectList.getId(handle), org.bukkit.craftbukkit.util.CraftNamespacedKey.fromMinecraft(net.minecraft.core.IRegistry.MOB_EFFECT.getKey(handle)));
this.handle = handle; this.handle = handle;
} }

View File

@ -0,0 +1,33 @@
package org.bukkit;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import com.google.common.collect.Lists;
import java.util.Collections;
import java.util.List;
import net.minecraft.core.IRegistry;
import net.minecraft.resources.MinecraftKey;
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.support.AbstractTestingBase;
import org.junit.Test;
public class PotionEffectTypeTest extends AbstractTestingBase {
@Test
public void verifyMapping() {
List<PotionEffectType> effects = Lists.newArrayList(PotionEffectType.values());
for (MinecraftKey key : IRegistry.MOB_EFFECT.keySet()) {
String name = key.getPath();
PotionEffectType effect = PotionEffectType.getByKey(CraftNamespacedKey.fromMinecraft(key));
String message = String.format("org.bukkit.PotionEffectType is missing '%s'", name);
assertNotNull(message, effect);
effects.remove(effect);
}
assertThat("org.bukkit.PotionEffectType has too many effects", effects, is(Collections.EMPTY_LIST));
}
}