diff --git a/src/com/djrapitops/plan/Plan.java b/src/com/djrapitops/plan/Plan.java index a9ff9f695..e453467bf 100644 --- a/src/com/djrapitops/plan/Plan.java +++ b/src/com/djrapitops/plan/Plan.java @@ -21,6 +21,7 @@ import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; +import java.util.Arrays; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -100,9 +101,10 @@ public class Plan extends JavaPlugin { public List hookInit() { this.hooks.clear(); List hookFail = new ArrayList<>(); - String[] plugins = {"OnTime", "Essentials", "Towny", "Vault", "Factions", "SuperbVote", "AdvancedAchievements"}; - for (String pluginName : plugins) { - + String[] pluginsArray = {"OnTime", "Essentials", "Towny", "Vault", "Factions", "SuperbVote", "AdvancedAchievements"}; + List plugins = new ArrayList<>(); + plugins.addAll(Arrays.asList(pluginsArray)); + plugins.parallelStream().forEach((pluginName) -> { if (getConfig().getBoolean("visible." + pluginName.toLowerCase())) { try { String className = "com.djrapitops.plan.command.hooks." + pluginName + "Hook"; @@ -118,7 +120,7 @@ public class Plan extends JavaPlugin { } else { hookFail.add(ChatColor.YELLOW + pluginName); } - } + }); for (String extraHook : this.extraHooks.keySet()) { this.hooks.put(extraHook, this.extraHooks.get(extraHook)); } @@ -176,7 +178,7 @@ public class Plan extends JavaPlugin { public API getAPI() { return api; } - + public void addExtraHook(String name, Hook hook) { this.extraHooks.put(name, hook); this.hooks.put(name, hook); diff --git a/src/com/djrapitops/plan/command/hooks/AdvancedAchievementsHook.java b/src/com/djrapitops/plan/command/hooks/AdvancedAchievementsHook.java index eb038ef4b..947b3dc54 100644 --- a/src/com/djrapitops/plan/command/hooks/AdvancedAchievementsHook.java +++ b/src/com/djrapitops/plan/command/hooks/AdvancedAchievementsHook.java @@ -82,10 +82,13 @@ public class AdvancedAchievementsHook implements Hook { data.put("AAC-ACHIEVEMENTS", aAPlugin.getDb().getPlayerAchievementsAmount(uuid.toString()) + " / " + totalAchievements); } else { // Fallback method for older versions, only returns Online player data - Player p = getPlayer(player); + Player p; if (uuid != null) { p = getPlayer(uuid); + } else { + p = getPlayer(player); } + if (p != null) { data.put("AAC-ACHIEVEMENTS", aAPlugin.getDb().getPlayerAchievementsAmount(p) + " / " + totalAchievements); } diff --git a/src/com/djrapitops/plan/command/hooks/PlaceholderAPIHook.java b/src/com/djrapitops/plan/command/hooks/PlaceholderAPIHook.java index 21598bf44..211195938 100644 --- a/src/com/djrapitops/plan/command/hooks/PlaceholderAPIHook.java +++ b/src/com/djrapitops/plan/command/hooks/PlaceholderAPIHook.java @@ -2,7 +2,6 @@ package com.djrapitops.plan.command.hooks; import com.djrapitops.plan.Plan; import com.djrapitops.plan.UUIDFetcher; -import com.djrapitops.plan.command.commands.InspectCommand; import com.djrapitops.plan.command.utils.DataFormatUtils; import com.djrapitops.plan.command.utils.DataUtils; import java.util.ArrayList; @@ -43,7 +42,7 @@ public class PlaceholderAPIHook extends EZPlaceholderHook implements Hook { HashMap data = new HashMap<>(); Player player = Bukkit.getPlayer(UUIDFetcher.getUUIDOf(playerName)); for (String placeholder : placeholders) { - if (placeholder.length() > 0) { + if (placeholder.length() > 0 && placeholder.contains("%") || placeholder.contains("{")) { String key = ("" + placeholder.subSequence(1, placeholder.length() - 1)).toUpperCase(); data.put("PHA-" + key.toUpperCase(), PlaceholderAPI.setPlaceholders(player, placeholder)); } diff --git a/src/com/djrapitops/plan/command/utils/DataFormatUtils.java b/src/com/djrapitops/plan/command/utils/DataFormatUtils.java index 9326aa823..dc79a6c76 100644 --- a/src/com/djrapitops/plan/command/utils/DataFormatUtils.java +++ b/src/com/djrapitops/plan/command/utils/DataFormatUtils.java @@ -3,7 +3,6 @@ package com.djrapitops.plan.command.utils; import com.djrapitops.plan.Plan; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.Date; @@ -16,7 +15,7 @@ public class DataFormatUtils { public static HashMap removeExtraDataPoints(HashMap data) throws NumberFormatException { List remove = new ArrayList<>(); Plan plugin = getPlugin(Plan.class); - for (String key : data.keySet()) { + data.keySet().parallelStream().forEach((key) -> { try { // Process OnTime empty data (returns -1 if empty) if (key.subSequence(0, 3).equals("ONT")) { @@ -33,7 +32,7 @@ public class DataFormatUtils { } catch (Exception e) { plugin.logToFile("FORMAT-Remove\n" + e + "\n" + key); } - } + }); // Remove faulty data to prevent TOW-LAST LOGIN from being removed with empty data for (String removedKey : remove) { data.remove(removedKey); @@ -189,9 +188,9 @@ public class DataFormatUtils { // Sorts HashMap into Sorted List of Arrays public static List turnDataHashMapToSortedListOfArrays(HashMap data) { List dataList = new ArrayList<>(); - for (String key : data.keySet()) { + data.keySet().parallelStream().forEach((key) -> { dataList.add(new String[]{key, data.get(key)}); - } + }); Collections.sort(dataList, new Comparator() { public int compare(String[] strings, String[] otherStrings) { return strings[0].compareTo(otherStrings[0]); diff --git a/src/com/djrapitops/plan/command/utils/DataUtils.java b/src/com/djrapitops/plan/command/utils/DataUtils.java index b39efbc69..c70519f95 100644 --- a/src/com/djrapitops/plan/command/utils/DataUtils.java +++ b/src/com/djrapitops/plan/command/utils/DataUtils.java @@ -21,7 +21,7 @@ public class DataUtils { public static HashMap getData(boolean allData, String playerName) { HashMap data = new HashMap<>(); Plan plugin = getPlugin(Plan.class); - for (String hook : plugin.getHooks().keySet()) { + plugin.getHooks().keySet().parallelStream().forEach((hook) -> { try { if (allData) { data.putAll(plugin.getHooks().get(hook).getAllData(playerName)); @@ -38,18 +38,21 @@ public class DataUtils { } plugin.logToFile(toLog); } - } + }); return data; } // Returns data HashMaps for all pplayers in a HashMap. public static HashMap> getTotalData() { HashMap> playerData = new HashMap<>(); - for (OfflinePlayer player : Bukkit.getOfflinePlayers()) { - if (playerData.get(player.getUniqueId()) == null) { - playerData.put(player.getUniqueId(), getData(true, player.getName())); - } - } + + List players = new ArrayList<>(); + players.addAll(Arrays.asList(Bukkit.getOfflinePlayers())); + players.parallelStream() + .filter((player) -> (playerData.get(player.getUniqueId()) == null)) + .forEach((player) -> { + playerData.put(player.getUniqueId(), getData(true, player.getName())); + }); return playerData; } @@ -93,17 +96,19 @@ public class DataUtils { ignoreKeys.addAll(Arrays.asList(ignore)); // Turn playerData into Hashmap of Lists sorted by keys. - for (UUID key : playerData.keySet()) { - for (String dataKey : playerData.get(key).keySet()) { - if (ignoreKeys.contains(dataKey)) { - continue; - } - if (playerDataLists.get(dataKey) == null) { - playerDataLists.put(dataKey, new ArrayList<>()); - } - playerDataLists.get(dataKey).add(playerData.get(key).get(dataKey)); - } - } + playerData.keySet().parallelStream().forEach((key) -> { + playerData.get(key).keySet().parallelStream() + .filter((dataKey) -> !(ignoreKeys.contains(dataKey))) + .map((dataKey) -> { + if (playerDataLists.get(dataKey) == null) { + playerDataLists.put(dataKey, new ArrayList<>()); + } + return dataKey; + }) + .forEach((dataKey) -> { + playerDataLists.get(dataKey).add(playerData.get(key).get(dataKey)); + }); + }); // Define analysis method for keys String[] numbers = {"AAC-ACHIEVEMENTS", "ESS-HEALTH", "ESS-XP LEVEL", "FAC-POWER", "FAC-POWER PER HOUR", diff --git a/src/plugin.yml b/src/plugin.yml index 9c3d4688a..596119c77 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,6 +1,6 @@ name: Plan main: com.djrapitops.plan.Plan -version: 1.4.3 +version: 1.5.0 commands: plan: