Java Code Examples for com.velocitypowered.api.command.CommandSource#sendMessage()

The following examples show how to use com.velocitypowered.api.command.CommandSource#sendMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GlistCommand.java    From Velocity with MIT License 6 votes vote down vote up
private void sendServerPlayers(CommandSource target, RegisteredServer server, boolean fromAll) {
  List<Player> onServer = ImmutableList.copyOf(server.getPlayersConnected());
  if (onServer.isEmpty() && fromAll) {
    return;
  }

  TextComponent.Builder builder = TextComponent.builder()
      .append(TextComponent.of("[" + server.getServerInfo().getName() + "] ",
          TextColor.DARK_AQUA))
      .append("(" + onServer.size() + ")", TextColor.GRAY)
      .append(": ")
      .resetStyle();

  for (int i = 0; i < onServer.size(); i++) {
    Player player = onServer.get(i);
    builder.append(player.getUsername());

    if (i + 1 < onServer.size()) {
      builder.append(", ");
    }
  }

  target.sendMessage(builder.build());
}
 
Example 2
Source File: SrCommand.java    From SkinsRestorerX with GNU General Public License v3.0 6 votes vote down vote up
@Subcommand("props") @CommandPermission("%srProps")
@CommandCompletion("@players")
@Description("%helpSrProps")
public void onProps(CommandSource source, OnlinePlayer target) {
    GameProfile.Property prop = target.getPlayer().getGameProfileProperties().get(0);

    if (prop == null) {
        source.sendMessage(plugin.deserialize(Locale.NO_SKIN_DATA));
        return;
    }

    source.sendMessage(plugin.deserialize("\n§aName: §8" + prop.getName()));
    source.sendMessage(plugin.deserialize("\n§aValue : §8" + prop.getValue()));
    source.sendMessage(plugin.deserialize("\n§aSignature : §8" + prop.getSignature()));

    byte[] decoded = Base64.getDecoder().decode(prop.getValue());
    source.sendMessage(plugin.deserialize("\n§aValue Decoded: §e" + Arrays.toString(decoded)));

    source.sendMessage(plugin.deserialize("\n§e" + Arrays.toString(decoded)));

    source.sendMessage(plugin.deserialize("§cMore info in console!"));
}
 
Example 3
Source File: VelocityCommand.java    From Velocity with MIT License 6 votes vote down vote up
@Override
public void execute(CommandSource source, String @NonNull [] args) {
  try {
    if (server.reloadConfiguration()) {
      source.sendMessage(TextComponent.of("Configuration reloaded.", TextColor.GREEN));
    } else {
      source.sendMessage(TextComponent.of(
          "Unable to reload your configuration. Check the console for more details.",
          TextColor.RED));
    }
  } catch (Exception e) {
    logger.error("Unable to reload configuration", e);
    source.sendMessage(TextComponent.of(
        "Unable to reload your configuration. Check the console for more details.",
        TextColor.RED));
  }
}
 
Example 4
Source File: VelocityCommand.java    From Velocity with MIT License 6 votes vote down vote up
@Override
public void execute(CommandSource source, String @NonNull [] args) {
  if (args.length != 0) {
    source.sendMessage(TextComponent.of("/velocity plugins", TextColor.RED));
    return;
  }

  List<PluginContainer> plugins = ImmutableList.copyOf(server.getPluginManager().getPlugins());
  int pluginCount = plugins.size();

  if (pluginCount == 0) {
    source.sendMessage(TextComponent.of("No plugins installed.", TextColor.YELLOW));
    return;
  }

  TextComponent.Builder output = TextComponent.builder("Plugins: ")
      .color(TextColor.YELLOW);
  for (int i = 0; i < pluginCount; i++) {
    PluginContainer plugin = plugins.get(i);
    output.append(componentForPlugin(plugin.getDescription()));
    if (i + 1 < pluginCount) {
      output.append(TextComponent.of(", "));
    }
  }

  source.sendMessage(output.build());
}
 
