@@ -26,7 +26,7 @@ set {_z::*} to remove((" hello ", " hey "), "h") # " ello ", " ey "
2626
2727## Creating a new builder
2828
29- First, create a new builder to start building our function . This builder takes the ` SkriptAddon `
29+ First, create a new ` DefaultFunction.Builder ` . This builder takes the ` SkriptAddon `
3030instance of your addon, the name of the function, and the return type of the function. Since our
3131function always returns an array of strings, we can specify the return type as ` String[].class ` .
3232If our function only returned a single string value, the return type would be ` String.class ` .
@@ -39,7 +39,7 @@ DefaultFunction.builder(addon, "remove", String[].class)
3939
4040## Documentation
4141
42- After creating the builder, the documentation should be specified.
42+ The documentation should be specified next .
4343This allows documentation sites to view more information about the function.
4444
4545- The description features a brief description of the function and information about how it works.
@@ -62,12 +62,11 @@ DefaultFunction.builder(addon, "remove", String[].class)
6262
6363## Parameters
6464
65- Next, we should specify what arguments our function can take. To do this, we use the ` parameter ` function.
66- This starts by specifying the parameter name, and then the type it accepts. Like the return type,
65+ Next, we should specify what arguments our function with the ` parameter ` function.
66+ This specifies the parameter name and the type it accepts. Like the return type,
6767using an array indicates that multiple values can be passed to the argument.
6868
69- Additionally, the ` char ` parameter contains a modifier, which changes the behaviour of a parameter.
70- The optional modifier indicates that no value has to be passed to the argument.
69+ Note that the ` char ` parameter contains a modifier which indicates that no value is required to be passed to the argument.
7170
7271``` java
7372DefaultFunction . builder(addon, " remove" , String []. class)
@@ -86,7 +85,7 @@ DefaultFunction.builder(addon, "remove", String[].class)
8685
8786## Implementation
8887
89- To complete our function, we add the implementation. This is the part that will handle the actual function logic .
88+ To complete our function, we add the actual implementation code .
9089The ` build ` method provides you with a ` FunctionArguments ` instance, called ` args ` in our example. This contains
9190all the values for the parameters that are passed when a function is called. These values are associated by the name
9291of the parameter.
@@ -157,4 +156,53 @@ DefaultFunction<String[]> remove = DefaultFunction.builder(addon, "remove", Stri
157156 });
158157
159158Functions . register(remove);
160- ```
159+ ```
160+
161+ ## Other examples
162+
163+ These are some other implementations that are currently being used by Skript.
164+
165+ ``` java
166+ DefaultFunction . builder(skript, " concat" , String . class)
167+ .description(" Joins the provided texts (and other things) into a single text." )
168+ .examples(
169+ " concat(\" hello \" , \" there\" ) # hello there" ,
170+ " concat(\" foo \" , 100, \" bar\" ) # foo 100 bar"
171+ )
172+ .since(" 2.9.0" )
173+ .parameter(" texts" , Object []. class)
174+ .build(args - > {
175+ StringBuilder builder = new StringBuilder ();
176+ Object [] objects = args. get(" texts" );
177+ for (Object object : objects) {
178+ builder. append(Classes . toString(object));
179+ }
180+ return builder. toString();
181+ });
182+ ```
183+
184+ ``` java
185+ Functions . register(DefaultFunction . builder(skript, " location" , Location . class)
186+ .description(
187+ " Creates a location from a world and 3 coordinates, with an optional yaw and pitch." ,
188+ " If for whatever reason the world is not found, it will fallback to the server's main world."
189+ )
190+ .examples(" " "
191+ # TELEPORTING
192+ teleport player to location(1,1,1, world " world" )" " "
193+ )
194+ .since(" 2.2" )
195+ .parameter(" x" , Number . class)
196+ .parameter(" y" , Number . class)
197+ .parameter(" z" , Number . class)
198+ .parameter(" world" , World . class, Modifier . OPTIONAL )
199+ .parameter(" yaw" , Float . class, Modifier . OPTIONAL )
200+ .parameter(" pitch" , Float . class, Modifier . OPTIONAL )
201+ .build(args - > {
202+ World world = args. getOrDefault(" world" , Bukkit . getWorlds(). get(0 ));
203+
204+ return new Location (world,
205+ args. < Number > get(" x" ). doubleValue(), args. < Number > get(" y" ). doubleValue(), args. < Number > get(" z" ). doubleValue(),
206+ args. getOrDefault(" yaw" , 0f ), args. getOrDefault(" pitch" , 0f ));
207+ }));
208+ ```
0 commit comments