这只是该插件的开始,还会有更多。这就是我想要的:对于/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) http://docs.oracle.com/javase/7/docs/api/java/lang/Integer.html#parseInt%28java.lang.String%29.
int bounty = Integer.parseInt(args[1]);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)