Exemplo n.º 1
0
  public Vector<Claim> getClaims() {
    if (this.claims == null) {
      int totalClaimsArea = 0;
      this.claims = new Vector<Claim>();

      // find all the claims belonging to this player and note them for
      // future reference
      for (final Claim claim : GriefPreventionPlus.getInstance().getDataStore().claims.values()) {
        if (this.playerID.equals(claim.getOwnerID())) {
          this.claims.add(claim);
          totalClaimsArea += claim.getArea();
        }
      }

      // ensure player has claim blocks for his claims, and at least the
      // minimum accrued
      this.loadDataFromSecondaryStorage();

      // if total claimed area is more than total blocks available
      int totalBlocks =
          this.accruedClaimBlocks
              + this.getBonusClaimBlocks()
              + GriefPreventionPlus.getInstance().getDataStore().getGroupBonusBlocks(this.playerID);
      if (totalBlocks < totalClaimsArea) {
        // try to fix it by adding to accrued blocks
        this.accruedClaimBlocks = totalClaimsArea;
        if (this.accruedClaimBlocks
            > GriefPreventionPlus.getInstance().config.claims_maxAccruedBlocks) {
          // remember to respect the maximum on accrued blocks
          this.accruedClaimBlocks =
              GriefPreventionPlus.getInstance().config.claims_maxAccruedBlocks;
        }

        // if that didn't fix it, then make up the difference with bonus
        // blocks
        totalBlocks =
            this.accruedClaimBlocks
                + this.getBonusClaimBlocks()
                + GriefPreventionPlus.getInstance()
                    .getDataStore()
                    .getGroupBonusBlocks(this.playerID);
        if (totalBlocks < totalClaimsArea) {
          this.bonusClaimBlocks += totalClaimsArea - totalBlocks;
        }
      }
    }

    return this.claims;
  }
Exemplo n.º 2
0
 public Date getLastLogin() {
   return new Date(
       GriefPreventionPlus.getInstance()
           .getServer()
           .getOfflinePlayer(this.playerID)
           .getLastPlayed());
 }
Exemplo n.º 3
0
  // don't load data from secondary storage until it's needed
  public int getAccruedClaimBlocks() {
    if (this.accruedClaimBlocks == null) {
      this.loadDataFromSecondaryStorage();
    }

    // move any in the holding area
    int newTotal = this.accruedClaimBlocks + this.newlyAccruedClaimBlocks;
    this.newlyAccruedClaimBlocks = 0;

    // respect limits
    if (newTotal > GriefPreventionPlus.getInstance().config.claims_maxAccruedBlocks) {
      newTotal = GriefPreventionPlus.getInstance().config.claims_maxAccruedBlocks;
    }
    this.accruedClaimBlocks = newTotal;

    return this.accruedClaimBlocks;
  }
Exemplo n.º 4
0
 void initLastLocation() {
   final Player player = GriefPreventionPlus.getInstance().getServer().getPlayer(this.playerID);
   if (player == null) {
     return;
   }
   this.lastX = player.getLocation().getBlockX();
   this.lastZ = player.getLocation().getBlockZ();
   this.lastWorld = player.getLocation().getWorld().getUID();
 }
Exemplo n.º 5
0
  // the number of claim blocks a player has available for claiming land
  public int getRemainingClaimBlocks() {
    // accrued blocks + bonus blocks + permission bonus blocks
    int remainingBlocks =
        this.getAccruedClaimBlocks()
            + this.getBonusClaimBlocks()
            + GriefPreventionPlus.getInstance().getDataStore().getGroupBonusBlocks(this.playerID);
    for (final Claim claim : this.getClaims()) {
      remainingBlocks -= claim.getArea();
    }

    return remainingBlocks;
  }
Exemplo n.º 6
0
  private void loadDataFromSecondaryStorage() {
    // reach out to secondary storage to get any data there
    PlayerData storageData =
        GriefPreventionPlus.getInstance().getDataStore().getPlayerDataFromStorage(this.playerID);

    if (storageData == null) {
      // initialize new player data
      storageData = new PlayerData(this.playerID);

      // shove that new player data into the hash map cache
      GriefPreventionPlus.getInstance()
          .getDataStore()
          .playerNameToPlayerDataMap
          .put(this.playerID, storageData);
    }

    if (this.accruedClaimBlocks == null) {
      if (storageData.accruedClaimBlocks != null) {
        this.accruedClaimBlocks = storageData.accruedClaimBlocks;
        // ensure at least minimum accrued are accrued (in case of
        // settings changes to increase initial amount)
        if (this.accruedClaimBlocks
            < GriefPreventionPlus.getInstance().config.claims_initialBlocks) {
          this.accruedClaimBlocks = GriefPreventionPlus.getInstance().config.claims_initialBlocks;
        }
      } else {
        this.accruedClaimBlocks = GriefPreventionPlus.getInstance().config.claims_initialBlocks;
      }
    }

    if (this.bonusClaimBlocks == null) {
      if (storageData.bonusClaimBlocks != null) {
        this.bonusClaimBlocks = storageData.bonusClaimBlocks;
      } else {
        this.bonusClaimBlocks = 0;
      }
    }
  }
Exemplo n.º 7
0
  // whether or not this player is "in" pvp combat
  public boolean inPvpCombat() {
    if (this.lastPvpTimestamp == 0) {
      return false;
    }

    final long now = Calendar.getInstance().getTimeInMillis();

    final long elapsed = now - this.lastPvpTimestamp;

    if (elapsed > (GriefPreventionPlus.getInstance().config.pvp_combatTimeoutSeconds * 1000)) // X
    // seconds
    {
      this.lastPvpTimestamp = 0;
      return false;
    }

    return true;
  }
Exemplo n.º 8
0
 public long getTimeLastLogin() {
   return GriefPreventionPlus.getInstance()
       .getServer()
       .getOfflinePlayer(this.playerID)
       .getLastPlayed();
 }