Update entity effect (#12104)

This commit is contained in:
Lulu13022002
2025-02-12 23:14:07 +01:00
committed by GitHub
parent 1be2e5f311
commit a06179a018
5 changed files with 196 additions and 90 deletions

View File

@ -544,13 +544,12 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
}
@Override
public void playEffect(EntityEffect type) {
Preconditions.checkArgument(type != null, "Type cannot be null");
public void playEffect(EntityEffect effect) {
Preconditions.checkArgument(effect != null, "Entity effect cannot be null");
Preconditions.checkState(!this.entity.generation, "Cannot play effect during world generation");
Preconditions.checkArgument(effect.isApplicableTo(this), "Entity effect cannot apply to this entity");
if (type.getApplicable().isInstance(this)) {
this.getHandle().level().broadcastEntityEvent(this.getHandle(), type.getData());
}
this.getHandle().level().broadcastEntityEvent(this.getHandle(), effect.getData());
}
@Override

View File

@ -120,6 +120,7 @@ import org.bukkit.BanList;
import org.bukkit.Bukkit;
import org.bukkit.DyeColor;
import org.bukkit.Effect;
import org.bukkit.EntityEffect;
import org.bukkit.GameMode;
import org.bukkit.Input;
import org.bukkit.Instrument;
@ -3543,10 +3544,11 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
// Paper start - entity effect API
@Override
public void sendEntityEffect(final org.bukkit.EntityEffect effect, final org.bukkit.entity.Entity target) {
if (this.getHandle().connection == null || !effect.isApplicableTo(target)) {
public void sendEntityEffect(final EntityEffect effect, final org.bukkit.entity.Entity target) {
if (this.getHandle().connection == null) {
return;
}
Preconditions.checkArgument(effect.isApplicableTo(target), "Entity effect cannot apply to the target");
this.getHandle().connection.send(new net.minecraft.network.protocol.game.ClientboundEntityEventPacket(((CraftEntity) target).getHandle(), effect.getData()));
}
// Paper end - entity effect API