Search in sources :

Example 1 with Permissible

use of org.bukkit.permissions.Permissible in project NoCheatPlus by NoCheatPlus.

the class NoCheatPlus method sendAdminNotifyMessageSubscriptions.

/**
 * Send notification to all CommandSenders found in permission subscriptions for the notify-permission as well as players that have stored permissions (those get re-checked here).
 * @param message
 * @return
 */
public int sendAdminNotifyMessageSubscriptions(final String message) {
    // TODO: Fetch from PlayerData - alt: update subscriptions on a regular basis - not every call!
    final String lcPerm = Permissions.NOTIFY.getLowerCaseStringRepresentation();
    final Permission bukkitPerm = Permissions.NOTIFY.getBukkitPermission();
    final Set<Permissible> permissibles = Bukkit.getPluginManager().getPermissionSubscriptions(lcPerm);
    final Set<String> done = new HashSet<String>(permissibles.size());
    for (final Permissible permissible : permissibles) {
        if (permissible instanceof CommandSender) {
            final CommandSender sender = (CommandSender) permissible;
            if (sender instanceof Player) {
                // Use the permission caching feature.
                final Player player = (Player) sender;
                final IPlayerData data = DataManager.getPlayerData(player);
                if (data.getNotifyOff() || !data.hasPermission(Permissions.NOTIFY, player)) {
                    continue;
                }
            } else if (!sender.hasPermission(bukkitPerm)) {
                // TODO: Add permission cache for non-player-things?
                continue;
            }
            // Finally send.
            sender.sendMessage(message);
            done.add(sender.getName());
        }
    }
    return done.size();
}
Also used : Player(org.bukkit.entity.Player) Permissible(org.bukkit.permissions.Permissible) RegisteredPermission(fr.neatmonster.nocheatplus.permissions.RegisteredPermission) Permission(org.bukkit.permissions.Permission) IPlayerData(fr.neatmonster.nocheatplus.players.IPlayerData) CommandSender(org.bukkit.command.CommandSender) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet)

Example 2 with Permissible

use of org.bukkit.permissions.Permissible in project LuckPerms by lucko.

the class InjectorSubscriptionMap method inject.

private LPSubscriptionMap inject() throws Exception {
    Objects.requireNonNull(PERM_SUBS_FIELD, "PERM_SUBS_FIELD");
    PluginManager pluginManager = this.plugin.getBootstrap().getServer().getPluginManager();
    if (!(pluginManager instanceof SimplePluginManager)) {
        this.plugin.getLogger().severe("PluginManager instance is not a 'SimplePluginManager', instead: " + pluginManager.getClass());
        this.plugin.getLogger().severe("Unable to inject LuckPerms Permission Subscription map.");
        return null;
    }
    Object map = PERM_SUBS_FIELD.get(pluginManager);
    if (map instanceof LPSubscriptionMap) {
        if (((LPSubscriptionMap) map).plugin == this.plugin) {
            return null;
        }
        map = ((LPSubscriptionMap) map).detach();
    }
    // noinspection unchecked
    Map<String, Map<Permissible, Boolean>> castedMap = (Map<String, Map<Permissible, Boolean>>) map;
    // make a new subscription map & inject it
    LPSubscriptionMap newMap = new LPSubscriptionMap(this.plugin, castedMap);
    PERM_SUBS_FIELD.set(pluginManager, newMap);
    return newMap;
}
Also used : SimplePluginManager(org.bukkit.plugin.SimplePluginManager) PluginManager(org.bukkit.plugin.PluginManager) Permissible(org.bukkit.permissions.Permissible) SimplePluginManager(org.bukkit.plugin.SimplePluginManager) Map(java.util.Map)

Example 3 with Permissible

use of org.bukkit.permissions.Permissible in project Bukkit by Bukkit.

the class Command method broadcastCommandMessage.

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) {
            CommandSender target = (CommandSender) user;
            if (target instanceof ConsoleCommandSender) {
                target.sendMessage(result);
            } else if (target != source) {
                target.sendMessage(colored);
            }
        }
    }
}
Also used : Permissible(org.bukkit.permissions.Permissible) CommandMinecart(org.bukkit.entity.minecart.CommandMinecart)

Example 4 with Permissible

use of org.bukkit.permissions.Permissible in project MassiveCore by MassiveCraft.

the class PermissionUtil method setAttachmentPermissions.

public static boolean setAttachmentPermissions(PermissionAttachment attachment, Map<String, Boolean> permissions) {
    if (attachment == null)
        throw new NullPointerException("attachment");
    if (permissions == null)
        return false;
    Map<String, Boolean> before = getAttachmentPermissions(attachment);
    if (before.equals(permissions))
        return false;
    before.clear();
    before.putAll(permissions);
    Permissible permissible = attachment.getPermissible();
    if (permissible != null)
        permissible.recalculatePermissions();
    return true;
}
Also used : Permissible(org.bukkit.permissions.Permissible)

Example 5 with Permissible

use of org.bukkit.permissions.Permissible in project Glowstone by GlowstoneMC.

the class GlowServer method broadcast.

@Override
public int broadcast(String message, String permission) {
    Set<CommandSender> sent = new HashSet<>();
    for (Permissible permissible : getPluginManager().getPermissionSubscriptions(permission)) {
        if (permissible instanceof CommandSender && permissible.hasPermission(permission)) {
            CommandSender cs = ((CommandSender) permissible);
            sent.add(cs);
        }
    }
    BroadcastMessageEvent event = EventFactory.getInstance().callEvent(new BroadcastMessageEvent(message, sent));
    if (event.isCancelled()) {
        return 0;
    }
    sent.forEach(cs -> cs.sendMessage(message));
    return sent.size();
}
Also used : BroadcastMessageEvent(org.bukkit.event.server.BroadcastMessageEvent) Permissible(org.bukkit.permissions.Permissible) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender) CommandSender(org.bukkit.command.CommandSender) HashSet(java.util.HashSet)

Aggregations

Permissible (org.bukkit.permissions.Permissible)5 HashSet (java.util.HashSet)2 CommandSender (org.bukkit.command.CommandSender)2 RegisteredPermission (fr.neatmonster.nocheatplus.permissions.RegisteredPermission)1 IPlayerData (fr.neatmonster.nocheatplus.players.IPlayerData)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1 ConsoleCommandSender (org.bukkit.command.ConsoleCommandSender)1 Player (org.bukkit.entity.Player)1 CommandMinecart (org.bukkit.entity.minecart.CommandMinecart)1 BroadcastMessageEvent (org.bukkit.event.server.BroadcastMessageEvent)1 Permission (org.bukkit.permissions.Permission)1 PluginManager (org.bukkit.plugin.PluginManager)1 SimplePluginManager (org.bukkit.plugin.SimplePluginManager)1