下面列出了怎么用org.bukkit.permissions.PermissionAttachment的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public void enable() {
final PermissionAttachment attachment = Bukkit.getConsoleSender().addAttachment(plugin);
Stream.of(
PERMISSION,
PERMISSION_GET,
PERMISSION_SET,
PERMISSION_ANY,
PERMISSION_ANY_GET,
PERMISSION_ANY_SET,
PERMISSION_IMMEDIATE
).forEach(name -> {
final Permission permission = new Permission(name, PermissionDefault.FALSE);
pluginManager.addPermission(permission);
attachment.setPermission(permission, true);
});
}
protected void applyPermissions(Player player, UserDoc.Login userDoc) {
boolean op = false;
final Server localServer = minecraftService.getLocalServer();
if(localServer.operators().containsKey(player.getUniqueId())) {
logger.info("Opping " + player.getName() + " because they are in the server op list");
op = true;
}
if(localServer.team() != null && localServer.team().members().contains(userDoc)) {
logger.info("Opping " + player.getName() + " because they are on the team that owns the server");
op = true;
}
PermissionAttachment attachment = player.addAttachment(this.plugin);
PermissionUtils.setPermissions(attachment, Permissions.mergePermissions(localServer.realms(), userDoc.mc_permissions_by_realm()));
player.recalculatePermissions();
if(player.hasPermission("op")) {
op = true;
logger.info("Opping " + player.getName() + " because they have the op permission node");
}
player.setOp(op); // This is always explicitly set to true or false on login
}
@Override
public @NonNull PermissionAttachment addAttachment(@NonNull Plugin plugin, @NonNull String permission, boolean value) {
Objects.requireNonNull(plugin, "plugin");
Objects.requireNonNull(permission, "permission");
PermissionAttachment attachment = addAttachment(plugin);
attachment.setPermission(permission, value);
return attachment;
}
@Override
public boolean add(PermissionAttachment attachment) {
if (LuckPermsPermissible.this.hookedAttachments.stream().anyMatch(at -> at.getSource() == attachment)) {
return false;
}
new LuckPermsPermissionAttachment(LuckPermsPermissible.this, attachment).hook();
return true;
}
@Override
public boolean addAll(@NonNull Collection<? extends PermissionAttachment> c) {
boolean modified = false;
for (PermissionAttachment e : c) {
if (add(e)) {
modified = true;
}
}
return modified;
}
public LuckPermsPermissionAttachment(LuckPermsPermissible permissible, PermissionAttachment source) {
super(source.getPlugin(), null);
this.permissible = permissible;
this.owner = source.getPlugin();
// copy
this.perms.putAll(source.getPermissions());
this.source = source;
injectFakeMap();
}
@Override
public PermissionAttachment addAttachment(Plugin plugin) {
validateOnline();
return getBukkitPlayer().addAttachment(plugin);
}
@Override
public PermissionAttachment addAttachment(Plugin plugin) {
return null;
}
public void removeAttachment(PermissionAttachment attachment) {
this.perm.removeAttachment(attachment);
}
@Override
public PermissionAttachment addAttachment(Plugin plugin, int ticks) {
return null;
}
public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value, int ticks) {
return perm.addAttachment(plugin, name, value, ticks);
}
public PermissionAttachment addAttachment(Plugin plugin) {
return perm.addAttachment(plugin);
}
public PermissionAttachment addAttachment(Plugin plugin) {
return this.perm.addAttachment(plugin);
}
public PermissionAttachment addAttachment(Plugin plugin, int ticks) {
return perm.addAttachment(plugin, ticks);
}
public void removeAttachment(PermissionAttachment attachment) {
perm.removeAttachment(attachment);
}
public PermissionAttachment addAttachment(Plugin plugin, int ticks) {
return perm.addAttachment(plugin, ticks);
}
@Override
public PermissionAttachment addAttachment(Plugin plugin) {
return perm.addAttachment(plugin);
}
@Override
public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value, int ticks) {
return perm.addAttachment(plugin, name, value, ticks);
}
@Override
public PermissionAttachment addAttachment(Plugin plugin, int ticks) {
return perm.addAttachment(plugin, ticks);
}
@Override
public void removeAttachment(PermissionAttachment attachment) {
perm.removeAttachment(attachment);
}
@Override
public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value) {
return getCaller().addAttachment(plugin, name, value);
}
@Override
public PermissionAttachment addAttachment(Plugin plugin) {
return getCaller().addAttachment(plugin);
}
@Override
public void removeAttachment(PermissionAttachment attachment) {
perm.removeAttachment(attachment);
}
public PermissionAttachment addAttachment(Plugin plugin) {
return perm.addAttachment(plugin);
}
@Override
public void removeAttachment(PermissionAttachment attachment)
{
oldPermissible.removeAttachment(attachment);
}
public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value) {
return perm.addAttachment(plugin, name, value);
}
public PermissionAttachment addAttachment(Plugin plugin) {
return perm.addAttachment(plugin);
}
public PermissionAttachment getPerms() {
return perms;
}
public PermissionAttachment addAttachment(Plugin plugin, int ticks) {
return perm.addAttachment(plugin, ticks);
}
public void removeAttachment(PermissionAttachment attachment) {
perm.removeAttachment(attachment);
}