cn.nukkit.permission.Permissible Java Examples

The following examples show how to use cn.nukkit.permission.Permissible. 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: Command.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public static void broadcastCommandMessage(CommandSender source, String message, boolean sendToSource) {
    Set<Permissible> users = source.getServer().getPluginManager().getPermissionSubscriptions(Server.BROADCAST_CHANNEL_ADMINISTRATIVE);

    TranslationContainer result = new TranslationContainer("chat.type.admin", new String[]{source.getName(), message});

    TranslationContainer colored = new TranslationContainer(TextFormat.GRAY + "" + TextFormat.ITALIC + "%chat.type.admin", new String[]{source.getName(), message});

    if (sendToSource && !(source instanceof ConsoleCommandSender)) {
        source.sendMessage(message);
    }

    for (Permissible user : users) {
        if (user instanceof CommandSender) {
            if (user instanceof ConsoleCommandSender) {
                ((ConsoleCommandSender) user).sendMessage(result);
            } else if (!user.equals(source)) {
                ((CommandSender) user).sendMessage(colored);
            }
        }
    }
}
 
Example #2
Source File: LuckPermsSubscriptionMap.java    From LuckPerms with MIT License 6 votes vote down vote up
@Override
public Set<Permissible> get(Object key) {
    if (key == null || !(key instanceof String)) {
        return null;
    }

    String permission = ((String) key);

    LPSubscriptionValueSet result = (LPSubscriptionValueSet) super.get(key);
    if (result == null) {
        // calculate a new map - always!
        result = new LPSubscriptionValueSet(permission);
        super.put(permission, result);
    }

    return result;
}
 
Example #3
Source File: Command.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public static void broadcastCommandMessage(CommandSender source, String message, boolean sendToSource) {
    Set<Permissible> users = source.getServer().getPluginManager().getPermissionSubscriptions(Server.BROADCAST_CHANNEL_ADMINISTRATIVE);

    TranslationContainer result = new TranslationContainer("chat.type.admin", source.getName(), message);

    TranslationContainer colored = new TranslationContainer(TextFormat.GRAY + "" + TextFormat.ITALIC + "%chat.type.admin", source.getName(), message);

    if (sendToSource && !(source instanceof ConsoleCommandSender)) {
        source.sendMessage(message);
    }

    for (Permissible user : users) {
        if (user instanceof CommandSender) {
            if (user instanceof ConsoleCommandSender) {
                ((ConsoleCommandSender) user).sendMessage(result);
            } else if (!user.equals(source)) {
                ((CommandSender) user).sendMessage(colored);
            }
        }
    }
}
 
Example #4
Source File: PlayerChatEvent.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public PlayerChatEvent(Player player, String message, String format, Set<CommandSender> recipients) {
    this.player = player;
    this.message = message;

    this.format = format;

    if (recipients == null) {
        for (Permissible permissible : Server.getInstance().getPluginManager().getPermissionSubscriptions(Server.BROADCAST_CHANNEL_USERS)) {
            if (permissible instanceof CommandSender) {
                this.recipients.add((CommandSender) permissible);
            }
        }

    } else {
        this.recipients = recipients;
    }
}
 
Example #5
Source File: Server.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public int broadcast(TextContainer message, String permissions) {
    Set<CommandSender> recipients = new HashSet<>();

    for (String permission : permissions.split(";")) {
        for (Permissible permissible : this.pluginManager.getPermissionSubscriptions(permission)) {
            if (permissible instanceof CommandSender && permissible.hasPermission(permission)) {
                recipients.add((CommandSender) permissible);
            }
        }
    }

    for (CommandSender recipient : recipients) {
        recipient.sendMessage(message);
    }

    return recipients.size();
}
 
Example #6
Source File: Server.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public int broadcast(String message, String permissions) {
    Set<CommandSender> recipients = new HashSet<>();

    for (String permission : permissions.split(";")) {
        for (Permissible permissible : this.pluginManager.getPermissionSubscriptions(permission)) {
            if (permissible instanceof CommandSender && permissible.hasPermission(permission)) {
                recipients.add((CommandSender) permissible);
            }
        }
    }

    for (CommandSender recipient : recipients) {
        recipient.sendMessage(message);
    }

    return recipients.size();
}
 
