mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 10:12:53 +00:00
Merge pull request #653 from CocoTheOwner/rawCommands
Raw commands in Entities
This commit is contained in:
commit
5078becbb3
@ -39,7 +39,7 @@ import org.bukkit.block.data.BlockData;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
@Decree(name = "what", origin = DecreeOrigin.PLAYER, studio = true, description = "Iris What?", aliases = "w")
|
||||
@Decree(name = "what", origin = DecreeOrigin.PLAYER, studio = true, description = "Iris What?")
|
||||
public class CommandWhat implements DecreeExecutor {
|
||||
@Decree(description = "What is in my hand?", origin = DecreeOrigin.PLAYER)
|
||||
public void hand() {
|
||||
@ -62,7 +62,7 @@ public class CommandWhat implements DecreeExecutor {
|
||||
}
|
||||
}
|
||||
|
||||
@Decree(description = "What biome am i in?", origin = DecreeOrigin.PLAYER, aliases = "b")
|
||||
@Decree(description = "What biome am i in?", origin = DecreeOrigin.PLAYER)
|
||||
public void biome() {
|
||||
try {
|
||||
IrisBiome b = engine().getBiome(player().getLocation().getBlockX(), player().getLocation().getBlockY(), player().getLocation().getBlockZ());
|
||||
|
50
src/main/java/com/volmit/iris/engine/object/IrisCommand.java
Normal file
50
src/main/java/com/volmit/iris/engine/object/IrisCommand.java
Normal file
@ -0,0 +1,50 @@
|
||||
package com.volmit.iris.engine.object;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.engine.object.annotations.ArrayType;
|
||||
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 set of Iris commands")
|
||||
@Data
|
||||
public class IrisCommand {
|
||||
|
||||
@ArrayType(min = 1, type = String.class)
|
||||
@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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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<IrisCommand> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -21,12 +21,8 @@ package com.volmit.iris.engine.object;
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.engine.data.cache.AtomicCache;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.engine.object.annotations.DependsOn;
|
||||
import com.volmit.iris.engine.object.annotations.Desc;
|
||||
import com.volmit.iris.engine.object.annotations.MaxNumber;
|
||||
import com.volmit.iris.engine.object.annotations.MinNumber;
|
||||
import com.volmit.iris.engine.object.annotations.Required;
|
||||
import com.volmit.iris.engine.object.annotations.Snippet;
|
||||
import com.volmit.iris.engine.object.annotations.*;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import com.volmit.iris.util.scheduling.ChronoLatch;
|
||||
import com.volmit.iris.util.scheduling.J;
|
||||
@ -151,6 +147,10 @@ public class IrisEffect {
|
||||
@MinNumber(1)
|
||||
@Desc("The chance is 1 in CHANCE per interval")
|
||||
private int chance = 50;
|
||||
@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();
|
||||
@ -221,6 +221,10 @@ public class IrisEffect {
|
||||
}
|
||||
}
|
||||
|
||||
if (commandRegistry != null) {
|
||||
commandRegistry.run(p);
|
||||
}
|
||||
|
||||
if (potionStrength > -1) {
|
||||
if (p.hasPotionEffect(getRealType())) {
|
||||
PotionEffect e = p.getPotionEffect(getRealType());
|
||||
|
@ -176,6 +176,10 @@ public class IrisEntity extends IrisRegistrant {
|
||||
@RegistryListResource(IrisScript.class)
|
||||
private KList<String> postSpawnScripts = new KList<>();
|
||||
|
||||
@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<IrisCommand> rawCommands = new KList<>();
|
||||
|
||||
public Entity spawn(Engine gen, Location at) {
|
||||
return spawn(gen, at, new RNG(at.hashCode()));
|
||||
}
|
||||
@ -357,6 +361,11 @@ public class IrisEntity extends IrisRegistrant {
|
||||
}
|
||||
}
|
||||
|
||||
if (rawCommands.isNotEmpty()) {
|
||||
final Location fat = at;
|
||||
rawCommands.forEach(r -> r.run(fat));
|
||||
}
|
||||
|
||||
Location finalAt1 = at;
|
||||
|
||||
J.s(() -> {
|
||||
|
Loading…
x
Reference in New Issue
Block a user