下面列出了org.bukkit.permissions.Permissible#hasPermission ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public int broadcast(String message, String permission) {
Set<CommandSender> recipients = new HashSet<>();
for (Permissible permissible : getPluginManager().getPermissionSubscriptions(permission)) {
if (permissible instanceof CommandSender && permissible.hasPermission(permission)) {
recipients.add((CommandSender) permissible);
}
}
BroadcastMessageEvent broadcastMessageEvent = new BroadcastMessageEvent(message, recipients);
getPluginManager().callEvent(broadcastMessageEvent);
if (broadcastMessageEvent.isCancelled()) {
return 0;
}
message = broadcastMessageEvent.getMessage();
for (CommandSender recipient : recipients) {
recipient.sendMessage(message);
}
return recipients.size();
}
/**
* Determine if an <i>object</i> can perform some action on this proxy using possible permissions
*
* @param object Object to check against
* @param permissions Permissions to check (use <b>%</b> as a placeholder for the proxy name)
* @return Permission Check Result
*/
public boolean permits(Permissible object, String... permissions) {
if (Util.isNull(object)) throw new NullPointerException();
boolean permitted = false;
for (int p = 0; !permitted && p < permissions.length; p++) {
String perm = permissions[p];
if (perm != null) {
// Check all proxies & individual proxies permission
permitted = object.hasPermission(perm.replace("%", "*"))
|| object.hasPermission(perm.replace("%", this.getName().toLowerCase()));
}
}
return permitted;
}
/**
* Determine if an <i>object</i> can perform some action on this host using possible permissions
*
* @param object Object to check against
* @param permissions Permissions to check (use <b>%</b> as a placeholder for the host name)
* @return Permission Check Result
*/
public boolean permits(Permissible object, String... permissions) {
if (Util.isNull(object)) throw new NullPointerException();
boolean permitted = false;
for (int p = 0; !permitted && p < permissions.length; p++) {
String perm = permissions[p];
if (perm != null) {
// Check all proxies & individual proxies permission
permitted = object.hasPermission(perm.replace("%", "*"))
|| object.hasPermission(perm.replace("%", this.getName().toLowerCase()));
}
}
return permitted;
}
public static void broadcastCommandMessage(CommandSender source, String message, boolean sendToSource) {
String result = source.getName() + ": " + message;
if (source instanceof BlockCommandSender) {
BlockCommandSender blockCommandSender = (BlockCommandSender) source;
if (blockCommandSender.getBlock().getWorld().getGameRuleValue("commandBlockOutput").equalsIgnoreCase("false")) {
Bukkit.getConsoleSender().sendMessage(result);
return;
}
} else if (source instanceof CommandMinecart) {
CommandMinecart commandMinecart = (CommandMinecart) source;
if (commandMinecart.getWorld().getGameRuleValue("commandBlockOutput").equalsIgnoreCase("false")) {
Bukkit.getConsoleSender().sendMessage(result);
return;
}
}
Set<Permissible> users = Bukkit.getPluginManager().getPermissionSubscriptions(Server.BROADCAST_CHANNEL_ADMINISTRATIVE);
String colored = ChatColor.GRAY + "" + ChatColor.ITALIC + "[" + result + ChatColor.GRAY + ChatColor.ITALIC + "]";
if (sendToSource && !(source instanceof ConsoleCommandSender)) {
source.sendMessage(message);
}
for (Permissible user : users) {
if (user instanceof CommandSender && user.hasPermission(Server.BROADCAST_CHANNEL_ADMINISTRATIVE)) {
CommandSender target = (CommandSender) user;
if (target instanceof ConsoleCommandSender) {
target.sendMessage(result);
} else if (target != source) {
target.sendMessage(colored);
}
}
}
}
/**
* Determine if an <i>object</i> can perform some action on this server using possible permissions
*
* @param object Object to check against
* @param permissions Permissions to check (use <b>%</b> as a placeholder for the server name)
* @return Permission Check Result
*/
public boolean permits(Permissible object, String... permissions) {
if (Util.isNull(object)) throw new NullPointerException();
boolean permitted = false;
for (int p = 0; !permitted && p < permissions.length; p++) {
String perm = permissions[p];
if (perm != null) {
// Check all servers & individual servers permission
permitted = object.hasPermission(perm.replace("%", "*"))
|| object.hasPermission(perm.replace("%", this.getName().toLowerCase()));
// Check all hosts & individual hosts permission
if (this instanceof SubServer) {
permitted = permitted || object.hasPermission(perm.replace("%", "::*"))
|| object.hasPermission(perm.replace("%", "::" + ((SubServer) this).getHost().toLowerCase()));
}
// Check all groups & individual groups permission
List<String> groups = this.getGroups();
if (groups.size() > 0) {
permitted = permitted || object.hasPermission(perm.replace("%", ":*"));
for (int g = 0; !permitted && g < groups.size(); g++) {
permitted = object.hasPermission(perm.replace("%", ":" + groups.get(g).toLowerCase()));
}
}
}
}
return permitted;
}
@Override
public int broadcast(String message, String permission) {
int count = 0;
Set<Permissible> permissibles = getPluginManager().getPermissionSubscriptions(permission);
for (Permissible permissible : permissibles) {
if (permissible instanceof CommandSender && permissible.hasPermission(permission)) {
CommandSender user = (CommandSender) permissible;
user.sendMessage(message);
count++;
}
}
return count;
}
public boolean canUseEditWand(Permissible permissible) {
return permissible.hasPermission(EDIT_WAND_PERMISSION);
}
public boolean canUseEditWand(Permissible permissible) {
return permissible.hasPermission(EDIT_WAND_PERMISSION);
}
public static void assertPermission(Permissible permissible, String permission) throws CommandPermissionsException {
if(!permissible.hasPermission(permission)) {
throw new CommandPermissionsException();
}
}
public static void assertPermission(Permissible permissible, Permission permission) throws CommandPermissionsException {
if(!permissible.hasPermission(permission)) {
throw new CommandPermissionsException();
}
}
public static boolean isStaff(Permissible permissible) {
return permissible.hasPermission(Permissions.STAFF);
}
public static boolean hasPermission(Permissible sender, String permission) {
return sender instanceof ConsoleCommandSender || sender.hasPermission(permission);
}
/**
* This method checks whether the given {@link Permissible} has the {@link Permission}
* to access the given {@link SlimefunItem}.
*
* @param p
* The {@link Permissible} to check
* @param item
* The {@link SlimefunItem} in question
*
* @return Whether the {@link Permissible} has the required {@link Permission}
*/
public boolean hasPermission(Permissible p, SlimefunItem item) {
if (item == null) {
// Failsafe
return true;
}
String permission = permissions.get(item.getID());
return permission == null || permission.equals("none") || p.hasPermission(permission);
}