diff --git a/Plan/src/main/java/com/djrapitops/plan/PlanLiteHook.java b/Plan/src/main/java/com/djrapitops/plan/PlanLiteHook.java index bf2341766..c5c714e73 100644 --- a/Plan/src/main/java/com/djrapitops/plan/PlanLiteHook.java +++ b/Plan/src/main/java/com/djrapitops/plan/PlanLiteHook.java @@ -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"); + } } diff --git a/Plan/src/main/java/com/djrapitops/plan/data/handlers/DemographicsHandler.java b/Plan/src/main/java/com/djrapitops/plan/data/handlers/DemographicsHandler.java index f9f3cd74e..daa691672 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/handlers/DemographicsHandler.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/handlers/DemographicsHandler.java @@ -44,14 +44,12 @@ public class DemographicsHandler { List triggers = Arrays.asList("i\'m", "am", "im"); List female = Arrays.asList("female", "girl", "gurl", "woman", "gal", "mrs", "she", "miss"); List male = Arrays.asList("male", "boy", "man", "boe", "sir", "mr", "guy", "he"); - List ages = Arrays.asList("years", "year-old", "old"); List 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 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()); + } } } diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/Analysis.java b/Plan/src/main/java/com/djrapitops/plan/utilities/Analysis.java index aa39204cf..28bde3c9b 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/Analysis.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/Analysis.java @@ -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("

Error Calcuclating Command usages (No usage data)

"); diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/AnalysisUtils.java b/Plan/src/main/java/com/djrapitops/plan/utilities/AnalysisUtils.java index 2ddbd12a2..b35c383ac 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/AnalysisUtils.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/AnalysisUtils.java @@ -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 ""; } - static String createCommandUseListHtml(HashMap commandUse) { - List sorted = MapComparator.sortByValue(commandUse); + static String createTableOutOfHashMap(HashMap commandUse) { + return createTableOutOfHashMap(commandUse, 50); + } + + static String createTableOutOfHashMap(HashMap map, int limit) { + List sorted = MapComparator.sortByValue(map); String html = ""; if (sorted.isEmpty()) { html = "

Error Calcuclating Command usages

"; @@ -143,47 +148,57 @@ public class AnalysisUtils { } private static String getPlanLiteAnalysisHtml(PlanLiteAnalyzedData planLiteData) { - List sortedTowns = MapComparator.sortByValue(planLiteData.getTownMap()); - Collections.reverse(sortedTowns); - List sortedFactions = MapComparator.sortByValue(planLiteData.getFactionMap()); - Collections.reverse(sortedFactions); - String html = "" - + "" + "" - + ""; - html += ""; return html; } + + private static HashMap getPlanLiteAnalysisReplaceRules(PlanLiteAnalyzedData planLiteData) { + HashMap replaceMap = new HashMap<>(); + PlanLiteHook hook = getPlugin(Plan.class).getPlanLiteHook(); + replaceMap.put("%townyheader%", hook.hasTowny() ? "

Top 20 Towns

" : ""); + replaceMap.put("%townylist%", hook.hasTowny() ? createTableOutOfHashMap(planLiteData.getTownMap(), 20) : ""); + replaceMap.put("%factionheader%", hook.hasFactions() ? "

Top 20 Factions

" : ""); + replaceMap.put("%factionlist%", hook.hasFactions() ? createTableOutOfHashMap(planLiteData.getFactionMap(), 20) : ""); + replaceMap.put("%totalmoneyline%", hook.hasVault() ? "

Server Total Balance: " + planLiteData.getTotalMoney() + "

" : ""); + replaceMap.put("%totalvotesline%", hook.hasSuperbVote() ? "

Players have voted total of " + planLiteData.getTotalVotes() + " times.

" : ""); + 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 replaceMap = getPlanLitePlayerReplaceRules(planLiteData); + for (String key : replaceMap.keySet()) { + html = html.replaceAll(key, replaceMap.get(key)); + } + return html; + } + + private static HashMap getPlanLitePlayerReplaceRules(PlanLitePlayerData planLiteData) { + HashMap replaceMap = new HashMap<>(); + PlanLiteHook hook = getPlugin(Plan.class).getPlanLiteHook(); + replaceMap.put("%townylinetown%", hook.hasTowny() ? "

