Added Recent Players, Top 20 active list, Fixes

- Fixed manage command not giving explanation for errors when database
connection is not establishable
- Fixed hotswap causing plugin reload to fail if database connection is
not establsihable.
- Added Phrase.GRABBING_DATA_MESSAGE to Analysis, Inspect & search
- Moved some methods from MiscUtils to DataCombineUtils
This commit is contained in:
Rsl1122 2017-01-30 18:35:32 +02:00
parent 369b20aa9b
commit c5d85d9ba5
19 changed files with 379 additions and 204 deletions

View File

@ -8,13 +8,14 @@ import static org.bukkit.plugin.java.JavaPlugin.getPlugin;
* @author Rsl1122
*/
public enum Phrase {
PREFIX("[Plan] "),
CONFIG_HEADER("Plan Config | More info at https://www.spigotmc.org/wiki/plan-configuration/"),
DATABASE_TYPE_DOES_NOT_EXIST("That database type doesn't exist."),
DATABASE_FAILURE_DISABLE("Database initialization has failed, disabling Plan."),
PLANLITE_REG_HOOK("Registered additional hook, passed on to PlanLite: "),
USERNAME_NOT_VALID(ChatColor.RED + "[Plan] This Player doesn't exist."),
USERNAME_NOT_SEEN(ChatColor.RED + "[Plan] This Player has not played on this server."),
USERNAME_NOT_KNOWN(ChatColor.RED + "[Plan] Player not found from the database."),
USERNAME_NOT_VALID(ChatColor.RED + "" + PREFIX + "This Player doesn't exist."),
USERNAME_NOT_SEEN(ChatColor.RED + "" + PREFIX + "This Player has not played on this server."),
USERNAME_NOT_KNOWN(ChatColor.RED + "" + PREFIX + "Player not found from the database."),
COLOR_MAIN(ChatColor.getByChar(getPlugin(Plan.class).getConfig().getString("Customization.Colors.Commands.Main").charAt(1))),
COLOR_SEC(ChatColor.getByChar(getPlugin(Plan.class).getConfig().getString("Customization.Colors.Commands.Secondary").charAt(1))),
COLOR_TER(ChatColor.getByChar(getPlugin(Plan.class).getConfig().getString("Customization.Colors.Commands.Highlight").charAt(1))),
@ -30,24 +31,38 @@ public enum Phrase {
HCOLOR_ACTP_JON(getPlugin(Plan.class).getConfig().getString("Customization.Colors.HTML.ActivityPie.JoinedOnce")),
ARROWS_RIGHT("»"),
BALL(""),
GRABBING_DATA_MESSAGE(COLOR_TER+""+ARROWS_RIGHT+COLOR_MAIN+" Fetching data to cache.."),
ANALYSIS("Analysis | "),
ANALYSIS_START(ANALYSIS + "Beginning analysis of user data.."),
ANALYSIS_FETCH_PLAYERS(ANALYSIS + "Checking for available players.."),
ANALYSIS_FETCH_DATA(ANALYSIS + "Fetching Data.."),
ANALYSIS_FAIL_NO_PLAYERS(ANALYSIS + "Analysis failed, no known players."),
ANALYSIS_FAIL_NO_DATA(ANALYSIS + "Analysis failed, no data in the database."),
ANALYSIS_BEGIN_ANALYSIS(ANALYSIS + "Data Fetched, beginning Analysis of data.."),
ANALYSIS_COMPLETE(ANALYSIS + "Analysis Complete."),
ERROR_PLANLITE("PlanLite not found, if you're have plugins using PlanAPI v1.6.0 download PlanLite."),
ERROR_NO_DATA_VIEW(ChatColor.YELLOW + "Webserver disabled but Alternative IP/PlanLite not used, no way to view data!"),
ERROR_WEBSERVER_OFF_ANALYSIS(ChatColor.YELLOW + "[Plan] This command can be only used if the webserver is running on this server."),
ERROR_WEBSERVER_OFF_INSPECT(ChatColor.YELLOW + "[Plan] This command can be only used if webserver/planlite is enabled on this server."),
MANAGE_ERROR_INCORRECT_PLUGIN(ChatColor.RED+"[Plan] Plugin not supported: "),
MANAGE_ERROR_PLUGIN_NOT_ENABLED(ChatColor.RED+"[Plan] Plugin is not enabled: "),
MANAGE_ERROR_INCORRECT_DB(ChatColor.RED+"[Plan] Incorrect database! (sqlite/mysql accepted): "),
MANAGE_ERROR_SAME_DB(ChatColor.RED+"[Plan] Can't move to the same database!"),
MANAGE_DATABASE_FAILURE(ChatColor.RED+"[Plan] One of the databases was not initialized properly."),
MANAGE_DB_CONFIG_REMINDER(ChatColor.YELLOW+"[Plan] Remember to swap to the new database and reload plugin"),
MANAGE_ERROR_NO_PLAYERS(ChatColor.RED+"[Plan] Database has no player data!"),
MANAGE_MOVE_SUCCESS(ChatColor.GREEN+"[Plan] All data moved successfully!"),
MANAGE_CLEAR_SUCCESS(ChatColor.GREEN+"[Plan] All data cleared successfully!"),
COMMAND_SENDER_NOT_PLAYER(ChatColor.RED + "[Plan] This command can be only used as a player."),
COMMAND_REQUIRES_ARGUMENTS(ChatColor.RED + "[Plan] Command requires arguments."),
COMMAND_ADD_CONFIRMATION_ARGUMENT(ChatColor.RED + "[Plan] Add -a to confirm execution!"),
COMMAND_REQUIRES_ARGUMENTS_ONE(ChatColor.RED + "[Plan] Command requires one argument."),
COMMAND_NO_PERMISSION(ChatColor.RED + "[Plan] You do not have the required permmission.");
ERROR_WEBSERVER_OFF_ANALYSIS(ChatColor.YELLOW + "" + PREFIX + "This command can be only used if the webserver is running on this server."),
ERROR_WEBSERVER_OFF_INSPECT(ChatColor.YELLOW + "" + PREFIX + "This command can be only used if webserver/planlite is enabled on this server."),
MANAGE_ERROR_INCORRECT_PLUGIN(ChatColor.RED + "" + PREFIX + "Plugin not supported: "),
MANAGE_ERROR_PLUGIN_NOT_ENABLED(ChatColor.RED + "" + PREFIX + "Plugin is not enabled: "),
MANAGE_ERROR_INCORRECT_DB(ChatColor.RED + "" + PREFIX + "Incorrect database! (sqlite/mysql accepted): "),
MANAGE_ERROR_SAME_DB(ChatColor.RED + "" + PREFIX + "Can't move to the same database!"),
MANAGE_DATABASE_FAILURE(ChatColor.RED + "" + PREFIX + "One of the databases was not initialized properly."),
MANAGE_DB_CONFIG_REMINDER(ChatColor.YELLOW + "" + PREFIX + "Remember to swap to the new database and reload plugin"),
MANAGE_ERROR_NO_PLAYERS(ChatColor.RED + "" + PREFIX + "Database has no player data!"),
MANAGE_MOVE_SUCCESS(ChatColor.GREEN + "" + PREFIX + "All data moved successfully!"),
MANAGE_CLEAR_SUCCESS(ChatColor.GREEN + "" + PREFIX + "All data cleared successfully!"),
COMMAND_SENDER_NOT_PLAYER(ChatColor.RED + "" + PREFIX + "This command can be only used as a player."),
COMMAND_REQUIRES_ARGUMENTS(ChatColor.RED + "" + PREFIX + "Command requires arguments."),
COMMAND_ADD_CONFIRMATION_ARGUMENT(ChatColor.RED + "" + PREFIX + "Add -a to confirm execution!"),
COMMAND_REQUIRES_ARGUMENTS_ONE(ChatColor.RED + "" + PREFIX + "Command requires one argument."),
COMMAND_NO_PERMISSION(ChatColor.RED + "" + PREFIX + "You do not have the required permmission.");
private final String text;
private final ChatColor color;

View File

@ -70,7 +70,7 @@ public class Plan extends JavaPlugin {
log(MiscUtils.checkVersion());
log("Database init..");
if (initDatabase()) {
log(db.getConfigName()+" Database initiated.");
log(db.getConfigName()+"-database connection established.");
} else {
logError(Phrase.DATABASE_FAILURE_DISABLE.toString());
getServer().getPluginManager().disablePlugin(this);

View File

@ -59,6 +59,7 @@ public class AnalyzeCommand extends SubCommand {
return true;
}
}
sender.sendMessage(Phrase.GRABBING_DATA_MESSAGE+"");
if (!analysisCache.isCached()) {
analysisCache.updateCache();
} else if (new Date().getTime() - analysisCache.getData().getRefreshDate() > 60000) {

View File

@ -20,7 +20,6 @@ import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import static org.bukkit.Bukkit.getOfflinePlayer;
import static org.bukkit.Bukkit.getOfflinePlayer;
/**
*
@ -93,11 +92,12 @@ public class InspectCommand extends SubCommand {
return true;
}
inspectCache.cache(uuid);
ChatColor oColor = Phrase.COLOR_MAIN.color();
ChatColor tColor = Phrase.COLOR_SEC.color();
ChatColor hColor = Phrase.COLOR_TER.color();
sender.sendMessage(Phrase.GRABBING_DATA_MESSAGE+"");
inspectCache.cache(uuid);
final boolean useAlternativeIP = config.getBoolean("Settings.WebServer.ShowAlternativeServerIP");
final int port = config.getInt("Settings.WebServer.Port");
final String alternativeIP = config.getString("Settings.WebServer.AlternativeIP").replaceAll("%port%", "" + port);

View File

@ -64,7 +64,8 @@ public class SearchCommand extends SubCommand {
ChatColor oColor = Phrase.COLOR_MAIN.color();
ChatColor tColor = Phrase.COLOR_SEC.color();
ChatColor hColor = Phrase.COLOR_TER.color();
sender.sendMessage(Phrase.GRABBING_DATA_MESSAGE+"");
Set<OfflinePlayer> matches = MiscUtils.getMatchingDisplaynames(args[0]);
Set<UUID> uuids = new HashSet<>();
for (OfflinePlayer match : matches) {

View File

@ -16,6 +16,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import main.java.com.djrapitops.plan.utilities.DataCombineUtils;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
@ -110,7 +111,7 @@ public class ManageCombineCommand extends SubCommand {
}
final List<UUID> fromUUIDS = new ArrayList<>();
final List<UUID> toUUIDS = new ArrayList<>();
for (OfflinePlayer p : offlinePlayers) {
try {for (OfflinePlayer p : offlinePlayers) {
UUID uuid = p.getUniqueId();
if (fromDatabase.wasSeenBefore(uuid)) {
fromUUIDS.add(uuid);
@ -141,13 +142,13 @@ public class ManageCombineCommand extends SubCommand {
uuids.addAll(toUUIDS);
uuids.addAll(fromUUIDS);
List<UserData> combinedUserData = MiscUtils.combineUserDatas(allFromUserData, allToUserData, uuids);
List<UserData> combinedUserData = DataCombineUtils.combineUserDatas(allFromUserData, allToUserData, uuids);
HashMap<Long, ServerData> fromServerData = moveFromDB.getServerDataHashMap();
HashMap<Long, ServerData> toServerData = moveToDB.getServerDataHashMap();
HashMap<Long, ServerData> combinedServerData = MiscUtils.combineServerDatas(fromServerData, toServerData);
HashMap<Long, ServerData> combinedServerData = DataCombineUtils.combineServerDatas(fromServerData, toServerData);
HashMap<String, Integer> commandUse = MiscUtils.combineCommandUses(getCommandUse(fromServerData), getCommandUse(toServerData));
HashMap<String, Integer> commandUse = DataCombineUtils.combineCommandUses(getCommandUse(fromServerData), getCommandUse(toServerData));
moveToDB.removeAllData();
@ -175,6 +176,9 @@ public class ManageCombineCommand extends SubCommand {
return fromCommandUse;
}
}).runTaskAsynchronously(plugin);
} catch (NullPointerException e) {
sender.sendMessage(Phrase.MANAGE_DATABASE_FAILURE+"");
}
return true;
}
}

View File

@ -4,25 +4,9 @@ import com.djrapitops.plan.Phrase;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.command.CommandType;
import com.djrapitops.plan.command.SubCommand;
import com.djrapitops.plan.data.ServerData;
import com.djrapitops.plan.data.UserData;
import com.djrapitops.plan.database.Database;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.scheduler.BukkitRunnable;
/**
*
@ -67,6 +51,19 @@ public class ManageHotswapCommand extends SubCommand {
sender.sendMessage(Phrase.MANAGE_ERROR_INCORRECT_DB + dbToSwapTo);
return true;
}
try {
Database db = null;
for (Database database : plugin.getDatabases()) {
if (dbToSwapTo.equalsIgnoreCase(database.getConfigName())) {
db = database;
db.init();
db.getNewestServerData();
}
}
} catch (NullPointerException e) {
sender.sendMessage(Phrase.MANAGE_DATABASE_FAILURE + "");
return true;
}
plugin.getConfig().set("database.type", dbToSwapTo);
plugin.saveConfig();
plugin.onDisable();

View File

@ -8,7 +8,6 @@ import com.djrapitops.plan.command.SubCommand;
import com.djrapitops.plan.data.UserData;
import com.djrapitops.plan.data.cache.DataCacheHandler;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@ -24,6 +23,7 @@ import org.bukkit.GameMode;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import static org.bukkit.Bukkit.getOfflinePlayer;
/**
*

View File

@ -123,25 +123,29 @@ public class ManageMoveCommand extends SubCommand {
(new BukkitRunnable() {
@Override
public void run() {
moveToDB.removeAllData();
List<UserData> allUserData = new ArrayList<>();
for (UUID uuid : uuids) {
allUserData.add(moveFromDB.getUserData(uuid));
}
moveToDB.saveMultipleUserData(allUserData);
HashMap<Long, ServerData> serverData = moveFromDB.getServerDataHashMap();
moveToDB.saveServerDataHashMap(serverData);
ServerData sData = null;
for (long sDataKey : serverData.keySet()) {
sData = serverData.get(sDataKey);
break;
}
if (sData != null) {
moveToDB.saveCommandUse(sData.getCommandUsage());
}
sender.sendMessage(Phrase.MANAGE_MOVE_SUCCESS+"");
if (!toDB.equals(plugin.getDB().getConfigName())) {
sender.sendMessage(Phrase.MANAGE_DB_CONFIG_REMINDER+"");
try {
moveToDB.removeAllData();
List<UserData> allUserData = new ArrayList<>();
for (UUID uuid : uuids) {
allUserData.add(moveFromDB.getUserData(uuid));
}
moveToDB.saveMultipleUserData(allUserData);
HashMap<Long, ServerData> serverData = moveFromDB.getServerDataHashMap();
moveToDB.saveServerDataHashMap(serverData);
ServerData sData = null;
for (long sDataKey : serverData.keySet()) {
sData = serverData.get(sDataKey);
break;
}
if (sData != null) {
moveToDB.saveCommandUse(sData.getCommandUsage());
}
sender.sendMessage(Phrase.MANAGE_MOVE_SUCCESS + "");
if (!toDB.equals(plugin.getDB().getConfigName())) {
sender.sendMessage(Phrase.MANAGE_DB_CONFIG_REMINDER + "");
}
} catch (NullPointerException e) {
sender.sendMessage(Phrase.MANAGE_DATABASE_FAILURE + "");
}
this.cancel();
}

View File

@ -16,6 +16,7 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.scheduler.BukkitRunnable;
import static org.bukkit.Bukkit.getOfflinePlayer;
import static org.bukkit.Bukkit.getOfflinePlayer;
/**
*

View File

@ -19,6 +19,8 @@ public class AnalysisData {
private String playersChartImgHtmlDay;
private String activityChartImgHtml;
private String top50CommandsListHtml;
private String top20ActivePlayers;
private String recentPlayers;
private double gm0Perc;
private double gm1Perc;
@ -395,4 +397,22 @@ public class AnalysisData {
this.ops = ops;
}
public String getTop20ActivePlayers() {
return top20ActivePlayers;
}
public void setTop20ActivePlayers(String top20ActivePlayers) {
this.top20ActivePlayers = top20ActivePlayers;
}
public String getRecentPlayers() {
return recentPlayers;
}
public void setRecentPlayers(String recentPlayers) {
this.recentPlayers = recentPlayers;
}
}

View File

@ -2,6 +2,7 @@ package com.djrapitops.plan.data.cache;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.data.UserData;
import java.util.Date;
import java.util.HashMap;
import java.util.UUID;
import org.bukkit.scheduler.BukkitRunnable;
@ -15,6 +16,7 @@ public class InspectCacheHandler {
private DataCacheHandler handler;
private Plan plugin;
private HashMap<UUID, UserData> cache;
private HashMap<UUID, Long> clearTimes;
/**
* Class constructor
@ -25,6 +27,7 @@ public class InspectCacheHandler {
this.handler = plugin.getHandler();
this.plugin = plugin;
this.cache = new HashMap<>();
this.clearTimes = new HashMap<>();
}
/**
@ -34,20 +37,36 @@ public class InspectCacheHandler {
* @param uuid UUID of the player
*/
public void cache(UUID uuid) {
if (!handler.getDB().wasSeenBefore(uuid)) {
return;
}
cache.put(uuid, handler.getCurrentData(uuid, false));
int minutes = plugin.getConfig().getInt("Settings.Cache.InspectCache.ClearFromInspectCacheAfterXMinutes");
if (minutes <= 0) {
minutes = 3;
}
(new BukkitRunnable() {
@Override
public void run() {
clearFomCache(uuid);
}
}).runTaskLater(plugin, 60 * 20 * minutes);
cache(uuid, minutes);
}
public void cache(UUID uuid, int minutes) {
if (!handler.getDB().wasSeenBefore(uuid)) {
return;
}
cache.put(uuid, handler.getCurrentData(uuid, false));
long clearTime = new Date().toInstant().getEpochSecond() + (long) 60 * (long) minutes;
if (clearTimes.get(uuid) == null) {
clearTimes.put(uuid, (long) 0);
}
if (clearTimes.get(uuid) < clearTime) {
clearTimes.put(uuid, clearTime);
(new BukkitRunnable() {
@Override
public void run() {
if (new Date().toInstant().getEpochSecond() - clearTimes.get(uuid) < 30) {
clearFomCache(uuid);
} else {
this.cancel();
}
this.cancel();
}
}).runTaskLater(plugin, 60 * 20 * minutes);
}
}
private void clearFomCache(UUID uuid) {

View File

@ -1,5 +1,6 @@
package com.djrapitops.plan.utilities;
import com.djrapitops.plan.Phrase;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.PlanLiteHook;
import com.djrapitops.plan.data.AnalysisData;
@ -14,9 +15,9 @@ import java.util.List;
import java.util.UUID;
import main.java.com.djrapitops.plan.data.PlanLiteAnalyzedData;
import main.java.com.djrapitops.plan.data.PlanLitePlayerData;
import main.java.com.djrapitops.plan.ui.graphs.HeatMapCreator;
import org.bukkit.GameMode;
import org.bukkit.OfflinePlayer;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.scheduler.BukkitRunnable;
/**
@ -48,22 +49,23 @@ public class Analysis {
*
* First retrieves all Offlineplayers and checks those that are in the
* database. Then Runs a new Analysis Task Asyncronously. Saves AnalysisData
* to the provided Cache.
* to the provided Cache. Saves all UserData to InspectCache for 8 minutes.
*
* @param analysisCache Cache that the data is saved to.
*/
public void analyze(AnalysisCacheHandler analysisCache) {
rawData.clear();
added.clear();
plugin.log("Analysis | Beginning analysis of user data..");
plugin.log(Phrase.ANALYSIS_START + "");
OfflinePlayer[] offlinePlayers;
try {
offlinePlayers = plugin.getServer().getOfflinePlayers();
} catch (IndexOutOfBoundsException e) {
plugin.log("Analysis | Analysis failed, no known players.");
plugin.log(Phrase.ANALYSIS_FAIL_NO_PLAYERS + "");
return;
}
final List<UUID> uuids = new ArrayList<>();
plugin.log(Phrase.ANALYSIS_FETCH_PLAYERS + "");
for (OfflinePlayer p : offlinePlayers) {
UUID uuid = p.getUniqueId();
if (plugin.getDB().wasSeenBefore(uuid)) {
@ -71,16 +73,20 @@ public class Analysis {
}
}
if (uuids.isEmpty()) {
plugin.log("Analysis | Analysis failed, no data in the database.");
plugin.log(Phrase.ANALYSIS_FAIL_NO_DATA + "");
return;
}
FileConfiguration config = plugin.getConfig();
final boolean useAlternativeIP = config.getBoolean("Settings.WebServer.ShowAlternativeServerIP");
final int port = config.getInt("Settings.WebServer.Port");
final String alternativeIP = config.getString("Settings.WebServer.AlternativeIP").replaceAll("%port%", "" + port);
(new BukkitRunnable() {
@Override
public void run() {
uuids.stream().forEach((uuid) -> {
inspectCache.cache(uuid);
inspectCache.cache(uuid, 8);
});
plugin.log("Analysis | Fetching Data..");
plugin.log(Phrase.ANALYSIS_FETCH_DATA + "");
while (rawData.size() != uuids.size()) {
uuids.stream()
.filter((uuid) -> (!added.contains(uuid)))
@ -93,7 +99,7 @@ public class Analysis {
});
}
rawServerData = plugin.getDB().getServerDataHashMap();
plugin.log("Analysis | Data Fetched, beginning Analysis of data..");
plugin.log(Phrase.ANALYSIS_BEGIN_ANALYSIS + "");
AnalysisData data = new AnalysisData();
createPlayerActivityGraphs(data);
@ -129,6 +135,8 @@ public class Analysis {
int totalVotes = 0;
int totalMoney = 0;
HashMap<String, Long> latestLogins = new HashMap<>();
HashMap<String, Long> playtimes = new HashMap<>();
// Fill Dataset with userdata.
for (UserData uData : rawData) {
if (planLiteEnabled) {
@ -157,7 +165,13 @@ public class Analysis {
}
} catch (NoSuchFieldError e) {
}
totalPlaytime += uData.getPlayTime();
long playTime = uData.getPlayTime();
totalPlaytime += playTime;
String playerName = uData.getName();
String url = "<a href=\"http://" + (useAlternativeIP ? alternativeIP : plugin.getServer().getIp() + ":" + port)
+ "/player/" + playerName+"\">"+playerName+"</a>";
playtimes.put(url, playTime);
latestLogins.put(url, uData.getLastPlayed());
totalLoginTimes += uData.getLoginTimes();
int age = uData.getDemData().getAge();
if (age != -1) {
@ -171,13 +185,16 @@ public class Analysis {
totalBanned++;
} else if (uData.getLoginTimes() == 1) {
joinleaver++;
} else if (AnalysisUtils.isActive(uData.getLastPlayed(), uData.getPlayTime(), uData.getLoginTimes())) {
} else if (AnalysisUtils.isActive(uData.getLastPlayed(), playTime, uData.getLoginTimes())) {
active++;
} else {
inactive++;
}
}
// Save Dataset to AnalysisData
data.setTop20ActivePlayers(AnalysisUtils.createActivePlayersTable(playtimes, 20));
data.setRecentPlayers(AnalysisUtils.createListStringOutOfHashMapLong(latestLogins, 20));
if (planLiteEnabled) {
plData.setFactionMap(factionMap);
plData.setTownMap(townMap);
@ -246,7 +263,7 @@ public class Analysis {
data.setRefreshDate(new Date().getTime());
analysisCache.cache(data);
plugin.log("Analysis | Analysis Complete.");
plugin.log(Phrase.ANALYSIS_COMPLETE + "");
this.cancel();
}

View File

@ -80,7 +80,7 @@ public class AnalysisUtils {
gm3 = (long) 0;
}
gmThree = gm3;
} catch (NoSuchFieldError e) {
} catch (NoSuchFieldError e) {
gmThree = 0;
}
long total = gmZero + gmOne + gmTwo + gmThree;
@ -143,6 +143,8 @@ public class AnalysisUtils {
replaceMap.put("%ops%", "" + data.getOps());
replaceMap.put("%refresh%", FormatUtils.formatTimeAmountSinceString("" + data.getRefreshDate(), new Date()));
replaceMap.put("%totallogins%", "" + data.getTotalLoginTimes());
replaceMap.put("%top20mostactive%", data.getTop20ActivePlayers());
replaceMap.put("%recentlogins%", data.getRecentPlayers());
PlanLiteHook hook = getPlugin(Plan.class).getPlanLiteHook();
if (hook != null) {
replaceMap.put("%planlite%", hook.isEnabled() ? getPlanLiteAnalysisHtml(data.getPlanLiteData()) : "");
@ -178,17 +180,21 @@ public class AnalysisUtils {
return createTableOutOfHashMap(commandUse, 50);
}
static String createTableOutOfHashMapLong(HashMap<String, Long> players) {
return createActivePlayersTable(players, 20);
}
static String createTableOutOfHashMap(HashMap<String, Integer> map, int limit) {
List<String[]> sorted = MapComparator.sortByValue(map);
String html = "<table style=\"border-collapse: collapse;table-layout: fixed; border-style: solid; border-width: 1px; width: 100%;\">";
if (sorted.isEmpty()) {
html = "<p>Error Calcuclating Command usages</p>";
html = "<p>Error Calcuclating Table usages (sorted data was empty)</p>";
return html;
}
Collections.reverse(sorted);
int i = 1;
for (String[] values : sorted) {
if (i >= 50) {
if (i >= limit) {
break;
}
html += "<tr style=\"text-align: center;border-style: solid; border-width: 1px;height: 28px;\"><td><b>" + values[1] + "</b></td>\r\n<td>" + values[0] + "</td></tr>";
@ -198,6 +204,46 @@ public class AnalysisUtils {
return html;
}
static String createActivePlayersTable(HashMap<String, Long> map, int limit) {
List<String[]> sorted = MapComparator.sortByValueLong(map);
String html = "<table style=\"border-collapse: collapse;table-layout: fixed; border-style: solid; border-width: 1px; width: 100%;\">";
if (sorted.isEmpty()) {
html = "<p>Error Calculating Active players (sorted list was empty)</p>";
return html;
}
Collections.reverse(sorted);
int i = 1;
for (String[] values : sorted) {
if (i >= limit) {
break;
}
html += "<tr style=\"text-align: center;border-style: solid; border-width: 1px;height: 28px;\"><td><b>" + values[1] + "</b></td>\r\n<td>" + FormatUtils.formatTimeAmount(values[0]) + "</td></tr>";
i++;
}
html += "</table>";
return html;
}
static String createListStringOutOfHashMapLong(HashMap<String, Long> map, int limit) {
List<String[]> sorted = MapComparator.sortByValueLong(map);
String html = "<p>";
if (sorted.isEmpty()) {
html = "Error Creating List</p>";
return html;
}
Collections.reverse(sorted);
int i = 1;
for (String[] values : sorted) {
if (i >= limit) {
break;
}
html += values[1]+" ";
i++;
}
html += "</p>";
return html;
}
private static String getPlanLiteAnalysisHtml(PlanLiteAnalyzedData planLiteData) {
Scanner scanner = new Scanner(getPlugin(Plan.class).getResource("planlite.html"));
String html = "";

View File

@ -0,0 +1,144 @@
package main.java.com.djrapitops.plan.utilities;
import com.djrapitops.plan.data.DemographicsData;
import com.djrapitops.plan.data.ServerData;
import com.djrapitops.plan.data.UserData;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import org.bukkit.GameMode;
/**
*
* @author Rsl1122
*/
public class DataCombineUtils {
/**
* Combines two conflicting UserDatasets from databases.
*
* @param allFromUserData First Dataset
* @param allToUserData Second Dataset
* @param uuids UUIDs from both Datasets
* @return Combined UserDataset
*/
public static List<UserData> combineUserDatas(HashMap<UUID, UserData> allFromUserData, HashMap<UUID, UserData> allToUserData, Set<UUID> uuids) {
List<UserData> combinedData = new ArrayList<>();
uuids.forEach((UUID uuid) -> {
UserData fData = allFromUserData.get(uuid);
UserData tData = allToUserData.get(uuid);
if (fData == null) {
combinedData.add(tData);
} else if (tData == null) {
combinedData.add(fData);
} else {
combinedData.add(combineUserData(fData, tData));
}
});
return combinedData;
}
private static UserData combineUserData(UserData fData, UserData tData) {
if (fData.getLastGmSwapTime() < tData.getLastGmSwapTime()) {
fData.setLastGmSwapTime(tData.getLastGmSwapTime());
fData.setLastGamemode(tData.getLastGamemode());
}
HashMap<GameMode, Long> gmTimes = fData.getGmTimes();
HashMap<GameMode, Long> tGmTimes = tData.getGmTimes();
gmTimes.keySet().stream().forEach((GameMode gm) -> {
long fTime = gmTimes.get(gm);
if (tGmTimes.get(gm) != null) {
long tTime = tGmTimes.get(gm);
gmTimes.put(gm, fTime + tTime);
}
});
if (fData.getLastPlayed() < tData.getLastPlayed()) {
fData.setLastPlayed(tData.getLastPlayed());
}
fData.setPlayTime(fData.getPlayTime() + tData.getPlayTime());
fData.setTimesKicked(fData.getTimesKicked() + tData.getTimesKicked());
fData.setLoginTimes(fData.getLoginTimes() + tData.getLoginTimes());
fData.addLocations(tData.getLocations());
fData.addNicknames(tData.getNicknames());
fData.addIpAddresses(tData.getIps());
DemographicsData tDemData = tData.getDemData();
DemographicsData fDemData = fData.getDemData();
if (tDemData.getAge() > fDemData.getAge()) {
fDemData.setAge(tDemData.getAge());
}
if (fDemData.getGeoLocation().equals("Not Known")) {
fDemData.setGeoLocation(tDemData.getGeoLocation());
}
fData.setDemData(fDemData);
return fData;
}
/**
* Combines two conflicting ServerDatasets
*
* @param fData First Dataset
* @param tData Second Dataset
* @return Combined ServerDataset
*/
public static HashMap<Long, ServerData> combineServerDatas(HashMap<Long, ServerData> fData, HashMap<Long, ServerData> tData) {
HashMap<Long, ServerData> combinedData = new HashMap<>();
Set<Long> allDates = new HashSet<>();
allDates.addAll(fData.keySet());
allDates.addAll(tData.keySet());
allDates.parallelStream().forEach((Long date) -> {
ServerData fServerData = fData.get(date);
ServerData tServerData = tData.get(date);
if (fServerData == null) {
combinedData.put(date, tServerData);
} else if (tServerData == null) {
combinedData.put(date, fServerData);
} else if (fServerData.getPlayersOnline() > tServerData.getPlayersOnline()) {
combinedData.put(date, fServerData);
} else {
combinedData.put(date, tServerData);
}
});
return combinedData;
}
/**
* Combines Two conflicting command usage datasets.
*
* @param fData First Dataset
* @param tData Second Dataset
* @return Combined Dataset
*/
public static HashMap<String, Integer> combineCommandUses(HashMap<String, Integer> fData, HashMap<String, Integer> tData) {
HashMap<String, Integer> combinedData = new HashMap<>();
Set<String> allCommands = new HashSet<>();
if (fData != null) {
allCommands.addAll(fData.keySet());
}
if (tData != null) {
allCommands.addAll(tData.keySet());
}
for (String command : allCommands) {
boolean fDataHasCommand = false;
if (fData != null) {
fDataHasCommand = fData.keySet().contains(command);
}
boolean tDataHasCommand = false;
if (tData != null) {
tDataHasCommand = tData.keySet().contains(command);
}
int value = 0;
if (fDataHasCommand) {
value += fData.get(command);
}
if (tDataHasCommand) {
value += tData.get(command);
}
combinedData.put(command, value);
}
return combinedData;
}
}

View File

@ -2,20 +2,14 @@ package com.djrapitops.plan.utilities;
import com.djrapitops.plan.Phrase;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.data.DemographicsData;
import com.djrapitops.plan.data.ServerData;
import com.djrapitops.plan.data.UserData;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -110,108 +104,4 @@ public class MiscUtils {
});
return matches;
}
public static List<UserData> combineUserDatas(HashMap<UUID, UserData> allFromUserData, HashMap<UUID, UserData> allToUserData, Set<UUID> uuids) {
List<UserData> combinedData = new ArrayList<>();
uuids.forEach((uuid) -> {
UserData fData = allFromUserData.get(uuid);
UserData tData = allToUserData.get(uuid);
if (fData == null) {
combinedData.add(tData);
} else if (tData == null) {
combinedData.add(fData);
} else {
combinedData.add(combineUserData(fData, tData));
}
});
return combinedData;
}
private static UserData combineUserData(UserData fData, UserData tData) {
if (fData.getLastGmSwapTime() < tData.getLastGmSwapTime()) {
fData.setLastGmSwapTime(tData.getLastGmSwapTime());
fData.setLastGamemode(tData.getLastGamemode());
}
HashMap<GameMode, Long> gmTimes = fData.getGmTimes();
HashMap<GameMode, Long> tGmTimes = tData.getGmTimes();
gmTimes.keySet().stream().forEach((gm) -> {
long fTime = gmTimes.get(gm);
if (tGmTimes.get(gm) != null) {
long tTime = tGmTimes.get(gm);
gmTimes.put(gm, fTime + tTime);
}
});
if (fData.getLastPlayed() < tData.getLastPlayed()) {
fData.setLastPlayed(tData.getLastPlayed());
}
fData.setPlayTime(fData.getPlayTime() + tData.getPlayTime());
fData.setTimesKicked(fData.getTimesKicked() + tData.getTimesKicked());
fData.setLoginTimes(fData.getLoginTimes() + tData.getLoginTimes());
fData.addLocations(tData.getLocations());
fData.addNicknames(tData.getNicknames());
fData.addIpAddresses(tData.getIps());
DemographicsData tDemData = tData.getDemData();
DemographicsData fDemData = fData.getDemData();
if (tDemData.getAge() > fDemData.getAge()) {
fDemData.setAge(tDemData.getAge());
}
if (fDemData.getGeoLocation().equals("Not Known")) {
fDemData.setGeoLocation(tDemData.getGeoLocation());
}
fData.setDemData(fDemData);
return fData;
}
public static HashMap<Long, ServerData> combineServerDatas(HashMap<Long, ServerData> fData, HashMap<Long, ServerData> tData) {
HashMap<Long, ServerData> combinedData = new HashMap<>();
Set<Long> allDates = new HashSet<>();
allDates.addAll(fData.keySet());
allDates.addAll(tData.keySet());
allDates.parallelStream().forEach((date) -> {
ServerData fServerData = fData.get(date);
ServerData tServerData = tData.get(date);
if (fServerData == null) {
combinedData.put(date, tServerData);
} else if (tServerData == null) {
combinedData.put(date, fServerData);
} else {
if (fServerData.getPlayersOnline() > tServerData.getPlayersOnline()) {
combinedData.put(date, fServerData);
} else {
combinedData.put(date, tServerData);
}
}
});
return combinedData;
}
public static HashMap<String, Integer> combineCommandUses(HashMap<String, Integer> fData, HashMap<String, Integer> tData) {
HashMap<String, Integer> combinedData = new HashMap<>();
Set<String> allCommands = new HashSet<>();
if (fData != null) {
allCommands.addAll(fData.keySet());
}
if (tData != null) {
allCommands.addAll(tData.keySet());
}
for (String command : allCommands) {
boolean fDataHasCommand = false;
if (fData != null) {
fDataHasCommand = fData.keySet().contains(command);
}
boolean tDataHasCommand = false;
if (tData != null) {
tDataHasCommand = tData.keySet().contains(command);
}
int value = 0;
if (fDataHasCommand) {
value += fData.get(command);
}
if (tDataHasCommand) {
value += tData.get(command);
}
combinedData.put(command, value);
}
return combinedData;
}
}

View File

@ -27,4 +27,13 @@ public class MapComparator {
return sortedList;
}
public static List<String[]> sortByValueLong(HashMap<String, Long> hashMap) {
List<String[]> sortedList = new ArrayList<>();
hashMap.keySet().stream().forEach((key) -> {
sortedList.add(new String[]{"" + hashMap.get(key), key});
});
Collections.sort(sortedList, (String[] strings, String[] otherStrings) -> (int) (Long.parseLong(strings[0]) - (Long.parseLong(otherStrings[0]))));
return sortedList;
}
}

View File

@ -28,9 +28,9 @@
%playerchartweek%
<h4>Player Activity - Last 30 days</h4>
%playerchartmonth%
<!-- <p>Recent logins: %recentlogins%</p>
<br/><h4>Top 20 Most Active</h4>
%top20mostactive%-->
<p><b>Most recent logins</b>: %recentlogins%</p>
<h4>Top 20 Most Active</h4>
%top20mostactive%
</td>
<td style="margin-left: 3px; margin-right: auto;
border-style: groove; border-width: 3px; border-radius: 12px; padding: 2px 4px 2px 3px;

View File

@ -1,7 +1,7 @@
name: Plan
author: Rsl1122
main: com.djrapitops.plan.Plan
version: 2.2.1
version: 2.3.0
commands:
plan:
@ -19,7 +19,10 @@ commands:
search:
usage: /plan <search terms> -p add -p to make not search playername
description: search data of multiple players with search terms
manage:
usage: /plan manage <manage subcommand>
description: manage the database
softdepend:
- PlanLite
@ -48,6 +51,9 @@ permissions:
plan.ignore.commanduse:
description: Commands used by this player are not saved
default: false
plan.manage:
description: Manage the database, clear, move, combine.
default: op
plan.basic:
children:
@ -66,4 +72,5 @@ permissions:
plan.reload: true
plan.*:
children:
plan.manage: true
plan.staff: true