use of com.velocitypowered.api.command.CommandSource in project ConnectorPlugin by Phoenix616.
the class TeleportCommand method run.
@Override
public boolean run(CommandSource sender, String alias, String[] args) {
if (args.length < 2) {
return false;
}
Player player = plugin.getProxy().getPlayer(args[0]).orElse(null);
if (player == null) {
sender.sendMessage(Component.text("No player with the name " + args[0] + " found!").color(NamedTextColor.RED));
return true;
}
RegisteredServer server = plugin.getProxy().getServer(args[1]).orElse(null);
if (server == null) {
sender.sendMessage(Component.text("No server with the name " + args[1] + " found!").color(NamedTextColor.RED));
return true;
}
if (args.length == 2) {
player.createConnectionRequest(server).connect().thenAccept(result -> {
if (result.isSuccessful()) {
sender.sendMessage(Component.text("Connected player " + player.getUsername() + " to server " + server.getServerInfo().getName()).color(NamedTextColor.GREEN));
} else {
sender.sendMessage(Component.text("Error while connecting player " + player.getUsername() + " to server " + server.getServerInfo().getName() + ": " + result.getReasonComponent().orElse(Component.empty())).color(NamedTextColor.RED));
}
});
return true;
}
if (args.length == 3) {
plugin.getBridge().teleport(player.getUsername(), server.getServerInfo().getName(), args[2], m -> sender.sendMessage(LegacyComponentSerializer.legacySection().deserialize(m))).thenAccept(success -> {
if (!success) {
sender.sendMessage(Component.text("Error while teleporting...").color(NamedTextColor.RED));
}
});
return true;
}
if (args.length < 6) {
return false;
}
try {
LocationInfo location = new LocationInfo(server.getServerInfo().getName(), args[2], Double.parseDouble(args[3]), Double.parseDouble(args[4]), Double.parseDouble(args[5]), args.length > 6 ? Float.parseFloat(args[6]) : 0, args.length > 7 ? Float.parseFloat(args[7]) : 0);
plugin.getBridge().teleport(player.getUsername(), location, m -> sender.sendMessage(LegacyComponentSerializer.legacySection().deserialize(m))).thenAccept(success -> {
if (!success) {
sender.sendMessage(Component.text("Error while teleporting...").color(NamedTextColor.RED));
}
});
return true;
} catch (IllegalArgumentException e) {
sender.sendMessage(Component.text("Error while parsing input! " + e.getMessage()).color(NamedTextColor.RED));
return false;
}
}
use of com.velocitypowered.api.command.CommandSource in project GrandModeration by Ciph3r-Zer0.
the class StaffList method execute.
@Override
public void execute(Invocation invocation) {
if (!(invocation.source().hasPermission(Perms.STAFF_LIST))) {
Utils.sendMessage(invocation.source(), Messages.NOT_PERMISSION);
return;
}
CommandSource source = invocation.source();
String[] args = invocation.arguments();
if (args.length == 0) {
List<Player> staffs = Utils.getPlayersByUUID(Manager.staffList);
Utils.sendMessage(source, Config.STAFF_LIST_FIRST_LINE_FORMAT);
for (Player p : staffs) {
if (p.hasPermission(Perms.STAFF_EXEMPT))
continue;
Utils.sendMessage(source, Config.STAFF_LIST_LIST_FORMAT.replace("{server}", p.getCurrentServer().get().getServerInfo().getName()).replace("{player}", p.getUsername()));
}
}
}
use of com.velocitypowered.api.command.CommandSource in project MiniMOTD by jpenilla.
the class MiniMOTDPlugin method registerCommand.
private void registerCommand() {
final class WrappingExecutor implements Command<CommandSource> {
private final CommandHandler.Executor handler;
WrappingExecutor(final CommandHandler.@NonNull Executor handler) {
this.handler = handler;
}
@Override
public int run(@NonNull final CommandContext<CommandSource> context) {
this.handler.execute(context.getSource());
return Command.SINGLE_SUCCESS;
}
}
final CommandHandler handler = new CommandHandler(this.miniMOTD);
this.commandManager.register(this.commandManager.metaBuilder("minimotd").build(), new BrigadierCommand(LiteralArgumentBuilder.<CommandSource>literal("minimotd").requires(source -> source.hasPermission("minimotd.admin")).then(LiteralArgumentBuilder.<CommandSource>literal("help").executes(new WrappingExecutor(handler::help))).then(LiteralArgumentBuilder.<CommandSource>literal("about").executes(new WrappingExecutor(handler::about))).then(LiteralArgumentBuilder.<CommandSource>literal("reload").executes(new WrappingExecutor(handler::reload)))));
}
use of com.velocitypowered.api.command.CommandSource in project Fallback-Server by sasi2006166.
the class HubCommand method execute.
@Override
public void execute(Invocation invocation) {
CommandSource commandSource = invocation.source();
if (!(commandSource instanceof Player)) {
commandSource.sendMessage(VelocityMessages.colorize(VelocityMessages.NOT_PLAYER.getString()));
return;
}
Player player = (Player) invocation;
}
use of com.velocitypowered.api.command.CommandSource in project LimboAuth-SocialAddon by Elytrium.
the class ValidateLinkCommand method execute.
@Override
public void execute(Invocation invocation) {
CommandSource source = invocation.source();
String[] args = invocation.arguments();
if (source instanceof Player) {
Player player = (Player) source;
if (args.length == 0) {
source.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(Settings.IMP.MAIN.STRINGS.LINK_CMD_USAGE.replace("{NICKNAME}", player.getUsername())));
} else {
try {
String username = player.getUsername().toLowerCase(Locale.ROOT);
int code = Integer.parseInt(args[0]);
if (this.addon.hasCode(username)) {
int validCode = this.addon.getCode(username);
if (code == validCode) {
Addon.TempAccount tempAccount = this.addon.getTempAccount(username);
this.socialDao.createIfNotExists(new SocialPlayer(username));
UpdateBuilder<SocialPlayer, String> updateBuilder = this.socialDao.updateBuilder();
updateBuilder.where().eq(SocialPlayer.LOWERCASE_NICKNAME_FIELD, username);
updateBuilder.updateColumnValue(tempAccount.getDbField(), tempAccount.getId());
updateBuilder.update();
Settings.IMP.MAIN.AFTER_LINKAGE_COMMANDS.forEach(command -> this.addon.getServer().getCommandManager().executeAsync(p -> Tristate.TRUE, command.replace("{NICKNAME}", player.getUsername()).replace("{UUID}", player.getUniqueId().toString())));
this.addon.getSocialManager().registerHook(tempAccount.getDbField(), tempAccount.getId());
this.addon.getSocialManager().broadcastMessage(tempAccount.getDbField(), tempAccount.getId(), Settings.IMP.MAIN.STRINGS.LINK_SUCCESS, this.addon.getKeyboard());
} else {
source.sendMessage(LegacyComponentSerializer.legacyAmpersand().deserialize(Settings.IMP.MAIN.STRINGS.LINK_WRONG_CODE.replace("{NICKNAME}", player.getUsername())));
}
this.addon.removeCode(username);
} else {
this.sendUsage(player);
}
} catch (NumberFormatException ignored) {
this.sendUsage(player);
} catch (SQLException ex) {
ex.printStackTrace();
}
}
}
}
Aggregations