Skip to content

Commit

Permalink
fix(context): Entity won't be generated
Browse files Browse the repository at this point in the history
  • Loading branch information
PeyaPeyaPeyang committed Oct 20, 2023
1 parent 2e322e5 commit 85b0061
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.kunlab.scenamatica.interfaces.scenariofile.misc.BlockBean;

import java.util.Locale;
import java.util.UUID;

@UtilityClass
public class Utils
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ private List<Actor> prepareActors(ContextBean context, ScenarioFileBean scenario

}

@SneakyThrows(InterruptedException.class)
private Entity spawnEntity(World stage, EntityBean entity)
{
EntityType type = entity.getType();
Expand All @@ -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;
}
);
Expand Down

0 comments on commit 85b0061

Please sign in to comment.