@@ -1,31 +0,0 @@
|
||||
package org.bukkit.craftbukkit.potion;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import org.bukkit.potion.PotionBrewer;
|
||||
import org.bukkit.potion.PotionData;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.potion.PotionType;
|
||||
|
||||
public class CraftPotionBrewer implements PotionBrewer {
|
||||
|
||||
@Override
|
||||
public Collection<PotionEffect> getEffects(PotionType type, boolean upgraded, boolean extended) {
|
||||
Preconditions.checkArgument(!type.getKey().getKey().startsWith("strong_"), "Strong potion type cannot be used directly, got %s", type.getKey());
|
||||
Preconditions.checkArgument(!type.getKey().getKey().startsWith("long_"), "Extended potion type cannot be used directly, got %s", type.getKey());
|
||||
|
||||
return CraftPotionUtil.fromBukkit(new PotionData(type, upgraded, extended)).getPotionEffects();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<PotionEffect> getEffectsFromDamage(int damage) {
|
||||
return new ArrayList<PotionEffect>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PotionEffect createEffect(PotionEffectType potion, int duration, int amplifier) {
|
||||
return new PotionEffect(potion, potion.isInstant() ? 1 : (int) (duration * potion.getDurationModifier()), amplifier);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.bukkit.craftbukkit.potion;
|
||||
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.world.effect.MobEffectList;
|
||||
import org.bukkit.Color;
|
||||
@@ -13,6 +14,10 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class CraftPotionEffectType extends PotionEffectType implements Handleable<MobEffectList> {
|
||||
|
||||
public static PotionEffectType minecraftHolderToBukkit(Holder<MobEffectList> minecraft) {
|
||||
return minecraftToBukkit(minecraft.value());
|
||||
}
|
||||
|
||||
public static PotionEffectType minecraftToBukkit(MobEffectList minecraft) {
|
||||
return CraftRegistry.minecraftToBukkit(minecraft, Registries.MOB_EFFECT, Registry.EFFECT);
|
||||
}
|
||||
@@ -21,6 +26,10 @@ public class CraftPotionEffectType extends PotionEffectType implements Handleabl
|
||||
return CraftRegistry.bukkitToMinecraft(bukkit);
|
||||
}
|
||||
|
||||
public static Holder<MobEffectList> bukkitToMinecraftHolder(PotionEffectType bukkit) {
|
||||
return CraftRegistry.bukkitToMinecraftHolder(bukkit, Registries.MOB_EFFECT);
|
||||
}
|
||||
|
||||
private final NamespacedKey key;
|
||||
private final MobEffectList handle;
|
||||
private final int id;
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.google.common.base.Preconditions;
|
||||
import com.google.common.base.Suppliers;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.IRegistry;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.world.item.alchemy.PotionRegistry;
|
||||
@@ -17,6 +18,10 @@ import org.bukkit.potion.PotionType;
|
||||
|
||||
public class CraftPotionType implements PotionType.InternalPotionData {
|
||||
|
||||
public static PotionType minecraftHolderToBukkit(Holder<PotionRegistry> minecraft) {
|
||||
return minecraftToBukkit(minecraft.value());
|
||||
}
|
||||
|
||||
public static PotionType minecraftToBukkit(PotionRegistry minecraft) {
|
||||
Preconditions.checkArgument(minecraft != null);
|
||||
|
||||
@@ -35,6 +40,19 @@ public class CraftPotionType implements PotionType.InternalPotionData {
|
||||
.getOptional(CraftNamespacedKey.toMinecraft(bukkit.getKey())).orElseThrow();
|
||||
}
|
||||
|
||||
public static Holder<PotionRegistry> bukkitToMinecraftHolder(PotionType bukkit) {
|
||||
Preconditions.checkArgument(bukkit != null);
|
||||
|
||||
IRegistry<PotionRegistry> registry = CraftRegistry.getMinecraftRegistry(Registries.POTION);
|
||||
|
||||
if (registry.wrapAsHolder(bukkitToMinecraft(bukkit)) instanceof Holder.c<PotionRegistry> holder) {
|
||||
return holder;
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException("No Reference holder found for " + bukkit
|
||||
+ ", this can happen if a plugin creates its own sound effect with out properly registering it.");
|
||||
}
|
||||
|
||||
public static String bukkitToString(PotionType potionType) {
|
||||
Preconditions.checkArgument(potionType != null);
|
||||
|
||||
|
||||
@@ -1,83 +1,20 @@
|
||||
package org.bukkit.craftbukkit.potion;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.ImmutableBiMap;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.world.effect.MobEffect;
|
||||
import net.minecraft.world.effect.MobEffectList;
|
||||
import org.bukkit.potion.PotionData;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.potion.PotionType;
|
||||
|
||||
public class CraftPotionUtil {
|
||||
|
||||
private static final BiMap<PotionType, PotionType> upgradeable = ImmutableBiMap.<PotionType, PotionType>builder()
|
||||
.put(PotionType.JUMP, PotionType.STRONG_LEAPING)
|
||||
.put(PotionType.SPEED, PotionType.STRONG_SWIFTNESS)
|
||||
.put(PotionType.INSTANT_HEAL, PotionType.STRONG_HEALING)
|
||||
.put(PotionType.INSTANT_DAMAGE, PotionType.STRONG_HARMING)
|
||||
.put(PotionType.POISON, PotionType.STRONG_POISON)
|
||||
.put(PotionType.REGEN, PotionType.STRONG_REGENERATION)
|
||||
.put(PotionType.STRENGTH, PotionType.STRONG_STRENGTH)
|
||||
.put(PotionType.SLOWNESS, PotionType.STRONG_SLOWNESS)
|
||||
.put(PotionType.TURTLE_MASTER, PotionType.STRONG_TURTLE_MASTER)
|
||||
.build();
|
||||
private static final BiMap<PotionType, PotionType> extendable = ImmutableBiMap.<PotionType, PotionType>builder()
|
||||
.put(PotionType.NIGHT_VISION, PotionType.LONG_NIGHT_VISION)
|
||||
.put(PotionType.INVISIBILITY, PotionType.LONG_INVISIBILITY)
|
||||
.put(PotionType.JUMP, PotionType.LONG_LEAPING)
|
||||
.put(PotionType.FIRE_RESISTANCE, PotionType.LONG_FIRE_RESISTANCE)
|
||||
.put(PotionType.SPEED, PotionType.LONG_SWIFTNESS)
|
||||
.put(PotionType.SLOWNESS, PotionType.LONG_SLOWNESS)
|
||||
.put(PotionType.WATER_BREATHING, PotionType.LONG_WATER_BREATHING)
|
||||
.put(PotionType.POISON, PotionType.LONG_POISON)
|
||||
.put(PotionType.REGEN, PotionType.LONG_REGENERATION)
|
||||
.put(PotionType.STRENGTH, PotionType.LONG_STRENGTH)
|
||||
.put(PotionType.WEAKNESS, PotionType.LONG_WEAKNESS)
|
||||
.put(PotionType.TURTLE_MASTER, PotionType.LONG_TURTLE_MASTER)
|
||||
.put(PotionType.SLOW_FALLING, PotionType.LONG_SLOW_FALLING)
|
||||
.build();
|
||||
|
||||
public static PotionType fromBukkit(PotionData data) {
|
||||
PotionType type;
|
||||
if (data.isUpgraded()) {
|
||||
type = upgradeable.get(data.getType());
|
||||
} else if (data.isExtended()) {
|
||||
type = extendable.get(data.getType());
|
||||
} else {
|
||||
type = data.getType();
|
||||
}
|
||||
Preconditions.checkNotNull(type, "Unknown potion type from data " + data);
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
public static PotionData toBukkit(PotionType type) {
|
||||
if (type == null) {
|
||||
return new PotionData(PotionType.UNCRAFTABLE, false, false);
|
||||
}
|
||||
|
||||
PotionType potionType;
|
||||
potionType = extendable.inverse().get(type);
|
||||
if (potionType != null) {
|
||||
return new PotionData(potionType, true, false);
|
||||
}
|
||||
potionType = upgradeable.inverse().get(type);
|
||||
if (potionType != null) {
|
||||
return new PotionData(potionType, false, true);
|
||||
}
|
||||
|
||||
return new PotionData(type, false, false);
|
||||
}
|
||||
|
||||
public static MobEffect fromBukkit(PotionEffect effect) {
|
||||
MobEffectList type = CraftPotionEffectType.bukkitToMinecraft(effect.getType());
|
||||
Holder<MobEffectList> type = CraftPotionEffectType.bukkitToMinecraftHolder(effect.getType());
|
||||
return new MobEffect(type, effect.getDuration(), effect.getAmplifier(), effect.isAmbient(), effect.hasParticles());
|
||||
}
|
||||
|
||||
public static PotionEffect toBukkit(MobEffect effect) {
|
||||
PotionEffectType type = CraftPotionEffectType.minecraftToBukkit(effect.getEffect());
|
||||
PotionEffectType type = CraftPotionEffectType.minecraftHolderToBukkit(effect.getEffect());
|
||||
int amp = effect.getAmplifier();
|
||||
int duration = effect.getDuration();
|
||||
boolean ambient = effect.isAmbient();
|
||||
@@ -85,8 +22,8 @@ public class CraftPotionUtil {
|
||||
return new PotionEffect(type, duration, amp, ambient, particles);
|
||||
}
|
||||
|
||||
public static boolean equals(MobEffectList mobEffect, PotionEffectType type) {
|
||||
PotionEffectType typeV = CraftPotionEffectType.minecraftToBukkit(mobEffect);
|
||||
public static boolean equals(Holder<MobEffectList> mobEffect, PotionEffectType type) {
|
||||
PotionEffectType typeV = CraftPotionEffectType.minecraftHolderToBukkit(mobEffect);
|
||||
return typeV.equals(type);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user