allow blocks with no drop tables

This commit is contained in:
Indyuce 2022-01-30 13:00:30 +01:00
parent 584619070b
commit 333ecf93da
2 changed files with 9 additions and 10 deletions

View File

@ -14,11 +14,9 @@ import org.bukkit.block.Block;
import org.bukkit.block.data.BlockData;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.logging.Level;
public class BlockInfo {
@ -78,18 +76,19 @@ public class BlockInfo {
return block;
}
@NotNull
public DropTable getDropTable() {
return table;
}
public List<ItemStack> collectDrops(LootBuilder builder) {
return hasDropTable() ? table.collect(builder) : new ArrayList<>();
return Objects.requireNonNull(table, "Block has no drop table");
}
public boolean hasDropTable() {
return table != null;
}
public List<ItemStack> collectDrops(LootBuilder builder) {
return table != null ? table.collect(builder) : new ArrayList<>();
}
public boolean hasRegen() {
return regen != null;
}

View File

@ -85,7 +85,7 @@ public class BlockListener implements Listener {
* Find the block drops
*/
boolean conditionsMet = !info.hasDropTable() || info.getDropTable().areConditionsMet(new ConditionInstance(player));
List<ItemStack> drops = conditionsMet ? info.getDropTable().collect(new LootBuilder(PlayerData.get(player), 0)) : new ArrayList<>();
List<ItemStack> drops = conditionsMet && info.hasDropTable() ? info.getDropTable().collect(new LootBuilder(PlayerData.get(player), 0)) : new ArrayList<>();
/*
* Calls the event and listen for cancel & for drops changes... also