diff --git a/src/main/java/com/volmit/iris/engine/object/IrisCommand.java b/src/main/java/com/volmit/iris/engine/object/IrisCommand.java index af1a6bc07..008fe5d51 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisCommand.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisCommand.java @@ -15,7 +15,7 @@ import org.bukkit.Location; @Snippet("command") @Accessors(chain = true) @NoArgsConstructor -@Desc("Represents a color") +@Desc("Represents a set of Iris commands") @Data public class IrisCommand { diff --git a/src/main/java/com/volmit/iris/engine/object/IrisCommandRegistry.java b/src/main/java/com/volmit/iris/engine/object/IrisCommandRegistry.java new file mode 100644 index 000000000..dc77a1f17 --- /dev/null +++ b/src/main/java/com/volmit/iris/engine/object/IrisCommandRegistry.java @@ -0,0 +1,66 @@ +package com.volmit.iris.engine.object; + +import com.volmit.iris.engine.object.annotations.*; +import com.volmit.iris.util.collection.KList; +import com.volmit.iris.util.math.RNG; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.experimental.Accessors; +import org.bukkit.Location; +import org.bukkit.entity.Player; + +@Snippet("command-registry") +@Accessors(chain = true) +@NoArgsConstructor +@Desc("Represents a casting location for a command") +@Data +public class IrisCommandRegistry { + @ArrayType(min = 1, type = IrisCommand.class) + @Desc("Run commands, at the exact location of the player") + private KList rawCommands = new KList<>(); + @DependsOn({"rawCommands"}) + @MinNumber(-8) + @MaxNumber(8) + @Desc("The alt x, usually represents motion if the particle count is zero. Otherwise an offset.") + private double commandOffsetX = 0; + @DependsOn({"rawCommands"}) + @MinNumber(-8) + @MaxNumber(8) + @Desc("The alt y, usually represents motion if the particle count is zero. Otherwise an offset.") + private double commandOffsetY = 0; + @DependsOn({"rawCommands"}) + @MinNumber(-8) + @MaxNumber(8) + @Desc("The alt z, usually represents motion if the particle count is zero. Otherwise an offset.") + private double commandOffsetZ = 0; + @DependsOn({"rawCommands"}) + @Desc("Randomize the altX from -altX to altX") + private boolean commandRandomAltX = true; + @DependsOn({"rawCommands"}) + @Desc("Randomize the altY from -altY to altY") + private boolean commandRandomAltY = false; + @DependsOn({"rawCommands"}) + @Desc("Randomize the altZ from -altZ to altZ") + private boolean commandRandomAltZ = true; + @DependsOn({"rawCommands"}) + @Desc("Randomize location for all separate commands (true), or run all on the same location (false)") + private boolean commandAllRandomLocations = true; + + public void run(Player p) { + if (rawCommands.isNotEmpty()) { + Location part = p.getLocation().clone().add( + commandRandomAltX ? RNG.r.d(-commandOffsetX, commandOffsetX) : commandOffsetX, + commandRandomAltY ? RNG.r.d(-commandOffsetY, commandOffsetY) : commandOffsetY, + commandRandomAltZ ? RNG.r.d(-commandOffsetZ, commandOffsetZ) : commandOffsetZ); + for (IrisCommand rawCommand : rawCommands) { + rawCommand.run(part); + if (commandAllRandomLocations) { + part = p.getLocation().clone().add( + commandRandomAltX ? RNG.r.d(-commandOffsetX, commandOffsetX) : commandOffsetX, + commandRandomAltY ? RNG.r.d(-commandOffsetY, commandOffsetY) : commandOffsetY, + commandRandomAltZ ? RNG.r.d(-commandOffsetZ, commandOffsetZ) : commandOffsetZ); + } + } + } + } +} diff --git a/src/main/java/com/volmit/iris/engine/object/IrisEffect.java b/src/main/java/com/volmit/iris/engine/object/IrisEffect.java index ed7c45449..8175c19f3 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisEffect.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisEffect.java @@ -147,36 +147,10 @@ public class IrisEffect { @MinNumber(1) @Desc("The chance is 1 in CHANCE per interval") private int chance = 50; - @ArrayType(min = 1, type = IrisCommand.class) - @Desc("Run commands, at the exact location of the player") - private KList rawCommands = new KList<>(); - @DependsOn({"rawCommands"}) - @MinNumber(-8) - @MaxNumber(8) - @Desc("The alt x, usually represents motion if the particle count is zero. Otherwise an offset.") - private double commandOffsetX = 0; - @DependsOn({"rawCommands"}) - @MinNumber(-8) - @MaxNumber(8) - @Desc("The alt y, usually represents motion if the particle count is zero. Otherwise an offset.") - private double commandOffsetY = 0; - @DependsOn({"rawCommands"}) - @MinNumber(-8) - @MaxNumber(8) - @Desc("The alt z, usually represents motion if the particle count is zero. Otherwise an offset.") - private double commandOffsetZ = 0; - @DependsOn({"rawCommands"}) - @Desc("Randomize the altX from -altX to altX") - private boolean commandRandomAltX = true; - @DependsOn({"rawCommands"}) - @Desc("Randomize the altY from -altY to altY") - private boolean commandRandomAltY = false; - @DependsOn({"rawCommands"}) - @Desc("Randomize the altZ from -altZ to altZ") - private boolean commandRandomAltZ = true; - @DependsOn({"rawCommands"}) - @Desc("Randomize location for all separate commands (true), or run all on the same location (false)") - private boolean commandAllRandomLocations = true; + @ArrayType(min = 1, type = IrisCommandRegistry.class) + @Desc("Run commands, with configurable location parameters") + private IrisCommandRegistry commandRegistry = null; + public boolean canTick() { return latch.aquire(() -> new ChronoLatch(interval)).flip(); @@ -247,20 +221,8 @@ public class IrisEffect { } } - if (rawCommands.isNotEmpty()) { - Location part = p.getLocation().clone().add( - commandRandomAltX ? RNG.r.d(-commandOffsetX, commandOffsetX) : commandOffsetX, - commandRandomAltY ? RNG.r.d(-commandOffsetY, commandOffsetY) : commandOffsetY, - commandRandomAltZ ? RNG.r.d(-commandOffsetZ, commandOffsetZ) : commandOffsetZ); - for (IrisCommand rawCommand : rawCommands) { - rawCommand.run(part); - if (commandAllRandomLocations) { - part = p.getLocation().clone().add( - commandRandomAltX ? RNG.r.d(-commandOffsetX, commandOffsetX) : commandOffsetX, - commandRandomAltY ? RNG.r.d(-commandOffsetY, commandOffsetY) : commandOffsetY, - commandRandomAltZ ? RNG.r.d(-commandOffsetZ, commandOffsetZ) : commandOffsetZ); - } - } + if (commandRegistry != null) { + commandRegistry.run(p); } if (potionStrength > -1) {