Java Code Examples for org.bukkit.permissions.Permissible#hasPermission()

The following examples show how to use org.bukkit.permissions.Permissible#hasPermission() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CraftServer.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
@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();
}
 
Example 2
Source File: Proxy.java    From SubServers-2 with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 3
Source File: Host.java    From SubServers-2 with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 4
Source File: Command.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
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);
            }
        }
    }
}
 
Example 5
Source File: Server.java    From SubServers-2 with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 6
Source File: CraftServer.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
@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;
}
 
Example 7
Source File: ObserverToolFactory.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
public boolean canUseEditWand(Permissible permissible) {
  return permissible.hasPermission(EDIT_WAND_PERMISSION);
}
 
Example 8
Source File: ObserverToolFactory.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public boolean canUseEditWand(Permissible permissible) {
    return permissible.hasPermission(EDIT_WAND_PERMISSION);
}
 
Example 9
Source File: CommandUtils.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public static void assertPermission(Permissible permissible, String permission) throws CommandPermissionsException {
    if(!permissible.hasPermission(permission)) {
        throw new CommandPermissionsException();
    }
}
 
Example 10
Source File: CommandUtils.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public static void assertPermission(Permissible permissible, Permission permission) throws CommandPermissionsException {
    if(!permissible.hasPermission(permission)) {
        throw new CommandPermissionsException();
    }
}
 
Example 11
Source File: PermissionUtils.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public static boolean isStaff(Permissible permissible) {
    return permissible.hasPermission(Permissions.STAFF);
}
 
Example 12
Source File: GamePermissionUtil.java    From DiscordSRV with GNU General Public License v3.0 4 votes vote down vote up
public static boolean hasPermission(Permissible sender, String permission) {
    return sender instanceof ConsoleCommandSender || sender.hasPermission(permission);
}
 
Example 13
Source File: PermissionsService.java    From Slimefun4 with GNU General Public License v3.0 3 votes vote down vote up
/**
 * 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);
}