Java Code Examples for org.bukkit.event.HandlerList.getRegisteredListeners()

The following are Jave code examples for showing how to use getRegisteredListeners() of the org.bukkit.event.HandlerList class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: EscapeLag   File: EventExecutorInjector.java   Source Code and License Vote up 7 votes
/**
 * 
 * @author jiongjionger,Vlvxingze
 */

// 将监听器原本的EventExecutor替换成带性能统计的版本
public static void inject(Plugin plg) {
	if (plg != null) {
		for (RegisteredListener listener : HandlerList.getRegisteredListeners(plg)) {
			try {
				FieldAccessor<EventExecutor> field = Reflection.getField(RegisteredListener.class, "executor", EventExecutor.class);
				EventExecutor fieldEventExecutor = field.get(listener);
				field.set(listener, new EventExecutorInjector(plg, fieldEventExecutor));
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
}
 
Example 2
Project: NeverLag   File: MonitorUtils.java   Source Code and License Vote up 7 votes
public static Map<String, MonitorRecord> getEventTimingsByPlugin(Plugin plg) {
	Map<String, MonitorRecord> record = new HashMap<>();
	if (plg == null) {
		return record;
	}
	for (RegisteredListener listener : HandlerList.getRegisteredListeners(plg)) {
		try {
			FieldAccessor<EventExecutor> field = Reflection.getField(RegisteredListener.class, "executor", EventExecutor.class);
			EventExecutor executor = field.get(listener);
			if (executor instanceof EventExecutorInjector) {
				EventExecutorInjector eventExecutorInjector = (EventExecutorInjector) executor;
				String eventName = eventExecutorInjector.getEventName();
				if (eventName != null) {
					MonitorRecord monitorRecord = getMonitorRecord(eventName, eventExecutorInjector.getTotalTime(), eventExecutorInjector.getTotalCount(),
						eventExecutorInjector.getMaxExecuteTime());
					if (record.containsKey(eventName)) {
						MonitorRecord otherMonitorRecord = record.get(eventName);
						record.put(eventName, otherMonitorRecord.merge(monitorRecord));
					} else {
						record.put(eventName, monitorRecord);
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	return record;
}
 
Example 3
Project: EscapeLag   File: MonitorUtils.java   Source Code and License Vote up 6 votes
public static Map<String, MonitorRecord> getEventTimingsByPlugin(Plugin plg) {
	Map<String, MonitorRecord> record = new HashMap<>();
	if (plg == null) {
		return record;
	}
	for (RegisteredListener listener : HandlerList.getRegisteredListeners(plg)) {
		try {
			FieldAccessor<EventExecutor> field = Reflection.getField(RegisteredListener.class, "executor",
					EventExecutor.class);
			EventExecutor executor = field.get(listener);
			if (executor instanceof EventExecutorInjector) {
				EventExecutorInjector eventExecutorInjector = (EventExecutorInjector) executor;
				String eventName = eventExecutorInjector.getEventName();
				if (eventName != null) {
					MonitorRecord monitorRecord = getMonitorRecord(eventName, eventExecutorInjector.getTotalTime(),
							eventExecutorInjector.getTotalCount(), eventExecutorInjector.getMaxExecuteTime());
					if (record.containsKey(eventName)) {
						MonitorRecord otherMonitorRecord = record.get(eventName);
						record.put(eventName, otherMonitorRecord.merge(monitorRecord));
					} else {
						record.put(eventName, monitorRecord);
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	return record;
}
 
Example 4
Project: EscapeLag   File: EventExecutorInjector.java   Source Code and License Vote up 5 votes
public static void uninject(Plugin plg) {
	if (plg != null) {
		for (RegisteredListener listener : HandlerList.getRegisteredListeners(plg)) {
			try {
				FieldAccessor<EventExecutor> field = Reflection.getField(RegisteredListener.class, "executor", EventExecutor.class);
				EventExecutor executor = field.get(listener);
				if (executor instanceof EventExecutorInjector) {
					field.set(listener, ((EventExecutorInjector) executor).getEventExecutor());
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
}
 
Example 5
Project: NeverLag   File: EventExecutorInjector.java   Source Code and License Vote up 5 votes
public static void inject(Plugin plg) {
	if (plg != null) {
		for (RegisteredListener listener : HandlerList.getRegisteredListeners(plg)) {
			try {
				FieldAccessor<EventExecutor> field = Reflection.getField(RegisteredListener.class, "executor", EventExecutor.class);
				EventExecutor fieldEventExecutor = field.get(listener);
				field.set(listener, new EventExecutorInjector(plg, fieldEventExecutor));
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
}
 
Example 6
Project: NeverLag   File: EventExecutorInjector.java   Source Code and License Vote up 5 votes
public static void uninject(Plugin plg) {
	if (plg != null) {
		for (RegisteredListener listener : HandlerList.getRegisteredListeners(plg)) {
			try {
				FieldAccessor<EventExecutor> field = Reflection.getField(RegisteredListener.class, "executor", EventExecutor.class);
				EventExecutor executor = field.get(listener);
				if (executor instanceof EventExecutorInjector) {
					field.set(listener, ((EventExecutorInjector) executor).getEventExecutor());
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
}