Skip to content
Open
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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;
Expand All @@ -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);
}

Expand All @@ -33,6 +34,7 @@ static UseCooldown.Builder useCooldown(final float seconds) {
* @return cooldown seconds
*/
@Contract(pure = true)
@Positive
float seconds();

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -16,6 +15,8 @@
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> {
Expand Down Expand Up @@ -73,15 +74,13 @@ static final class BuilderImpl implements Builder {

@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;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -16,6 +15,8 @@
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> {
Expand Down Expand Up @@ -73,8 +74,7 @@ static final class BuilderImpl implements Builder {

@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;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -17,6 +17,9 @@
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> {
Expand Down Expand Up @@ -57,8 +60,7 @@ public boolean canDestroyBlocksInCreative() {
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);
}
}

Expand All @@ -71,8 +73,7 @@ static final class BuilderImpl implements Builder {

@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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
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> {
Expand Down Expand Up @@ -34,7 +36,7 @@ static final class BuilderImpl implements Builder {
private Optional<ResourceLocation> cooldownGroup = Optional.empty();

BuilderImpl(final float seconds) {
this.seconds = seconds;
this.seconds = requireArgumentPositive(seconds, "seconds");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -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> {
Expand All @@ -29,15 +31,13 @@ static final class BuilderImpl implements Builder {

@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;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,6 +11,8 @@
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 {
Expand Down Expand Up @@ -52,8 +53,7 @@ public Builder type(final @Nullable RegistryKeySet<DamageType> type) {

@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;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -36,8 +37,7 @@ static final class BuilderImpl implements Builder {

@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;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -15,16 +14,18 @@
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)
)
);
}
Expand Down Expand Up @@ -52,9 +53,8 @@ public ConsumeEffect.PlaySound playSoundEffect(final Key sound) {

@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"))
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ public PaperBuilder(final Conversions conversions, final @Nullable BannerPattern

@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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
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 {
Expand Down Expand Up @@ -46,7 +46,7 @@ public PaperBuilder(final Conversions conversions, final @Nullable CatVariant in

@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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
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 {
Expand Down Expand Up @@ -57,13 +57,13 @@ public PaperBuilder(final Conversions conversions, final @Nullable ChickenVarian

@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;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
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 {
Expand Down Expand Up @@ -58,13 +58,13 @@ public PaperBuilder(final Conversions conversions, final @Nullable CowVariant in

@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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
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 {
Expand Down Expand Up @@ -71,13 +71,13 @@ public PaperBuilder(final Conversions conversions, final @Nullable DamageType in

@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;
}

Expand All @@ -89,13 +89,13 @@ public Builder exhaustion(final float exhaustion) {

@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;
}

Expand Down
Loading
Loading