public static boolean addFriend(
     ProxiedPlayer p, String who) { // who == der, der geaddedt werden soll
   if (who == null || who == "") return false; // Parameter fehlt bzw. ungültig
   PlayerData pd =
       PlayerData.get(p.getUniqueId()); // All ProxiedPlayer's are registered in the RAM
   ProxiedPlayer whoPlayer = Util.getPlayer(who);
   if (whoPlayer == null) {
     Messages.FRIEND_NOT_ONLINE.msg(p, "%player%", who);
     return false;
   }
   if (p.getUniqueId() == whoPlayer.getUniqueId()) {
     Messages.FRIEND_YOURSELF.msg(p);
     return false;
   }
   if (pd.getFriends().containsKey(whoPlayer.getUniqueId()) == true) {
     Messages.FRIEND_ALREADY_A_FRIEND.msg(p, "%player%", whoPlayer.getName());
     return false;
   }
   Friend f =
       new Friend(p.getUniqueId(), whoPlayer.getUniqueId(), p.getName(), whoPlayer.getName());
   FriendRequest fRequest = new FriendRequest(p, whoPlayer, f);
   PlayerData.get(whoPlayer.getUniqueId()).addFriendRequest(fRequest);
   f.insertSQL();
   pd.getFriends().put(whoPlayer.getUniqueId(), f);
   Messages.FRIENDREQUEST_SUCCESSFULLY_SEND.msg(p, "%player%", whoPlayer.getName());
   Messages.FRIENDREQUEST_GOT.msg(whoPlayer, "%player%", p.getName());
   PluginMessenger.sendMessage(p, "Friend", "Update");
   return true;
 }
Example #2
0
 public Iterable<String> onTabComplete(CommandSender sender, String[] args) {
   if ((args.length > 2) || (args.length == 0)) {
     return ImmutableSet.of();
   }
   Set<String> matches = new HashSet<>();
   String search;
   if (args.length == 1) {
     search = args[0].toLowerCase();
     for (ProxiedPlayer player : ProxyServer.getInstance().getPlayers()) {
       if (player.getName().toLowerCase().startsWith(search)) {
         matches.add(player.getName());
       }
     }
     if ("all".startsWith(search)) {
       matches.add("all");
     }
     if ("current".startsWith(search)) {
       matches.add("current");
     }
   } else {
     search = args[1].toLowerCase();
     for (String server : ProxyServer.getInstance().getServers().keySet()) {
       if (server.toLowerCase().startsWith(search)) {
         matches.add(server);
       }
     }
   }
   return matches;
 }
Example #3
0
  public static void loadPlayer(ProxiedPlayer player) {
    if (playerExists(player, FeatureDetector.canUseUUID())) {
      boolean tps;

      if (FeatureDetector.canUseUUID()) {
        tps = DatabaseManager.players.getPlayerTPS(player.getUUID());
      } else {
        tps = DatabaseManager.players.getPlayerTPS(player.getName());
      }

      GSPlayer gsPlayer =
          new GSPlayer(
              player.getName(),
              (FeatureDetector.canUseUUID()) ? player.getUUID() : null,
              tps,
              player.getAddress().getHostString());
      onlinePlayers.put(player.getName(), gsPlayer);

      DatabaseManager.players.updatePlayer(gsPlayer);

      LoggingManager.log(
          ConfigManager.messages.PLAYER_LOAD.replace("{player}", gsPlayer.getName()));

      HomesManager.loadPlayersHomes(gsPlayer);
    } else {
      createNewPlayer(player);
    }
  }
