From 1b0447274f9250e34e2b97b737ca046d6a2742af Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Wed, 24 Apr 2024 01:15:00 +1000 Subject: [PATCH] #1357: Remove legacy Particle values By: DerFrZocker --- .../java/org/bukkit/craftbukkit/CraftParticle.java | 9 --------- .../java/org/bukkit/craftbukkit/CraftWorld.java | 1 - .../craftbukkit/entity/CraftAreaEffectCloud.java | 1 - .../org/bukkit/craftbukkit/entity/CraftPlayer.java | 1 - .../org/bukkit/craftbukkit/legacy/CraftEvil.java | 13 +++++++++++++ .../java/org/bukkit/craftbukkit/util/Commodore.java | 11 ++++++----- .../src/test/java/org/bukkit/ParticleTest.java | 2 -- 7 files changed, 19 insertions(+), 19 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 bdcd7403fe..5e3781ed3d 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftParticle.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftParticle.java @@ -78,15 +78,6 @@ public abstract class CraftParticle implements Keyed { return object; } - public static Particle convertLegacy(Particle particle) { - return switch (particle) { - case LEGACY_BLOCK_DUST -> Particle.BLOCK_DUST; - case LEGACY_FALLING_DUST -> Particle.FALLING_DUST; - case LEGACY_BLOCK_CRACK -> Particle.BLOCK_CRACK; - default -> particle; - }; - } - private final NamespacedKey key; private final net.minecraft.core.particles.Particle particle; private final Class clazz; 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 1b4808581c..96fe7c7e17 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -1869,7 +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) { - particle = CraftParticle.convertLegacy(particle); data = CraftParticle.convertLegacy(data); if (data != null) { Preconditions.checkArgument(particle.getDataType().isInstance(data), "data (%s) should be %s", data.getClass(), particle.getDataType()); 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 fac14cef14..1034c6a78d 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 @@ -122,7 +122,6 @@ public class CraftAreaEffectCloud extends CraftEntity implements AreaEffectCloud @Override public void setParticle(Particle particle, T data) { - particle = CraftParticle.convertLegacy(particle); data = CraftParticle.convertLegacy(data); if (data != null) { Preconditions.checkArgument(particle.getDataType().isInstance(data), "data (%s) should be %s", data.getClass(), particle.getDataType()); 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 9484fa2d97..7c268035f7 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 @@ -2240,7 +2240,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) { - particle = CraftParticle.convertLegacy(particle); data = CraftParticle.convertLegacy(data); if (data != null) { Preconditions.checkArgument(particle.getDataType().isInstance(data), "data (%s) should be %s", data.getClass(), particle.getDataType()); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/legacy/CraftEvil.java b/paper-server/src/main/java/org/bukkit/craftbukkit/legacy/CraftEvil.java index afb706fc82..c96d9940a1 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/legacy/CraftEvil.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/legacy/CraftEvil.java @@ -5,12 +5,15 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectLinkedOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.Particle; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.BlockState; +import org.bukkit.block.data.BlockData; import org.bukkit.craftbukkit.block.CraftBlock; import org.bukkit.craftbukkit.block.CraftBlockState; import org.bukkit.inventory.ItemStack; +import org.bukkit.material.MaterialData; /** * @deprecated do not use for any reason @@ -103,4 +106,14 @@ public final class CraftEvil { public static int getId(Material material) { return CraftLegacy.toLegacy(material).getId(); } + + public static Class getDataType(Particle particle) { + Class clazz = particle.getDataType(); + + if (clazz == BlockData.class) { + return MaterialData.class; + } + + return clazz; + } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/util/Commodore.java b/paper-server/src/main/java/org/bukkit/craftbukkit/util/Commodore.java index 8da49869b8..4d7718eba7 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/util/Commodore.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/util/Commodore.java @@ -261,11 +261,6 @@ public class Commodore { case "SPELL_MOB_AMBIENT": super.visitFieldInsn(opcode, owner, "SPELL_MOB", desc); return; - case "BLOCK_CRACK": - case "BLOCK_DUST": - case "FALLING_DUST": - super.visitFieldInsn(opcode, owner, "LEGACY_" + name, desc); - return; } } @@ -307,6 +302,12 @@ public class Commodore { return; } + // Change Particle#getDataType() from BlockData to MaterialData for legacy plugins and particle + if (owner.equals("org/bukkit/Particle") && name.equals("getDataType") && desc.equals("()Ljava/lang/Class;")) { + visitor.visit(Opcodes.INVOKESTATIC, "org/bukkit/craftbukkit/legacy/CraftEvil", name, "(Lorg/bukkit/Particle;)Ljava/lang/Class;", false, samMethodType, instantiatedMethodType); + return; + } + if (owner.equals("org/bukkit/ChunkSnapshot") && name.equals("getBlockData") && desc.equals("(III)I")) { visitor.visit(opcode, owner, "getData", desc, itf, samMethodType, instantiatedMethodType); return; diff --git a/paper-server/src/test/java/org/bukkit/ParticleTest.java b/paper-server/src/test/java/org/bukkit/ParticleTest.java index b23589184e..54a893aa98 100644 --- a/paper-server/src/test/java/org/bukkit/ParticleTest.java +++ b/paper-server/src/test/java/org/bukkit/ParticleTest.java @@ -54,7 +54,6 @@ public class ParticleTest extends AbstractTestingBase { @EnumSource(Particle.class) public void testMinecraftValuesPresent(Particle bukkit) { // TODO: 10/19/23 Remove with enum PR, it is then no longer needed, since the enum PR has a extra test for this - bukkit = CraftParticle.convertLegacy(bukkit); Particle finalBukkit = bukkit; assertDoesNotThrow(() -> CraftParticle.bukkitToMinecraft(finalBukkit), String.format(""" No minecraft particle found for bukkit particle %s. @@ -65,7 +64,6 @@ public class ParticleTest extends AbstractTestingBase { @ParameterizedTest @EnumSource(Particle.class) public void testRightParticleParamCreation(Particle bukkit) { - bukkit = CraftParticle.convertLegacy(bukkit); net.minecraft.core.particles.Particle minecraft = CraftParticle.bukkitToMinecraft(bukkit); if (bukkit.getDataType().equals(Void.class)) {