mirror of
https://github.com/Samsuik/Sakura.git
synced 2025-12-23 00:39:20 +00:00
Update api to use jspecify and renamed some methods
This commit is contained in:
@@ -6,14 +6,15 @@ Subject: [PATCH] Merge Cannon Entities
|
||||
|
||||
diff --git a/src/main/java/me/samsuik/sakura/entity/merge/MergeLevel.java b/src/main/java/me/samsuik/sakura/entity/merge/MergeLevel.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..506ea3cb8c3b965661a65f9a91903999c1eba309
|
||||
index 0000000000000000000000000000000000000000..f8010a92ac82e76611ff7a9be259f11db0a1cc90
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/me/samsuik/sakura/entity/merge/MergeLevel.java
|
||||
@@ -0,0 +1,64 @@
|
||||
@@ -0,0 +1,42 @@
|
||||
+package me.samsuik.sakura.entity.merge;
|
||||
+
|
||||
+import java.util.Locale;
|
||||
+import org.jspecify.annotations.NullMarked;
|
||||
+
|
||||
+@NullMarked
|
||||
+public enum MergeLevel {
|
||||
+ /**
|
||||
+ * Disabled.
|
||||
@@ -44,50 +45,28 @@ index 0000000000000000000000000000000000000000..506ea3cb8c3b965661a65f9a91903999
|
||||
+ }
|
||||
+
|
||||
+ public boolean atLeast(MergeLevel level) {
|
||||
+ return getLevel() >= level.getLevel();
|
||||
+ return this.getLevel() >= level.getLevel();
|
||||
+ }
|
||||
+
|
||||
+ public int getLevel() {
|
||||
+ return level;
|
||||
+ }
|
||||
+
|
||||
+ public static MergeLevel from(int of) {
|
||||
+ for (MergeLevel t : values()) {
|
||||
+ if (t.getLevel() == of) {
|
||||
+ return t;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ return NONE;
|
||||
+ }
|
||||
+
|
||||
+ public static MergeLevel from(String string) {
|
||||
+ try {
|
||||
+ return from(Integer.parseInt(string));
|
||||
+ } catch (NumberFormatException ignored) {}
|
||||
+
|
||||
+ try {
|
||||
+ var name = string.toUpperCase(Locale.ROOT);
|
||||
+ return valueOf(name);
|
||||
+ } catch (IllegalArgumentException ignored) {}
|
||||
+
|
||||
+ return NONE;
|
||||
+ return this.level;
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/java/me/samsuik/sakura/entity/merge/Mergeable.java b/src/main/java/me/samsuik/sakura/entity/merge/Mergeable.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..c241a3a359cad1d7c2cdb690649e0cacc491508b
|
||||
index 0000000000000000000000000000000000000000..c33c461b10ff27bc5b0a294b61078c89cceae6b8
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/me/samsuik/sakura/entity/merge/Mergeable.java
|
||||
@@ -0,0 +1,13 @@
|
||||
@@ -0,0 +1,14 @@
|
||||
+package me.samsuik.sakura.entity.merge;
|
||||
+
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
+import org.jspecify.annotations.NullMarked;
|
||||
+
|
||||
+@NullMarked
|
||||
+public interface Mergeable {
|
||||
+ @NotNull MergeLevel getMergeLevel();
|
||||
+ MergeLevel getMergeLevel();
|
||||
+
|
||||
+ void setMergeLevel(@NotNull MergeLevel level);
|
||||
+ void setMergeLevel(MergeLevel level);
|
||||
+
|
||||
+ int getStacked();
|
||||
+
|
||||
|
||||
@@ -6,20 +6,26 @@ Subject: [PATCH] Local Value Storage API
|
||||
|
||||
diff --git a/src/main/java/me/samsuik/sakura/local/LocalRegion.java b/src/main/java/me/samsuik/sakura/local/LocalRegion.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..34a0755da6c471a51fb18a5e139af42df1362a93
|
||||
index 0000000000000000000000000000000000000000..6f76eae76ab40c0aa9e53d66df9af9827d067dda
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/me/samsuik/sakura/local/LocalRegion.java
|
||||
@@ -0,0 +1,36 @@
|
||||
@@ -0,0 +1,41 @@
|
||||
+package me.samsuik.sakura.local;
|
||||
+
|
||||
+import org.bukkit.Location;
|
||||
+import io.papermc.paper.math.Position;
|
||||
+import org.bukkit.util.Vector;
|
||||
+import org.jspecify.annotations.NullMarked;
|
||||
+
|
||||
+@NullMarked
|
||||
+public record LocalRegion(int minX, int minZ, int maxX, int maxZ) {
|
||||
+
|
||||
+ public static LocalRegion of(Location min, Location max) {
|
||||
+ public static LocalRegion of(Vector min, Vector max) {
|
||||
+ return of(min.getBlockX(), min.getBlockZ(), max.getBlockX(), max.getBlockZ());
|
||||
+ }
|
||||
+
|
||||
+ public static LocalRegion of(Position min, Position max) {
|
||||
+ return of(min.blockX(), min.blockZ(), max.blockX(), max.blockZ());
|
||||
+ }
|
||||
+
|
||||
+ public static LocalRegion of(int minX, int minZ, int maxX, int maxZ) {
|
||||
+ return new LocalRegion(
|
||||
+ Math.min(minX, maxX), Math.min(minZ, maxZ),
|
||||
@@ -32,59 +38,57 @@ index 0000000000000000000000000000000000000000..34a0755da6c471a51fb18a5e139af42d
|
||||
+ }
|
||||
+
|
||||
+ public boolean intersects(LocalRegion region) {
|
||||
+ return (minX < region.minX() && maxX > region.minX() || maxX > region.maxX() && minX < region.maxX())
|
||||
+ && (minZ < region.minZ() && maxZ > region.minZ() || maxZ > region.maxZ() && minZ < region.maxZ());
|
||||
+ return (this.minX < region.minX() && this.maxX > region.minX() || this.maxX > region.maxX() && this.minX < region.maxX())
|
||||
+ && (this.minZ < region.minZ() && this.maxZ > region.minZ() || this.maxZ > region.maxZ() && this.minZ < region.maxZ());
|
||||
+ }
|
||||
+
|
||||
+ public boolean contains(LocalRegion region) {
|
||||
+ return minX < region.minX() && maxX > region.maxX()
|
||||
+ && maxZ < region.minZ() && maxZ > region.maxZ();
|
||||
+ return this.minX < region.minX() && this.maxX > region.maxX()
|
||||
+ && this.maxZ < region.minZ() && this.maxZ > region.maxZ();
|
||||
+ }
|
||||
+
|
||||
+ public boolean contains(int x, int z) {
|
||||
+ return minX <= x && maxX >= x && minZ <= z && maxZ >= z;
|
||||
+ return this.minX <= x && this.maxX >= x && this.minZ <= z && this.maxZ >= z;
|
||||
+ }
|
||||
+
|
||||
+}
|
||||
diff --git a/src/main/java/me/samsuik/sakura/local/LocalValueKey.java b/src/main/java/me/samsuik/sakura/local/LocalValueKey.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..ee3057c7969956b9c552ac5ceb2f5e38a30e9cdf
|
||||
index 0000000000000000000000000000000000000000..adb2048a02e71433618b26a14f4c71f0e26fe943
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/me/samsuik/sakura/local/LocalValueKey.java
|
||||
@@ -0,0 +1,27 @@
|
||||
@@ -0,0 +1,26 @@
|
||||
+package me.samsuik.sakura.local;
|
||||
+
|
||||
+import org.bukkit.NamespacedKey;
|
||||
+import org.jspecify.annotations.NullMarked;
|
||||
+
|
||||
+import java.util.Objects;
|
||||
+import java.util.function.Supplier;
|
||||
+
|
||||
+@NullMarked
|
||||
+public record LocalValueKey<T>(NamespacedKey key, Supplier<T> defaultSupplier) {
|
||||
+
|
||||
+ // ...
|
||||
+
|
||||
+ @Override
|
||||
+ public boolean equals(Object o) {
|
||||
+ if (this == o) return true;
|
||||
+ if (o == null || getClass() != o.getClass()) return false;
|
||||
+ if (o == null || this.getClass() != o.getClass()) return false;
|
||||
+
|
||||
+ LocalValueKey<?> that = (LocalValueKey<?>) o;
|
||||
+
|
||||
+ return Objects.equals(key, that.key);
|
||||
+ return this.key.equals(that.key);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public int hashCode() {
|
||||
+ return key != null ? key.hashCode() : 0;
|
||||
+ return this.key.hashCode();
|
||||
+ }
|
||||
+
|
||||
+}
|
||||
diff --git a/src/main/java/me/samsuik/sakura/local/storage/LocalStorageHandler.java b/src/main/java/me/samsuik/sakura/local/storage/LocalStorageHandler.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..5c971fb4266f46de258767fccaf7fe55be467886
|
||||
index 0000000000000000000000000000000000000000..220a12eddf3aeaeb7adfd6404b5225e392439ca8
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/me/samsuik/sakura/local/storage/LocalStorageHandler.java
|
||||
@@ -0,0 +1,24 @@
|
||||
@@ -0,0 +1,22 @@
|
||||
+package me.samsuik.sakura.local.storage;
|
||||
+
|
||||
+import me.samsuik.sakura.local.LocalRegion;
|
||||
@@ -93,7 +97,6 @@ index 0000000000000000000000000000000000000000..5c971fb4266f46de258767fccaf7fe55
|
||||
+import java.util.List;
|
||||
+
|
||||
+public interface LocalStorageHandler {
|
||||
+
|
||||
+ LocalRegion locate(Location location, int searchDistance);
|
||||
+
|
||||
+ LocalRegion locate(int x, int z, int searchDistance);
|
||||
@@ -107,21 +110,23 @@ index 0000000000000000000000000000000000000000..5c971fb4266f46de258767fccaf7fe55
|
||||
+ void remove(LocalRegion region);
|
||||
+
|
||||
+ List<LocalRegion> regions();
|
||||
+
|
||||
+}
|
||||
diff --git a/src/main/java/me/samsuik/sakura/local/storage/LocalValueStorage.java b/src/main/java/me/samsuik/sakura/local/storage/LocalValueStorage.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..de18836d1a2a6038a661cdc60161d3bacdcb8bfe
|
||||
index 0000000000000000000000000000000000000000..791637f4c817b32e30b47a88adc5a525389cdcdd
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/me/samsuik/sakura/local/storage/LocalValueStorage.java
|
||||
@@ -0,0 +1,39 @@
|
||||
@@ -0,0 +1,42 @@
|
||||
+package me.samsuik.sakura.local.storage;
|
||||
+
|
||||
+import me.samsuik.sakura.local.LocalValueKey;
|
||||
+import org.jspecify.annotations.NullMarked;
|
||||
+
|
||||
+import java.util.HashMap;
|
||||
+import java.util.Map;
|
||||
+
|
||||
+@NullMarked
|
||||
+@SuppressWarnings("unchecked")
|
||||
+public final class LocalValueStorage {
|
||||
+ private final Map<LocalValueKey<?>, Object> map = new HashMap<>();
|
||||
+
|
||||
|
||||
@@ -5,7 +5,7 @@ Subject: [PATCH] Add physics version API
|
||||
|
||||
|
||||
diff --git a/src/main/java/me/samsuik/sakura/local/LocalValueKey.java b/src/main/java/me/samsuik/sakura/local/LocalValueKey.java
|
||||
index ee3057c7969956b9c552ac5ceb2f5e38a30e9cdf..58f220a3f48a8cc1a25249d4a56cf356dc2c9c99 100644
|
||||
index adb2048a02e71433618b26a14f4c71f0e26fe943..f80f7f299c2208c5160bcf763f686f7bd6375eec 100644
|
||||
--- a/src/main/java/me/samsuik/sakura/local/LocalValueKey.java
|
||||
+++ b/src/main/java/me/samsuik/sakura/local/LocalValueKey.java
|
||||
@@ -1,5 +1,6 @@
|
||||
@@ -13,11 +13,11 @@ index ee3057c7969956b9c552ac5ceb2f5e38a30e9cdf..58f220a3f48a8cc1a25249d4a56cf356
|
||||
|
||||
+import me.samsuik.sakura.physics.PhysicsVersion;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
import java.util.Objects;
|
||||
@@ -8,6 +9,9 @@ import java.util.function.Supplier;
|
||||
@@ -9,6 +10,9 @@ import java.util.function.Supplier;
|
||||
@NullMarked
|
||||
public record LocalValueKey<T>(NamespacedKey key, Supplier<T> defaultSupplier) {
|
||||
|
||||
// ...
|
||||
+ public static final LocalValueKey<PhysicsVersion> PHYSICS_VERSION = new LocalValueKey<>(
|
||||
+ new NamespacedKey("sakura", "physics-version"), () -> PhysicsVersion.LATEST
|
||||
@@ -27,18 +27,18 @@ index ee3057c7969956b9c552ac5ceb2f5e38a30e9cdf..58f220a3f48a8cc1a25249d4a56cf356
|
||||
public boolean equals(Object o) {
|
||||
diff --git a/src/main/java/me/samsuik/sakura/physics/PhysicsVersion.java b/src/main/java/me/samsuik/sakura/physics/PhysicsVersion.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..51aa1c9495170b51182cf76e9b6526d6e9c5287f
|
||||
index 0000000000000000000000000000000000000000..685fefb4ac36153f038b28452e3b29ded52cff07
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/me/samsuik/sakura/physics/PhysicsVersion.java
|
||||
@@ -0,0 +1,95 @@
|
||||
@@ -0,0 +1,74 @@
|
||||
+package me.samsuik.sakura.physics;
|
||||
+
|
||||
+public enum PhysicsVersion {
|
||||
+import org.jspecify.annotations.NullMarked;
|
||||
+
|
||||
+ // replicates patched 1.8.8 mechanics
|
||||
+ LEGACY("legacy", 1_0_0),
|
||||
+ // vanilla mechanics:
|
||||
+ v1_8_2("1.8.2", 1_8_2),
|
||||
+@NullMarked
|
||||
+public enum PhysicsVersion {
|
||||
+ LEGACY("legacy", 1_0_0), // replicates patched 1.8.8 paper mechanics
|
||||
+ v1_8_2("1.8.2", 1_8_2), // vanilla mechanics
|
||||
+ v1_9("1.9", 1_9_0),
|
||||
+ v1_10("1.10", 1_10_0),
|
||||
+ v1_11("1.11", 1_11_0),
|
||||
@@ -51,43 +51,7 @@ index 0000000000000000000000000000000000000000..51aa1c9495170b51182cf76e9b6526d6
|
||||
+ v1_19_3("1.19.3", 1_19_3),
|
||||
+ v1_20("1.20", 1_20_0),
|
||||
+ v1_21_2("1.21.2", 1_21_2),
|
||||
+ // refers to the latest mechanic version
|
||||
+ LATEST("latest", 9_99_9);
|
||||
+
|
||||
+ // utilities:
|
||||
+ public static PhysicsVersion of(String string) {
|
||||
+ for (PhysicsVersion ver : values()) {
|
||||
+ if (ver.getFriendlyName().equalsIgnoreCase(string)) {
|
||||
+ return ver;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ return null;
|
||||
+ }
|
||||
+
|
||||
+ public static PhysicsVersion closest(int formattedVersion) {
|
||||
+ PhysicsVersion found = null;
|
||||
+
|
||||
+ for (PhysicsVersion ver : values()) {
|
||||
+ if (formattedVersion >= ver.getVersion()) {
|
||||
+ found = ver;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ return found;
|
||||
+ }
|
||||
+
|
||||
+ public static PhysicsVersion closest(String provided) {
|
||||
+ // check for "legacy" or "latest"
|
||||
+ PhysicsVersion physicsVersion = of(provided);
|
||||
+
|
||||
+ if (physicsVersion != null) {
|
||||
+ return physicsVersion;
|
||||
+ }
|
||||
+
|
||||
+ String versionString = provided.replace(".", "");
|
||||
+ return closest(Integer.parseInt(versionString));
|
||||
+ }
|
||||
+ LATEST("latest", 9_99_9); // latest version
|
||||
+
|
||||
+ private final String friendlyName;
|
||||
+ private final int version;
|
||||
@@ -101,16 +65,16 @@ index 0000000000000000000000000000000000000000..51aa1c9495170b51182cf76e9b6526d6
|
||||
+ return this == LEGACY;
|
||||
+ }
|
||||
+
|
||||
+ public boolean afterOrEqual(int max) {
|
||||
+ return this.version >= max;
|
||||
+ public boolean afterOrEqual(int version) {
|
||||
+ return this.version >= version;
|
||||
+ }
|
||||
+
|
||||
+ public boolean before(int max) {
|
||||
+ return this.version < max;
|
||||
+ public boolean before(int version) {
|
||||
+ return this.version < version;
|
||||
+ }
|
||||
+
|
||||
+ public boolean is(int max) {
|
||||
+ return this.version == max;
|
||||
+ public boolean is(int version) {
|
||||
+ return this.version == version;
|
||||
+ }
|
||||
+
|
||||
+ public boolean isWithin(int min, int max) {
|
||||
@@ -125,4 +89,19 @@ index 0000000000000000000000000000000000000000..51aa1c9495170b51182cf76e9b6526d6
|
||||
+ return this.friendlyName;
|
||||
+ }
|
||||
+
|
||||
+ public static PhysicsVersion from(String string) {
|
||||
+ int parsedVersion = Integer.MIN_VALUE;
|
||||
+ try {
|
||||
+ String versionString = string.replace(".", "");
|
||||
+ parsedVersion = Integer.parseInt(versionString);
|
||||
+ } catch (NumberFormatException nfe) {
|
||||
+ // ignored
|
||||
+ }
|
||||
+ for (PhysicsVersion ver : values()) {
|
||||
+ if (ver.name().equalsIgnoreCase(string) || ver.getFriendlyName().equalsIgnoreCase(string) || ver.is(parsedVersion)) {
|
||||
+ return ver;
|
||||
+ }
|
||||
+ }
|
||||
+ return LATEST;
|
||||
+ }
|
||||
+}
|
||||
|
||||
@@ -5,22 +5,24 @@ Subject: [PATCH] Add durable material API
|
||||
|
||||
|
||||
diff --git a/src/main/java/me/samsuik/sakura/local/LocalValueKey.java b/src/main/java/me/samsuik/sakura/local/LocalValueKey.java
|
||||
index 58f220a3f48a8cc1a25249d4a56cf356dc2c9c99..4735e5d8dcea4835061b5cada9d601794efdf390 100644
|
||||
index f80f7f299c2208c5160bcf763f686f7bd6375eec..8a688431aaa56166afd2c95731220c0aba2147ed 100644
|
||||
--- a/src/main/java/me/samsuik/sakura/local/LocalValueKey.java
|
||||
+++ b/src/main/java/me/samsuik/sakura/local/LocalValueKey.java
|
||||
@@ -1,8 +1,11 @@
|
||||
@@ -1,10 +1,12 @@
|
||||
package me.samsuik.sakura.local;
|
||||
|
||||
import me.samsuik.sakura.physics.PhysicsVersion;
|
||||
+import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
-import java.util.Objects;
|
||||
+import java.util.HashMap;
|
||||
+import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@@ -13,6 +16,10 @@ public record LocalValueKey<T>(NamespacedKey key, Supplier<T> defaultSupplier) {
|
||||
@NullMarked
|
||||
@@ -14,6 +16,10 @@ public record LocalValueKey<T>(NamespacedKey key, Supplier<T> defaultSupplier) {
|
||||
new NamespacedKey("sakura", "physics-version"), () -> PhysicsVersion.LATEST
|
||||
);
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ Subject: [PATCH] Add redstone implementation API
|
||||
|
||||
|
||||
diff --git a/src/main/java/me/samsuik/sakura/local/LocalValueKey.java b/src/main/java/me/samsuik/sakura/local/LocalValueKey.java
|
||||
index 4735e5d8dcea4835061b5cada9d601794efdf390..098ce4d0356fb1dddbd4e34c02f77848da1fb546 100644
|
||||
index 8a688431aaa56166afd2c95731220c0aba2147ed..346f6392c82ff27ec4439c645948337ce1832ba3 100644
|
||||
--- a/src/main/java/me/samsuik/sakura/local/LocalValueKey.java
|
||||
+++ b/src/main/java/me/samsuik/sakura/local/LocalValueKey.java
|
||||
@@ -1,6 +1,7 @@
|
||||
@@ -15,7 +15,7 @@ index 4735e5d8dcea4835061b5cada9d601794efdf390..098ce4d0356fb1dddbd4e34c02f77848
|
||||
+import me.samsuik.sakura.redstone.RedstoneImplementation;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
@@ -20,6 +21,10 @@ public record LocalValueKey<T>(NamespacedKey key, Supplier<T> defaultSupplier) {
|
||||
new NamespacedKey("sakura", "durable-materials"), HashMap::new
|
||||
);
|
||||
@@ -29,14 +29,16 @@ index 4735e5d8dcea4835061b5cada9d601794efdf390..098ce4d0356fb1dddbd4e34c02f77848
|
||||
if (this == o) return true;
|
||||
diff --git a/src/main/java/me/samsuik/sakura/redstone/RedstoneImplementation.java b/src/main/java/me/samsuik/sakura/redstone/RedstoneImplementation.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..f89b5112d98d351435c63b27c64b1a981b8a820f
|
||||
index 0000000000000000000000000000000000000000..bfb5e9ec99dfdd6f4664ddb8191496706bc0d2a1
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/me/samsuik/sakura/redstone/RedstoneImplementation.java
|
||||
@@ -0,0 +1,19 @@
|
||||
@@ -0,0 +1,20 @@
|
||||
+package me.samsuik.sakura.redstone;
|
||||
+
|
||||
+public enum RedstoneImplementation {
|
||||
+import org.jspecify.annotations.NullMarked;
|
||||
+
|
||||
+@NullMarked
|
||||
+public enum RedstoneImplementation {
|
||||
+ VANILLA("vanilla"),
|
||||
+ EIGENCRAFT("eigencraft"),
|
||||
+ ALTERNATE_CURRENT("alternate-current");
|
||||
@@ -48,7 +50,6 @@ index 0000000000000000000000000000000000000000..f89b5112d98d351435c63b27c64b1a98
|
||||
+ }
|
||||
+
|
||||
+ public String getFriendlyName() {
|
||||
+ return friendlyName;
|
||||
+ return this.friendlyName;
|
||||
+ }
|
||||
+
|
||||
+}
|
||||
|
||||
Reference in New Issue
Block a user