Example #7
Source File: LuckPermsSubscriptionMap.java    From LuckPerms with MIT License 6 votes vote down vote up
@Override
public boolean contains(Object key) {
    // try the backing map
    if (this.backing.contains(key)) {
        return true;
    }

    // then try the permissible
    if (key instanceof Permissible) {
        Permissible p = (Permissible) key;
        return p.hasPermission(this.permission);
    }

    // no result
    return false;
}
 
Example #8
Source File: InjectorSubscriptionMap.java    From LuckPerms with MIT License 6 votes vote down vote up
private LuckPermsSubscriptionMap inject() throws Exception {
    Objects.requireNonNull(PERM_SUBS_FIELD, "PERM_SUBS_FIELD");
    PluginManager pluginManager = this.plugin.getBootstrap().getServer().getPluginManager();

    Object map = PERM_SUBS_FIELD.get(pluginManager);
    if (map instanceof LuckPermsSubscriptionMap) {
        if (((LuckPermsSubscriptionMap) map).plugin == this.plugin) {
            return null;
        }

        map = ((LuckPermsSubscriptionMap) map).detach();
    }

    //noinspection unchecked
    Map<String, Set<Permissible>> castedMap = (Map<String, Set<Permissible>>) map;

    // make a new subscription map & inject it
    LuckPermsSubscriptionMap newMap = new LuckPermsSubscriptionMap(this.plugin, castedMap);
    PERM_SUBS_FIELD.set(pluginManager, newMap);
    return newMap;
}
 
Example #9
Source File: Command.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
public static void broadcastCommandMessage(CommandSender source, String message, boolean sendToSource) {
    Set<Permissible> users = source.getServer().getPluginManager().getPermissionSubscriptions(Server.BROADCAST_CHANNEL_ADMINISTRATIVE);

    TranslationContainer result = new TranslationContainer("chat.type.admin", new String[]{source.getName(), message});

    TranslationContainer colored = new TranslationContainer(TextFormat.GRAY + "" + TextFormat.ITALIC + "%chat.type.admin", new String[]{source.getName(), message});

    if (sendToSource && !(source instanceof ConsoleCommandSender)) {
        source.sendMessage(message);
    }

    for (Permissible user : users) {
        if (user instanceof CommandSender) {
            if (user instanceof ConsoleCommandSender) {
                ((ConsoleCommandSender) user).sendMessage(result);
            } else if (!user.equals(source)) {
                ((CommandSender) user).sendMessage(colored);
            }
        }
    }
}
 
Example #10
Source File: PlayerChatEvent.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
public PlayerChatEvent(Player player, String message, String format, Set<CommandSender> recipients) {
    this.player = player;
    this.message = message;

    this.format = format;

    if (recipients == null) {
        for (Permissible permissible : Server.getInstance().getPluginManager().getPermissionSubscriptions(Server.BROADCAST_CHANNEL_USERS)) {
            if (permissible instanceof CommandSender) {
                this.recipients.add((CommandSender) permissible);
            }
        }

    } else {
        this.recipients = recipients;
    }
}
 
Example #11
Source File: Server.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
public int broadcastImportantMessage(String message, String permissions) {
    Set<CommandSender> recipients = new HashSet<>();

    for (String permission : permissions.split(";")) {
        for (Permissible permissible : this.pluginManager.getPermissionSubscriptions(permission)) {
            if (permissible instanceof CommandSender && permissible.hasPermission(permission)) {
                recipients.add((CommandSender) permissible);
            }
        }
    }

    for (CommandSender recipient : recipients) {
        recipient.sendImportantMessage(message);
    }

    return recipients.size();
}
 
Example #12
Source File: Server.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
public int broadcastTitle(String message, String permissions) {
    Set<Player> recipients = new HashSet<>();

    for (String permission : permissions.split(";")) {
        for (Permissible permissible : this.pluginManager.getPermissionSubscriptions(permission)) {
            if (permissible instanceof Player && permissible.hasPermission(permission)) {
                recipients.add((Player) permissible);
            }
        }
    }

    for (Player recipient : recipients) {
        recipient.sendTitle(message);
    }

    return recipients.size();
}
 
Example #13
Source File: PlayerChatEvent.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public PlayerChatEvent(Player player, String message, String format, Set<CommandSender> recipients) {
    this.player = player;
    this.message = message;

    this.format = format;

    if (recipients == null) {
        for (Permissible permissible : Server.getInstance().getPluginManager().getPermissionSubscriptions(Server.BROADCAST_CHANNEL_USERS)) {
            if (permissible instanceof CommandSender) {
                this.recipients.add((CommandSender) permissible);
            }
        }

    } else {
        this.recipients = recipients;
    }
}
 
