mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-24 00:51:25 +01:00
Kingdoms & Kingdoms+ support #371
This commit is contained in:
parent
1765819b14
commit
46ea5ccc6e
@ -8,6 +8,7 @@ import com.djrapitops.pluginbridge.plan.essentials.EssentialsHook;
|
||||
import com.djrapitops.pluginbridge.plan.factions.FactionsHook;
|
||||
import com.djrapitops.pluginbridge.plan.griefprevention.GriefPreventionHook;
|
||||
import com.djrapitops.pluginbridge.plan.jobs.JobsHook;
|
||||
import com.djrapitops.pluginbridge.plan.kingdoms.KingdomsHook;
|
||||
import com.djrapitops.pluginbridge.plan.litebans.LiteBansHook;
|
||||
import com.djrapitops.pluginbridge.plan.mcmmo.McmmoHook;
|
||||
import com.djrapitops.pluginbridge.plan.protocolsupport.ProtocolSupportHook;
|
||||
@ -30,6 +31,7 @@ import main.java.com.djrapitops.plan.data.additional.HookHandler;
|
||||
* @see FactionsHook
|
||||
* @see GriefPreventionHook
|
||||
* @see JobsHook
|
||||
* @see KingdomsHook
|
||||
* @see LiteBansHook
|
||||
* @see McmmoHook
|
||||
* @see SuperbVoteHook
|
||||
@ -55,6 +57,7 @@ public class Bridge {
|
||||
new FactionsHook(h),
|
||||
new GriefPreventionHook(h),
|
||||
new JobsHook(h),
|
||||
new KingdomsHook(h),
|
||||
new LiteBansHook(h),
|
||||
new McmmoHook(h),
|
||||
new SuperbVoteHook(h),
|
||||
|
@ -0,0 +1,98 @@
|
||||
/*
|
||||
* 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 com.djrapitops.pluginbridge.plan.kingdoms;
|
||||
|
||||
import main.java.com.djrapitops.plan.data.PlayerProfile;
|
||||
import main.java.com.djrapitops.plan.data.ServerProfile;
|
||||
import main.java.com.djrapitops.plan.data.Session;
|
||||
import main.java.com.djrapitops.plan.utilities.analysis.Analysis;
|
||||
import main.java.com.djrapitops.plan.utilities.html.HtmlStructure;
|
||||
import org.kingdoms.constants.kingdom.OfflineKingdom;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Creates a Town Accordion for Towny tab.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class KingdomAccordionCreator {
|
||||
|
||||
public static String createAccordion(Map<String, OfflineKingdom> kingdoms) {
|
||||
StringBuilder html = new StringBuilder("<div class=\"panel-group scrollbar\" id=\"towny_accordion\" role=\"tablist\" aria-multiselectable=\"true\">");
|
||||
|
||||
ServerProfile serverProfile = Analysis.getServerProfile();
|
||||
List<PlayerProfile> players = serverProfile != null ? serverProfile.getPlayers() : new ArrayList<>();
|
||||
|
||||
for (Map.Entry<String, OfflineKingdom> entry : kingdoms.entrySet()) {
|
||||
String kingdomName = entry.getKey();
|
||||
|
||||
OfflineKingdom kingdom = entry.getValue();
|
||||
String kingName = kingdom.getKingName();
|
||||
String kingdomLore = kingdom.getKingdomLore();
|
||||
|
||||
int might = kingdom.getMight();
|
||||
int resourcePoints = kingdom.getResourcepoints();
|
||||
|
||||
List<UUID> members = kingdom.getMembersList();
|
||||
int residentsNum = members.size();
|
||||
|
||||
List<PlayerProfile> memberProfiles = players.stream().filter(p -> members.contains(p.getUniqueId())).collect(Collectors.toList());
|
||||
|
||||
List<Session> sessions = memberProfiles.stream()
|
||||
.map(PlayerProfile::getSessions)
|
||||
.map(Map::values)
|
||||
.flatMap(Collection::stream)
|
||||
.flatMap(Collection::stream)
|
||||
.collect(Collectors.toList());
|
||||
long playerKills = ServerProfile.getPlayerKills(sessions).size();
|
||||
long mobKills = ServerProfile.getMobKillCount(sessions);
|
||||
long deaths = ServerProfile.getDeathCount(sessions);
|
||||
|
||||
String separated = HtmlStructure.separateWithDots(String.valueOf(residentsNum), kingName);
|
||||
|
||||
String htmlID = "kingdom_" + kingdomName.replace(" ", "-");
|
||||
|
||||
// Accordion panel header
|
||||
html.append("<div class=\"panel panel-col-amber\">")
|
||||
.append("<div class=\"panel-heading\" role=\"tab\" id=\"heading_").append(htmlID).append("\">")
|
||||
.append("<h4 class=\"panel-title\">")
|
||||
.append("<a class=\"collapsed\" role=\"button\" data-toggle=\"collapse\" data-parent=\"#session_accordion\" ")
|
||||
.append("href=\"#session_").append(htmlID).append("\" aria-expanded=\"false\" ")
|
||||
.append("aria-controls=\"session_").append(htmlID).append("\">")
|
||||
.append(kingdomName).append("<span class=\"pull-right\">").append(separated).append("</span>") // Title (header)
|
||||
.append("</a></h4>") // Closes collapsed, panel title
|
||||
.append("</div>"); // Closes panel heading
|
||||
|
||||
// Content
|
||||
html.append("<div id=\"session_").append(htmlID).append("\" class=\"panel-collapse collapse\" role=\"tabpanel\"")
|
||||
.append(" aria-labelledby=\"heading_").append(htmlID).append("\">")
|
||||
.append("<div class=\"panel-body\"><div class=\"row clearfix\">")
|
||||
.append("<div class=\"col-xs-12 col-sm-6 col-md-6 col-lg-6\">") // Left col-6
|
||||
// Lore
|
||||
.append("<p>").append(kingdomLore).append("</p>")
|
||||
.append("<p><i class=\"col-amber fa fa-user\"></i> Mayor <span class=\"pull-right\">").append(kingName).append("</span></p>")
|
||||
// Playtime
|
||||
.append("<p><i class=\"col-amber fa fa-users\"></i> Members<span class=\"pull-right\"><b>").append(residentsNum).append("</b></span></p>")
|
||||
.append("<p><i class=\"col-amber fa fa-bolt\"></i> Might<span class=\"pull-right\"><b>").append(might).append("</b></span></p>")
|
||||
.append("<p><i class=\"col-amber fa fa-cubes\"></i> Resources<span class=\"pull-right\"><b>").append(resourcePoints).append("</b></span></p>")
|
||||
.append("</div>") // Closes Left col-6
|
||||
.append("<div class=\"col-xs-12 col-sm-6 col-md-6 col-lg-6\">") // Right col-6
|
||||
// Player Kills
|
||||
.append("<p><i class=\"col-red fa fa-crosshairs\"></i> Player Kills<span class=\"pull-right\"><b>").append(playerKills).append("</b></span></p>")
|
||||
.append("<p><i class=\"col-green fa fa-crosshairs\"></i> Mob Kills<span class=\"pull-right\"><b>").append(mobKills).append("</b></span></p>")
|
||||
// Deaths
|
||||
.append("<p><i class=\"col-red fa fa-frown-o\"></i> Deaths<span class=\"pull-right\"><b>").append(deaths).append("</b></span></p>")
|
||||
.append("</div>") // Right col-6
|
||||
.append("</div>") // Closes row clearfix
|
||||
.append("</div>") // Closes panel-body
|
||||
.append("</div>") // Closes panel-collapse
|
||||
.append("</div>"); // Closes panel
|
||||
}
|
||||
return html.append("</div>").toString();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* 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 com.djrapitops.pluginbridge.plan.kingdoms;
|
||||
|
||||
import main.java.com.djrapitops.plan.Plan;
|
||||
import main.java.com.djrapitops.plan.data.additional.AnalysisContainer;
|
||||
import main.java.com.djrapitops.plan.data.additional.ContainerSize;
|
||||
import main.java.com.djrapitops.plan.data.additional.InspectContainer;
|
||||
import main.java.com.djrapitops.plan.data.additional.PluginData;
|
||||
import main.java.com.djrapitops.plan.utilities.html.Html;
|
||||
import org.kingdoms.constants.kingdom.OfflineKingdom;
|
||||
import org.kingdoms.constants.player.OfflineKingdomPlayer;
|
||||
import org.kingdoms.manager.game.GameManagement;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* PluginData for Kingdoms and Kingdoms+ plugins.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class KingdomsData extends PluginData {
|
||||
|
||||
public KingdomsData() {
|
||||
super(ContainerSize.TAB, "Kingdoms");
|
||||
super.setIconColor("amber");
|
||||
super.setPluginIcon("shield");
|
||||
}
|
||||
|
||||
@Override
|
||||
public InspectContainer getPlayerData(UUID uuid, InspectContainer inspectContainer) throws Exception {
|
||||
OfflineKingdomPlayer kingdomPlayer = GameManagement.getPlayerManager().getOfflineKingdomPlayer(uuid);
|
||||
String kingdomName = kingdomPlayer.getKingdomName();
|
||||
|
||||
if (kingdomName == null) {
|
||||
inspectContainer.addValue(getWithIcon("Kingdom", "shield", "amber"), "No Kingdom");
|
||||
} else {
|
||||
OfflineKingdom kingdom = GameManagement.getKingdomManager().getOfflineKingdom(kingdomName);
|
||||
if (kingdom != null) {
|
||||
String king = kingdom.getKingName();
|
||||
String link = Html.LINK.parse(Plan.getPlanAPI().getPlayerInspectPageLink(king), king);
|
||||
inspectContainer.addValue(getWithIcon("Kingdom", "shield", "amber"), kingdomName);
|
||||
inspectContainer.addValue(" " + getWithIcon("King", "user", "amber"), link);
|
||||
}
|
||||
}
|
||||
|
||||
return inspectContainer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AnalysisContainer getServerData(Collection<UUID> collection, AnalysisContainer analysisContainer) throws Exception {
|
||||
Map<String, OfflineKingdom> kingdoms = GameManagement.getKingdomManager().getKingdomList();
|
||||
|
||||
analysisContainer.addValue(getWithIcon("Kingdoms", "shield", "amber"), kingdoms.size());
|
||||
analysisContainer.addHtml("kingdomsAccordion", KingdomAccordionCreator.createAccordion(kingdoms));
|
||||
|
||||
Map<UUID, String> userKingDoms = new HashMap<>();
|
||||
for (Map.Entry<String, OfflineKingdom> entry : kingdoms.entrySet()) {
|
||||
String kingdom = entry.getKey();
|
||||
for (UUID member : entry.getValue().getMembersList()) {
|
||||
userKingDoms.put(member, kingdom);
|
||||
}
|
||||
}
|
||||
analysisContainer.addPlayerTableValues(getWithIcon("Kingdom", "shield"), userKingDoms);
|
||||
|
||||
return analysisContainer;
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* 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 com.djrapitops.pluginbridge.plan.kingdoms;
|
||||
|
||||
import com.djrapitops.pluginbridge.plan.Hook;
|
||||
import main.java.com.djrapitops.plan.data.additional.HookHandler;
|
||||
|
||||
/**
|
||||
* Hook for Kingdoms and Kingdoms+ plugins.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class KingdomsHook extends Hook {
|
||||
public KingdomsHook(HookHandler hookHandler) {
|
||||
super("org.kingdoms.main.Kingdoms", hookHandler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hook() throws NoClassDefFoundError {
|
||||
if (!enabled) {
|
||||
return;
|
||||
}
|
||||
addPluginDataSource(new KingdomsData());
|
||||
}
|
||||
}
|
@ -91,7 +91,7 @@ public class TownAccordionCreator {
|
||||
// Playtime
|
||||
.append("<p><i class=\"col-brown fa fa-users\"></i> Residents<span class=\"pull-right\"><b>").append(residentsNum).append("</b></span></p>")
|
||||
.append("<p><i class=\"col-brown fa fa-map\"></i> Town Blocks<span class=\"pull-right\"><b>").append(landCount).append("</b></span></p>")
|
||||
.append("<p><i class=\"col-brown fa fa-map-pin\"></i> Members<span class=\"pull-right\"><b>").append(coordinates).append("</b></span></p>")
|
||||
.append("<p><i class=\"col-brown fa fa-map-pin\"></i> Location<span class=\"pull-right\"><b>").append(coordinates).append("</b></span></p>")
|
||||
.append("</div>") // Closes Left col-6
|
||||
.append("<div class=\"col-xs-12 col-sm-6 col-md-6 col-lg-6\">") // Right col-6
|
||||
// Player Kills
|
||||
|
Loading…
Reference in New Issue
Block a user