这只是插件的开始,还会有更多。这就是我想要的:对于 /bounty <name> <amount>
我希望能够读取所读取的金额以创建类似 int a = args[1]
的变量,但我不知道该怎么做。
我已经尝试过了,但它给了我一些错误。我也想要它,所以它只能是命令上的数字。我使用的bukkit版本:craftbukkit-1.7.10-R0.1-20140804.183445-7
这是我的代码:
public class Main extends JavaPlugin {
public void onEnable() {
Bukkit.getServer().getLogger().info("[Bounty] Enabled");
Bukkit.getServer().getLogger().info("[Bounty] Developed by ITaco_v2");
}
public void onDisable() {
Bukkit.getServer().getLogger().info("[Bounty] Disabled");
}
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
if ( !(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "[" + ChatColor.GREEN + "Bounty" + ChatColor.RED + "] " + ChatColor.GOLD + "In game use only!");
return true;
}
if (cmd.getName().equalsIgnoreCase("bounty")) {
if (sender.hasPermission("bounty.setbounty"));
if (args.length == 0) {
sender.sendMessage(ChatColor.RED + "Please specify a Player and a bounty amount.");
sender.sendMessage(ChatColor.GREEN + "Like this: /bounty <playername> <amount>");
return true;
}
Player target = Bukkit.getServer().getPlayer(args[0]);
if (target == null) {
sender.sendMessage(ChatColor.RED + "Could not find player!");
return true;
}
if (target != null) {
sender.sendMessage(ChatColor.RED + "Please specify a bounty amount.");
sender.sendMessage(ChatColor.GREEN + "Like this: /bounty " + args[0] + " <amount>");
return true;
}
}
return false;
}
}
最佳答案
您可以使用 Integer.parseInt(String)
从字符串中解析整数.
int bounty = Integer.parseInt(args[1]);
关于java - 在 Bukkit 插件中将赏金参数读取为整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25193058/