Skip to content

Commit 243a2cb

Browse files
committed
Added example to register_command.
Who doesn't like hugs? The example shows how to use all indices of the options array.
1 parent bd5247e commit 243a2cb

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/main/java/com/laytonsmith/core/functions/Commands.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.laytonsmith.core.constructs.Construct;
1919
import com.laytonsmith.core.constructs.Target;
2020
import com.laytonsmith.core.environments.Environment;
21+
import com.laytonsmith.core.exceptions.ConfigCompileException;
2122
import com.laytonsmith.core.exceptions.ConfigRuntimeException;
2223
import com.laytonsmith.core.functions.Exceptions.ExceptionType;
2324

@@ -276,6 +277,41 @@ public String docs() {
276277
public Version since() {
277278
return CHVersion.V3_3_1;
278279
}
280+
281+
@Override
282+
public ExampleScript[] examples() throws ConfigCompileException {
283+
return new ExampleScript[]{
284+
new ExampleScript("Register the /hug <player> command.",
285+
"register_command('hug', array(\n"
286+
+ "\t'description': 'Spread the love!',\n"
287+
+ "\t'usage': '/hug <player>',\n"
288+
+ "\t'permission': 'perms.hugs',\n"
289+
+ "\t'noPermMsg': 'You do not have permission to give hugs to players (Sorry :o).',\n"
290+
+ "\t'tabcompleter': closure(@alias, @sender, @args) {\n"
291+
+ "\t\t\tif(array_size(@args) == 0) {\n"
292+
+ "\t\t\t\treturn(all_players());\n"
293+
+ "\t\t\t}\n"
294+
+ "\t\t\t@search = @args[array_size(@args) - 1];\n"
295+
+ "\t\t\treturn(array_filter(all_players(), closure(@index, @player) {\n"
296+
+ "\t\t\t\treturn(equals_ic(@search, substr(@player, 0, length(@search))));\n"
297+
+ "\t\t\t}));\n"
298+
+ "\t\t},\n"
299+
+ "\t'aliases':array('hugg', 'hugs'),\n"
300+
+ "\t'executor': closure(@alias, @sender, @args) {\n"
301+
+ "\t\t\tif(array_size(@args) == 1) {\n"
302+
+ "\t\t\t\tif(!ponline(@args[0])) {\n"
303+
+ "\t\t\t\t\tbroadcast(colorize('&4'.@sender.' &6hugs &4'.@args[0]));\n"
304+
+ "\t\t\t\t} else {\n"
305+
+ "\t\t\t\t\ttmsg(@sender, colorize('&cThe given player is not online.'));\n"
306+
+ "\t\t\t\t}\n"
307+
+ "\t\t\t\treturn(true);\n"
308+
+ "\t\t\t}\n"
309+
+ "\t\t\treturn(false);\n"
310+
+ "\t\t}\n"
311+
+ "));",
312+
"Registers the /hug command.")
313+
};
314+
}
279315
}
280316

281317
@api

0 commit comments

Comments
 (0)