Skip to content

Commit

Permalink
Check that CampfireStartEvent exists before registering
Browse files Browse the repository at this point in the history
  • Loading branch information
Intelli committed Jul 14, 2023
1 parent d4997cc commit c7cf035
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/main/java/net/coreprotect/listener/ListenerHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import org.bukkit.plugin.PluginManager;

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.BlockBurnListener;
import net.coreprotect.listener.block.BlockDispenseListener;
Expand Down Expand Up @@ -86,9 +84,13 @@ public ListenerHandler(CoreProtect plugin) {
pluginManager.registerEvents(new BlockPistonListener(), plugin);
pluginManager.registerEvents(new BlockPlaceListener(), 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);
}
catch (Exception e) {
CampfireStartListener.useCampfireStartEvent = false;
}

// Entity Listeners
pluginManager.registerEvents(new CreatureSpawnListener(), plugin);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

public final class CampfireStartListener extends Queue implements Listener {

public static boolean useCampfireStartEvent = true;

@EventHandler(priority = EventPriority.MONITOR)
protected void onCampfireStart(CampfireStartEvent event) {
Block block = event.getBlock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import net.coreprotect.database.lookup.InteractionLookup;
import net.coreprotect.database.lookup.SignMessageLookup;
import net.coreprotect.language.Phrase;
import net.coreprotect.listener.block.CampfireStartListener;
import net.coreprotect.model.BlockGroup;
import net.coreprotect.paper.PaperAdapter;
import net.coreprotect.thread.CacheHandler;
Expand Down Expand Up @@ -640,7 +641,7 @@ else if (BlockGroup.LIGHTABLES.contains(type)) { // extinguishing a lit block su
});
*/
}
else if (type == Material.CAMPFIRE || type == Material.SOUL_CAMPFIRE) {
else if ((type == Material.CAMPFIRE || type == Material.SOUL_CAMPFIRE) && CampfireStartListener.useCampfireStartEvent) {
ItemStack handItem = null;
ItemStack mainHand = player.getInventory().getItemInMainHand();
ItemStack offHand = player.getInventory().getItemInOffHand();
Expand Down

0 comments on commit c7cf035

Please sign in to comment.