2016-12-05 129 views
0

我正在開發一個Bukkit插件,我需要給予某些玩家權限的幫助。爲了解釋更多,一些管理員會使用帶有一個參數(一名玩家)的命令,然後該玩家需要獲得一些權限。我怎樣才能做到這一點?bukkit - 給予一定的權限,以目標

我到目前爲止有:

@Override 
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { 

    if (cmd.getName().equalsIgnoreCase("giveallkits") || sender.hasPermission("ekits.command.giveallkits")) { 
    if(!(sender instanceof Player)) { 
     sender.sendMessage(ChatColor.RED + "The console should not play. It would be so OP.."); 
     return true; 
    } 
    if (!sender.hasPermission("ekits.permission.giveallkits")) { 
     sender.sendMessage(ChatColor.GRAY + "~ " + ChatColor.GOLD + "You can't to use this command."); 
     sender.sendMessage(ChatColor.GRAY + "(Error 01(No Permission))"); 
    } 

    Player player = (Player) sender; 

    if(args.length == 0){ 
     //send the sender an error message, and return true 

     player.sendMessage(ChatColor.RED + "Correct usage: /" + commandLabel + " <player>"); 
     return true; 
    } 

    @SuppressWarnings("deprecation") 
    Player target = Bukkit.getServer().getPlayer(args[0]); 
    if (target == null) { 
     sender.sendMessage(ChatColor.GRAY + "~ " + ChatColor.GOLD + "Player not specified"); 
    } else { 
     // Then how to give the permissions here? 
player.sendMessage(ChatColor.GRAY + "~ " + ChatColor.GOLD + "You gave " +  ChatColor.BOLD + target.getDisplayName() + ChatColor.GOLD + "all kits"); 
    } 
    } return true; 
} 
+0

你可以使用PEX和PEX API – Kerooker

+0

我知道,但我喜歡有0依賴關係 – MucaP

回答

0

嘗試在目標這一功能,它應該爲你做的工作: (你應該檢查你的第一個if語句& &更有意義。)

/** 
* Adds a new {@link PermissionAttachment} with a single permission by 
* name and value 
* 
* @param plugin Plugin responsible for this attachment, may not be null 
*  or disabled 
* @param name Name of the permission to attach 
* @param value Value of the permission 
* @return The PermissionAttachment that was just created 
*/ 
public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value); 
+0

哦,是的,我搞砸了&&。這個附件有什麼權限? – MucaP

+0

您需要將其存儲在某個位置以設置或取消其中的權限。 – Marlin

+0

請參閱:http://wiki.bukkit.org/Developing_a_permissions_plugin – Marlin