mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-11-01 00:10:12 +01:00
method optimization with getSavedUUIDs, timeouts, fixes
- fixed serverdata newplayers not resetting to 0 if server is not reloaded. - Importing Ontime data will no longer reset every stat of player.
This commit is contained in:
parent
0b26ea5530
commit
51c5a7e7b6
@ -53,6 +53,7 @@ public enum Phrase {
|
||||
NOT_IN_FAC("Not in a faction"),
|
||||
//
|
||||
ANALYSIS("Analysis | "),
|
||||
COMMAND_TIMEOUT(ChatColor.RED + "" + PREFIX + "REPLACE0 Command timed out! Error most likely on console."),
|
||||
ANALYSIS_START(ANALYSIS + "Beginning analysis of user data.."),
|
||||
ANALYSIS_BOOT_NOTIFY(ANALYSIS + "Boot analysis in 30 seconds.."),
|
||||
ANALYSIS_BOOT(ANALYSIS + "Starting Boot Analysis.."),
|
||||
|
@ -30,7 +30,6 @@ Integrate PlanLite features to Plan and discontinue PlanLite
|
||||
Seperate serverdata and userdata saving
|
||||
Database Cleaning of useless data
|
||||
Fix any bugs that come up
|
||||
- New Players not reset if server not restarted
|
||||
*/
|
||||
/**
|
||||
*
|
||||
|
@ -69,12 +69,19 @@ public class AnalyzeCommand extends SubCommand {
|
||||
}
|
||||
|
||||
(new BukkitRunnable() {
|
||||
|
||||
private int timesrun = 0;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
timesrun++;
|
||||
if (analysisCache.isCached()) {
|
||||
sendAnalysisMessage(sender);
|
||||
this.cancel();
|
||||
}
|
||||
if (timesrun > 45) {
|
||||
sender.sendMessage(Phrase.COMMAND_TIMEOUT.parse("Analysis"));
|
||||
}
|
||||
}
|
||||
}).runTaskTimer(plugin, 1 * 20, 5 * 20);
|
||||
return true;
|
||||
|
@ -19,6 +19,7 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -100,8 +101,11 @@ public class InspectCommand extends SubCommand {
|
||||
}
|
||||
final int available = configValue;
|
||||
(new BukkitRunnable() {
|
||||
private int timesrun = 0;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
timesrun++;
|
||||
if (inspectCache.isCached(uuid)) {
|
||||
sender.sendMessage(Phrase.CMD_INSPECT_HEADER + playerName);
|
||||
// Link
|
||||
@ -124,6 +128,9 @@ public class InspectCommand extends SubCommand {
|
||||
sender.sendMessage(Phrase.CMD_FOOTER+"");
|
||||
this.cancel();
|
||||
}
|
||||
if (timesrun > 45) {
|
||||
sender.sendMessage(Phrase.COMMAND_TIMEOUT.parse("Inspect"));
|
||||
}
|
||||
}
|
||||
}).runTaskTimer(plugin, 1 * 20, 5 * 20);
|
||||
return true;
|
||||
|
@ -7,7 +7,6 @@ import com.djrapitops.plan.command.SubCommand;
|
||||
import com.djrapitops.plan.data.ServerData;
|
||||
import com.djrapitops.plan.database.Database;
|
||||
import com.djrapitops.plan.database.databases.SQLiteDB;
|
||||
import com.djrapitops.plan.utilities.FormatUtils;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
@ -79,7 +78,7 @@ public class ManageBackupCommand extends SubCommand {
|
||||
public void run() {
|
||||
Date now = new Date();
|
||||
SQLiteDB backupDB = new SQLiteDB(plugin,
|
||||
"backup-"+now.toString().substring(4, 10).replaceAll(" ", "-").replaceAll(":", "-"));
|
||||
args[0]+"-backup-"+now.toString().substring(4, 10).replaceAll(" ", "-").replaceAll(":", "-"));
|
||||
|
||||
if (!backupDB.init()) {
|
||||
sender.sendMessage(Phrase.MANAGE_DATABASE_FAILURE + "");
|
||||
|
@ -8,7 +8,6 @@ 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.HashSet;
|
||||
@ -17,7 +16,6 @@ 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;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
@ -101,25 +99,9 @@ public class ManageCombineCommand extends SubCommand {
|
||||
return true;
|
||||
}
|
||||
|
||||
OfflinePlayer[] offlinePlayers;
|
||||
final Set<UUID> fromUUIDS = fromDatabase.getSavedUUIDs();
|
||||
final Set<UUID> toUUIDS = toDatabase.getSavedUUIDs();
|
||||
try {
|
||||
offlinePlayers = plugin.getServer().getOfflinePlayers();
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
sender.sendMessage(Phrase.MANAGE_ERROR_NO_PLAYERS + " (" + fromDB + ")");
|
||||
return true;
|
||||
}
|
||||
final List<UUID> fromUUIDS = new ArrayList<>();
|
||||
final List<UUID> toUUIDS = new ArrayList<>();
|
||||
try {
|
||||
for (OfflinePlayer p : offlinePlayers) {
|
||||
UUID uuid = p.getUniqueId();
|
||||
if (fromDatabase.wasSeenBefore(uuid)) {
|
||||
fromUUIDS.add(uuid);
|
||||
}
|
||||
if (toDatabase.wasSeenBefore(uuid)) {
|
||||
toUUIDS.add(uuid);
|
||||
}
|
||||
}
|
||||
if (fromUUIDS.isEmpty() && toUUIDS.isEmpty()) {
|
||||
sender.sendMessage(Phrase.MANAGE_ERROR_NO_PLAYERS + " (" + fromDB + ")");
|
||||
return true;
|
||||
|
@ -23,6 +23,7 @@ import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||
import static org.bukkit.Bukkit.getOfflinePlayer;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -93,10 +94,10 @@ public class ManageImportCommand extends SubCommand {
|
||||
for (OfflinePlayer p : Bukkit.getOfflinePlayers()) {
|
||||
uuids.add(p.getUniqueId());
|
||||
}
|
||||
HashMap<UUID, Long> data = importPlugins.get(importFromPlugin).grabNumericData(uuids);
|
||||
HashMap<UUID, Long> onTimeData = importPlugins.get(importFromPlugin).grabNumericData(uuids);
|
||||
DataCacheHandler handler = plugin.getHandler();
|
||||
if (importFromPlugin.equals("ontime")) {
|
||||
importOnTime(data, handler);
|
||||
importOnTime(onTimeData, handler);
|
||||
}
|
||||
handler.saveCachedUserData();
|
||||
|
||||
@ -107,15 +108,14 @@ public class ManageImportCommand extends SubCommand {
|
||||
return true;
|
||||
}
|
||||
|
||||
private void importOnTime(HashMap<UUID, Long> data, DataCacheHandler handler) {
|
||||
for (UUID uuid : data.keySet()) {
|
||||
private void importOnTime(HashMap<UUID, Long> onTimeData, DataCacheHandler handler) {
|
||||
for (UUID uuid : onTimeData.keySet()) {
|
||||
OfflinePlayer player = getOfflinePlayer(uuid);
|
||||
handler.newPlayer(player);
|
||||
if (handler.getActivityHandler().isFirstTimeJoin(uuid)) {
|
||||
handler.newPlayer(player);
|
||||
}
|
||||
UserData uData = handler.getCurrentData(uuid);
|
||||
Long playTime = data.get(uuid);
|
||||
Long playTime = onTimeData.get(uuid);
|
||||
if (playTime > uData.getPlayTime()) {
|
||||
uData.setPlayTime(playTime);
|
||||
uData.setLastGamemode(GameMode.SURVIVAL);
|
||||
|
@ -12,9 +12,9 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
@ -98,21 +98,7 @@ public class ManageMoveCommand extends SubCommand {
|
||||
plugin.logError(toDB + " was null!");
|
||||
return true;
|
||||
}
|
||||
|
||||
OfflinePlayer[] offlinePlayers;
|
||||
try {
|
||||
offlinePlayers = plugin.getServer().getOfflinePlayers();
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
sender.sendMessage(Phrase.MANAGE_ERROR_NO_PLAYERS + " (" + fromDB + ")");
|
||||
return true;
|
||||
}
|
||||
final List<UUID> uuids = new ArrayList<>();
|
||||
for (OfflinePlayer p : offlinePlayers) {
|
||||
UUID uuid = p.getUniqueId();
|
||||
if (fromDatabase.wasSeenBefore(uuid)) {
|
||||
uuids.add(uuid);
|
||||
}
|
||||
}
|
||||
final Set<UUID> uuids = fromDatabase.getSavedUUIDs();
|
||||
if (uuids.isEmpty()) {
|
||||
sender.sendMessage(Phrase.MANAGE_ERROR_NO_PLAYERS + " (" + fromDB + ")");
|
||||
return true;
|
||||
|
@ -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;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -114,4 +114,8 @@ public class ServerData {
|
||||
public int getNewPlayers() {
|
||||
return newPlayers;
|
||||
}
|
||||
|
||||
public void setNewPlayers(int newPlayers) {
|
||||
this.newPlayers = newPlayers;
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,9 @@ import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.database.Database;
|
||||
import com.djrapitops.plan.data.*;
|
||||
import com.djrapitops.plan.data.handlers.*;
|
||||
import com.djrapitops.plan.utilities.MiscUtils;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
@ -15,8 +17,8 @@ import main.java.com.djrapitops.plan.Settings;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import static org.bukkit.Bukkit.getPlayer;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import static org.bukkit.Bukkit.getPlayer;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -40,6 +42,7 @@ public class DataCacheHandler {
|
||||
|
||||
private int timesSaved;
|
||||
private int maxPlayers;
|
||||
private Date lastServerDataSave;
|
||||
|
||||
/**
|
||||
* Class Constructor.
|
||||
@ -66,6 +69,7 @@ public class DataCacheHandler {
|
||||
|
||||
timesSaved = 0;
|
||||
maxPlayers = plugin.getServer().getMaxPlayers();
|
||||
lastServerDataSave = new Date();
|
||||
|
||||
int minutes = Settings.SAVE_CACHE_MIN.getNumber();
|
||||
if (minutes <= 0) {
|
||||
@ -91,8 +95,13 @@ public class DataCacheHandler {
|
||||
if (timesSaved % clearAfterXsaves == 0) {
|
||||
handler.clearCache();
|
||||
}
|
||||
Date serverDataSave = new Date();
|
||||
if (MiscUtils.isOnSameDay(serverDataSave, lastServerDataSave)) {
|
||||
serverData.setNewPlayers(0);
|
||||
}
|
||||
serverData.updatePlayerCount();
|
||||
saveServerData();
|
||||
lastServerDataSave = serverDataSave;
|
||||
handler.clearNulls();
|
||||
timesSaved++;
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.api.Gender;
|
||||
import com.djrapitops.plan.database.Database;
|
||||
import com.djrapitops.plan.data.*;
|
||||
import com.djrapitops.plan.utilities.MiscUtils;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.sql.Connection;
|
||||
@ -353,7 +354,6 @@ public abstract class SQLDB extends Database {
|
||||
HashMap<String, Integer> commandUse = getCommandUse();
|
||||
int newPlayers = 0;
|
||||
Date now = new Date();
|
||||
Date startOfToday = new Date(now.getTime() - (now.getTime() % 86400000));
|
||||
try {
|
||||
PreparedStatement statement = connection.prepareStatement("SELECT * FROM " + serverdataName
|
||||
+ " ORDER BY " + serverdataColumnDate + " DESC LIMIT 1");
|
||||
@ -361,8 +361,7 @@ public abstract class SQLDB extends Database {
|
||||
ResultSet set = statement.executeQuery();
|
||||
while (set.next()) {
|
||||
Date lastSave = new Date(set.getLong(serverdataColumnDate));
|
||||
Date startOfSaveDay = new Date(lastSave.getTime() - (lastSave.getTime() % 86400000));
|
||||
if (startOfSaveDay == startOfToday) {
|
||||
if (MiscUtils.isOnSameDay(now, lastSave)) {
|
||||
newPlayers = set.getInt(serverdataColumnNewPlayers);
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import main.java.com.djrapitops.plan.Settings;
|
||||
import main.java.com.djrapitops.plan.data.PlanLiteAnalyzedData;
|
||||
@ -304,9 +305,10 @@ public class Analysis {
|
||||
private List<UUID> fetchPlayersInDB(OfflinePlayer[] offlinePlayers) {
|
||||
final List<UUID> uuids = new ArrayList<>();
|
||||
log(Phrase.ANALYSIS_FETCH_PLAYERS + "");
|
||||
Set<UUID> savedUUIDs = plugin.getDB().getSavedUUIDs();
|
||||
for (OfflinePlayer p : offlinePlayers) {
|
||||
UUID uuid = p.getUniqueId();
|
||||
if (plugin.getDB().wasSeenBefore(uuid)) {
|
||||
if (savedUUIDs.contains(uuid)) {
|
||||
uuids.add(uuid);
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
@ -49,12 +50,12 @@ public class MiscUtils {
|
||||
if (newestVersionNumber > currentVersionNumber) {
|
||||
return Phrase.VERSION_NEW_AVAILABLE.parse(versionString);
|
||||
} else {
|
||||
return Phrase.VERSION_LATEST+"";
|
||||
return Phrase.VERSION_LATEST + "";
|
||||
}
|
||||
} catch (IOException | NumberFormatException e) {
|
||||
plugin.logError(Phrase.VERSION_CHECK_ERROR+"");
|
||||
plugin.logError(Phrase.VERSION_CHECK_ERROR + "");
|
||||
}
|
||||
return Phrase.VERSION_FAIL+"";
|
||||
return Phrase.VERSION_FAIL + "";
|
||||
}
|
||||
|
||||
/**
|
||||
@ -105,4 +106,10 @@ public class MiscUtils {
|
||||
});
|
||||
return matches;
|
||||
}
|
||||
|
||||
public static boolean isOnSameDay(Date first, Date second) {
|
||||
Date startOfFirst = new Date(first.getTime() - (first.getTime() % 86400000));
|
||||
Date startOfSecond = new Date(second.getTime() - (second.getTime() % 86400000));
|
||||
return (startOfFirst != startOfSecond);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user