Reputation: 7
I am getting the following error on Eclipse Java Mars while coding a simple Minecraft 1.10 test plugin: "Cannot make a static reference to the non-static method sendMessage(String) from the type CommandSender." This is in a separate class just for commands, aside from the main class. Here is the entire class:
package io.github.ultraMLGcode.TestPlugin;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class TestPluginCommandExecutor implements CommandExecutor {
public TestPlugin plugin;
public TestPluginCommandExecutor(TestPlugin instance) {
plugin = instance;
}
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (cmd.getName().equalsIgnoreCase("basic") && sender instanceof Player) { //If the player typed /basic then do the following...
if (sender instanceof Player) {
Player player = (Player) sender;
//do something
Player.sendMessage("Hello, it is a nice day, isn't it?");
} else {
sender.sendMessage("You must be a player!");
}
//doSomething
return true;
}
return false;
}
}
Upvotes: 0
Views: 1293
Reputation: 296
I don't know about the minecraft api, but i think this can helps:
Change this line:
Player.sendMessage("Hello, it is a nice day, isn't it?");
to this line
player.sendMessage("Hello, it is a nice day, isn't it?");
I think "sendMessage" is a non static method.
I hope it helps.
Upvotes: 1