mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-28 12:07:35 +01:00
Merge pull request #283 from Fuzzlemann/master
PR for 4.0.0 (Fuzzlemann) (13)
This commit is contained in:
commit
d9b287ff9a
@ -42,6 +42,12 @@
|
||||
<version>3.6</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- Geo IP -->
|
||||
<dependency>
|
||||
<groupId>com.maxmind.geoip2</groupId>
|
||||
<artifactId>geoip2</artifactId>
|
||||
<version>2.9.0</version>
|
||||
</dependency>
|
||||
<!-- Framework for easier plugin development -->
|
||||
<dependency>
|
||||
<groupId>com.djrapitops</groupId>
|
||||
@ -75,7 +81,7 @@
|
||||
<version>3.7.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- -->
|
||||
<!-- Testing -->
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock</artifactId>
|
||||
|
@ -30,7 +30,6 @@ import main.java.com.djrapitops.plan.api.API;
|
||||
import main.java.com.djrapitops.plan.api.IPlan;
|
||||
import main.java.com.djrapitops.plan.api.exceptions.DatabaseInitException;
|
||||
import main.java.com.djrapitops.plan.command.PlanCommand;
|
||||
import main.java.com.djrapitops.plan.command.commands.RegisterCommandFilter;
|
||||
import main.java.com.djrapitops.plan.data.additional.HookHandler;
|
||||
import main.java.com.djrapitops.plan.database.Database;
|
||||
import main.java.com.djrapitops.plan.database.databases.MySQLDB;
|
||||
@ -38,6 +37,7 @@ import main.java.com.djrapitops.plan.database.databases.SQLiteDB;
|
||||
import main.java.com.djrapitops.plan.locale.Locale;
|
||||
import main.java.com.djrapitops.plan.locale.Msg;
|
||||
import main.java.com.djrapitops.plan.systems.cache.DataCache;
|
||||
import main.java.com.djrapitops.plan.systems.cache.GeolocationCache;
|
||||
import main.java.com.djrapitops.plan.systems.info.InformationManager;
|
||||
import main.java.com.djrapitops.plan.systems.info.server.ServerInfoManager;
|
||||
import main.java.com.djrapitops.plan.systems.listeners.*;
|
||||
@ -47,7 +47,6 @@ import main.java.com.djrapitops.plan.systems.tasks.TPSCountTimer;
|
||||
import main.java.com.djrapitops.plan.systems.webserver.PageCache;
|
||||
import main.java.com.djrapitops.plan.systems.webserver.WebServer;
|
||||
import main.java.com.djrapitops.plan.utilities.Benchmark;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import java.util.HashSet;
|
||||
@ -133,6 +132,8 @@ public class Plan extends BukkitPlugin<Plan> implements IPlan {
|
||||
|
||||
Benchmark.start("Enable");
|
||||
|
||||
GeolocationCache.checkDB();
|
||||
|
||||
// Initialize Locale
|
||||
new Locale(this).loadLocale();
|
||||
|
||||
@ -173,8 +174,6 @@ public class Plan extends BukkitPlugin<Plan> implements IPlan {
|
||||
|
||||
this.api = new API(this);
|
||||
|
||||
setupFilter(); // TODO Move to RegisterCommand Constructor
|
||||
|
||||
// Data view settings // TODO Rewrite. (TextUI removed & webServer might be running on bungee
|
||||
boolean usingAlternativeIP = Settings.SHOW_ALTERNATIVE_IP.isTrue();
|
||||
boolean hasDataViewCapability = usingAlternativeIP;
|
||||
@ -213,14 +212,15 @@ public class Plan extends BukkitPlugin<Plan> implements IPlan {
|
||||
|
||||
Benchmark.start("Task Registration");
|
||||
tpsCountTimer = new TPSCountTimer(this);
|
||||
|
||||
runnableFactory.createNew(tpsCountTimer).runTaskTimer(1000, TimeAmount.SECOND.ticks());
|
||||
|
||||
// Analysis refresh settings
|
||||
int analysisRefreshMinutes = Settings.ANALYSIS_AUTO_REFRESH.getNumber();
|
||||
boolean analysisRefreshTaskIsEnabled = analysisRefreshMinutes > 0;
|
||||
long analysisPeriod = analysisRefreshMinutes * TimeAmount.MINUTE.ticks();
|
||||
|
||||
Log.info(bootAnalysisMsg);
|
||||
|
||||
ITask bootAnalysisTask = runnableFactory.createNew("BootAnalysisTask", new AbsRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@ -229,7 +229,9 @@ public class Plan extends BukkitPlugin<Plan> implements IPlan {
|
||||
this.cancel();
|
||||
}
|
||||
}).runTaskLaterAsynchronously(30 * TimeAmount.SECOND.ticks());
|
||||
|
||||
bootAnalysisTaskID = bootAnalysisTask.getTaskId();
|
||||
|
||||
if (analysisRefreshTaskIsEnabled) {
|
||||
runnableFactory.createNew("PeriodicalAnalysisTask", new AbsRunnable() {
|
||||
@Override
|
||||
@ -238,6 +240,7 @@ public class Plan extends BukkitPlugin<Plan> implements IPlan {
|
||||
}
|
||||
}).runTaskTimerAsynchronously(analysisPeriod, analysisPeriod);
|
||||
}
|
||||
|
||||
Benchmark.stop("Enable", "Task Registration");
|
||||
}
|
||||
|
||||
@ -331,14 +334,6 @@ public class Plan extends BukkitPlugin<Plan> implements IPlan {
|
||||
db.init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Setups the command console output filter
|
||||
*/
|
||||
private void setupFilter() {
|
||||
org.apache.logging.log4j.core.Logger logger = (org.apache.logging.log4j.core.Logger) LogManager.getRootLogger();
|
||||
logger.addFilter(new RegisterCommandFilter());
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to access Cache.
|
||||
*
|
||||
|
@ -1,5 +1,8 @@
|
||||
package main.java.com.djrapitops.plan;
|
||||
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import org.bukkit.Server;
|
||||
|
||||
/**
|
||||
* Class responsible for holding server variable values that do not change
|
||||
* without a reload.
|
||||
@ -22,7 +25,7 @@ public class ServerVariableHolder {
|
||||
*
|
||||
* @param server instance the plugin is running on.
|
||||
*/
|
||||
public ServerVariableHolder(org.bukkit.Server server) {
|
||||
public ServerVariableHolder(Server server) {
|
||||
ip = server.getIp();
|
||||
name = server.getName();
|
||||
port = server.getPort();
|
||||
@ -40,7 +43,7 @@ public class ServerVariableHolder {
|
||||
*
|
||||
* @param server instance the plugin is running on.
|
||||
*/
|
||||
public ServerVariableHolder(net.md_5.bungee.api.ProxyServer server) {
|
||||
public ServerVariableHolder(ProxyServer server) {
|
||||
ip = Settings.BUNGEE_IP.toString();
|
||||
name = "BungeeCord";
|
||||
port = -1;
|
||||
|
@ -10,6 +10,7 @@ package main.java.com.djrapitops.plan.api.exceptions;
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class DatabaseInitException extends DatabaseException {
|
||||
|
||||
public DatabaseInitException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ package main.java.com.djrapitops.plan.api.exceptions;
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class ParseException extends Exception {
|
||||
|
||||
public ParseException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ package main.java.com.djrapitops.plan.api.exceptions;
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class PlanEnableException extends Exception {
|
||||
|
||||
public PlanEnableException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
@ -42,14 +42,9 @@ public class PlanBungee extends BungeePlugin<PlanBungee> implements IPlan {
|
||||
|
||||
private ProcessingQueue processingQueue;
|
||||
|
||||
public PlanBungee() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
try {
|
||||
|
||||
|
||||
super.setInstance(this);
|
||||
super.setDebugMode(Settings.DEBUG.toString());
|
||||
super.getPluginLogger().setFolder(getDataFolder());
|
||||
|
@ -14,6 +14,8 @@ import main.java.com.djrapitops.plan.locale.Locale;
|
||||
import main.java.com.djrapitops.plan.locale.Msg;
|
||||
import main.java.com.djrapitops.plan.utilities.Check;
|
||||
import main.java.com.djrapitops.plan.utilities.PassEncryptUtil;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.core.Logger;
|
||||
|
||||
/**
|
||||
* Command for registering web users.
|
||||
@ -38,7 +40,7 @@ public class RegisterCommand extends SubCommand {
|
||||
Locale.get(Msg.CMD_USG_WEB_REGISTER).toString(),
|
||||
"<password> [name] [access lvl]");
|
||||
this.plugin = plugin;
|
||||
|
||||
setupFilter();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -133,4 +135,12 @@ public class RegisterCommand extends SubCommand {
|
||||
}
|
||||
}).runTaskAsynchronously();
|
||||
}
|
||||
|
||||
/**
|
||||
* Setups the command console output filter
|
||||
*/
|
||||
private void setupFilter() {
|
||||
Logger logger = (Logger) LogManager.getRootLogger();
|
||||
logger.addFilter(new RegisterCommandFilter());
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package main.java.com.djrapitops.plan.data.additional;
|
||||
|
||||
import main.java.com.djrapitops.plan.utilities.html.Html;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
@ -289,40 +290,35 @@ public abstract class PluginData {
|
||||
&& analysisTypes.contains(AnalysisType.BOOLEAN_TOTAL);
|
||||
}
|
||||
|
||||
/**
|
||||
* If a PluginData object has same placeholder, sourcePlugin and
|
||||
* analysisTypes, it is considered equal.
|
||||
*
|
||||
* @param obj Another Object.
|
||||
* @return Is current object equal to given object.
|
||||
*/
|
||||
@Override
|
||||
public final boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final PluginData other = (PluginData) obj;
|
||||
return this.analysisOnly == other.analysisOnly
|
||||
&& Objects.equals(this.placeholder, other.placeholder)
|
||||
&& Objects.equals(this.sourcePlugin, other.sourcePlugin)
|
||||
&& Objects.equals(this.analysisTypes, other.analysisTypes);
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
PluginData that = (PluginData) o;
|
||||
return analysisOnly == that.analysisOnly &&
|
||||
Objects.equals(analysisTypes, that.analysisTypes) &&
|
||||
Objects.equals(placeholder, that.placeholder) &&
|
||||
Objects.equals(sourcePlugin, that.sourcePlugin) &&
|
||||
Objects.equals(icon, that.icon) &&
|
||||
Objects.equals(prefix, that.prefix) &&
|
||||
Objects.equals(suffix, that.suffix);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int hashCode() {
|
||||
int hash = 5;
|
||||
hash = 47 * hash + Objects.hashCode(this.placeholder);
|
||||
hash = 47 * hash + Objects.hashCode(this.sourcePlugin);
|
||||
hash = 47 * hash + (this.analysisOnly ? 1 : 0);
|
||||
hash = 47 * hash + Objects.hashCode(this.prefix);
|
||||
hash = 47 * hash + Objects.hashCode(this.suffix);
|
||||
hash = 47 * hash + Objects.hashCode(this.analysisTypes);
|
||||
return hash;
|
||||
public int hashCode() {
|
||||
return Objects.hash(analysisTypes, placeholder, sourcePlugin, analysisOnly, icon, prefix, suffix);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this)
|
||||
.append("analysisTypes", analysisTypes)
|
||||
.append("placeholder", placeholder)
|
||||
.append("sourcePlugin", sourcePlugin)
|
||||
.append("analysisOnly", analysisOnly)
|
||||
.append("icon", icon)
|
||||
.append("prefix", prefix)
|
||||
.append("suffix", suffix)
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
|
@ -81,10 +81,7 @@ public abstract class TimeKeeper {
|
||||
if (state == null) {
|
||||
state = newState;
|
||||
}
|
||||
Long currentTime = times.get(state);
|
||||
if (currentTime == null) {
|
||||
currentTime = 0L;
|
||||
}
|
||||
Long currentTime = times.getOrDefault(state, 0L);
|
||||
long diff = playTime - lastStateChange;
|
||||
times.put(state, currentTime + Math.abs(diff));
|
||||
state = newState;
|
||||
|
@ -40,7 +40,7 @@ public class MySQLDB extends SQLDB {
|
||||
String port = config.getInt("Database.MySQL.Port").toString();
|
||||
String database = config.getString("Database.MySQL.Database");
|
||||
|
||||
dataSource.setUrl("jdbc:mysql://" + host + ":" + port + "/" + database + "?rewriteBatchedStatements=true");
|
||||
dataSource.setUrl("jdbc:mysql://" + host + ":" + port + "/" + database + "?rewriteBatchedStatements=true&useSSL=false");
|
||||
|
||||
String username = config.getString("Database.MySQL.User");
|
||||
String password = config.getString("Database.MySQL.Password");
|
||||
|
@ -59,16 +59,17 @@ public abstract class Table {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return @throws SQLException
|
||||
* @return
|
||||
* @throws SQLException
|
||||
*/
|
||||
protected Connection getConnection() throws SQLException {
|
||||
return db.getConnection();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return @throws SQLException
|
||||
* @return
|
||||
* @throws SQLException
|
||||
*/
|
||||
public int getVersion() throws SQLException {
|
||||
return db.getVersion();
|
||||
|
@ -2,12 +2,20 @@ package main.java.com.djrapitops.plan.systems.cache;
|
||||
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import com.maxmind.geoip2.DatabaseReader;
|
||||
import com.maxmind.geoip2.exception.GeoIp2Exception;
|
||||
import com.maxmind.geoip2.model.CountryResponse;
|
||||
import com.maxmind.geoip2.record.Country;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.MalformedURLException;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.URL;
|
||||
import java.nio.channels.Channels;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
/**
|
||||
* This class contains the geolocation cache.
|
||||
@ -21,6 +29,8 @@ import java.net.URL;
|
||||
*/
|
||||
public class GeolocationCache {
|
||||
|
||||
private static File geolocationDB = new File(Plan.getInstance().getDataFolder(), "GeoIP.dat");
|
||||
|
||||
private static final Cache<String, String> geolocationCache = CacheBuilder.newBuilder()
|
||||
.build();
|
||||
|
||||
@ -59,39 +69,48 @@ public class GeolocationCache {
|
||||
/**
|
||||
* Retrieves the country in full length (e.g. United States) from the IP Address.
|
||||
* <p>
|
||||
* This method uses the free service of freegeoip.net. The maximum amount of requests is 15.000 per hour.
|
||||
*
|
||||
* This product includes GeoLite2 data created by MaxMind, available from
|
||||
* <a href="http://www.maxmind.com">http://www.maxmind.com</a>.
|
||||
* @param ipAddress The IP Address from which the country is retrieved
|
||||
* @return The name of the country in full length.
|
||||
* <p>
|
||||
* An exception from that rule is when the country is unknown or the retrieval of the country failed in any way,
|
||||
* if that happens, "Not Known" will be returned.
|
||||
* @see <a href="http://freegeoip.net">http://freegeoip.net</a>
|
||||
* @see <a href="http://maxmind.com">http://maxmind.com</a>
|
||||
* @see #getCountry(String)
|
||||
*/
|
||||
private static String getUncachedCountry(String ipAddress) {
|
||||
URL url;
|
||||
|
||||
String urlString = "http://freegeoip.net/csv/" + ipAddress;
|
||||
String unknownString = "Not Known";
|
||||
|
||||
try {
|
||||
url = new URL(urlString);
|
||||
} catch (MalformedURLException e) {
|
||||
Log.error("The URL \"" + urlString + "\" couldn't be converted to URL: " + e.getCause()); //Shouldn't ever happen
|
||||
return unknownString;
|
||||
checkDB();
|
||||
|
||||
try (DatabaseReader reader = new DatabaseReader.Builder(geolocationDB).build()) {
|
||||
InetAddress inetAddress = InetAddress.getByName(ipAddress);
|
||||
|
||||
CountryResponse response = reader.country(inetAddress);
|
||||
Country country = response.getCountry();
|
||||
|
||||
return country.getName();
|
||||
}
|
||||
|
||||
try (BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()))) {
|
||||
String resultLine = in.readLine();
|
||||
Log.debug("Result for country request for " + ipAddress + ": " + resultLine);
|
||||
} catch (IOException | GeoIp2Exception e) {
|
||||
return "Not Known";
|
||||
}
|
||||
}
|
||||
|
||||
String[] results = resultLine.split(",");
|
||||
String result = results[2];
|
||||
/**
|
||||
* Checks if the DB exists, if not, it downloads it
|
||||
*
|
||||
* @throws IOException when an error at download or saving the DB happens
|
||||
*/
|
||||
public static void checkDB() throws IOException {
|
||||
if (geolocationDB.exists()) {
|
||||
return;
|
||||
}
|
||||
|
||||
return result.isEmpty() ? unknownString : result;
|
||||
} catch (Exception exc) {
|
||||
return unknownString;
|
||||
URL downloadSite = new URL("http://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.mmdb.gz");
|
||||
try (ReadableByteChannel rbc = Channels.newChannel(new GZIPInputStream(downloadSite.openStream()));
|
||||
FileOutputStream fos = new FileOutputStream(geolocationDB.getAbsoluteFile())) {
|
||||
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
|
||||
}
|
||||
}
|
||||
|
||||
@ -115,6 +134,9 @@ public class GeolocationCache {
|
||||
return geolocationCache.asMap().containsKey(ipAddress);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the cache
|
||||
*/
|
||||
public static void clearCache() {
|
||||
geolocationCache.invalidateAll();
|
||||
}
|
||||
|
@ -110,16 +110,8 @@ public class InspectPageParser extends PageParser {
|
||||
long playtimeDay = AnalysisUtils.getTotalPlaytime(sessionsDay);
|
||||
long playtimeWeek = AnalysisUtils.getTotalPlaytime(sessionsWeek);
|
||||
|
||||
if (!sessionsDay.isEmpty()) {
|
||||
addValue("sessionLengthLongestDay", FormatUtils.formatTimeAmount(sessionsDay.get(0).getLength()));
|
||||
} else {
|
||||
addValue("sessionLengthLongestDay", "-");
|
||||
}
|
||||
if (!sessionsWeek.isEmpty()) {
|
||||
addValue("sessionLengthLongestWeek", FormatUtils.formatTimeAmount(sessionsWeek.get(0).getLength()));
|
||||
} else {
|
||||
addValue("sessionLengthLongestWeek", "-");
|
||||
}
|
||||
addValue("sessionLengthLongestDay", !sessionsDay.isEmpty() ? FormatUtils.formatTimeAmount(sessionsDay.get(0).getLength()) : "-");
|
||||
addValue("sessionLengthLongestWeek", !sessionsWeek.isEmpty() ? FormatUtils.formatTimeAmount(sessionsWeek.get(0).getLength()) : "-");
|
||||
|
||||
addValue("sessionCountDay", sessionCountDay);
|
||||
addValue("sessionCountWeek", sessionCountWeek);
|
||||
|
@ -16,7 +16,7 @@ import java.util.*;
|
||||
public class UserImportData {
|
||||
|
||||
private String name;
|
||||
private String uuid;
|
||||
private UUID uuid;
|
||||
private List<String> nicknames;
|
||||
|
||||
private long registered;
|
||||
@ -32,7 +32,7 @@ public class UserImportData {
|
||||
private int mobKills;
|
||||
private int deaths;
|
||||
|
||||
private UserImportData(String name, String uuid, List<String> nicknames, long registered, boolean op, boolean banned, int timesKicked, List<String> ips, Map<String, GMTimes> worldTimes, List<PlayerKill> kills, int mobKills, int deaths) {
|
||||
private UserImportData(String name, UUID uuid, List<String> nicknames, long registered, boolean op, boolean banned, int timesKicked, List<String> ips, Map<String, GMTimes> worldTimes, List<PlayerKill> kills, int mobKills, int deaths) {
|
||||
this.name = name;
|
||||
this.uuid = uuid;
|
||||
this.nicknames = nicknames;
|
||||
@ -59,11 +59,11 @@ public class UserImportData {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getUuid() {
|
||||
public UUID getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public void setUuid(String uuid) {
|
||||
public void setUuid(UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
@ -153,7 +153,7 @@ public class UserImportData {
|
||||
private final Map<String, GMTimes> worldTimes = new HashMap<>();
|
||||
private final List<PlayerKill> kills = new ArrayList<>();
|
||||
private String name;
|
||||
private String uuid;
|
||||
private UUID uuid;
|
||||
private long registered;
|
||||
private boolean op;
|
||||
private boolean banned;
|
||||
@ -171,12 +171,12 @@ public class UserImportData {
|
||||
}
|
||||
|
||||
public UserImportDataBuilder uuid(UUID uuid) {
|
||||
return uuid(uuid.toString());
|
||||
this.uuid = uuid;
|
||||
return this;
|
||||
}
|
||||
|
||||
public UserImportDataBuilder uuid(String uuid) {
|
||||
this.uuid = uuid;
|
||||
return this;
|
||||
return uuid(UUID.fromString(uuid));
|
||||
}
|
||||
|
||||
public UserImportDataBuilder registered(long registered) {
|
||||
|
@ -96,17 +96,15 @@ public class UserImportRefiner {
|
||||
|
||||
importers.parallelStream().forEach(importer -> {
|
||||
String name = importer.getName();
|
||||
String uuid = importer.getUuid();
|
||||
UUID uuid = importer.getUuid();
|
||||
|
||||
boolean nameNull = name == null;
|
||||
boolean uuidNull = uuid == null;
|
||||
|
||||
if (nameNull && uuidNull) {
|
||||
invalidData.add(importer);
|
||||
}
|
||||
|
||||
if (nameNull) {
|
||||
namesMissing.put(importer, uuid);
|
||||
} else if (nameNull) {
|
||||
namesMissing.put(importer, uuid.toString());
|
||||
} else if (uuidNull) {
|
||||
uuidsMissing.put(importer, name);
|
||||
}
|
||||
@ -133,7 +131,13 @@ public class UserImportRefiner {
|
||||
addMissingUUIDsOverFetcher();
|
||||
}
|
||||
|
||||
foundUUIDs.entrySet().parallelStream().forEach(entry -> entry.getKey().setUuid(entry.getValue()));
|
||||
foundUUIDs.entrySet().parallelStream()
|
||||
.forEach(entry -> {
|
||||
UserImportData userImportData = entry.getKey();
|
||||
UUID uuid = UUID.fromString(entry.getValue());
|
||||
|
||||
userImportData.setUuid(uuid);
|
||||
});
|
||||
|
||||
importers.removeAll(uuidsMissing.keySet());
|
||||
|
||||
|
@ -5,14 +5,25 @@
|
||||
package main.java.com.djrapitops.plan.systems.processing.importing.importers;
|
||||
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import main.java.com.djrapitops.plan.Log;
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.data.Session;
|
||||
import main.java.com.djrapitops.plan.data.UserInfo;
|
||||
import main.java.com.djrapitops.plan.data.time.WorldTimes;
|
||||
import main.java.com.djrapitops.plan.database.Database;
|
||||
import main.java.com.djrapitops.plan.systems.cache.GeolocationCache;
|
||||
import main.java.com.djrapitops.plan.systems.processing.importing.ServerImportData;
|
||||
import main.java.com.djrapitops.plan.systems.processing.importing.UserImportData;
|
||||
import main.java.com.djrapitops.plan.systems.processing.importing.UserImportRefiner;
|
||||
import main.java.com.djrapitops.plan.utilities.Benchmark;
|
||||
|
||||
import java.util.List;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author Fuzzlemann
|
||||
@ -26,7 +37,7 @@ public abstract class Importer {
|
||||
|
||||
public abstract List<UserImportData> getUserImportData();
|
||||
|
||||
public final void processImport() {
|
||||
public final void processImport() throws SQLException {
|
||||
String benchmarkName = "Import processing";
|
||||
String serverBenchmarkName = "Server Data processing";
|
||||
String userDataBenchmarkName = "User Data processing";
|
||||
@ -44,7 +55,7 @@ public abstract class Importer {
|
||||
Benchmark.stop(benchmarkName);
|
||||
}
|
||||
|
||||
private void processServerData() {
|
||||
private void processServerData() throws SQLException {
|
||||
String benchmarkName = "Processing Server Data";
|
||||
String getDataBenchmarkName = "Getting Server Data";
|
||||
|
||||
@ -60,12 +71,17 @@ public abstract class Importer {
|
||||
return;
|
||||
}
|
||||
|
||||
//TODO
|
||||
Plan plan = Plan.getInstance();
|
||||
UUID uuid = plan.getServerInfoManager().getServerUUID();
|
||||
Database db = plan.getDB();
|
||||
|
||||
db.getTpsTable().insertAllTPS(ImmutableMap.of(uuid, serverImportData.getTpsData()));
|
||||
db.getCommandUseTable().insertCommandUsage(ImmutableMap.of(uuid, serverImportData.getCommandUsages()));
|
||||
|
||||
Benchmark.start(benchmarkName);
|
||||
}
|
||||
|
||||
private void processUserData() {
|
||||
private void processUserData() throws SQLException {
|
||||
String benchmarkName = "Processing User Data";
|
||||
String getDataBenchmarkName = "Getting User Data";
|
||||
|
||||
@ -81,11 +97,133 @@ public abstract class Importer {
|
||||
return;
|
||||
}
|
||||
|
||||
UserImportRefiner userImportRefiner = new UserImportRefiner(Plan.getInstance(), userImportData);
|
||||
Plan plan = Plan.getInstance();
|
||||
|
||||
UserImportRefiner userImportRefiner = new UserImportRefiner(plan, userImportData);
|
||||
userImportData = userImportRefiner.refineData();
|
||||
|
||||
//TODO
|
||||
UUID serverUUID = plan.getServerInfoManager().getServerUUID();
|
||||
Database db = plan.getDB();
|
||||
|
||||
Set<UUID> existingUUIDs = db.getSavedUUIDs();
|
||||
Map<UUID, UserInfo> users = new Hashtable<>();
|
||||
List<UserInfo> userInfo = new Vector<>();
|
||||
Map<UUID, List<String>> nickNames = new Hashtable<>();
|
||||
Map<UUID, Session> sessions = new Hashtable<>();
|
||||
Map<UUID, Map<String, String>> ips = new Hashtable<>();
|
||||
Map<UUID, Integer> timesKicked = new Hashtable<>();
|
||||
|
||||
userImportData.parallelStream().forEach(data -> {
|
||||
UUID uuid = data.getUuid();
|
||||
UserInfo info = toUserInfo(data);
|
||||
|
||||
if (!existingUUIDs.contains(uuid)) {
|
||||
userInfo.add(info);
|
||||
}
|
||||
|
||||
users.put(uuid, info);
|
||||
nickNames.put(uuid, data.getNicknames());
|
||||
ips.put(uuid, convertIPs(data));
|
||||
timesKicked.put(uuid, data.getTimesKicked());
|
||||
sessions.put(uuid, toSession(data));
|
||||
});
|
||||
|
||||
ExecutorService service = Executors.newCachedThreadPool();
|
||||
|
||||
db.getUsersTable().insertUsers(users);
|
||||
|
||||
new ImportExecutorHelper() {
|
||||
@Override
|
||||
void execute() throws SQLException {
|
||||
// TODO db.getSessionsTable().insertSessions(ImmutableMap.of(serverUUID, sessions));
|
||||
}
|
||||
}.submit(service);
|
||||
|
||||
new ImportExecutorHelper() {
|
||||
@Override
|
||||
void execute() throws SQLException {
|
||||
db.getUsersTable().updateKicked(timesKicked);
|
||||
}
|
||||
}.submit(service);
|
||||
|
||||
new ImportExecutorHelper() {
|
||||
@Override
|
||||
void execute() throws SQLException {
|
||||
db.getUserInfoTable().insertUserInfo(ImmutableMap.of(serverUUID, userInfo));
|
||||
}
|
||||
}.submit(service);
|
||||
|
||||
new ImportExecutorHelper() {
|
||||
@Override
|
||||
void execute() throws SQLException {
|
||||
db.getNicknamesTable().insertNicknames(ImmutableMap.of(serverUUID, nickNames));
|
||||
}
|
||||
}.submit(service);
|
||||
|
||||
new ImportExecutorHelper() {
|
||||
@Override
|
||||
void execute() throws SQLException {
|
||||
db.getIpsTable().insertIPsAndGeolocations(ips);
|
||||
}
|
||||
}.submit(service);
|
||||
|
||||
service.shutdown();
|
||||
|
||||
try {
|
||||
service.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
|
||||
} catch (InterruptedException e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
}
|
||||
|
||||
Benchmark.stop(benchmarkName);
|
||||
}
|
||||
|
||||
private UserInfo toUserInfo(UserImportData userImportData) {
|
||||
UUID uuid = userImportData.getUuid();
|
||||
String name = userImportData.getName();
|
||||
long registered = userImportData.getRegistered();
|
||||
boolean op = userImportData.isOp();
|
||||
boolean banned = userImportData.isBanned();
|
||||
|
||||
return new UserInfo(uuid, name, registered, op, banned);
|
||||
}
|
||||
|
||||
private Session toSession(UserImportData userImportData) {
|
||||
int mobKills = userImportData.getMobKills();
|
||||
int deaths = userImportData.getDeaths();
|
||||
|
||||
Session session = new Session(0, 0L, 0L, mobKills, deaths);
|
||||
|
||||
session.setPlayerKills(userImportData.getKills());
|
||||
session.setWorldTimes(new WorldTimes(userImportData.getWorldTimes()));
|
||||
|
||||
return session;
|
||||
}
|
||||
|
||||
private Map<String, String> convertIPs(UserImportData userImportData) {
|
||||
Map<String, String> convertedIPs;
|
||||
List<String> ips = userImportData.getIps();
|
||||
|
||||
convertedIPs = ips.parallelStream()
|
||||
.collect(Collectors.toMap(ip -> ip, GeolocationCache::getCountry, (a, b) -> b, HashMap::new));
|
||||
|
||||
return convertedIPs;
|
||||
}
|
||||
|
||||
private abstract class ImportExecutorHelper {
|
||||
abstract void execute() throws SQLException;
|
||||
|
||||
void submit(ExecutorService service) {
|
||||
service.submit(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
execute();
|
||||
} catch (SQLException e) {
|
||||
Log.toLog(this.getClass().getName(), e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Licence is provided in the jar as license.yml also here:
|
||||
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
|
||||
*/
|
||||
package main.java.com.djrapitops.plan.systems.webapi.universal;
|
||||
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.systems.webapi.WebAPI;
|
||||
import main.java.com.djrapitops.plan.systems.webserver.PageCache;
|
||||
import main.java.com.djrapitops.plan.systems.webserver.response.Response;
|
||||
import main.java.com.djrapitops.plan.systems.webserver.response.api.SuccessResponse;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Fuzzlemann
|
||||
*/
|
||||
public class PingWebAPI implements WebAPI {
|
||||
@Override
|
||||
public Response onResponse(Plan plan, Map<String, String> variables) {
|
||||
return PageCache.loadPage("success", SuccessResponse::new);
|
||||
}
|
||||
}
|
@ -14,6 +14,7 @@ import main.java.com.djrapitops.plan.systems.info.InformationManager;
|
||||
import main.java.com.djrapitops.plan.systems.webapi.WebAPI;
|
||||
import main.java.com.djrapitops.plan.systems.webapi.WebAPIManager;
|
||||
import main.java.com.djrapitops.plan.systems.webapi.bukkit.*;
|
||||
import main.java.com.djrapitops.plan.systems.webapi.universal.PingWebAPI;
|
||||
import main.java.com.djrapitops.plan.systems.webserver.response.*;
|
||||
import main.java.com.djrapitops.plan.systems.webserver.response.api.BadRequestResponse;
|
||||
import main.java.com.djrapitops.plan.systems.webserver.response.api.JsonResponse;
|
||||
@ -72,6 +73,7 @@ public class WebServer {
|
||||
WebAPIManager.registerNewAPI("configure", new ConfigureWebAPI());
|
||||
WebAPIManager.registerNewAPI("inspect", new InspectWebAPI());
|
||||
WebAPIManager.registerNewAPI("onlineplayers", new OnlinePlayersWebAPI());
|
||||
WebAPIManager.registerNewAPI("ping", new PingWebAPI());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -133,7 +133,7 @@ public class ImportBuilderTest {
|
||||
assertEquals(3, data.getNicknames().size());
|
||||
assertEquals(randomInt, data.getTimesKicked());
|
||||
|
||||
assertEquals(uuid.toString(), data.getUuid());
|
||||
assertEquals(uuid, data.getUuid());
|
||||
assertEquals(randomString, data.getName());
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,6 @@ import static org.powermock.api.mockito.PowerMockito.when;
|
||||
@PrepareForTest({JavaPlugin.class, Bukkit.class})
|
||||
public class MiscUtilsTest {
|
||||
|
||||
private Plan plan;
|
||||
private SQLDB db;
|
||||
|
||||
@Test
|
||||
@ -152,7 +151,7 @@ public class MiscUtilsTest {
|
||||
TestInit.init();
|
||||
|
||||
TestInit t = TestInit.init();
|
||||
plan = t.getPlanMock();
|
||||
Plan plan = t.getPlanMock();
|
||||
|
||||
db = new SQLiteDB(plan, "debug" + MiscUtils.getTime());
|
||||
db.init();
|
||||
|
Loading…
Reference in New Issue
Block a user