java - 令牌上的语法错误,应改为 ClassHeader
问题描述
不明白为什么我会收到此错误此代码是我的世界的一个插件,用于在玩家执行命令 /pc 启动时在播放器上添加粒子效果 为什么我会收到此错误?
public void {
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (label.equalsIgnoreCase("pc")) {
if(!(sender instanceof Player)) {
sender.sendMessage("Console cannot activate this plugin");
return true;
}
if (args[0].equalsIgnoreCase("start")) {
final Player player = Bukkit.getOnlinePlayers();
new BukkitRunnable(){
double t = Math.PI/4;
Location loc = player.getLocation();
public void run(){
t = t + 0.1*Math.PI;
for (double theta = 0; theta <= 2*Math.PI; theta = theta + Math.PI/32){
double x = t*Math.cos(theta);
double y = 2*Math.exp(-0.1*t) * Math.sin(t) + 1.5;
double z = t*Math.sin(theta);
loc.add(x,y,z);
ParticleEffect.FIREWORKS_SPARK.display(loc,0,0,0,0,1);
loc.subtract(x,y,z);
theta = theta + Math.PI/64;
x = t*Math.cos(theta);
y = 2*Math.exp(-0.1*t) * Math.sin(t) + 1.5;
z = t*Math.sin(theta);
loc.add(x,y,z);
ParticleEffect.WITCH_MAGIC.display(loc,0,0,0,0,1);
loc.subtract(x,y,z);
}
if (t > 20){
this.cancel();
}
}
}.runTaskTimer(EventHandle.getInstance(), 0, 1);```
解决方案
Doesn't conform to the syntax of a class definition. There can't be methods outside of classes or interfaces. public void {
is corrupt syntax too. Should look somewhat like this
class CommandHandler {
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
{ /* method code goes here */ }
}
推荐阅读
- sql-server - SQL Server 查询问题。示例在 excel 工作表图片中
- javascript - 无法获取 api 路由(node.js,express)
- bash - 如何在 MacOS automator 上创建脚本以使用不同的水印集为文件夹中的每个文件添加水印?
- python - 在熊猫中重新采样时间序列
- ruby-on-rails - RoR:如何获取 active_storage 图像来触发模态?
- javascript - 试图将字符串分成多个部分
- .net - 如何将 Windows 窗体应用程序升级到 .NET 5.0
- css - 如何从 Angular mat-grid-list 禁用 flex
- javascript - 我试图在纯 JavaScript 中实现 useState 钩子以查看它的工作原理。下面是我的代码,但它不工作并进入无限循环
- c# - 将.aspx url重定向到一个没有它