Check that CampfireStartEvent exists before registering

This commit is contained in:
Intelli 2023-07-13 19:27:03 -06:00
parent d4997cca60
commit c7cf035564
3 changed files with 9 additions and 4 deletions

View File

@ -3,8 +3,6 @@ package net.coreprotect.listener;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import net.coreprotect.CoreProtect; import net.coreprotect.CoreProtect;
import net.coreprotect.bukkit.BukkitAdapter;
import net.coreprotect.config.ConfigHandler;
import net.coreprotect.listener.block.BlockBreakListener; import net.coreprotect.listener.block.BlockBreakListener;
import net.coreprotect.listener.block.BlockBurnListener; import net.coreprotect.listener.block.BlockBurnListener;
import net.coreprotect.listener.block.BlockDispenseListener; import net.coreprotect.listener.block.BlockDispenseListener;
@ -86,9 +84,13 @@ public final class ListenerHandler {
pluginManager.registerEvents(new BlockPistonListener(), plugin); pluginManager.registerEvents(new BlockPistonListener(), plugin);
pluginManager.registerEvents(new BlockPlaceListener(), plugin); pluginManager.registerEvents(new BlockPlaceListener(), plugin);
pluginManager.registerEvents(new BlockSpreadListener(), plugin); pluginManager.registerEvents(new BlockSpreadListener(), plugin);
if (ConfigHandler.SERVER_VERSION >= BukkitAdapter.BUKKIT_V1_20) { try {
Class.forName("org.bukkit.event.block.CampfireStartEvent"); // Bukkit 1.20+
pluginManager.registerEvents(new CampfireStartListener(), plugin); pluginManager.registerEvents(new CampfireStartListener(), plugin);
} }
catch (Exception e) {
CampfireStartListener.useCampfireStartEvent = false;
}
// Entity Listeners // Entity Listeners
pluginManager.registerEvents(new CreatureSpawnListener(), plugin); pluginManager.registerEvents(new CreatureSpawnListener(), plugin);

View File

@ -15,6 +15,8 @@ import net.coreprotect.utility.Util;
public final class CampfireStartListener extends Queue implements Listener { public final class CampfireStartListener extends Queue implements Listener {
public static boolean useCampfireStartEvent = true;
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
protected void onCampfireStart(CampfireStartEvent event) { protected void onCampfireStart(CampfireStartEvent event) {
Block block = event.getBlock(); Block block = event.getBlock();

View File

@ -52,6 +52,7 @@ import net.coreprotect.database.lookup.ChestTransactionLookup;
import net.coreprotect.database.lookup.InteractionLookup; import net.coreprotect.database.lookup.InteractionLookup;
import net.coreprotect.database.lookup.SignMessageLookup; import net.coreprotect.database.lookup.SignMessageLookup;
import net.coreprotect.language.Phrase; import net.coreprotect.language.Phrase;
import net.coreprotect.listener.block.CampfireStartListener;
import net.coreprotect.model.BlockGroup; import net.coreprotect.model.BlockGroup;
import net.coreprotect.paper.PaperAdapter; import net.coreprotect.paper.PaperAdapter;
import net.coreprotect.thread.CacheHandler; import net.coreprotect.thread.CacheHandler;
@ -640,7 +641,7 @@ public final class PlayerInteractListener extends Queue implements Listener {
}); });
*/ */
} }
else if (type == Material.CAMPFIRE || type == Material.SOUL_CAMPFIRE) { else if ((type == Material.CAMPFIRE || type == Material.SOUL_CAMPFIRE) && CampfireStartListener.useCampfireStartEvent) {
ItemStack handItem = null; ItemStack handItem = null;
ItemStack mainHand = player.getInventory().getItemInMainHand(); ItemStack mainHand = player.getInventory().getItemInMainHand();
ItemStack offHand = player.getInventory().getItemInOffHand(); ItemStack offHand = player.getInventory().getItemInOffHand();