Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
org.bukkit.permissions.PermissibleBase Class Reference
Inheritance diagram for org.bukkit.permissions.PermissibleBase:
org.bukkit.permissions.Permissible org.bukkit.permissions.ServerOperator

Public Member Functions

 PermissibleBase (ServerOperator opable)
 
boolean isOp ()
 
void setOp (boolean value)
 
boolean isPermissionSet (String name)
 
boolean isPermissionSet (Permission perm)
 
boolean hasPermission (String inName)
 
boolean hasPermission (Permission perm)
 
PermissionAttachment addAttachment (Plugin plugin, String name, boolean value)
 
PermissionAttachment addAttachment (Plugin plugin)
 
void removeAttachment (PermissionAttachment attachment)
 
void recalculatePermissions ()
 
synchronized void clearPermissions ()
 
PermissionAttachment addAttachment (Plugin plugin, String name, boolean value, int ticks)
 
PermissionAttachment addAttachment (Plugin plugin, int ticks)
 
Set< PermissionAttachmentInfogetEffectivePermissions ()
 

Detailed Description

Base Permissible for use in any Permissible object via proxy or extension

Definition at line 16 of file PermissibleBase.java.

Member Function Documentation

PermissionAttachment org.bukkit.permissions.PermissibleBase.addAttachment ( Plugin  plugin,
String  name,
boolean  value 
)

Adds a new PermissionAttachment with a single permission by name and value

Parameters
pluginPlugin responsible for this attachment, may not be null or disabled
nameName of the permission to attach
valueValue of the permission
Returns
The PermissionAttachment that was just created

Implements org.bukkit.permissions.Permissible.

Definition at line 97 of file PermissibleBase.java.

References org.bukkit.plugin.Plugin.getDescription(), org.bukkit.plugin.PluginDescriptionFile.getFullName(), org.bukkit.plugin.Plugin.isEnabled(), org.bukkit.permissions.PermissibleBase.recalculatePermissions(), and org.bukkit.permissions.PermissionAttachment.setPermission().

Referenced by org.bukkit.permissions.PermissibleBase.addAttachment().

97  {
98  if (name == null) {
99  throw new IllegalArgumentException("Permission name cannot be null");
100  } else if (plugin == null) {
101  throw new IllegalArgumentException("Plugin cannot be null");
102  } else if (!plugin.isEnabled()) {
103  throw new IllegalArgumentException("Plugin " + plugin.getDescription().getFullName() + " is disabled");
104  }
105 
106  PermissionAttachment result = addAttachment(plugin);
107  result.setPermission(name, value);
108 
110 
111  return result;
112  }
PermissionAttachment addAttachment(Plugin plugin, String name, boolean value)
PermissionAttachment org.bukkit.permissions.PermissibleBase.addAttachment ( Plugin  plugin)

Adds a new empty PermissionAttachment to this object

Parameters
pluginPlugin responsible for this attachment, may not be null or disabled
Returns
The PermissionAttachment that was just created

Implements org.bukkit.permissions.Permissible.

Definition at line 114 of file PermissibleBase.java.

References org.bukkit.plugin.Plugin.getDescription(), org.bukkit.plugin.PluginDescriptionFile.getFullName(), org.bukkit.plugin.Plugin.isEnabled(), and org.bukkit.permissions.PermissibleBase.recalculatePermissions().

114  {
115  if (plugin == null) {
116  throw new IllegalArgumentException("Plugin cannot be null");
117  } else if (!plugin.isEnabled()) {
118  throw new IllegalArgumentException("Plugin " + plugin.getDescription().getFullName() + " is disabled");
119  }
120 
121  PermissionAttachment result = new PermissionAttachment(plugin, parent);
122 
123  attachments.add(result);
125 
126  return result;
127  }
PermissionAttachment org.bukkit.permissions.PermissibleBase.addAttachment ( Plugin  plugin,
String  name,
boolean  value,
int  ticks 
)

Temporarily adds a new PermissionAttachment with a single permission by name and value

Parameters
pluginPlugin responsible for this attachment, may not be null or disabled
nameName of the permission to attach
valueValue of the permission
ticksAmount of ticks to automatically remove this attachment after
Returns
The PermissionAttachment that was just created

Implements org.bukkit.permissions.Permissible.

Definition at line 195 of file PermissibleBase.java.

References org.bukkit.permissions.PermissibleBase.addAttachment(), org.bukkit.plugin.Plugin.getDescription(), org.bukkit.plugin.PluginDescriptionFile.getFullName(), org.bukkit.plugin.Plugin.isEnabled(), and org.bukkit.permissions.PermissionAttachment.setPermission().