Example 5
Source File: SkinCommand.java    From SkinsRestorerX with GNU General Public License v3.0 6 votes vote down vote up
@Subcommand("set") @CommandPermission("%skinSetOther")
@CommandCompletion("@players")
@Description("%helpSkinSetOther")
@Syntax("<target> <skin/url>")
public void onSkinSetOther(CommandSource source, OnlinePlayer target, String skin) {
    if (Config.PER_SKIN_PERMISSIONS && Config.USE_NEW_PERMISSIONS) {
        if (!source.hasPermission("skinsrestorer.skin." + skin)) {
            if (!getSenderName(source).equals(target.getPlayer().getUsername()) || (!source.hasPermission("skinsrestorer.ownskin") && !skin.equalsIgnoreCase(getSenderName(source)))) {
                source.sendMessage(LegacyComponentSerializer.legacy().deserialize(Locale.PLAYER_HAS_NO_PERMISSION_SKIN));
                return;
            }
        }
    }

    plugin.getService().execute(() -> {
        if (this.setSkin(source, target.getPlayer(), skin)) {
            if (!getSenderName(source).equals(target.getPlayer().getUsername())) {
                source.sendMessage(LegacyComponentSerializer.legacy().deserialize(Locale.ADMIN_SET_SKIN.replace("%player", target.getPlayer().getUsername())));
            }
        }
    });
}
 
Example 6
Source File: TestVoteCmd.java    From NuVotifier with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void execute(CommandSource sender, @NonNull String[] args) {
    Vote v;
    try {
        v = ArgsToVote.parse(args);
    } catch (IllegalArgumentException e) {
        sender.sendMessage(TextComponent.of("Error while parsing arguments to create test vote: " + e.getMessage()).color(TextColor.DARK_RED));
        sender.sendMessage(TextComponent.of("Usage hint: /testvote [username] [serviceName=?] [username=?] [address=?] [localTimestamp=?] [timestamp=?]").color(TextColor.GRAY));
        return;
    }

    plugin.onVoteReceived(v, VotifierSession.ProtocolVersion.TEST, "localhost.test");
    sender.sendMessage(TextComponent.of("Test vote executed: " + v.toString()).color(TextColor.GREEN));
}
 
Example 7
Source File: GeyserVelocityCommandExecutor.java    From Geyser with MIT License 5 votes vote down vote up
@Override
public void execute(CommandSource source, String[] args) {
    if (args.length > 0) {
        if (getCommand(args[0]) != null) {
            if (!source.hasPermission(getCommand(args[0]).getPermission())) {
                source.sendMessage(TextComponent.of(ChatColor.RED + "You do not have permission to execute this command!"));
                return;
            }
            getCommand(args[0]).execute(new VelocityCommandSender(source), args);
        }
    } else {
        getCommand("help").execute(new VelocityCommandSender(source), args);
    }
}
 
Example 8
Source File: NVReloadCmd.java    From NuVotifier with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void execute(CommandSource sender, @NonNull String[] args) {
    sender.sendMessage(TextComponent.of("Reloading NuVotifier...").color(TextColor.GRAY));
    if (plugin.reload()) {
        sender.sendMessage(TextComponent.of("NuVotifier has been reloaded!").color(TextColor.DARK_GREEN));
    } else {
        sender.sendMessage(TextComponent.of("Looks like there was a problem reloading NuVotifier, check the console!").color(TextColor.DARK_RED));
    }
}
 
Example 9
Source File: SrCommand.java    From SkinsRestorerX with GNU General Public License v3.0 5 votes vote down vote up
@Subcommand("drop") @CommandPermission("%srDrop")
@CommandCompletion("@players")
@Description("%helpSrDrop")
public void onDrop(CommandSource source, OnlinePlayer target) {
    String player = target.getPlayer().getUsername();
    plugin.getSkinStorage().removeSkinData(player);
    source.sendMessage(plugin.deserialize(Locale.SKIN_DATA_DROPPED.replace("%player", player)));
}
 