Example #14
Source File: Server.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public int broadcast(TextContainer message, String permissions) {
    Set<CommandSender> recipients = new HashSet<>();

    for (String permission : permissions.split(";")) {
        for (Permissible permissible : this.pluginManager.getPermissionSubscriptions(permission)) {
            if (permissible instanceof CommandSender && permissible.hasPermission(permission)) {
                recipients.add((CommandSender) permissible);
            }
        }
    }

    for (CommandSender recipient : recipients) {
        recipient.sendMessage(message);
    }

    return recipients.size();
}
 
Example #15
Source File: Server.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public int broadcast(String message, String permissions) {
    Set<CommandSender> recipients = new HashSet<>();

    for (String permission : permissions.split(";")) {
        for (Permissible permissible : this.pluginManager.getPermissionSubscriptions(permission)) {
            if (permissible instanceof CommandSender && permissible.hasPermission(permission)) {
                recipients.add((CommandSender) permissible);
            }
        }
    }

    for (CommandSender recipient : recipients) {
        recipient.sendMessage(message);
    }

    return recipients.size();
}
 
Example #16
Source File: Server.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
public int broadcast(String message, String permissions) {
    Set<CommandSender> recipients = new HashSet<>();

    for (String permission : permissions.split(";")) {
        for (Permissible permissible : this.pluginManager.getPermissionSubscriptions(permission)) {
            if (permissible instanceof CommandSender && permissible.hasPermission(permission)) {
                recipients.add((CommandSender) permissible);
            }
        }
    }

    for (CommandSender recipient : recipients) {
        recipient.sendMessage(message);
    }

    return recipients.size();
}
 
Example #17
Source File: Server.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
public int broadcast(TextContainer message, String permissions) {
    Set<CommandSender> recipients = new HashSet<>();

    for (String permission : permissions.split(";")) {
        for (Permissible permissible : this.pluginManager.getPermissionSubscriptions(permission)) {
            if (permissible instanceof CommandSender && permissible.hasPermission(permission)) {
                recipients.add((CommandSender) permissible);
            }
        }
    }

    for (CommandSender recipient : recipients) {
        recipient.sendMessage(message);
    }

    return recipients.size();
}
 
Example #18
Source File: Server.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
public int broadcastPopup(String message, String permissions) {
    Set<Player> recipients = new HashSet<>();

    for (String permission : permissions.split(";")) {
        for (Permissible permissible : this.pluginManager.getPermissionSubscriptions(permission)) {
            if (permissible instanceof Player && permissible.hasPermission(permission)) {
                recipients.add((Player) permissible);
            }
        }
    }

    for (Player recipient : recipients) {
        recipient.sendPopup(message);
    }

    return recipients.size();
}
 
Example #19
Source File: Server.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
public int broadcastTip(String message, String permissions) {
    Set<Player> recipients = new HashSet<>();

    for (String permission : permissions.split(";")) {
        for (Permissible permissible : this.pluginManager.getPermissionSubscriptions(permission)) {
            if (permissible instanceof Player && permissible.hasPermission(permission)) {
                recipients.add((Player) permissible);
            }
        }
    }

    for (Player recipient : recipients) {
        recipient.sendTip(message);
    }

    return recipients.size();
}
 
Example #20
Source File: Server.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
public int broadcastSubtitle(String message, String permissions) {
    Set<Player> recipients = new HashSet<>();

    for (String permission : permissions.split(";")) {
        for (Permissible permissible : this.pluginManager.getPermissionSubscriptions(permission)) {
            if (permissible instanceof Player && permissible.hasPermission(permission)) {
                recipients.add((Player) permissible);
            }
        }
    }

    for (Player recipient : recipients) {
        recipient.setSubtitle(message);
    }

    return recipients.size();
}
 
Example #21
Source File: PluginManager.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void unsubscribeFromPermission(String permission, Permissible permissible) {
    if (this.permSubs.containsKey(permission)) {
        this.permSubs.get(permission).remove(permissible);
        if (this.permSubs.get(permission).size() == 0) {
            this.permSubs.remove(permission);
        }
    }
}
 
Example #22
Source File: PluginManager.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public Set<Permissible> getPermissionSubscriptions(String permission) {
    if (this.permSubs.containsKey(permission)) {
        Set<Permissible> subs = new HashSet<>();
        for (Permissible p : this.permSubs.get(permission).values()) {
            subs.add(p);
        }
        return subs;
    }

    return new HashSet<>();
}
 
