首页 > 解决方案 > 令牌上的语法错误,应改为 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);```

             
    

标签: javapluginsevent-handlingminecraft

解决方案


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 */ }
}

推荐阅读