diff --git a/EpicSpawners-Plugin/src/main/java/com/craftaro/epicspawners/listeners/BlockListeners.java b/EpicSpawners-Plugin/src/main/java/com/craftaro/epicspawners/listeners/BlockListeners.java index 495d40b..1467330 100644 --- a/EpicSpawners-Plugin/src/main/java/com/craftaro/epicspawners/listeners/BlockListeners.java +++ b/EpicSpawners-Plugin/src/main/java/com/craftaro/epicspawners/listeners/BlockListeners.java @@ -3,6 +3,7 @@ package com.craftaro.epicspawners.listeners; import com.craftaro.core.compatibility.CompatibleHand; import com.craftaro.core.compatibility.ServerVersion; import com.craftaro.core.hooks.EconomyManager; +import com.craftaro.epicspawners.utils.CoreProtectLogger; import com.craftaro.third_party.com.cryptomorin.xseries.XMaterial; import com.craftaro.core.utils.ItemUtils; import com.craftaro.core.utils.PlayerUtils; @@ -149,7 +150,6 @@ public class BlockListeners implements Listener { int spawnerStackSize = spawnerTier.getStackSize(event.getItemInHand()); SpawnerStack stack = new SpawnerStackImpl(spawner, spawnerTier, spawnerStackSize); spawner.addSpawnerStack(stack); - EpicSpawners.getInstance().getDataManager().save(stack, "spawner_id", spawner.getId()); Player player = event.getPlayer(); @@ -193,7 +193,6 @@ public class BlockListeners implements Listener { return; } - this.plugin.getSpawnerManager().addSpawnerToWorld(location, spawner); if (Settings.ALERT_PLACE_BREAK.getBoolean()) { @@ -214,7 +213,9 @@ public class BlockListeners implements Listener { spawner.updateDelay(); spawner.setPlacedBy(player); + spawner.setId(EpicSpawners.getInstance().getDataManager().getNextId(spawner.getTableName())); EpicSpawners.getInstance().getDataManager().save(spawner); + EpicSpawners.getInstance().getDataManager().save(stack, "spawner_id", spawner.getId()); this.plugin.processChange(block); this.plugin.createHologram(spawner); @@ -317,9 +318,7 @@ public class BlockListeners implements Listener { return; } - plugin.logCoreProtect(coreProtectAPI -> { - coreProtectAPI.logRemoval(player.getName(), block.getLocation(), block.getType(), block.getBlockData()); - }); + CoreProtectLogger.logRemoval(player.getName(), block); } else { SpawnerChangeEvent changeEvent = new SpawnerChangeEvent(player, spawner, currentStackSize - 1, currentStackSize); Bukkit.getPluginManager().callEvent(changeEvent); @@ -328,9 +327,7 @@ public class BlockListeners implements Listener { return; } - plugin.logCoreProtect(coreProtectAPI -> { - coreProtectAPI.logRemoval(player.getName(), block.getLocation(), block.getType(), block.getBlockData()); - }); + CoreProtectLogger.logRemoval(player.getName(), block); } boolean naturalOnly = Settings.ONLY_CHARGE_NATURAL.getBoolean(); diff --git a/EpicSpawners-Plugin/src/main/java/com/craftaro/epicspawners/listeners/InteractListeners.java b/EpicSpawners-Plugin/src/main/java/com/craftaro/epicspawners/listeners/InteractListeners.java index 556a69e..fbdf2ce 100644 --- a/EpicSpawners-Plugin/src/main/java/com/craftaro/epicspawners/listeners/InteractListeners.java +++ b/EpicSpawners-Plugin/src/main/java/com/craftaro/epicspawners/listeners/InteractListeners.java @@ -4,6 +4,7 @@ import com.craftaro.core.compatibility.CompatibleHand; import com.craftaro.core.compatibility.CompatibleMaterial; import com.craftaro.core.compatibility.ServerVersion; import com.craftaro.core.hooks.ProtectionManager; +import com.craftaro.epicspawners.utils.CoreProtectLogger; import com.craftaro.third_party.com.cryptomorin.xseries.XMaterial; import com.craftaro.core.utils.ItemUtils; import com.craftaro.epicspawners.EpicSpawners; @@ -247,7 +248,7 @@ public class InteractListeners implements Listener { return; } - plugin.logCoreProtect(coreProtectAPI -> coreProtectAPI.logInteraction(player.getName(), block.getLocation())); + CoreProtectLogger.logInteraction(player.getName(), block.getLocation()); spawner.overview(player); this.plugin.processChange(block); diff --git a/EpicSpawners-Plugin/src/main/java/com/craftaro/epicspawners/spawners/spawner/PlacedSpawnerImpl.java b/EpicSpawners-Plugin/src/main/java/com/craftaro/epicspawners/spawners/spawner/PlacedSpawnerImpl.java index 6798319..26af770 100644 --- a/EpicSpawners-Plugin/src/main/java/com/craftaro/epicspawners/spawners/spawner/PlacedSpawnerImpl.java +++ b/EpicSpawners-Plugin/src/main/java/com/craftaro/epicspawners/spawners/spawner/PlacedSpawnerImpl.java @@ -106,7 +106,6 @@ public class PlacedSpawnerImpl implements PlacedSpawner { public PlacedSpawnerImpl(Location location) { this.location = location; this.sSpawner = new SSpawner(this.location); - this.id = EpicSpawners.getInstance().getDataManager().getNextId(getTableName()); } @Override @@ -391,9 +390,6 @@ public class PlacedSpawnerImpl implements PlacedSpawner { return false; } - plugin.logCoreProtect(coreProtectAPI -> { - coreProtectAPI.logPlacement(player.getName(), this.location, XMaterial.SPAWNER.parseMaterial(), XMaterial.SPAWNER.parseMaterial().createBlockData()); - }); if ((getStackSize() + amount) > max) { PlayerUtils.giveItem(player, tier.toItemStack(1, (getStackSize() + amount) - max)); diff --git a/EpicSpawners-Plugin/src/main/java/com/craftaro/epicspawners/utils/CoreProtectLogger.java b/EpicSpawners-Plugin/src/main/java/com/craftaro/epicspawners/utils/CoreProtectLogger.java new file mode 100644 index 0000000..9f2e808 --- /dev/null +++ b/EpicSpawners-Plugin/src/main/java/com/craftaro/epicspawners/utils/CoreProtectLogger.java @@ -0,0 +1,33 @@ +package com.craftaro.epicspawners.utils; + +import net.coreprotect.CoreProtectAPI; +import org.bukkit.Location; +import org.bukkit.block.Block; +import org.bukkit.block.data.BlockData; + +public class CoreProtectLogger { + + private static CoreProtectAPI coreProtectAPI; + + private static boolean isCoreProtectEnabled() { + return CoreProtectLogger.coreProtectAPI != null; + } + + public static void init(CoreProtectAPI coreProtectAPI) { + CoreProtectLogger.coreProtectAPI = coreProtectAPI; + } + + public static void logRemoval(String playerName, Block block) { + if (!isCoreProtectEnabled()) { + return; + } + coreProtectAPI.logRemoval(playerName, block.getLocation(), block.getType(), block.getBlockData()); + } + + public static void logInteraction(String playerName, Location location) { + if (!isCoreProtectEnabled()) { + return; + } + coreProtectAPI.logInteraction(playerName, location); + } +}