Skip to content
This repository has been archived by the owner on Mar 8, 2022. It is now read-only.

Commit

Permalink
check null for ShopItem
Browse files Browse the repository at this point in the history
  • Loading branch information
ReinWD committed Apr 20, 2020
1 parent 55155e2 commit 905ad87
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/main/java/cat/nyaa/HamsterEcoHelper/database/SignShop.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ public List<ShopItem> loadItems(String path) {
if (config.isConfigurationSection(path)) {
ConfigurationSection section = config.getConfigurationSection(path);
for (String k : section.getKeys(false)) {
list.add(new ShopItem(section.getConfigurationSection(k)));
try{
list.add(new ShopItem(section.getConfigurationSection(k)));
}catch (Exception e){
logCorruptedItem();
}
}
}
return list;
Expand All @@ -81,21 +85,25 @@ public void saveItems(String path, List<ShopItem> list) {
if (item.amount > 0 && item.getItemStack(1).getType() != Material.AIR) {
ShopItem shopItem = list.get(i);
if (shopItem.itemStack == null){
OfflinePlayer player = getPlayer();
String playerName = "";
if (player == null){
playerName = "null";
}else {
playerName = player.getName();
}
Bukkit.getLogger().severe("null item found saving shop for " + playerName + ", uid " + getOwner() +".");
logCorruptedItem();
continue;
}
shopItem.save(section.createSection(String.valueOf(i)));
}
}
}

private void logCorruptedItem() {
OfflinePlayer player = getPlayer();
String playerName = "";
if (player == null){
playerName = "null";
}else {
playerName = player.getName();
}
Bukkit.getLogger().severe("null item found saving shop for " + playerName + ", uid " + getOwner() +".");
}

public void yamlToNBT() {
if (config == null) {
load();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cat.nyaa.HamsterEcoHelper.signshop;

import cat.nyaa.nyaacore.utils.ItemStackUtils;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemStack;

Expand Down Expand Up @@ -36,6 +37,9 @@ public void save(ConfigurationSection section) {
}

public ItemStack getItemStack(int amount) {
if (itemStack == null){
return new ItemStack(Material.AIR);
}
ItemStack item = itemStack.clone();
item.setAmount(amount);
return item;
Expand Down

0 comments on commit 905ad87

Please sign in to comment.