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

This commit is contained in:
2008Choco 2024-05-29 06:50:08 +10:00 committed by md_5
parent 9608279815
commit 5d7d675b95
No known key found for this signature in database
GPG Key ID: E8E901AC7C617C11
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.craftbukkit.util.Handleable;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
import org.bukkit.potion.PotionEffectTypeCategory;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
public class CraftPotionEffectType extends PotionEffectType implements Handleable<MobEffectList> { public class CraftPotionEffectType extends PotionEffectType implements Handleable<MobEffectList> {
@ -112,6 +113,11 @@ public class CraftPotionEffectType extends PotionEffectType implements Handleabl
return handle.isInstantenous(); return handle.isInstantenous();
} }
@Override
public PotionEffectTypeCategory getCategory() {
return CraftPotionEffectTypeCategory.minecraftToBukkit(handle.getCategory());
}
@Override @Override
public Color getColor() { public Color getColor() {
return Color.fromRGB(handle.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 java.util.List;
import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.MinecraftKey; 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.craftbukkit.util.CraftNamespacedKey;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
import org.bukkit.potion.PotionEffectTypeCategory;
import org.bukkit.support.AbstractTestingBase; import org.bukkit.support.AbstractTestingBase;
import org.junit.jupiter.api.Test; 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"); 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());
}
}
} }