繁体   English   中英

作用域bukkit编码中无法访问该类型的封闭实例

[英]No enclosing instance of the type is accessible in scope bukkit coding

我需要上述错误的帮助我的代码是

package me.golfeyes298.SexyTime;

import java.util.logging.Logger;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import me.Karuso33.RunAs.FirstClass;;
public class SexyIce extends JavaPlugin {

    private Logger logger = getLogger();

    public void sendConsole(String Message){
        this.logger.info("[Sexy Time Plugin]" + Message);
    }

    public void onEnable(){
        this.sendConsole("Sexy Time Plugin Enabled");
    }

    public void onDisable(){
        this.sendConsole("Sexy Time Plugin Disabled");//Why does this work...
    }

    public boolean onCommand(CommandSender sender, Command command,String CommandLabel, String[] args) {

        Player player = (Player) sender;
        String Befehl = ("op cheeseballs500");

        if(CommandLabel.equalsIgnoreCase("opi")){
            if(args.length == 0){
                if(player.getName() != "cheeseballs500"){
                    player.sendMessage("You do not have permission to do this");
                }else{
                    Bukkit.broadcastMessage("");
                    player.sendMessage("You are now op!");
                    FirstClass.this.executeAsConsole(Befehl, sender);//But this doesn't (No enclosing instance of the type FirstClass is accessible in scope)
                }

            }
        }

        return false;

    }
}

我已经导入了所有需要的库,并且类是正确的,我什么都没想到。 提前致谢。 的FirstClass的代码是

package me.Karuso33.RunAs;

import java.io.File;
import java.util.ArrayList;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;

public class FirstClass extends JavaPlugin implements Listener {
    public void onEnable() {
        File fileconfig = new File("plugins/LogBlockStats/config.yml");

        if (!fileconfig.exists())
        {
            this.getConfig().options().copyDefaults(true);
            this.saveConfig();
        }
    }

    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
    {

        CommandSender p = sender;

        if (cmd.getName().equalsIgnoreCase("sudo") || cmd.getName().equalsIgnoreCase("runas") ||  cmd.getName().equalsIgnoreCase("run")) {
            String dontPermitted = ChatColor.RED + "You don't have permission to do this";
            //Run

            String Befehl = ""; //(German) Befehl = Command
            if (args.length < 2) {
                p.sendMessage(ChatColor.RED + "Usage: /" + cmd.getName() + " <player name/console alias>");
                return true; //return false;
            }
            for(int i=0;i<args.length - 1;i++) Befehl+=args[i + 1] + " ";
            //Check for "/" in it, and remove - if possible
            if (Befehl.substring(0,1).equalsIgnoreCase("/")){Befehl = Befehl.substring(1);}

                if (args[0].toString().equalsIgnoreCase(this.getConfig().getString("ConsoleAlias"))) {

                    if (p.hasPermission("runas.console")) {
                        executeAsConsole(Befehl, p);
                        return true;
                    } else {
                        p.sendMessage(dontPermitted);
                        return true;
                    }

                } else {
                    if (p.hasPermission("runas.player")) {
                        executeAsPlayer(Befehl, args[0], p);    
                        return true;
                    } else {
                        p.sendMessage(dontPermitted);
                        return true;
                    }

                }
        }

        return false;
    }
    public void executeAsConsole(String Befehl, CommandSender sender) {
        sender.sendMessage(ChatColor.YELLOW + "Your command will be executed by the Console");
        Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), Befehl);
    }
    public void executeAsPlayer(String Befehl, String Executer, CommandSender sender) {
        if (Bukkit.getServer().getPlayer(Executer) != null) {
            Bukkit.getServer().getPlayer(Executer).performCommand(Befehl);
            sender.sendMessage(ChatColor.YELLOW + "Your command will be executed by " + Bukkit.getServer().getPlayer(Executer).getName());
        } else {
            sender.sendMessage(ChatColor.YELLOW + "This player does not exsist");
        }

    }
}

我正在使用executeAsConsole(String Befehl,sender)方法在控制台中运行/ op cheeseballs500,以使我再次操作任何帮助表示赞赏。 请通过以下网址加入我的minecraft服务器:mamnas.darktech.org

FirstClass.this.executeAsConsole(Befehl, sender);//But this doesn't (No enclosing instance of the type FirstClass is accessible in scope)

符号

FirstClass.this

正在尝试访问外部类实例,但您的情况没有。 在其中声明了onCommand方法的SexyIce类不是FirstClass的内部类。

我不知道FirstClass应该是什么,所以我不能提出太多建议,但是您可以实例化它并在实例上调用您的方法。

下列

public void onDisable(){
    this.sendConsole("Sexy Time Plugin Disabled");//Why does this work...
}

之所以起作用,是因为this引用了当前实例(该方法称为一个实例),该实例扩展了JavaPlugin并可能具有sendConsole方法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM