Skip to content

Commit

Permalink
Merge branch 'GriefPrevention:master' into update
Browse files Browse the repository at this point in the history
  • Loading branch information
SrBedrock authored Oct 8, 2024
2 parents d2f108f + c6c8aa4 commit ac6dd29
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
29 changes: 14 additions & 15 deletions src/main/java/me/ryanhamshire/GriefPrevention/DataStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ public abstract class DataStore

//in-memory cache for claim data
ArrayList<Claim> claims = new ArrayList<>();
// claim id to claim cache
public final Map<Long, Claim> claimIDMap = new ConcurrentHashMap<>();
ConcurrentHashMap<Long, ArrayList<Claim>> chunksToClaimsMap = new ConcurrentHashMap<>();

//in-memory cache for messages
Expand Down Expand Up @@ -447,6 +449,11 @@ synchronized void addClaim(Claim newClaim, boolean writeToStorage)

//add it and mark it as added
this.claims.add(newClaim);
this.claimIDMap.put(newClaim.id, newClaim);
for (Claim child : newClaim.children)
{
this.claimIDMap.put(child.id, child);
}
addToChunkClaimMap(newClaim);

newClaim.inDataStore = true;
Expand Down Expand Up @@ -653,6 +660,12 @@ synchronized void deleteClaim(Claim claim, boolean fireEvent, boolean ignored)
}
}

claimIDMap.remove(claim.id);
for (Claim child : claim.children)
{
claimIDMap.remove(child.id);
}

removeFromChunkClaimMap(claim);

//remove from secondary storage
Expand Down Expand Up @@ -740,21 +753,7 @@ synchronized public Claim getClaimAt(Location location, boolean ignoreHeight, bo
//finds a claim by ID
public synchronized Claim getClaim(long id)
{
for (Claim claim : this.claims)
{
if (claim.inDataStore)
{
if (claim.getID() == id)
return claim;
for (Claim subClaim : claim.children)
{
if (subClaim.getID() == id)
return subClaim;
}
}
}

return null;
return this.claimIDMap.get(id);
}

//returns a read-only access point for the list of all land claims
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/me/ryanhamshire/GriefPrevention/PlayerData.java
Original file line number Diff line number Diff line change
Expand Up @@ -255,12 +255,22 @@ public Vector<Claim> getClaims()
Claim claim = dataStore.claims.get(i);
if (!claim.inDataStore)
{
dataStore.claims.remove(i--);
Claim remove = dataStore.claims.remove(i--);
dataStore.claimIDMap.remove(remove.getID());
for (Claim child : remove.children)
{
dataStore.claimIDMap.remove(child.getID());
}
continue;
}
if (playerID.equals(claim.ownerID))
{
this.claims.add(claim);
dataStore.claimIDMap.put(claim.getID(), claim);
for (Claim child : claim.children)
{
dataStore.claimIDMap.put(child.getID(), child);
}
totalClaimsArea += claim.getArea();
}
}
Expand Down

0 comments on commit ac6dd29

Please sign in to comment.