Example #4
0
  @EventHandler(priority = EventPriority.HIGHEST, canVeto = true)
  public boolean onPM(PMEvent event) {
    IRC config = plugin.getConfigManager().getConfig("irc");

    if (FontFormat.stripColor(event.getFrom()).contains(FontFormat.stripColor(config.IngameName))) {
      Messages messages = plugin.getConfigManager().getConfig("messages");

      // Check if there is a " " in the name
      String ircNick;
      if (event.getFrom().contains(config.IngameName)) {
        ircNick = FontFormat.stripColor(event.getFrom().replace(config.IngameName, ""));
      } else {
        ircNick =
            FontFormat.stripColor(event.getMessage().replace(config.IngameName, "").split(" ")[0]);
      }

      ProxiedPlayer sen = plugin.getProxy().getPlayer(event.getTo());

      if (sen == null) {
        ircModule.getIrcBot().sendToChannel("Player " + event.getTo() + " is offline", ircNick);
        return true;
      }

      if (ircModule.getIrcBot().getIrcManager().hasPmSession(ircNick)) {
        PMSession pmSession = ircModule.getIrcBot().getIrcManager().getPmSession(ircNick);
        pmSession.setTo(sen.getName());
      } else {
        ircModule.getIrcBot().getIrcManager().newPMSession(ircNick);
        PMSession pmSession = ircModule.getIrcBot().getIrcManager().getPmSession(ircNick);
        pmSession.setTo(sen.getName());
      }

      playerManager.get(sen.getName()).Reply = FontFormat.stripColor(config.IngameName) + ircNick;
      MessageBuilder messageBuilder = new MessageBuilder();
      messageBuilder.setText(
          FontFormat.translateString(
              messages.Message_Receiver.replace("%sender", config.IngameName + ircNick)
                  .replace("%message", event.getMessage().replace(ircNick + " ", ""))));
      messageBuilder.send(sen);

      plugin
          .getPluginLogger()
          .info(
              event.getFrom()
                  + " -> "
                  + event.getTo()
                  + ": "
                  + event.getMessage().replace(ircNick + " ", ""));

      return true;
    }

    return false;
  }
Example #5
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");
    }
  }
 public static boolean removeFriend(ProxiedPlayer p, String who) {
   if (who == null || who == "") {
     Messages.FRIEND_FAIL_REMOVED.msg(p, "%player%", who);
     return false;
   } // Parameter fehlt bzw. ungültig
   ProxiedPlayer whoPlayer = Util.getPlayer(who);
   PlayerData pd = PlayerData.get(p.getUniqueId());
   if (whoPlayer == null) {
     for (UUID uuid : pd.getFriends().keySet()) {
       Friend friend = pd.getFriends().get(uuid);
       if (friend.getFriendName().equalsIgnoreCase(who)) {
         friend.remove(true);
         pd.getFriends().remove(uuid);
         Messages.FRIEND_REMOVED.msg(p, "%player%", who);
         PluginMessenger.sendMessage(p, "Friend", "Update");
         return true;
       }
     }
     Messages.FRIEND_NOT_IN_FRIENDLIST.msg(p, "%player%", who);
     return false;
   } else {
     if (pd.getFriends().containsKey(whoPlayer.getUniqueId())) {
       pd.getFriends().remove(whoPlayer.getUniqueId());
       Messages.FRIEND_REMOVED.msg(p, "%player%", whoPlayer.getName());
       PluginMessenger.sendMessage(p, "Friend", "Update");
       return true;
     }
     Messages.FRIEND_NOT_IN_FRIENDLIST.msg(p, "%player%", who);
     return false;
   }
 }
