Solved Cannot make a static reference to non-static field

Discussion in 'Plugin Development' started by kacpicygan123, Jan 9, 2022.

Thread Status:
Not open for further replies.
  1. Offline

    kacpicygan123

    I've been trying to execute this snippet of code:
    Code:
    package quest;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityDeathEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    public class QuestManager implements Listener {
        private Player player;
        Quest1 quest1;
        QuestManager(Player p) {
            player = p;
            quest1 = new Quest1(player, "The beginning", "The description", "You've begun your first quest!", "Your first quest ends here. Good luck!");
        }
       
        @EventHandler
        public static void onEntityDeath(EntityDeathEvent event) {
            if (quest1.checkIfActive() == true) {
                player.sendMessage("Quest is active!");
            }
        }
    }
    
    However, there is an error telling me that:
    Cannot make a static reference to the non-static field quest1
    Cannot make a static reference to the non-static field player

    Quest1.java:
    Code:
    package quest;
    import org.bukkit.Material;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    
    public class Quest1 implements IQuest {
    private boolean isActive = false;
    //some code here
        public boolean checkIfActive() {
            return this.isActive;
    }
    
    What might be the solution?
     
  2. Online

    timtower Administrator Administrator Moderator

  3. Offline

    kacpicygan123

    it worked, thank you!
     
Thread Status:
Not open for further replies.

Share This Page