Skip to content

Commit 46e7c75

Browse files
committed
fix legacy serialization with equipOnInteract and add preconditions
1 parent 46d21c1 commit 46e7c75

File tree

7 files changed

+16
-11
lines changed

7 files changed

+16
-11
lines changed

paper-api/src/main/java/io/papermc/paper/datacomponent/item/TooltipDisplay.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ interface Builder extends DataComponentBuilder<TooltipDisplay> {
3939
Builder hideTooltip(boolean hide);
4040

4141
@Contract(value = "_ -> this", mutates = "this")
42-
Builder addHiddenComponents(DataComponentType... component);
42+
Builder addHiddenComponents(DataComponentType... components);
4343

4444
@Contract(value = "_ -> this", mutates = "this")
4545
Builder hiddenComponents(Set<DataComponentType> components);

paper-api/src/main/java/io/papermc/paper/datacomponent/item/Weapon.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ static Builder builder() {
2424
float disableBlockingForSeconds();
2525

2626
/**
27-
* Builder for Weapon.
27+
* Builder for {@link Weapon}.
2828
*/
2929
interface Builder extends DataComponentBuilder<Weapon> {
30+
3031
/**
3132
* Sets the damage per attack.
3233
*
@@ -42,6 +43,5 @@ interface Builder extends DataComponentBuilder<Weapon> {
4243
* @return the builder for chaining.
4344
*/
4445
Builder disableBlockingForSeconds(float seconds);
45-
4646
}
4747
}

paper-server/src/main/java/io/papermc/paper/datacomponent/item/PaperBlocksAttacks.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.papermc.paper.datacomponent.item;
22

3+
import com.google.common.base.Preconditions;
34
import io.papermc.paper.adventure.PaperAdventure;
45
import io.papermc.paper.registry.PaperRegistries;
56
import io.papermc.paper.registry.tag.TagKey;
@@ -31,8 +32,8 @@ public float disableCooldownScale() {
3132

3233
@Override
3334
public @Nullable TagKey<DamageType> bypassedBy() {
34-
final Optional<TagKey<DamageType>> optionalTagKey = this.impl.bypassedBy().map(PaperRegistries::fromNms);
35-
return optionalTagKey.orElse(null);
35+
final Optional<TagKey<DamageType>> tagKey = this.impl.bypassedBy().map(PaperRegistries::fromNms);
36+
return tagKey.orElse(null);
3637
}
3738

3839
@Override
@@ -57,12 +58,14 @@ static final class BuilderImpl implements Builder {
5758

5859
@Override
5960
public Builder blockDelaySeconds(final float delay) {
61+
Preconditions.checkArgument(delay >= 0, "delay must be non-negative, was %s", delay);
6062
this.blockDelaySeconds = delay;
6163
return this;
6264
}
6365

6466
@Override
6567
public Builder disableCooldownScale(final float scale) {
68+
Preconditions.checkArgument(scale >= 0, "scale must be non-negative, was %s", scale);
6669
this.disableCooldownScale = scale;
6770
return this;
6871
}

paper-server/src/main/java/io/papermc/paper/datacomponent/item/PaperEquippable.java

-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
package io.papermc.paper.datacomponent.item;
22

33
import io.papermc.paper.adventure.PaperAdventure;
4-
import io.papermc.paper.registry.PaperRegistries;
54
import io.papermc.paper.registry.RegistryKey;
65
import io.papermc.paper.registry.set.PaperRegistrySets;
76
import io.papermc.paper.registry.set.RegistryKeySet;
87
import java.util.Optional;
9-
import java.util.function.Function;
108
import net.kyori.adventure.key.Key;
119
import net.minecraft.core.Holder;
1210
import net.minecraft.core.HolderSet;
@@ -16,7 +14,6 @@
1614
import net.minecraft.resources.ResourceLocation;
1715
import net.minecraft.sounds.SoundEvent;
1816
import net.minecraft.sounds.SoundEvents;
19-
import net.minecraft.util.datafix.fixes.EquippableAssetRenameFix;
2017
import net.minecraft.world.item.equipment.EquipmentAsset;
2118
import net.minecraft.world.item.equipment.EquipmentAssets;
2219
import org.bukkit.craftbukkit.CraftEquipmentSlot;

paper-server/src/main/java/io/papermc/paper/datacomponent/item/PaperTooltipDisplay.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ public Builder hideTooltip(final boolean hide) {
4141
}
4242

4343
@Override
44-
public Builder addHiddenComponents(final DataComponentType... component) {
45-
this.hiddenComponents.addAll(Arrays.asList(component));
44+
public Builder addHiddenComponents(final DataComponentType... components) {
45+
this.hiddenComponents.addAll(Arrays.asList(components));
4646
return this;
4747
}
4848

paper-server/src/main/java/io/papermc/paper/datacomponent/item/PaperWeapon.java

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.papermc.paper.datacomponent.item;
22

3+
import com.google.common.base.Preconditions;
34
import org.bukkit.craftbukkit.util.Handleable;
45

56
public record PaperWeapon(
@@ -28,12 +29,14 @@ static final class BuilderImpl implements Builder {
2829

2930
@Override
3031
public Builder itemDamagePerAttack(final int damage) {
32+
Preconditions.checkArgument(damage >= 0, "damage must be non-negative, was %s", damage);
3133
this.itemDamagePerAttack = damage;
3234
return this;
3335
}
3436

3537
@Override
3638
public Builder disableBlockingForSeconds(final float seconds) {
39+
Preconditions.checkArgument(seconds >= 0, "seconds must be non-negative, was %s", seconds);
3740
this.disableBlockingForSeconds = seconds;
3841
return this;
3942
}

paper-server/src/main/java/org/bukkit/craftbukkit/inventory/components/CraftEquippableComponent.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public CraftEquippableComponent(Map<String, Object> map) {
6464
Boolean dispensable = SerializableMeta.getObject(Boolean.class, map, "dispensable", true);
6565
Boolean swappable = SerializableMeta.getObject(Boolean.class, map, "swappable", true);
6666
Boolean damageOnHurt = SerializableMeta.getObject(Boolean.class, map, "damage-on-hurt", true);
67+
Boolean equipOnInteract = SerializableMeta.getObject(Boolean.class, map, "equip-on-interact", true);
6768

6869
this.handle = new Equippable(slot,
6970
(equipSound != null) ? CraftSound.bukkitToMinecraftHolder(equipSound) : SoundEvents.ARMOR_EQUIP_GENERIC,
@@ -73,7 +74,7 @@ public CraftEquippableComponent(Map<String, Object> map) {
7374
(dispensable != null) ? dispensable : true,
7475
(swappable != null) ? swappable : true,
7576
(damageOnHurt != null) ? damageOnHurt : true,
76-
false
77+
(equipOnInteract != null) ? equipOnInteract : false
7778
);
7879
}
7980

@@ -98,6 +99,7 @@ public Map<String, Object> serialize() {
9899
result.put("dispensable", this.isDispensable());
99100
result.put("swappable", this.isSwappable());
100101
result.put("damage-on-hurt", this.isDamageOnHurt());
102+
result.put("equip-on-interact", this.isEquipOnInteract());
101103

102104
return result;
103105
}

0 commit comments

Comments
 (0)