Example #7
0
  @Override
  public void execute(CommandSender sender, String[] args) {
    if (Tickets.getTickets(sender.getName(), "open").length != 0) {
      sender.sendMessage(ChatColor.RED + "Je hebt al een open ticket.");
      return;
    }

    if (Tickets.inTicket(sender.getName())) {
      sender.sendMessage(ChatColor.RED + "Je wordt al geholpen.");
      return;
    }

    boolean adminsOnline = false;
    for (ProxiedPlayer player : Main.instance.getProxy().getPlayers())
      if (Permissions.hasPermission(player.getName(), "bs.bungee.tickets.receive_broadcast"))
        adminsOnline = true;

    if (!adminsOnline) {
      sender.sendMessage(
          ChatColor.RED
              + "Er zijn op dit moment geen admins online om je te helpen. Probeer het later nog eens.");
      return;
    }

    String question = "";
    for (int i = 0; i < args.length; i++) {
      if (!args[i].equals("create")) question += ((question.equals("")) ? "" : " ") + args[i];
    }

    Ticket ticket = new Ticket();

    ticket.username = sender.getName();
    ticket.server =
        Main.instance.getProxy().getPlayer(sender.getName()).getServer().getInfo().getName();
    ticket.question = question;

    Tickets.createTicket(ticket);

    for (ProxiedPlayer player : Main.instance.getProxy().getPlayers())
      if (Permissions.hasPermission(player.getName(), "bs.bungee.tickets.receive_broadcast"))
        player.sendMessage(
            ChatColor.AQUA + ticket.username + " heeft een ticket aangemaakt: " + ticket.question);

    sender.sendMessage(
        ChatColor.GREEN + "Je ticket is aangemaakt. Je wordt zo snel mogelijk geholpen!");
  }
  private static Iterator<String> getRandomPlayers(Collection<ProxiedPlayer> players) {
    if (Helper.isNullOrEmpty(players)) return null;

    List<String> result = new ArrayList<>(players.size());

    for (ProxiedPlayer player : players) {
      result.add(player.getName());
    }

    return Randoms.shuffle(result).iterator();
  }
