Merge branch 'master' of https://github.com/Fuzzlemann/Plan-PlayerAnalytics into Fuzzlemann-master

# Conflicts:
#	Plan/src/main/java/com/djrapitops/plan/utilities/file/dump/DumpUtils.java
This commit is contained in:
Rsl1122 2017-08-12 13:00:59 +03:00
commit a38e103456
11 changed files with 99 additions and 50 deletions

View File

@ -24,7 +24,7 @@ public class ManageCommand extends TreeCommand<Plan> {
* @param plugin Current instance of Plan
*/
public ManageCommand(Plan plugin) {
super(plugin, "manage,m", CommandType.CONSOLE, Permissions.MANAGE.getPermission(), Locale.get(Msg.CMD_USG_MANAGE) + "", "plan m");
super(plugin, "manage,m", CommandType.CONSOLE, Permissions.MANAGE.getPermission(), Locale.get(Msg.CMD_USG_MANAGE).toString(), "plan m");
}

View File

@ -50,8 +50,12 @@ public class ManageDumpCommand extends SubCommand {
plugin.getRunnableFactory().createNew(new AbsRunnable("DumpTask") {
@Override
public void run() {
sender.sendLink("Link to the Dump", DumpUtils.dump(plugin));
sender.sendLink("Report Issues here", "https://github.com/Rsl1122/Plan-PlayerAnalytics/issues/new");
try {
sender.sendLink("Link to the Dump", DumpUtils.dump(plugin));
sender.sendLink("Report Issues here", "https://github.com/Rsl1122/Plan-PlayerAnalytics/issues/new");
} finally {
this.cancel();
}
}
}).runTaskAsynchronously();
}

View File

@ -27,7 +27,7 @@ public class DataCacheClearQueue extends Queue<UUID> {
* @param handler current instance of DataCacheHandler.
*/
public DataCacheClearQueue(DataCacheHandler handler) {
super(new ArrayBlockingQueue(Settings.PROCESS_CLEAR_LIMIT.getNumber()));
super(new ArrayBlockingQueue<>(Settings.PROCESS_CLEAR_LIMIT.getNumber()));
setup = new ClearSetup(queue, handler);
setup.go();
}
@ -65,7 +65,7 @@ class ClearConsumer extends Consumer<UUID> implements Runnable {
private DataCacheHandler handler;
ClearConsumer(BlockingQueue q, DataCacheHandler handler) {
ClearConsumer(BlockingQueue<UUID> q, DataCacheHandler handler) {
super(q, "ClearQueueConsumer");
this.handler = handler;
}
@ -97,7 +97,7 @@ class ClearConsumer extends Consumer<UUID> implements Runnable {
class ClearSetup extends Setup<UUID> {
public ClearSetup(BlockingQueue<UUID> q, DataCacheHandler handler) {
ClearSetup(BlockingQueue<UUID> q, DataCacheHandler handler) {
super(new ClearConsumer(q, handler));
}
}

View File

@ -27,7 +27,7 @@ public class DataCacheGetQueue extends Queue<Map<UUID, List<DBCallableProcessor>
* @param plugin current instance of Plan
*/
public DataCacheGetQueue(Plan plugin) {
super(new ArrayBlockingQueue(Settings.PROCESS_GET_LIMIT.getNumber()));
super(new ArrayBlockingQueue<>(Settings.PROCESS_GET_LIMIT.getNumber()));
setup = new GetSetup(queue, plugin.getDB());
setup.go();
}
@ -50,8 +50,12 @@ public class DataCacheGetQueue extends Queue<Map<UUID, List<DBCallableProcessor>
}
}
public boolean containsUUIDtoBeCached(UUID uuid) {
return uuid != null && new ArrayList<>(queue).stream().anyMatch(map -> (map.get(uuid) != null && map.get(uuid).size() >= 2));
boolean containsUUIDtoBeCached(UUID uuid) {
return uuid != null
&& queue.stream()
.map(map -> map.get(uuid))
.filter(Objects::nonNull)
.anyMatch(list -> list.size() >= 2);
}
}
@ -59,7 +63,7 @@ class GetConsumer extends Consumer<Map<UUID, List<DBCallableProcessor>>> {
private Database db;
GetConsumer(BlockingQueue q, Database db) {
GetConsumer(BlockingQueue<Map<UUID, List<DBCallableProcessor>>> q, Database db) {
super(q, "GetQueueConsumer");
this.db = db;
}

View File

@ -39,7 +39,7 @@ public class Locale implements Closeable {
private final Map<Msg, Message> messages;
public Locale(Plan plugin) {
LocaleHolder.setLOCALE(this);
LocaleHolder.setLocale(this);
this.plugin = plugin;
messages = new HashMap<>();
}
@ -62,9 +62,9 @@ public class Locale implements Closeable {
}
} catch (IOException e) {
Log.toLog(this.getClass().getName(), e);
} finally {
Benchmark.stop("Enable", "Initializing locale");
}
Benchmark.stop("Enable", "Initializing locale");
}
private void writeNewDefaultLocale() throws IOException {
@ -316,25 +316,24 @@ public class Locale implements Closeable {
}
public Message getMessage(Msg msg) {
Message message = messages.get(msg);
return message != null ? message : new Message("");
return messages.getOrDefault(msg, new Message(""));
}
@Override
public void close() {
messages.clear();
LocaleHolder.LOCALE = null;
LocaleHolder.locale = null;
}
public static void unload() {
Locale locale = LocaleHolder.getLOCALE();
Locale locale = LocaleHolder.getLocale();
if (locale != null) {
locale.close();
}
}
public static Message get(Msg msg) {
Locale locale = LocaleHolder.getLOCALE();
Locale locale = LocaleHolder.getLocale();
if (locale == null) {
throw new IllegalStateException("Locale has not been initialized.");
}
@ -343,14 +342,14 @@ public class Locale implements Closeable {
private static class LocaleHolder {
private static Locale LOCALE;
private static Locale locale;
public static void setLOCALE(Locale LOCALE) {
LocaleHolder.LOCALE = LOCALE;
public static void setLocale(Locale locale) {
LocaleHolder.locale = locale;
}
public static Locale getLOCALE() {
return LOCALE;
public static Locale getLocale() {
return locale;
}
}
}

View File

@ -84,12 +84,12 @@ public class TextUI {
final TPSPart tps = d.getTpsPart();
return new String[]{
ball + " Total Players: " + sec + count.getPlayerCount(),
//
ball + " Active: " + sec + activity.getActive().size()
+ main + " Inactive: " + sec + activity.getInactive().size()
+ main + " Single Join: " + sec + activity.getJoinedOnce().size()
+ main + " Banned: " + sec + activity.getBans().size(),
//
ball + " New Players 24h: " + sec + join.get("npday") + main + " 7d: " + sec + d.get("npweek") + main + " 30d: " + sec + d.get("npmonth"),
"",
ball + " Total Playtime: " + sec + playtime.get("totalplaytime") + main + " Player Avg: " + sec + playtime.get("avgplaytime"),

View File

@ -167,7 +167,7 @@ public class Analysis {
PageCacheHandler.cachePage("analysisPage", () -> new AnalysisPageResponse(plugin.getUiServer().getDataReqHandler()));
PageCacheHandler.cachePage("players", () -> new PlayersPageResponse(plugin));
ExportUtility.export(plugin, analysisData, rawData);
ExportUtility.export(analysisData, rawData);
} catch (Exception e) {
Log.toLog(this.getClass().getName(), e);
plugin.processStatus().setStatus("Analysis", "Error: " + e);

View File

@ -54,27 +54,31 @@ public class ExportUtility {
}
/**
* @param plugin
* @param analysisData
* @param rawData
*/
public static void export(Plan plugin, AnalysisData analysisData, List<UserData> rawData) {
public static void export(AnalysisData analysisData, List<UserData> rawData) {
if (!Settings.ANALYSIS_EXPORT.isTrue()) {
return;
}
Benchmark.start("Exporting Html pages");
try {
File folder = getFolder();
Log.debug("Export", "Folder: " + folder.getAbsolutePath());
writePlayersPageHtml(rawData, new File(folder, "players"));
writeAnalysisHtml(analysisData, new File(folder, "server"));
File playersFolder = getPlayersFolder(folder);
Log.debug("Export", "Player html files.");
Log.debug("Export", "Player Page Folder: " + playersFolder.getAbsolutePath());
String playerHtml = HtmlUtils.getStringFromResource("player.html");
rawData.forEach(userData -> {
writeInspectHtml(userData, playersFolder, playerHtml);
});
Benchmark.start("Exporting Player pages");
rawData.forEach(userData -> writeInspectHtml(userData, playersFolder, playerHtml));
Benchmark.stop("Exporting Player pages");
} catch (IOException ex) {
Log.toLog("ExportUtils.export", ex);
} finally {
@ -96,17 +100,18 @@ public class ExportUtility {
/**
* @param userData
* @param playersFolder
* @throws FileNotFoundException
* @throws IOException
*/
public static boolean writeInspectHtml(UserData userData, File playersFolder, String playerHtml) {
public static void writeInspectHtml(UserData userData, File playersFolder, String playerHtml) {
if (!Settings.ANALYSIS_EXPORT.isTrue()) {
return false;
return;
}
String name = userData.getName();
if (name.endsWith(".")) {
name = name.replace(".", "%2E");
}
if (name.endsWith(" ")) {
name = name.replace(" ", "%20");
}
@ -114,16 +119,17 @@ public class ExportUtility {
try {
String inspectHtml = HtmlUtils.replacePlaceholders(playerHtml,
PlaceholderUtils.getInspectReplaceRules(userData));
File playerFolder = new File(playersFolder, name);
playerFolder.mkdirs();
File inspectHtmlFile = new File(playerFolder, "index.html");
inspectHtmlFile.createNewFile();
Files.write(inspectHtmlFile.toPath(), Collections.singletonList(inspectHtml));
} catch (IOException e) {
Log.toLog("Export.inspectPage: " + name, e);
return false;
Log.toLog("Export.writeInspectHtml: " + name, e);
}
return true;
}
/**

View File

@ -1,5 +1,7 @@
package main.java.com.djrapitops.plan.utilities.file.dump;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableList;
import main.java.com.djrapitops.plan.Log;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
@ -21,7 +23,7 @@ import java.util.List;
*/
public class DumpLog {
private List<CharSequence> lines = new ArrayList<>();
private final List<CharSequence> lines = new ArrayList<>();
/**
* Writes a header
@ -88,6 +90,11 @@ public class DumpLog {
* @param line The content of the line
*/
private void addLine(CharSequence line) {
if (line == null) {
lines.add("\n");
return;
}
lines.add(line.toString());
}
@ -97,7 +104,27 @@ public class DumpLog {
* @return The link to the Dump Log
*/
String upload() {
String content = this.toString();
List<String> parts = ImmutableList.copyOf(split()).reverse();
String lastLink = null;
for (String part : parts) {
if (lastLink != null) {
part += "\n" + lastLink;
}
lastLink = upload(part);
}
return lastLink;
}
/**
* Uploads the content to Hastebin using HTTPS and POST
*
* @param content The content
* @return The link to the content
*/
private String upload(String content) {
HttpsURLConnection connection = null;
try {
URL url = new URL("https://hastebin.com/documents");
@ -111,13 +138,16 @@ public class DumpLog {
connection.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
wr.writeBytes(this.toString());
wr.writeBytes(content);
wr.flush();
wr.close();
BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream()));
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String response = reader.readLine();
JSONParser parser = new JSONParser();
JSONObject json = (JSONObject) parser.parse(rd.readLine());
JSONObject json = (JSONObject) parser.parse(response);
return "https://hastebin.com/" + json.get("key");
} catch (IOException | ParseException e) {
@ -130,6 +160,15 @@ public class DumpLog {
}
}
/**
* Splits the content of the DumpLog into parts
*
* @return The splitted content
*/
private Iterable<String> split() {
return Splitter.fixedLength(390000).split(this.toString());
}
@Override
public String toString() {
return String.join("\n", lines);

View File

@ -741,12 +741,12 @@
function openFunc(i) {
return function() {
if (window.getComputedStyle(document.getElementById("navbutton")).getPropertyValue('display') == "inline") {
if (window.getComputedStyle(document.getElementById("navbutton")).getPropertyValue('display') === "inline") {
closeNav();
}
var max = navButtons.length;
for (var j = 0; j < max; j++) {
if (j == i) {
if (j === i) {
navButtons[j].classList.add('active');
continue;
}
@ -770,9 +770,7 @@
var begin = new Date(%refreshlong%);
var seconds = now.getTime() - begin.getTime();
var out = formatTime(seconds);
document.getElementById('divTime').innerHTML = out;
document.getElementById('divTime').innerHTML = formatTime(seconds);
setTimeout('countUpTimer()', 1000);
}
</script>

View File

@ -16,7 +16,6 @@ import org.bukkit.entity.Player;
import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.HashSet;
@ -154,7 +153,7 @@ public class MockUtils {
return PowerMockito.mock(CommandSender.class);
}
public static HttpServer mockHTTPServer() throws IOException {
public static HttpServer mockHTTPServer() {
HttpServer httpServer = PowerMockito.mock(HttpServer.class);
when(httpServer.getAddress()).thenReturn(new InetSocketAddress(80));
when(httpServer.getExecutor()).thenReturn(command -> System.out.println("HTTP Server command received"));