IScriptCommand API
Prerequisites
1. Creating th Command Class
package com.yourmod.storyscript.commands;
import com.lasticks.storyscript.api.IScriptCommand;
import com.lasticks.storyscript.api.ScriptContext;
import net.minecraft.server.network.ServerPlayerEntity;
public class HealCommand implements IScriptCommand {
@Override
public void execute(ScriptContext ctx, String[] args) {
// 1. Get the player (the command source)
ServerPlayerEntity player = ctx.getSource().getPlayer();
// Check if the source is a player (not the console)
if (player != null) {
// 2. Execute the action
player.setHealth(player.getMaxHealth());
player.getHungerManager().setFoodLevel(20);
// 3. Provide feedback (optional)
ctx.sendMessage("You feel refreshed!");
} else {
// Handle if the command was run by console
ctx.sendError("The HEAL command can only be used by players.");
}
// Note: Commands should execute instantly.
// If you need a pause, use: ctx.sleep(seconds);
}
}2. Registering the Command
Example: Mod Initialization
3. Usage in Script Files
Argument Handling
4. Key Context Methods
Last updated