use of cloud.commandframework.CommandManager in project CrossplatForms by ProjectG-Plugins.
the class IdentifyCommand method register.
@Override
public void register(CommandManager<CommandOrigin> manager, Command.Builder<CommandOrigin> defaultBuilder) {
BedrockHandler bedrockHandler = crossplatForms.getBedrockHandler();
ServerHandler serverHandler = crossplatForms.getServerHandler();
manager.command(defaultBuilder.literal(NAME).permission(sender -> sender.hasPermission(PERMISSION) && sender.isPlayer()).handler(context -> {
CommandOrigin origin = context.getSender();
String message;
if (bedrockHandler.isBedrockPlayer(origin.getUUID().orElseThrow(NoSuchElementException::new))) {
message = "You are a bedrock player";
} else {
message = "You are not a bedrock player";
}
origin.sendMessage(message);
}).build());
manager.command(defaultBuilder.literal(NAME).argument(StringArgument.<CommandOrigin>newBuilder("player").withSuggestionsProvider((context, s) -> serverHandler.getPlayers().stream().map(FormPlayer::getName).collect(Collectors.toList())).build()).permission(PERMISSION_OTHER).handler(context -> {
CommandOrigin origin = context.getSender();
String targetName = context.get("player");
FormPlayer target = serverHandler.getPlayer(targetName);
if (target == null) {
origin.warn("That player doesn't exist");
} else {
String message = targetName + (bedrockHandler.isBedrockPlayer(target.getUuid()) ? " is a Bedrock player" : " is not a Bedrock player");
origin.sendMessage(message);
}
}).build());
}
use of cloud.commandframework.CommandManager in project CrossplatForms by ProjectG-Plugins.
the class InspectCommand method register.
@Override
public void register(CommandManager<CommandOrigin> manager, Command.Builder<CommandOrigin> defaultBuilder) {
ServerHandler serverHandler = crossplatForms.getServerHandler();
BedrockFormRegistry bedrockRegistry = crossplatForms.getInterfacer().getBedrockRegistry();
JavaMenuRegistry javaRegistry = crossplatForms.getInterfacer().getJavaRegistry();
Command.Builder<CommandOrigin> base = defaultBuilder.literal(NAME).permission(PERMISSION);
manager.command(base.literal("form").argument(StringArgument.<CommandOrigin>newBuilder("form").withSuggestionsProvider(((context, s) -> bedrockRegistry.getForms().values().stream().map(Interface::getIdentifier).collect(Collectors.toList())))).handler(context -> {
CommandOrigin origin = context.getSender();
String name = context.get("form");
BedrockForm form = bedrockRegistry.getForm(name);
if (form == null) {
origin.warn("That form doesn't exist!");
} else {
origin.sendMessage("Inspection of form: " + name);
origin.sendMessage(form.toString());
}
}));
manager.command(base.literal("menu").argument(StringArgument.<CommandOrigin>newBuilder("menu").withSuggestionsProvider(((context, s) -> javaRegistry.getMenus().values().stream().map(Interface::getIdentifier).collect(Collectors.toList())))).handler(context -> {
CommandOrigin origin = context.getSender();
String name = context.get("menu");
JavaMenu menu = javaRegistry.getMenu(name);
if (menu == null) {
origin.warn("That menu doesn't exist!");
} else {
origin.sendMessage("Inspection of menu: " + name);
origin.sendMessage(CrossplatForms.PLAIN_SERIALIZER.deserialize(menu.toString()));
}
}));
}
use of cloud.commandframework.CommandManager in project CrossplatForms by ProjectG-Plugins.
the class ListCommand method register.
@Override
public void register(CommandManager<CommandOrigin> manager, Command.Builder<CommandOrigin> defaultBuilder) {
BedrockHandler bedrockHandler = crossplatForms.getBedrockHandler();
BedrockFormRegistry bedrockRegistry = crossplatForms.getInterfacer().getBedrockRegistry();
JavaMenuRegistry javaRegistry = crossplatForms.getInterfacer().getJavaRegistry();
manager.command(defaultBuilder.literal(NAME).permission(PERMISSION).handler(context -> {
List<Interface> interfaces = new ArrayList<>();
CommandOrigin origin = context.getSender();
if (origin.isPlayer() && !origin.hasPermission(OpenCommand.PERMISSION_OTHER)) {
if (bedrockHandler.isBedrockPlayer(origin.getUUID().orElseThrow(NoSuchElementException::new))) {
interfaces.addAll(bedrockRegistry.getForms().values());
javaRegistry.getMenus().values().stream().filter(JavaMenu::isAllowBedrock).forEach(interfaces::add);
} else {
interfaces.addAll(javaRegistry.getMenus().values());
}
} else {
// Origin is console or they have permission to send to others
interfaces.addAll(bedrockRegistry.getForms().values());
interfaces.addAll(javaRegistry.getMenus().values());
}
List<String> names = interfaces.stream().filter(ui -> origin.hasPermission(ui.permission(Interface.Limit.COMMAND))).map(Interface::getIdentifier).distinct().collect(Collectors.toList());
if (names.isEmpty()) {
context.getSender().sendMessage("There are no menus or forms to list.");
} else {
context.getSender().sendMessage("Available forms/menus:");
context.getSender().sendMessage(String.join(", ", names));
}
}).build());
}
use of cloud.commandframework.CommandManager in project CrossplatForms by ProjectG-Plugins.
the class OpenCommand method register.
@Override
public void register(CommandManager<CommandOrigin> manager, Command.Builder<CommandOrigin> defaultBuilder) {
// Base open command
manager.command(defaultBuilder.literal(OPEN_NAME).permission(origin -> origin.hasPermission(PERMISSION) && origin.isPlayer()).argument(StringArgument.<CommandOrigin>newBuilder(ARGUMENT).withSuggestionsProvider((context, s) -> openSuggestions(context)).build()).handler(context -> {
CommandOrigin origin = context.getSender();
UUID uuid = origin.getUUID().orElseThrow(NoSuchElementException::new);
FormPlayer player = Objects.requireNonNull(serverHandler.getPlayer(uuid));
String identifier = context.get(ARGUMENT);
Interface ui = interfacer.getInterface(identifier, bedrockHandler.isBedrockPlayer(uuid));
if (ui == null) {
origin.warn("'" + identifier + "' doesn't exist.");
return;
}
if (origin.hasPermission(ui.permission(Interface.Limit.COMMAND))) {
if (origin.hasPermission(ui.permission(Interface.Limit.USE))) {
ui.send(player);
} else {
origin.warn("You don't have permission to use: " + identifier);
}
} else {
origin.warn("You don't have permission to send: " + identifier);
}
}));
// Send command to make other players open a form or menu
manager.command(defaultBuilder.literal(SEND_NAME).permission(PERMISSION_OTHER).argument(StringArgument.<CommandOrigin>newBuilder("player").withSuggestionsProvider((context, s) -> serverHandler.getPlayers().stream().map(FormPlayer::getName).collect(Collectors.toList())).build()).argument(StringArgument.<CommandOrigin>newBuilder(ARGUMENT).withSuggestionsProvider((context, s) -> sendSuggestions(context)).build()).handler(context -> {
CommandOrigin origin = context.getSender();
String target = context.get("player");
FormPlayer targetPlayer = serverHandler.getPlayer(target);
if (targetPlayer == null) {
origin.warn("The player " + target + " doesn't exist.");
return;
}
String identifier = context.get(ARGUMENT);
Interface ui = this.interfacer.getInterface(identifier, bedrockHandler.isBedrockPlayer(targetPlayer.getUuid()));
if (ui == null) {
origin.warn("'" + identifier + "' doesn't exist.");
return;
}
if (origin.hasPermission(ui.permission(Interface.Limit.COMMAND))) {
if (targetPlayer.hasPermission(ui.permission(Interface.Limit.USE))) {
ui.send(targetPlayer);
} else {
origin.warn(target + " doesn't have permission to use: " + identifier);
}
} else {
origin.warn("You don't have permission to send: " + identifier);
}
}).build());
}
use of cloud.commandframework.CommandManager in project CrossplatForms by ProjectG-Plugins.
the class GiveCommand method register.
@Override
public void register(CommandManager<CommandOrigin> manager, Command.Builder<CommandOrigin> defaultBuilder) {
// Base open command
manager.command(defaultBuilder.literal(NAME).argument(StringArgument.<CommandOrigin>newBuilder(ARGUMENT).withSuggestionsProvider((context, s) -> itemSuggestions(context)).build()).permission(origin -> origin.hasPermission(PERMISSION) && origin.isPlayer()).handler(context -> {
CommandOrigin origin = context.getSender();
FormPlayer player = serverHandler.getPlayer(origin.getUUID().orElseThrow(NoSuchElementException::new));
String identifier = context.get(ARGUMENT);
AccessItem item = itemRegistry.getItems().get(identifier);
if (item == null) {
origin.warn("'" + identifier + "' doesn't exist.");
return;
}
if (origin.hasPermission(item.permission(AccessItem.Limit.COMMAND))) {
if (origin.hasPermission(item.permission(AccessItem.Limit.POSSESS))) {
if (!itemRegistry.giveAccessItem(player, item, false)) {
origin.warn("Your inventory is too full!");
}
} else {
origin.warn("You don't have permission to have: " + identifier);
}
} else {
origin.warn("You don't have permission to give: " + identifier);
}
}));
// Additional command to make other players open a form or menu
manager.command(defaultBuilder.literal(NAME).argument(StringArgument.<CommandOrigin>newBuilder(ARGUMENT).withSuggestionsProvider((context, s) -> itemSuggestions(context)).build()).argument(StringArgument.<CommandOrigin>newBuilder("player").withSuggestionsProvider(((context, s) -> playerSuggestions(context))).build()).permission(PERMISSION_OTHER).handler(context -> {
CommandOrigin origin = context.getSender();
String target = context.get("player");
FormPlayer targetPlayer = serverHandler.getPlayer(target);
if (targetPlayer == null) {
origin.warn("The player " + target + " doesn't exist.");
return;
}
String identifier = context.get(ARGUMENT);
AccessItem item = itemRegistry.getItems().get(identifier);
if (item == null) {
origin.warn("'" + identifier + "' doesn't exist.");
return;
}
if (origin.hasPermission(item.permission(AccessItem.Limit.COMMAND))) {
if (targetPlayer.hasPermission(item.permission(AccessItem.Limit.POSSESS))) {
if (!itemRegistry.giveAccessItem(targetPlayer, item, false)) {
origin.warn(String.format("%s's inventory is too full!", targetPlayer.getName()));
}
} else {
origin.warn(target + " doesn't have permission to have: " + identifier);
}
} else {
origin.warn("You don't have permission to give: " + identifier);
}
}).build());
}
Aggregations