Java 静态和非静态和世界接口不可实例化错误
Java static and non-static and world interface not instanceable error
我对
有疑问
Cannot make a static reference to the non-static method spawnParticle(blabla)
这就是我所说的我的代码..
public class Particle implements CommandExecutor
{
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] arg) {
if (sender instanceof Player)
{
Particle particle = new Particle();
Player player = (Player) sender;
double x = ((Player) sender).getLocation().getX();
double y = ((Player) sender).getLocation().getY();
double z = ((Player) sender).getLocation().getZ();
World.spawnParticle(org.bukkit.Particle.TOTEM, x, y, z, 1, 0, 0, 0);
}
return false;
}
}
我已经阅读了很多关于非静态静态问题解决的文章并且知道那个问题是什么意思,但我真的不知道如何在这里解决它。
扩展到那个世界的问题是一个接口,不能被增强。修复在评论中感谢您的帮助
该方法是一个实例方法,这意味着你必须用new来实例化对象,而World是一个接口,所以你不能实例化它,你必须实例化一个实现了这个接口的class , 玩家拥有世界
(别忘了导入 class WorldEvent)
if (sender instanceof Player)
{
Particle particle = new Particle();
Player player = (Player) sender;
double x = ((Player) sender).getLocation().getX();
double y = ((Player) sender).getLocation().getY();
double z = ((Player) sender).getLocation().getZ();
World w = sender.getWorld();
w.spawnParticle(org.bukkit.Particle.TOTEM, x, y, z, 1, 0, 0, 0);
}
我对
有疑问Cannot make a static reference to the non-static method spawnParticle(blabla)
这就是我所说的我的代码..
public class Particle implements CommandExecutor
{
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] arg) {
if (sender instanceof Player)
{
Particle particle = new Particle();
Player player = (Player) sender;
double x = ((Player) sender).getLocation().getX();
double y = ((Player) sender).getLocation().getY();
double z = ((Player) sender).getLocation().getZ();
World.spawnParticle(org.bukkit.Particle.TOTEM, x, y, z, 1, 0, 0, 0);
}
return false;
}
}
我已经阅读了很多关于非静态静态问题解决的文章并且知道那个问题是什么意思,但我真的不知道如何在这里解决它。 扩展到那个世界的问题是一个接口,不能被增强。修复在评论中感谢您的帮助
该方法是一个实例方法,这意味着你必须用new来实例化对象,而World是一个接口,所以你不能实例化它,你必须实例化一个实现了这个接口的class , 玩家拥有世界
(别忘了导入 class WorldEvent)
if (sender instanceof Player)
{
Particle particle = new Particle();
Player player = (Player) sender;
double x = ((Player) sender).getLocation().getX();
double y = ((Player) sender).getLocation().getY();
double z = ((Player) sender).getLocation().getZ();
World w = sender.getWorld();
w.spawnParticle(org.bukkit.Particle.TOTEM, x, y, z, 1, 0, 0, 0);
}