Example #23
Source File: LuckPermsSubscriptionMap.java    From LuckPerms with MIT License 5 votes vote down vote up
@Override
public boolean add(Permissible permissible) {
    // don't allow players to be put into this map
    if (permissible instanceof Player) {
        return true;
    }

    return this.backing.add(permissible);
}
 
Example #24
Source File: PluginManager.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void subscribeToDefaultPerms(boolean op, Permissible permissible) {
    if (op) {
        this.defSubsOp.put(permissible, permissible);
    } else {
        this.defSubs.put(permissible, permissible);
    }
}
 
Example #25
Source File: LuckPermsSubscriptionMap.java    From LuckPerms with MIT License 5 votes vote down vote up
private Set<Permissible> getContentView() {
    // gather players (LPPermissibles)
    Set<Permissible> players = LuckPermsSubscriptionMap.this.plugin.getBootstrap().getServer().getOnlinePlayers().values().stream()
            .filter(player -> player.hasPermission(this.permission) || player.isPermissionSet(this.permission))
            .collect(Collectors.toSet());

    ImmutableSet<Permissible> backing;
    synchronized (this.backing) {
        backing = ImmutableSet.copyOf(this.backing);
    }

    return Sets.union(players, backing);
}
 
Example #26
Source File: LuckPermsSubscriptionMap.java    From LuckPerms with MIT License 5 votes vote down vote up
private LPSubscriptionValueSet(String permission, Set<Permissible> content) {
    this.permission = permission;
    this.backing = Collections.synchronizedSet(Collections.newSetFromMap(new WeakHashMap<>()));
    
    if (content != null) {
        this.backing.addAll(content);
    }

    // remove all players from the map
    this.backing.removeIf(p -> p instanceof Player);
}
 
Example #27
Source File: PluginManager.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void unsubscribeFromDefaultPerms(boolean op, Permissible permissible) {
    if (op) {
        this.defSubsOp.remove(permissible);
    } else {
        this.defSubs.remove(permissible);
    }
}
 
Example #28
Source File: LuckPermsSubscriptionMap.java    From LuckPerms with MIT License 5 votes vote down vote up
/**
 * Converts this map back to a standard HashMap
 *
 * @return a standard representation of this map
 */
public Map<String, Set<Permissible>> detach() {
    Map<String, Set<Permissible>> map = new HashMap<>();
    for (Map.Entry<String, Set<Permissible>> ent : entrySet()) {
        Set<Permissible> backing = ((LPSubscriptionValueSet) ent.getValue()).backing;
        Set<Permissible> copy = Collections.newSetFromMap(new WeakHashMap<>(backing.size()));
        copy.addAll(backing);
        map.put(ent.getKey(), copy);
    }
    return map;
}
 
Example #29
Source File: LuckPermsSubscriptionMap.java    From LuckPerms with MIT License 5 votes vote down vote up
@Override
public Set<Permissible> put(String key, Set<Permissible> value) {
    if (value == null) {
        throw new NullPointerException("Map value cannot be null");
    }

    // ensure values are LP subscription maps
    if (!(value instanceof LPSubscriptionValueSet)) {
        value = new LPSubscriptionValueSet(key, value);
    }
    return super.put(key, value);
}
 
Example #30
Source File: Command.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public static void broadcastCommandMessage(CommandSender source, TextContainer message, boolean sendToSource) {
    TextContainer m = message.clone();
    String resultStr = "[" + source.getName() + ": " + (!m.getText().equals(source.getServer().getLanguage().get(m.getText())) ? "%" : "") + m.getText() + "]";

    Set<Permissible> users = source.getServer().getPluginManager().getPermissionSubscriptions(Server.BROADCAST_CHANNEL_ADMINISTRATIVE);

    String coloredStr = TextFormat.GRAY + "" + TextFormat.ITALIC + resultStr;

    m.setText(resultStr);
    TextContainer result = m.clone();
    m.setText(coloredStr);
    TextContainer colored = m.clone();

    if (sendToSource && !(source instanceof ConsoleCommandSender)) {
        source.sendMessage(message);
    }

    for (Permissible user : users) {
        if (user instanceof CommandSender) {
            if (user instanceof ConsoleCommandSender) {
                ((ConsoleCommandSender) user).sendMessage(result);
            } else if (!user.equals(source)) {
                ((CommandSender) user).sendMessage(colored);
            }
        }
    }
}