Catch classification errors early
This commit is contained in:
parent
cfcb38360b
commit
bb25a90c45
|
@ -1,6 +1,7 @@
|
|||
package net.anxuiz.tourney;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.logging.Logger;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.inject.Inject;
|
||||
|
||||
|
@ -17,15 +18,24 @@ public class ClassificationManager {
|
|||
|
||||
private final Set<MapClassification> classifications;
|
||||
|
||||
@Inject ClassificationManager(Tournament tournament, MapLibrary mapLibrary) {
|
||||
this.classifications = tournament.map_classifications()
|
||||
.stream()
|
||||
.map(cl -> new MapClassification(cl.name(),
|
||||
cl.map_ids()
|
||||
.stream()
|
||||
.map(mapLibrary::getMapById)
|
||||
.collect(Collectors.toImmutableSet())))
|
||||
.collect(Collectors.toImmutableSet());
|
||||
@Inject ClassificationManager(Tournament tournament, MapLibrary mapLibrary, Logger logger) {
|
||||
this.classifications =
|
||||
tournament.map_classifications().stream()
|
||||
.map(
|
||||
cl ->
|
||||
new MapClassification(
|
||||
cl.name(),
|
||||
cl.map_ids().stream()
|
||||
.map(
|
||||
id -> {
|
||||
PGMMap map = mapLibrary.getMapById(id);
|
||||
if (map == null) {
|
||||
logger.severe("Unable to find map matching ID: " + id);
|
||||
return null;
|
||||
} else return map;
|
||||
})
|
||||
.collect(Collectors.toImmutableSet())))
|
||||
.collect(Collectors.toImmutableSet());
|
||||
}
|
||||
|
||||
public @Nullable MapClassification firstClassificationForMap(PGMMap map) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package net.anxuiz.tourney;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Provider;
|
||||
|
@ -18,8 +19,10 @@ import tc.oc.commons.bukkit.chat.ListComponent;
|
|||
import tc.oc.commons.bukkit.inject.BukkitPluginManifest;
|
||||
import tc.oc.commons.core.chat.Component;
|
||||
import tc.oc.commons.core.concurrent.Flexecutor;
|
||||
import tc.oc.commons.core.formatting.StringUtils;
|
||||
import tc.oc.inject.ProtectedBinder;
|
||||
import tc.oc.minecraft.scheduler.Sync;
|
||||
import tc.oc.pgm.map.PGMMap;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
|
@ -37,6 +40,7 @@ public class Tourney extends JavaPlugin {
|
|||
@Inject private Provider<Tournament> tournamentProvider;
|
||||
@Inject private Provider<MatchManager> matchManagerProvider;
|
||||
@Inject private Provider<KDMSession> kdmSessionProvider;
|
||||
@Inject private Provider<ClassificationManager> classificationManagerProvider;
|
||||
|
||||
public static Tourney get() {
|
||||
return checkNotNull(inst);
|
||||
|
@ -146,5 +150,17 @@ public class Tourney extends JavaPlugin {
|
|||
ChatColor.RED + "Please re-connect without BetterSprint enabled."
|
||||
));
|
||||
}
|
||||
|
||||
ClassificationManager classificationManager = classificationManagerProvider.get();
|
||||
if (!classificationManager.getClassifications().isEmpty()) {
|
||||
getLogger().info("Map Classifications: ");
|
||||
classificationManager
|
||||
.getClassifications()
|
||||
.forEach(
|
||||
classification -> getLogger().info(classification.name() + " - " +
|
||||
StringUtils.listToEnglishCompound(classification.maps().stream()
|
||||
.map(map -> map.getId().toString())
|
||||
.collect(Collectors.toList()))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue