From 7ebbf538f20055880bee5889a8441937cbd94b8d Mon Sep 17 00:00:00 2001 From: Eclipse Date: Sun, 11 Aug 2024 10:44:40 +0100 Subject: [PATCH] Improve exception messages for stackSize and maxDamage builder methods, and add proper method argument annotations for these methods --- .../geysermc/geyser/api/item/custom/CustomItemData.java | 5 +++-- .../geyser/api/item/custom/NonVanillaCustomItemData.java | 5 +++-- .../org/geysermc/geyser/item/GeyserCustomItemData.java | 8 ++++---- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/api/src/main/java/org/geysermc/geyser/api/item/custom/CustomItemData.java b/api/src/main/java/org/geysermc/geyser/api/item/custom/CustomItemData.java index e09e0c9b5..bbf7e1f1c 100644 --- a/api/src/main/java/org/geysermc/geyser/api/item/custom/CustomItemData.java +++ b/api/src/main/java/org/geysermc/geyser/api/item/custom/CustomItemData.java @@ -26,6 +26,7 @@ package org.geysermc.geyser.api.item.custom; import org.checkerframework.checker.index.qual.NonNegative; +import org.checkerframework.checker.index.qual.Positive; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.geyser.api.GeyserApi; @@ -226,9 +227,9 @@ public interface CustomItemData { Builder tags(@Nullable Set tags); - Builder stackSize(@NonNegative int stackSize); + Builder stackSize(@Positive int stackSize); - Builder maxDamage(int maxDamage); + Builder maxDamage(@NonNegative int maxDamage); Builder attackDamage(int attackDamage); diff --git a/api/src/main/java/org/geysermc/geyser/api/item/custom/NonVanillaCustomItemData.java b/api/src/main/java/org/geysermc/geyser/api/item/custom/NonVanillaCustomItemData.java index 98b4694c2..9718b0653 100644 --- a/api/src/main/java/org/geysermc/geyser/api/item/custom/NonVanillaCustomItemData.java +++ b/api/src/main/java/org/geysermc/geyser/api/item/custom/NonVanillaCustomItemData.java @@ -26,6 +26,7 @@ package org.geysermc.geyser.api.item.custom; import org.checkerframework.checker.index.qual.NonNegative; +import org.checkerframework.checker.index.qual.Positive; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.geyser.api.GeyserApi; @@ -142,10 +143,10 @@ public interface NonVanillaCustomItemData extends CustomItemData { Builder tags(@Nullable Set tags); @Override - Builder stackSize(@NonNegative int stackSize); + Builder stackSize(@Positive int stackSize); @Override - Builder maxDamage(int maxDamage); + Builder maxDamage(@NonNegative int maxDamage); @Override Builder attackDamage(int attackDamage); diff --git a/core/src/main/java/org/geysermc/geyser/item/GeyserCustomItemData.java b/core/src/main/java/org/geysermc/geyser/item/GeyserCustomItemData.java index 9762d78e5..b43b921c5 100644 --- a/core/src/main/java/org/geysermc/geyser/item/GeyserCustomItemData.java +++ b/core/src/main/java/org/geysermc/geyser/item/GeyserCustomItemData.java @@ -276,10 +276,10 @@ public class GeyserCustomItemData implements CustomItemData { @Override public Builder stackSize(int stackSize) { if (stackSize < 1) { - throw new IllegalArgumentException("Stack size cannot be below 1"); + throw new IllegalArgumentException("Stack size cannot be below 1 (" + stackSize + " was given)"); } else if (stackSize > 1) { if (this.maxDamage > 0) { - throw new IllegalStateException("Stack size cannot be above 1 when max damage is above 0"); + throw new IllegalArgumentException("Stack size cannot be above 1 when max damage is above 0 (" + stackSize + " was given)"); } // Explicitly set max damage to 0 instead of falling back to the Java vanilla item value this.maxDamage = 0; @@ -292,10 +292,10 @@ public class GeyserCustomItemData implements CustomItemData { @Override public Builder maxDamage(int maxDamage) { if (maxDamage < 0) { - throw new IllegalArgumentException("Max damage cannot be below 0"); + throw new IllegalArgumentException("Max damage cannot be below 0 (" + maxDamage + " was given)"); } else if (maxDamage > 0) { if (this.stackSize > 1) { - throw new IllegalStateException("Max damage cannot be above 0 when stack size is above 1"); + throw new IllegalArgumentException("Max damage cannot be above 0 when stack size is above 1 (" + maxDamage + " was given)"); } // Explicitly set stack size to 1 instead of falling back to the Java vanilla item value this.stackSize = 1;