Example 10
Source File: SrCommand.java    From SkinsRestorerX with GNU General Public License v3.0 5 votes vote down vote up
@Subcommand("status") @CommandPermission("%srStatus")
@Description("%helpSrStatus")
public void onStatus(CommandSource source) {
    source.sendMessage(plugin.deserialize("§3----------------------------------------------"));
    source.sendMessage(plugin.deserialize("§7Checking needed services for SR to work properly..."));

    plugin.getService().execute(() -> {
        ServiceChecker checker = new ServiceChecker();
        checker.setMojangAPI(plugin.getMojangAPI());
        checker.checkServices();

        ServiceChecker.ServiceCheckResponse response = checker.getResponse();
        List<String> results = response.getResults();

        for (String result : results) {
            source.sendMessage(plugin.deserialize(result));
        }
        source.sendMessage(plugin.deserialize("§7Working UUID API count: §6" + response.getWorkingUUID()));
        source.sendMessage(plugin.deserialize("§7Working Profile API count: §6" + response.getWorkingProfile()));
        if (response.getWorkingUUID() >= 1 && response.getWorkingProfile() >= 1)
            source.sendMessage(plugin.deserialize("§aThe plugin currently is in a working state."));
        else
            source.sendMessage(plugin.deserialize("§cPlugin currently can't fetch new skins. You might check out our discord at https://discord.me/servers/skinsrestorer"));
        source.sendMessage(plugin.deserialize("§3----------------------------------------------"));
        source.sendMessage(plugin.deserialize("§7SkinsRestorer §6v" + plugin.getVersion()));
        source.sendMessage(plugin.deserialize("§7Server: §6" + plugin.getProxy().getVersion()));
        source.sendMessage(plugin.deserialize("§7BungeeMode: §6Velocity-Plugin"));
        source.sendMessage(plugin.deserialize("§7Finished checking services."));
        source.sendMessage(plugin.deserialize("§3----------------------------------------------"));
    });
}
 
Example 11
Source File: SrCommand.java    From SkinsRestorerX with GNU General Public License v3.0 5 votes vote down vote up
@Subcommand("reload") @CommandPermission("%srReload")
@Description("%helpSrReload")
public void onReload(CommandSource source) {
    Locale.load(plugin.getConfigPath());
    Config.load(plugin.getConfigPath(), plugin.getClass().getClassLoader().getResourceAsStream("config.yml"));
    source.sendMessage(plugin.deserialize(Locale.RELOAD));
}
 
Example 12
Source File: SkinCommand.java    From SkinsRestorerX with GNU General Public License v3.0 5 votes vote down vote up
private void sendHelp(CommandSource commandSource) {
    if (!Locale.SR_LINE.isEmpty())
        commandSource.sendMessage(plugin.deserialize(Locale.SR_LINE));
    commandSource.sendMessage(plugin.deserialize(Locale.HELP_PLAYER.replace("%ver%", plugin.getVersion())));
    if (!Locale.SR_LINE.isEmpty())
        commandSource.sendMessage(plugin.deserialize(Locale.SR_LINE));
}
 
Example 13
Source File: VelocityCommand.java    From Velocity with MIT License 5 votes vote down vote up
@Override
public void execute(CommandSource source, String @NonNull [] args) {
  if (args.length != 0) {
    source.sendMessage(TextComponent.of("/velocity version", TextColor.RED));
    return;
  }

  ProxyVersion version = server.getVersion();

  TextComponent velocity = TextComponent.builder(version.getName() + " ")
      .decoration(TextDecoration.BOLD, true)
      .color(TextColor.DARK_AQUA)
      .append(TextComponent.of(version.getVersion()).decoration(TextDecoration.BOLD, false))
      .build();
  TextComponent copyright = TextComponent
      .of("Copyright 2018-2020 " + version.getVendor() + ". " + version.getName()
          + " is freely licensed under the terms of the MIT License.");
  source.sendMessage(velocity);
  source.sendMessage(copyright);

  if (version.getName().equals("Velocity")) {
    TextComponent velocityWebsite = TextComponent.builder()
        .content("Visit the ")
        .append(TextComponent.builder("Velocity website")
            .color(TextColor.GREEN)
            .clickEvent(
                ClickEvent.openUrl("https://www.velocitypowered.com"))
            .build())
        .append(TextComponent.of(" or the "))
        .append(TextComponent.builder("Velocity GitHub")
            .color(TextColor.GREEN)
            .clickEvent(ClickEvent.openUrl(
                "https://github.com/VelocityPowered/Velocity"))
            .build())
        .build();
    source.sendMessage(velocityWebsite);
  }
}
 
Example 14
Source File: VelocityCommand.java    From Velocity with MIT License 5 votes vote down vote up
private void usage(CommandSource source) {
  String availableCommands = subcommands.entrySet().stream()
      .filter(e -> e.getValue().hasPermission(source, new String[0]))
      .map(Map.Entry::getKey)
      .collect(Collectors.joining("|"));
  String commandText = "/velocity <" + availableCommands + ">";
  source.sendMessage(TextComponent.of(commandText, TextColor.RED));
}
 
