Solved "No enclosing instance of type Player is accessible in scope" Error

Discussion in 'Spigot Plugin Development' started by ZombieKnifer223, Apr 30, 2017.

Thread Status:
Not open for further replies.
  1. This is my first time coding a plugin using the 1.11.2 Spigot API, but when it is my first time it is highly possible for an error, that I have no idea how to solve, will happen.

    So, I got this error, No enclosing instance of type Player is accessible in scope, and I don't know what that means and not even the Spigot API Java Docs can clearly explain this. So here is my source code and I marked where the error happened, you can even see the stuff I imported too.

    Code (Text):
    package cf.zombieknifer223.essentialseconomyeditor;

    import org.bukkit.command.*;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;

    public class EssentialsEconomyEditor extends JavaPlugin{
       
        @Override
        public void onEnable() {
        getLogger().info("EssentialsEconomyEditor has been enabled!");
        }
        @Override
        public void onDisable() {
            getLogger().info("EssentialsEconomyEditor has been disabled!");
        }
       
        // START OF ERROR
        public boolean onCommand(CommandSender sender, Command cmd, String label, String args[]) {
            if(cmd.getName().equalsIgnoreCase("about")) {
            Player.this.sendMessage(""); // <---- That's the line of code that has the error.
            }
            // END OF ERROR
           
            return false;  
       
    }
    }
     
    I talked to my friend who is a beginner at Java Spigot programmer, but still better then me, and he couldn't explain the error too.
     
  2. You can't just do Player.this like that. You need to check if the CommandSender is a Player with instanceof, cast it, then send the message to that object
     
    • Like Like x 1
Thread Status:
Not open for further replies.