Suspicious Effect Entry API
Exposes a new suspicious effect entry type that properly represents storable effects in the context of suspicious effects as they only define the potion effect type and duration. This differentiates them from the existing PotionEffect API found in bukkit and hence clarifies that storable values in the parts of the API in which it replaces PotionEffect. Co-authored-by: Yannick Lamprecht <yannicklamprecht@live.de>
This commit is contained in:
@@ -37,16 +37,24 @@ public class CraftMushroomCow extends CraftCow implements MushroomCow, io.paperm
|
||||
@Override
|
||||
public boolean addEffectToNextStew(PotionEffect potionEffect, boolean overwrite) {
|
||||
Preconditions.checkArgument(potionEffect != null, "PotionEffect cannot be null");
|
||||
MobEffectInstance minecraftPotionEffect = CraftPotionUtil.fromBukkit(potionEffect);
|
||||
if (!overwrite && this.hasEffectForNextStew(potionEffect.getType())) {
|
||||
// Paper start - add overloads to use suspicious effect entry to mushroom cow and suspicious stew meta
|
||||
return this.addEffectToNextStew(io.papermc.paper.potion.SuspiciousEffectEntry.create(potionEffect.getType(), potionEffect.getDuration()), overwrite);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addEffectToNextStew(io.papermc.paper.potion.SuspiciousEffectEntry suspiciousEffectEntry, boolean overwrite) {
|
||||
Preconditions.checkArgument(suspiciousEffectEntry != null, "SuspiciousEffectEntry cannot be null");
|
||||
Holder<MobEffect> minecraftPotionEffect = CraftPotionEffectType.bukkitToMinecraftHolder(suspiciousEffectEntry.effect());
|
||||
// Paper end - add overloads to use suspicious effect entry to mushroom cow and suspicious stew meta
|
||||
if (!overwrite && this.hasEffectForNextStew(suspiciousEffectEntry.effect())) {
|
||||
return false;
|
||||
}
|
||||
SuspiciousStewEffects stewEffects = this.getHandle().stewEffects;
|
||||
if (stewEffects == null) {
|
||||
stewEffects = SuspiciousStewEffects.EMPTY;
|
||||
}
|
||||
SuspiciousStewEffects.Entry recordSuspiciousEffect = new SuspiciousStewEffects.Entry(minecraftPotionEffect.getEffect(), minecraftPotionEffect.getDuration());
|
||||
this.removeEffectFromNextStew(potionEffect.getType()); // Avoid duplicates of effects
|
||||
SuspiciousStewEffects.Entry recordSuspiciousEffect = new SuspiciousStewEffects.Entry(minecraftPotionEffect, suspiciousEffectEntry.duration()); // Paper - sus effect entry API
|
||||
this.removeEffectFromNextStew(suspiciousEffectEntry.effect()); // Avoid duplicates of effects // Paper - sus effect entry API
|
||||
this.getHandle().stewEffects = stewEffects.withEffectAdded(recordSuspiciousEffect);
|
||||
return true;
|
||||
}
|
||||
@@ -101,6 +109,43 @@ public class CraftMushroomCow extends CraftCow implements MushroomCow, io.paperm
|
||||
this.getHandle().setVariant(net.minecraft.world.entity.animal.MushroomCow.Variant.values()[variant.ordinal()]);
|
||||
}
|
||||
|
||||
// Paper start
|
||||
@Override
|
||||
public List<io.papermc.paper.potion.SuspiciousEffectEntry> getStewEffects() {
|
||||
if (this.getHandle().stewEffects == null) {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
final List<io.papermc.paper.potion.SuspiciousEffectEntry> effectEntries = new java.util.ArrayList<>(this.getHandle().stewEffects.effects().size());
|
||||
for (final SuspiciousStewEffects.Entry effect : this.getHandle().stewEffects.effects()) {
|
||||
effectEntries.add(io.papermc.paper.potion.SuspiciousEffectEntry.create(
|
||||
org.bukkit.craftbukkit.potion.CraftPotionEffectType.minecraftHolderToBukkit(effect.effect()),
|
||||
effect.duration()
|
||||
));
|
||||
}
|
||||
|
||||
return java.util.Collections.unmodifiableList(effectEntries);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStewEffects(final List<io.papermc.paper.potion.SuspiciousEffectEntry> effects) {
|
||||
if (effects.isEmpty()) {
|
||||
this.getHandle().stewEffects = null;
|
||||
return;
|
||||
}
|
||||
|
||||
List<SuspiciousStewEffects.Entry> nmsPairs = new java.util.ArrayList<>(effects.size());
|
||||
for (final io.papermc.paper.potion.SuspiciousEffectEntry effect : effects) {
|
||||
nmsPairs.add(new SuspiciousStewEffects.Entry(
|
||||
org.bukkit.craftbukkit.potion.CraftPotionEffectType.bukkitToMinecraftHolder(effect.effect()),
|
||||
effect.duration()
|
||||
));
|
||||
}
|
||||
|
||||
this.getHandle().stewEffects = new SuspiciousStewEffects(nmsPairs);
|
||||
}
|
||||
// Paper end
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CraftMushroomCow";
|
||||
|
||||
Reference in New Issue
Block a user