From 3742cd65dc8d34107eab908dd8c3440bf3c2b372 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Tue, 21 Nov 2017 11:01:50 +0200 Subject: [PATCH] Fixed possible backwards compatibility issues with html files in wrong location (/plugins/Plan/ instead of /plugins/Plan/web/charts/ for example) --- .../djrapitops/plan/data/PlayerProfile.java | 6 ++- .../plan/utilities/FormatUtils.java | 6 +-- .../plan/utilities/file/FileUtil.java | 38 +++++++++++++++++-- 3 files changed, 42 insertions(+), 8 deletions(-) diff --git a/Plan/src/main/java/com/djrapitops/plan/data/PlayerProfile.java b/Plan/src/main/java/com/djrapitops/plan/data/PlayerProfile.java index 3cd465198..4320f271f 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/PlayerProfile.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/PlayerProfile.java @@ -74,6 +74,7 @@ public class PlayerProfile implements OfflinePlayer { // Calculating Getters + @Deprecated // TODO Remove after 4.1.0, made for old html users public boolean isActive(long date) { return getActivityIndex(date) > 1.0; } @@ -119,9 +120,10 @@ public class PlayerProfile implements OfflinePlayer { double extraMultiplier = 1.0; double loginTotal = weekLogin + week2Login + week3Login; - double loginAvg = loginTotal / 3.0; - if (loginTotal < 2.0) { + + if (loginTotal <= 2.0) { + // Reduce index for players that have not logged in the threshold amount for 2 weeks extraMultiplier = 0.75; } diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/FormatUtils.java b/Plan/src/main/java/com/djrapitops/plan/utilities/FormatUtils.java index 5037deb03..b090311f7 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/FormatUtils.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/FormatUtils.java @@ -213,12 +213,12 @@ public class FormatUtils { } public static String[] readableActivityIndex(double activityIndex) { - if (activityIndex >= 5.0) { + if (activityIndex >= 3.5) { return new String[]{"green", "Very Active"}; - } else if (activityIndex >= 2.0) { + } else if (activityIndex >= 1.75) { return new String[]{"green", "Active"}; } else if (activityIndex >= 1.0) { - return new String[]{"green", "Regular"}; + return new String[]{"lime", "Regular"}; } else if (activityIndex >= 0.5) { return new String[]{"amber", "Irregular"}; } else { diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/file/FileUtil.java b/Plan/src/main/java/com/djrapitops/plan/utilities/file/FileUtil.java index 0b872a6d4..87f4f87e8 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/file/FileUtil.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/file/FileUtil.java @@ -11,9 +11,7 @@ import java.io.InputStream; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.nio.file.Files; -import java.util.ArrayList; -import java.util.List; -import java.util.Scanner; +import java.util.*; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -35,10 +33,44 @@ public class FileUtil { public static List lines(IPlan plugin, File savedFile, String defaults) throws IOException { if (savedFile.exists()) { return lines(savedFile); + } else { + String fileName = savedFile.getName(); + File found = attemptToFind(fileName, plugin.getDataFolder()); + if (found != null) { + return lines(found); + } } return lines(plugin, defaults); } + /** + * Breadth-First search through the file tree to find the file. + * + * @param fileName Name of the searched file + * @param dataFolder Folder to look from + * @return File if found or null + */ + private static File attemptToFind(String fileName, File dataFolder) { + if (dataFolder.isDirectory()) { + ArrayDeque que = new ArrayDeque<>(); + que.add(dataFolder); + + while (!que.isEmpty()) { + File file = que.pop(); + if (file.isFile() && fileName.equals(file.getName())) { + return file; + } + if (file.isDirectory()) { + File[] files = file.listFiles(); + if (files != null) { + que.addAll(Arrays.asList(files)); + } + } + } + } + return null; + } + public static List lines(IPlan plugin, String resource) throws IOException { List lines = new ArrayList<>(); Scanner scanner = null;