mirror of
https://github.com/boy0001/FastAsyncWorldedit.git
synced 2024-11-22 02:25:53 +01:00
Page:
JavaScript API
Pages
API
Anvil API
AsyncWorld
Brushes
Clipboard API
Commands
Configuration
Copying a region to another world.
CreateFromImage
Download Instructions: Bukkit Spigot
Fawe TaskManager
FawePlayer
FaweQueue
Home
JavaScript API
Jobs API
Light API
NBT stream API
Packet sending
Pasting a schematic
Permissions
Progress API
Recovering corrupt NBT files (MCA Schematic etc.)
Region restriction API
Registering Custom Masks, Patterns and Transforms
Registering custom brushes or commands
Rollback API
Some tips when using the FAWE API
TaskBuilder
TextureUtil block and biome coloring
Third party loggers
Transforms
Web API
WorldEdit FAWE mask list
WorldEdit EditSession
WorldEdit World Player
WorldEdit and FAWE patterns
4
JavaScript API
Jesse Boyd edited this page 2018-08-23 13:49:18 +10:00
Requirements
- FAWE for 1.13
- Java 9 (Or nashorn with es6 support)
Introduction
- JavaScript can be used to register commands, patterns, masks, and brushes
- Scripts should be placed in
plugins/FastAsyncWorldEdit/commands
(can be configured in theconfig.yml
) - Use
/fawe reload
to reload the scripts. - Nashorn Tutorial | Oracle Nashorn Tutorial
Creating normal commands
Create a new .js
file in commands/
, or commands/<alias>/
Example file:
- All functions with a description (
desc
) will be registered.
load("nashorn:mozilla_compat.js") // Allow package imports
importPackage(Packages.java.io);
importPackage(Packages.java.lang);
importPackage(Packages.org.bukkit);
importPackage(Packages.com.sk89q.worldedit); // Import whatever packages you need
hello.desc = "Some description"; // this is the only required field
hello.aliases = ["hello", "helloworld"]; // Defaults to the function name
hello.usage = "[blah=3]"; // Defaults to the parameters
hello.flags = "f"; // A string with the characters that are flag parameters (defaults to empty string)
hello.permission = "fawe.use"; // The permission (defaults to fawe.use)
function hello(player = Player, blah = Double = "3", f) {
// Parameters are in the form: param = type = default
// Type defaults to String (flags default to Boolean)
// To make a value optional use null as the default (flags are optional)
player.print("Hello World: " + blah + " | " + f);
}
Creating a custom pattern
Create a new .js
file in commands/patterns
(Similar thing with masks, except in commands/masks
, and returns a Mask)
load("nashorn:mozilla_compat.js")
importPackage(Packages.java.io);
importPackage(Packages.java.lang);
importPackage(Packages.org.bukkit);
importPackage(Packages.com.sk89q.worldedit);
importPackage(Packages.com.sk89q.worldedit.blocks);
test.desc = "Using a pattern from javascript";
test.aliases = ["#blah"];
function test(player = Player) {
// Return some pattern here - idk stone?
return new BaseBlock(1, 0);
}
Registering a brush
Create a new .js
file in commands/brush
// Some standard imports, half of which aren't used, lol
load("nashorn:mozilla_compat.js")
importPackage(Packages.java.io);
importPackage(Packages.java.lang);
importPackage(Packages.org.bukkit);
importPackage(Packages.com.boydti.fawe);
importPackage(Packages.com.sk89q.worldedit);
importPackage(Packages.com.sk89q.worldedit.entity);
importPackage(Packages.com.sk89q.worldedit.blocks);
importPackage(Packages.com.sk89q.worldedit.patterns);
importPackage(Packages.com.sk89q.worldedit.vector);
importPackage(Packages.com.sk89q.worldedit.regions);
importPackage(Packages.com.sk89q.worldedit.regions.region);
importPackage(Packages.com.sk89q.minecraft.util.commands)
importPackage(Packages.com.sk89q.worldedit.tools);
importPackage(Packages.com.sk89q.worldedit.command);
importPackage(Packages.com.sk89q.worldedit.tools.brushes);
importPackage(Packages.com.sk89q.worldedit.world.biome);
importPackage(Packages.com.sk89q.worldedit.command.tool);
importPackage(Packages.com.sk89q.worldedit.command.tool.brush);
importPackage(Packages.com.sk89q.worldedit.function.operation);
importPackage(Packages.com.sk89q.worldedit.function.pattern);
importPackage(Packages.com.sk89q.worldedit.extension.platform.permission);
// Brush commands expect a BrushSettings to be returned
// We can use the BrushProcessor class to help construct one
var worldEdit = WorldEdit.getInstance();
var processor = new BrushProcessor(worldEdit);
spherejs.desc = "Sphere brush from javascript"; // The description (required)
spherejs.aliases = ["spherejs"]; // The aliases for the command (defaults to the name of the function)
spherejs.usage = "<pattern> [radius=2]"; // The usage (defaults to the function parameters)
spherejs.flags = "hf"; // The flag parameters (defaults to empty string)
spherejs.permission = "worldedit.brush.spherejs"; // The permission (defaults to fawe.use)
function spherejs(player = Player, editSession = EditSession, session = LocalSession, fill = Pattern, radius = Expression = "5", h, f, context = CommandContext) {
// Parameters are in the form: param = type = default
// Type defaults to String (flags default to Boolean)
// To make a value optional use null as the default
worldEdit.checkMaxBrushRadius(radius);
player.print("h flag is " + h); // TODO do something with the flags?
player.print("f flag is " + f);
// TODO return some custom brush instead of sphere
return processor.set(session, context, new SphereBrush()).setSize(radius).setFill(fill);
}
This Wiki is for Legacy Versions (1.8 - 1.12.2). Check here for 1.13+ versions: https://github.com/IntellectualSites/FastAsyncWorldEdit-Documentation/