mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 11:48:02 +00:00
Move empty init exception into BagRandomizer
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package forge.item.generation;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import forge.card.CardEdition;
|
||||
import forge.item.BoosterPack;
|
||||
import forge.item.PaperCard;
|
||||
@@ -11,10 +10,7 @@ import java.util.List;
|
||||
public class ChaosBoosterSupplier implements IUnOpenedProduct {
|
||||
private BagRandomizer<CardEdition> randomizer;
|
||||
|
||||
public ChaosBoosterSupplier(Iterable<CardEdition> sets) throws Exception {
|
||||
if (Iterables.size(sets) <= 0) {
|
||||
throw new Exception("At least one set needed to generate chaos draft!");
|
||||
}
|
||||
public ChaosBoosterSupplier(Iterable<CardEdition> sets) throws IllegalArgumentException {
|
||||
randomizer = new BagRandomizer<>(sets);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,16 +17,22 @@ public class BagRandomizer<T > implements Iterable<T>{
|
||||
private T[] bag;
|
||||
private int currentPosition = 0;
|
||||
|
||||
public BagRandomizer(T[] items) {
|
||||
public BagRandomizer(T[] items) throws IllegalArgumentException {
|
||||
if (items.length == 0) {
|
||||
throw new IllegalArgumentException("Must include at least one item!");
|
||||
}
|
||||
bag = items;
|
||||
shuffleBag();
|
||||
}
|
||||
|
||||
public BagRandomizer(Iterable<T> items) {
|
||||
public BagRandomizer(Iterable<T> items) throws IllegalArgumentException {
|
||||
ArrayList<T> list = new ArrayList<>();
|
||||
for (T item : items) {
|
||||
list.add(item);
|
||||
}
|
||||
if (list.size() == 0) {
|
||||
throw new IllegalArgumentException("Must include at least one item!");
|
||||
}
|
||||
bag = (T[]) list.toArray();
|
||||
shuffleBag();
|
||||
}
|
||||
|
||||
@@ -207,9 +207,9 @@ public class BoosterDraft implements IBoosterDraft {
|
||||
themeFilter);
|
||||
// Add chaos "boosters" as special suppliers
|
||||
final Supplier<List<PaperCard>> ChaosDraftSupplier;
|
||||
try{
|
||||
try {
|
||||
ChaosDraftSupplier = new ChaosBoosterSupplier(chaosDraftEditions);
|
||||
} catch(Exception e) {
|
||||
} catch(IllegalArgumentException e) {
|
||||
System.out.println(e.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user