com.velocitypowered.api.command.CommandSource Java Examples

The following examples show how to use com.velocitypowered.api.command.CommandSource. 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: 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 #2
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 #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 List<String> suggest(CommandSource source, String @NonNull [] currentArgs) {
  if (currentArgs.length == 0) {
    return subcommands.entrySet().stream()
            .filter(e -> e.getValue().hasPermission(source, new String[0]))
            .map(Map.Entry::getKey)
            .collect(ImmutableList.toImmutableList());
  }

  if (currentArgs.length == 1) {
    return subcommands.entrySet().stream()
        .filter(e -> e.getKey().regionMatches(true, 0, currentArgs[0], 0,
            currentArgs[0].length()))
        .filter(e -> e.getValue().hasPermission(source, new String[0]))
        .map(Map.Entry::getKey)
        .collect(ImmutableList.toImmutableList());
  }

  Command command = subcommands.get(currentArgs[0].toLowerCase(Locale.US));
  if (command == null) {
    return ImmutableList.of();
  }
  @SuppressWarnings("nullness")
  String[] actualArgs = Arrays.copyOfRange(currentArgs, 1, currentArgs.length);
  return command.suggest(source, actualArgs);
}
 
Example #5
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) {
    usage(source);
    return;
  }

  Command command = subcommands.get(args[0].toLowerCase(Locale.US));
  if (command == null) {
    usage(source);
    return;
  }
  @SuppressWarnings("nullness")
  String[] actualArgs = Arrays.copyOfRange(args, 1, args.length);
  command.execute(source, actualArgs);
}
 
Example #6
Source File: SkinCommand.java    From SkinsRestorerX with GNU General Public License v3.0 6 votes vote down vote up
@Subcommand("clear") @CommandPermission("%skinClearOther")
@CommandCompletion("@players")
@Description("%helpSkinClearOther")
public void onSkinClearOther(CommandSource source, OnlinePlayer target) {
    plugin.getService().execute(() -> {
        Player p = target.getPlayer();
        String skin = plugin.getSkinStorage().getDefaultSkinNameIfEnabled(p.getUsername(), true);

        // remove users custom skin and set default skin / his skin
        plugin.getSkinStorage().removePlayerSkin(p.getUsername());
        if (this.setSkin(source, p, skin, false)) {
            if (!getSenderName(source).equals(target.getPlayer().getUsername()))
                source.sendMessage(plugin.deserialize(Locale.SKIN_CLEAR_ISSUER.replace("%player", target.getPlayer().getUsername())));
            else
                source.sendMessage(plugin.deserialize(Locale.SKIN_CLEAR_SUCCESS));
        }
    });
}
 
Example #7
Source File: GlistCommand.java    From Velocity with MIT License 6 votes vote down vote up
@Override
public List<String> suggest(CommandSource source, String @NonNull [] currentArgs) {
  ImmutableList.Builder<String> options = ImmutableList.builder();
  for (RegisteredServer server : server.getAllServers()) {
    options.add(server.getServerInfo().getName());
  }
  options.add("all");

  switch (currentArgs.length) {
    case 0:
      return options.build();
    case 1:
      return options.build().stream()
          .filter(o -> o.regionMatches(true, 0, currentArgs[0], 0, currentArgs[0].length()))
          .collect(ImmutableList.toImmutableList());
    default:
      return ImmutableList.of();
  }
}
 
Example #8
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 #9
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 #10
Source File: SkinCommand.java    From SkinsRestorerX with GNU General Public License v3.0 6 votes vote down vote up
@Subcommand("update") @CommandPermission("%skinUpdateOther")
@CommandCompletion("@players")
@Description("%helpSkinUpdateOther")
public void onSkinUpdateOther(CommandSource source, OnlinePlayer target) {
    plugin.getService().execute(() -> {
        Player p = target.getPlayer();
        String skin = plugin.getSkinStorage().getPlayerSkin(p.getUsername());

        // User has no custom skin set, get the default skin name / his skin
        if (skin == null)
            skin = plugin.getSkinStorage().getDefaultSkinNameIfEnabled(p.getUsername(), true);

        if (!plugin.getSkinStorage().forceUpdateSkinData(skin)) {
            source.sendMessage(plugin.deserialize(Locale.ERROR_UPDATING_SKIN));
            return;
        }

        if (this.setSkin(source, p, skin, false)) {
            if (!getSenderName(source).equals(target.getPlayer().getUsername()))
                source.sendMessage(plugin.deserialize(Locale.SUCCESS_UPDATING_SKIN_OTHER.replace("%player", target.getPlayer().getUsername())));
            else
                source.sendMessage(plugin.deserialize(Locale.SUCCESS_UPDATING_SKIN));
        }
    });
}
 
Example #11
Source File: VelocitySenderFactory.java    From LuckPerms with MIT License 5 votes vote down vote up
@Override
protected String getName(CommandSource source) {
    if (source instanceof Player) {
        return ((Player) source).getUsername();
    }
    return Sender.CONSOLE_NAME;
}
 
