SPIGOT-7633: Clearer error message for missing particle data

This commit is contained in:
md_5 2024-04-25 16:38:33 +10:00
parent 807b465b32
commit 661afb43c3
No known key found for this signature in database
GPG Key ID: E8E901AC7C617C11
4 changed files with 9 additions and 14 deletions

View File

@ -61,7 +61,15 @@ public abstract class CraftParticle<D> implements Keyed {
} }
public static <D> ParticleParam createParticleParam(Particle particle, D data) { public static <D> 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<D> craftParticle = (CraftParticle<D>) CRAFT_PARTICLE_REGISTRY.get(particle.getKey()); CraftParticle<D> craftParticle = (CraftParticle<D>) CRAFT_PARTICLE_REGISTRY.get(particle.getKey());

View File

@ -1869,10 +1869,6 @@ public class CraftWorld extends CraftRegionAccessor implements World {
@Override @Override
public <T> void spawnParticle(Particle particle, double x, double y, double z, int count, double offsetX, double offsetY, double offsetZ, double extra, T data, boolean force) { public <T> 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( getHandle().sendParticles(
null, // Sender null, // Sender
CraftParticle.createParticleParam(particle, data), // Particle CraftParticle.createParticleParam(particle, data), // Particle

View File

@ -1,6 +1,5 @@
package org.bukkit.craftbukkit.entity; package org.bukkit.craftbukkit.entity;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
@ -122,10 +121,6 @@ public class CraftAreaEffectCloud extends CraftEntity implements AreaEffectCloud
@Override @Override
public <T> void setParticle(Particle particle, T data) { public <T> 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)); getHandle().setParticle(CraftParticle.createParticleParam(particle, data));
} }

View File

@ -2241,10 +2241,6 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
@Override @Override
public <T> void spawnParticle(Particle particle, double x, double y, double z, int count, double offsetX, double offsetY, double offsetZ, double extra, T data) { public <T> 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); 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); getHandle().connection.send(packetplayoutworldparticles);