mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-08 09:17:36 +01:00
Added service register and unregister events. Addresses BUKKIT-816
By: zml2008 <zach@zachsthings.com>
This commit is contained in:
parent
1d03cfb423
commit
860011dcc1
@ -0,0 +1,18 @@
|
||||
package org.bukkit.event.server;
|
||||
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
||||
/**
|
||||
* An event relating to a registered service. This is called in a {@link org.bukkit.plugin.ServicesManager}
|
||||
*/
|
||||
public abstract class ServiceEvent extends ServerEvent {
|
||||
private final RegisteredServiceProvider<?> provider;
|
||||
|
||||
public ServiceEvent(final RegisteredServiceProvider<?> provider) {
|
||||
this.provider = provider;
|
||||
}
|
||||
|
||||
public RegisteredServiceProvider<?> getProvider() {
|
||||
return provider;
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package org.bukkit.event.server;
|
||||
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
||||
/**
|
||||
* This event is called when a service is registered.
|
||||
*/
|
||||
public class ServiceRegisterEvent extends ServiceEvent {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
public ServiceRegisterEvent(RegisteredServiceProvider<?> registeredProvider) {
|
||||
super(registeredProvider);
|
||||
}
|
||||
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package org.bukkit.event.server;
|
||||
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
||||
/**
|
||||
* This event is called when a service is unregistered.
|
||||
*/
|
||||
public class ServiceUnregisterEvent extends ServiceEvent {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
public ServiceUnregisterEvent(RegisteredServiceProvider<?> serviceProvider) {
|
||||
super(serviceProvider);
|
||||
}
|
||||
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
@ -1,5 +1,9 @@
|
||||
package org.bukkit.plugin;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.server.ServiceRegisterEvent;
|
||||
import org.bukkit.event.server.ServiceUnregisterEvent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@ -37,12 +41,15 @@ public class SimpleServicesManager implements ServicesManager {
|
||||
registered = new ArrayList<RegisteredServiceProvider<?>>();
|
||||
providers.put(service, registered);
|
||||
}
|
||||
RegisteredServiceProvider<T> registeredProvider = new RegisteredServiceProvider<T>(service, provider, priority, plugin);
|
||||
|
||||
registered.add(new RegisteredServiceProvider<T>(service, provider, priority, plugin));
|
||||
registered.add(registeredProvider);
|
||||
|
||||
// Make sure that providers are in the right order in order
|
||||
// for priorities to work correctly
|
||||
Collections.sort(registered);
|
||||
|
||||
Bukkit.getServer().getPluginManager().callEvent(new ServiceRegisterEvent(registeredProvider));
|
||||
}
|
||||
}
|
||||
|
||||
@ -64,8 +71,11 @@ public class SimpleServicesManager implements ServicesManager {
|
||||
// Removed entries that are from this plugin
|
||||
|
||||
while (it2.hasNext()) {
|
||||
if (it2.next().getPlugin() == plugin) {
|
||||
RegisteredServiceProvider<?> registered = it2.next();
|
||||
|
||||
if (registered.getPlugin() == plugin) {
|
||||
it2.remove();
|
||||
Bukkit.getServer().getPluginManager().callEvent(new ServiceUnregisterEvent(registered));
|
||||
}
|
||||
}
|
||||
} catch (NoSuchElementException e) { // Why does Java suck
|
||||
@ -105,8 +115,11 @@ public class SimpleServicesManager implements ServicesManager {
|
||||
// Removed entries that are from this plugin
|
||||
|
||||
while (it2.hasNext()) {
|
||||
if (it2.next().getProvider() == provider) {
|
||||
RegisteredServiceProvider<?> registered = it2.next();
|
||||
|
||||
if (registered.getProvider() == provider) {
|
||||
it2.remove();
|
||||
Bukkit.getServer().getPluginManager().callEvent(new ServiceUnregisterEvent(registered));
|
||||
}
|
||||
}
|
||||
} catch (NoSuchElementException e) { // Why does Java suck
|
||||
@ -139,8 +152,11 @@ public class SimpleServicesManager implements ServicesManager {
|
||||
// Removed entries that are from this plugin
|
||||
|
||||
while (it2.hasNext()) {
|
||||
if (it2.next().getProvider() == provider) {
|
||||
RegisteredServiceProvider<?> registered = it2.next();
|
||||
|
||||
if (registered.getProvider() == provider) {
|
||||
it2.remove();
|
||||
Bukkit.getServer().getPluginManager().callEvent(new ServiceUnregisterEvent(registered));
|
||||
}
|
||||
}
|
||||
} catch (NoSuchElementException e) { // Why does Java suck
|
||||
|
Loading…
Reference in New Issue
Block a user