Example #9
0
  private static void createNewPlayer(final ProxiedPlayer player) {
    String ip = player.getAddress().getAddress().toString();
    final GSPlayer gsPlayer =
        new GSPlayer(
            player.getName(), (FeatureDetector.canUseUUID()) ? player.getUUID() : null, true);

    DatabaseManager.players.insertPlayer(gsPlayer, ip.substring(1, ip.length()));

    if (ConfigManager.main.NewPlayerBroadcast) {
      String welcomeMsg = null;
      sendBroadcast(
          welcomeMsg =
              ConfigManager.messages.NEW_PLAYER_BROADCAST.replace("{player}", player.getName()));
      // Firing custom event
      ProxyServer.getInstance()
          .getPluginManager()
          .callEvent(new NewPlayerJoinEvent(player.getName(), welcomeMsg));
    }

    onlinePlayers.put(player.getName(), gsPlayer);
    LoggingManager.log(ConfigManager.messages.PLAYER_LOAD.replace("{player}", gsPlayer.getName()));

    if (ConfigManager.spawn.SpawnNewPlayerAtNewspawn && SpawnManager.NewPlayerSpawn != null) {
      SpawnManager.newPlayers.add(player);

      ProxyServer.getInstance()
          .getScheduler()
          .schedule(
              geSuit.instance,
              new Runnable() {

                @Override
                public void run() {
                  SpawnManager.sendPlayerToNewPlayerSpawn(gsPlayer);
                  SpawnManager.newPlayers.remove(player);
                }
              },
              300,
              TimeUnit.MILLISECONDS);
    }
  }
 public static void addReport(
     int number, ProxiedPlayer reporter, ProxiedPlayer reported, String reason) {
   try {
     Statement st = dbmanager.getConnection().createStatement();
     st.executeUpdate(
         "INSERT INTO Reports(Number, Reporter, Player, Reason) VALUES ('"
             + number
             + "', '"
             + reporter.getName()
             + "', '"
             + reported.getName()
             + "', '"
             + reason
             + "')");
   } catch (SQLException e) {
     System.out.println(
         "[BungeeUtilisals]: Can't add Report from: "
             + reporter.getName()
             + ", "
             + e.getMessage());
   }
 }
  public void run() {
    Collection<ProxiedPlayer> players = ProxyServer.getInstance().getPlayers();
    if (players.isEmpty()) {
      return;
    }

    int fadeIn = TitleAnnouncements.titleannouncements.getInt("Announcements.Global.FadeIn", 30);
    int stay = TitleAnnouncements.titleannouncements.getInt("Announcements.Global.Stay", 60);
    int fadeOut = TitleAnnouncements.titleannouncements.getInt("Announcements.Global.FadeOut", 30);

    for (ProxiedPlayer player : players) {
      for (String line : list.get(count).split("\n")) {
        if (line.contains("%n")) {
          String[] titles = line.split("%n");
          String stitle = titles[0];
          String ssubtitle = titles[1];

          BaseComponent[] title =
              new ComponentBuilder(stitle.replace("%p%", player.getName())).create();
          BaseComponent[] subtitle =
              new ComponentBuilder(ssubtitle.replace("%p%", player.getName())).create();

          TitleUtil.sendFullTitle(player, fadeIn, stay, fadeOut, subtitle, title);
        } else {
          BaseComponent[] title =
              new ComponentBuilder(line.replace("%p%", player.getName())).create();
          BaseComponent[] subtitle = new ComponentBuilder("").create();

          TitleUtil.sendFullTitle(player, fadeIn, stay, fadeOut, subtitle, title);
        }
      }
    }
    count++;
    if ((count + 1) > list.size()) {
      count = 0;
    }
  }
  public static boolean acceptFriend(ProxiedPlayer p, String toAcceptFriendName) {
    if (toAcceptFriendName == null || toAcceptFriendName == "") return false;
    PlayerData pd = PlayerData.get(p.getUniqueId());
    ProxiedPlayer toAcceptFriend = Util.getPlayer(toAcceptFriendName);
    if (toAcceptFriend == null) {
      Messages.FRIEND_NOT_ONLINE.msg(p, "%player%", toAcceptFriendName);
      return false;
    }
    if (!pd.getFriendRequests().isEmpty()) {
      for (FriendRequest fr : pd.getFriendRequests()) {
        ProxiedPlayer friend = fr.getReceiver();
        if (friend == null) continue;
        if (friend.getUniqueId().toString() == toAcceptFriend.getUniqueId().toString()) {
          fr.setAccepted(true);
          fr.setAnswered(true);
          Messages.FRIENDREQUEST_ACCEPTED.msg(p, "%player%", toAcceptFriend.getName());
          Messages.FRIENDREQUEST_ACCEPTED_FORSENDER.msg(toAcceptFriend, "%player%", p.getName());
          PluginMessenger.sendMessage(p, "Friend", "Update");
          PluginMessenger.sendMessage(toAcceptFriend, "Friend", "Update");
          return true;
        }
      }
    }

    if (!pd.getFriends().containsKey(toAcceptFriend.getUniqueId())) {
      Messages.FRIEND_NOT_IN_FRIENDLIST.msg(p, "%player%", toAcceptFriendName);
      return false;
    }
    Friend friend = pd.getFriends().get(toAcceptFriend.getUniqueId());
    friend.setRequestAccepted(true);
    friend.updateSQL();
    Messages.FRIENDREQUEST_ACCEPTED.msg(p, "%player%", toAcceptFriend.getName());
    Messages.FRIENDREQUEST_ACCEPTED_FORSENDER.msg(toAcceptFriend, "%player%", p.getName());
    PluginMessenger.sendMessage(p, "Friend", "Update");
    PluginMessenger.sendMessage(toAcceptFriend, "Friend", "Update");
    return true;
  }
 public static boolean acceptLastFriend(ProxiedPlayer p) { // p = der user
   PlayerData pd = PlayerData.get(p.getUniqueId());
   FriendRequest fr = pd.getFriendRequests().poll();
   if (fr == null) {
     Messages.FRIENDREQUEST_LAST_NOT_EXISTS.msg(p);
     return false;
   }
   Messages.FRIENDREQUEST_ACCEPTED.msg(p, "%player%", fr.getFriend().getFriendName());
   Messages.FRIENDREQUEST_ACCEPTED_FORSENDER.msg(fr.getSender(), "%player%", p.getName());
   PluginMessenger.sendMessage(p, "Friend", "Update");
   PluginMessenger.sendMessage(fr.getSender(), "Friend", "Update");
   fr.setAccepted(true);
   fr.setAnswered(true);
   return true;
 }
 @SuppressWarnings("deprecation")
 public void run() {
   Collection<ProxiedPlayer> players = ProxyServer.getInstance().getPlayers();
   if (players.isEmpty()) {
     return;
   }
   for (ProxiedPlayer player : players) {
     for (String line : list.get(count).split("\n")) {
       player.sendMessage(line.replace("%p%", player.getName()));
     }
   }
   count++;
   if ((count + 1) > list.size()) {
     count = 0;
   }
 }
 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 void handle(AbstractPacketHandler handler) throws Exception {
   if (handler instanceof DownstreamBridge) {
     getPlayerField(DownstreamBridge.class);
     if (playerField != null) {
       ProxiedPlayer player;
       try {
         playerField.setAccessible(true);
         player = (ProxiedPlayer) playerField.get(handler);
       } catch (IllegalAccessException ex) {
         BungeeTabListPlus.getInstance()
             .getLogger()
             .warning("Failed to access player object in TeamPacketHandler for " + handler);
         return;
       }
       if (BungeeTabListPlus.getTabList(player) instanceof TabList18v3) {
         Server server = player.getServer();
         if (server != null) {
           BungeeTabListPlus.getInstance()
               .getLogger()
               .warning(
                   "Server "
                       + server.getInfo().getName()
                       + " uses Scoreboard teams. This feature is not compatible with BungeeTabListPlus.");
         } else {
           BungeeTabListPlus.getInstance()
               .getLogger()
               .warning(
                   "Player "
                       + player.getName()
                       + " received a Scoreboard team packet. This feature is not compatible with BungeeTabListPlus.");
         }
         throw CancelSendSignal.INSTANCE;
       }
     } else {
       BungeeTabListPlus.getInstance().getLogger().severe("Could not get player for " + handler);
     }
   }
   super.handle(handler);
 }
  @EventHandler
  public void onJoin(final PostLoginEvent e) {
    final ProxiedPlayer p = e.getPlayer();
    ProxyServer.getInstance()
        .getScheduler()
        .runAsync(
            plugin,
            () -> {
              TextComponent welcome = new TextComponent("Bienvenue, " + p.getName() + " !");
              welcome.setColor(ChatColor.GOLD);

              String key = "rejoinlist:" + e.getPlayer().getUniqueId().toString();
              Jedis cache = plugin.getConnector().getBungeeResource();
              String srv = cache.get(key);
              cache.close();
              if (srv != null) {
                final ServerInfo server = ProxyServer.getInstance().getServerInfo(srv);
                if (server != null)
                  ProxyServer.getInstance()
                      .getScheduler()
                      .schedule(
                          plugin,
                          () ->
                              e.getPlayer()
                                  .connect(
                                      server,
                                      (aBoolean, throwable) -> {
                                        if (aBoolean) {
                                          p.sendMessage(
                                              new ComponentBuilder("")
                                                  .color(ChatColor.GREEN)
                                                  .append("Vous avez été remis en jeu.")
                                                  .create());
                                        }
                                      }),
                          200L,
                          TimeUnit.MILLISECONDS);
              }
            });
  }
