From c04bc89f2fe486c97a42b9a2a016e17c4967e96d Mon Sep 17 00:00:00 2001 From: Woder <17339354+wode490390@users.noreply.github.com> Date: Sun, 12 May 2024 22:25:42 +0800 Subject: [PATCH] Fix player feed particle --- src/main/java/cn/nukkit/Player.java | 20 +++++++++++++++---- .../java/cn/nukkit/command/CommandSender.java | 4 ++++ .../nukkit/command/ConsoleCommandSender.java | 6 ++++++ 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/main/java/cn/nukkit/Player.java b/src/main/java/cn/nukkit/Player.java index 22a562d24ae..f0ea21e3fda 100644 --- a/src/main/java/cn/nukkit/Player.java +++ b/src/main/java/cn/nukkit/Player.java @@ -65,6 +65,7 @@ import cn.nukkit.network.PacketViolationReason; import cn.nukkit.network.SourceInterface; import cn.nukkit.network.protocol.*; +import cn.nukkit.network.protocol.types.CommandOriginData.Origin; import cn.nukkit.network.protocol.types.ContainerIds; import cn.nukkit.network.protocol.types.NetworkInventoryAction; import cn.nukkit.permission.PermissibleBase; @@ -3333,11 +3334,17 @@ public void onCompletion(Server server) { if (entityEventPacket.data == 0 || entityEventPacket.eid != this.id) { break; } - entityEventPacket.isEncoded = false; - - this.dataPacket(entityEventPacket); - Server.broadcastPacket(this.getViewers().values(), entityEventPacket); + Item held = inventory.getItemInHand(); + if (!(held instanceof ItemEdible)) { + break; + } + EntityEventPacket pk = new EntityEventPacket(); + pk.eid = getId(); + pk.event = EntityEventPacket.EATING_ITEM; + pk.data = (held.getId() << 16) | held.getDamage(); + this.dataPacket(pk); + Server.broadcastPacket(this.getViewers().values(), pk); break; case EntityEventPacket.ENCHANT: if (entityEventPacket.eid != this.id) { @@ -6429,4 +6436,9 @@ public void swingArm() { public int getMaxViewDistance() { return server.getViewDistance(); } + + @Override + public Origin getCommandOrigin() { + return Origin.PLAYER; + } } diff --git a/src/main/java/cn/nukkit/command/CommandSender.java b/src/main/java/cn/nukkit/command/CommandSender.java index 00d6e119138..91ac52bc350 100644 --- a/src/main/java/cn/nukkit/command/CommandSender.java +++ b/src/main/java/cn/nukkit/command/CommandSender.java @@ -2,6 +2,7 @@ import cn.nukkit.Server; import cn.nukkit.lang.TextContainer; +import cn.nukkit.network.protocol.types.CommandOriginData.Origin; import cn.nukkit.permission.Permissible; /** @@ -68,4 +69,7 @@ public interface CommandSender extends Permissible { boolean isPlayer(); + default Origin getCommandOrigin() { + return Origin.SCRIPT; + } } diff --git a/src/main/java/cn/nukkit/command/ConsoleCommandSender.java b/src/main/java/cn/nukkit/command/ConsoleCommandSender.java index ab567195149..e75321d780c 100644 --- a/src/main/java/cn/nukkit/command/ConsoleCommandSender.java +++ b/src/main/java/cn/nukkit/command/ConsoleCommandSender.java @@ -2,6 +2,7 @@ import cn.nukkit.Server; import cn.nukkit.lang.TextContainer; +import cn.nukkit.network.protocol.types.CommandOriginData.Origin; import cn.nukkit.permission.PermissibleBase; import cn.nukkit.permission.Permission; import cn.nukkit.permission.PermissionAttachment; @@ -109,4 +110,9 @@ public boolean isOp() { public void setOp(boolean value) { } + + @Override + public Origin getCommandOrigin() { + return Origin.DEDICATED_SERVER; + } }