From aa7955c2663f5623213b529b6d331909e00cac36 Mon Sep 17 00:00:00 2001
From: Patrick Miller <apickledwalrus@gmail.com>
Date: Sat, 15 Jun 2024 12:59:10 -0400
Subject: [PATCH] Fix Particle Definition Conflicts (#6760)

---
 .../skript/classes/data/SkriptClasses.java    |  1 +
 src/main/resources/lang/default.lang          | 38 +++++++++----------
 .../pull-6760-particle itemtype conflicts.sk  |  5 +++
 .../tests/syntaxes/effects/EffVisualEffect.sk |  6 +--
 4 files changed, 28 insertions(+), 22 deletions(-)
 create mode 100644 src/test/skript/tests/regressions/pull-6760-particle itemtype conflicts.sk

diff --git a/src/main/java/ch/njol/skript/classes/data/SkriptClasses.java b/src/main/java/ch/njol/skript/classes/data/SkriptClasses.java
index 39dc6447fa5..6f92502cd2a 100644
--- a/src/main/java/ch/njol/skript/classes/data/SkriptClasses.java
+++ b/src/main/java/ch/njol/skript/classes/data/SkriptClasses.java
@@ -661,6 +661,7 @@ public String toVariableNameString(final Experience xp) {
 				.usage(VisualEffects.getAllNames())
 				.since("2.1")
 				.user("(visual|particle) effects?")
+				.after("itemtype")
 				.parser(new Parser<VisualEffect>() {
 					@Override
 					@Nullable
diff --git a/src/main/resources/lang/default.lang b/src/main/resources/lang/default.lang
index 9f7df2c9e4c..90a37eb9e32 100644
--- a/src/main/resources/lang/default.lang
+++ b/src/main/resources/lang/default.lang
@@ -1473,13 +1473,13 @@ visual effects:
 
 		block_marker: # added in 1.18
 			name: block marker @a
-			pattern: (barrierbm:barrier|lightbm:light|%-blockdata/itemtype% block marker)
+			pattern: (barrierbm:barrier [particle]|lightbm:light [particle]|%-blockdata/itemtype% block marker)
 		barrier:
 			name: barrier @a
-			pattern: barrier
+			pattern: barrier [particle]
 		light: # added in 1.17
 			name: light @-
-			pattern: light
+			pattern: light [particle]
 
 		bubble: # added in 1.20.5
 			name: bubble @-
@@ -1534,7 +1534,7 @@ visual effects:
 
 		dolphin: # added in 1.13
 			name: dolphin @-
-			pattern: dolphin
+			pattern: dolphin [particle]
 
 		dragon_breath: # added in 1.14
 			name: dragon breath @-
@@ -1602,10 +1602,10 @@ visual effects:
 
 		elder_guardian: # added in 1.20.5
 			name: elder guardian @-
-			pattern: (elder guardian|mob appearance|guardian ghost)
+			pattern: (elder guardian particle|mob appearance|guardian ghost)
 		mob_appearance: # for versions below 1.20.5
 			name: mob appearance @-
-			pattern: (elder guardian|mob appearance|guardian ghost)
+			pattern: (elder guardian particle|mob appearance|guardian ghost)
 
 		electric_spark:
 			name: electric spark @-
@@ -1627,7 +1627,7 @@ visual effects:
 
 		end_rod:
 			name: end rod @-
-			pattern: end rod
+			pattern: end rod [particle]
 
 		entity_effect: # added in 1.20.5
 			name: entity effect @an
@@ -1693,10 +1693,10 @@ visual effects:
 
 		firework: # added in 1.20.5
 			name: firework @-
-			pattern: (firework|firework['s] spark)
+			pattern: (firework particle|firework['s] spark)
 		fireworks_spark: # for versions below 1.20.5
 			name: firework's spark @-
-			pattern: (firework|firework['s] spark)
+			pattern: (firework particle|firework['s] spark)
 
 		fishing: # added in 1.20.5
 			name: water wake @-
@@ -1764,24 +1764,24 @@ visual effects:
 
 		item_cobweb: # added in 1.20.5 (for 1.21)
 			name: cobweb @-
-			pattern: cobweb
+			pattern: cobweb [item|particle]
 
 		item_slime: # added in 1.20.5
 			name: slime @-
-			pattern: slime
+			pattern: slime [item|particle]
 		slime: # for versions below 1.20.5
 			name: slime @-
-			pattern: slime
+			pattern: slime [item|particle]
 
 		item_snowball: # added in 1.20.5
 			name: snowball @-
-			pattern: (snowball [break]|snow shovel|snow(man| golem) spawn)
+			pattern: (snowball [item|break|particle]|snow shovel|snow(man| golem) spawn)
 		snowball: # for versions below 1.20.5
 			name: snowball break @-
 			pattern: snowball break
 		snow_shovel: # for versions below 1.20.5
 			name: snow shovel @-
-			pattern: (snowball|snow shovel|snow(man| golem) spawn)
+			pattern: (snowball [item|particle]|snow shovel|snow(man| golem) spawn)
 
 		landing_honey: # added in 1.15
 			name: landing honey @-
@@ -1808,7 +1808,7 @@ visual effects:
 
 		mycelium: # previously town_aura, changed in 1.20.5
 			name: mycelium @-
-			pattern: (mycelium|small smoke|town aura)
+			pattern: (mycelium [particle]|small smoke|town aura)
 		town_aura:
 			name: small smoke @-
 			pattern: (mycelium|small smoke|town aura)
@@ -1931,10 +1931,10 @@ visual effects:
 
 		totem_of_undying: # added in 1.20.5
 			name: totem of undying @a
-			pattern: totem [of undying]
+			pattern: totem [of undying] [particle]
 		totem: # for versions below 1.20.5
 			name: totem @a
-			pattern: totem [of undying]
+			pattern: totem [of undying] [particle]
 
 		trial omen: # added in 1.20.5 (for 1.21)
 			name: trial omen @a
@@ -1989,10 +1989,10 @@ visual effects:
 
 		witch: # added in 1.20.5
 			name: witch @a
-			pattern: (witch [magic|spell]|purple spark)
+			pattern: (witch (magic|spell|particle)|purple spark)
 		spell_witch: # for versions below 1.20.5
 			name: witch spell @a
-			pattern: (witch [magic|spell]|purple spark)
+			pattern: (witch (magic|spell|particle)|purple spark)
 
 # -- Inventory Actions --
 inventory actions:
diff --git a/src/test/skript/tests/regressions/pull-6760-particle itemtype conflicts.sk b/src/test/skript/tests/regressions/pull-6760-particle itemtype conflicts.sk
new file mode 100644
index 00000000000..d4cac535c18
--- /dev/null
+++ b/src/test/skript/tests/regressions/pull-6760-particle itemtype conflicts.sk	
@@ -0,0 +1,5 @@
+test "particle itemtype conflicts":
+
+	# itemtype parsing should take priority over visual effects
+	assert totem of undying is an itemtype with "totem of undying is not an itemtype"
+	assert mycelium is an itemtype with "mycelium is not an itemtype"
diff --git a/src/test/skript/tests/syntaxes/effects/EffVisualEffect.sk b/src/test/skript/tests/syntaxes/effects/EffVisualEffect.sk
index b8631e79cf2..a4791d1752a 100644
--- a/src/test/skript/tests/syntaxes/effects/EffVisualEffect.sk
+++ b/src/test/skript/tests/syntaxes/effects/EffVisualEffect.sk
@@ -16,7 +16,7 @@ test "visual effects":
 	play dripping water at {_}
 	play white dust with size 2 at {_}
 	play effect at {_}
-	play elder guardian at {_}
+	play elder guardian particle at {_}
 	play enchant at {_}
 	play enchanted hit at {_}
 	play end rod at {_}
@@ -26,7 +26,7 @@ test "visual effects":
 	play large explosion at {_}
 	play explosion emitter at {_}
 	play falling dust of air at {_}
-	play firework at {_}
+	play firework spark at {_}
 	play fishing at {_}
 	play flame at {_}
 	play happy villager at {_}
@@ -51,7 +51,7 @@ test "visual effects":
 	play totem of undying at {_}
 	play suspended at {_}
 	play void fog at {_}
-	play witch at {_}
+	play witch particle at {_}
 	parse if running minecraft "1.14.4":
 		play campfire cosy smoke at {_}
 		play campfire signal smoke at {_}