From c214807fdd1ec3bd81524f4ace4bf3feae256241 Mon Sep 17 00:00:00 2001 From: Alexander Noyle Date: Mon, 9 Mar 2026 09:13:34 -0400 Subject: [PATCH] Integrate CoreProtect logging for bounty head metadata --- build.gradle.kts | 2 + .../playerbountiesplus/PlayerBountiesOG.java | 22 +++- .../hook/logging/CoreProtectHook.java | 113 ++++++++++++++++++ .../listener/BountyHeadListener.java | 19 ++- 4 files changed, 154 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/tcoded/playerbountiesplus/hook/logging/CoreProtectHook.java diff --git a/build.gradle.kts b/build.gradle.kts index d99d2d0..7ea51b5 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -66,6 +66,7 @@ repositories { maven { url = uri("https://repo.glaremasters.me/repository/towny/") } maven { url = uri("https://repo.extendedclip.com/releases/") } maven { url = uri("https://repo.tcoded.com/public/") } + maven { url = uri("https://maven.playpro.com") } } /* ---------------------- Java project deps ---------------------------- */ @@ -73,6 +74,7 @@ dependencies { compileOnly("org.purpurmc.purpur:purpur-api:1.19.4-R0.1-SNAPSHOT") // Declare Purpur API version to be packaged. compileOnly("net.sacredlabyrinth.phaed.simpleclans:SimpleClans:2.15.2") compileOnly("net.luckperms:api:5.5") // Import LuckPerms API. + compileOnly("net.coreprotect:coreprotect:23.1") compileOnlyApi(project(":libs:Utilities-OG")) // Import TrueOG Network Utilities-OG Java API (from source). compileOnlyApi(project(":libs:GxUI-OG")) // Import TrueOG Network GxUI-OG Java API (from source). compileOnlyApi(project(":libs:DiamondBank-OG")) { diff --git a/src/main/java/com/tcoded/playerbountiesplus/PlayerBountiesOG.java b/src/main/java/com/tcoded/playerbountiesplus/PlayerBountiesOG.java index ef03488..4b64b6d 100644 --- a/src/main/java/com/tcoded/playerbountiesplus/PlayerBountiesOG.java +++ b/src/main/java/com/tcoded/playerbountiesplus/PlayerBountiesOG.java @@ -16,6 +16,7 @@ import com.google.common.collect.ImmutableList; import com.tcoded.playerbountiesplus.command.BountyCommand; import com.tcoded.playerbountiesplus.command.PlayerBountiesPlusAdminCmd; import com.tcoded.playerbountiesplus.hook.currency.DiamondBankOGHook; +import com.tcoded.playerbountiesplus.hook.logging.CoreProtectHook; import com.tcoded.playerbountiesplus.hook.currency.EconomyHook; import com.tcoded.playerbountiesplus.hook.team.TeamHook; import com.tcoded.playerbountiesplus.listener.BountyHeadListener; @@ -61,6 +62,9 @@ public final class PlayerBountiesOG extends JavaPlugin { // LuckPerms API hook. private LuckPerms luckPerms; + // CoreProtect API hook. + private CoreProtectHook coreProtectHook; + public PlayerBountiesOG() { instance = this; @@ -88,6 +92,14 @@ public final class PlayerBountiesOG extends JavaPlugin { } + this.coreProtectHook = new CoreProtectHook(this); + if (!this.coreProtectHook.isEnabled()) { + + getLogger().warning( + "CoreProtect API v11+ not found - custom bounty head metadata may not rollback correctly."); + + } + // Initialize the DiamondBank-OG API. final RegisteredServiceProvider provider = getServer().getServicesManager() .getRegistration(DiamondBankAPIJava.class); @@ -146,7 +158,9 @@ public final class PlayerBountiesOG extends JavaPlugin { this.getServer().getPluginManager().registerEvents(new DeathListener(this, this.diamondBankAPI, this.luckPerms), this); this.getServer().getPluginManager() - .registerEvents(new BountyHeadListener(this, this.diamondBankAPI, this.luckPerms), this); + .registerEvents( + new BountyHeadListener(this, this.diamondBankAPI, this.luckPerms, this.coreProtectHook), + this); this.getServer().getPluginManager().registerEvents(new GuiProtectionListener(this), this); final List plugins = ImmutableList.copyOf(this.getServer().getPluginManager().getPlugins()); @@ -212,6 +226,12 @@ public final class PlayerBountiesOG extends JavaPlugin { } + public CoreProtectHook getCoreProtectHook() { + + return this.coreProtectHook; + + } + // Utilities. private static void findPluginWithQuery(List plugins, String pluginNameQuery, String... excludeStrings) { diff --git a/src/main/java/com/tcoded/playerbountiesplus/hook/logging/CoreProtectHook.java b/src/main/java/com/tcoded/playerbountiesplus/hook/logging/CoreProtectHook.java new file mode 100644 index 0000000..c94a964 --- /dev/null +++ b/src/main/java/com/tcoded/playerbountiesplus/hook/logging/CoreProtectHook.java @@ -0,0 +1,113 @@ +package com.tcoded.playerbountiesplus.hook.logging; + +import org.bukkit.Location; +import org.bukkit.block.Block; +import org.bukkit.block.BlockState; +import org.bukkit.plugin.Plugin; + +import net.coreprotect.CoreProtect; +import net.coreprotect.CoreProtectAPI; + +public class CoreProtectHook { + + private final CoreProtectAPI coreProtectAPI; + + public CoreProtectHook(Plugin plugin) { + + this.coreProtectAPI = findCoreProtect(plugin); + + } + + public boolean isEnabled() { + + return this.coreProtectAPI != null; + + } + + public boolean logPlacement(String user, BlockState blockState) { + + if (this.coreProtectAPI == null || user == null || blockState == null) { + + return false; + + } + + return this.coreProtectAPI.logPlacement(user, blockState); + + } + + public boolean logRemoval(String user, BlockState blockState) { + + if (this.coreProtectAPI == null || user == null || blockState == null) { + + return false; + + } + + return this.coreProtectAPI.logRemoval(user, blockState); + + } + + public boolean logContainerTransaction(String user, Location location) { + + if (this.coreProtectAPI == null || user == null || location == null) { + + return false; + + } + + return this.coreProtectAPI.logContainerTransaction(user, location); + + } + + public boolean logInteraction(String user, Location location) { + + if (this.coreProtectAPI == null || user == null || location == null) { + + return false; + + } + + return this.coreProtectAPI.logInteraction(user, location); + + } + + public boolean hasPlaced(String user, Block block, int time, int offset) { + + if (this.coreProtectAPI == null || user == null || block == null) { + + return false; + + } + + return this.coreProtectAPI.hasPlaced(user, block, time, offset); + + } + + private static CoreProtectAPI findCoreProtect(Plugin plugin) { + + if (plugin == null) { + + return null; + + } + + final Plugin coreProtectPlugin = plugin.getServer().getPluginManager().getPlugin("CoreProtect"); + if (!(coreProtectPlugin instanceof CoreProtect coreProtect)) { + + return null; + + } + + final CoreProtectAPI api = coreProtect.getAPI(); + if (api == null || !api.isEnabled() || api.APIVersion() < 11) { + + return null; + + } + + return api; + + } + +} diff --git a/src/main/java/com/tcoded/playerbountiesplus/listener/BountyHeadListener.java b/src/main/java/com/tcoded/playerbountiesplus/listener/BountyHeadListener.java index af56c08..6cb362c 100644 --- a/src/main/java/com/tcoded/playerbountiesplus/listener/BountyHeadListener.java +++ b/src/main/java/com/tcoded/playerbountiesplus/listener/BountyHeadListener.java @@ -24,6 +24,7 @@ import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.persistence.PersistentDataType; import com.tcoded.playerbountiesplus.PlayerBountiesOG; +import com.tcoded.playerbountiesplus.hook.logging.CoreProtectHook; import net.kyori.adventure.text.TextComponent; import net.luckperms.api.LuckPerms; @@ -39,14 +40,17 @@ public class BountyHeadListener implements Listener { private final NamespacedKey targetUuidKey; private final NamespacedKey amountKey; private final LuckPerms luckPerms; + private final CoreProtectHook coreProtectHook; - public BountyHeadListener(PlayerBountiesOG plugin, DiamondBankAPIJava diamondBankAPI, LuckPerms luckPerms) { + public BountyHeadListener(PlayerBountiesOG plugin, DiamondBankAPIJava diamondBankAPI, LuckPerms luckPerms, + CoreProtectHook coreProtectHook) { this.diamondBankAPI = diamondBankAPI; this.targetKey = new NamespacedKey(plugin, DeathListener.BOUNTY_HEAD_NAME_KEY); this.targetUuidKey = new NamespacedKey(plugin, DeathListener.BOUNTY_HEAD_UUID_KEY); this.amountKey = new NamespacedKey(plugin, DeathListener.BOUNTY_HEAD_AMOUNT_KEY); this.luckPerms = luckPerms; + this.coreProtectHook = coreProtectHook; } @@ -89,6 +93,12 @@ public class BountyHeadListener implements Listener { blockData.set(amountKey, PersistentDataType.DOUBLE, bountyAmount); skull.update(true, false); + if (this.coreProtectHook != null) { + + this.coreProtectHook.logPlacement(event.getPlayer().getName(), skull); + + } + } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @@ -101,6 +111,7 @@ public class BountyHeadListener implements Listener { } final BlockState state = event.getBlock().getState(); + final BlockState snapshot = state; if (!(state instanceof Skull skull)) { return; @@ -126,6 +137,12 @@ public class BountyHeadListener implements Listener { drop.setItemMeta(meta); + if (this.coreProtectHook != null) { + + this.coreProtectHook.logRemoval(event.getPlayer().getName(), snapshot); + + } + event.setDropItems(false); event.getBlock().setType(Material.AIR, false); event.getBlock().getWorld().dropItemNaturally(event.getBlock().getLocation(), drop); -- 2.47.3