From bab07e0ff9d17cd695c696c75893d24a842fea19 Mon Sep 17 00:00:00 2001 From: Lulu13022002 <41980282+Lulu13022002@users.noreply.github.com> Date: Thu, 20 Jun 2024 18:32:32 +0200 Subject: [PATCH] Validate speed for tool component rule (#10923) --- .../server/0970-General-ItemMeta-fixes.patch | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/patches/server/0970-General-ItemMeta-fixes.patch b/patches/server/0970-General-ItemMeta-fixes.patch index b7c7c44ede..ad2f78a179 100644 --- a/patches/server/0970-General-ItemMeta-fixes.patch +++ b/patches/server/0970-General-ItemMeta-fixes.patch @@ -1518,6 +1518,42 @@ index 63fc9138dc3388ceb9acf672b3f75ba0976e8e54..cad52601583c1f304f94de954c4d18a6 List effects = new ArrayList<>(this.handle.effects()); FoodProperties.PossibleEffect newEffect = new net.minecraft.world.food.FoodProperties.PossibleEffect(CraftPotionUtil.fromBukkit(effect), probability); +diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/components/CraftToolComponent.java b/src/main/java/org/bukkit/craftbukkit/inventory/components/CraftToolComponent.java +index 4d7889ccd1c70db537402a9bbab42e40c3bb0d65..73be17186c87019868fdd7f9e0fdcdadeef79570 100644 +--- a/src/main/java/org/bukkit/craftbukkit/inventory/components/CraftToolComponent.java ++++ b/src/main/java/org/bukkit/craftbukkit/inventory/components/CraftToolComponent.java +@@ -108,6 +108,7 @@ public final class CraftToolComponent implements ToolComponent { + public ToolRule addRule(Material block, Float speed, Boolean correctForDrops) { + Preconditions.checkArgument(block != null, "block must not be null"); + Preconditions.checkArgument(block.isBlock(), "block must be a block type, given %s", block.getKey()); ++ Preconditions.checkArgument(speed == null || speed > 0, "speed must be positive"); // Paper - validate speed + + Holder.Reference nmsBlock = CraftBlockType.bukkitToMinecraft(block).builtInRegistryHolder(); + return this.addRule(HolderSet.direct(nmsBlock), speed, correctForDrops); +@@ -115,6 +116,7 @@ public final class CraftToolComponent implements ToolComponent { + + @Override + public ToolRule addRule(Collection blocks, Float speed, Boolean correctForDrops) { ++ Preconditions.checkArgument(speed == null || speed > 0, "speed must be positive"); // Paper - validate speed + List> nmsBlocks = new ArrayList<>(blocks.size()); + + for (Material material : blocks) { +@@ -128,6 +130,7 @@ public final class CraftToolComponent implements ToolComponent { + @Override + public ToolRule addRule(Tag tag, Float speed, Boolean correctForDrops) { + Preconditions.checkArgument(tag instanceof CraftBlockTag, "tag must be a block tag"); ++ Preconditions.checkArgument(speed == null || speed > 0, "speed must be positive"); // Paper - validate speed + return this.addRule(((CraftBlockTag) tag).getHandle(), speed, correctForDrops); + } + +@@ -290,6 +293,7 @@ public final class CraftToolComponent implements ToolComponent { + + @Override + public void setSpeed(Float speed) { ++ Preconditions.checkArgument(speed == null || speed > 0, "speed must be positive"); // Paper - validate speed + this.handle = new Tool.Rule(this.handle.blocks(), Optional.ofNullable(speed), this.handle.correctForDrops()); + } + diff --git a/src/test/java/org/bukkit/craftbukkit/inventory/DeprecatedItemMetaCustomValueTest.java b/src/test/java/org/bukkit/craftbukkit/inventory/DeprecatedItemMetaCustomValueTest.java index 6bed0a5c8d9f1ca72678cdf4699128e441a24541..8e03e14d0e65bfdf2196a08220d1408b1297aa0d 100644 --- a/src/test/java/org/bukkit/craftbukkit/inventory/DeprecatedItemMetaCustomValueTest.java