Fix removal of holograms not working properly (#103)

This commit is contained in:
OmerBenGera 2024-06-29 15:24:41 +03:00
parent 0cc90156a8
commit c4c30c1265
5 changed files with 39 additions and 4 deletions

View File

@ -1,6 +1,7 @@
package com.bgsoftware.wildloaders.nms.v1_19; package com.bgsoftware.wildloaders.nms.v1_19;
import com.bgsoftware.wildloaders.api.holograms.Hologram; import com.bgsoftware.wildloaders.api.holograms.Hologram;
import com.bgsoftware.wildloaders.scheduler.Scheduler;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerLevel; 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.AABB;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_19_R3.CraftServer; 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.CraftArmorStand;
import org.bukkit.craftbukkit.v1_19_R3.entity.CraftEntity; import org.bukkit.craftbukkit.v1_19_R3.entity.CraftEntity;
@ -48,7 +50,14 @@ public final class EntityHologram extends ArmorStand implements Hologram {
@Override @Override
public void removeHologram() { 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 @Override

View File

@ -16,6 +16,7 @@ import net.minecraft.world.item.ItemStack;
import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_20_R3.CraftServer; 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.CraftArmorStand;
import org.bukkit.craftbukkit.v1_20_R3.entity.CraftEntity; import org.bukkit.craftbukkit.v1_20_R3.entity.CraftEntity;
@ -50,7 +51,10 @@ public final class EntityHologram extends ArmorStand implements Hologram {
@Override @Override
public void removeHologram() { public void removeHologram() {
if (Scheduler.isRegionScheduler() || !Bukkit.isPrimaryThread()) { 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 { } else {
super.remove(RemovalReason.DISCARDED); super.remove(RemovalReason.DISCARDED);
} }

View File

@ -1,6 +1,7 @@
package com.bgsoftware.wildloaders.nms.v1_20_4; package com.bgsoftware.wildloaders.nms.v1_20_4;
import com.bgsoftware.wildloaders.api.holograms.Hologram; import com.bgsoftware.wildloaders.api.holograms.Hologram;
import com.bgsoftware.wildloaders.scheduler.Scheduler;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerLevel; 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.AABB;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.entity.CraftArmorStand; import org.bukkit.craftbukkit.entity.CraftArmorStand;
import org.bukkit.craftbukkit.entity.CraftEntity; import org.bukkit.craftbukkit.entity.CraftEntity;
@ -48,7 +50,14 @@ public final class EntityHologram extends ArmorStand implements Hologram {
@Override @Override
public void removeHologram() { 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 @Override

View File

@ -1,6 +1,7 @@
package com.bgsoftware.wildloaders.nms.v1_21; package com.bgsoftware.wildloaders.nms.v1_21;
import com.bgsoftware.wildloaders.api.holograms.Hologram; import com.bgsoftware.wildloaders.api.holograms.Hologram;
import com.bgsoftware.wildloaders.scheduler.Scheduler;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerLevel; 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.AABB;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.entity.CraftArmorStand; import org.bukkit.craftbukkit.entity.CraftArmorStand;
import org.bukkit.craftbukkit.entity.CraftEntity; import org.bukkit.craftbukkit.entity.CraftEntity;
@ -48,7 +50,14 @@ public final class EntityHologram extends ArmorStand implements Hologram {
@Override @Override
public void removeHologram() { 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 @Override

View File

@ -64,6 +64,10 @@ public class Scheduler {
return runTask(location.getWorld(), location.getBlockX() >> 4, location.getBlockZ() >> 4, task, delay); 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) { public static ScheduledTask runTask(Entity entity, Runnable task) {
return runTask(entity, task, 0L); return runTask(entity, task, 0L);
} }