diff --git a/src/main/java/com/botdetector/BotDetectorPlugin.java b/src/main/java/com/botdetector/BotDetectorPlugin.java index 2042dfbb..ee0519a4 100644 --- a/src/main/java/com/botdetector/BotDetectorPlugin.java +++ b/src/main/java/com/botdetector/BotDetectorPlugin.java @@ -680,7 +680,7 @@ private void processPlayer(Player player) String rawName = player.getName(); - boolean invalidName = rawName == null || rawName.length() == 0 || rawName.charAt(0) == '#' || rawName.charAt(0) == '['; + boolean invalidName = rawName == null || rawName.isEmpty() || rawName.charAt(0) == '#' || rawName.charAt(0) == '['; if (player == client.getLocalPlayer()) { diff --git a/src/main/java/com/botdetector/http/BotDetectorClient.java b/src/main/java/com/botdetector/http/BotDetectorClient.java index ed00e175..d84bb2e2 100644 --- a/src/main/java/com/botdetector/http/BotDetectorClient.java +++ b/src/main/java/com/botdetector/http/BotDetectorClient.java @@ -398,7 +398,19 @@ public void onResponse(Call call, Response response) { try { - future.complete(processResponse(gson, response, Prediction.class)); + Prediction p = processResponse(gson, response, Prediction.class); + // Sanity check for if the primary label does not appear in the breakdown + if (p != null + && p.getConfidence() != null // Some 'debug' labels such as 'Stats_Too_Low' will have null confidence, ignore these! + && p.getPredictionBreakdown() != null + && !p.getPredictionBreakdown().isEmpty() + && p.getPredictionBreakdown().keySet().stream().noneMatch(x -> x.equalsIgnoreCase(p.getPredictionLabel()))) + { + p.getPredictionBreakdown().put(p.getPredictionLabel(), p.getConfidence()); + log.warn(String.format("Primary prediction label missing from breakdown! Added missing label. (pl:'%s', id:'%d', lb:'%s', cf:'%.4f')", + p.getPlayerName(), p.getPlayerId(), p.getPredictionLabel(), p.getConfidence())); + } + future.complete(p); } catch (IOException e) { diff --git a/src/main/java/com/botdetector/ui/BotDetectorPanel.java b/src/main/java/com/botdetector/ui/BotDetectorPanel.java index e7cb4278..d12c3a8c 100644 --- a/src/main/java/com/botdetector/ui/BotDetectorPanel.java +++ b/src/main/java/com/botdetector/ui/BotDetectorPanel.java @@ -1107,7 +1107,7 @@ public void setPrediction(Prediction pred, PlayerSighting sighting) feedbackLabelComboBox.setSelectedItem(UNSURE_PREDICTION_LABEL); feedbackLabelComboBox.addItem(SOMETHING_ELSE_PREDICTION_LABEL); - if (pred.getPredictionBreakdown() == null || pred.getPredictionBreakdown().size() == 0) + if (pred.getPredictionBreakdown() == null || pred.getPredictionBreakdown().isEmpty()) { predictionBreakdownLabel.setText(EMPTY_LABEL); predictionBreakdownPanel.setVisible(false); @@ -1133,7 +1133,7 @@ public void setPrediction(Prediction pred, PlayerSighting sighting) entry -> { FeedbackPredictionLabel pLabel = new FeedbackPredictionLabel(entry.getKey(), entry.getValue(), - entry.getKey().equals(primaryLabel) ? FeedbackValue.POSITIVE : FeedbackValue.NEGATIVE); + entry.getKey().equalsIgnoreCase(primaryLabel) ? FeedbackValue.POSITIVE : FeedbackValue.NEGATIVE); feedbackLabelComboBox.addItem(pLabel); if (pLabel.getFeedbackValue() == FeedbackValue.POSITIVE) { @@ -1253,7 +1253,7 @@ private void predictPlayer() { String target = sanitize(searchBar.getText()); - if (target.length() <= 0) + if (target.isEmpty()) { return; } @@ -1654,7 +1654,7 @@ private static String toColoredPercentSpan(double percent) */ private static String toPredictionBreakdownString(Map predictionMap) { - if (predictionMap == null || predictionMap.size() == 0) + if (predictionMap == null || predictionMap.isEmpty()) { return null; }