use of org.spongepowered.plugin.builtin.jvm.Plugin in project SpongeCommon by SpongePowered.
the class PackTest method onRegisterCommand.
@Listener
public void onRegisterCommand(final RegisterCommandEvent<Command.Parameterized> event) {
final Parameter.Value<PluginContainer> pluginContainerParameter = Parameter.plugin().key("plugin").build();
final Parameter.Value<String> nameParameter = Parameter.string().key("name").build();
final Parameter.Value<String> pathParameter = Parameter.string().key("path").build();
event.register(this.plugin, Command.builder().addParameter(Parameter.firstOf(pluginContainerParameter, nameParameter)).addParameter(pathParameter).executor(exec -> {
final Pack pack;
final String path = exec.requireOne(pathParameter);
if (exec.hasAny(pluginContainerParameter)) {
pack = Sponge.server().packRepository().pack(exec.requireOne(pluginContainerParameter));
} else {
final String packName = exec.requireOne(nameParameter);
pack = Sponge.server().packRepository().pack(packName).orElse(null);
if (pack == null) {
return CommandResult.error(Component.text("Pack " + packName + " does not exist."));
}
}
try (final Resource resource = pack.contents().requireResource(PackType.server(), ResourcePath.of(pack.id(), path))) {
final BufferedReader reader = new BufferedReader(new InputStreamReader(resource.inputStream()));
reader.lines().map(x -> Component.text(x.substring(0, Math.min(100, x.length())))).forEach(x -> exec.sendMessage(Identity.nil(), x));
} catch (final Exception e) {
e.printStackTrace();
return CommandResult.error(Component.text("Could not locate: " + e.getMessage()));
}
return CommandResult.success();
}).build(), "packtest");
}
Aggregations