2013-12-15 40 views
-5
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]; 
     } 
    } 
    } 
} 

我的問題是試圖使參數改變整數的值,它只是不想改變。整數不工作bukkit

回答

0

首先,你應該檢查是否CommandSender是玩家的一個實例(命令可以從控制檯發送):

if (sender instanceof Player) { 

你正確地獲取從參數的數目,但我沒有看到你曾經使用它。嘗試發送給玩家數量的消息if(player.isOp()){

0

我猜你以後有

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 
     } 
    } 
    } 
    } 
} 

如果這不能解決它,那麼你已經搞砸了給定的代碼以外的東西了。