|
21 | 21 | /** |
22 | 22 | * Discovery process for locating entry points in Velocity plugins. |
23 | 23 | * |
24 | | - * @author Matt Coley |
25 | 24 | * @author TheWakz |
26 | 25 | * @see <a href="https://docs.papermc.io/velocity/dev/api-basics/#create-the-plugin-class">Velocity plugin entry points</a> |
27 | 26 | */ |
28 | 27 | @ApplicationScoped |
29 | 28 | public class VelocityPluginEntryPointDiscovery implements EntryPointDiscovery { |
30 | | - private final InheritanceGraphService inheritanceGraphService; |
| 29 | + private final InheritanceGraphService inheritanceGraphService; |
31 | 30 |
|
32 | | - @Inject |
33 | | - public VelocityPluginEntryPointDiscovery(@Nonnull InheritanceGraphService inheritanceGraphService) { |
34 | | - this.inheritanceGraphService = inheritanceGraphService; |
35 | | - } |
| 31 | + @Inject |
| 32 | + public VelocityPluginEntryPointDiscovery(@Nonnull InheritanceGraphService inheritanceGraphService) { |
| 33 | + this.inheritanceGraphService = inheritanceGraphService; |
| 34 | + } |
36 | 35 |
|
37 | | - @Nonnull |
38 | | - @Override |
39 | | - public EntryPointKind kind() { |
40 | | - return EntryPointKind.MC_VELOCITY_PLUGIN_INIT; |
41 | | - } |
| 36 | + @Nonnull |
| 37 | + @Override |
| 38 | + public EntryPointKind kind() { |
| 39 | + return EntryPointKind.MC_VELOCITY_PLUGIN_INIT; |
| 40 | + } |
42 | 41 |
|
43 | | - @Nonnull |
44 | | - @Override |
45 | | - public List<EntryPoint> findEntryPoints(@Nonnull Workspace workspace, @Nonnull WorkspaceResource resource) { |
46 | | - InheritanceGraph graph = inheritanceGraphService.getOrCreateInheritanceGraph(workspace); |
47 | | - List<EntryPoint> entries = new ArrayList<>(); |
48 | | - resource.jvmAllClassBundleStream().forEach(bundle -> bundle.forEach(cls -> { |
49 | | - ClassPathNode classPath = null; |
50 | | - EntryPoint classEntry = null; |
| 42 | + @Nonnull |
| 43 | + @Override |
| 44 | + public List<EntryPoint> findEntryPoints(@Nonnull Workspace workspace, @Nonnull WorkspaceResource resource) { |
| 45 | + InheritanceGraph graph = inheritanceGraphService.getOrCreateInheritanceGraph(workspace); |
| 46 | + List<EntryPoint> entries = new ArrayList<>(); |
| 47 | + resource.jvmAllClassBundleStream().forEach(bundle -> bundle.forEach(cls -> { |
| 48 | + ClassPathNode classPath = null; |
| 49 | + EntryPoint classEntry = null; |
51 | 50 |
|
52 | | - // Check for @Plugin annotations |
53 | | - Set<String> annotations = Sets.combine( |
54 | | - cls.getAnnotations().stream().map(AnnotationInfo::getDescriptor).collect(Collectors.toSet()), |
55 | | - cls.getTypeAnnotations().stream().map(AnnotationInfo::getDescriptor).collect(Collectors.toSet()) |
56 | | - ); |
57 | | - for (String annotation : annotations) { |
58 | | - if ("Lcom/velocitypowered/api/plugin/Plugin;".equals(annotation)) { |
59 | | - classPath = PathNodes.classPath(workspace, resource, bundle, cls); |
60 | | - classEntry = new EntryPoint(kind(), classPath, null); |
61 | | - break; |
62 | | - } |
63 | | - } |
| 51 | + // Check for @Plugin annotations |
| 52 | + Set<String> annotations = Sets.combine( |
| 53 | + cls.getAnnotations().stream().map(AnnotationInfo::getDescriptor).collect(Collectors.toSet()), |
| 54 | + cls.getTypeAnnotations().stream().map(AnnotationInfo::getDescriptor).collect(Collectors.toSet()) |
| 55 | + ); |
| 56 | + for (String annotation : annotations) { |
| 57 | + if ("Lcom/velocitypowered/api/plugin/Plugin;".equals(annotation)) { |
| 58 | + classPath = PathNodes.classPath(workspace, resource, bundle, cls); |
| 59 | + classEntry = new EntryPoint(kind(), classPath, null); |
| 60 | + break; |
| 61 | + } |
| 62 | + } |
64 | 63 |
|
65 | | - // Check for initialization event receivers |
66 | | - boolean foundEventReceiver = false; |
67 | | - for (MethodMember method : cls.getMethods()) { |
68 | | - String desc = method.getDescriptor(); |
69 | | - if ("(Lcom/velocitypowered/api/event/proxy/ProxyInitializeEvent;)V".equals(desc) |
70 | | - || "(Lcom/velocitypowered/api/event/proxy/ProxyReloadEvent;)V".equals(desc) |
71 | | - ) { |
72 | | - if (classPath == null) |
73 | | - classPath = PathNodes.classPath(workspace, resource, bundle, cls); |
74 | | - entries.add(new EntryPoint(kind(), classPath, classPath.child(method))); |
75 | | - foundEventReceiver = true; |
76 | | - } |
77 | | - } |
| 64 | + // Check for initialization event receivers |
| 65 | + boolean foundEventReceiver = false; |
| 66 | + for (MethodMember method : cls.getMethods()) { |
| 67 | + String desc = method.getDescriptor(); |
| 68 | + if ("(Lcom/velocitypowered/api/event/proxy/ProxyInitializeEvent;)V".equals(desc) |
| 69 | + || "(Lcom/velocitypowered/api/event/proxy/ProxyReloadEvent;)V".equals(desc) |
| 70 | + ) { |
| 71 | + if (classPath == null) |
| 72 | + classPath = PathNodes.classPath(workspace, resource, bundle, cls); |
| 73 | + entries.add(new EntryPoint(kind(), classPath, classPath.child(method))); |
| 74 | + foundEventReceiver = true; |
| 75 | + } |
| 76 | + } |
78 | 77 |
|
79 | | - // Only add the class as an entry point if it wasn't already added as an event receiver. |
80 | | - // The event receiver is more specific and the containing class shares the same path. |
81 | | - if (!foundEventReceiver && classEntry != null) |
82 | | - entries.add(classEntry); |
83 | | - })); |
84 | | - return entries; |
85 | | - } |
| 78 | + // Only add the class as an entry point if it wasn't already added as an event receiver. |
| 79 | + // The event receiver is more specific and the containing class shares the same path. |
| 80 | + if (!foundEventReceiver && classEntry != null) |
| 81 | + entries.add(classEntry); |
| 82 | + })); |
| 83 | + return entries; |
| 84 | + } |
86 | 85 | } |
0 commit comments