use of com.velocitypowered.api.command.CommandSource in project Plan by plan-player-analytics.
the class VelocityCommand method execute.
@Override
public void execute(final Invocation invocation) {
CommandSource source = invocation.source();
String[] args = invocation.arguments();
runnableFactory.create(() -> {
try {
command.getExecutor().accept(getSender(source), new Arguments(args));
} catch (Exception e) {
errorLogger.error(e, ErrorContext.builder().related(source.getClass()).related(Arrays.toString(args)).build());
}
}).runTaskAsynchronously();
}
use of com.velocitypowered.api.command.CommandSource in project CrossplatForms by ProjectG-Plugins.
the class VelocityHandler method onCommandExecute.
@Subscribe
public void onCommandExecute(CommandExecuteEvent event) {
CommandSource source = event.getCommandSource();
if (!event.getResult().isAllowed() || !(source instanceof Player)) {
return;
}
String input = event.getCommand();
Logger.get().debug("preprocess command: [" + event.getCommand() + "] -> [" + input + "]");
InterceptCommand command = findCommand(input);
if (command != null) {
Player player = (Player) source;
CommandType type = command.getMethod();
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 VelocityPlayer(player));
if (type == CommandType.INTERCEPT_CANCEL) {
// todo: if this sends a message about denial we might have to replace the common with a dummy
event.setResult(CommandExecuteEvent.CommandResult.denied());
}
}
}
}
}
use of com.velocitypowered.api.command.CommandSource in project commands by aikar.
the class ACFVelocityUtil method findPlayerSmart.
public static Player findPlayerSmart(ProxyServer server, CommandIssuer issuer, String search) {
CommandSource requester = issuer.getIssuer();
String name = ACFUtil.replace(search, ":confirm", "");
List<Player> matches = new ArrayList<>(matchPlayer(server, name));
if (matches.size() > 1) {
String allMatches = matches.stream().map(Player::getUsername).collect(Collectors.joining(", "));
issuer.sendError(MinecraftMessageKeys.MULTIPLE_PLAYERS_MATCH, "{search}", name, "{all}", allMatches);
return null;
}
if (matches.isEmpty()) {
if (!isValidName(name)) {
issuer.sendError(MinecraftMessageKeys.IS_NOT_A_VALID_NAME, "{name}", name);
return null;
}
issuer.sendError(MinecraftMessageKeys.NO_PLAYER_FOUND_SERVER, "{search}", name);
return null;
}
return matches.get(0);
}
use of com.velocitypowered.api.command.CommandSource in project InteractiveChat by LOOHP.
the class CommandsVelocity method createBrigadierCommand.
public static void createBrigadierCommand() {
LiteralCommandNode<CommandSource> backendinfoNode = LiteralArgumentBuilder.<CommandSource>literal("backendinfo").requires(sender -> {
return sender.hasPermission("interactivechat.backendinfo");
}).executes(command -> {
try {
CommandSource sender = command.getSource();
if (InteractiveChatVelocity.hasPermission(sender, "interactivechat.backendinfo").get()) {
InteractiveChatVelocity.sendMessage(sender, Component.text(TextColor.AQUA + "Proxy -> InteractiveChat: " + InteractiveChatVelocity.plugin.getDescription().getVersion() + " (PM Protocol: " + Registry.PLUGIN_MESSAGING_PROTOCOL_VERSION + ")"));
InteractiveChatVelocity.sendMessage(sender, Component.text(TextColor.AQUA + "Expected latency: " + InteractiveChatVelocity.delay + " ms"));
InteractiveChatVelocity.sendMessage(sender, Component.text(TextColor.AQUA + "Backends under this proxy:"));
InteractiveChatVelocity.plugin.getServer().getAllServers().stream().sorted(Comparator.comparing(each -> each.getServerInfo().getName())).forEach(server -> {
String name = server.getServerInfo().getName();
BackendInteractiveChatData data = InteractiveChatVelocity.serverInteractiveChatInfo.get(name);
if (data == null) {
InteractiveChatVelocity.sendMessage(sender, Component.text(TextColor.RED + name + " -> Attempting to retrieve data from backend..."));
} else {
String minecraftVersion = data.getExactMinecraftVersion();
if (data.isOnline()) {
if (!data.hasInteractiveChat()) {
InteractiveChatVelocity.sendMessage(sender, Component.text(TextColor.YELLOW + name + " -> InteractiveChat: NOT INSTALLED (PM Protocol: -1) | Minecraft: " + minecraftVersion + " | Ping: " + (data.getPing() < 0 ? "N/A" : (data.getPing() + " ms"))));
} else {
InteractiveChatVelocity.sendMessage(sender, Component.text(TextColor.GREEN + name + " -> InteractiveChat: " + data.getVersion() + " (PM Protocol: " + data.getProtocolVersion() + ") | Minecraft: " + minecraftVersion + " | Ping: " + (data.getPing() < 0 ? "N/A" : (data.getPing() + " ms"))));
}
} else {
InteractiveChatVelocity.sendMessage(sender, Component.text(TextColor.RED + name + " -> Status: OFFLINE"));
}
}
});
}
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
return 1;
}).build();
LiteralCommandNode<CommandSource> rootNode = LiteralArgumentBuilder.<CommandSource>literal("interactivechatproxy").then(backendinfoNode).executes(command -> {
defaultMessage(command.getSource());
return 1;
}).build();
LiteralCommandNode<CommandSource> aliasNode1 = LiteralArgumentBuilder.<CommandSource>literal("icp").then(backendinfoNode).executes(command -> {
defaultMessage(command.getSource());
return 1;
}).build();
BrigadierCommand command = new BrigadierCommand(rootNode);
BrigadierCommand alias1 = new BrigadierCommand(aliasNode1);
CommandManager commandManager = InteractiveChatVelocity.plugin.getServer().getCommandManager();
commandManager.register(command);
commandManager.register(alias1);
}
use of com.velocitypowered.api.command.CommandSource in project Plan by plan-player-analytics.
the class VelocityCommand method suggest.
@Override
public List<String> suggest(final Invocation invocation) {
CommandSource source = invocation.source();
String[] currentArgs = invocation.arguments();
try {
return command.getArgumentResolver().apply(getSender(source), new Arguments(currentArgs));
} catch (Exception e) {
errorLogger.error(e, ErrorContext.builder().related(source.getClass()).related("tab completion").related(Arrays.toString(currentArgs)).build());
return Collections.emptyList();
}
}
Aggregations