Example #12
Source File: VelocityCommand.java    From Velocity with MIT License 5 votes vote down vote up
@Override
public boolean hasPermission(CommandSource source, String @NonNull [] args) {
  if (args.length == 0) {
    return subcommands.values().stream().anyMatch(e -> e.hasPermission(source, args));
  }
  Command command = subcommands.get(args[0].toLowerCase(Locale.US));
  if (command == null) {
    return true;
  }
  @SuppressWarnings("nullness")
  String[] actualArgs = Arrays.copyOfRange(args, 1, args.length);
  return command.hasPermission(source, actualArgs);
}
 
Example #13
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 #14
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 #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: 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 #17
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 #18
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 #19
Source File: VelocitySenderFactory.java    From LuckPerms with MIT License 5 votes vote down vote up
@Override
protected UUID getUniqueId(CommandSource source) {
    if (source instanceof Player) {
        return ((Player) source).getUniqueId();
    }
    return Sender.CONSOLE_UUID;
}
 
Example #20
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 #21
Source File: ServerCommand.java    From Velocity with MIT License 5 votes vote down vote up
@Override
public List<String> suggest(CommandSource source, String @NonNull [] currentArgs) {
  Stream<String> possibilities = Stream.concat(Stream.of("all"), server.getAllServers()
      .stream().map(rs -> rs.getServerInfo().getName()));
  if (currentArgs.length == 0) {
    return possibilities.collect(Collectors.toList());
  } else if (currentArgs.length == 1) {
    return possibilities
        .filter(name -> name.regionMatches(true, 0, currentArgs[0], 0, currentArgs[0].length()))
        .collect(Collectors.toList());
  } else {
    return ImmutableList.of();
  }
}
 
Example #22
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 #23
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 #24
Source File: VelocityCommandManager.java    From Velocity with MIT License 5 votes vote down vote up
@Override
public boolean execute(CommandSource source, String cmdLine) {
  Preconditions.checkNotNull(source, "invoker");
  Preconditions.checkNotNull(cmdLine, "cmdLine");

  String[] split = cmdLine.split(" ", -1);
  if (split.length == 0) {
    return false;
  }

  String alias = split[0];
  Command command = commands.get(alias.toLowerCase(Locale.ENGLISH));
  if (command == null) {
    return false;
  }

  @SuppressWarnings("nullness")
  String[] actualArgs = Arrays.copyOfRange(split, 1, split.length);
  try {
    if (!command.hasPermission(source, actualArgs)) {
      return false;
    }

    command.execute(source, actualArgs);
    return true;
  } catch (Exception e) {
    throw new RuntimeException("Unable to invoke command " + cmdLine + " for " + source, e);
  }
}
 
Example #25
Source File: VelocityCommandManager.java    From Velocity with MIT License 5 votes vote down vote up
/**
 * Determines if the {@code source} has permission to run the {@code cmdLine}.
 * @param source the source to check against
 * @param cmdLine the command to run
 * @return {@code true} if the command can be run, otherwise {@code false}
 */
public boolean hasPermission(CommandSource source, String cmdLine) {
  Preconditions.checkNotNull(source, "source");
  Preconditions.checkNotNull(cmdLine, "cmdLine");

  String[] split = cmdLine.split(" ", -1);
  if (split.length == 0) {
    // No command available.
    return false;
  }

  String alias = split[0];
  Command command = commands.get(alias.toLowerCase(Locale.ENGLISH));
  if (command == null) {
    // No such command.
    return false;
  }

  @SuppressWarnings("nullness")
  String[] actualArgs = Arrays.copyOfRange(split, 1, split.length);
  try {
    return command.hasPermission(source, actualArgs);
  } catch (Exception e) {
    throw new RuntimeException(
        "Unable to invoke suggestions for command " + alias + " for " + source, e);
  }
}
 
Example #26
Source File: SkinCommand.java    From SkinsRestorerX with GNU General Public License v3.0 5 votes vote down vote up
@HelpCommand
public void onHelp(CommandSource commandSource, CommandHelp help) {
    if (Config.USE_OLD_SKIN_HELP)
        sendHelp(commandSource);
    else
        help.showHelp();
}
 
Example #27
Source File: VelocityCommandExecutor.java    From LuckPerms with MIT License 5 votes vote down vote up
public void register() {
    ProxyServer proxy = this.plugin.getBootstrap().getProxy();
    proxy.getCommandManager().register(this, ALIASES);

    // register slash aliases so the console can run '/lpv' in the same way as 'lpv'.
    proxy.getCommandManager().register(new ForwardingCommand(this) {
        @Override
        public boolean hasPermission(CommandSource source, @NonNull String[] args) {
            return source instanceof ConsoleCommandSource;
        }
    }, SLASH_ALIASES);
}
 
Example #28
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 #29
Source File: VelocitySenderFactory.java    From LuckPerms with MIT License 4 votes vote down vote up
@Override
protected void sendMessage(CommandSource source, String s) {
    sendMessage(source, TextUtils.fromLegacy(s));
}
 
Example #30
Source File: TestVoteCmd.java    From NuVotifier with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean hasPermission(CommandSource source, @NonNull String[] args) {
    return source.hasPermission("nuvotifier.testvote");
}