#1404: Add PotionEffectTypeCategory to distinguish between beneficial and harmful effects

By: 2008Choco <hawkeboyz2@hotmail.com>
This commit is contained in:
CraftBukkit/Spigot 2024-05-29 06:50:08 +10:00
parent 402878b8cd
commit 3433d3f5b7
3 changed files with 39 additions and 0 deletions

View File

@ -10,6 +10,7 @@ import org.bukkit.craftbukkit.CraftRegistry;
import org.bukkit.craftbukkit.util.Handleable;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.potion.PotionEffectTypeCategory;
import org.jetbrains.annotations.NotNull;
public class CraftPotionEffectType extends PotionEffectType implements Handleable<MobEffectList> {
@ -112,6 +113,11 @@ public class CraftPotionEffectType extends PotionEffectType implements Handleabl
return handle.isInstantenous();
}
@Override
public PotionEffectTypeCategory getCategory() {
return CraftPotionEffectTypeCategory.minecraftToBukkit(handle.getCategory());
}
@Override
public Color getColor() {
return Color.fromRGB(handle.getColor());

View File

@ -0,0 +1,18 @@
package org.bukkit.craftbukkit.potion;
import com.google.common.base.Preconditions;
import net.minecraft.world.effect.MobEffectInfo;
import org.bukkit.potion.PotionEffectTypeCategory;
public final class CraftPotionEffectTypeCategory {
public static PotionEffectTypeCategory minecraftToBukkit(MobEffectInfo minecraft) {
Preconditions.checkArgument(minecraft != null);
return PotionEffectTypeCategory.valueOf(minecraft.name());
}
public static MobEffectInfo bukkitToMinecraft(PotionEffectTypeCategory bukkit) {
Preconditions.checkArgument(bukkit != null);
return MobEffectInfo.valueOf(bukkit.name());
}
}

View File

@ -8,8 +8,11 @@ import java.util.Collections;
import java.util.List;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.MinecraftKey;
import net.minecraft.world.effect.MobEffectInfo;
import org.bukkit.craftbukkit.potion.CraftPotionEffectTypeCategory;
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.potion.PotionEffectTypeCategory;
import org.bukkit.support.AbstractTestingBase;
import org.junit.jupiter.api.Test;
@ -31,4 +34,16 @@ public class PotionEffectTypeTest extends AbstractTestingBase {
assertThat(effects, is(Collections.EMPTY_LIST), "org.bukkit.PotionEffectType has too many effects");
}
@Test
public void verifyCategories() {
for (PotionEffectTypeCategory category : PotionEffectTypeCategory.values()) {
String categoryName = category.name();
assertDoesNotThrow(() -> CraftPotionEffectTypeCategory.bukkitToMinecraft(category), "PotionEffectTypeCategory." + categoryName + " exists but MobEffectInfo." + categoryName + " does not!");
}
for (MobEffectInfo info : MobEffectInfo.values()) {
assertDoesNotThrow(() -> CraftPotionEffectTypeCategory.minecraftToBukkit(info), "Missing PotionEffectTypeCategory for MobEffectInfo." + info.name());
}
}
}