From 2b2f2389e725d0ce9addaf32921d9f6d6630cff0 Mon Sep 17 00:00:00 2001 From: Woder <17339354+wode490390@users.noreply.github.com> Date: Tue, 9 Jul 2024 14:28:40 +0800 Subject: [PATCH] Fix entity link removing --- src/main/java/cn/nukkit/entity/Entity.java | 7 +++++ src/main/java/cn/nukkit/utils/Utils.java | 32 ++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/src/main/java/cn/nukkit/entity/Entity.java b/src/main/java/cn/nukkit/entity/Entity.java index 6dfe02618e4..afad4035b06 100644 --- a/src/main/java/cn/nukkit/entity/Entity.java +++ b/src/main/java/cn/nukkit/entity/Entity.java @@ -31,6 +31,7 @@ import cn.nukkit.plugin.Plugin; import cn.nukkit.potion.Effect; import cn.nukkit.utils.ChunkException; +import cn.nukkit.utils.Utils; import com.google.common.collect.Iterables; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; @@ -1184,6 +1185,11 @@ public void sendData(Player[] players, EntityMetadata data) { } public void despawnFrom(Player player) { + if (player.riding == this && !dismountEntity(player)) { + log.warn("Please remove entity links before despawning", new Throwable("debug trace")); + Utils.pauseInIde(); + } + if (this.hasSpawned.remove(player.getLoaderId()) != null) { RemoveEntityPacket pk = new RemoveEntityPacket(); pk.eid = this.getId(); @@ -2483,6 +2489,7 @@ public boolean teleport(Location location, PlayerTeleportEvent.TeleportCause cau } if (this.riding != null && !this.riding.dismountEntity(this)) { + Utils.pauseInIde(); return false; } diff --git a/src/main/java/cn/nukkit/utils/Utils.java b/src/main/java/cn/nukkit/utils/Utils.java index 205c54932e6..7f9ad0ea57c 100644 --- a/src/main/java/cn/nukkit/utils/Utils.java +++ b/src/main/java/cn/nukkit/utils/Utils.java @@ -1,5 +1,7 @@ package cn.nukkit.utils; +import lombok.extern.log4j.Log4j2; + import java.io.*; import java.lang.management.ManagementFactory; import java.lang.management.ThreadInfo; @@ -9,12 +11,33 @@ import java.util.Map; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; +import java.util.function.Consumer; +import java.util.function.Supplier; + +import static cn.nukkit.SharedConstants.*; /** * author: MagicDroidX * Nukkit Project */ +@Log4j2 public class Utils { + private static Consumer PAUSER = message -> { + }; + + public static void setPause(Consumer pauser) { + PAUSER = pauser; + } + + public static void pauseInIde() { + pauseInIde(""); + } + + public static void pauseInIde(String message) { + if (BREAKPOINT_DEBUGGING) { + PAUSER.accept(message); + } + } public static void writeFile(String fileName, String content) throws IOException { writeFile(fileName, new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8))); @@ -280,4 +303,13 @@ public static int[] toPrimitive(Integer[] array) { return result; } } + + public static T make(Supplier supplier) { + return supplier.get(); + } + + public static T make(T value, Consumer consumer) { + consumer.accept(value); + return value; + } }