diff --git a/NMS/v1_19/src/main/java/com/bgsoftware/wildloaders/nms/v1_19/EntityHologram.java b/NMS/v1_19/src/main/java/com/bgsoftware/wildloaders/nms/v1_19/EntityHologram.java index 287e14c..796557c 100644 --- a/NMS/v1_19/src/main/java/com/bgsoftware/wildloaders/nms/v1_19/EntityHologram.java +++ b/NMS/v1_19/src/main/java/com/bgsoftware/wildloaders/nms/v1_19/EntityHologram.java @@ -1,6 +1,7 @@ package com.bgsoftware.wildloaders.nms.v1_19; import com.bgsoftware.wildloaders.api.holograms.Hologram; +import com.bgsoftware.wildloaders.scheduler.Scheduler; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.server.level.ServerLevel; @@ -15,6 +16,7 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.Vec3; import org.bukkit.Bukkit; +import org.bukkit.World; import org.bukkit.craftbukkit.v1_19_R3.CraftServer; import org.bukkit.craftbukkit.v1_19_R3.entity.CraftArmorStand; import org.bukkit.craftbukkit.v1_19_R3.entity.CraftEntity; @@ -48,7 +50,14 @@ public final class EntityHologram extends ArmorStand implements Hologram { @Override public void removeHologram() { - super.remove(RemovalReason.DISCARDED); + if (Scheduler.isRegionScheduler() || !Bukkit.isPrimaryThread()) { + World world = level.getWorld(); + int chunkX = getBlockX() >> 4; + int chunkZ = getBlockZ() >> 4; + Scheduler.runTask(world, chunkX, chunkZ, () -> super.remove(RemovalReason.DISCARDED)); + } else { + super.remove(RemovalReason.DISCARDED); + } } @Override diff --git a/NMS/v1_20_3/src/main/java/com/bgsoftware/wildloaders/nms/v1_20_3/EntityHologram.java b/NMS/v1_20_3/src/main/java/com/bgsoftware/wildloaders/nms/v1_20_3/EntityHologram.java index 548f755..7ff0aa5 100644 --- a/NMS/v1_20_3/src/main/java/com/bgsoftware/wildloaders/nms/v1_20_3/EntityHologram.java +++ b/NMS/v1_20_3/src/main/java/com/bgsoftware/wildloaders/nms/v1_20_3/EntityHologram.java @@ -16,6 +16,7 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.Vec3; import org.bukkit.Bukkit; +import org.bukkit.World; import org.bukkit.craftbukkit.v1_20_R3.CraftServer; import org.bukkit.craftbukkit.v1_20_R3.entity.CraftArmorStand; import org.bukkit.craftbukkit.v1_20_R3.entity.CraftEntity; @@ -50,7 +51,10 @@ public final class EntityHologram extends ArmorStand implements Hologram { @Override public void removeHologram() { if (Scheduler.isRegionScheduler() || !Bukkit.isPrimaryThread()) { - Scheduler.runTask(getBukkitEntity(), () -> super.remove(RemovalReason.DISCARDED)); + World world = level().getWorld(); + int chunkX = getBlockX() >> 4; + int chunkZ = getBlockZ() >> 4; + Scheduler.runTask(world, chunkX, chunkZ, () -> super.remove(RemovalReason.DISCARDED)); } else { super.remove(RemovalReason.DISCARDED); } diff --git a/NMS/v1_20_4/src/main/java/com/bgsoftware/wildloaders/nms/v1_20_4/EntityHologram.java b/NMS/v1_20_4/src/main/java/com/bgsoftware/wildloaders/nms/v1_20_4/EntityHologram.java index fb977c0..fd09e9b 100644 --- a/NMS/v1_20_4/src/main/java/com/bgsoftware/wildloaders/nms/v1_20_4/EntityHologram.java +++ b/NMS/v1_20_4/src/main/java/com/bgsoftware/wildloaders/nms/v1_20_4/EntityHologram.java @@ -1,6 +1,7 @@ package com.bgsoftware.wildloaders.nms.v1_20_4; import com.bgsoftware.wildloaders.api.holograms.Hologram; +import com.bgsoftware.wildloaders.scheduler.Scheduler; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.server.level.ServerLevel; @@ -15,6 +16,7 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.Vec3; import org.bukkit.Bukkit; +import org.bukkit.World; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.entity.CraftArmorStand; import org.bukkit.craftbukkit.entity.CraftEntity; @@ -48,7 +50,14 @@ public final class EntityHologram extends ArmorStand implements Hologram { @Override public void removeHologram() { - super.remove(RemovalReason.DISCARDED); + if (Scheduler.isRegionScheduler() || !Bukkit.isPrimaryThread()) { + World world = level().getWorld(); + int chunkX = getBlockX() >> 4; + int chunkZ = getBlockZ() >> 4; + Scheduler.runTask(world, chunkX, chunkZ, () -> super.remove(RemovalReason.DISCARDED)); + } else { + super.remove(RemovalReason.DISCARDED); + } } @Override diff --git a/NMS/v1_21/src/main/java/com/bgsoftware/wildloaders/nms/v1_21/EntityHologram.java b/NMS/v1_21/src/main/java/com/bgsoftware/wildloaders/nms/v1_21/EntityHologram.java index 6764b9d..ea47c76 100644 --- a/NMS/v1_21/src/main/java/com/bgsoftware/wildloaders/nms/v1_21/EntityHologram.java +++ b/NMS/v1_21/src/main/java/com/bgsoftware/wildloaders/nms/v1_21/EntityHologram.java @@ -1,6 +1,7 @@ package com.bgsoftware.wildloaders.nms.v1_21; import com.bgsoftware.wildloaders.api.holograms.Hologram; +import com.bgsoftware.wildloaders.scheduler.Scheduler; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.server.level.ServerLevel; @@ -15,6 +16,7 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.Vec3; import org.bukkit.Bukkit; +import org.bukkit.World; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.entity.CraftArmorStand; import org.bukkit.craftbukkit.entity.CraftEntity; @@ -48,7 +50,14 @@ public final class EntityHologram extends ArmorStand implements Hologram { @Override public void removeHologram() { - super.remove(RemovalReason.DISCARDED); + if (Scheduler.isRegionScheduler() || !Bukkit.isPrimaryThread()) { + World world = level().getWorld(); + int chunkX = getBlockX() >> 4; + int chunkZ = getBlockZ() >> 4; + Scheduler.runTask(world, chunkX, chunkZ, () -> super.remove(RemovalReason.DISCARDED)); + } else { + super.remove(RemovalReason.DISCARDED); + } } @Override diff --git a/src/main/java/com/bgsoftware/wildloaders/scheduler/Scheduler.java b/src/main/java/com/bgsoftware/wildloaders/scheduler/Scheduler.java index 9ddff66..4df0ba8 100644 --- a/src/main/java/com/bgsoftware/wildloaders/scheduler/Scheduler.java +++ b/src/main/java/com/bgsoftware/wildloaders/scheduler/Scheduler.java @@ -64,6 +64,10 @@ public class Scheduler { return runTask(location.getWorld(), location.getBlockX() >> 4, location.getBlockZ() >> 4, task, delay); } + public static ScheduledTask runTask(World world, int chunkX, int chunkZ, Runnable task) { + return runTask(world, chunkX, chunkZ, task, 0L); + } + public static ScheduledTask runTask(Entity entity, Runnable task) { return runTask(entity, task, 0L); }