Skip to content

Commit

Permalink
fix handling empty messages
Browse files Browse the repository at this point in the history
  • Loading branch information
hyperdefined committed Jan 18, 2025
1 parent c68a048 commit 98ee84a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

<groupId>lol.hyper</groupId>
<artifactId>toolstats</artifactId>
<version>1.8.5</version>
<version>1.8.6</version>
<packaging>jar</packaging>

<name>ToolStats</name>
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/lol/hyper/toolstats/events/CraftItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ public void onCraft(CraftItemEvent event) {
// if the player shift clicks, send them this warning
if (event.isShiftClick()) {
Component component = toolStats.configTools.formatLore("shift-click-warning.crafting", null, null);
event.getWhoClicked().sendMessage(component);
if (component != null) {
event.getWhoClicked().sendMessage(component);
}
}

// test the item before setting it
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/lol/hyper/toolstats/events/VillagerTrade.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ public void onTrade(InventoryClickEvent event) {
// if the player shift clicks, show the warning
if (event.isShiftClick()) {
Component component = toolStats.configTools.formatLore("shift-click-warning.trading", null, null);
event.getWhoClicked().sendMessage(component);
if (component != null) {
event.getWhoClicked().sendMessage(component);
}
}
ItemStack newItem = addLore(item, player);
if (newItem != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ public boolean checkConfig(Material material, String configName) {
public Component formatLore(String configName, String placeHolder, Object value) {
String lore = toolStats.config.getString("messages." + configName);
if (lore == null) {
toolStats.logger.warning("Unable to find config message for: messages." + configName);
return null;
}

// if the config message is empty, don't send it
if (lore.isEmpty()) {
return null;
}

Expand Down

0 comments on commit 98ee84a

Please sign in to comment.