Add try/catch around potioneffects for older servers

This commit is contained in:
tastybento 2024-07-23 13:19:24 -07:00
parent a7c9ae6e36
commit 4bfd405c4e

View File

@ -363,16 +363,23 @@ public class LangUtilsHook extends Hook {
* @param user The user's language will be used for translation.
* @return Return the translation result.
*/
@SuppressWarnings("deprecation")
public static String getPotionBaseEffectName(PotionType potionType, User user) {
if (hooked) {
return LanguageHelper.getPotionBaseEffectName(potionType, getUserLocale(user));
}
try {
List<PotionEffect> effects = potionType.getPotionEffects();
if (effects.isEmpty()) {
return "No Effects";
}
return effects.stream().map(effect -> Util.prettifyText(effect.getType().getKey().getKey()))
.collect(Collectors.joining(", "));
} catch (Exception e) {
// Older versions of Spigot pre-1.20.4 don't have getPotionEffects()
return Util.prettifyText(potionType.getEffectType().getKey().getKey());
}
}
/**