mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 18:23:06 +00:00
Introduction if IrisCommands
This commit is contained in:
parent
940a65cac0
commit
b73f9798e4
48
src/main/java/com/volmit/iris/engine/object/IrisCommand.java
Normal file
48
src/main/java/com/volmit/iris/engine/object/IrisCommand.java
Normal file
@ -0,0 +1,48 @@
|
||||
package com.volmit.iris.engine.object;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.engine.object.annotations.Desc;
|
||||
import com.volmit.iris.engine.object.annotations.RegistryListResource;
|
||||
import com.volmit.iris.engine.object.annotations.Snippet;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
|
||||
@Snippet("command")
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@Desc("Represents a color")
|
||||
@Data
|
||||
public class IrisCommand {
|
||||
|
||||
@Desc("List of commands. Iris replaces {x} {y} and {z} with the location of the entity spawn")
|
||||
private KList<String> commands = new KList<>();
|
||||
|
||||
@Desc("The delay for running the command. Instant by default")
|
||||
private long delay = 0;
|
||||
|
||||
@Desc("If this should be repeated (indefinitely, cannot be cancelled). This does not persist with server-restarts, so it only repeats when the chunk is generated.")
|
||||
private boolean repeat = false;
|
||||
|
||||
@Desc("The delay between repeats, in server ticks (by default 100, so 5 seconds)")
|
||||
private long repeatDelay = 100;
|
||||
|
||||
|
||||
public void run(Location at) {
|
||||
for (String command : commands) {
|
||||
command = (command.startsWith("/") ? command.replaceFirst("/", "") : command)
|
||||
.replaceAll("\\Q{x}\\E", String.valueOf(at.getBlockX()))
|
||||
.replaceAll("\\Q{y}\\E", String.valueOf(at.getBlockY()))
|
||||
.replaceAll("\\Q{z}\\E", String.valueOf(at.getBlockZ()));
|
||||
final String finalCommand = command;
|
||||
if (repeat) {
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(Iris.instance, () -> Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), finalCommand), delay, repeatDelay);
|
||||
} else {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(Iris.instance, () -> Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), finalCommand), delay);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -176,9 +176,9 @@ public class IrisEntity extends IrisRegistrant {
|
||||
@RegistryListResource(IrisScript.class)
|
||||
private KList<String> postSpawnScripts = new KList<>();
|
||||
|
||||
@ArrayType(min = 1, type = String.class)
|
||||
@ArrayType(min = 1, type = IrisCommand.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<>();
|
||||
private KList<IrisCommand> rawCommands = new KList<>();
|
||||
|
||||
public Entity spawn(Engine gen, Location at) {
|
||||
return spawn(gen, at, new RNG(at.hashCode()));
|
||||
@ -362,14 +362,8 @@ 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);
|
||||
}
|
||||
}
|
||||
final Location fat = at;
|
||||
rawCommands.forEach(r -> r.run(fat));
|
||||
}
|
||||
|
||||
Location finalAt1 = at;
|
||||
|
Loading…
x
Reference in New Issue
Block a user