docs: update docs for changes

dependabot/gradle/org.projectlombok-lombok-1.18.34
William 5 months ago
parent 331f54407b
commit f9742ccedf
No known key found for this signature in database

@ -56,52 +56,63 @@ Using Maven/something else? There's instructions on how to include Uniform on [t
## Basic use ## Basic use
Uniform lets you create commands either natively per-platform, or cross-platform (by compiling against `uniform-common` in a common module, then implementing `uniform-PLATFORM` in each platform, getting the platform specific Uniform manager instance and registering your commands). Uniform lets you create commands either natively per-platform, or cross-platform (by compiling against `uniform-common` in a common module, then implementing `uniform-PLATFORM` in each platform, getting the platform specific Uniform manager instance and registering your commands).
Check `example-plugin` for a full example of a cross-platform command being registered on Paper.
### Platform-specific commands ### Platform-specific commands
Extend the platform-specific `PlatformCommand` class and add your Brigadier syntax. Extend the platform-specific `PlatformCommand` class and add your Brigadier syntax.
```java ```java
public class ExampleCommand extends PaperCommand { public class ExampleCommand extends PaperCommand {
public ExampleCommand() { public ExampleCommand() {
super("example", "platform-specific"); super("example", "platform-specific");
command.setDefaultExecutor((context) -> {
context.getSource().getBukkitSender().sendMessage("Hello, world!");
});
addSyntax((context) -> { addSyntax((context) -> {
context.getSource().getBukkitSender().sendMessage("Woah!!!!"); context.getSource().getBukkitSender().sendMessage("Woah!!!!");
String arg = context.getArgument("message", String.class); String arg = context.getArgument("message", String.class);
context.getSource().getBukkitSender().sendMessage(MiniMessage.miniMessage().deserialize(arg)); context.getSource().getBukkitSender().sendMessage(MiniMessage.miniMessage().deserialize(arg));
}, stringArg("message")); }, stringArg("message"));
} }
} }
``` ```
### Cross-platform commands ### Cross-platform commands
Target `uniform-common` and implement the `Command` class. Target `uniform-common` and extend the `Command` class. You'll want to use `BaseCommand#getUser` to get a platform-agnostic User from which you can acquire the adventure `Audience` to send messages to.
```java ```java
public class ExampleCrossPlatCommand implements Command { import java.awt.*;
@Override public class ExampleCrossPlatCommand extends Command {
@NotNull public ExampleCrossPlatCommand() {
public String getNamespace() { super("example", "cross-platform");
return "example";
}
@Override
@NotNull
public List<String> getAliases() {
return List.of("cross-plat");
} }
@Override @Override
public <S> void provide(@NotNull BaseCommand<S> command) { public <S> void provide(@NotNull BaseCommand<S> command) {
command.setCondition(source -> true); // What gets executed when no args are passed. For tidiness, feel free to delegate this stuff to methods!
command.setDefaultExecutor((ctx) -> { command.setDefaultExecutor((context) -> {
// Use command.getUser(ctx.getSource()) to get the user // Use command.getUser(context.getSource()) to get the user
final Audience user = command.getUser(ctx.getSource()).getAudience(); final Audience user = command.getUser(context.getSource()).getAudience();
user.sendMessage(Component.text("Hello, world!")); user.sendMessage(Component.text("Hello, world!"));
}); });
}
// Add syntax to the command
command.addSyntax((context) -> {
final Audience user = command.getUser(ctx.getSource()).getAudience();
user.sendMessage(Component.text("Woah!!!!"));
String arg = context.getArgument("message", String.class);
user.sendMessage(MiniMessage.miniMessage().deserialize(arg));
}, stringArg("message"));
// Sub-commands, too
command.addSubCommand("subcommand", (sub) -> {
sub.setDefaultExecutor((context) -> {
final Audience user = sub.getUser(context.getSource()).getAudience();
user.sendMessage(Component.text("Subcommand executed!"));
});
});
}
} }
``` ```

Loading…
Cancel
Save