diff --git a/Plan/src/main/java/com/djrapitops/plan/Plan.java b/Plan/src/main/java/com/djrapitops/plan/Plan.java index cadc28d14..6f01f9908 100644 --- a/Plan/src/main/java/com/djrapitops/plan/Plan.java +++ b/Plan/src/main/java/com/djrapitops/plan/Plan.java @@ -92,14 +92,7 @@ public class Plan extends RslPlugin<Plan> { Server server = getServer(); variable = new ServerVariableHolder(server); - - Log.debug("-------------------------------------"); - Log.debug("Debug log: Plan v." + getVersion()); - Log.debug("Implements RslPlugin v." + getRslVersion()); - Log.debug("Server: " + server.getBukkitVersion()); - Log.debug("Version: " + server.getVersion()); - Log.debug("-------------------------------------"); - + databases = new HashSet<>(); databases.add(new MySQLDB(this)); databases.add(new SQLiteDB(this)); @@ -147,7 +140,7 @@ public class Plan extends RslPlugin<Plan> { Log.infoColor(Phrase.NOTIFY_EMPTY_IP + ""); } - hookHandler = new HookHandler(); + hookHandler = new HookHandler(this); Log.debug("Verboose debug messages are enabled."); Log.info(Phrase.ENABLED + ""); @@ -162,17 +155,17 @@ public class Plan extends RslPlugin<Plan> { public void onDisable() { if (uiServer != null) { uiServer.stop(); - } + } Bukkit.getScheduler().cancelTasks(this); if (handler != null) { Log.info(Phrase.CACHE_SAVE + ""); ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); scheduler.execute(() -> { handler.saveCacheOnDisable(); + taskStatus().cancelAllKnownTasks(); }); - scheduler.shutdown(); - } + } Log.info(Phrase.DISABLED + ""); } diff --git a/Plan/src/main/java/com/djrapitops/plan/Settings.java b/Plan/src/main/java/com/djrapitops/plan/Settings.java index 7b2c12e67..716bbc706 100644 --- a/Plan/src/main/java/com/djrapitops/plan/Settings.java +++ b/Plan/src/main/java/com/djrapitops/plan/Settings.java @@ -27,14 +27,6 @@ public enum Settings { SECURITY_IP_UUID("Settings.WebServer.Security.DisplayIPsAndUUIDs"), GRAPH_PLAYERS_USEMAXPLAYERS_SCALE("Customization.Graphs.PlayersOnlineGraph.UseMaxPlayersAsScale"), PLAYERLIST_SHOW_IMAGES("Customization.SmallHeadImagesOnAnalysisPlayerlist"), - ENABLED_AA("Customization.Plugins.Enabled.AdvancedAchievements"), - ENABLED_ESS("Customization.Plugins.Enabled.Essentials"), - ENABLED_FAC("Customization.Plugins.Enabled.Factions"), - ENABLED_JOB("Customization.Plugins.Enabled.Jobs"), - ENABLED_MCM("Customization.Plugins.Enabled.McMMO"), - ENABLED_ONT("Customization.Plugins.Enabled.OnTime"), - ENABLED_TOW("Customization.Plugins.Enabled.Towny"), - ENABLED_VAU("Customization.Plugins.Enabled.Vault"), LINK_PROTOCOL("Settings.WebServer.LinkProtocol"), // Integer ANALYSIS_MINUTES_FOR_ACTIVE("Settings.Analysis.MinutesPlayedUntilConsidiredActive"), diff --git a/Plan/src/main/java/com/djrapitops/plan/data/additional/HookHandler.java b/Plan/src/main/java/com/djrapitops/plan/data/additional/HookHandler.java index 34941969c..c4ce454e5 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/additional/HookHandler.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/additional/HookHandler.java @@ -9,6 +9,7 @@ import java.util.Map; import java.util.UUID; import java.util.stream.Collectors; import main.java.com.djrapitops.plan.Log; +import main.java.com.djrapitops.plan.Plan; import main.java.com.djrapitops.plan.utilities.HtmlUtils; /** @@ -21,12 +22,16 @@ import main.java.com.djrapitops.plan.utilities.HtmlUtils; public class HookHandler { private List<PluginData> additionalDataSources; + private final PluginConfigSectionHandler configHandler; /** * Class constructor, hooks to plugins. + * + * @param plugin Current instance of plan. */ - public HookHandler() { + public HookHandler(Plan plugin) { additionalDataSources = new ArrayList<>(); + configHandler = new PluginConfigSectionHandler(plugin); try { Bridge.hook(this); } catch (Throwable e) { @@ -46,8 +51,18 @@ public class HookHandler { * @param dataSource an object extending the PluginData class. */ public void addPluginDataSource(PluginData dataSource) { - Log.debug("Registered a new datasource: " + dataSource.getPlaceholder("").replace("%", "")); - additionalDataSources.add(dataSource); + try { + if (!configHandler.hasSection(dataSource)) { + configHandler.createSection(dataSource); + } + if (configHandler.isEnabled(dataSource)) { + Log.debug("Registered a new datasource: " + dataSource.getPlaceholder("").replace("%", "")); + additionalDataSources.add(dataSource); + } + } catch (Exception e) { + Log.toLog(this.getClass().getName(), e); + Log.error("Attempting to register PluginDataSource caused an exception."); + } } /** diff --git a/Plan/src/main/java/com/djrapitops/plan/data/additional/PluginConfigSectionHandler.java b/Plan/src/main/java/com/djrapitops/plan/data/additional/PluginConfigSectionHandler.java new file mode 100644 index 000000000..60af2a164 --- /dev/null +++ b/Plan/src/main/java/com/djrapitops/plan/data/additional/PluginConfigSectionHandler.java @@ -0,0 +1,58 @@ +package main.java.com.djrapitops.plan.data.additional; + +import main.java.com.djrapitops.plan.Plan; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.file.FileConfiguration; + +/** + * Class responsible for generating and generating settings for PluginData + * objects to the config. + * + * @author Rsl1122 + * @since 3.5.0 + */ +public class PluginConfigSectionHandler { + + private final Plan plan; + + public PluginConfigSectionHandler(Plan plan) { + this.plan = plan; + } + + public boolean hasSection(PluginData dataSource) { + ConfigurationSection section = getPluginsSection(); + String pluginName = dataSource.getSourcePlugin(); + if (!section.contains(pluginName)) { + return false; + } + ConfigurationSection pluginSection = section.getConfigurationSection(pluginName); + return pluginSection.contains(dataSource.getPlaceholder("")); + } + + private ConfigurationSection getPluginsSection() { + FileConfiguration config = plan.getConfig(); + ConfigurationSection section = config.getConfigurationSection("Customization.Plugins"); + return section; + } + + public void createSection(PluginData dataSource) { + ConfigurationSection section = getPluginsSection(); + String pluginName = dataSource.getSourcePlugin(); + String source = dataSource.placeholder; + section.addDefault(pluginName + ".Enabled", true); + section.addDefault(pluginName + ".Data." + source, true); + FileConfiguration config = plan.getConfig(); + config.set("Customization.Plugins", section); + plan.saveConfig(); + } + + public boolean isEnabled(PluginData dataSource) { + ConfigurationSection section = getPluginsSection(); + String pluginName = dataSource.getSourcePlugin(); + if (!section.getBoolean(pluginName + ".Enabled")) { + return false; + } + String source = dataSource.placeholder; + return section.getBoolean(pluginName + ".Data." + source); + } +} diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/Analysis.java b/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/Analysis.java index 641050811..4571a405d 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/Analysis.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/Analysis.java @@ -394,7 +394,9 @@ public class Analysis { Benchmark.start("Analysis 3rd party"); final Map<String, String> replaceMap = new HashMap<>(); final HookHandler hookHandler = plugin.getHookHandler(); - final List<PluginData> sources = hookHandler.getAdditionalDataSources(); + final List<PluginData> sources = hookHandler.getAdditionalDataSources().stream() + .filter(p -> !p.getAnalysisTypes().isEmpty()) + .collect(Collectors.toList()); final AnalysisType[] totalTypes = new AnalysisType[]{ AnalysisType.INT_TOTAL, AnalysisType.LONG_TOTAL, AnalysisType.LONG_TIME_MS_TOTAL, AnalysisType.DOUBLE_TOTAL }; diff --git a/Plan/src/main/resources/config.yml b/Plan/src/main/resources/config.yml index 243f76d51..938cc047c 100644 --- a/Plan/src/main/resources/config.yml +++ b/Plan/src/main/resources/config.yml @@ -88,15 +88,6 @@ Customization: Male: 'male, boy, man, boe, sir, mr, guy, he, männlich, maskulin, junge, mann' IgnoreWhen: 'sure, think, with, are, you, din' Plugins: - Enabled: - AdvancedAchievements: true - Essentials: true - Factions: true - Jobs: true - McMMO: true - OnTime: true - Towny: true - Vault: true Factions: HideFactions: - ExampleFaction diff --git a/Plan/src/main/resources/plugin.yml b/Plan/src/main/resources/plugin.yml index 25a5fe01b..b714dfd6c 100644 --- a/Plan/src/main/resources/plugin.yml +++ b/Plan/src/main/resources/plugin.yml @@ -13,6 +13,7 @@ softdepend: - McMMO - Jobs - ASkyBlock +- GriefPrevention commands: plan: diff --git a/PlanPluginBridge/pom.xml b/PlanPluginBridge/pom.xml index ba5504b61..3bcec5f71 100644 --- a/PlanPluginBridge/pom.xml +++ b/PlanPluginBridge/pom.xml @@ -10,6 +10,10 @@ <id>vault-repo</id> <url>http://nexus.hc.to/content/repositories/pub_releases</url> </repository> + <repository> + <id>jitpack.io</id> + <url>https://jitpack.io</url> + </repository> </repositories> <dependencies> <dependency> @@ -84,6 +88,12 @@ <version>3.0.6.8</version> <scope>provided</scope> </dependency> + <dependency> + <groupId>com.github.TechFortress</groupId> + <artifactId>GriefPrevention</artifactId> + <version>16.7.1</version> + <scope>provided</scope> + </dependency> </dependencies> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/Bridge.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/Bridge.java index 5666d3c39..fbc4804da 100644 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/Bridge.java +++ b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/Bridge.java @@ -14,7 +14,6 @@ import com.djrapitops.pluginbridge.plan.mcmmo.McmmoHook; import com.djrapitops.pluginbridge.plan.ontime.OnTimeHook; import com.djrapitops.pluginbridge.plan.towny.TownyHook; import com.djrapitops.pluginbridge.plan.vault.VaultHook; -import main.java.com.djrapitops.plan.Settings; import main.java.com.djrapitops.plan.data.additional.HookHandler; /** @@ -25,51 +24,35 @@ public class Bridge { public static void hook(HookHandler handler) { try { - if (Settings.ENABLED_AA.isTrue()) { - AdvancedAchievementsHook advancedAchievementsHook = new AdvancedAchievementsHook(handler); - } + AdvancedAchievementsHook advancedAchievementsHook = new AdvancedAchievementsHook(handler); } catch (NoClassDefFoundError e) { } try { - if (Settings.ENABLED_ESS.isTrue()) { - EssentialsHook essentialsHook = new EssentialsHook(handler); - } + EssentialsHook essentialsHook = new EssentialsHook(handler); } catch (NoClassDefFoundError e) { } try { - if (Settings.ENABLED_FAC.isTrue()) { - FactionsHook factionsHook = new FactionsHook(handler); - } + FactionsHook factionsHook = new FactionsHook(handler); } catch (NoClassDefFoundError e) { } try { - if (Settings.ENABLED_MCM.isTrue()) { - McmmoHook mcMmoHook = new McmmoHook(handler); - } + McmmoHook mcMmoHook = new McmmoHook(handler); } catch (NoClassDefFoundError e) { } try { - if (Settings.ENABLED_JOB.isTrue()) { - JobsHook jobsHook = new JobsHook(handler); - } + JobsHook jobsHook = new JobsHook(handler); } catch (NoClassDefFoundError e) { } try { - if (Settings.ENABLED_ONT.isTrue()) { - OnTimeHook onTimeHook = new OnTimeHook(handler); - } + OnTimeHook onTimeHook = new OnTimeHook(handler); } catch (NoClassDefFoundError e) { } try { - if (Settings.ENABLED_TOW.isTrue()) { - TownyHook townyHook = new TownyHook(handler); - } + TownyHook townyHook = new TownyHook(handler); } catch (NoClassDefFoundError e) { } try { - if (Settings.ENABLED_VAU.isTrue()) { - VaultHook vaultHook = new VaultHook(handler); - } + VaultHook vaultHook = new VaultHook(handler); } catch (NoClassDefFoundError e) { } try { diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/askyblock/ASkyBlockIslandLevel.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/askyblock/ASkyBlockIslandLevel.java index cafbae957..dd1605d58 100644 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/askyblock/ASkyBlockIslandLevel.java +++ b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/askyblock/ASkyBlockIslandLevel.java @@ -19,7 +19,7 @@ public class ASkyBlockIslandLevel extends PluginData { /** * Class Constructor, sets the parameters of the PluginData object. * - * @param aaAPI AdvancedAchievementsAPI given by AdvancedAchievementsHook + * @param aaAPI ASkyBlockAPI */ public ASkyBlockIslandLevel(ASkyBlockAPI aaAPI) { super("ASkyBlock", "island_level", new AnalysisType[]{AnalysisType.INT_AVG}); diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/askyblock/ASkyBlockIslandName.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/askyblock/ASkyBlockIslandName.java index 36bc5cbc8..92ef8c0f7 100644 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/askyblock/ASkyBlockIslandName.java +++ b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/askyblock/ASkyBlockIslandName.java @@ -18,7 +18,7 @@ public class ASkyBlockIslandName extends PluginData { /** * Class Constructor, sets the parameters of the PluginData object. * - * @param aaAPI AdvancedAchievementsAPI given by AdvancedAchievementsHook + * @param aaAPI ASkyBlockAPI */ public ASkyBlockIslandName(ASkyBlockAPI aaAPI) { super("ASkyBlock", "islandname"); diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/askyblock/ASkyBlockIslandResets.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/askyblock/ASkyBlockIslandResets.java index 9f1c17a68..07fae4ac6 100644 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/askyblock/ASkyBlockIslandResets.java +++ b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/askyblock/ASkyBlockIslandResets.java @@ -1,6 +1,5 @@ package com.djrapitops.pluginbridge.plan.askyblock; -import com.djrapitops.pluginbridge.plan.advancedachievements.*; import com.wasteofplastic.askyblock.ASkyBlockAPI; import java.io.Serializable; import java.util.UUID; @@ -19,7 +18,7 @@ public class ASkyBlockIslandResets extends PluginData { /** * Class Constructor, sets the parameters of the PluginData object. * - * @param aaAPI AdvancedAchievementsAPI given by AdvancedAchievementsHook + * @param aaAPI ASkyBlockAPI */ public ASkyBlockIslandResets(ASkyBlockAPI aaAPI) { super("ASkyBlock", "islandresetsleft"); diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/askyblock/ASkyBlockIslands.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/askyblock/ASkyBlockIslands.java index 70e6a490f..854fe4f14 100644 --- a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/askyblock/ASkyBlockIslands.java +++ b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/askyblock/ASkyBlockIslands.java @@ -1,6 +1,5 @@ package com.djrapitops.pluginbridge.plan.askyblock; -import com.djrapitops.pluginbridge.plan.advancedachievements.*; import com.wasteofplastic.askyblock.ASkyBlockAPI; import java.io.Serializable; import java.util.UUID; @@ -20,7 +19,7 @@ public class ASkyBlockIslands extends PluginData { /** * Class Constructor, sets the parameters of the PluginData object. * - * @param aaAPI AdvancedAchievementsAPI given by AdvancedAchievementsHook + * @param aaAPI ASkyBlockAPI */ public ASkyBlockIslands(ASkyBlockAPI aaAPI) { super("ASkyBlock", "island_count", new AnalysisType[]{AnalysisType.HTML}); diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/griefprevention/GriefPreventionClaimArea.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/griefprevention/GriefPreventionClaimArea.java new file mode 100644 index 000000000..e23732802 --- /dev/null +++ b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/griefprevention/GriefPreventionClaimArea.java @@ -0,0 +1,43 @@ +package com.djrapitops.pluginbridge.plan.griefprevention; + +import java.io.Serializable; +import java.util.UUID; +import main.java.com.djrapitops.plan.data.additional.AnalysisType; +import main.java.com.djrapitops.plan.data.additional.PluginData; +import main.java.com.djrapitops.plan.utilities.analysis.MathUtils; +import me.ryanhamshire.GriefPrevention.DataStore; + +/** + * PluginData class for GriefPrevention-plugin. + * + * @author Rsl1122 + * @since 3.5.0 + */ +public class GriefPreventionClaimArea extends PluginData { + + private final DataStore dataStore; + + /** + * Class Constructor, sets the parameters of the PluginData object. + * + * @param dataStore DataStore of GriefPrevention + */ + public GriefPreventionClaimArea(DataStore dataStore) { + super("GriefPrevention", "claim_area", new AnalysisType[]{AnalysisType.INT_TOTAL}); + this.dataStore = dataStore; + super.setAnalysisOnly(false); + super.setIcon("map-o"); + super.setPrefix("Claimed Area: "); + } + + @Override + public String getHtmlReplaceValue(String modifierPrefix, UUID uuid) { + int area = MathUtils.sumInt(dataStore.getClaims().stream().filter(claim -> claim.ownerID.equals(uuid)).map(c -> c.getArea())); + return parseContainer(modifierPrefix, area + ""); + } + + @Override + public Serializable getValue(UUID uuid) { + return MathUtils.sumInt(dataStore.getClaims().stream().filter(claim -> claim.ownerID.equals(uuid)).map(c -> c.getArea())); + } +} diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/griefprevention/GriefPreventionClaimBlocksAvailable.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/griefprevention/GriefPreventionClaimBlocksAvailable.java new file mode 100644 index 000000000..f9b89ae3f --- /dev/null +++ b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/griefprevention/GriefPreventionClaimBlocksAvailable.java @@ -0,0 +1,42 @@ +package com.djrapitops.pluginbridge.plan.griefprevention; + +import java.io.Serializable; +import java.util.UUID; +import main.java.com.djrapitops.plan.data.additional.PluginData; +import me.ryanhamshire.GriefPrevention.DataStore; +import me.ryanhamshire.GriefPrevention.PlayerData; + +/** + * PluginData class for GriefPrevention-plugin. + * + * @author Rsl1122 + * @since 3.5.0 + */ +public class GriefPreventionClaimBlocksAvailable extends PluginData { + + private final DataStore dataStore; + + /** + * Class Constructor, sets the parameters of the PluginData object. + * + * @param dataStore DataStore of GriefPrevention + */ + public GriefPreventionClaimBlocksAvailable(DataStore dataStore) { + super("GriefPrevention", "claim_available"); + this.dataStore = dataStore; + super.setIcon("map-o"); + super.setPrefix("Claim blocks available: "); + } + + @Override + public String getHtmlReplaceValue(String modifierPrefix, UUID uuid) { + PlayerData data = dataStore.getPlayerData(uuid); + int blocks = data.getAccruedClaimBlocks() + data.getBonusClaimBlocks() + dataStore.getGroupBonusBlocks(uuid); + return parseContainer(modifierPrefix, blocks + ""); + } + + @Override + public Serializable getValue(UUID uuid) { + return -1; + } +} diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/griefprevention/GriefPreventionClaimTable.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/griefprevention/GriefPreventionClaimTable.java new file mode 100644 index 000000000..3a144b3c5 --- /dev/null +++ b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/griefprevention/GriefPreventionClaimTable.java @@ -0,0 +1,55 @@ +package com.djrapitops.pluginbridge.plan.griefprevention; + +import com.djrapitops.javaplugin.utilities.FormattingUtils; +import java.io.Serializable; +import java.util.UUID; +import main.java.com.djrapitops.plan.data.additional.PluginData; +import main.java.com.djrapitops.plan.ui.Html; +import me.ryanhamshire.GriefPrevention.DataStore; + +/** + * PluginData class for GriefPrevention-plugin. + * + * @author Rsl1122 + * @since 3.5.0 + */ +public class GriefPreventionClaimTable extends PluginData { + + private final DataStore dataStore; + + /** + * Class Constructor, sets the parameters of the PluginData object. + * + * @param dataStore DataStore of GriefPrevention + */ + public GriefPreventionClaimTable(DataStore dataStore) { + super("GriefPrevention", "inspectclaimtable"); + this.dataStore = dataStore; + String location = Html.FONT_AWESOME_ICON.parse("map-marker") + " Location"; + String size = Html.FONT_AWESOME_ICON.parse("map-o") + " Area"; + super.setPrefix(Html.TABLE_START_3.parse(location, size)); + super.setSuffix(Html.TABLE_END.parse()); + } + + @Override + public String getHtmlReplaceValue(String modifierPrefix, UUID uuid) { + return parseContainer(modifierPrefix, getTableLines(uuid)); + } + + @Override + public Serializable getValue(UUID uuid) { + return -1; + } + + private String getTableLines(UUID uuid) { + StringBuilder html = new StringBuilder(); + dataStore.getClaims().stream() + .filter(claim -> claim.ownerID.equals(uuid)) + .forEach(claim -> { + String location = FormattingUtils.formatLocation(claim.getGreaterBoundaryCorner()); + String area = claim.getArea() + ""; + html.append(Html.TABLELINE_3.parse(location, area)); + }); + return html.toString(); + } +} diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/griefprevention/GriefPreventionClaims.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/griefprevention/GriefPreventionClaims.java new file mode 100644 index 000000000..9e7d902dc --- /dev/null +++ b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/griefprevention/GriefPreventionClaims.java @@ -0,0 +1,45 @@ +package com.djrapitops.pluginbridge.plan.griefprevention; + +import java.io.Serializable; +import java.util.List; +import java.util.UUID; +import java.util.stream.Collectors; +import main.java.com.djrapitops.plan.data.additional.AnalysisType; +import main.java.com.djrapitops.plan.data.additional.PluginData; +import me.ryanhamshire.GriefPrevention.Claim; +import me.ryanhamshire.GriefPrevention.DataStore; + +/** + * PluginData class for GriefPrevention-plugin. + * + * @author Rsl1122 + * @since 3.5.0 + */ +public class GriefPreventionClaims extends PluginData { + + private final DataStore dataStore; + + /** + * Class Constructor, sets the parameters of the PluginData object. + * + * @param dataStore DataStore of GriefPrevention + */ + public GriefPreventionClaims(DataStore dataStore) { + super("GriefPrevention", "claim_count", new AnalysisType[]{AnalysisType.INT_TOTAL}); + this.dataStore = dataStore; + super.setAnalysisOnly(false); + super.setIcon("flag-o"); + super.setPrefix("Claims: "); + } + + @Override + public String getHtmlReplaceValue(String modifierPrefix, UUID uuid) { + List<Claim> claims = dataStore.getClaims().stream().filter(claim -> claim.ownerID.equals(uuid)).collect(Collectors.toList()); + return parseContainer(modifierPrefix, claims.size()+""); + } + + @Override + public Serializable getValue(UUID uuid) { + return dataStore.getClaims().stream().filter(claim -> claim.ownerID.equals(uuid)).collect(Collectors.toList()).size(); + } +} diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/griefprevention/GriefPreventionHook.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/griefprevention/GriefPreventionHook.java new file mode 100644 index 000000000..0331a32a3 --- /dev/null +++ b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/griefprevention/GriefPreventionHook.java @@ -0,0 +1,39 @@ +package com.djrapitops.pluginbridge.plan.griefprevention; + +import com.djrapitops.pluginbridge.plan.Hook; +import main.java.com.djrapitops.plan.api.API; +import main.java.com.djrapitops.plan.data.additional.HookHandler; +import me.ryanhamshire.GriefPrevention.DataStore; +import me.ryanhamshire.GriefPrevention.GriefPrevention; +import static org.bukkit.plugin.java.JavaPlugin.getPlugin; + +/** + * A Class responsible for hooking to GriefPrevention and registering data + * sources. + * + * @author Rsl1122 + * @since 3.5.0 + */ +public class GriefPreventionHook 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. + * @see API + * @throws NoClassDefFoundError when the plugin class can not be found. + */ + public GriefPreventionHook(HookHandler hookH) throws NoClassDefFoundError { + super("me.ryanhamshire.GriefPrevention"); + if (enabled) { + DataStore dataStore = getPlugin(GriefPrevention.class).dataStore; + hookH.addPluginDataSource(new GriefPreventionClaims(dataStore)); + hookH.addPluginDataSource(new GriefPreventionClaimArea(dataStore)); + hookH.addPluginDataSource(new GriefPreventionClaimBlocksAvailable(dataStore)); + hookH.addPluginDataSource(new GriefPreventionSoftMuted(dataStore)); + hookH.addPluginDataSource(new GriefPreventionClaimTable(dataStore)); + } + } +} diff --git a/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/griefprevention/GriefPreventionSoftMuted.java b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/griefprevention/GriefPreventionSoftMuted.java new file mode 100644 index 000000000..98aec0de9 --- /dev/null +++ b/PlanPluginBridge/src/main/java/com/djrapitops/pluginbridge/plan/griefprevention/GriefPreventionSoftMuted.java @@ -0,0 +1,41 @@ +package com.djrapitops.pluginbridge.plan.griefprevention; + +import java.io.Serializable; +import java.util.UUID; +import main.java.com.djrapitops.plan.data.additional.AnalysisType; +import main.java.com.djrapitops.plan.data.additional.PluginData; +import me.ryanhamshire.GriefPrevention.DataStore; + +/** + * PluginData class for GriefPrevention-plugin. + * + * @author Rsl1122 + * @since 3.5.0 + */ +public class GriefPreventionSoftMuted extends PluginData { + + private final DataStore dataStore; + + /** + * Class Constructor, sets the parameters of the PluginData object. + * + * @param dataStore DataStore of GriefPrevention + */ + public GriefPreventionSoftMuted(DataStore dataStore) { + super("GriefPrevention", "softmuted", new AnalysisType[]{AnalysisType.BOOLEAN_TOTAL, AnalysisType.BOOLEAN_PERCENTAGE}); + this.dataStore = dataStore; + super.setAnalysisOnly(false); + super.setIcon("bell-slash-o"); + super.setPrefix("SoftMuted: "); + } + + @Override + public String getHtmlReplaceValue(String modifierPrefix, UUID uuid) { + return parseContainer(modifierPrefix, dataStore.isSoftMuted(uuid) ? "Yes" : "No"); + } + + @Override + public Serializable getValue(UUID uuid) { + return dataStore.isSoftMuted(uuid); + } +}