Пример #1
0
 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;
   }
 }
Пример #2
0
 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;
 }
Пример #3
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;
  }
Пример #4
0
  @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;
  }