mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-26 12:36:07 +01:00
31699ae9a8
* Updated Upstream (Bukkit/CraftBukkit) 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: a6a9d2a4 Remove some old ApiStatus.Experimental annotations be72314c SPIGOT-7300, PR-829: Add new DamageSource API providing enhanced information about entity damage b252cf05 SPIGOT-7576, PR-970: Add methods in MushroomCow to change stew effects b1c689bd PR-902: Add Server#isLoggingIPs to get log-ips configuration 08f86d1c PR-971: Add Player methods for client-side potion effects 2e3024a9 PR-963: Add API for in-world structures a23292a7 SPIGOT-7530, PR-948: Improve Resource Pack API with new 1.20.3 functionality 1851857b SPIGOT-3071, PR-969: Add entity spawn method with spawn reason cde4c52a SPIGOT-5553, PR-964: Add EntityKnockbackEvent CraftBukkit Changes: 38fd4bd50 Fix accidentally renamed internal damage method 80f0ce4be SPIGOT-7300, PR-1180: Add new DamageSource API providing enhanced information about entity damage 7e43f3b16 SPIGOT-7581: Fix typo in BlockMushroom ea14b7d90 SPIGOT-7576, PR-1347: Add methods in MushroomCow to change stew effects 4c687f243 PR-1259: Add Server#isLoggingIPs to get log-ips configuration 22a541a29 Improve support for per-world game rules cb7dccce2 PR-1348: Add Player methods for client-side potion effects b8d6109f0 PR-1335: Add API for in-world structures 4398a1b5b SPIGOT-7577: Make CraftWindCharge#explode discard the entity e74107678 Fix Crafter maximum stack size 0bb0f4f6a SPIGOT-7530, PR-1314: Improve Resource Pack API with new 1.20.3 functionality 4949f556d SPIGOT-3071, PR-1345: Add entity spawn method with spawn reason 20ac73ca2 PR-1353: Fix Structure#place not working as documented with 0 palette 3c1b77871 SPIGOT-6911, PR-1349: Change max book length in CraftMetaBook 333701839 SPIGOT-7572: Bee nests generated without bees f48f4174c SPIGOT-5553, PR-1336: Add EntityKnockbackEvent
158 lines
8.1 KiB
Diff
158 lines
8.1 KiB
Diff
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
|
|
index a4519762175c68256b1f303daca8b9408ac182bb..457e9093adb99d31ffc7f061d8c858f98c5d0572 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftEffect.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftEffect.java
|
|
@@ -16,12 +16,16 @@ public class CraftEffect {
|
|
public static <T> int getDataValue(Effect effect, T data) {
|
|
int datavalue;
|
|
switch (effect) {
|
|
+ case PARTICLES_SCULK_CHARGE: // Paper - add missing effects
|
|
+ case TRIAL_SPAWNER_DETECT_PLAYER: // Paper - add missing effects
|
|
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;
|
|
@@ -29,6 +33,13 @@ public class CraftEffect {
|
|
Preconditions.checkArgument(data == Material.AIR || ((Material) data).isRecord(), "Invalid record type for Material %s!", data);
|
|
datavalue = Item.getId(CraftItemType.bukkitToMinecraft((Material) data));
|
|
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:
|
|
@@ -60,8 +71,15 @@ public class CraftEffect {
|
|
}
|
|
break;
|
|
case STEP_SOUND:
|
|
+ if (data instanceof Material) { // Paper - support BlockData
|
|
Preconditions.checkArgument(((Material) data).isBlock(), "Material %s is not a block!", data);
|
|
datavalue = Block.getId(CraftBlockType.bukkitToMinecraft((Material) data).defaultBlockState());
|
|
+ // 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
|
|
index 54cdb4b6a97250c1e15e2fce355e3699c9189948..457d5cdb510a11a069ac7f54a8ed95a74527bff3 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
|
@@ -1371,7 +1371,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
|
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
|
|
index 0f32750ec4bc85033c6da8a21f4ad3150112ece6..59dd4f06d33a0bb8e747857ee81f6465b7ed78b1 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
@@ -837,7 +837,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|
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
|
|
index 0000000000000000000000000000000000000000..875eacc2e5776901ba8593d0183844db2571f71b
|
|
--- /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;
|
|
+import org.junit.jupiter.api.Test;
|
|
+
|
|
+import static org.junit.jupiter.api.Assertions.assertNotNull;
|
|
+import static org.junit.jupiter.api.Assertions.assertNull;
|
|
+import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
+
|
|
+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);
|
|
+ assertNull(put, "duplicate API effect: " + put);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ for (final Integer event : collectNmsLevelEvents()) {
|
|
+ assertNotNull(toId.get(event), "missing API Effect: " + event);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ @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);
|
|
+ assertNull(put, "duplicate API effect: " + put);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ final List<Integer> nmsEvents = collectNmsLevelEvents();
|
|
+ for (final Map.Entry<Integer, Effect> entry : toId.entrySet()) {
|
|
+ assertTrue(nmsEvents.contains(entry.getKey()), "Extra API Effect: " + entry.getValue());
|
|
+ }
|
|
+ }
|
|
+}
|