mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Improve exception messages for stackSize and maxDamage builder methods, and add proper method argument annotations for these methods
This commit is contained in:
parent
7394cf5a18
commit
7ebbf538f2
3 changed files with 10 additions and 8 deletions
|
@ -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<String> tags);
|
||||
|
||||
Builder stackSize(@NonNegative int stackSize);
|
||||
Builder stackSize(@Positive int stackSize);
|
||||
|
||||
Builder maxDamage(int maxDamage);
|
||||
Builder maxDamage(@NonNegative int maxDamage);
|
||||
|
||||
Builder attackDamage(int attackDamage);
|
||||
|
||||
|
|
|
@ -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<String> 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);
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue