Example #1
0
  @Override
  public void execute(CommandSender sender, String[] args) {
    if (sender instanceof ProxiedPlayer) {
      if (args == null || args.length < 1) {
        sender.sendMessage(Dictionary.format(Dictionary.ERROR_INVALID_ARGUMENTS));
        return;
      }

      ProxiedPlayer player = (ProxiedPlayer) sender;
      ProxiedPlayer join = ProxyServer.getInstance().getPlayer(args[0]);
      if (join == null || Messenger.isHidden(join)) {
        sender.sendMessage(Dictionary.format(Dictionary.ERROR_PLAYER_OFFLINE));
        return;
      }

      if (player.getUniqueId() == join.getUniqueId()) {
        sender.sendMessage(ChatColor.RED + "You cannot join yourself!");
        return;
      }

      ServerInfo info = join.getServer().getInfo();
      if (info.canAccess(player)) {
        sender.sendMessage(
            ChatColor.LIGHT_PURPLE + "Attempting to join " + join.getName() + "'s server..");
        player.connect(info);
      } else {
        sender.sendMessage(ProxyServer.getInstance().getTranslation("no_server_permission"));
      }
    } else {
      sender.sendMessage(ChatColor.RED + "Console cannot join servers");
    }
  }
Example #2
0
  /** Used to passthrough the ping of the relevant server */
  @EventHandler
  public void onPing(ProxyPingEvent event) {
    if (!PodConfig.inst().getPingPassthrough()) return;

    int protocol = event.getConnection().getVersion();
    ServerInfo info = getServer(protocol);
    if (info == null) return;

    final Exchanger<ServerPing> exch = new Exchanger<>();

    // Get the child server's ping, pass it to back to main ping.
    info.ping(
        new Callback<ServerPing>() {
          @Override
          public void done(ServerPing result, Throwable error) {
            try {
              exch.exchange(result);
            } catch (InterruptedException e) {
              e.printStackTrace();
            }
          }
        });

    try {
      ServerPing ping = exch.exchange(null); // Wait for child ping thread to finish
      if (ping == null) return;
      event.setResponse(ping);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
  }
Example #3
0
 private void summon(ProxiedPlayer player, ServerInfo target, CommandSender sender) {
   if ((player.getServer() != null) && (!player.getServer().getInfo().equals(target))) {
     player.connect(target);
     player.sendMessage(
         ChatColor.GOLD + "Summoned to " + target.getName() + " by " + sender.getName());
   }
 }
 public void run() {
   if (list.isEmpty()) {
     return;
   }
   if (server.getPlayers().isEmpty()) {
     return;
   }
   for (ProxiedPlayer player : server.getPlayers()) {
     for (String line : list.get(count).split("\n")) {
       ActionBarUtil.sendActionBar(player, line.replace("%p%", player.getName()));
     }
   }
   count++;
   if ((count + 1) > list.size()) {
     count = 0;
   }
 }
 @Override
 public Iterator<String> getRandomPlayers(String location) {
   ServerInfo server = getProxy().getServerInfo(location);
   return server != null ? getRandomPlayers(server.getPlayers()) : null;
 }
 @Override
 public Integer getOnlinePlayers(String location) {
   ServerInfo server = getProxy().getServerInfo(location);
   return server != null ? server.getPlayers().size() : null;
 }
    @EventHandler
    public void onProxyPing(ProxyPingEvent event) {
      if (event.getResponse() == null) return; // Check if response is not empty

      PendingConnection con = event.getConnection();
      StatusRequest request = core.createRequest(con.getAddress().getAddress());

      request.setProtocolVersion(con.getVersion());
      InetSocketAddress host = con.getVirtualHost();
      if (host != null) {
        ServerInfo forcedHost = AbstractReconnectHandler.getForcedHost(con);
        request.setTarget(host, forcedHost != null ? forcedHost.getName() : null);
      }

      final ServerPing ping = event.getResponse();
      final ServerPing.Players players = ping.getPlayers();
      final ServerPing.Protocol version = ping.getVersion();

      StatusResponse response =
          request.createResponse(
              core.getStatus(),
              // Return unknown player counts if it has been hidden
              new ResponseFetcher() {
                @Override
                public Integer getOnlinePlayers() {
                  return players != null ? players.getOnline() : null;
                }

                @Override
                public Integer getMaxPlayers() {
                  return players != null ? players.getMax() : null;
                }

                @Override
                public int getProtocolVersion() {
                  return version != null ? version.getProtocol() : 0;
                }
              });

      // Description
      String message = response.getDescription();
      if (message != null) ping.setDescription(message);

      if (version != null) {
        // Version name
        message = response.getVersion();
        if (message != null) version.setName(message);
        // Protocol version
        Integer protocol = response.getProtocolVersion();
        if (protocol != null) version.setProtocol(protocol);
      }

      // Favicon
      FaviconSource favicon = response.getFavicon();
      if (favicon != null) {
        Optional<Favicon> icon = faviconCache.getUnchecked(favicon);
        if (icon.isPresent()) ping.setFavicon(icon.get());
      }

      if (players != null) {
        if (response.hidePlayers()) {
          ping.setPlayers(null);
        } else {
          // Online players
          Integer count = response.getOnlinePlayers();
          if (count != null) players.setOnline(count);
          // Max players
          count = response.getMaxPlayers();
          if (count != null) players.setMax(count);

          // Player hover
          message = response.getPlayerHover();
          if (message != null) {
            if (response.useMultipleSamples()) {
              count = response.getDynamicSamples();
              List<String> lines =
                  count != null
                      ? Helper.splitLinesCached(message, count)
                      : Helper.splitLinesCached(message);

              ServerPing.PlayerInfo[] sample = new ServerPing.PlayerInfo[lines.size()];
              for (int i = 0; i < sample.length; i++)
                sample[i] = new ServerPing.PlayerInfo(lines.get(i), StatusManager.EMPTY_UUID);

              players.setSample(sample);
            } else
              players.setSample(
                  new ServerPing.PlayerInfo[] {
                    new ServerPing.PlayerInfo(message, StatusManager.EMPTY_UUID)
                  });
          }
        }
      }
    }
Example #8
0
  @Override
  public boolean execute(IRCSender sender, String[] args) {
    Messages messages = plugin.getConfigManager().getConfig("messages");

    // Check for Permissions
    if (!ircModule.getPermissions().has(sender.getRawNick(), "command.scmd")) {
      ircModule
          .getIrcBot()
          .sendToChannel(
              MCToIrcFormat.translateString(
                  messages.IRC_Command_Scmd_NotEnoughPermission.replace(
                      "%nick", sender.getRawNick())),
              sender.getChannel());
      return true;
    }

    if (args.length < 2) {
      ircModule
          .getIrcBot()
          .sendToChannel(
              MCToIrcFormat.translateString(
                  messages.IRC_Command_Scmd_NotEnoughArguments.replace(
                      "%nick", sender.getRawNick())),
              sender.getChannel());
      return true;
    }

    // Check for Server and command permission
    String server = args[0];
    String command = args[1];

    if (!ircModule.getPermissions().has(sender.getRawNick(), "command.scmd.server." + server)) {
      ircModule
          .getIrcBot()
          .sendToChannel(
              MCToIrcFormat.translateString(
                  messages.IRC_Command_Scmd_NotEnoughPermissionForServer.replace(
                      "%nick", sender.getRawNick())),
              sender.getChannel());
      return true;
    }

    if (!ircModule.getPermissions().has(sender.getRawNick(), "command.scmd.command." + command)) {
      ircModule
          .getIrcBot()
          .sendToChannel(
              MCToIrcFormat.translateString(
                  messages.IRC_Command_Scmd_NotEnoughPermissionForCommand.replace(
                      "%nick", sender.getRawNick())),
              sender.getChannel());
      return true;
    }

    // Check if there is a Player online on the wanted Server
    if (!server.equals("bungee")) {
      ServerInfo serverInfo = plugin.getProxy().getServerInfo(server);
      if (serverInfo == null) {
        ircModule
            .getIrcBot()
            .sendToChannel(
                MCToIrcFormat.translateString(
                    messages.IRC_Command_Scmd_InvalidServer.replace("%nick", sender.getRawNick())),
                sender.getChannel());
        return true;
      }

      if (serverInfo.getPlayers().size() == 0) {
        ircModule
            .getIrcBot()
            .sendToChannel(
                MCToIrcFormat.translateString(
                    messages.IRC_Command_Scmd_ServerIsEmpty.replace("%nick", sender.getRawNick())),
                sender.getChannel());
        return true;
      }

      // Create a new SCMD Session
      String scommand = StringUtils.join(Arrays.copyOfRange(args, 1, args.length), " ");
      plugin
          .getPluginLogger()
          .info("Issuing SCMD '" + scommand + "' on " + args[0] + " for " + sender.getNick());
      Integer sessionId =
          ircModule
              .getIrcBot()
              .getIrcManager()
              .newScmdSession(sender.getRawNick(), sender.getChannel(), scommand);

      DispatchScmdMessage dispatchScmdMessage = new DispatchScmdMessage(scommand, sessionId);
      plugin
          .getPluginMessageManager("CloudChat")
          .sendPluginMessage(serverInfo.getPlayers().iterator().next(), dispatchScmdMessage);
    } else {
      String scommand = StringUtils.join(Arrays.copyOfRange(args, 1, args.length), " ");
      plugin
          .getPluginLogger()
          .info("Issuing SCMD '" + scommand + "' on " + args[0] + " for " + sender.getNick());
      plugin
          .getProxy()
          .getPluginManager()
          .dispatchCommand(new CloudChatCommandSender(ircModule, sender), scommand);
    }

    ircModule
        .getIrcBot()
        .sendToChannel(
            MCToIrcFormat.translateString(
                messages.IRC_Command_Scmd_CommandIssued.replace("%nick", sender.getRawNick())),
            sender.getChannel());
    return true;
  }