当我调用此方法时,它在 java 中不起作用
When I call this method it doesn't work in java
当我从 class 公司调用方法 "getName(companyName)" 时,它不会从 yml 向用户发送公司名称,它只是抛出很多异常。但是,当我将方法 "getName(companyName)" returns 的代码放入 sender.sendMessage 时,它确实会向用户发送公司名称。这是为什么?
Class 方法执行位置:
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;
}
}
Class 其中方法 "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: {}
让你的 getName()
方法 static
.
当我从 class 公司调用方法 "getName(companyName)" 时,它不会从 yml 向用户发送公司名称,它只是抛出很多异常。但是,当我将方法 "getName(companyName)" returns 的代码放入 sender.sendMessage 时,它确实会向用户发送公司名称。这是为什么?
Class 方法执行位置:
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;
}
}
Class 其中方法 "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: {}
让你的 getName()
方法 static
.