2023-08-13 00:19:34 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Fri, 28 Jul 2023 15:02:44 -0700
Subject: [PATCH] Bandaid fix for Effect
Effect or LevelEvent needs to be replaced
but ideally after the enum PR has been merged
upstream. Until then, this test and these fixes
should address all the known issues with them
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftEffect.java b/src/main/java/org/bukkit/craftbukkit/CraftEffect.java
2024-01-14 10:46:04 +01:00
index a4519762175c68256b1f303daca8b9408ac182bb..457e9093adb99d31ffc7f061d8c858f98c5d0572 100644
2023-08-13 00:19:34 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/CraftEffect.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftEffect.java
2024-01-14 10:46:04 +01:00
@@ -16,12 +16,16 @@ public class CraftEffect {
2023-08-13 00:19:34 +02:00
public static <T> int getDataValue(Effect effect, T data) {
int datavalue;
switch (effect) {
+ case PARTICLES_SCULK_CHARGE: // Paper - add missing effects
2023-12-08 21:07:56 +01:00
+ case TRIAL_SPAWNER_DETECT_PLAYER: // Paper - add missing effects
2023-08-13 00:19:34 +02:00
case VILLAGER_PLANT_GROW:
datavalue = (Integer) data;
break;
case POTION_BREAK:
+ if (data instanceof Potion) { // Paper - use Color for POTION_BREAK
datavalue = ((Potion) data).toDamageValue() & 0x3F;
break;
+ } // Paper - Color will fall through to cast below
case INSTANT_POTION_BREAK:
datavalue = ((Color) data).asRGB();
break;
2024-01-14 10:46:04 +01:00
@@ -29,6 +33,13 @@ public class CraftEffect {
2023-12-08 21:07:56 +01:00
Preconditions.checkArgument(data == Material.AIR || ((Material) data).isRecord(), "Invalid record type for Material %s!", data);
2024-01-14 10:46:04 +01:00
datavalue = Item.getId(CraftItemType.bukkitToMinecraft((Material) data));
2023-12-08 21:07:56 +01:00
break;
+ // Paper start - handle shoot white smoke event
+ case SHOOT_WHITE_SMOKE:
+ final BlockFace face = (BlockFace) data;
+ Preconditions.checkArgument(face.isCartesian(), face + " isn't cartesian");
+ datavalue = org.bukkit.craftbukkit.block.CraftBlock.blockFaceToNotch(face).get3DDataValue();
+ break;
+ // Paper end - handle shoot white smoke event
case SMOKE:
switch ((BlockFace) data) {
case DOWN:
2024-01-14 10:46:04 +01:00
@@ -60,8 +71,15 @@ public class CraftEffect {
2023-08-13 00:19:34 +02:00
}
break;
case STEP_SOUND:
+ if (data instanceof Material) { // Paper - support BlockData
Preconditions.checkArgument(((Material) data).isBlock(), "Material %s is not a block!", data);
2024-01-14 10:46:04 +01:00
datavalue = Block.getId(CraftBlockType.bukkitToMinecraft((Material) data).defaultBlockState());
2023-08-13 00:19:34 +02:00
+ // Paper start - support BlockData
+ break;
+ }
+ case PARTICLES_AND_SOUND_BRUSH_BLOCK_COMPLETE:
+ datavalue = Block.getId(((org.bukkit.craftbukkit.block.data.CraftBlockData) data).getState());
+ // Paper end
break;
case COMPOSTER_FILL_ATTEMPT:
datavalue = ((Boolean) data) ? 1 : 0;
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
2024-01-19 17:54:05 +01:00
index cd2b1a0441d478f50a4d45159e506628dafaa9fc..dff7bfaef05290b07ca6cbfbdefb3fd02a1cf8f6 100644
2023-08-13 00:19:34 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
2023-12-25 23:51:56 +01:00
@@ -1430,7 +1430,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
2023-08-13 00:19:34 +02:00
public <T> void playEffect(Location loc, Effect effect, T data, int radius) {
if (data != null) {
Preconditions.checkArgument(effect.getData() != null, "Effect.%s does not have a valid Data", effect);
- Preconditions.checkArgument(effect.getData().isAssignableFrom(data.getClass()), "%s data cannot be used for the %s effect", data.getClass().getName(), effect);
+ Preconditions.checkArgument(effect.isApplicable(data), "%s data cannot be used for the %s effect", data.getClass().getName(), effect); // Paper
} else {
// Special case: the axis is optional for ELECTRIC_SPARK
Preconditions.checkArgument(effect.getData() == null || effect == Effect.ELECTRIC_SPARK, "Wrong kind of data for the %s effect", effect);
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
2024-01-19 17:54:05 +01:00
index ce1ba360df24798ea3e45918b4a18c2944b53f95..f5066806e7d62cd17c73397b8fc7b5bbab3227ea 100644
2023-08-13 00:19:34 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
Updated Upstream (Bukkit/CraftBukkit) (#10034)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing
Bukkit Changes:
f29cb801 Separate checkstyle-suppressions file is not required
86f99bbe SPIGOT-7540, PR-946: Add ServerTickManager API
d4119585 SPIGOT-6903, PR-945: Add BlockData#getMapColor
b7a2ed41 SPIGOT-7530, PR-947: Add Player#removeResourcePack
9dd56255 SPIGOT-7527, PR-944: Add WindCharge#explode()
994a6163 Attempt upgrade of resolver libraries
CraftBukkit Changes:
b3b43a6ad Add Checkstyle check for unused imports
13fb3358e SPIGOT-7544: Scoreboard#getEntries() doesn't get entries but class names
3dda99c06 SPIGOT-7540, PR-1312: Add ServerTickManager API
2ab4508c0 SPIGOT-6903, PR-1311: Add BlockData#getMapColor
1dbdbbed4 PR-1238: Remove unnecessary sign ticking
659728d2a MC-264285, SPIGOT-7439, PR-1237: Fix unbreakable flint and steel is completely consumed while igniting creeper
e37e29ce0 Increase outdated build delay
c00438b39 SPIGOT-7530, PR-1313: Add Player#removeResourcePack
492dd80ce SPIGOT-7527, PR-1310: Add WindCharge#explode()
e11fbb9d7 Upgrade MySQL driver
9f3a0bd2a Attempt upgrade of resolver libraries
60d16d7ca PR-1306: Centralize Bukkit and Minecraft entity conversion
Spigot Changes:
06d602e7 Rebuild patches
2023-12-17 03:09:28 +01:00
@@ -873,7 +873,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
2023-08-13 00:19:34 +02:00
Preconditions.checkArgument(effect != null, "Effect cannot be null");
if (data != null) {
Preconditions.checkArgument(effect.getData() != null, "Effect.%s does not have a valid Data", effect);
- Preconditions.checkArgument(effect.getData().isAssignableFrom(data.getClass()), "%s data cannot be used for the %s effect", data.getClass().getName(), effect);
+ Preconditions.checkArgument(effect.isApplicable(data), "%s data cannot be used for the %s effect", data.getClass().getName(), effect); // Paper
} else {
// Special case: the axis is optional for ELECTRIC_SPARK
Preconditions.checkArgument(effect.getData() == null || effect == Effect.ELECTRIC_SPARK, "Wrong kind of data for the %s effect", effect);
diff --git a/src/test/java/org/bukkit/EffectTest.java b/src/test/java/org/bukkit/EffectTest.java
new file mode 100644
2023-09-24 09:16:58 +02:00
index 0000000000000000000000000000000000000000..875eacc2e5776901ba8593d0183844db2571f71b
2023-08-13 00:19:34 +02:00
--- /dev/null
+++ b/src/test/java/org/bukkit/EffectTest.java
@@ -0,0 +1,64 @@
+package org.bukkit;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import net.minecraft.world.level.block.LevelEvent;
2023-09-24 09:16:58 +02:00
+import org.junit.jupiter.api.Test;
2023-08-13 00:19:34 +02:00
+
2023-09-24 09:16:58 +02:00
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
2023-08-13 00:19:34 +02:00
+
+public class EffectTest {
+
+ private static List<Integer> collectNmsLevelEvents() throws ReflectiveOperationException {
+ final List<Integer> events = new ArrayList<>();
+ for (final Field field : LevelEvent.class.getFields()) {
+ if (Modifier.isStatic(field.getModifiers()) && Modifier.isFinal(field.getModifiers()) && field.getType() == int.class) {
+ events.add((int) field.get(null));
+ }
+ }
+ return events;
+ }
+
+ private static boolean isNotDeprecated(Effect effect) throws ReflectiveOperationException {
+ return !Effect.class.getDeclaredField(effect.name()).isAnnotationPresent(Deprecated.class);
+ }
+
+ @SuppressWarnings("deprecation")
+ @Test
+ public void checkAllApiExists() throws ReflectiveOperationException {
+ Map<Integer, Effect> toId = new HashMap<>();
+ for (final Effect effect : Effect.values()) {
+ if (isNotDeprecated(effect)) {
+ final Effect put = toId.put(effect.getId(), effect);
2023-09-24 09:16:58 +02:00
+ assertNull(put, "duplicate API effect: " + put);
2023-08-13 00:19:34 +02:00
+ }
+ }
+
+ for (final Integer event : collectNmsLevelEvents()) {
2023-09-24 09:16:58 +02:00
+ assertNotNull(toId.get(event), "missing API Effect: " + event);
2023-08-13 00:19:34 +02:00
+ }
+ }
+
+ @SuppressWarnings("deprecation")
+ @Test
+ public void checkNoExtraApi() throws ReflectiveOperationException {
+ Map<Integer, Effect> toId = new HashMap<>();
+ for (final Effect effect : Effect.values()) {
+ if (isNotDeprecated(effect)) {
+ final Effect put = toId.put(effect.getId(), effect);
2023-09-24 09:16:58 +02:00
+ assertNull(put, "duplicate API effect: " + put);
2023-08-13 00:19:34 +02:00
+ }
+ }
+
+ final List<Integer> nmsEvents = collectNmsLevelEvents();
+ for (final Map.Entry<Integer, Effect> entry : toId.entrySet()) {
2023-09-24 09:16:58 +02:00
+ assertTrue(nmsEvents.contains(entry.getKey()), "Extra API Effect: " + entry.getValue());
2023-08-13 00:19:34 +02:00
+ }
+ }
+}