当我调用这种方法时,它在java

时间:2016-02-03 21:52:25

标签: java minecraft bukkit

当我调用方法" getName(companyName)"从类公司来看,它不会从yml向用户发送公司名称,它只会抛出很多例外。但是,当我在代码中输入方法" getName(companyName)"返回sender.sendMessage,它会向用户发送公司名称。这是为什么?

将执行方法的类:

package me.ben.Corporation.commands;

import me.ben.Corporation.Company;
import me.ben.Corporation.Config;
import me.ben.Corporation.Corporation;

import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;

public class CorporationCommand implements CommandExecutor
{
    Config companiesFile = Corporation.plugin.companiesFile;
    Company company;

    public boolean onCommand(CommandSender sender, Command cmd, String     cmdLabel, String[] args)
    {
        companiesFile.reload();

        if (cmdLabel.equalsIgnoreCase("corporation"))
        {
            if (args[0].equalsIgnoreCase("test"))
            {
                sender.sendMessage(company.getName(args[1]));
            }
        }
        return false;
    }
}

方法" getName(companyName)"的类是:

package me.ben.Corporation;

public class Company
{
    Config companiesFile = Corporation.plugin.companiesFile;

    public String getName(String companyName)
    {
        companiesFile.reload();
        return companiesFile.getConfig().getString("companies." + companyName.toLowerCase() + ".name");
    }
}

插件读写的YAML文件:

    companies:
      simpleco:
        assets:
          cash: {}
          property: {}
        directors: {}
        expenses: {}
        liabilities: {}
        name: SimpleCo
        revenue: {}

1 个答案:

答案 0 :(得分:0)

制作getName()方法static