Introdution
Have you ever face difficulty of creating even simple spigot command working well? Are you a begginer and you got lost creating a command with more then one argument?
A The library offers easy and elegant approach of creating commands.
Spigot/Paper library dedicated for simplifying commands registration for your plugin!
See the
documentation to see more advanced examples!
Join the support
discord and visit the #programming channel for questions, contributions and ideas. Feel free to make pull requests with missing/new features, fixes, etc
Patterns
Code (Java):
public
final
class Example
extends JavaPlugin
{
@Override
public
void onEnable
(
)
{
CommandsApi commandsApi
= CommandsFramework.
enable
(
this
)
;
commands.
create
(
"/hello <name:Text> <age:number> <job:Text[Miner, Fisherman, Farmer]>"
)
.
onPlayerExecute
(event
->
{
event.
sender
(
).
sendMessage
(
"You called the hello command"
)
;
var name
= event.
getString
(
"name"
)
;
var age
= event.
getNumber
(
"age"
)
;
var job
= event.
getString
(
"job"
)
;
event.
sender
(
).
sendMessage
(
"Name: "
+ name
+
" Age: "
+ age
+
" Job: "
+ job
)
;
}
).
register
(
)
;
}
}
Templates
Is the most streight-forward way of creating command! Just add annotation
@FCommand above a method and that's it!
Code (Java):
public
final
class MyHelloCommand
{
@FCommand
(pattern
=
"/hello <name:Text> <age:Number> <job:[Miner,Fisherman,Farmer]"
)
public
void helloCommand
(CommandSender sender,
String name,
int age,
String job
)
{
event.
sender
(
).
sendMessage
(
"Name: "
+ name
+
" Age: "
+ age
+
" Job: "
+ job
)
;
}
}
public
final
class ExamplePlugin
extends JavaPlugin
{
@Override
public
void onEnable
(
)
{
MyHelloCommand helloCommand
=
new MyHelloCommand
(
)
;
Commands commands
= CommandsFramework.
enable
(
this
)
;
commands.
create
(helloCommand
).
register
(
)
;
}
}
Getting started
1. Install dependency
HTML:
<dependency>
<groupId>io.github.jwdeveloper.spigot.commands
</groupId>
<artifactId>commands-framework-core
</artifactId>
<version>1.0.1
</version>
</dependency>
2
. Create your first command
Code (Java):
public
final
class Example
extends JavaPlugin
{
@Override
public
void onEnable
(
)
{
CommandsApi commandsApi
= CommandsFramework.
enable
(
this
)
;
commands.
create
(
"/hello <name:Text> <age:number> <job:Text[Miner, Fisherman, Farmer]>"
)
.
onPlayerExecute
(event
->
{
event.
sender
(
).
sendMessage
(
"You called the hello command"
)
;
var name
= event.
getString
(
"name"
)
;
var age
= event.
getNumber
(
"age"
)
;
var job
= event.
getString
(
"job"
)
;
event.
sender
(
).
sendMessage
(
"Name: "
+ name
+
" Age: "
+ age
+
" Job: "
+ job
)
;
}
).
register
(
)
;
}
}
3. Use a command in the game
Contributing
Library documentation for contributors
Your improvements are welcome! Feel free to open an issue or pull request.