Town: "+planLiteData.getTown()+"

" : ""); + replaceMap.put("%townylineplotperms%", ""); + replaceMap.put("%townylineplotoptions%", hook.hasTowny() ? "

Plot options: "+planLiteData.getPlotOptions()+"

" : ""); + replaceMap.put("%townylinefriends%", hook.hasTowny() ? "

Friends with "+planLiteData.getFriends()+"

" : ""); + replaceMap.put("%factionsline%", hook.hasFactions() ? "

Faction: "+planLiteData.getFaction()+"

" : ""); + replaceMap.put("%totalmoneyline%", hook.hasVault() ? "

Balance: "+planLiteData.getMoney()+"

" : ""); + replaceMap.put("%totalvotesline%", hook.hasSuperbVote() ? "

Player has voted " + planLiteData.getVotes()+ " times.

" : ""); + return replaceMap; + } } diff --git a/Plan/src/main/resources/planlite.html b/Plan/src/main/resources/planlite.html index 109369c26..93ec6dfc5 100644 --- a/Plan/src/main/resources/planlite.html +++ b/Plan/src/main/resources/planlite.html @@ -1,22 +1,16 @@ - - - -
"; - - if (sortedTowns.size() > 1) { - html += ""; - - int i = 1; - for (String[] values : sortedTowns) { - if (i >= 20) { - break; - } - html += "\r\n"; - i++; - } - html += "
" + values[1] + "" + values[0] + "
"; + Scanner scanner = new Scanner(getPlugin(Plan.class).getResource("planlite.html")); + String html = ""; + while (scanner.hasNextLine()) { + String line = scanner.nextLine(); + html += line + "\r\n"; } - html += ""; - int j = 1; - for (String[] values : sortedFactions) { - if (j >= 20) { - break; - } - html += "\r\n"; - j++; + HashMap replaceMap = getPlanLiteAnalysisReplaceRules(planLiteData); + for (String key : replaceMap.keySet()) { + html = html.replaceAll(key, replaceMap.get(key)); } - html += "
" + values[1] + "" + values[0] + "
" - + "

Information

" - + "

Total Money on the server: " + planLiteData.getTotalMoney() + "
Players have voted the server " - + planLiteData.getTotalVotes() + " times.

" - + "
- - - - -
-

%townyheader%

-

%townylist%

-
-

%factionheader%

-

%factionlist%

-
-

Information from PlanLite

-

%totalmoneyline%

-

%totalvotesline%

-
- \ No newline at end of file + + +

Information from PlanLite

+ %totalmoneyline% + %totalvotesline% + + + %townyheader% + %townylist% +
+ %factionheader% + %factionlist% + + \ No newline at end of file diff --git a/Plan/src/main/resources/planliteplayer.html b/Plan/src/main/resources/planliteplayer.html new file mode 100644 index 000000000..5614b938c --- /dev/null +++ b/Plan/src/main/resources/planliteplayer.html @@ -0,0 +1,13 @@ + + +

Information from PlanLite

+ %totalmoneyline% + %totalvotesline% + %factionsline% + %townylinetown% + %townylineplotperms% + %townylineplotoptions% + %townylinefriends% + + \ No newline at end of file diff --git a/Plan/src/main/resources/player.html b/Plan/src/main/resources/player.html index 6bb93d1ee..9fd0cd10c 100644 --- a/Plan/src/main/resources/player.html +++ b/Plan/src/main/resources/player.html @@ -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;">

Information

-

Last seen: %lastseen% - %active%

+

Last seen: %lastseen% %active%

Nicknames: %nicknames% | Has connected from ips: %ips%

Geolocation: %geoloc%

Playtime: %playtime%

@@ -39,6 +39,7 @@

Survival: %gm0% | Creative: %gm1% | Adventure: %gm2% | Spectator: %gm3% | Total: %gmtotal%

+ %planlite%