Well java is annoying. Help me out

Status
This thread has been locked.

Ghast

Founding Father of Hypocrisy - https://artemis.ac
Supreme
Feedback score
54
Posts
2,096
Reactions
3,285
Resources
79
This is my method to show rewards,
Code:
 public void showRewards(Player p, Bossraid raid, boolean regular) {
        Inventory inv;
        RewardList list;
        if (regular) {
            inv = Bukkit.createInventory(null, 54, ChatColor.RED + "Regular rewards for " + raid.getName());
            list = HandlerManager.getRewardHandler().getRewardList(raid.getRegularRewardList());

        } else {
            inv = Bukkit.createInventory(null, 54, ChatColor.RED + "Epic rewards for " + raid.getName());
            list = HandlerManager.getRewardHandler().getRewardList(raid.getEpicRewardList());
        }
        if (!list.isReady()) {
            MessageManager.message(p, ChatColor.RED + "List is not yet finalized.");
        } else {
            list.getItems().forEach((i, c) -> {
                inv.addItem(ItemFactory.createItem(i, "", ChatColor.GREEN + "Chance: " + ChatColor.YELLOW + i + "%"));
            });
            p.openInventory(inv);
        }
    }
Reward handler:
Code:
public RewardList getRewardList(String name) {
        Optional<RewardList> o = rewards.stream().filter(rewardList -> rewardList.getName().equalsIgnoreCase(name)).findAny();
        return o.isPresent() ? o.get() : null;
    }


This is my command to show rewards:
Code:
if (args[1].equalsIgnoreCase("rewards")) {
                if (args[2].equalsIgnoreCase("regular")) {
                    BossraidManager.getInstance().showRewards(p, raid, true);
                    return true;
                }
                if (args[2].equalsIgnoreCase("epic")) {
                    BossraidManager.getInstance().showRewards(p, raid, false);
                    return true;
                }
                MessageManager.message(p, Message.NO_SUCH_LIST.toString());
                return true;
            }

And this is the wall I keep hitting:
45641.png
 

Attachments

  • 45641.png
    45641.png
    50.8 KB · Views: 63
PebbleHost
High performance, consistent uptime and fast support. Minecraft hosting that just works.

Cole

Developer
Supreme
Feedback score
19
Posts
944
Reactions
477
Resources
0
What's line 81 in the boss raid manager class? It's returning null
 

Ghast

Founding Father of Hypocrisy - https://artemis.ac
Supreme
Feedback score
54
Posts
2,096
Reactions
3,285
Resources
79
Well, it's pretty clear that list is null. Since getRewardList can return null you should add in a null check before you attempt to see if it's ready.

So you can try to change
Code:
if (!list.isReady()) {

}
to

Code:
if (list == null || !list.isReady()) {

}

Since the list is null, you should go over getRewardList and follow wherever it's retrieving its information from and try to see if you can spot why it might be returning null.
I appreciate the spoon feed, I guess I learnt more about nulls :shrug:
Thank you Carlos.
 
Status
This thread has been locked.
Top