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 bbf7e1f1c..0f80aae0a 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 @@ -125,8 +125,7 @@ public interface CustomItemData { * * @return the stack size of the item */ - @NonNegative - int stackSize(); + @NonNegative int stackSize(); /** * Gets the max damage of the item. @@ -147,7 +146,7 @@ public interface CustomItemData { * * @return the attack damage of the item */ - int attackDamage(); + @NonNegative int attackDamage(); /** * Gets the armor type of the item. @@ -166,7 +165,7 @@ public interface CustomItemData { * * @return the armor protection value of the item */ - int protectionValue(); + @NonNegative int protectionValue(); /** * Gets if the item is a hat. This is used to determine if the item should be rendered on the player's head, and @@ -231,11 +230,11 @@ public interface CustomItemData { Builder maxDamage(@NonNegative int maxDamage); - Builder attackDamage(int attackDamage); + Builder attackDamage(@NonNegative int attackDamage); Builder armorType(@Nullable String armorType); - Builder protectionValue(int protectionValue); + Builder protectionValue(@NonNegative int protectionValue); Builder hat(boolean isHat); 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 9718b0653..51d6a984c 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 @@ -149,13 +149,13 @@ public interface NonVanillaCustomItemData extends CustomItemData { Builder maxDamage(@NonNegative int maxDamage); @Override - Builder attackDamage(int attackDamage); + Builder attackDamage(@NonNegative int attackDamage); @Override Builder armorType(@Nullable String armorType); @Override - Builder protectionValue(int protectionValue); + Builder protectionValue(@NonNegative int protectionValue); @Override Builder hat(boolean isHat); 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 b43b921c5..6fb020729 100644 --- a/core/src/main/java/org/geysermc/geyser/item/GeyserCustomItemData.java +++ b/core/src/main/java/org/geysermc/geyser/item/GeyserCustomItemData.java @@ -27,6 +27,8 @@ package org.geysermc.geyser.item; import lombok.EqualsAndHashCode; import lombok.ToString; +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.item.custom.CustomItemData; @@ -274,7 +276,7 @@ public class GeyserCustomItemData implements CustomItemData { } @Override - public Builder stackSize(int stackSize) { + public Builder stackSize(@Positive int stackSize) { if (stackSize < 1) { throw new IllegalArgumentException("Stack size cannot be below 1 (" + stackSize + " was given)"); } else if (stackSize > 1) { @@ -290,7 +292,7 @@ public class GeyserCustomItemData implements CustomItemData { } @Override - public Builder maxDamage(int maxDamage) { + public Builder maxDamage(@NonNegative int maxDamage) { if (maxDamage < 0) { throw new IllegalArgumentException("Max damage cannot be below 0 (" + maxDamage + " was given)"); } else if (maxDamage > 0) { @@ -306,7 +308,10 @@ public class GeyserCustomItemData implements CustomItemData { } @Override - public Builder attackDamage(int attackDamage) { + public Builder attackDamage(@NonNegative int attackDamage) { + if (attackDamage < 0) { + throw new IllegalArgumentException("Protection value cannot be below 0 (" + attackDamage + " was given)"); + } this.attackDamage = attackDamage; return this; } @@ -318,7 +323,10 @@ public class GeyserCustomItemData implements CustomItemData { } @Override - public Builder protectionValue(int protectionValue) { + public Builder protectionValue(@NonNegative int protectionValue) { + if (protectionValue < 0) { + throw new IllegalArgumentException("Protection value cannot be below 0 (" + protectionValue + " was given)"); + } this.protectionValue = protectionValue; return this; } diff --git a/core/src/main/java/org/geysermc/geyser/item/GeyserNonVanillaCustomItemData.java b/core/src/main/java/org/geysermc/geyser/item/GeyserNonVanillaCustomItemData.java index c5ac4f68e..5ae41479c 100644 --- a/core/src/main/java/org/geysermc/geyser/item/GeyserNonVanillaCustomItemData.java +++ b/core/src/main/java/org/geysermc/geyser/item/GeyserNonVanillaCustomItemData.java @@ -27,6 +27,8 @@ package org.geysermc.geyser.item; import lombok.EqualsAndHashCode; import lombok.ToString; +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.item.custom.CustomItemOptions; @@ -167,17 +169,17 @@ public final class GeyserNonVanillaCustomItemData extends GeyserCustomItemData i } @Override - public Builder stackSize(int stackSize) { + public Builder stackSize(@Positive int stackSize) { return (Builder) super.stackSize(stackSize); } @Override - public Builder maxDamage(int maxDamage) { + public Builder maxDamage(@NonNegative int maxDamage) { return (Builder) super.maxDamage(maxDamage); } @Override - public Builder attackDamage(int attackDamage) { + public Builder attackDamage(@NonNegative int attackDamage) { return (Builder) super.attackDamage(attackDamage); } @@ -187,7 +189,7 @@ public final class GeyserNonVanillaCustomItemData extends GeyserCustomItemData i } @Override - public Builder protectionValue(int protectionValue) { + public Builder protectionValue(@NonNegative int protectionValue) { return (Builder) super.protectionValue(protectionValue); }