From 18cee9d332cb1e291db3d46e7178a5882cc1548a Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Thu, 25 Apr 2024 16:38:33 +1000 Subject: [PATCH] SPIGOT-7633: Clearer error message for missing particle data By: md_5 --- .../java/org/bukkit/craftbukkit/CraftParticle.java | 10 +++++++++- .../main/java/org/bukkit/craftbukkit/CraftWorld.java | 4 ---- .../craftbukkit/entity/CraftAreaEffectCloud.java | 5 ----- .../org/bukkit/craftbukkit/entity/CraftPlayer.java | 4 ---- 4 files changed, 9 insertions(+), 14 deletions(-) diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftParticle.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftParticle.java index 5e3781ed3d..9a11517097 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftParticle.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftParticle.java @@ -61,7 +61,15 @@ public abstract class CraftParticle implements Keyed { } public static ParticleParam createParticleParam(Particle particle, D data) { - Preconditions.checkArgument(particle != null); + Preconditions.checkArgument(particle != null, "particle cannot be null"); + + data = CraftParticle.convertLegacy(data); + if (particle.getDataType() != Void.class) { + Preconditions.checkArgument(data != null, "missing required data %s", particle.getDataType()); + } + if (data != null) { + Preconditions.checkArgument(particle.getDataType().isInstance(data), "data (%s) should be %s", data.getClass(), particle.getDataType()); + } CraftParticle craftParticle = (CraftParticle) CRAFT_PARTICLE_REGISTRY.get(particle.getKey()); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index 96fe7c7e17..fe3252ea23 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -1869,10 +1869,6 @@ public class CraftWorld extends CraftRegionAccessor implements World { @Override public void spawnParticle(Particle particle, double x, double y, double z, int count, double offsetX, double offsetY, double offsetZ, double extra, T data, boolean force) { - data = CraftParticle.convertLegacy(data); - if (data != null) { - Preconditions.checkArgument(particle.getDataType().isInstance(data), "data (%s) should be %s", data.getClass(), particle.getDataType()); - } getHandle().sendParticles( null, // Sender CraftParticle.createParticleParam(particle, data), // Particle diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftAreaEffectCloud.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftAreaEffectCloud.java index 1034c6a78d..524d014a24 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftAreaEffectCloud.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftAreaEffectCloud.java @@ -1,6 +1,5 @@ package org.bukkit.craftbukkit.entity; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import java.util.List; import java.util.Optional; @@ -122,10 +121,6 @@ public class CraftAreaEffectCloud extends CraftEntity implements AreaEffectCloud @Override public void setParticle(Particle particle, T data) { - data = CraftParticle.convertLegacy(data); - if (data != null) { - Preconditions.checkArgument(particle.getDataType().isInstance(data), "data (%s) should be %s", data.getClass(), particle.getDataType()); - } getHandle().setParticle(CraftParticle.createParticleParam(particle, data)); } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java index 5249e056d2..304453fcd9 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -2241,10 +2241,6 @@ public class CraftPlayer extends CraftHumanEntity implements Player { @Override public void spawnParticle(Particle particle, double x, double y, double z, int count, double offsetX, double offsetY, double offsetZ, double extra, T data) { - data = CraftParticle.convertLegacy(data); - if (data != null) { - Preconditions.checkArgument(particle.getDataType().isInstance(data), "data (%s) should be %s", data.getClass(), particle.getDataType()); - } PacketPlayOutWorldParticles packetplayoutworldparticles = new PacketPlayOutWorldParticles(CraftParticle.createParticleParam(particle, data), true, (float) x, (float) y, (float) z, (float) offsetX, (float) offsetY, (float) offsetZ, (float) extra, count); getHandle().connection.send(packetplayoutworldparticles);