Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
org.bukkit.plugin.SimpleServicesManager Class Reference
Inheritance diagram for org.bukkit.plugin.SimpleServicesManager:
org.bukkit.plugin.ServicesManager

Public Member Functions

void unregisterAll (Plugin plugin)
 
void unregister (Class<?> service, Object provider)
 
void unregister (Object provider)
 
List< RegisteredServiceProvider<?> > getRegistrations (Plugin plugin)
 
Set< Class<?> > getKnownServices ()
 

Detailed Description

A simple services manager.

Definition at line 22 of file SimpleServicesManager.java.

Member Function Documentation

Set<Class<?> > org.bukkit.plugin.SimpleServicesManager.getKnownServices ( )

Get a list of known services. A service is known if it has registered providers for it.

Returns
a copy of the set of known services

Implements org.bukkit.plugin.ServicesManager.

Definition at line 288 of file SimpleServicesManager.java.

288  {
289  synchronized (providers) {
290  return ImmutableSet.<Class<?>>copyOf(providers.keySet());
291  }
292  }
List<RegisteredServiceProvider<?> > org.bukkit.plugin.SimpleServicesManager.getRegistrations ( Plugin  plugin)

Get registrations of providers for a plugin.

Parameters
pluginThe plugin
Returns
provider registration or null

Implements org.bukkit.plugin.ServicesManager.

Definition at line 240 of file SimpleServicesManager.java.

240  {
241  ImmutableList.Builder<RegisteredServiceProvider<?>> ret = ImmutableList.<RegisteredServiceProvider<?>>builder();
242  synchronized (providers) {
243  for (List<RegisteredServiceProvider<?>> registered : providers.values()) {
244  for (RegisteredServiceProvider<?> provider : registered) {
245  if (provider.getPlugin().equals(plugin)) {
246  ret.add(provider);
247  }
248  }
249  }
250  }
251  return ret.build();
252  }
void org.bukkit.plugin.SimpleServicesManager.unregister ( Class<?>  service,
Object  provider 
)

Unregister a particular provider for a particular service.

Parameters
serviceThe service interface
providerThe service provider implementation

Implements org.bukkit.plugin.ServicesManager.

Definition at line 108 of file SimpleServicesManager.java.

References org.bukkit.plugin.PluginManager.callEvent(), org.bukkit.Server.getPluginManager(), and org.bukkit.Bukkit.getServer().

108  {
109  ArrayList<ServiceUnregisterEvent> unregisteredEvents = new ArrayList<ServiceUnregisterEvent>();
110  synchronized (providers) {
111  Iterator<Map.Entry<Class<?>, List<RegisteredServiceProvider<?>>>> it = providers.entrySet().iterator();
112 
113  try {
114  while (it.hasNext()) {
115  Map.Entry<Class<?>, List<RegisteredServiceProvider<?>>> entry = it.next();
116 
117  // We want a particular service
118  if (entry.getKey() != service) {
119  continue;
120  }
121 
122  Iterator<RegisteredServiceProvider<?>> it2 = entry.getValue().iterator();
123 
124  try {
125  // Removed entries that are from this plugin
126 
127  while (it2.hasNext()) {
128  RegisteredServiceProvider<?> registered = it2.next();
129 
130  if (registered.getProvider() == provider) {
131  it2.remove();
132  unregisteredEvents.add(new ServiceUnregisterEvent(registered));
133  }
134  }
135  } catch (NoSuchElementException e) { // Why does Java suck
136  }
137 
138  // Get rid of the empty list
139  if (entry.getValue().size() == 0) {
140  it.remove();
141  }
142  }
143  } catch (NoSuchElementException e) {}
144  }
145  for (ServiceUnregisterEvent event : unregisteredEvents) {
146  Bukkit.getServer().getPluginManager().callEvent(event);
147  }
148  }
void org.bukkit.plugin.SimpleServicesManager.unregister ( Object  provider)

Unregister a particular provider.

Parameters
providerThe service provider implementation

Implements org.bukkit.plugin.ServicesManager.

Definition at line 155 of file SimpleServicesManager.java.

References org.bukkit.plugin.PluginManager.callEvent(), org.bukkit.Server.getPluginManager(), and org.bukkit.Bukkit.getServer().

155  {
156  ArrayList<ServiceUnregisterEvent> unregisteredEvents = new ArrayList<ServiceUnregisterEvent>();
157  synchronized (providers) {
158  Iterator<Map.Entry<Class<?>, List<RegisteredServiceProvider<?>>>> it = providers.entrySet().iterator();
159 
160  try {
161  while (it.hasNext()) {
162  Map.Entry<Class<?>, List<RegisteredServiceProvider<?>>> entry = it.next();
163  Iterator<RegisteredServiceProvider<?>> it2 = entry.getValue().iterator();
164 
165  try {
166  // Removed entries that are from this plugin
167 
168  while (it2.hasNext()) {
169  RegisteredServiceProvider<?> registered = it2.next();
170 
171  if (registered.getProvider().equals(provider)) {
172  it2.remove();
173  unregisteredEvents.add(new ServiceUnregisterEvent(registered));
174  }
175  }
176  } catch (NoSuchElementException e) { // Why does Java suck
177  }
178 
179  // Get rid of the empty list
180  if (entry.getValue().size() == 0) {
181  it.remove();
182  }
183  }
184  } catch (NoSuchElementException e) {}
185  }
186  for (ServiceUnregisterEvent event : unregisteredEvents) {
187  Bukkit.getServer().getPluginManager().callEvent(event);
188  }
189  }
void org.bukkit.plugin.SimpleServicesManager.unregisterAll ( Plugin  plugin)

Unregister all the providers registered by a particular plugin.

Parameters
pluginThe plugin

Implements org.bukkit.plugin.ServicesManager.

Definition at line 66 of file SimpleServicesManager.java.

References org.bukkit.plugin.PluginManager.callEvent(), org.bukkit.Server.getPluginManager(), and org.bukkit.Bukkit.getServer().

66  {
67  ArrayList<ServiceUnregisterEvent> unregisteredEvents = new ArrayList<ServiceUnregisterEvent>();
68  synchronized (providers) {
69  Iterator<Map.Entry<Class<?>, List<RegisteredServiceProvider<?>>>> it = providers.entrySet().iterator();
70 
71  try {
72  while (it.hasNext()) {
73  Map.Entry<Class<?>, List<RegisteredServiceProvider<?>>> entry = it.next();
74  Iterator<RegisteredServiceProvider<?>> it2 = entry.getValue().iterator();
75 
76  try {
77  // Removed entries that are from this plugin
78 
79  while (it2.hasNext()) {
80  RegisteredServiceProvider<?> registered = it2.next();
81 
82  if (registered.getPlugin().equals(plugin)) {
83  it2.remove();
84  unregisteredEvents.add(new ServiceUnregisterEvent(registered));
85  }
86  }
87  } catch (NoSuchElementException e) { // Why does Java suck
88  }
89 
90  // Get rid of the empty list
91  if (entry.getValue().size() == 0) {
92  it.remove();
93  }
94  }
95  } catch (NoSuchElementException e) {}
96  }
97  for (ServiceUnregisterEvent event : unregisteredEvents) {
98  Bukkit.getServer().getPluginManager().callEvent(event);
99  }
100  }

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