【问题标题】:Integer not working bukkit整数不工作 bukkit
【发布时间】:2013-12-15 16:51:03
【问题描述】:
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
  Player player = (Player) sender;
  if(commandLabel.equalsIgnoreCase("FlyTime")
     || commandLabel.equalsIgnoreCase("ft")){
    if(args.length ==0){
      player.sendMessage(
        ChatColor.DARK_BLUE + "[FlyTime] " + ChatColor.GREEN
        + player.getDisplayName() + ChatColor.DARK_RED + " " + number
        + ChatColor.GREEN + " Secconds remain until "
        + ChatColor.AQUA + "FlyTime " + ChatColor.RED + "Enjoy!");
    }
    else if(args.length ==1){
      if(player.isOp()){
        number = args[0];
      }
    }
  }
}

我的问题是试图让参数改变它不想改变的整数值。

【问题讨论】:

    标签: java integer bukkit


    【解决方案1】:

    首先,您应该检查 CommandSender 是否是 Player 的实例(命令可以从控制台发送):

    if (sender instanceof Player) {
    

    您从参数中正确获取了数字,但我没有看到您使用过它。尝试用if(player.isOp()){后面的号码向玩家发送消息

    【讨论】:

      【解决方案2】:

      我猜你有

      private int number;
      

      在你的代码中。

          public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
        if(sender instanceof Player) //first add what August said; check if its a player.
        {
        Player player = (Player) sender;
        if(cmd.getName().equalsIgnoreCase("FlyTime") || cmd.getName().equalsIgnoreCase("ft")){ //second its a common method to use command name instead of command label.
          if(args.length ==0)
          {
            player.sendMessage(
              ChatColor.DARK_BLUE + "[FlyTime] " + ChatColor.GREEN
              + player.getDisplayName() + ChatColor.DARK_RED + " " + number
              + ChatColor.GREEN + " Secconds remain until "
              + ChatColor.AQUA + "FlyTime " + ChatColor.RED + "Enjoy!");
          }
          else if(args.length ==1)
           {
            if(player.isOp())
            {
              System.out.println("PRE-NUMBER:" + number); //display the number
              number = args[0];
              System.out.println("NUMBER: " + number); //do a check to see if the number has changed
            }
          }
         }
        }
      }
      

      如果这不能解决问题,那么除了给定的代码之外,你已经搞砸了。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-10-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多