Skip to content
Jesse Boyd edited this page Aug 23, 2018 · 4 revisions

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 the config.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 importsimportPackage(Packages.java.io);importPackage(Packages.java.lang);importPackage(Packages.org.bukkit);importPackage(Packages.com.sk89q.worldedit);// Import whatever packages you needhello.desc="Some description";// this is the only required fieldhello.aliases=["hello","helloworld"];// Defaults to the function namehello.usage="[blah=3]";// Defaults to the parametershello.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)functionhello(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"];functiontest(player=Player){// Return some pattern here - idk stone?returnnewBaseBlock(1,0);}

Registering a brush

Create a new .js file in commands/brush

// Some standard imports, half of which aren't used, lolload("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 onevarworldEdit=WorldEdit.getInstance();varprocessor=newBrushProcessor(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)functionspherejs(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 defaultworldEdit.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 spherereturnprocessor.set(session,context,newSphereBrush()).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/

Clone this wiki locally