1 package org.bukkit.permissions;
3 import java.util.HashMap;
4 import java.util.HashSet;
5 import java.util.LinkedList;
9 import java.util.logging.Level;
10 import org.bukkit.Bukkit;
11 import org.bukkit.plugin.Plugin;
19 private final List<PermissionAttachment> attachments =
new LinkedList<PermissionAttachment>();
20 private final Map<String, PermissionAttachmentInfo> permissions =
new HashMap<String, PermissionAttachmentInfo>();
26 this.parent = (Permissible) opable;
40 public void setOp(
boolean value) {
42 throw new UnsupportedOperationException(
"Cannot change op value as no ServerOperator is set");
50 throw new IllegalArgumentException(
"Permission name cannot be null");
53 return permissions.containsKey(name.toLowerCase());
58 throw new IllegalArgumentException(
"Permission cannot be null");
66 throw new IllegalArgumentException(
"Permission name cannot be null");
69 String name = inName.toLowerCase();
72 return permissions.get(name).getValue();
86 throw new IllegalArgumentException(
"Permission cannot be null");
89 String name = perm.
getName().toLowerCase();
92 return permissions.get(name).getValue();
99 throw new IllegalArgumentException(
"Permission name cannot be null");
100 }
else if (plugin == null) {
101 throw new IllegalArgumentException(
"Plugin cannot be null");
115 if (plugin == null) {
116 throw new IllegalArgumentException(
"Plugin cannot be null");
123 attachments.add(result);
130 if (attachment == null) {
131 throw new IllegalArgumentException(
"Attachment cannot be null");
134 if (attachments.contains(attachment)) {
135 attachments.remove(attachment);
144 throw new IllegalArgumentException(
"Given attachment is not part of Permissible object " + parent);
154 String name = perm.getName().toLowerCase();
157 calculateChildPermissions(perm.getChildren(),
false, null);
161 calculateChildPermissions(attachment.getPermissions(),
false, attachment);
166 Set<String> perms = permissions.keySet();
168 for (String name : perms) {
178 private void calculateChildPermissions(Map<String, Boolean> children,
boolean invert,
PermissionAttachment attachment) {
179 Set<String> keys = children.keySet();
181 for (String name : keys) {
183 boolean value = children.get(name) ^ invert;
184 String lname = name.toLowerCase();
190 calculateChildPermissions(perm.
getChildren(), !value, attachment);
197 throw new IllegalArgumentException(
"Permission name cannot be null");
198 }
else if (plugin == null) {
199 throw new IllegalArgumentException(
"Plugin cannot be null");
206 if (result != null) {
214 if (plugin == null) {
215 throw new IllegalArgumentException(
"Plugin cannot be null");
232 return new HashSet<PermissionAttachmentInfo>(permissions.values());
235 private class RemoveAttachmentRunnable
implements Runnable {
239 this.attachment = attachment;