Example #18
0
  @Override
  protected void channelRead0(ChannelHandlerContext ctx, DatagramPacket msg) throws Exception {
    ByteBuf in = msg.content();
    if (in.readUnsignedByte() != 0xFE || in.readUnsignedByte() != 0xFD) {
      bungee.getLogger().log(Level.WARNING, "Query - Incorrect magic!: {0}", msg.sender());
      return;
    }

    ByteBuf out = ctx.alloc().buffer();
    AddressedEnvelope response = new DatagramPacket(out, msg.sender());

    byte type = in.readByte();
    int sessionId = in.readInt();

    if (type == 0x09) {
      out.writeByte(0x09);
      out.writeInt(sessionId);

      int challengeToken = random.nextInt();
      sessions.put(challengeToken, System.currentTimeMillis());

      writeNumber(out, challengeToken);
    }

    if (type == 0x00) {
      int challengeToken = in.readInt();
      Long session = sessions.get(challengeToken);
      if (session == null || System.currentTimeMillis() - session > TimeUnit.SECONDS.toMillis(30)) {
        throw new IllegalStateException("No session!");
      }

      out.writeByte(0x00);
      out.writeInt(sessionId);

      if (in.readableBytes() == 0) {
        // Short response
        writeString(out, listener.getMotd()); // MOTD
        writeString(out, "SMP"); // Game Type
        writeString(out, "BungeeCord_Proxy"); // World Name
        writeNumber(out, bungee.getOnlineCount()); // Online Count
        writeNumber(out, listener.getMaxPlayers()); // Max Players
        writeShort(out, listener.getHost().getPort()); // Port
        writeString(out, listener.getHost().getHostString()); // IP
      } else if (in.readableBytes() == 4) {
        // Long Response
        out.writeBytes(
            new byte[] {0x73, 0x70, 0x6C, 0x69, 0x74, 0x6E, 0x75, 0x6D, 0x00, (byte) 0x80, 0x00});
        Map<String, String> data = new LinkedHashMap<>();

        data.put("hostname", listener.getMotd());
        data.put("gametype", "SMP");
        // Start Extra Info
        data.put("game_id", "MINECRAFT");
        data.put("version", bungee.getGameVersion());
        data.put("plugins", "");
        // End Extra Info
        data.put("map", "BungeeCord");
        // data.put( "numplayers", Integer.toString( bungee.getOnlineCount() ) );
        data.put("numplayers", Integer.toString(getFakePlayerNumber()));
        data.put("maxplayers", Integer.toString(listener.getMaxPlayers()));
        data.put("hostport", Integer.toString(listener.getHost().getPort()));
        data.put("hostip", listener.getHost().getHostString());

        for (Map.Entry<String, String> entry : data.entrySet()) {
          writeString(out, entry.getKey());
          writeString(out, entry.getValue());
        }
        out.writeByte(0x00); // Null

        // Padding
        writeString(out, "\01player_\00");
        // Player List
        for (ProxiedPlayer p : bungee.getPlayers()) {
          writeString(out, p.getName());
        }
        // writeString( out, "Mr_ludek" );
        // for(int x = 0; x < getFakePlayerNumber(); x++){

        // }
        writePlayers(getFakePlayerNumber(), out);

        out.writeByte(0x00); // Null
      } else {
        // Error!
        throw new IllegalStateException("Invalid data request packet");
      }
    }

    ctx.writeAndFlush(response);
  }
  @Override
  public void execute(CommandSender cs, String[] args) {
    if (!(cs instanceof ProxiedPlayer)) return;
    ProxiedPlayer p = (ProxiedPlayer) cs;

    if (args.length <= 0) {
      Util.message(p, Util.getFriendHelp());
      return;
    }
    switch (args[0]) {
      case "help":
        Util.message(p, Util.getFriendHelp());
        break;

      case "list":
        break;

      case "accept":
        switch (args.length) {
          case 1:
            Util.debugBoolean(DebugMessage.ACCEPT_LAST, acceptLastFriend(p), "%here%", p.getName());
            break;
          case 2:
            acceptFriend(p, args[1]);
            break;
          default:
            Util.message(p, Util.getFriendHelp());
            break;
        }
        break;

      case "add":
        if (args.length == 2) addFriend(p, args[1]);
        else Util.message(p, Util.getFriendHelp());
        break;

      case "remove":
        if (args.length == 2) removeFriend(p, args[1]);
        else Util.message(p, Util.getFriendHelp());
        break;

      default:
        break;
    }
  }
 public Player getPlayer(ProxiedPlayer proxiedPlayer) {
   Player player;
   if ((player = uuidMap.get(proxiedPlayer.getUniqueId())) == null)
     player = nameMap.get(proxiedPlayer.getName());
   return player;
 }
  @Override
  public Iterable<String> onTabComplete(CommandSender sender, String[] args) {
    if (args.length <= 0) return null;
    Set<String> matches = new HashSet<>();
    switch (args[0].toLowerCase()) {
      case "add":
        {
          if (args.length != 2) break;
          if (args[1].length() >= 2) {
            String search = args[1].toLowerCase();
            for (ProxiedPlayer p : Util.PROXY.getPlayers()) {
              if (p.getName().toLowerCase().startsWith(search)) matches.add(p.getName());
            }
            return matches;
          }
          break;
        }

      case "remove":
        {
          if (args.length != 2) break;
          if (args[1].length() >= 2) {
            if (!(sender instanceof ProxiedPlayer)) return null;
            ProxiedPlayer player = (ProxiedPlayer) sender;
            String search = args[1].toLowerCase();
            PlayerData pd = PlayerData.get(player.getUniqueId());
            for (Friend friend : pd.getFriends().values()) {
              if (friend.getFriendName().toLowerCase().startsWith(search))
                matches.add(friend.getFriendName());
            }
          }
          break;
        }

      case "accept":
        {
          if (args.length != 3) break;
          if (args[2].length() >= 2) {
            if (!(sender instanceof ProxiedPlayer)) return null;
            ProxiedPlayer player = (ProxiedPlayer) sender;
            String search = args[2].toLowerCase();
            PlayerData pd = PlayerData.get(player.getUniqueId());
            for (FriendRequest fr : pd.getFriendRequests()) {
              if (fr.getSender().getName().toLowerCase().startsWith(search))
                matches.add(fr.getSender().getName());
            }
          }
          break;
        }

      default:
        {
          if (args.length == 1) {
            String search = args[0].toLowerCase();
            for (String subcmd : Util.FRIEND_SUBCOMMANDS) {
              if (subcmd.toLowerCase().startsWith(search)) matches.add(subcmd);
            }
          }
          break;
        }
    }
    return matches;
  }
	/**
	 * Will be executed on player disconnect
	 * 
	 * @author Simonsator
	 * @version 1.0.0
	 * @param e
	 *            The disconnect event
	 * @throws SQLException
	 *             Can throw a {@link SQLException}
	 */
	@EventHandler
	public void onPlayerDisconnect(PlayerDisconnectEvent e) throws SQLException {
		ProxiedPlayer player = e.getPlayer();
		if (PartyManager.getParty(player) != null) {
			PlayerParty party = PartyManager.getParty(player);
			if (party.isleader(player)) {
				ArrayList<ProxiedPlayer> liste = party.getPlayer();
				if (liste.size() > 1) {
					ProxiedPlayer newLeader = liste.get(0);
					for (ProxiedPlayer p : party.getPlayer()) {
						if (Main.main.language.equalsIgnoreCase("english")) {
							p.sendMessage(new TextComponent(Main.main.partyPrefix
									+ "The Leader has left the Party. The new Leader is "
									+ newLeader.getDisplayName() + "."));
						} else {
							if (Main.main.language.equalsIgnoreCase("own")) {
								p.sendMessage(new TextComponent(Main.main.partyPrefix
										+ Main.main.messagesYml.getString("Party.Command.Leave.NewLeaderIs")
												.replace("[NEWLEADER]", newLeader.getDisplayName())));
							} else {
								p.sendMessage(new TextComponent(Main.main.partyPrefix
										+ "Der Leader hat die Party verlassen. Der neue Leader ist "
										+ newLeader.getDisplayName() + "."));
							}
						}
					}
					party.setLeader(newLeader);
					liste.remove(newLeader);
					party.setPlayer(liste);
				} else {
					for (ProxiedPlayer p : party.getPlayer()) {
						if (Main.main.language.equalsIgnoreCase("english")) {
							p.sendMessage(new TextComponent(Main.main.partyPrefix
									+ "�he �arty �as �issolved �ecause �f �o �ess �layers."));
						} else {
							if (Main.main.language.equalsIgnoreCase("own")) {
								p.sendMessage(new TextComponent(Main.main.partyPrefix + Main.main.messagesYml
										.getString("Party.Command.General.DissolvedPartyCauseOfNotEnoughPlayers")));
							} else {
								p.sendMessage(new TextComponent(Main.main.partyPrefix
										+ "�ie �arty �urde �egen �u �enig �itgliedern �ufgel鰏t."));
							}
						}
					}
					PartyManager.deleteParty(party);
				}
			} else {
				party.removePlayer(player);
				for (ProxiedPlayer p : party.getPlayer()) {
					if (Main.main.language.equalsIgnoreCase("english")) {
						p.sendMessage(new TextComponent(Main.main.partyPrefix + "The player �
								+ player.getDisplayName() + " has left the party."));
					} else {
						if (Main.main.language.equalsIgnoreCase("own")) {
							p.sendMessage(new TextComponent(Main.main.partyPrefix
									+ Main.main.messagesYml.getString("Party.Command.General.PlayerHasLeftTheParty")
											.replace("[PLAYER]", player.getDisplayName())));
						} else {
							p.sendMessage(new TextComponent(Main.main.partyPrefix + "Der Spieler �
									+ player.getDisplayName() + " hat die Party verlassen."));
						}
					}
				}

				if (Main.main.language.equalsIgnoreCase("english")) {
					party.getleader().sendMessage(new TextComponent(Main.main.partyPrefix + "The player �
							+ player.getDisplayName() + " has left the party."));
				} else {
					if (Main.main.language.equalsIgnoreCase("own")) {
						party.getleader()
								.sendMessage(new TextComponent(Main.main.partyPrefix
										+ Main.main.messagesYml.getString("Party.Command.General.PlayerHasLeftTheParty")
												.replace("[PLAYER]", player.getDisplayName())));
					} else {
						party.getleader().sendMessage(new TextComponent(Main.main.partyPrefix + "Der Spieler �
								+ player.getDisplayName() + " hat die Party verlassen."));
					}
				}
				ArrayList<ProxiedPlayer> liste = party.getPlayer();
				if (liste.size() == 1) {
					if (Main.main.language.equalsIgnoreCase("english")) {
						party.getleader().sendMessage(new TextComponent(Main.main.partyPrefix
								+ "�he �arty �as �issolved �ecause �f �o �ess �layers."));
					} else {
						if (Main.main.language.equalsIgnoreCase("own")) {
							party.getleader()
									.sendMessage(new TextComponent(Main.main.partyPrefix + Main.main.messagesYml
											.getString("Party.Command.General.DissolvedPartyCauseOfNotEnoughPlayers")));
						} else {
							party.getleader().sendMessage(new TextComponent(Main.main.partyPrefix
									+ "�ie �arty �urde �egen �u �enig �itgliedern �ufgel鰏t."));
						}
					}
				}
			}
		}
		try {
			int[] freundeArrayID = Main.main.verbindung
					.getFreundeArray(Main.main.verbindung.getIDByPlayerName(player.getName()));
			if (freundeArrayID.length == 0) {
				return;
			}
			for (int i = 0; i < freundeArrayID.length; i++) {
				String befreundeterSpieler = Main.main.verbindung.getNameDesSpielers(freundeArrayID[i]);
				ProxiedPlayer freundGeladen = BungeeCord.getInstance().getPlayer(befreundeterSpieler);
				if (freundGeladen != null) {
					if (Main.main.language.equalsIgnoreCase("english")) {
						freundGeladen.sendMessage(new TextComponent("��Friends�" + ChatColor.RESET
								+ " �our friend " + player.getDisplayName() + " �s �ow offline."));
					} else {
						if (Main.main.language.equalsIgnoreCase("own")) {
							freundGeladen.sendMessage(new TextComponent(Main.main.friendsPrefix
									+ Main.main.messagesYml.getString("Friends.General.PlayerIsNowOffline")
											.replace("[PLAYER]", player.getDisplayName())));
						} else {
							freundGeladen.sendMessage(new TextComponent("��Friends�" + ChatColor.RESET
									+ " �er Freund " + player.getDisplayName() + " �st �un Offline."));
						}
					}
				}
			}
		} catch (NullPointerException exceptionNull) {

		}
	}
 private String key(ProxiedPlayer player) {
   InetSocketAddress host = player.getPendingConnection().getVirtualHost();
   return player.getName() + ";" + host.getHostString() + ":" + host.getPort();
 }
Example #24
0
 public static boolean playerExists(ProxiedPlayer player, boolean uuid) {
   return getPlayer(player.getName()) != null || (uuid)
       ? DatabaseManager.players.playerExists(player.getUUID())
       : DatabaseManager.players.playerExists(player.getName());
 }
Example #25
0
 public static void sendBroadcast(String message) {
   for (ProxiedPlayer p : ProxyServer.getInstance().getPlayers()) {
     sendMessageToTarget(p.getName(), message);
   }
   LoggingManager.log(message);
 }