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();
}
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;
}
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);
}
}
}
}
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;
}
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();
}
Aggregations