-
Notifications
You must be signed in to change notification settings - Fork 0
Getting Started
Shard has to be installed manually to the local repository as it's not
deployed to any public repository.
Open the command line and clone the git repository:
$ git clone https://github.com/AdityaSF/Shard.git
$ cd ShardFinally, build Shard from sources with maven:
$ mvn clean installAfter this is done, Shard should be locally installed.
First of all, add Shard as a dependency:
<project>
...
<dependencies>
<dependency>
<groupId>adiitya.spigot</groupId>
<artifactId>shard</artifactId>
<version>@VERSION@</version>
<scope>compile</scope>
</dependency>
</dependencies>
...
</project>The artifact will be retrieved from your local repository. If maven can't find the artifact, try installing it again.
Shard isn't a standalone plugin like most Spigot libraries, so you must shade it into your plugin:
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
</project>Maven Shade can be configure to minimize your jar size and change the name. For more about Maven Shade, see the documentation.
Shards implementation of a simple vanilla style command is SingleCommand.
A SingleCommand can't have children and passes all arguments to the
execute method. The following command will print whether the sender
requested a page, which page is being served, and it will tab complete
pages 0 to 2:
import adiitya.shard.SingleCommand;
import adiitya.shard.completion.TabCompleter;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.List;
public class ExampleCommand extends SimpleCommand {
public ExampleCommand(JavaPlugin plugin) {
super(plugin, "example", "[page]");
}
@Override
public void execute(CommandSender sender, List<String> args) {
boolean pageRequested = !args.isEmpty();
int page = pageRequested ? Integer.parseInt(args.get(0)) : 0;
sender.sendMessage(String.format("You %s request a specific page", pageRequested ? "did" : "didn't"));
sender.sendMessage("Showing page " + page);
}
@Override
public List<String> tabComplete(CommandSender sender, List<String> args) {
return new TabCompleter()
.add(0, new TabCompletion("0", test -> "0".startsWith(test)))
.add(0, new TabCompletion("1", test -> "1".startsWith(test)))
.add(0, new TabCompletion("2", test -> "2".startsWith(test)))
.get(args);
}
}This command has no aliases as it doesn't override the getAliases method,
and its usage will be /example [page].
CommandRegister is a class that eases command registration. Shard commands
can be registered using the vanilla method of getting a PluginCommand and
settings it's executor and tab completer. Doing this manually would require
you to go through each alias and register it. The CommandRegister class
does this for you so you don't need to write extra code for registering.
public class ExamplePlugin extends JavaPlugin {
@Override
public void onEnable() {
CommandRegister register = new CommandRegister(this);
register.registerCommand(new ExampleCommand(this));
}
}