use of dev.projectg.crossplatforms.handler.BedrockHandler in project CrossplatForms by ProjectG-Plugins.
the class ProxyCommandManager method load.
private void load() {
if (configManager.getConfig(GeneralConfig.class).isEmpty()) {
return;
}
GeneralConfig config = configManager.getConfig(GeneralConfig.class).get();
commandManager.setSetting(CommandManager.ManagerSettings.ALLOW_UNSAFE_REGISTRATION, config.isUnsafeCommandRegistration());
registeredCommands.clear();
for (ProxyCommand command : config.getCommands().values()) {
String name = command.getName();
if (command.getPermission() == null || command.getPermission().isBlank()) {
command.setPermission(Constants.ID + ".shortcut." + name);
}
CommandType type = command.getMethod();
if (type == CommandType.REGISTER) {
if (commandManager.getCommandTree().getNamedNode(name) == null) {
// any references to the command are done through the map so that it can be updated after a reload
if (commandManager.isCommandRegistrationAllowed()) {
Logger.getLogger().debug("Registering shortcut command: " + command.getName());
commandManager.command(commandManager.commandBuilder(name).permission((origin) -> {
ProxyCommand target = registeredCommands.get(name);
if (target == null) {
// no longer present in the config
return false;
} else {
return origin.isPlayer() && origin.hasPermission(target.getPermission());
}
}).handler((context) -> {
FormPlayer player = Objects.requireNonNull(serverHandler.getPlayer(context.getSender().getUUID().orElseThrow()));
registeredCommands.get(name).run(player, interfaceManager, bedrockHandler);
}));
} else {
Logger.getLogger().warn("Unable to register shortcut command '" + name + "' because registration is no longer possible. Restart the server for changes to apply.");
}
}
// store the command
registeredCommands.put(name, command);
} else if (type == CommandType.INTERCEPT_CANCEL || type == CommandType.INTERCEPT_PASS) {
serverHandler.registerProxyCommand(command);
} else {
Logger.getLogger().severe("Unhandled CommandType enum constant: " + type);
}
}
}
use of dev.projectg.crossplatforms.handler.BedrockHandler 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 dev.projectg.crossplatforms.handler.BedrockHandler 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 dev.projectg.crossplatforms.handler.BedrockHandler in project CrossplatForms by ProjectG-Plugins.
the class OpenCommand method sendSuggestions.
private List<String> sendSuggestions(CommandContext<CommandOrigin> context) {
CommandOrigin origin = context.getSender();
if (origin.isBedrockPlayer(bedrockHandler)) {
return Collections.emptyList();
}
String recipient = context.get("player");
FormPlayer target = serverHandler.getPlayer(recipient);
if (target == null) {
return Collections.emptyList();
}
return interfacer.getInterfaces(bedrockHandler.isBedrockPlayer(target.getUuid())).stream().filter(ui -> origin.hasPermission(ui.permission(Interface.Limit.COMMAND)) && target.hasPermission(ui.permission(Interface.Limit.USE))).map(Interface::getIdentifier).distinct().collect(Collectors.toList());
}
use of dev.projectg.crossplatforms.handler.BedrockHandler in project CrossplatForms by ProjectG-Plugins.
the class BungeeCordHandler method onPreProcessCommand.
@EventHandler
public void onPreProcessCommand(ChatEvent event) {
Connection connection = event.getSender();
if (event.isCancelled() || !(connection instanceof ProxiedPlayer) || !event.isCommand() || !event.isProxyCommand()) {
return;
}
String input = event.getMessage().substring(1);
Logger.get().debug("preprocess command: [" + event.getMessage() + "] -> [" + input + "]");
// attempt to find an exact match
InterceptCommand command = findCommand(input);
if (command != null) {
ProxiedPlayer player = (ProxiedPlayer) connection;
BedrockHandler bedrockHandler = CrossplatForms.getInstance().getBedrockHandler();
if (command.getPlatform().matches(player.getUniqueId(), bedrockHandler)) {
String permission = command.getPermission();
if (permission == null || player.hasPermission(permission)) {
command.run(new BungeeCordPlayer(player));
if (command.getMethod() == CommandType.INTERCEPT_CANCEL) {
event.setCancelled(true);
}
}
}
}
}
Aggregations