mirror of
https://github.com/PaperMC/Paper.git
synced 2025-12-05 04:54:44 +01:00
Merge c643f5ecb2 into 84a789b263
This commit is contained in:
commit
73404172ac
@ -2,6 +2,7 @@ package io.papermc.paper.datacomponent.item;
|
||||
|
||||
import io.papermc.paper.datacomponent.DataComponentBuilder;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import org.checkerframework.checker.index.qual.Positive;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
@ -23,7 +24,7 @@ public interface UseCooldown {
|
||||
* @return builder
|
||||
*/
|
||||
@Contract(value = "_ -> new", pure = true)
|
||||
static UseCooldown.Builder useCooldown(final float seconds) {
|
||||
static UseCooldown.Builder useCooldown(@Positive final float seconds) {
|
||||
return ItemComponentTypesBridge.bridge().useCooldown(seconds);
|
||||
}
|
||||
|
||||
@ -33,6 +34,7 @@ public interface UseCooldown {
|
||||
* @return cooldown seconds
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
@Positive
|
||||
float seconds();
|
||||
|
||||
/**
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
package io.papermc.paper.datacomponent.item;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import io.papermc.paper.adventure.PaperAdventure;
|
||||
import io.papermc.paper.datacomponent.item.blocksattacks.DamageReduction;
|
||||
import io.papermc.paper.datacomponent.item.blocksattacks.ItemDamageFunction;
|
||||
@ -16,6 +15,8 @@ import org.bukkit.craftbukkit.util.Handleable;
|
||||
import org.bukkit.damage.DamageType;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import static io.papermc.paper.registry.data.util.Checks.requireArgumentNonNegative;
|
||||
|
||||
public record PaperBlocksAttacks(
|
||||
net.minecraft.world.item.component.BlocksAttacks impl
|
||||
) implements BlocksAttacks, Handleable<net.minecraft.world.item.component.BlocksAttacks> {
|
||||
@ -73,15 +74,13 @@ public record PaperBlocksAttacks(
|
||||
|
||||
@Override
|
||||
public Builder blockDelaySeconds(final float delay) {
|
||||
Preconditions.checkArgument(delay >= 0, "delay must be non-negative, was %s", delay);
|
||||
this.blockDelaySeconds = delay;
|
||||
this.blockDelaySeconds = requireArgumentNonNegative(delay, "delay");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder disableCooldownScale(final float scale) {
|
||||
Preconditions.checkArgument(scale >= 0, "scale must be non-negative, was %s", scale);
|
||||
this.disableCooldownScale = scale;
|
||||
this.disableCooldownScale = requireArgumentNonNegative(scale, "scale");
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
package io.papermc.paper.datacomponent.item;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import io.papermc.paper.adventure.PaperAdventure;
|
||||
import io.papermc.paper.datacomponent.item.consumable.ConsumeEffect;
|
||||
import io.papermc.paper.datacomponent.item.consumable.ItemUseAnimation;
|
||||
@ -16,6 +15,8 @@ import org.bukkit.craftbukkit.util.Handleable;
|
||||
import org.checkerframework.checker.index.qual.NonNegative;
|
||||
import org.jetbrains.annotations.Unmodifiable;
|
||||
|
||||
import static io.papermc.paper.registry.data.util.Checks.requireArgumentNonNegative;
|
||||
|
||||
public record PaperConsumable(
|
||||
net.minecraft.world.item.component.Consumable impl
|
||||
) implements Consumable, Handleable<net.minecraft.world.item.component.Consumable> {
|
||||
@ -73,8 +74,7 @@ public record PaperConsumable(
|
||||
|
||||
@Override
|
||||
public Builder consumeSeconds(final @NonNegative float consumeSeconds) {
|
||||
Preconditions.checkArgument(consumeSeconds >= 0, "consumeSeconds must be non-negative, was %s", consumeSeconds);
|
||||
this.consumeSeconds = consumeSeconds;
|
||||
this.consumeSeconds = requireArgumentNonNegative(consumeSeconds, "consumeSeconds");
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package io.papermc.paper.datacomponent.item;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import io.papermc.paper.registry.RegistryKey;
|
||||
import io.papermc.paper.registry.data.util.Checks;
|
||||
import io.papermc.paper.registry.data.util.Conversions;
|
||||
import io.papermc.paper.registry.set.PaperRegistrySets;
|
||||
import io.papermc.paper.registry.set.RegistryKeySet;
|
||||
@ -17,6 +17,9 @@ import org.bukkit.craftbukkit.util.Handleable;
|
||||
import org.jetbrains.annotations.Unmodifiable;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import static io.papermc.paper.registry.data.util.Checks.requireArgumentNonNegative;
|
||||
import static io.papermc.paper.registry.data.util.Checks.requireArgumentPositive;
|
||||
|
||||
public record PaperItemTool(
|
||||
net.minecraft.world.item.component.Tool impl
|
||||
) implements Tool, Handleable<net.minecraft.world.item.component.Tool> {
|
||||
@ -57,8 +60,7 @@ public record PaperItemTool(
|
||||
record PaperRule(RegistryKeySet<BlockType> blocks, @Nullable Float speed, TriState correctForDrops) implements Rule {
|
||||
|
||||
public static PaperRule fromUnsafe(final RegistryKeySet<BlockType> blocks, final @Nullable Float speed, final TriState correctForDrops) {
|
||||
Preconditions.checkArgument(speed == null || speed > 0, "speed must be positive");
|
||||
return new PaperRule(blocks, speed, correctForDrops);
|
||||
return new PaperRule(blocks, (speed == null) ? null : requireArgumentPositive(speed, "speed"), correctForDrops);
|
||||
}
|
||||
}
|
||||
|
||||
@ -71,8 +73,7 @@ public record PaperItemTool(
|
||||
|
||||
@Override
|
||||
public Builder damagePerBlock(final int damage) {
|
||||
Preconditions.checkArgument(damage >= 0, "damage must be non-negative, was %s", damage);
|
||||
this.damage = damage;
|
||||
this.damage = Checks.requireArgumentNonNegative(damage, "damage");
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@ -7,6 +7,8 @@ import net.minecraft.resources.Identifier;
|
||||
import org.bukkit.craftbukkit.util.Handleable;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import static io.papermc.paper.registry.data.util.Checks.requireArgumentPositive;
|
||||
|
||||
public record PaperUseCooldown(
|
||||
net.minecraft.world.item.component.UseCooldown impl
|
||||
) implements UseCooldown, Handleable<net.minecraft.world.item.component.UseCooldown> {
|
||||
@ -34,7 +36,7 @@ public record PaperUseCooldown(
|
||||
private Optional<Identifier> cooldownGroup = Optional.empty();
|
||||
|
||||
BuilderImpl(final float seconds) {
|
||||
this.seconds = seconds;
|
||||
this.seconds = requireArgumentPositive(seconds, "seconds");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
package io.papermc.paper.datacomponent.item;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import io.papermc.paper.registry.data.util.Checks;
|
||||
import org.bukkit.craftbukkit.util.Handleable;
|
||||
|
||||
import static io.papermc.paper.registry.data.util.Checks.requireArgumentNonNegative;
|
||||
|
||||
public record PaperWeapon(
|
||||
net.minecraft.world.item.component.Weapon impl
|
||||
) implements Weapon, Handleable<net.minecraft.world.item.component.Weapon> {
|
||||
@ -29,15 +31,13 @@ public record PaperWeapon(
|
||||
|
||||
@Override
|
||||
public Builder itemDamagePerAttack(final int damage) {
|
||||
Preconditions.checkArgument(damage >= 0, "damage must be non-negative, was %s", damage);
|
||||
this.itemDamagePerAttack = damage;
|
||||
this.itemDamagePerAttack = Checks.requireArgumentNonNegative(damage, "damage");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder disableBlockingForSeconds(final float seconds) {
|
||||
Preconditions.checkArgument(seconds >= 0, "seconds must be non-negative, was %s", seconds);
|
||||
this.disableBlockingForSeconds = seconds;
|
||||
this.disableBlockingForSeconds = requireArgumentNonNegative(seconds, "seconds");
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
package io.papermc.paper.datacomponent.item.blocksattacks;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import io.papermc.paper.registry.RegistryKey;
|
||||
import io.papermc.paper.registry.data.util.Conversions;
|
||||
import io.papermc.paper.registry.set.PaperRegistrySets;
|
||||
@ -12,6 +11,8 @@ import org.bukkit.damage.DamageType;
|
||||
import org.checkerframework.checker.index.qual.Positive;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import static io.papermc.paper.registry.data.util.Checks.requireArgumentPositive;
|
||||
|
||||
public record PaperDamageReduction(
|
||||
net.minecraft.world.item.component.BlocksAttacks.DamageReduction internal
|
||||
) implements DamageReduction {
|
||||
@ -52,8 +53,7 @@ public record PaperDamageReduction(
|
||||
|
||||
@Override
|
||||
public Builder horizontalBlockingAngle(final @Positive float horizontalBlockingAngle) {
|
||||
Preconditions.checkArgument(horizontalBlockingAngle > 0, "horizontalBlockingAngle must be positive and not zero, was %s", horizontalBlockingAngle);
|
||||
this.horizontalBlockingAngle = horizontalBlockingAngle;
|
||||
this.horizontalBlockingAngle = requireArgumentPositive(horizontalBlockingAngle, "horizontalBlockingAngle");
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@ -1,9 +1,10 @@
|
||||
package io.papermc.paper.datacomponent.item.blocksattacks;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import net.minecraft.world.item.component.BlocksAttacks;
|
||||
import org.checkerframework.checker.index.qual.NonNegative;
|
||||
|
||||
import static io.papermc.paper.registry.data.util.Checks.requireArgumentNonNegative;
|
||||
|
||||
public record PaperItemDamageFunction(
|
||||
net.minecraft.world.item.component.BlocksAttacks.ItemDamageFunction internal
|
||||
) implements ItemDamageFunction {
|
||||
@ -36,8 +37,7 @@ public record PaperItemDamageFunction(
|
||||
|
||||
@Override
|
||||
public Builder threshold(final @NonNegative float threshold) {
|
||||
Preconditions.checkArgument(threshold >= 0, "threshold must be non-negative, was %s", threshold);
|
||||
this.threshold = threshold;
|
||||
this.threshold = requireArgumentNonNegative(threshold, "threshold");
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
package io.papermc.paper.datacomponent.item.consumable;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.Lists;
|
||||
import io.papermc.paper.adventure.PaperAdventure;
|
||||
import io.papermc.paper.registry.data.util.Conversions;
|
||||
@ -15,16 +14,18 @@ import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
import static io.papermc.paper.registry.data.util.Checks.requireArgumentMinInclusive;
|
||||
import static io.papermc.paper.registry.data.util.Checks.requireArgumentPositive;
|
||||
|
||||
@NullMarked
|
||||
public class ConsumableTypesBridgeImpl implements ConsumableTypesBridge {
|
||||
|
||||
@Override
|
||||
public ConsumeEffect.ApplyStatusEffects applyStatusEffects(final List<PotionEffect> effectList, final float probability) {
|
||||
Preconditions.checkArgument(0 <= probability && probability <= 1, "probability must be between 0-1, was %s", probability);
|
||||
return new PaperApplyStatusEffects(
|
||||
new net.minecraft.world.item.consume_effects.ApplyStatusEffectsConsumeEffect(
|
||||
new ArrayList<>(Lists.transform(effectList, CraftPotionUtil::fromBukkit)),
|
||||
probability
|
||||
requireArgumentMinInclusive(probability, "probability", 0.0F, 1.0F)
|
||||
)
|
||||
);
|
||||
}
|
||||
@ -52,9 +53,8 @@ public class ConsumableTypesBridgeImpl implements ConsumableTypesBridge {
|
||||
|
||||
@Override
|
||||
public ConsumeEffect.TeleportRandomly teleportRandomlyEffect(final float diameter) {
|
||||
Preconditions.checkArgument(diameter > 0, "diameter must be positive, was %s", diameter);
|
||||
return new PaperTeleportRandomly(
|
||||
new net.minecraft.world.item.consume_effects.TeleportRandomlyConsumeEffect(diameter)
|
||||
new net.minecraft.world.item.consume_effects.TeleportRandomlyConsumeEffect(requireArgumentPositive(diameter, "diameter"))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -44,13 +44,13 @@ public class PaperBannerPatternRegistryEntry implements BannerPatternRegistryEnt
|
||||
|
||||
@Override
|
||||
public Builder assetId(final Key assetId) {
|
||||
this.assetId = PaperAdventure.asVanilla(asArgument(assetId, "assetId"));
|
||||
this.assetId = PaperAdventure.asVanilla(requireArgument(assetId, "assetId"));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder translationKey(final String translationKey) {
|
||||
this.translationKey = asArgument(translationKey, "translationKey");
|
||||
this.translationKey = requireArgument(translationKey, "translationKey");
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@ -9,7 +9,7 @@ import net.minecraft.world.entity.variant.SpawnPrioritySelectors;
|
||||
import org.bukkit.entity.Cat;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import static io.papermc.paper.registry.data.util.Checks.asArgument;
|
||||
import static io.papermc.paper.registry.data.util.Checks.requireArgument;
|
||||
import static io.papermc.paper.registry.data.util.Checks.asConfigured;
|
||||
|
||||
public class PaperCatTypeRegistryEntry implements CatTypeRegistryEntry {
|
||||
@ -46,7 +46,7 @@ public class PaperCatTypeRegistryEntry implements CatTypeRegistryEntry {
|
||||
|
||||
@Override
|
||||
public Builder clientTextureAsset(final ClientTextureAsset clientTextureAsset) {
|
||||
this.clientTextureAsset = this.conversions.asVanilla(asArgument(clientTextureAsset, "clientTextureAsset"));
|
||||
this.clientTextureAsset = this.conversions.asVanilla(requireArgument(clientTextureAsset, "clientTextureAsset"));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@ -10,7 +10,7 @@ import net.minecraft.world.entity.variant.SpawnPrioritySelectors;
|
||||
import org.bukkit.entity.Chicken;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import static io.papermc.paper.registry.data.util.Checks.asArgument;
|
||||
import static io.papermc.paper.registry.data.util.Checks.requireArgument;
|
||||
import static io.papermc.paper.registry.data.util.Checks.asConfigured;
|
||||
|
||||
public class PaperChickenVariantRegistryEntry implements ChickenVariantRegistryEntry {
|
||||
@ -57,13 +57,13 @@ public class PaperChickenVariantRegistryEntry implements ChickenVariantRegistryE
|
||||
|
||||
@Override
|
||||
public Builder clientTextureAsset(final ClientTextureAsset clientTextureAsset) {
|
||||
this.clientTextureAsset = this.conversions.asVanilla(asArgument(clientTextureAsset, "clientTextureAsset"));
|
||||
this.clientTextureAsset = this.conversions.asVanilla(requireArgument(clientTextureAsset, "clientTextureAsset"));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder model(final Model model) {
|
||||
this.model = switch (asArgument(model, "model")) {
|
||||
this.model = switch (requireArgument(model, "model")) {
|
||||
case NORMAL -> ChickenVariant.ModelType.NORMAL;
|
||||
case COLD -> ChickenVariant.ModelType.COLD;
|
||||
};
|
||||
|
||||
@ -10,7 +10,7 @@ import net.minecraft.world.entity.variant.SpawnPrioritySelectors;
|
||||
import org.bukkit.entity.Cow;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import static io.papermc.paper.registry.data.util.Checks.asArgument;
|
||||
import static io.papermc.paper.registry.data.util.Checks.requireArgument;
|
||||
import static io.papermc.paper.registry.data.util.Checks.asConfigured;
|
||||
|
||||
public class PaperCowVariantRegistryEntry implements CowVariantRegistryEntry {
|
||||
@ -58,13 +58,13 @@ public class PaperCowVariantRegistryEntry implements CowVariantRegistryEntry {
|
||||
|
||||
@Override
|
||||
public Builder clientTextureAsset(final ClientTextureAsset clientTextureAsset) {
|
||||
this.clientTextureAsset = this.conversions.asVanilla(asArgument(clientTextureAsset, "clientTextureAsset"));
|
||||
this.clientTextureAsset = this.conversions.asVanilla(requireArgument(clientTextureAsset, "clientTextureAsset"));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder model(final Model model) {
|
||||
this.model = switch (asArgument(model, "model")) {
|
||||
this.model = switch (requireArgument(model, "model")) {
|
||||
case NORMAL -> CowVariant.ModelType.NORMAL;
|
||||
case COLD -> CowVariant.ModelType.COLD;
|
||||
case WARM -> CowVariant.ModelType.WARM;
|
||||
|
||||
@ -11,7 +11,7 @@ import org.bukkit.craftbukkit.damage.CraftDamageType;
|
||||
import org.bukkit.damage.DamageEffect;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import static io.papermc.paper.registry.data.util.Checks.asArgument;
|
||||
import static io.papermc.paper.registry.data.util.Checks.requireArgument;
|
||||
import static io.papermc.paper.registry.data.util.Checks.asConfigured;
|
||||
|
||||
public class PaperDamageTypeRegistryEntry implements DamageTypeRegistryEntry {
|
||||
@ -71,13 +71,13 @@ public class PaperDamageTypeRegistryEntry implements DamageTypeRegistryEntry {
|
||||
|
||||
@Override
|
||||
public Builder messageId(final String messageId) {
|
||||
this.messageId = asArgument(messageId, "messageId");
|
||||
this.messageId = requireArgument(messageId, "messageId");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder damageScaling(final org.bukkit.damage.DamageScaling scaling) {
|
||||
this.scaling = CraftDamageType.damageScalingToNMS(asArgument(scaling, "scaling"));
|
||||
this.scaling = CraftDamageType.damageScalingToNMS(requireArgument(scaling, "scaling"));
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -89,13 +89,13 @@ public class PaperDamageTypeRegistryEntry implements DamageTypeRegistryEntry {
|
||||
|
||||
@Override
|
||||
public Builder damageEffect(final DamageEffect effect) {
|
||||
this.effects = ((CraftDamageEffect) asArgument(effect, "effects")).getHandle();
|
||||
this.effects = ((CraftDamageEffect) requireArgument(effect, "effects")).getHandle();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder deathMessageType(final org.bukkit.damage.DeathMessageType deathMessageType) {
|
||||
this.deathMessageType = CraftDamageType.deathMessageTypeToNMS(asArgument(deathMessageType, "deathMessageType"));
|
||||
this.deathMessageType = CraftDamageType.deathMessageTypeToNMS(requireArgument(deathMessageType, "deathMessageType"));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@ -24,8 +24,8 @@ import org.bukkit.inventory.ItemType;
|
||||
import org.jetbrains.annotations.Range;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import static io.papermc.paper.registry.data.util.Checks.asArgument;
|
||||
import static io.papermc.paper.registry.data.util.Checks.asArgumentMin;
|
||||
import static io.papermc.paper.registry.data.util.Checks.requireArgument;
|
||||
import static io.papermc.paper.registry.data.util.Checks.requireArgumentMin;
|
||||
import static io.papermc.paper.registry.data.util.Checks.asConfigured;
|
||||
|
||||
public class PaperEnchantmentRegistryEntry implements EnchantmentRegistryEntry {
|
||||
@ -143,13 +143,13 @@ public class PaperEnchantmentRegistryEntry implements EnchantmentRegistryEntry {
|
||||
|
||||
@Override
|
||||
public Builder description(final net.kyori.adventure.text.Component description) {
|
||||
this.description = this.conversions.asVanilla(asArgument(description, "description"));
|
||||
this.description = this.conversions.asVanilla(requireArgument(description, "description"));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder supportedItems(final RegistryKeySet<ItemType> supportedItems) {
|
||||
this.supportedItems = PaperRegistrySets.convertToNms(Registries.ITEM, this.conversions.lookup(), asArgument(supportedItems, "supportedItems"));
|
||||
this.supportedItems = PaperRegistrySets.convertToNms(Registries.ITEM, this.conversions.lookup(), requireArgument(supportedItems, "supportedItems"));
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -161,45 +161,45 @@ public class PaperEnchantmentRegistryEntry implements EnchantmentRegistryEntry {
|
||||
|
||||
@Override
|
||||
public Builder weight(final @Range(from = 1, to = 1024) int weight) {
|
||||
this.weight = OptionalInt.of(Checks.asArgumentRange(weight, "weight", 1, 1024));
|
||||
this.weight = OptionalInt.of(Checks.requireArgumentRange(weight, "weight", 1, 1024));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder maxLevel(final @Range(from = 1, to = 255) int maxLevel) {
|
||||
this.maxLevel = OptionalInt.of(Checks.asArgumentRange(maxLevel, "maxLevel", 1, 255));
|
||||
this.maxLevel = OptionalInt.of(Checks.requireArgumentRange(maxLevel, "maxLevel", 1, 255));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder minimumCost(final EnchantmentCost minimumCost) {
|
||||
final EnchantmentCost validCost = asArgument(minimumCost, "minimumCost");
|
||||
final EnchantmentCost validCost = requireArgument(minimumCost, "minimumCost");
|
||||
this.minimumCost = Enchantment.dynamicCost(validCost.baseCost(), validCost.additionalPerLevelCost());
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder maximumCost(final EnchantmentCost maximumCost) {
|
||||
final EnchantmentCost validCost = asArgument(maximumCost, "maximumCost");
|
||||
final EnchantmentCost validCost = requireArgument(maximumCost, "maximumCost");
|
||||
this.maximumCost = Enchantment.dynamicCost(validCost.baseCost(), validCost.additionalPerLevelCost());
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder anvilCost(final @Range(from = 0, to = Integer.MAX_VALUE) int anvilCost) {
|
||||
this.anvilCost = OptionalInt.of(asArgumentMin(anvilCost, "anvilCost", 0));
|
||||
this.anvilCost = OptionalInt.of(requireArgumentMin(anvilCost, "anvilCost", 0));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder activeSlots(final Iterable<org.bukkit.inventory.EquipmentSlotGroup> activeSlots) {
|
||||
this.activeSlots = Lists.newArrayList(Iterables.transform(asArgument(activeSlots, "activeSlots"), CraftEquipmentSlot::getNMSGroup));
|
||||
this.activeSlots = Lists.newArrayList(Iterables.transform(requireArgument(activeSlots, "activeSlots"), CraftEquipmentSlot::getNMSGroup));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder exclusiveWith(final RegistryKeySet<org.bukkit.enchantments.Enchantment> exclusiveWith) {
|
||||
this.exclusiveWith = PaperRegistrySets.convertToNms(Registries.ENCHANTMENT, this.conversions.lookup(), asArgument(exclusiveWith, "exclusiveWith"));
|
||||
this.exclusiveWith = PaperRegistrySets.convertToNms(Registries.ENCHANTMENT, this.conversions.lookup(), requireArgument(exclusiveWith, "exclusiveWith"));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@ -9,7 +9,7 @@ import net.minecraft.world.entity.variant.SpawnPrioritySelectors;
|
||||
import org.bukkit.entity.Frog;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import static io.papermc.paper.registry.data.util.Checks.asArgument;
|
||||
import static io.papermc.paper.registry.data.util.Checks.requireArgument;
|
||||
import static io.papermc.paper.registry.data.util.Checks.asConfigured;
|
||||
|
||||
public class PaperFrogVariantRegistryEntry implements FrogVariantRegistryEntry {
|
||||
@ -46,7 +46,7 @@ public class PaperFrogVariantRegistryEntry implements FrogVariantRegistryEntry {
|
||||
|
||||
@Override
|
||||
public Builder clientTextureAsset(final ClientTextureAsset clientTextureAsset) {
|
||||
this.clientTextureAsset = this.conversions.asVanilla(asArgument(clientTextureAsset, "clientTextureAsset"));
|
||||
this.clientTextureAsset = this.conversions.asVanilla(requireArgument(clientTextureAsset, "clientTextureAsset"));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@ -7,7 +7,7 @@ import net.minecraft.world.level.gameevent.GameEvent;
|
||||
import org.jetbrains.annotations.Range;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import static io.papermc.paper.registry.data.util.Checks.asArgumentMin;
|
||||
import static io.papermc.paper.registry.data.util.Checks.requireArgumentMin;
|
||||
import static io.papermc.paper.registry.data.util.Checks.asConfigured;
|
||||
|
||||
public class PaperGameEventRegistryEntry implements GameEventRegistryEntry {
|
||||
@ -40,7 +40,7 @@ public class PaperGameEventRegistryEntry implements GameEventRegistryEntry {
|
||||
|
||||
@Override
|
||||
public GameEventRegistryEntry.Builder range(final @Range(from = 0, to = Integer.MAX_VALUE) int range) {
|
||||
this.range = OptionalInt.of(asArgumentMin(range, "range", 0));
|
||||
this.range = OptionalInt.of(requireArgumentMin(range, "range", 0));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@ -18,8 +18,8 @@ import org.bukkit.Sound;
|
||||
import org.checkerframework.checker.index.qual.Positive;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import static io.papermc.paper.registry.data.util.Checks.asArgument;
|
||||
import static io.papermc.paper.registry.data.util.Checks.asArgumentMinExclusive;
|
||||
import static io.papermc.paper.registry.data.util.Checks.requireArgument;
|
||||
import static io.papermc.paper.registry.data.util.Checks.requireArgumentPositive;
|
||||
import static io.papermc.paper.registry.data.util.Checks.asConfigured;
|
||||
|
||||
public class PaperInstrumentRegistryEntry implements InstrumentRegistryEntry {
|
||||
@ -71,13 +71,13 @@ public class PaperInstrumentRegistryEntry implements InstrumentRegistryEntry {
|
||||
|
||||
@Override
|
||||
public Builder soundEvent(final TypedKey<Sound> soundEvent) {
|
||||
this.soundEvent = this.conversions.getReferenceHolder(PaperRegistries.toNms(asArgument(soundEvent, "soundEvent")));
|
||||
this.soundEvent = this.conversions.getReferenceHolder(PaperRegistries.toNms(requireArgument(soundEvent, "soundEvent")));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder soundEvent(final Consumer<RegistryBuilderFactory<Sound, ? extends SoundEventRegistryEntry.Builder>> soundEvent) {
|
||||
this.soundEvent = this.conversions.createHolderFromBuilder(RegistryKey.SOUND_EVENT, asArgument(soundEvent, "soundEvent"));
|
||||
this.soundEvent = this.conversions.createHolderFromBuilder(RegistryKey.SOUND_EVENT, requireArgument(soundEvent, "soundEvent"));
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -89,19 +89,19 @@ public class PaperInstrumentRegistryEntry implements InstrumentRegistryEntry {
|
||||
|
||||
@Override
|
||||
public Builder duration(final @Positive float duration) {
|
||||
this.useDuration = asArgumentMinExclusive(duration, "useDuration", 0);
|
||||
this.useDuration = requireArgumentPositive(duration, "useDuration");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder range(final @Positive float range) {
|
||||
this.range = asArgumentMinExclusive(range, "range", 0);
|
||||
this.range = requireArgumentPositive(range, "range");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder description(final net.kyori.adventure.text.Component description) {
|
||||
this.description = this.conversions.asVanilla(asArgument(description, "description"));
|
||||
this.description = this.conversions.asVanilla(requireArgument(description, "description"));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@ -5,6 +5,7 @@ import io.papermc.paper.registry.PaperRegistryBuilder;
|
||||
import io.papermc.paper.registry.RegistryBuilderFactory;
|
||||
import io.papermc.paper.registry.RegistryKey;
|
||||
import io.papermc.paper.registry.TypedKey;
|
||||
import io.papermc.paper.registry.data.util.Checks;
|
||||
import io.papermc.paper.registry.data.util.Conversions;
|
||||
import io.papermc.paper.registry.holder.PaperRegistryHolders;
|
||||
import io.papermc.paper.registry.holder.RegistryHolder;
|
||||
@ -20,9 +21,9 @@ import org.checkerframework.checker.index.qual.Positive;
|
||||
import org.jetbrains.annotations.Range;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import static io.papermc.paper.registry.data.util.Checks.asArgument;
|
||||
import static io.papermc.paper.registry.data.util.Checks.asArgumentMinExclusive;
|
||||
import static io.papermc.paper.registry.data.util.Checks.asArgumentRange;
|
||||
import static io.papermc.paper.registry.data.util.Checks.requireArgument;
|
||||
import static io.papermc.paper.registry.data.util.Checks.requireArgumentPositive;
|
||||
import static io.papermc.paper.registry.data.util.Checks.requireArgumentRange;
|
||||
import static io.papermc.paper.registry.data.util.Checks.asConfigured;
|
||||
|
||||
public class PaperJukeboxSongRegistryEntry implements JukeboxSongRegistryEntry {
|
||||
@ -74,13 +75,13 @@ public class PaperJukeboxSongRegistryEntry implements JukeboxSongRegistryEntry {
|
||||
|
||||
@Override
|
||||
public JukeboxSongRegistryEntry.Builder soundEvent(final TypedKey<Sound> soundEvent) {
|
||||
this.soundEvent = this.conversions.getReferenceHolder(PaperRegistries.toNms(asArgument(soundEvent, "soundEvent")));
|
||||
this.soundEvent = this.conversions.getReferenceHolder(PaperRegistries.toNms(requireArgument(soundEvent, "soundEvent")));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JukeboxSongRegistryEntry.Builder soundEvent(final Consumer<RegistryBuilderFactory<Sound, ? extends SoundEventRegistryEntry.Builder>> soundEvent) {
|
||||
this.soundEvent = this.conversions.createHolderFromBuilder(RegistryKey.SOUND_EVENT, asArgument(soundEvent, "soundEvent"));
|
||||
this.soundEvent = this.conversions.createHolderFromBuilder(RegistryKey.SOUND_EVENT, requireArgument(soundEvent, "soundEvent"));
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -92,19 +93,19 @@ public class PaperJukeboxSongRegistryEntry implements JukeboxSongRegistryEntry {
|
||||
|
||||
@Override
|
||||
public JukeboxSongRegistryEntry.Builder description(final net.kyori.adventure.text.Component description) {
|
||||
this.description = this.conversions.asVanilla(asArgument(description, "description"));
|
||||
this.description = this.conversions.asVanilla(requireArgument(description, "description"));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JukeboxSongRegistryEntry.Builder lengthInSeconds(final @Positive float lengthInSeconds) {
|
||||
this.lengthInSeconds = asArgumentMinExclusive(lengthInSeconds, "lengthInSeconds", 0);
|
||||
this.lengthInSeconds = requireArgumentPositive(lengthInSeconds, "lengthInSeconds");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JukeboxSongRegistryEntry.Builder comparatorOutput(final @Range(from = 0, to = 15) int comparatorOutput) {
|
||||
this.comparatorOutput = OptionalInt.of(asArgumentRange(comparatorOutput, "comparatorOutput", Redstone.SIGNAL_MIN, Redstone.SIGNAL_MAX));
|
||||
this.comparatorOutput = OptionalInt.of(Checks.requireArgumentRange(comparatorOutput, "comparatorOutput", Redstone.SIGNAL_MIN, Redstone.SIGNAL_MAX));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@ -2,6 +2,7 @@ package io.papermc.paper.registry.data;
|
||||
|
||||
import io.papermc.paper.adventure.PaperAdventure;
|
||||
import io.papermc.paper.registry.PaperRegistryBuilder;
|
||||
import io.papermc.paper.registry.data.util.Checks;
|
||||
import io.papermc.paper.registry.data.util.Conversions;
|
||||
import java.util.Optional;
|
||||
import java.util.OptionalInt;
|
||||
@ -13,8 +14,8 @@ import org.bukkit.Art;
|
||||
import org.jetbrains.annotations.Range;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import static io.papermc.paper.registry.data.util.Checks.asArgument;
|
||||
import static io.papermc.paper.registry.data.util.Checks.asArgumentRange;
|
||||
import static io.papermc.paper.registry.data.util.Checks.requireArgument;
|
||||
import static io.papermc.paper.registry.data.util.Checks.requireArgumentRange;
|
||||
import static io.papermc.paper.registry.data.util.Checks.asConfigured;
|
||||
|
||||
public class PaperPaintingVariantRegistryEntry implements PaintingVariantRegistryEntry {
|
||||
@ -74,13 +75,13 @@ public class PaperPaintingVariantRegistryEntry implements PaintingVariantRegistr
|
||||
|
||||
@Override
|
||||
public Builder width(final @Range(from = 1, to = 16) int width) {
|
||||
this.width = OptionalInt.of(asArgumentRange(width, "width", 1, 16));
|
||||
this.width = OptionalInt.of(Checks.requireArgumentRange(width, "width", 1, 16));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder height(final @Range(from = 1, to = 16) int height) {
|
||||
this.height = OptionalInt.of(asArgumentRange(height, "height", 1, 16));
|
||||
this.height = OptionalInt.of(Checks.requireArgumentRange(height, "height", 1, 16));
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -98,7 +99,7 @@ public class PaperPaintingVariantRegistryEntry implements PaintingVariantRegistr
|
||||
|
||||
@Override
|
||||
public Builder assetId(final Key assetId) {
|
||||
this.assetId = PaperAdventure.asVanilla(asArgument(assetId, "assetId"));
|
||||
this.assetId = PaperAdventure.asVanilla(requireArgument(assetId, "assetId"));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@ -10,7 +10,7 @@ import net.minecraft.world.entity.variant.SpawnPrioritySelectors;
|
||||
import org.bukkit.entity.Pig;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import static io.papermc.paper.registry.data.util.Checks.asArgument;
|
||||
import static io.papermc.paper.registry.data.util.Checks.requireArgument;
|
||||
import static io.papermc.paper.registry.data.util.Checks.asConfigured;
|
||||
|
||||
public class PaperPigVariantRegistryEntry implements PigVariantRegistryEntry {
|
||||
@ -57,13 +57,13 @@ public class PaperPigVariantRegistryEntry implements PigVariantRegistryEntry {
|
||||
|
||||
@Override
|
||||
public Builder clientTextureAsset(final ClientTextureAsset clientTextureAsset) {
|
||||
this.clientTextureAsset = this.conversions.asVanilla(asArgument(clientTextureAsset, "clientTextureAsset"));
|
||||
this.clientTextureAsset = this.conversions.asVanilla(requireArgument(clientTextureAsset, "clientTextureAsset"));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder model(final Model model) {
|
||||
this.model = switch (asArgument(model, "model")) {
|
||||
this.model = switch (requireArgument(model, "model")) {
|
||||
case NORMAL -> PigVariant.ModelType.NORMAL;
|
||||
case COLD -> PigVariant.ModelType.COLD;
|
||||
};
|
||||
|
||||
@ -10,7 +10,7 @@ import net.minecraft.sounds.SoundEvent;
|
||||
import org.bukkit.Sound;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import static io.papermc.paper.registry.data.util.Checks.asArgument;
|
||||
import static io.papermc.paper.registry.data.util.Checks.requireArgument;
|
||||
import static io.papermc.paper.registry.data.util.Checks.asConfigured;
|
||||
|
||||
/**
|
||||
@ -51,7 +51,7 @@ public class PaperSoundEventRegistryEntry implements SoundEventRegistryEntry {
|
||||
|
||||
@Override
|
||||
public SoundEventRegistryEntry.Builder location(final Key location) {
|
||||
this.location = PaperAdventure.asVanilla(asArgument(location, "location"));
|
||||
this.location = PaperAdventure.asVanilla(requireArgument(location, "location"));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@ -9,7 +9,7 @@ import net.minecraft.world.entity.variant.SpawnPrioritySelectors;
|
||||
import org.bukkit.entity.Wolf;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import static io.papermc.paper.registry.data.util.Checks.asArgument;
|
||||
import static io.papermc.paper.registry.data.util.Checks.requireArgument;
|
||||
import static io.papermc.paper.registry.data.util.Checks.asConfigured;
|
||||
|
||||
public class PaperWolfVariantRegistryEntry implements WolfVariantRegistryEntry {
|
||||
@ -60,19 +60,19 @@ public class PaperWolfVariantRegistryEntry implements WolfVariantRegistryEntry {
|
||||
|
||||
@Override
|
||||
public Builder angryClientTextureAsset(final ClientTextureAsset angryClientTextureAsset) {
|
||||
this.angryClientTextureAsset = this.conversions.asVanilla(asArgument(angryClientTextureAsset, "angryClientTextureAsset"));
|
||||
this.angryClientTextureAsset = this.conversions.asVanilla(requireArgument(angryClientTextureAsset, "angryClientTextureAsset"));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder wildClientTextureAsset(final ClientTextureAsset wildClientTextureAsset) {
|
||||
this.wildClientTextureAsset = this.conversions.asVanilla(asArgument(wildClientTextureAsset, "wildClientTextureAsset"));
|
||||
this.wildClientTextureAsset = this.conversions.asVanilla(requireArgument(wildClientTextureAsset, "wildClientTextureAsset"));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder tameClientTextureAsset(final ClientTextureAsset tameClientTextureAsset) {
|
||||
this.tameClientTextureAsset = this.conversions.asVanilla(asArgument(tameClientTextureAsset, "tameClientTextureAsset"));
|
||||
this.tameClientTextureAsset = this.conversions.asVanilla(requireArgument(tameClientTextureAsset, "tameClientTextureAsset"));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@ -10,7 +10,7 @@ import net.minecraft.server.dialog.CommonDialogData;
|
||||
import net.minecraft.server.dialog.Dialog;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import static io.papermc.paper.registry.data.util.Checks.asArgument;
|
||||
import static io.papermc.paper.registry.data.util.Checks.requireArgument;
|
||||
import static io.papermc.paper.registry.data.util.Checks.asConfigured;
|
||||
|
||||
public class PaperDialogRegistryEntry implements DialogRegistryEntry {
|
||||
@ -56,13 +56,13 @@ public class PaperDialogRegistryEntry implements DialogRegistryEntry {
|
||||
|
||||
@Override
|
||||
public Builder base(final DialogBase dialogBase) {
|
||||
this.dialogBase = asArgument(dialogBase, "dialogBase");
|
||||
this.dialogBase = requireArgument(dialogBase, "dialogBase");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder type(final DialogType dialogType) {
|
||||
this.dialogType = asArgument(dialogType, "dialogType");
|
||||
this.dialogType = requireArgument(dialogType, "dialogType");
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@ -1,11 +1,16 @@
|
||||
package io.papermc.paper.registry.data.dialog.input;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import io.papermc.paper.registry.data.util.Checks;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minecraft.commands.functions.StringTemplate;
|
||||
import net.minecraft.server.dialog.body.PlainMessage;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import static io.papermc.paper.registry.data.util.Checks.requireArgumentMinInclusive;
|
||||
import static io.papermc.paper.registry.data.util.Checks.requireArgumentPositive;
|
||||
import static io.papermc.paper.registry.data.util.Checks.requireArgumentRange;
|
||||
|
||||
public record NumberRangeDialogInputImpl(
|
||||
String key,
|
||||
int width,
|
||||
@ -38,8 +43,7 @@ public record NumberRangeDialogInputImpl(
|
||||
|
||||
@Override
|
||||
public BuilderImpl width(final int width) {
|
||||
Preconditions.checkArgument(width >= 1 && width <= 1024, "width must be between 1 and 1024");
|
||||
this.width = width;
|
||||
this.width = Checks.requireArgumentRange(width, "width", 1, 1024);
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -51,17 +55,13 @@ public record NumberRangeDialogInputImpl(
|
||||
|
||||
@Override
|
||||
public BuilderImpl initial(final @Nullable Float initial) {
|
||||
if (initial != null) {
|
||||
Preconditions.checkArgument(initial >= this.start && initial <= this.end, "initial must be within the range");
|
||||
}
|
||||
this.initial = initial;
|
||||
this.initial = (initial == null ? null : requireArgumentMinInclusive(initial, "initial", this.start, this.end));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BuilderImpl step(final @Nullable Float step) {
|
||||
Preconditions.checkArgument(step == null || step > 0, "step must be null or greater than 0");
|
||||
this.step = step;
|
||||
this.step = (step == null ? null : requireArgumentPositive(step, "step"));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
package io.papermc.paper.registry.data.util;
|
||||
|
||||
import java.util.OptionalInt;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
@NullMarked
|
||||
public final class Checks {
|
||||
|
||||
public static <T> T asConfigured(final @Nullable T value, final String field) {
|
||||
@ -12,6 +14,7 @@ public final class Checks {
|
||||
return value;
|
||||
}
|
||||
|
||||
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
|
||||
public static int asConfigured(final OptionalInt value, final String field) {
|
||||
if (value.isEmpty()) {
|
||||
throw new IllegalStateException(field + " has not been configured");
|
||||
@ -19,34 +22,73 @@ public final class Checks {
|
||||
return value.getAsInt();
|
||||
}
|
||||
|
||||
public static <T> T asArgument(final @Nullable T value, final String field) {
|
||||
public static <T> T requireArgument(final @Nullable T value, final String field) {
|
||||
if (value == null) {
|
||||
throw new IllegalArgumentException("argument " + field + " cannot be null");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public static int asArgumentRange(final int value, final String field, final int min, final int max) {
|
||||
public static int requireArgumentRange(final int value, final String field, final int min, final int max) {
|
||||
if (value < min || value > max) {
|
||||
throw new IllegalArgumentException("argument " + field + " must be [" + min + ", " + max + "]");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public static int asArgumentMin(final int value, final String field, final int min) {
|
||||
public static int requireArgumentMin(final int value, final String field, final int min) {
|
||||
if (value < min) {
|
||||
throw new IllegalArgumentException("argument " + field + " must be [" + min + ",+inf)");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public static float asArgumentMinExclusive(final float value, final String field, final float min) {
|
||||
if (value <= min) {
|
||||
throw new IllegalArgumentException("argument " + field + " must be (" + min + ",+inf)");
|
||||
public static int requireArgumentNonNegative(final int value, final String field) {
|
||||
if (value < 0) {
|
||||
throw new IllegalArgumentException("argument " + field + " must be non-negative");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public static int requireArgumentPositive(final int value, final String field) {
|
||||
if (value < 1) {
|
||||
throw new IllegalArgumentException("argument " + field + " must be positive");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public static float requireArgumentNonNegative(final float value, final String field) {
|
||||
if (Float.compare(value, 0.0F) > 0 && Float.compare(value, Float.MAX_VALUE) <= 0) {
|
||||
return value;
|
||||
}
|
||||
throw new IllegalArgumentException("argument " + field + " must be non-negative");
|
||||
}
|
||||
|
||||
public static float requireArgumentPositive(final float value, final String field) {
|
||||
if (Float.compare(value, 0.0F) >= 0 && Float.compare(value, Float.MAX_VALUE) <= 0) {
|
||||
return value;
|
||||
}
|
||||
throw new IllegalArgumentException("argument " + field + " must be positive");
|
||||
}
|
||||
|
||||
public static float requireArgumentRange(final float value, final String field, final float min, final float max) {
|
||||
return requireArgumentMinExclusive(value, field, min, max);
|
||||
}
|
||||
|
||||
public static float requireArgumentMinExclusive(final float value, final String field, final float min, final float max) {
|
||||
if (Float.compare(value, min) > 0 && Float.compare(value, max) <= 0) {
|
||||
return value;
|
||||
}
|
||||
throw new IllegalArgumentException("argument " + field + " must be (" + min + "," + max +"]");
|
||||
}
|
||||
|
||||
public static float requireArgumentMinInclusive(final float value, final String field, final float min, final float max) {
|
||||
if (Float.compare(value, min) >= 0 && Float.compare(value, max) <= 0) {
|
||||
return value;
|
||||
}
|
||||
throw new IllegalArgumentException("argument " + field + " must be (" + min + "," + max +"]");
|
||||
}
|
||||
|
||||
private Checks() {
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user