Run raw commands for entity spawns

This commit is contained in:
CocoTheOwner 2021-09-21 17:57:55 +02:00
parent 8539bc5ade
commit 7878b05030

View File

@ -176,6 +176,10 @@ public class IrisEntity extends IrisRegistrant {
@RegistryListResource(IrisScript.class)
private KList<String> postSpawnScripts = new KList<>();
@ArrayType(min = 1, type = String.class)
@Desc("Run raw commands when this entity is spawned. Use {x}, {y}, and {z} for location. /summon pig {x} {y} {z}")
private KList<String> rawCommands = new KList<>();
public Entity spawn(Engine gen, Location at) {
return spawn(gen, at, new RNG(at.hashCode()));
}
@ -357,6 +361,17 @@ public class IrisEntity extends IrisRegistrant {
}
}
if (rawCommands.isNotEmpty()) {
synchronized (this) {
for (String rawCommand : rawCommands) {
rawCommand.replaceAll("\\Q{x}\\E", String.valueOf(at.getBlockX()));
rawCommand.replaceAll("\\Q{y}\\E", String.valueOf(at.getBlockY()));
rawCommand.replaceAll("\\Q{z}\\E", String.valueOf(at.getBlockZ()));
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), rawCommand);
}
}
}
Location finalAt1 = at;
J.s(() -> {