Example #1
0
  @Override
  public void addInvite(String owner, String home, String target, Date expiry, String reason) {
    boolean inviteSet = false;

    ArrayList<InviteEntry> invites;
    if (this.inviteEntries.containsKey(owner.toLowerCase())) {
      invites = this.inviteEntries.get(owner.toLowerCase());
    } else {
      invites = new ArrayList<InviteEntry>();
    }

    for (int index = 0; index < invites.size(); index++) {
      InviteEntry thisInvite = invites.get(index);
      if (thisInvite.getInviteTarget().compareToIgnoreCase(target) == 0
          && thisInvite.getInviteHome().compareToIgnoreCase(home) == 0) {
        thisInvite.setInviteSource(owner);
        thisInvite.setInviteHome(home);
        thisInvite.setInviteTarget(target);
        thisInvite.setInviteExpires(expiry);
        thisInvite.setInviteReason(reason);
        invites.set(index, thisInvite);
        inviteSet = true;
      }
    }

    if (!inviteSet) {
      InviteEntry invite = new InviteEntry(owner, home, target, expiry, reason);
      invites.add(invite);
    }

    this.inviteEntries.put(owner.toLowerCase(), invites);

    updateInviteExpiry();
    saveInvites();
  }
Example #2
0
  @Override
  public void importInvites(ArrayList<InviteEntry> invites, boolean overwrite) {
    ArrayList<InviteEntry> playerInvites;

    updateInviteExpiry();

    for (InviteEntry thisEntry : invites) {
      // Get the ArrayList of invites for this player
      if (this.inviteEntries.containsKey(thisEntry.getInviteSource().toLowerCase())) {
        playerInvites = this.inviteEntries.get(thisEntry.getInviteSource().toLowerCase());
      } else {
        playerInvites = new ArrayList<InviteEntry>();
      }

      boolean inviteFound = false;

      for (int index = 0; index < playerInvites.size(); index++) {
        InviteEntry thisInvite = playerInvites.get(index);
        if (thisInvite.getInviteHome().compareToIgnoreCase(thisEntry.getInviteHome()) == 0
            && thisInvite.getInviteTarget().compareToIgnoreCase(thisEntry.getInviteTarget()) == 0) {
          // An existing home was found.
          if (overwrite) {
            thisInvite.setInviteSource(thisEntry.getInviteSource());
            thisInvite.setInviteHome(thisEntry.getInviteHome());
            thisInvite.setInviteTarget(thisEntry.getInviteTarget());
            thisInvite.setInviteExpires(thisEntry.getInviteExpires());
            thisInvite.setInviteReason(thisEntry.getInviteReason());
            playerInvites.set(index, thisInvite);
          }

          inviteFound = true;
        }
      }

      if (!inviteFound) {
        // No existing location found. Create new entry.
        InviteEntry newInvite =
            new InviteEntry(
                thisEntry.getInviteSource(),
                thisEntry.getInviteHome(),
                thisEntry.getInviteTarget(),
                thisEntry.getInviteExpires(),
                thisEntry.getInviteReason());
        playerInvites.add(newInvite);
      }

      // Replace the ArrayList in the homes HashMap
      this.inviteEntries.remove(thisEntry.getInviteSource().toLowerCase());
      this.inviteEntries.put(thisEntry.getInviteSource().toLowerCase(), playerInvites);
    }

    // Save
    updateInviteExpiry();
    saveInvites();
  }