Solved Interact with Campfire

Discussion in 'Spigot Plugin Development' started by ichigo8480, May 29, 2020.

Thread Status:
Not open for further replies.
  1. Hi all,

    I don't know why, but i've got an error when i perform this :

    Code (Java):
        @EventHandler
        public void OnInteract(PlayerInteractEvent event) {
            Player player = event.getPlayer();
            Action action = event.getAction();
            Block block = event.getClickedBlock();
            if(block == null) return;
           
            if(action.equals(Action.LEFT_CLICK_BLOCK)) {
                if(block.getType().equals(Material.CAMPFIRE)) {
                    player.sendMessage("test");
                }
            }
        }
    Someone know how to detect when player interact with a campfire ?

    Thanks for you help,
     
  2. are you registering the event correctly?

    PS: use "==" comparators instead of .equals method
    with that you can avoid NullPointExceptions in ENUMS
     
    • Friendly Friendly x 1
  3. I didn't understand what you said about registering the event.

    Here is my entire Listeners file :

    Code (Java):
    package fr.gael.bonefire;

    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.event.player.PlayerJoinEvent;

    public class BoneFireListeners implements Listener {

        @EventHandler
        public void onJoin(PlayerJoinEvent event) {
            Player player = event.getPlayer();
            if(!player.hasPlayedBefore()) {
                player.setHealthScale(6);
                player.sendMessage("§8Bienvenue dans Mine Souls !");
            }
            if(player.hasPlayedBefore()){
                player.sendMessage("§7Amuses toi bien !");
            }
        }
        @EventHandler
        public void OnInteract(PlayerInteractEvent event) {
            Player player = event.getPlayer();
            Action action = event.getAction();
            Block block = event.getClickedBlock();
           
            if(action == (Action.LEFT_CLICK_BLOCK)) {
                if(block.getType() == (Material.CAMPFIRE)) {
                    player.sendMessage("test");
                }
            }
        }
    }
     
  4. I can see your Main class please?
     
    • Like Like x 1
  5. I found the bug, i inserted "*" to the api-version in config.yml by mistake...
    Sorry for the bother
     
    • Funny Funny x 1
Thread Status:
Not open for further replies.