Skip to content

Commit

Permalink
Fix entity link removing
Browse files Browse the repository at this point in the history
  • Loading branch information
wode490390 committed Jul 9, 2024
1 parent 02f724c commit 2b2f238
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/main/java/cn/nukkit/entity/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -2483,6 +2489,7 @@ public boolean teleport(Location location, PlayerTeleportEvent.TeleportCause cau
}

if (this.riding != null && !this.riding.dismountEntity(this)) {
Utils.pauseInIde();
return false;
}

Expand Down
32 changes: 32 additions & 0 deletions src/main/java/cn/nukkit/utils/Utils.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<String> PAUSER = message -> {
};

public static void setPause(Consumer<String> 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)));
Expand Down Expand Up @@ -280,4 +303,13 @@ public static int[] toPrimitive(Integer[] array) {
return result;
}
}

public static <T> T make(Supplier<T> supplier) {
return supplier.get();
}

public static <T> T make(T value, Consumer<? super T> consumer) {
consumer.accept(value);
return value;
}
}

0 comments on commit 2b2f238

Please sign in to comment.