From ee1a5c567b686d07c7dedb54331a53f12fdb322d Mon Sep 17 00:00:00 2001 From: Frank van der Heijden <22407829+FrankHeijden@users.noreply.github.com> Date: Thu, 6 Aug 2020 17:27:24 +0200 Subject: [PATCH] DataStore#getChunkHash is publicly accessible (#943) --- .../ryanhamshire/GriefPrevention/Claim.java | 16 +----------- .../GriefPrevention/DataStore.java | 26 +++++++++++++++++-- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/main/java/me/ryanhamshire/GriefPrevention/Claim.java b/src/main/java/me/ryanhamshire/GriefPrevention/Claim.java index 5f266cf..7c9219c 100644 --- a/src/main/java/me/ryanhamshire/GriefPrevention/Claim.java +++ b/src/main/java/me/ryanhamshire/GriefPrevention/Claim.java @@ -976,20 +976,6 @@ public class Claim ArrayList getChunkHashes() { - ArrayList hashes = new ArrayList(); - int smallX = this.getLesserBoundaryCorner().getBlockX() >> 4; - int smallZ = this.getLesserBoundaryCorner().getBlockZ() >> 4; - int largeX = this.getGreaterBoundaryCorner().getBlockX() >> 4; - int largeZ = this.getGreaterBoundaryCorner().getBlockZ() >> 4; - - for (int x = smallX; x <= largeX; x++) - { - for (int z = smallZ; z <= largeZ; z++) - { - hashes.add(DataStore.getChunkHash(x, z)); - } - } - - return hashes; + return DataStore.getChunkHashes(this); } } diff --git a/src/main/java/me/ryanhamshire/GriefPrevention/DataStore.java b/src/main/java/me/ryanhamshire/GriefPrevention/DataStore.java index 6f74f05..a23ca2f 100644 --- a/src/main/java/me/ryanhamshire/GriefPrevention/DataStore.java +++ b/src/main/java/me/ryanhamshire/GriefPrevention/DataStore.java @@ -785,17 +785,39 @@ public abstract class DataStore } //gets an almost-unique, persistent identifier for a chunk - static Long getChunkHash(long chunkx, long chunkz) + public static Long getChunkHash(long chunkx, long chunkz) { return (chunkz ^ (chunkx << 32)); } //gets an almost-unique, persistent identifier for a chunk - static Long getChunkHash(Location location) + public static Long getChunkHash(Location location) { return getChunkHash(location.getBlockX() >> 4, location.getBlockZ() >> 4); } + public static ArrayList getChunkHashes(Claim claim) { + return getChunkHashes(claim.getLesserBoundaryCorner(), claim.getGreaterBoundaryCorner()); + } + + public static ArrayList getChunkHashes(Location min, Location max) { + ArrayList hashes = new ArrayList<>(); + int smallX = min.getBlockX() >> 4; + int smallZ = min.getBlockZ() >> 4; + int largeX = max.getBlockX() >> 4; + int largeZ = max.getBlockZ() >> 4; + + for (int x = smallX; x <= largeX; x++) + { + for (int z = smallZ; z <= largeZ; z++) + { + hashes.add(getChunkHash(x, z)); + } + } + + return hashes; + } + /* * Creates a claim and flags it as being new....throwing a create claim event; */