Finished PlanLite features, partial fix to Demographics

- PlanLite features done.

Fixed bugs:
- Demographics data is not properly detected (partial fix)
-> Geolocation untested.

Known bugs:
- MapComparator compares values as strings (causes wrong order)
- Graph is wrong way around
- Graph is written to points with no data present
- (Player activity graph data might not be properly saved)
-> Graph uses players from a single point and draws a line

Other:
- (MySQL not tested)
- new API unimplemented
This commit is contained in:
Rsl1122 2017-01-15 21:29:40 +02:00
parent 2a76db770e
commit 5108213df6
7 changed files with 128 additions and 97 deletions

View File

@ -69,4 +69,20 @@ public class PlanLiteHook {
public boolean passCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
return planLite.getPlanCommand().onCommand(sender, cmd, commandLabel, args);
}
public boolean hasTowny() {
return getEnabledHooksNames().contains("Towny");
}
public boolean hasFactions() {
return getEnabledHooksNames().contains("Factions");
}
public boolean hasSuperbVote() {
return getEnabledHooksNames().contains("SuperbVote");
}
public boolean hasVault() {
return getEnabledHooksNames().contains("Vault");
}
}

View File

@ -44,14 +44,12 @@ public class DemographicsHandler {
List<String> triggers = Arrays.asList("i\'m", "am", "im");
List<String> female = Arrays.asList("female", "girl", "gurl", "woman", "gal", "mrs", "she", "miss");
List<String> male = Arrays.asList("male", "boy", "man", "boe", "sir", "mr", "guy", "he");
List<String> ages = Arrays.asList("years", "year-old", "old");
List<String> ignore = Arrays.asList("sure", "think", "with", "are");
String message = event.getMessage();
String[] messageA = message.split("\\s+");
String[] messageA = message.toLowerCase().split("\\s+");
boolean trigger = false;
boolean age = false;
boolean gender = false;
// Does message contain important data?
@ -63,9 +61,6 @@ public class DemographicsHandler {
if (triggers.contains(string)) {
trigger = true;
}
if (ages.contains(string)) {
age = true;
}
if (female.contains(string) || male.contains(string)) {
gender = true;
}
@ -77,20 +72,18 @@ public class DemographicsHandler {
}
// Manage important data
if (age) {
int ageNum = -1;
for (String string : messageA) {
try {
ageNum = Integer.parseInt(string);
if (ageNum != -1) {
break;
}
} catch (Exception e) {
int ageNum = -1;
for (String string : messageA) {
try {
ageNum = Integer.parseInt(string);
if (ageNum != -1) {
break;
}
} catch (Exception e) {
}
if (ageNum != -1 && ageNum < 100) {
data.getDemData().setAge(ageNum);
}
}
if (ageNum != -1 && ageNum < 100) {
data.getDemData().setAge(ageNum);
}
if (gender) {
for (String string : messageA) {
@ -114,22 +107,21 @@ public class DemographicsHandler {
*/
public void handleLogin(PlayerJoinEvent event, UserData data) {
InetAddress address = event.getPlayer().getAddress().getAddress();
Plan plugin = getPlugin(Plan.class);
try {
Scanner locationScanner = new Scanner("http://ip-api.com/line/" + address.getHostAddress());
List<String> results = new ArrayList<>();
Scanner locationScanner = new Scanner("http://freegeoip.net/csv/" + address.getHostAddress());
String result = "";
while (locationScanner.hasNextLine()) {
results.add(locationScanner.nextLine());
result = locationScanner.nextLine();
}
if (results.size() >= 2) {
data.getDemData().setGeoLocation(results.get(1));
String[] results = result.split(",");
if (!result.isEmpty()) {
data.getDemData().setGeoLocation(results[2]);
} else {
data.getDemData().setGeoLocation("Not Known");
}
} catch (Exception e) {
Plan plugin = getPlugin(Plan.class);
plugin.logToFile("http://ip-api.com/line/" + address.getHostAddress());
plugin.logToFile("" + e);
plugin.logToFile(address.toString());
}
}
}

View File

@ -197,7 +197,7 @@ public class Analysis {
break;
}
if (sData != null) {
data.setTop50CommandsListHtml(AnalysisUtils.createCommandUseListHtml(sData.getCommandUsage()));
data.setTop50CommandsListHtml(AnalysisUtils.createTableOutOfHashMap(sData.getCommandUsage()));
}
} else {
data.setTop50CommandsListHtml("<p>Error Calcuclating Command usages (No usage data)</p>");

View File

@ -1,6 +1,7 @@
package com.djrapitops.plan.utilities;
import com.djrapitops.plan.Plan;
import com.djrapitops.plan.PlanLiteHook;
import com.djrapitops.plan.data.AnalysisData;
import com.djrapitops.plan.data.ServerData;
import com.djrapitops.plan.data.UserData;
@ -9,7 +10,9 @@ import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Scanner;
import main.java.com.djrapitops.plan.data.PlanLiteAnalyzedData;
import main.java.com.djrapitops.plan.data.PlanLitePlayerData;
import main.java.com.djrapitops.plan.ui.graphs.ActivityPieChartCreator;
import main.java.com.djrapitops.plan.ui.graphs.PlayerActivityGraphCreator;
import main.java.com.djrapitops.plan.utilities.comparators.MapComparator;
@ -64,6 +67,8 @@ public class AnalysisUtils {
replaceMap.put("%playtime%", FormatUtils.formatTimeAmount("" + data.getPlayTime()));
replaceMap.put("%banned%", data.isBanned() ? "Banned" : "Not Banned");
replaceMap.put("%op%", data.isOp() ? ", Operator (Op)" : "");
PlanLiteHook hook = getPlugin(Plan.class).getPlanLiteHook();
replaceMap.put("%planlite%", hook.isEnabled() ? getPlanLitePlayerHtml(data.getPlanLiteData()) : "");
return replaceMap;
}
@ -94,12 +99,8 @@ public class AnalysisUtils {
replaceMap.put("%ops%", "" + data.getOps());
replaceMap.put("%refresh%", FormatUtils.formatTimeAmountSinceString("" + data.getRefreshDate(), new Date()));
replaceMap.put("%totallogins%", "" + data.getTotalLoginTimes());
if (data.isPlanLiteEnabled()) {
replaceMap.put("%planlite%", getPlanLiteAnalysisHtml(data.getPlanLiteData()));
} else {
replaceMap.put("%planlite%", "");
}
PlanLiteHook hook = getPlugin(Plan.class).getPlanLiteHook();
replaceMap.put("%planlite%", hook.isEnabled() ? getPlanLiteAnalysisHtml(data.getPlanLiteData()) : "");
return replaceMap;
}
@ -122,8 +123,12 @@ public class AnalysisUtils {
return "<img src=\"" + url + "\">";
}
static String createCommandUseListHtml(HashMap<String, Integer> commandUse) {
List<String[]> sorted = MapComparator.sortByValue(commandUse);
static String createTableOutOfHashMap(HashMap<String, Integer> commandUse) {
return createTableOutOfHashMap(commandUse, 50);
}
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>";
@ -143,47 +148,57 @@ public class AnalysisUtils {
}
private static String getPlanLiteAnalysisHtml(PlanLiteAnalyzedData planLiteData) {
List<String[]> sortedTowns = MapComparator.sortByValue(planLiteData.getTownMap());
Collections.reverse(sortedTowns);
List<String[]> sortedFactions = MapComparator.sortByValue(planLiteData.getFactionMap());
Collections.reverse(sortedFactions);
String html = "<tr>"
+ "<td style=\"margin-left: 3px; margin-right: auto; "
+ "border-style: groove; border-width: 3px; border-radius: 12px; padding: 2px 4px 2px 3px; "
+ "box-shadow: 5px 5px 4px 0px #888888;\">";
if (sortedTowns.size() > 1) {
html += "<table style=\"border-collapse: collapse;table-layout: fixed; border-style: solid; border-width: 1px; width: 100%;\">";
int i = 1;
for (String[] values : sortedTowns) {
if (i >= 20) {
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>";
i++;
}
html += "</table>";
Scanner scanner = new Scanner(getPlugin(Plan.class).getResource("planlite.html"));
String html = "";
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
html += line + "\r\n";
}
html += "<table style=\"border-collapse: collapse;table-layout: fixed; border-style: solid; border-width: 1px; width: 100%;\">";
int j = 1;
for (String[] values : sortedFactions) {
if (j >= 20) {
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>";
j++;
HashMap<String, String> replaceMap = getPlanLiteAnalysisReplaceRules(planLiteData);
for (String key : replaceMap.keySet()) {
html = html.replaceAll(key, replaceMap.get(key));
}
html += "</table></tr>" + "<tr>"
+ "<td style=\"margin-left: 3px; margin-right: auto; "
+ "border-style: groove; border-width: 3px; border-radius: 12px; padding: 2px 4px 2px 3px;"
+ "box-shadow: 5px 5px 4px 0px #888888;\">"
+ "<h4>Information</h4>"
+ "<p>Total Money on the server: " + planLiteData.getTotalMoney() + "<br/>Players have voted the server "
+ planLiteData.getTotalVotes() + " times.</p>"
+ "</td>";
html += "</tr>";
return html;
}
private static HashMap<String, String> getPlanLiteAnalysisReplaceRules(PlanLiteAnalyzedData planLiteData) {
HashMap<String, String> replaceMap = new HashMap<>();
PlanLiteHook hook = getPlugin(Plan.class).getPlanLiteHook();
replaceMap.put("%townyheader%", hook.hasTowny() ? "<p>Top 20 Towns</p>" : "");
replaceMap.put("%townylist%", hook.hasTowny() ? createTableOutOfHashMap(planLiteData.getTownMap(), 20) : "");
replaceMap.put("%factionheader%", hook.hasFactions() ? "<p>Top 20 Factions</p>" : "");
replaceMap.put("%factionlist%", hook.hasFactions() ? createTableOutOfHashMap(planLiteData.getFactionMap(), 20) : "");
replaceMap.put("%totalmoneyline%", hook.hasVault() ? "<p>Server Total Balance: " + planLiteData.getTotalMoney() + "</p>" : "");
replaceMap.put("%totalvotesline%", hook.hasSuperbVote() ? "<p>Players have voted total of " + planLiteData.getTotalVotes() + " times.</p>" : "");
return replaceMap;
}
private static String getPlanLitePlayerHtml(PlanLitePlayerData planLiteData) {
Scanner scanner = new Scanner(getPlugin(Plan.class).getResource("planliteplayer.html"));
String html = "";
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
html += line + "\r\n";
}
HashMap<String, String> replaceMap = getPlanLitePlayerReplaceRules(planLiteData);
for (String key : replaceMap.keySet()) {
html = html.replaceAll(key, replaceMap.get(key));
}
return html;
}
private static HashMap<String, String> getPlanLitePlayerReplaceRules(PlanLitePlayerData planLiteData) {
HashMap<String, String> replaceMap = new HashMap<>();
PlanLiteHook hook = getPlugin(Plan.class).getPlanLiteHook();
replaceMap.put("%townylinetown%", hook.hasTowny() ? "<p>Town: "+planLiteData.getTown()+"</p>" : "");
replaceMap.put("%townylineplotperms%", "");
replaceMap.put("%townylineplotoptions%", hook.hasTowny() ? "<p>Plot options: "+planLiteData.getPlotOptions()+"</p>" : "");
replaceMap.put("%townylinefriends%", hook.hasTowny() ? "<p>Friends with "+planLiteData.getFriends()+"</p>" : "");
replaceMap.put("%factionsline%", hook.hasFactions() ? "<p>Faction: "+planLiteData.getFaction()+"</p>" : "");
replaceMap.put("%totalmoneyline%", hook.hasVault() ? "<p>Balance: "+planLiteData.getMoney()+"</p>" : "");
replaceMap.put("%totalvotesline%", hook.hasSuperbVote() ? "<p>Player has voted " + planLiteData.getVotes()+ " times.</p>" : "");
return replaceMap;
}
}

View File

@ -1,22 +1,16 @@
<!doctype html>
<head></head>
<body>
<table>
<tr>
<td style="margin-left: 3px; margin-right: auto;border-style: groove; border-width: 3px;
border-radius: 12px; padding: 2px 4px 2px 3px; box-shadow: 5px 5px 4px 0px #888888;">
<p>%townyheader%</p>
<p>%townylist%</p>
<br/>
<p>%factionheader%</p>
<p>%factionlist%</p>
</td>
<td style="margin-left: 3px; margin-right: auto;border-style: groove; border-width: 3px;
border-radius: 12px; padding: 2px 4px 2px 3px; box-shadow: 5px 5px 4px 0px #888888;">
<h4>Information from PlanLite</h4>
<p>%totalmoneyline%</p>
<p>%totalvotesline%</p>
</td>
</tr>
</table>
</body>
<tr>
<td style="margin-left: 3px; margin-right: auto;border-style: groove; border-width: 3px;
border-radius: 12px; padding: 2px 4px 2px 3px; box-shadow: 5px 5px 4px 0px #888888;">
<h4>Information from PlanLite</h4>
%totalmoneyline%
%totalvotesline%
</td>
<td style="margin-left: 3px; margin-right: auto;border-style: groove; border-width: 3px;
border-radius: 12px; padding: 2px 4px 2px 3px; box-shadow: 5px 5px 4px 0px #888888;">
%townyheader%
%townylist%
<br/>
%factionheader%
%factionlist%
</td>
</tr>

View File

@ -0,0 +1,13 @@
<tr>
<td style="margin-left: 3px; margin-right: auto;border-style: groove; border-width: 3px;
border-radius: 12px; padding: 2px 4px 2px 3px; box-shadow: 5px 5px 4px 0px #888888;">
<h4>Information from PlanLite</h4>
%totalmoneyline%
%totalvotesline%
%factionsline%
%townylinetown%
%townylineplotperms%
%townylineplotoptions%
%townylinefriends%
</td>
</tr>

View File

@ -24,7 +24,7 @@
border-style: groove; border-width: 3px; border-radius: 12px; padding: 2px 4px 2px 3px;
box-shadow: 5px 5px 4px 0px #888888;">
<h4>Information</h4>
<p>Last seen: %lastseen% - %active%</p>
<p>Last seen: %lastseen% %active%</p>
<p>Nicknames: %nicknames% | Has connected from ips: %ips%</p>
<p>Geolocation: %geoloc%</p>
<p>Playtime: %playtime%</p>
@ -39,6 +39,7 @@
<p>Survival: %gm0% | Creative: %gm1% | Adventure: %gm2% | Spectator: %gm3% | Total: %gmtotal%</p>
</td>
</tr>
%planlite%
</table>
</div>
</body>