[Bug] NullPointerException in SummonMerchantEnchantment.onPlayerChat on every chat message
EliteMobs Version: 10.0.1
Server: Paper 1.21.8
Java: 21
Description
Every time a player sends a chat message, the following error is thrown:
[ERROR] Could not pass event AsyncPlayerChatEvent to EliteMobs v10.0.1
java.lang.NullPointerException: Cannot invoke "String.isEmpty()" because
"com.magmaguy.elitemobs.items.customenchantments.SummonMerchantEnchantment.merchantMessage" is null
at SummonMerchantEnchantment$SummonMerchantEvents.onPlayerChat(SummonMerchantEnchantment.java:88)
Root Cause
In SummonMerchantEnchantment.java (Line 24), the merchantMessage field is initialized as a static final field:
private static final String merchantMessage = EnchantmentsConfig.getEnchantment("summon_merchant.yml")
.getFileConfiguration().getString("message");
However, the message key is only written to the config file by SummonMerchantConfig.processAdditionalFields(), which runs after the SummonMerchantEnchantment class is loaded by the JVM.
This means getString("message") returns null because the key doesn't exist in the YAML file yet at the time of class loading.
The onPlayerChat method at line 88 then calls merchantMessage.isEmpty() on this null value, causing the NPE on every single chat message.
Suggested Fix
Either:
Option 1: Use a null-safe default value
private static final String merchantMessage = EnchantmentsConfig.getEnchantment("summon_merchant.yml")
.getFileConfiguration().getString("message", "");
Option 2: Add a null check in onPlayerChat
@EventHandler
public void onPlayerChat(AsyncPlayerChatEvent event) {
if (merchantMessage == null || merchantMessage.isEmpty()) return;
// ...
}
Option 3: Read from SummonMerchantConfig.message instead
Use SummonMerchantConfig.message (the static field that IS properly initialized via processAdditionalFields) instead of directly reading from FileConfiguration.
Steps to Reproduce
- Fresh install EliteMobs 10.0.1
- Start the server
- Join and type any chat message
- Observe the NPE in console
Additional Notes
- Setting
isEnabled: false in enchantments/summon_merchant.yml does NOT prevent the error, because the event listener is still registered regardless of the enchantment's enabled state.
- The
message key is never written to the YAML file, confirming that processAdditionalFields() is not being called before the static initializer runs.
- The error does not crash the server or prevent chat from working — the chat message is still delivered — but it spams the console with error stack traces on every single chat message.
Relevant Source Files
[Bug] NullPointerException in SummonMerchantEnchantment.onPlayerChat on every chat message
EliteMobs Version: 10.0.1
Server: Paper 1.21.8
Java: 21
Description
Every time a player sends a chat message, the following error is thrown:
Root Cause
In
SummonMerchantEnchantment.java(Line 24), themerchantMessagefield is initialized as astatic finalfield:However, the
messagekey is only written to the config file bySummonMerchantConfig.processAdditionalFields(), which runs after theSummonMerchantEnchantmentclass is loaded by the JVM.This means
getString("message")returnsnullbecause the key doesn't exist in the YAML file yet at the time of class loading.The
onPlayerChatmethod at line 88 then callsmerchantMessage.isEmpty()on thisnullvalue, causing the NPE on every single chat message.Suggested Fix
Either:
Option 1: Use a null-safe default value
Option 2: Add a null check in
onPlayerChatOption 3: Read from SummonMerchantConfig.message instead
Use
SummonMerchantConfig.message(the static field that IS properly initialized viaprocessAdditionalFields) instead of directly reading fromFileConfiguration.Steps to Reproduce
Additional Notes
isEnabled: falseinenchantments/summon_merchant.ymldoes NOT prevent the error, because the event listener is still registered regardless of the enchantment's enabled state.messagekey is never written to the YAML file, confirming thatprocessAdditionalFields()is not being called before the static initializer runs.Relevant Source Files