mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-15 05:41:51 +08:00
Processing optimization, version changed to 1.5.0
Changed some for each methods to use parallelStream.foreach instead - this should speed up the inspect and analyze queries, especially when the data set is large. Changed version to 1.5.0 - Search command will be added this version. - Possibly seperate analysis utility package incoming.
This commit is contained in:
parent
ba488c3f70
commit
c7d1b487d3
@ -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<String> hookInit() {
|
||||
this.hooks.clear();
|
||||
List<String> 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<String> 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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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<String, String> 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));
|
||||
}
|
||||
|
@ -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<String, String> removeExtraDataPoints(HashMap<String, String> data) throws NumberFormatException {
|
||||
List<String> 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<String[]> turnDataHashMapToSortedListOfArrays(HashMap<String, String> data) {
|
||||
List<String[]> 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<String[]>() {
|
||||
public int compare(String[] strings, String[] otherStrings) {
|
||||
return strings[0].compareTo(otherStrings[0]);
|
||||
|
@ -21,7 +21,7 @@ public class DataUtils {
|
||||
public static HashMap<String, String> getData(boolean allData, String playerName) {
|
||||
HashMap<String, String> 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<UUID, HashMap<String, String>> getTotalData() {
|
||||
HashMap<UUID, HashMap<String, String>> playerData = new HashMap<>();
|
||||
for (OfflinePlayer player : Bukkit.getOfflinePlayers()) {
|
||||
if (playerData.get(player.getUniqueId()) == null) {
|
||||
playerData.put(player.getUniqueId(), getData(true, player.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
List<OfflinePlayer> 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",
|
||||
|
@ -1,6 +1,6 @@
|
||||
name: Plan
|
||||
main: com.djrapitops.plan.Plan
|
||||
version: 1.4.3
|
||||
version: 1.5.0
|
||||
|
||||
commands:
|
||||
plan:
|
||||
|
Loading…
Reference in New Issue
Block a user