2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Ivan Pekov <ivan@mrivanplays.com>
Date: Tue, 5 Jan 2021 10:19:11 +0200
Subject: [PATCH] Add missing effects
2023-12-08 21:07:56 +01:00
Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/org/bukkit/Effect.java b/src/main/java/org/bukkit/Effect.java
2024-06-14 18:53:32 +02:00
index fd9cf25f2fdef5ee3b7143f27e5f43dfe3f21a38..d98612cad7f7477f6d4fe496f4d87b139aa3c681 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/org/bukkit/Effect.java
+++ b/src/main/java/org/bukkit/Effect.java
2024-04-23 19:02:08 +02:00
@@ -131,9 +131,9 @@ public enum Effect {
2023-08-13 00:19:34 +02:00
/**
* Sound of a block breaking. Needs block ID as additional info.
*/
- STEP_SOUND(2001, Type.SOUND, Material.class),
+ STEP_SOUND(2001, Type.SOUND, org.bukkit.block.data.BlockData.class, Material.class), // Paper - block data is more correct, but the impl of the mtehods will still work with Material
/**
- * Visual effect of a splash potion breaking. Needs potion data value as
+ * Visual effect of a splash potion breaking. Needs color data value as
* additional info.
*/
2024-04-23 19:02:08 +02:00
POTION_BREAK(2002, Type.VISUAL, Color.class),
2024-06-14 18:53:32 +02:00
@@ -168,7 +168,9 @@ public enum Effect {
PORTAL_TRAVEL(1032, Type.SOUND),
/**
* The sound played when launching an endereye
+ * @deprecated No longer exists
*/
+ @Deprecated(forRemoval = true, since = "1.21") // Paper
ENDEREYE_LAUNCH(1003, Type.SOUND),
/**
* The sound played when launching a firework
@@ -177,7 +179,9 @@ public enum Effect {
2024-04-26 20:39:20 +02:00
/**
* Particles displayed when a villager grows a plant, data
* is the number of particles
+ * @deprecated partially replaced by {@link #BEE_GROWTH}
*/
+ @Deprecated(forRemoval = true, since = "1.20.5") // Paper
VILLAGER_PLANT_GROW(2005, Type.VISUAL, Integer.class),
/**
* The sound/particles used by the enderdragon's breath
2024-06-14 18:53:32 +02:00
@@ -336,21 +340,199 @@ public enum Effect {
2021-09-11 19:27:48 +02:00
* block.
2021-06-11 14:02:28 +02:00
*/
2021-09-11 19:27:48 +02:00
OXIDISED_COPPER_SCRAPE(3005, Type.VISUAL),
2021-06-11 14:02:28 +02:00
+ // Paper start - add missing effects
+ /**
+ * The sound of a wither spawning
+ */
+ WITHER_SPAWNED(1023, Type.SOUND),
+ /**
+ * The sound of an ender dragon dying
+ */
+ ENDER_DRAGON_DEATH(1028, Type.SOUND),
+ /**
+ * The sound of an ender portal being created in the overworld
+ */
+ END_PORTAL_CREATED_IN_OVERWORLD(1038, Type.SOUND),
+ /**
+ * The sound of phantom's bites
2021-09-11 19:27:48 +02:00
+ *
+ * @deprecated use {@link #PHANTOM_BITE}
2021-06-11 14:02:28 +02:00
+ */
2023-06-07 15:47:32 +02:00
+ @Deprecated(forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.21")
2021-06-11 14:02:28 +02:00
+ PHANTOM_BITES(1039, Type.SOUND),
+ /**
+ * The sound of zombie converting to drowned zombie
2021-09-11 19:27:48 +02:00
+ *
+ * @deprecated use {@link #ZOMBIE_CONVERTED_TO_DROWNED}
2021-06-11 14:02:28 +02:00
+ */
2023-06-07 15:47:32 +02:00
+ @Deprecated(forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.21")
2021-06-11 14:02:28 +02:00
+ ZOMBIE_CONVERTS_TO_DROWNED(1040, Type.SOUND),
+ /**
+ * The sound of a husk converting to zombie by drowning
2021-09-11 19:27:48 +02:00
+ *
+ * @deprecated use {@link #HUSK_CONVERTED_TO_ZOMBIE}
2021-06-11 14:02:28 +02:00
+ */
2023-06-07 15:47:32 +02:00
+ @Deprecated(forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.21")
2021-06-11 14:02:28 +02:00
+ HUSK_CONVERTS_TO_ZOMBIE(1041, Type.SOUND),
+ /**
+ * The sound of a grindstone being used
2021-09-11 19:27:48 +02:00
+ *
+ * @deprecated use {@link #GRINDSTONE_USE}
2021-06-11 14:02:28 +02:00
+ */
2023-06-07 15:47:32 +02:00
+ @Deprecated(forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.21")
2021-06-11 14:02:28 +02:00
+ GRINDSTONE_USED(1042, Type.SOUND),
+ /**
+ * The sound of a book page being turned
2021-09-11 19:27:48 +02:00
+ *
+ * @deprecated use {@link #BOOK_PAGE_TURN}
2021-06-11 14:02:28 +02:00
+ */
2023-06-07 15:47:32 +02:00
+ @Deprecated(forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.21")
2021-06-11 14:02:28 +02:00
+ BOOK_PAGE_TURNED(1043, Type.SOUND),
+ /**
+ * Particles displayed when a composter composts
2021-09-11 19:27:48 +02:00
+ *
+ * @deprecated use {@link #COMPOSTER_FILL_ATTEMPT}
2021-06-11 14:02:28 +02:00
+ */
2023-06-07 15:47:32 +02:00
+ @Deprecated(forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.21")
2021-06-11 14:02:28 +02:00
+ COMPOSTER_COMPOSTS(1500, Type.VISUAL),
+ /**
+ * Particles displayed when lava converts a block (either water to stone, or
+ * removing existing blocks such as torches)
2021-09-11 19:27:48 +02:00
+ *
+ * @deprecated use {@link #LAVA_INTERACT}
2021-06-11 14:02:28 +02:00
+ */
2023-06-07 15:47:32 +02:00
+ @Deprecated(forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.21")
2021-06-11 14:02:28 +02:00
+ LAVA_CONVERTS_BLOCK(1501, Type.VISUAL),
+ /**
+ * Particles displayd when a redstone torch burns out
2021-09-11 19:27:48 +02:00
+ *
+ * @deprecated use {@link #REDSTONE_TORCH_BURNOUT}
2021-06-11 14:02:28 +02:00
+ */
2023-06-07 15:47:32 +02:00
+ @Deprecated(forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.21")
2021-06-11 14:02:28 +02:00
+ REDSTONE_TORCH_BURNS_OUT(1502, Type.VISUAL),
+ /**
+ * Particles displayed when an ender eye is placed
2021-09-11 19:27:48 +02:00
+ *
+ * @deprecated use {@link #END_PORTAL_FRAME_FILL}
2021-06-11 14:02:28 +02:00
+ */
2023-06-07 15:47:32 +02:00
+ @Deprecated(forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.21")
2021-06-11 14:02:28 +02:00
+ ENDER_EYE_PLACED(1503, Type.VISUAL),
+ /**
+ * Particles displayed when an ender dragon destroys block
2021-09-11 19:27:48 +02:00
+ *
+ * @deprecated use {@link #ENDER_DRAGON_DESTROY_BLOCK}
2021-06-11 14:02:28 +02:00
+ */
2023-06-07 15:47:32 +02:00
+ @Deprecated(forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.21")
2021-06-11 14:02:28 +02:00
+ ENDER_DRAGON_DESTROYS_BLOCK(2008, Type.VISUAL),
+ /**
+ * Particles displayed when a wet sponge vaporizes in nether.
2021-09-11 19:27:48 +02:00
+ *
+ * @deprecated use {@link #SPONGE_DRY}
2021-06-11 14:02:28 +02:00
+ */
2023-06-07 15:47:32 +02:00
+ @Deprecated(forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.21")
2021-09-11 19:27:48 +02:00
+ WET_SPONGE_VAPORIZES_IN_NETHER(2009, Type.VISUAL),
2023-08-13 00:19:34 +02:00
+
+ SOUND_STOP_JUKEBOX_SONG(1011, Type.SOUND),
+
2023-12-08 21:07:56 +01:00
+ CRAFTER_CRAFT(1049, Type.SOUND),
+
+ CRAFTER_FAIL(1050, Type.SOUND),
+
+ /**
+ * {@link BlockFace} param is the direction to shoot
+ */
+ SHOOT_WHITE_SMOKE(2010, Type.VISUAL, BlockFace.class),
+
2024-04-26 20:39:20 +02:00
+ /**
+ * {@link Integer} param is the number of particles
+ */
+ BEE_GROWTH(2011, Type.VISUAL, Integer.class),
+
2024-04-26 23:29:16 +02:00
+ /**
+ * {@link Integer} param is the number of particles
+ */
+ TURTLE_EGG_PLACEMENT(2012, Type.VISUAL, Integer.class),
+
+ /**
+ * {@link Integer} param is relative to the number of particles
+ */
+ SMASH_ATTACK(2013, Type.VISUAL, Integer.class),
+
2023-08-13 00:19:34 +02:00
+ PARTICLES_SCULK_CHARGE(3006, Type.VISUAL, Integer.class),
+
+ PARTICLES_SCULK_SHRIEK(3007, Type.SOUND),
+
+ PARTICLES_AND_SOUND_BRUSH_BLOCK_COMPLETE(3008, Type.VISUAL, org.bukkit.block.data.BlockData.class),
+
2023-12-08 21:07:56 +01:00
+ PARTICLES_EGG_CRACK(3009, Type.VISUAL),
+
2024-04-26 20:39:20 +02:00
+ @Deprecated(forRemoval = true, since = "1.20.5")
2023-12-08 21:07:56 +01:00
+ GUST_DUST(3010, Type.VISUAL),
+
2024-04-26 23:29:16 +02:00
+ /**
+ * {@link Boolean} param is true for "ominous" vaults
+ */
+ TRIAL_SPAWNER_SPAWN(3011, Type.VISUAL, Boolean.class),
2023-12-08 21:07:56 +01:00
+
2024-04-26 23:29:16 +02:00
+ /**
+ * {@link Boolean} param is true for "ominous" vaults
+ */
+ TRIAL_SPAWNER_SPAWN_MOB_AT(3012, Type.VISUAL, Boolean.class),
2023-12-08 21:07:56 +01:00
+
+ /**
+ * {@link Integer} param is the number of players
+ */
+ TRIAL_SPAWNER_DETECT_PLAYER(3013, Type.VISUAL, Integer.class),
+
+ TRIAL_SPAWNER_EJECT_ITEM(3014, Type.VISUAL),
2024-04-26 23:29:16 +02:00
+
+ /**
+ * {@link Boolean} param is true for "ominous" vaults
+ */
+ VAULT_ACTIVATE(3015, Type.VISUAL, Boolean.class),
+
+ /**
+ * {@link Boolean} param is true for "ominous" vaults
+ */
+ VAULT_DEACTIVATE(3016, Type.VISUAL, Boolean.class),
+
+ VAULT_EJECT_ITEM(3017, Type.VISUAL),
+
+ SPAWN_COBWEB(3018, Type.VISUAL),
+
+ /**
+ * {@link Integer} param is the number of players
+ */
+ TRIAL_SPAWNER_DETECT_PLAYER_OMINOUS(3019, Type.VISUAL, Integer.class),
+
+ /**
+ * {@link Boolean} param is true for changing to "ominous"
+ */
+ TRIAL_SPAWNER_BECOME_OMINOUS(3020, Type.VISUAL, Boolean.class),
+
+ /**
+ * {@link Boolean} param is true for "ominous" vaults
+ */
2024-06-14 18:53:32 +02:00
+ TRIAL_SPAWNER_SPAWN_ITEM(3021, Type.VISUAL, Boolean.class),
+
+ SOUND_WITH_CHARGE_SHOT(1051, Type.SOUND),
2021-06-11 14:02:28 +02:00
;
2021-09-11 19:27:48 +02:00
+ private static final org.apache.logging.log4j.Logger LOGGER = org.apache.logging.log4j.LogManager.getLogger();
+ // Paper end
2021-06-11 14:02:28 +02:00
private final int id;
2021-09-11 19:27:48 +02:00
private final Type type;
2023-08-13 00:19:34 +02:00
- private final Class<?> data;
+ private final java.util.List<Class<?>> data; // Paper - support multiple data types
private static final Map<Integer, Effect> BY_ID = Maps.newHashMap();
Effect(int id, /*@NotNull*/ Type type) {
- this(id, type, null);
+ this(id, type, (Class<?>[]) null); // Paper - support multiple data types
}
- Effect(int id, /*@NotNull*/ Type type, /*@Nullable*/ Class<?> data) {
+ Effect(int id, /*@NotNull*/ Type type, /*@Nullable*/ Class<?>...data) { // Paper - support multiple data types
this.id = id;
this.type = type;
- this.data = data;
+ this.data = data != null ? java.util.List.of(data) : null; // Paper - support multiple data types
}
/**
2024-06-14 18:53:32 +02:00
@@ -366,8 +548,10 @@ public enum Effect {
2023-08-13 00:19:34 +02:00
/**
* @return The type of the effect.
+ * @deprecated some effects can be both or neither
*/
@NotNull
+ @Deprecated // Paper - both
public Type getType() {
return this.type;
}
2024-06-14 18:53:32 +02:00
@@ -378,9 +562,16 @@ public enum Effect {
2023-08-13 00:19:34 +02:00
*/
@Nullable
public Class<?> getData() {
- return this.data;
+ return this.data == null ? null : this.data.get(0); // Paper
2024-04-26 23:29:16 +02:00
}
2023-08-13 00:19:34 +02:00
+ // Paper start - support deprecated data types
+ @org.jetbrains.annotations.ApiStatus.Internal
+ public boolean isApplicable(Object obj) {
+ return this.data != null && com.google.common.collect.Iterables.any(this.data, aClass -> aClass.isAssignableFrom(obj.getClass()));
2024-04-26 23:29:16 +02:00
+ }
2023-08-13 00:19:34 +02:00
+ // Paper end - support deprecated data types
2024-04-26 23:29:16 +02:00
+
2023-08-13 00:19:34 +02:00
/**
* Gets the Effect associated with the given ID.
2024-04-26 23:29:16 +02:00
*
2024-06-14 18:53:32 +02:00
@@ -396,12 +587,26 @@ public enum Effect {
2021-09-11 19:27:48 +02:00
static {
for (Effect effect : values()) {
+ if (!isDeprecated(effect)) // Paper
BY_ID.put(effect.id, effect);
}
}
+ // Paper start
+ private static boolean isDeprecated(Effect effect) {
+ try {
+ return Effect.class.getDeclaredField(effect.name()).isAnnotationPresent(Deprecated.class);
+ } catch (NoSuchFieldException e) {
+ LOGGER.error("Error getting effect enum field {}", effect.name(), e);
+ return false;
+ }
+ }
+ // Paper end
+
/**
* Represents the type of an effect.
2023-08-13 00:19:34 +02:00
+ * @deprecated not representative of what Effect does
2021-09-11 19:27:48 +02:00
*/
2023-08-13 00:19:34 +02:00
+ @Deprecated // Paper
public enum Type { SOUND, VISUAL }
}
2021-09-11 19:27:48 +02:00
diff --git a/src/test/java/org/bukkit/EffectTest.java b/src/test/java/org/bukkit/EffectTest.java
2023-09-24 09:16:58 +02:00
index 4344512fa84a2f97a750e06761d8e160c0959f6a..615a4583ef8e70a7c86c28e648d0b57e8e6b9674 100644
2021-09-11 19:27:48 +02:00
--- a/src/test/java/org/bukkit/EffectTest.java
+++ b/src/test/java/org/bukkit/EffectTest.java
2023-09-24 09:16:58 +02:00
@@ -5,10 +5,24 @@ import static org.hamcrest.CoreMatchers.*;
import org.junit.jupiter.api.Test;
2021-09-11 19:27:48 +02:00
public class EffectTest {
+ private static final org.apache.logging.log4j.Logger LOGGER = org.apache.logging.log4j.LogManager.getLogger(); // Paper
+
@Test
public void getById() {
for (Effect effect : Effect.values()) {
+ if (!isDeprecated(effect)) // Paper
assertThat(Effect.getById(effect.getId()), is(effect));
}
}
+
+ // Paper start
+ private static boolean isDeprecated(Effect effect) {
+ try {
+ return Effect.class.getDeclaredField(effect.name()).isAnnotationPresent(Deprecated.class);
+ } catch (NoSuchFieldException e) {
+ LOGGER.error("Error getting effect enum field {}", effect.name(), e);
+ return false;
+ }
+ }
+ // Paper end
}