4
4
import com .gmail .nossr50 .datatypes .skills .alchemy .AlchemyPotion ;
5
5
import com .gmail .nossr50 .mcMMO ;
6
6
import com .gmail .nossr50 .util .ItemUtils ;
7
+ import com .gmail .nossr50 .util .LogUtils ;
7
8
import org .bukkit .ChatColor ;
8
9
import org .bukkit .Color ;
9
10
import org .bukkit .Material ;
14
15
import org .bukkit .potion .PotionEffect ;
15
16
import org .bukkit .potion .PotionEffectType ;
16
17
import org .bukkit .potion .PotionType ;
18
+ import org .jetbrains .annotations .NotNull ;
17
19
import org .jetbrains .annotations .VisibleForTesting ;
18
20
19
21
import java .io .File ;
26
28
import static com .gmail .nossr50 .util .PotionUtil .*;
27
29
28
30
public class PotionConfig extends LegacyConfigLoader {
31
+ private static final String BREEZE_ROD_STR = "BREEZE_ROD" ;
32
+ private static final String INFESTED_EFFECT_STR = "INFESTED" ;
33
+ private static final String WEAVING_EFFECT_STR = "WEAVING" ;
34
+ private static final String OOZING_EFFECT_STR = "OOZING" ;
35
+ private static final String WIND_CHARGED_EFFECT_STR = "WIND_CHARGED" ;
36
+ private static final String SLIME_BLOCK_STR = "SLIME_BLOCK" ;
37
+ private static final String COBWEB_STR = "COBWEB" ;
38
+ private static final String STONE_STR = "STONE" ;
29
39
30
40
private final List <ItemStack > concoctionsIngredientsTierOne = new ArrayList <>();
31
41
private final List <ItemStack > concoctionsIngredientsTierTwo = new ArrayList <>();
@@ -35,6 +45,17 @@ public class PotionConfig extends LegacyConfigLoader {
35
45
private final List <ItemStack > concoctionsIngredientsTierSix = new ArrayList <>();
36
46
private final List <ItemStack > concoctionsIngredientsTierSeven = new ArrayList <>();
37
47
private final List <ItemStack > concoctionsIngredientsTierEight = new ArrayList <>();
48
+ private final AlchemyPotionConfigResult INCOMPATIBLE_POTION_RESULT = new AlchemyPotionConfigResult (null ,
49
+ AlchemyPotionConfigResultType .INCOMPATIBLE );
50
+ private final AlchemyPotionConfigResult ERROR_POTION_RESULT = new AlchemyPotionConfigResult (null ,
51
+ AlchemyPotionConfigResultType .ERROR );
52
+
53
+ record AlchemyPotionConfigResult (AlchemyPotion alchemyPotion , AlchemyPotionConfigResultType resultType ) {}
54
+ enum AlchemyPotionConfigResultType {
55
+ LOADED ,
56
+ INCOMPATIBLE ,
57
+ ERROR ;
58
+ }
38
59
39
60
/**
40
61
* Map of potion names to AlchemyPotion objects.
@@ -93,39 +114,45 @@ private void loadConcoctionsTier(List<ItemStack> ingredientList, List<String> in
93
114
}
94
115
}
95
116
}
96
-
97
117
/**
98
118
* Find the Potions configuration section and load all defined potions.
99
119
*/
100
120
int loadPotionMap () {
101
121
ConfigurationSection potionSection = config .getConfigurationSection ("Potions" );
102
122
int potionsLoaded = 0 ;
123
+ int incompatible = 0 ;
103
124
int failures = 0 ;
104
125
105
126
for (String potionName : potionSection .getKeys (false )) {
106
- AlchemyPotion potion = loadPotion (potionSection .getConfigurationSection (potionName ));
127
+ AlchemyPotionConfigResult alchemyPotionConfigResult = loadPotion (potionSection .getConfigurationSection (potionName ));
128
+ AlchemyPotion potion = alchemyPotionConfigResult .alchemyPotion ;
107
129
108
130
if (potion != null ) {
109
131
alchemyPotions .put (potionName , potion );
110
132
potionsLoaded ++;
111
133
} else {
112
- failures ++;
134
+ if (alchemyPotionConfigResult .resultType == AlchemyPotionConfigResultType .INCOMPATIBLE ) {
135
+ incompatible ++;
136
+ } else {
137
+ failures ++;
138
+ }
113
139
}
114
140
}
115
141
116
- mcMMO .p .getLogger ().info ("Loaded " + potionsLoaded + " Alchemy potions, skipped " + failures + "." );
142
+ int totalPotions = potionsLoaded + incompatible + failures ;
143
+
144
+ mcMMO .p .getLogger ().info ("Loaded " + potionsLoaded + "/" + totalPotions + " Alchemy potions." );
145
+ if (incompatible > 0 ) {
146
+ mcMMO .p .getLogger ().info ("Skipped " + incompatible + " Alchemy potions that require a newer" +
147
+ " Minecraft game version." );
148
+ }
149
+ if (failures > 0 ) {
150
+ mcMMO .p .getLogger ().info ("Failed to load " + failures + " Alchemy potions that encountered errors while loading." );
151
+ }
117
152
return potionsLoaded ;
118
153
}
119
154
120
- /**
121
- * Parse a ConfigurationSection representing a AlchemyPotion.
122
- * Returns null if input cannot be parsed.
123
- *
124
- * @param potion_section ConfigurationSection to be parsed.
125
- *
126
- * @return Parsed AlchemyPotion.
127
- */
128
- private AlchemyPotion loadPotion (ConfigurationSection potion_section ) {
155
+ private @ NotNull AlchemyPotionConfigResult loadPotion (ConfigurationSection potion_section ) {
129
156
try {
130
157
final String key = potion_section .getName ();
131
158
@@ -159,7 +186,7 @@ private AlchemyPotion loadPotion(ConfigurationSection potion_section) {
159
186
if (potionMeta == null ) {
160
187
mcMMO .p .getLogger ().severe ("PotionConfig: Failed to get PotionMeta for " + key + ", from configuration section:" +
161
188
" " + potion_section );
162
- return null ;
189
+ return ERROR_POTION_RESULT ;
163
190
}
164
191
165
192
// extended and upgraded seem to be mutually exclusive
@@ -173,14 +200,14 @@ private AlchemyPotion loadPotion(ConfigurationSection potion_section) {
173
200
if (potionTypeStr == null ) {
174
201
mcMMO .p .getLogger ().severe ("PotionConfig: Missing PotionType for " + key + ", from configuration section:" +
175
202
" " + potion_section );
176
- return null ;
203
+ return ERROR_POTION_RESULT ;
177
204
}
178
205
179
206
// This works via side effects
180
207
// TODO: Redesign later, side effects are stupid
181
208
if (!setPotionType (potionMeta , potionTypeStr , upgraded , extended )) {
182
209
mcMMO .p .getLogger ().severe ("PotionConfig: Failed to set parameters of potion for " + key + ": " + potionTypeStr );
183
- return null ;
210
+ return ERROR_POTION_RESULT ;
184
211
}
185
212
186
213
final List <String > lore = new ArrayList <>();
@@ -194,6 +221,12 @@ private AlchemyPotion loadPotion(ConfigurationSection potion_section) {
194
221
if (potion_section .contains ("Effects" )) {
195
222
for (String effect : potion_section .getStringList ("Effects" )) {
196
223
String [] parts = effect .split (" " );
224
+ if (isTrickyTrialsPotionEffect (parts [0 ])
225
+ && !mcMMO .getCompatibilityManager ().getMinecraftGameVersion ().isAtLeast (1 , 21 , 0 )) {
226
+ LogUtils .debug (mcMMO .p .getLogger (), "Skipping potion effect " + effect +" because it is not" +
227
+ " compatible with the current Minecraft game version." );
228
+ return INCOMPATIBLE_POTION_RESULT ;
229
+ }
197
230
198
231
PotionEffectType type = parts .length > 0 ? PotionEffectType .getByName (parts [0 ]) : null ;
199
232
int amplifier = parts .length > 1 ? Integer .parseInt (parts [1 ]) : 0 ;
@@ -217,12 +250,19 @@ private AlchemyPotion loadPotion(ConfigurationSection potion_section) {
217
250
218
251
final Map <ItemStack , String > children = new HashMap <>();
219
252
if (potion_section .contains ("Children" )) {
220
- for (String child : potion_section .getConfigurationSection ("Children" ).getKeys (false )) {
221
- ItemStack ingredient = loadIngredient (child );
253
+ for (String childIngredient : potion_section .getConfigurationSection ("Children" ).getKeys (false )) {
254
+ // Breeze Rod was only for potions after 1.21.0
255
+ if (isTrickyTrialsIngredient (childIngredient )
256
+ && !mcMMO .getCompatibilityManager ().getMinecraftGameVersion ().isAtLeast (1 , 21 , 0 )) {
257
+ continue ;
258
+ }
259
+ ItemStack ingredient = loadIngredient (childIngredient );
222
260
if (ingredient != null ) {
223
- children .put (ingredient , potion_section .getConfigurationSection ("Children" ).getString (child ));
261
+ children .put (ingredient ,
262
+ potion_section .getConfigurationSection ("Children" ).getString (childIngredient ));
224
263
} else {
225
- mcMMO .p .getLogger ().severe ("PotionConfig: Failed to parse child for potion " + key + ": " + child );
264
+ mcMMO .p .getLogger ().severe (
265
+ "PotionConfig: Failed to parse child for potion " + key + ": " + childIngredient );
226
266
}
227
267
}
228
268
}
@@ -231,14 +271,25 @@ private AlchemyPotion loadPotion(ConfigurationSection potion_section) {
231
271
232
272
// TODO: Might not need to .setItemMeta
233
273
itemStack .setItemMeta (potionMeta );
234
- return new AlchemyPotion (potion_section .getName (), itemStack , children );
274
+ return new AlchemyPotionConfigResult (new AlchemyPotion (potion_section .getName (), itemStack , children ),
275
+ AlchemyPotionConfigResultType .LOADED );
235
276
} catch (Exception e ) {
236
277
mcMMO .p .getLogger ().warning ("PotionConfig: Failed to load Alchemy potion: " + potion_section .getName ());
237
278
e .printStackTrace ();
238
- return null ;
279
+ return ERROR_POTION_RESULT ;
239
280
}
240
281
}
241
282
283
+ private static boolean isTrickyTrialsIngredient (String ingredientStr ) {
284
+ return ingredientStr .equalsIgnoreCase (BREEZE_ROD_STR ) || ingredientStr .equalsIgnoreCase (SLIME_BLOCK_STR )
285
+ || ingredientStr .equalsIgnoreCase (COBWEB_STR ) || ingredientStr .equalsIgnoreCase (STONE_STR );
286
+ }
287
+
288
+ private static boolean isTrickyTrialsPotionEffect (String effectStr ) {
289
+ return effectStr .equalsIgnoreCase (INFESTED_EFFECT_STR ) || effectStr .equalsIgnoreCase (WEAVING_EFFECT_STR )
290
+ || effectStr .equalsIgnoreCase (OOZING_EFFECT_STR ) || effectStr .equalsIgnoreCase (WIND_CHARGED_EFFECT_STR );
291
+ }
292
+
242
293
private boolean setPotionType (PotionMeta potionMeta , String potionTypeStr , boolean upgraded , boolean extended ) {
243
294
final PotionType potionType = matchPotionType (potionTypeStr , upgraded , extended );
244
295
0 commit comments