Minecraft Spigot 插件编码,Player.sendMessage 有问题
Minecraft Spigot Plugin coding, having issue with Player.sendMessage
我在编写一个简单的 Minecraft 1.10 测试插件时在 Eclipse Java Mars 上收到以下错误:"Cannot make a static reference to the non-static method sendMessage(String) from the type CommandSender."这是一个单独的 class 命令,除了主要class。这是整个 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;
}
}
我不知道 minecraft api,但我认为这会有所帮助:
更改此行:
Player.sendMessage("Hello, it is a nice day, isn't it?");
到这一行
player.sendMessage("Hello, it is a nice day, isn't it?");
我认为"sendMessage"是一个非静态方法。
希望对您有所帮助。
我在编写一个简单的 Minecraft 1.10 测试插件时在 Eclipse Java Mars 上收到以下错误:"Cannot make a static reference to the non-static method sendMessage(String) from the type CommandSender."这是一个单独的 class 命令,除了主要class。这是整个 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;
}
}
我不知道 minecraft api,但我认为这会有所帮助:
更改此行:
Player.sendMessage("Hello, it is a nice day, isn't it?");
到这一行
player.sendMessage("Hello, it is a nice day, isn't it?");
我认为"sendMessage"是一个非静态方法。
希望对您有所帮助。