195  {
196  if (name == null) {
197  throw new IllegalArgumentException("Permission name cannot be null");
198  } else if (plugin == null) {
199  throw new IllegalArgumentException("Plugin cannot be null");
200  } else if (!plugin.isEnabled()) {
201  throw new IllegalArgumentException("Plugin " + plugin.getDescription().getFullName() + " is disabled");
202  }
203 
204  PermissionAttachment result = addAttachment(plugin, ticks);
205 
206  if (result != null) {
207  result.setPermission(name, value);
208  }
209 
210  return result;
211  }
PermissionAttachment addAttachment(Plugin plugin, String name, boolean value)
PermissionAttachment org.bukkit.permissions.PermissibleBase.addAttachment ( Plugin  plugin,
int  ticks 
)

Temporarily adds a new empty PermissionAttachment to this object

Parameters
pluginPlugin responsible for this attachment, may not be null or disabled
ticksAmount of ticks to automatically remove this attachment after
Returns
The PermissionAttachment that was just created

Implements org.bukkit.permissions.Permissible.

Definition at line 213 of file PermissibleBase.java.

References org.bukkit.permissions.PermissibleBase.addAttachment(), org.bukkit.plugin.Plugin.getDescription(), org.bukkit.plugin.PluginDescriptionFile.getFullName(), org.bukkit.Server.getLogger(), org.bukkit.Server.getScheduler(), org.bukkit.Bukkit.getServer(), org.bukkit.plugin.Plugin.isEnabled(), org.bukkit.permissions.PermissionAttachment.remove(), and org.bukkit.scheduler.BukkitScheduler.scheduleSyncDelayedTask().

213  {
214  if (plugin == null) {
215  throw new IllegalArgumentException("Plugin cannot be null");
216  } else if (!plugin.isEnabled()) {
217  throw new IllegalArgumentException("Plugin " + plugin.getDescription().getFullName() + " is disabled");
218  }
219 
220  PermissionAttachment result = addAttachment(plugin);
221 
222  if (Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new RemoveAttachmentRunnable(result), ticks) == -1) {
223  Bukkit.getServer().getLogger().log(Level.WARNING, "Could not add PermissionAttachment to " + parent + " for plugin " + plugin.getDescription().getFullName() + ": Scheduler returned -1");
224  result.remove();
225  return null;
226  } else {
227  return result;
228  }
229  }
PermissionAttachment addAttachment(Plugin plugin, String name, boolean value)
Set<PermissionAttachmentInfo> org.bukkit.permissions.PermissibleBase.getEffectivePermissions ( )

Gets a set containing all of the permissions currently in effect by this object

Returns
Set of currently effective permissions

Implements org.bukkit.permissions.Permissible.

Definition at line 231 of file PermissibleBase.java.

231  {
232  return new HashSet<PermissionAttachmentInfo>(permissions.values());
233  }
boolean org.bukkit.permissions.PermissibleBase.hasPermission ( String  name)

Gets the value of the specified permission, if set.

If a permission override is not set on this object, the default value of the permission will be returned.

Parameters
nameName of the permission
Returns
Value of the permission

Implements org.bukkit.permissions.Permissible.

Definition at line 64 of file PermissibleBase.java.

References org.bukkit.permissions.Permission.getDefault(), org.bukkit.plugin.PluginManager.getPermission(), org.bukkit.Server.getPluginManager(), org.bukkit.Bukkit.getServer(), org.bukkit.permissions.PermissionDefault.getValue(), org.bukkit.permissions.PermissibleBase.isOp(), and org.bukkit.permissions.PermissibleBase.isPermissionSet().

64  {
65  if (inName == null) {
66  throw new IllegalArgumentException("Permission name cannot be null");
67  }
68 
69  String name = inName.toLowerCase();
70 
71  if (isPermissionSet(name)) {
72  return permissions.get(name).getValue();
73  } else {
74  Permission perm = Bukkit.getServer().getPluginManager().getPermission(name);
75 
76  if (perm != null) {
77  return perm.getDefault().getValue(isOp());
78  } else {
79  return Permission.DEFAULT_PERMISSION.getValue(isOp());
80  }
81  }
82  }
boolean org.bukkit.permissions.PermissibleBase.hasPermission ( Permission  perm)

Gets the value of the specified permission, if set.

If a permission override is not set on this object, the default value of the permission will be returned

Parameters
permPermission to get
Returns
Value of the permission

Implements org.bukkit.permissions.Permissible.

Definition at line 84 of file PermissibleBase.java.

References org.bukkit.permissions.Permission.getDefault(), org.bukkit.permissions.Permission.getName(), org.bukkit.permissions.PermissionDefault.getValue(), org.bukkit.permissions.PermissibleBase.isOp(), and org.bukkit.permissions.PermissibleBase.isPermissionSet().

84  {
85  if (perm == null) {
86  throw new IllegalArgumentException("Permission cannot be null");
87  }
88 
89  String name = perm.getName().toLowerCase();
90 
91  if (isPermissionSet(name)) {
92  return permissions.get(name).getValue();
93  }
94  return perm.getDefault().getValue(isOp());
95  }
boolean org.bukkit.permissions.PermissibleBase.isOp ( )

Checks if this object is a server operator

Returns
true if this is an operator, otherwise false

