Fix CoreProtect hook when plugin not present

This commit is contained in:
ceze88 2024-01-07 14:37:12 +01:00
parent 08b25e8852
commit 15542a3229
4 changed files with 40 additions and 13 deletions

View File

@ -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();

View File

@ -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);

View File

@ -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));

View File

@ -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);
}
}