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