From 85b0061a1129664714df4dc4538d98e93588d7b2 Mon Sep 17 00:00:00 2001 From: PeyaPeyaPeyang Date: Fri, 20 Oct 2023 23:50:04 +0900 Subject: [PATCH] fix(context): Entity won't be generated --- .../scenamatica/commons/utils/Utils.java | 15 +++++++++++++++ .../context/ContextManagerImpl.java | 19 +++++++++++++------ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/ScenamaticaCommons/src/main/java/org/kunlab/scenamatica/commons/utils/Utils.java b/ScenamaticaCommons/src/main/java/org/kunlab/scenamatica/commons/utils/Utils.java index 542e4d9d4..2508ee0df 100644 --- a/ScenamaticaCommons/src/main/java/org/kunlab/scenamatica/commons/utils/Utils.java +++ b/ScenamaticaCommons/src/main/java/org/kunlab/scenamatica/commons/utils/Utils.java @@ -10,6 +10,7 @@ import org.kunlab.scenamatica.interfaces.scenariofile.misc.BlockBean; import java.util.Locale; +import java.util.UUID; @UtilityClass public class Utils @@ -82,4 +83,18 @@ else if ((material = Material.matchMaterial(nameLower)) != null) else return null; } + + public static int[] convertUUIDToIntegers(UUID uuid) + { + int[] uuidIntegers = new int[4]; + long mostSigBits = uuid.getMostSignificantBits(); + long leastSigBits = uuid.getLeastSignificantBits(); + + uuidIntegers[0] = (int) (mostSigBits >> 32); + uuidIntegers[1] = (int) mostSigBits; + uuidIntegers[2] = (int) (leastSigBits >> 32); + uuidIntegers[3] = (int) leastSigBits; + + return uuidIntegers; + } } diff --git a/ScenamaticaContextEngine/src/main/java/org/kunlab/scenamatica/context/ContextManagerImpl.java b/ScenamaticaContextEngine/src/main/java/org/kunlab/scenamatica/context/ContextManagerImpl.java index 1f6d35e9c..b142b2c46 100644 --- a/ScenamaticaContextEngine/src/main/java/org/kunlab/scenamatica/context/ContextManagerImpl.java +++ b/ScenamaticaContextEngine/src/main/java/org/kunlab/scenamatica/context/ContextManagerImpl.java @@ -122,6 +122,7 @@ private List prepareActors(ContextBean context, ScenarioFileBean scenario } + @SneakyThrows(InterruptedException.class) private Entity spawnEntity(World stage, EntityBean entity) { EntityType type = entity.getType(); @@ -142,17 +143,23 @@ private Entity spawnEntity(World stage, EntityBean entity) spawnLoc = entity.getLocation(); return ThreadingUtil.waitForOrThrow(this.registry, () -> { + UUID entityTag = UUID.randomUUID(); + String tagName = "scenamatica-" + entityTag; Entity e = stage.spawnEntity(spawnLoc, type, CreatureSpawnEvent.SpawnReason.CUSTOM, - generatedEntity -> BeanUtils.applyEntityBeanData(entity, generatedEntity) + generatedEntity -> { + BeanUtils.applyEntityBeanData(entity, generatedEntity); + generatedEntity.addScoreboardTag(tagName); + } ); - try - { - Thread.sleep(100); - } - catch (InterruptedException ignored) + do { + Thread.sleep(1000); } + while (Bukkit.selectEntities(Bukkit.getConsoleSender(), "@e[tag=" + tagName + "]").isEmpty()); + + e.removeScoreboardTag(tagName); + return e; } );