diff --git a/PlanPluginBridge/pom.xml b/PlanPluginBridge/pom.xml index 90547f22f..afa451298 100644 --- a/PlanPluginBridge/pom.xml +++ b/PlanPluginBridge/pom.xml @@ -149,6 +149,13 @@ 16.7.1 provided + + + net.kaikk.mc + GriefPreventionPlus + RELEASE + provided + litebans api diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/griefprevention/plus/GriefPreventionPlusData.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/griefprevention/plus/GriefPreventionPlusData.java new file mode 100644 index 000000000..37a14527e --- /dev/null +++ b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/griefprevention/plus/GriefPreventionPlusData.java @@ -0,0 +1,85 @@ +/* + * 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.griefprevention.plus; + +import com.djrapitops.plan.data.element.AnalysisContainer; +import com.djrapitops.plan.data.element.InspectContainer; +import com.djrapitops.plan.data.element.TableContainer; +import com.djrapitops.plan.data.plugin.ContainerSize; +import com.djrapitops.plan.data.plugin.PluginData; +import com.djrapitops.plan.utilities.analysis.MathUtils; +import com.djrapitops.plugin.utilities.FormatUtils; +import net.kaikk.mc.gpp.Claim; +import net.kaikk.mc.gpp.DataStore; +import net.kaikk.mc.gpp.PlayerData; + +import java.util.*; +import java.util.stream.Collectors; + +/** + * PluginData for GriefPreventionPlus plugin. + * + * @author Rsl1122 + */ +public class GriefPreventionPlusData extends PluginData { + + private final DataStore dataStore; + + public GriefPreventionPlusData(DataStore dataStore) { + super(ContainerSize.THIRD, "GriefPreventionPlus"); + super.setPluginIcon("shield"); + super.setIconColor("blue-grey"); + this.dataStore = dataStore; + } + + @Override + public InspectContainer getPlayerData(UUID uuid, InspectContainer inspectContainer) { + Map claims = dataStore.getClaims().values().stream() + .filter(Objects::nonNull) + .filter(claim -> uuid.equals(claim.getOwnerID())) + .collect(Collectors.toMap( + claim -> FormatUtils.formatLocation(claim.getGreaterBoundaryCorner()), + Claim::getArea) + ); + PlayerData data = dataStore.getPlayerData(uuid); + int blocks = data.getAccruedClaimBlocks() + data.getBonusClaimBlocks(); + long totalArea = MathUtils.sumLong(claims.values().stream().map(i -> (long) i)); + + inspectContainer.addValue(getWithIcon("Claims", "map-marker", "blue-grey"), claims.size()); + inspectContainer.addValue(getWithIcon("Claimed Area", "map-o", "light-green"), totalArea); + inspectContainer.addValue(getWithIcon("Claim Blocks Available", "map-o", "light-green"), blocks); + + TableContainer claimsTable = new TableContainer(getWithIcon("Claim", "map-marker"), getWithIcon("Area", "map-o")); + claimsTable.setColor("blue-grey"); + for (Map.Entry entry : claims.entrySet()) { + claimsTable.addRow(entry.getKey(), entry.getValue()); + } + inspectContainer.addTable("claimTable", claimsTable); + + return inspectContainer; + } + + @Override + public AnalysisContainer getServerData(Collection collection, AnalysisContainer analysisContainer) { + Map area = new HashMap<>(); + + for (Claim claim : dataStore.getClaims().values()) { + if (claim == null) { + continue; + } + UUID uuid = claim.getOwnerID(); + int blocks = area.getOrDefault(uuid, 0); + blocks += claim.getArea(); + area.put(uuid, blocks); + } + + long totalArea = MathUtils.sumLong(area.values().stream().map(i -> (long) i)); + analysisContainer.addValue(getWithIcon("Total Claimed Area", "map-o", "blue-grey"), totalArea); + + analysisContainer.addPlayerTableValues(getWithIcon("Claimed Area", "map-o"), area); + + return analysisContainer; + } +} \ No newline at end of file diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/griefprevention/plus/GriefPreventionPlusHook.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/griefprevention/plus/GriefPreventionPlusHook.java new file mode 100644 index 000000000..2596bdd42 --- /dev/null +++ b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/griefprevention/plus/GriefPreventionPlusHook.java @@ -0,0 +1,37 @@ +package com.djrapitops.pluginbridge.plan.griefprevention.plus; + +import com.djrapitops.plan.data.plugin.HookHandler; +import com.djrapitops.pluginbridge.plan.Hook; +import net.kaikk.mc.gpp.DataStore; +import net.kaikk.mc.gpp.GriefPreventionPlus; + +import static org.bukkit.plugin.java.JavaPlugin.getPlugin; + +/** + * A Class responsible for hooking to GriefPreventionPlus and registering data + * sources. + * + * @author Rsl1122 + * @since 3.5.0 + */ +public class GriefPreventionPlusHook extends Hook { + + /** + * Hooks the plugin and registers it's PluginData objects. + *

+ * API#addPluginDataSource uses the same method from HookHandler. + * + * @param hookH HookHandler instance for registering the data sources. + * @throws NoClassDefFoundError when the plugin class can not be found. + */ + public GriefPreventionPlusHook(HookHandler hookH) { + super("net.kaikk.mc.gpp.GriefPreventionPlus", hookH); + } + + public void hook() throws NoClassDefFoundError { + if (enabled) { + DataStore dataStore = getPlugin(GriefPreventionPlus.class).getDataStore(); + addPluginDataSource(new GriefPreventionPlusData(dataStore)); + } + } +}