forked from Bukkit/Bukkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added services manager framework. Services are interfaces that specif…
…ies capabilities to be implemented by providers. Example services include economy, <insert example 2>, etc.
- Loading branch information
Showing
6 changed files
with
469 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/main/java/org/bukkit/plugin/RegisteredServiceProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.bukkit.plugin; | ||
|
||
/** | ||
* A registered service provider. | ||
* | ||
* @author sk89q | ||
* @param <T> Service | ||
*/ | ||
public class RegisteredServiceProvider<T> | ||
implements Comparable<RegisteredServiceProvider<?>> { | ||
|
||
private Class<T> service; | ||
private Plugin plugin; | ||
private T provider; | ||
private ServicePriority priority; | ||
|
||
public RegisteredServiceProvider(Class<T> service, T provider, | ||
ServicePriority priority, Plugin plugin) { | ||
|
||
this.service = service; | ||
this.plugin = plugin; | ||
this.provider = provider; | ||
this.priority = priority; | ||
} | ||
|
||
public Class<T> getService() { | ||
return service; | ||
} | ||
|
||
public Plugin getPlugin() { | ||
return plugin; | ||
} | ||
|
||
public T getProvider() { | ||
return provider; | ||
} | ||
|
||
public ServicePriority getPriority() { | ||
return priority; | ||
} | ||
|
||
public int compareTo(RegisteredServiceProvider<?> other) { | ||
if (priority.ordinal() == other.getPriority().ordinal()) { | ||
return 0; | ||
} else { | ||
return priority.ordinal() < other.getPriority().ordinal() ? 1 : -1; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.bukkit.plugin; | ||
|
||
/** | ||
* Represents various priorities of a provider. | ||
*/ | ||
public enum ServicePriority { | ||
Lowest, | ||
Low, | ||
Normal, | ||
High, | ||
Highest | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package org.bukkit.plugin; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
/** | ||
* Manages services and service providers. Services are an interface specifying | ||
* a list of methods that a provider must implement. Providers are | ||
* implementations of these services. A provider can be queried from the | ||
* services manager in order to use a service (if one is available). If | ||
* multiple plugins register a service, then the service with the highest | ||
* priority takes precedence. | ||
* | ||
* @author sk89q | ||
*/ | ||
public interface ServicesManager { | ||
|
||
/** | ||
* Register a provider of a service. | ||
* | ||
* @param <T> Provider | ||
* @param service service class | ||
* @param provider provider to register | ||
* @param plugin plugin with the provider | ||
* @param priority priority of the provider | ||
*/ | ||
public <T> void register(Class<T> service, T provider, Plugin plugin, | ||
ServicePriority priority); | ||
|
||
/** | ||
* Unregister all the providers registered by a particular plugin. | ||
* | ||
* @param plugin | ||
*/ | ||
public void unregisterAll(Plugin plugin); | ||
|
||
/** | ||
* Unregister a particular provider for a particular service. | ||
* | ||
* @param service | ||
* @param provider | ||
*/ | ||
public void unregister(Class<?> service, Object provider); | ||
|
||
/** | ||
* Unregister a particular provider. | ||
* | ||
* @param provider | ||
*/ | ||
public void unregister(Object provider); | ||
|
||
/** | ||
* Queries for a provider. This may return if no provider has been | ||
* registered for a service. The highest priority provider is returned. | ||
* | ||
* @param <T> | ||
* @param service | ||
* @return provider or null | ||
*/ | ||
public <T> T load(Class<T> service); | ||
|
||
/** | ||
* Queries for a provider registration. This may return if no provider | ||
* has been registered for a service. | ||
* | ||
* @param <T> | ||
* @param service | ||
* @return provider registration or null | ||
*/ | ||
public <T> RegisteredServiceProvider<T> getRegistration(Class<T> service); | ||
|
||
/** | ||
* Get registrations of providers for a plugin. | ||
* | ||
* @param plugin | ||
* @return provider registration or null | ||
*/ | ||
public List<RegisteredServiceProvider<?>> getRegistrations(Plugin plugin); | ||
|
||
/** | ||
* Get registrations of providers for a service. The returned list is | ||
* unmodifiable. | ||
* | ||
* @param <T> | ||
* @param service | ||
* @return list of registrations | ||
*/ | ||
public <T> Collection<RegisteredServiceProvider<T>> getRegistrations( | ||
Class<T> service); | ||
|
||
/** | ||
* Get a list of known services. A service is known if it has registered | ||
* providers for it. | ||
* | ||
* @return list of known services | ||
*/ | ||
public Collection<Class<?>> getKnownServices(); | ||
|
||
/** | ||
* Returns whether a provider has been registered for a service. Do not | ||
* check this first only to call <code>load(service)</code> later, as that | ||
* would be a non-thread safe situation. | ||
* | ||
* @param <T> service | ||
* @param service service to check | ||
* @return whether there has been a registered provider | ||
*/ | ||
public <T> boolean isProvidedFor(Class<T> service); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.