Fix null-check for loot items and adjust rarity handling in generateLoot method
This commit is contained in:
parent
25c95dd46a
commit
8ba514c9c2
|
|
@ -2,6 +2,7 @@ package com.alttd.hunger_games.services;
|
|||
|
||||
import com.alttd.hunger_games.config.LootItems;
|
||||
import com.alttd.hunger_games.data_objects.RARITY;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
|
|
@ -14,6 +15,7 @@ import java.util.List;
|
|||
import java.util.Random;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
@Slf4j
|
||||
public class LootService {
|
||||
|
||||
private final HashMap<Location, Inventory> chestInventories = new HashMap<>();
|
||||
|
|
@ -31,16 +33,18 @@ public class LootService {
|
|||
|
||||
private Inventory generateLoot() {
|
||||
Inventory inventory = Bukkit.createInventory(null, 27, Component.text("Chest"));
|
||||
RARITY rarity = decideRarity();
|
||||
List<Material> possibleItems = LootItems.ITEMS.get(rarity);
|
||||
|
||||
if (possibleItems.isEmpty()) {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
int itemCount = random.nextInt(3, 7);
|
||||
for (int i = 0; i < itemCount; i++) {
|
||||
int slot = random.nextInt(27);
|
||||
RARITY rarity = decideRarity();
|
||||
List<Material> possibleItems = LootItems.ITEMS.get(rarity);
|
||||
|
||||
if (possibleItems == null || possibleItems.isEmpty()) {
|
||||
log.warn("No items found for rarity: {}", rarity);
|
||||
continue;
|
||||
}
|
||||
|
||||
Material material = possibleItems.get(random.nextInt(possibleItems.size()));
|
||||
inventory.setItem(slot, new ItemStack(material));
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user