Example 15
Source File: GlistCommand.java    From Velocity with MIT License 5 votes vote down vote up
@Override
public void execute(CommandSource source, String @NonNull [] args) {
  if (args.length == 0) {
    sendTotalProxyCount(source);
    source.sendMessage(
        TextComponent.builder("To view all players on servers, use ", TextColor.YELLOW)
            .append("/glist all", TextColor.DARK_AQUA)
            .append(".", TextColor.YELLOW)
            .build());
  } else if (args.length == 1) {
    String arg = args[0];
    if (arg.equalsIgnoreCase("all")) {
      for (RegisteredServer server : server.getAllServers()) {
        sendServerPlayers(source, server, true);
      }
      sendTotalProxyCount(source);
    } else {
      Optional<RegisteredServer> registeredServer = server.getServer(arg);
      if (!registeredServer.isPresent()) {
        source.sendMessage(
            TextComponent.of("Server " + arg + " doesn't exist.", TextColor.RED));
        return;
      }
      sendServerPlayers(source, registeredServer.get(), false);
    }
  } else {
    source.sendMessage(TextComponent.of("Too many arguments.", TextColor.RED));
  }
}
 
Example 16
Source File: ServerCommand.java    From Velocity with MIT License 4 votes vote down vote up
@Override
public void execute(CommandSource source, String @NonNull [] args) {
  if (!(source instanceof Player)) {
    source.sendMessage(TextComponent.of("Only players may run this command.", TextColor.RED));
    return;
  }

  Player player = (Player) source;
  if (args.length == 1) {
    // Trying to connect to a server.
    String serverName = args[0];
    Optional<RegisteredServer> toConnect = server.getServer(serverName);
    if (!toConnect.isPresent()) {
      player.sendMessage(
          TextComponent.of("Server " + serverName + " doesn't exist.", TextColor.RED));
      return;
    }

    player.createConnectionRequest(toConnect.get()).fireAndForget();
  } else {
    String currentServer = player.getCurrentServer().map(ServerConnection::getServerInfo)
        .map(ServerInfo::getName)
        .orElse("<unknown>");
    player.sendMessage(TextComponent
        .of("You are currently connected to " + currentServer + ".", TextColor.YELLOW));

    // Assemble the list of servers as components
    TextComponent.Builder serverListBuilder = TextComponent.builder("Available servers: ")
        .color(TextColor.YELLOW);
    List<RegisteredServer> infos = ImmutableList.copyOf(server.getAllServers());
    for (int i = 0; i < infos.size(); i++) {
      RegisteredServer rs = infos.get(i);
      TextComponent infoComponent = TextComponent.of(rs.getServerInfo().getName());
      String playersText = rs.getPlayersConnected().size() + " player(s) online";
      if (rs.getServerInfo().getName().equals(currentServer)) {
        infoComponent = infoComponent.color(TextColor.GREEN)
            .hoverEvent(HoverEvent.showText(
                TextComponent.of("Currently connected to this server\n" + playersText)));
      } else {
        infoComponent = infoComponent.color(TextColor.GRAY)
            .clickEvent(ClickEvent.runCommand(
                "/server " + rs.getServerInfo().getName()))
            .hoverEvent(HoverEvent.showText(
                TextComponent.of("Click to connect to this server\n" + playersText)));
      }
      serverListBuilder.append(infoComponent);
      if (i != infos.size() - 1) {
        serverListBuilder.append(TextComponent.of(", ", TextColor.GRAY));
      }
    }

    player.sendMessage(serverListBuilder.build());
  }
}
 
Example 17
Source File: VelocitySenderFactory.java    From LuckPerms with MIT License 4 votes vote down vote up
@Override
protected void sendMessage(CommandSource source, Component message) {
    source.sendMessage(message);
}
 
Example 18
Source File: GlistCommand.java    From Velocity with MIT License 4 votes vote down vote up
private void sendTotalProxyCount(CommandSource target) {
  target.sendMessage(TextComponent.builder("There are ", TextColor.YELLOW)
      .append(Integer.toString(server.getAllPlayers().size()), TextColor.GREEN)
      .append(" player(s) online.", TextColor.YELLOW)
      .build());
}