Implements org.bukkit.permissions.ServerOperator.

Definition at line 32 of file PermissibleBase.java.

References org.bukkit.permissions.ServerOperator.isOp().

Referenced by org.bukkit.permissions.PermissibleBase.hasPermission(), and org.bukkit.permissions.PermissibleBase.recalculatePermissions().

32  {
33  if (opable == null) {
34  return false;
35  } else {
36  return opable.isOp();
37  }
38  }
boolean org.bukkit.permissions.PermissibleBase.isPermissionSet ( String  name)

Checks if this object contains an override for the specified permission, by fully qualified name

Parameters
nameName of the permission
Returns
true if the permission is set, otherwise false

Implements org.bukkit.permissions.Permissible.

Definition at line 48 of file PermissibleBase.java.

Referenced by org.bukkit.permissions.PermissibleBase.hasPermission(), and org.bukkit.permissions.PermissibleBase.isPermissionSet().

48  {
49  if (name == null) {
50  throw new IllegalArgumentException("Permission name cannot be null");
51  }
52 
53  return permissions.containsKey(name.toLowerCase());
54  }
boolean org.bukkit.permissions.PermissibleBase.isPermissionSet ( Permission  perm)

Checks if this object contains an override for the specified Permission

Parameters
permPermission to check
Returns
true if the permission is set, otherwise false

Implements org.bukkit.permissions.Permissible.

Definition at line 56 of file PermissibleBase.java.

References org.bukkit.permissions.Permission.getName(), and org.bukkit.permissions.PermissibleBase.isPermissionSet().

56  {
57  if (perm == null) {
58  throw new IllegalArgumentException("Permission cannot be null");
59  }
60 
61  return isPermissionSet(perm.getName());
62  }
void org.bukkit.permissions.PermissibleBase.recalculatePermissions ( )

Recalculates the permissions for this object, if the attachments have changed values.

This should very rarely need to be called from a plugin.

Implements org.bukkit.permissions.Permissible.

Definition at line 148 of file PermissibleBase.java.

References org.bukkit.plugin.PluginManager.getDefaultPermissions(), org.bukkit.Server.getPluginManager(), org.bukkit.Bukkit.getServer(), org.bukkit.permissions.PermissibleBase.isOp(), org.bukkit.plugin.PluginManager.subscribeToDefaultPerms(), and org.bukkit.plugin.PluginManager.subscribeToPermission().

Referenced by org.bukkit.permissions.PermissibleBase.addAttachment(), and org.bukkit.permissions.PermissibleBase.removeAttachment().

148  {
149  clearPermissions();
150  Set<Permission> defaults = Bukkit.getServer().getPluginManager().getDefaultPermissions(isOp());
151  Bukkit.getServer().getPluginManager().subscribeToDefaultPerms(isOp(), parent);
152 
153  for (Permission perm : defaults) {
154  String name = perm.getName().toLowerCase();
155  permissions.put(name, new PermissionAttachmentInfo(parent, name, null, true));
156  Bukkit.getServer().getPluginManager().subscribeToPermission(name, parent);
157  calculateChildPermissions(perm.getChildren(), false, null);
158  }
159 
160  for (PermissionAttachment attachment : attachments) {
161  calculateChildPermissions(attachment.getPermissions(), false, attachment);
162  }
163  }
void org.bukkit.permissions.PermissibleBase.removeAttachment ( PermissionAttachment  attachment)

Removes the given PermissionAttachment from this object

Parameters
attachmentAttachment to remove
Exceptions
IllegalArgumentExceptionThrown when the specified attachment isn't part of this object

Implements org.bukkit.permissions.Permissible.

Definition at line 129 of file PermissibleBase.java.

References org.bukkit.permissions.PermissionRemovedExecutor.attachmentRemoved(), org.bukkit.permissions.PermissionAttachment.getRemovalCallback(), and org.bukkit.permissions.PermissibleBase.recalculatePermissions().

129  {
130  if (attachment == null) {
131  throw new IllegalArgumentException("Attachment cannot be null");
132  }
133 
134  if (attachments.contains(attachment)) {
135  attachments.remove(attachment);
136  PermissionRemovedExecutor ex = attachment.getRemovalCallback();
137 
138  if (ex != null) {
139  ex.attachmentRemoved(attachment);
140  }
141 
143  } else {
144  throw new IllegalArgumentException("Given attachment is not part of Permissible object " + parent);
145  }
146  }
void org.bukkit.permissions.PermissibleBase.setOp ( boolean  value)

Sets the operator status of this object

Parameters
valueNew operator value

Implements org.bukkit.permissions.ServerOperator.

Definition at line 40 of file PermissibleBase.java.

References org.bukkit.permissions.ServerOperator.setOp().

40  {
41  if (opable == null) {
42  throw new UnsupportedOperationException("Cannot change op value as no ServerOperator is set");
43  } else {
44  opable.setOp(value);
45  }
46  }

The documentation for this class was generated from the following file: