mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-22 18:45:54 +01:00
263 lines
9.6 KiB
Diff
263 lines
9.6 KiB
Diff
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
|
|
|
|
Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
|
|
|
|
diff --git a/src/main/java/org/bukkit/Effect.java b/src/main/java/org/bukkit/Effect.java
|
|
index 611b7df0e31de932f15c2f13bd8ed286e0b3b43f..b8ad6ec6795433770604a1cc93384ef639e810bd 100644
|
|
--- a/src/main/java/org/bukkit/Effect.java
|
|
+++ b/src/main/java/org/bukkit/Effect.java
|
|
@@ -132,12 +132,12 @@ public enum Effect {
|
|
/**
|
|
* 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.
|
|
*/
|
|
- POTION_BREAK(2002, Type.VISUAL, Potion.class),
|
|
+ POTION_BREAK(2002, Type.VISUAL, Color.class, Potion.class), // Paper - color is correct
|
|
/**
|
|
* Visual effect of an instant splash potion breaking. Needs color data
|
|
* value as additional info.
|
|
@@ -337,21 +337,146 @@ public enum Effect {
|
|
* block.
|
|
*/
|
|
OXIDISED_COPPER_SCRAPE(3005, Type.VISUAL),
|
|
+ // 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
|
|
+ *
|
|
+ * @deprecated use {@link #PHANTOM_BITE}
|
|
+ */
|
|
+ @Deprecated(forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.21")
|
|
+ PHANTOM_BITES(1039, Type.SOUND),
|
|
+ /**
|
|
+ * The sound of zombie converting to drowned zombie
|
|
+ *
|
|
+ * @deprecated use {@link #ZOMBIE_CONVERTED_TO_DROWNED}
|
|
+ */
|
|
+ @Deprecated(forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.21")
|
|
+ ZOMBIE_CONVERTS_TO_DROWNED(1040, Type.SOUND),
|
|
+ /**
|
|
+ * The sound of a husk converting to zombie by drowning
|
|
+ *
|
|
+ * @deprecated use {@link #HUSK_CONVERTED_TO_ZOMBIE}
|
|
+ */
|
|
+ @Deprecated(forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.21")
|
|
+ HUSK_CONVERTS_TO_ZOMBIE(1041, Type.SOUND),
|
|
+ /**
|
|
+ * The sound of a grindstone being used
|
|
+ *
|
|
+ * @deprecated use {@link #GRINDSTONE_USE}
|
|
+ */
|
|
+ @Deprecated(forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.21")
|
|
+ GRINDSTONE_USED(1042, Type.SOUND),
|
|
+ /**
|
|
+ * The sound of a book page being turned
|
|
+ *
|
|
+ * @deprecated use {@link #BOOK_PAGE_TURN}
|
|
+ */
|
|
+ @Deprecated(forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.21")
|
|
+ BOOK_PAGE_TURNED(1043, Type.SOUND),
|
|
+ /**
|
|
+ * Particles displayed when a composter composts
|
|
+ *
|
|
+ * @deprecated use {@link #COMPOSTER_FILL_ATTEMPT}
|
|
+ */
|
|
+ @Deprecated(forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.21")
|
|
+ COMPOSTER_COMPOSTS(1500, Type.VISUAL),
|
|
+ /**
|
|
+ * Particles displayed when lava converts a block (either water to stone, or
|
|
+ * removing existing blocks such as torches)
|
|
+ *
|
|
+ * @deprecated use {@link #LAVA_INTERACT}
|
|
+ */
|
|
+ @Deprecated(forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.21")
|
|
+ LAVA_CONVERTS_BLOCK(1501, Type.VISUAL),
|
|
+ /**
|
|
+ * Particles displayd when a redstone torch burns out
|
|
+ *
|
|
+ * @deprecated use {@link #REDSTONE_TORCH_BURNOUT}
|
|
+ */
|
|
+ @Deprecated(forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.21")
|
|
+ REDSTONE_TORCH_BURNS_OUT(1502, Type.VISUAL),
|
|
+ /**
|
|
+ * Particles displayed when an ender eye is placed
|
|
+ *
|
|
+ * @deprecated use {@link #END_PORTAL_FRAME_FILL}
|
|
+ */
|
|
+ @Deprecated(forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.21")
|
|
+ ENDER_EYE_PLACED(1503, Type.VISUAL),
|
|
+ /**
|
|
+ * Particles displayed when an ender dragon destroys block
|
|
+ *
|
|
+ * @deprecated use {@link #ENDER_DRAGON_DESTROY_BLOCK}
|
|
+ */
|
|
+ @Deprecated(forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.21")
|
|
+ ENDER_DRAGON_DESTROYS_BLOCK(2008, Type.VISUAL),
|
|
+ /**
|
|
+ * Particles displayed when a wet sponge vaporizes in nether.
|
|
+ *
|
|
+ * @deprecated use {@link #SPONGE_DRY}
|
|
+ */
|
|
+ @Deprecated(forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.21")
|
|
+ WET_SPONGE_VAPORIZES_IN_NETHER(2009, Type.VISUAL),
|
|
+
|
|
+ SOUND_STOP_JUKEBOX_SONG(1011, Type.SOUND),
|
|
+
|
|
+ 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),
|
|
+
|
|
+ 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),
|
|
+
|
|
+ PARTICLES_EGG_CRACK(3009, Type.VISUAL),
|
|
+
|
|
+ GUST_DUST(3010, Type.VISUAL),
|
|
+
|
|
+ TRIAL_SPAWNER_SPAWN(3011, Type.VISUAL),
|
|
+
|
|
+ TRIAL_SPAWNER_SPAWN_MOB_AT(3012, Type.VISUAL),
|
|
+
|
|
+ /**
|
|
+ * {@link Integer} param is the number of players
|
|
+ */
|
|
+ TRIAL_SPAWNER_DETECT_PLAYER(3013, Type.VISUAL, Integer.class),
|
|
+
|
|
+ TRIAL_SPAWNER_EJECT_ITEM(3014, Type.VISUAL),
|
|
;
|
|
+ private static final org.apache.logging.log4j.Logger LOGGER = org.apache.logging.log4j.LogManager.getLogger();
|
|
+ // Paper end
|
|
|
|
private final int id;
|
|
private final Type type;
|
|
- 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
|
|
}
|
|
|
|
/**
|
|
@@ -367,8 +492,10 @@ public enum Effect {
|
|
|
|
/**
|
|
* @return The type of the effect.
|
|
+ * @deprecated some effects can be both or neither
|
|
*/
|
|
@NotNull
|
|
+ @Deprecated // Paper - both
|
|
public Type getType() {
|
|
return this.type;
|
|
}
|
|
@@ -379,8 +506,15 @@ public enum Effect {
|
|
*/
|
|
@Nullable
|
|
public Class<?> getData() {
|
|
- return this.data;
|
|
+ return this.data == null ? null : this.data.get(0); // Paper
|
|
+ }
|
|
+
|
|
+ // 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()));
|
|
}
|
|
+ // Paper end - support deprecated data types
|
|
|
|
/**
|
|
* Gets the Effect associated with the given ID.
|
|
@@ -397,12 +531,26 @@ public enum Effect {
|
|
|
|
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.
|
|
+ * @deprecated not representative of what Effect does
|
|
*/
|
|
+ @Deprecated // Paper
|
|
public enum Type { SOUND, VISUAL }
|
|
}
|
|
diff --git a/src/test/java/org/bukkit/EffectTest.java b/src/test/java/org/bukkit/EffectTest.java
|
|
index 4344512fa84a2f97a750e06761d8e160c0959f6a..615a4583ef8e70a7c86c28e648d0b57e8e6b9674 100644
|
|
--- a/src/test/java/org/bukkit/EffectTest.java
|
|
+++ b/src/test/java/org/bukkit/EffectTest.java
|
|
@@ -5,10 +5,24 @@ import static org.hamcrest.CoreMatchers.*;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
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
|
|
}
|