Skip to content

Commit 43d90a4

Browse files
committed
Formatting, appropriate credits for bukkit/velocity entry-point scanners
1 parent 2c9d089 commit 43d90a4

2 files changed

Lines changed: 91 additions & 93 deletions

File tree

recaf-core/src/main/java/software/coley/recaf/services/analysis/entry/BukkitPluginEntryPointDiscovery.java

Lines changed: 41 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -17,58 +17,57 @@
1717
/**
1818
* Discovery process for locating entry points in Bukkit plugins.
1919
*
20-
* @author Matt Coley
2120
* @author TheWakz
2221
* @see <a href="https://docs.papermc.io/paper/dev/how-do-plugins-work/#plugin-lifecycle">Bukkit plugin entry points</a>
2322
*/
2423
@ApplicationScoped
2524
public class BukkitPluginEntryPointDiscovery implements EntryPointDiscovery {
26-
private final InheritanceGraphService inheritanceGraphService;
25+
private final InheritanceGraphService inheritanceGraphService;
2726

28-
@Inject
29-
public BukkitPluginEntryPointDiscovery(@Nonnull InheritanceGraphService inheritanceGraphService) {
30-
this.inheritanceGraphService = inheritanceGraphService;
31-
}
27+
@Inject
28+
public BukkitPluginEntryPointDiscovery(@Nonnull InheritanceGraphService inheritanceGraphService) {
29+
this.inheritanceGraphService = inheritanceGraphService;
30+
}
3231

33-
@Nonnull
34-
@Override
35-
public EntryPointKind kind() {
36-
return EntryPointKind.MC_BUKKIT_PLUGIN_INIT;
37-
}
32+
@Nonnull
33+
@Override
34+
public EntryPointKind kind() {
35+
return EntryPointKind.MC_BUKKIT_PLUGIN_INIT;
36+
}
3837

39-
@Nonnull
40-
@Override
41-
public List<EntryPoint> findEntryPoints(@Nonnull Workspace workspace, @Nonnull WorkspaceResource resource) {
42-
InheritanceGraph graph = inheritanceGraphService.getOrCreateInheritanceGraph(workspace);
43-
List<EntryPoint> entries = new ArrayList<>();
44-
resource.jvmAllClassBundleStream().forEach(bundle -> bundle.forEach(cls -> {
45-
String className = cls.getName();
46-
ClassPathNode classPath = null;
47-
Boolean isPlugin = null;
48-
for (MethodMember method : cls.getMethods()) {
49-
// Must be a plugin enable or load method name.
50-
String methodName = method.getName();
51-
if (!methodName.equals("onEnable") && !methodName.equals("onLoad"))
52-
continue;
38+
@Nonnull
39+
@Override
40+
public List<EntryPoint> findEntryPoints(@Nonnull Workspace workspace, @Nonnull WorkspaceResource resource) {
41+
InheritanceGraph graph = inheritanceGraphService.getOrCreateInheritanceGraph(workspace);
42+
List<EntryPoint> entries = new ArrayList<>();
43+
resource.jvmAllClassBundleStream().forEach(bundle -> bundle.forEach(cls -> {
44+
String className = cls.getName();
45+
ClassPathNode classPath = null;
46+
Boolean isPlugin = null;
47+
for (MethodMember method : cls.getMethods()) {
48+
// Must be a plugin enable or load method name.
49+
String methodName = method.getName();
50+
if (!methodName.equals("onEnable") && !methodName.equals("onLoad"))
51+
continue;
5352

54-
// Lazily check if this class is a plugin subtype.
55-
if (isPlugin == null)
56-
isPlugin = isPlugin(graph, className);
53+
// Lazily check if this class is a plugin subtype.
54+
if (isPlugin == null)
55+
isPlugin = isPlugin(graph, className);
5756

58-
// Skip methods if the class is not a valid plugin.
59-
if (!isPlugin)
60-
continue;
57+
// Skip methods if the class is not a valid plugin.
58+
if (!isPlugin)
59+
continue;
6160

62-
// Add the entry point.
63-
if (classPath == null)
64-
classPath = PathNodes.classPath(workspace, resource, bundle, cls);
65-
entries.add(new EntryPoint(kind(), classPath, classPath.child(method)));
66-
}
67-
}));
68-
return entries;
69-
}
61+
// Add the entry point.
62+
if (classPath == null)
63+
classPath = PathNodes.classPath(workspace, resource, bundle, cls);
64+
entries.add(new EntryPoint(kind(), classPath, classPath.child(method)));
65+
}
66+
}));
67+
return entries;
68+
}
7069

71-
private static boolean isPlugin(@Nonnull InheritanceGraph graph, @Nonnull String className) {
72-
return graph.isAssignableFrom("org/bukkit/plugin/java/JavaPlugin", className);
73-
}
70+
private static boolean isPlugin(@Nonnull InheritanceGraph graph, @Nonnull String className) {
71+
return graph.isAssignableFrom("org/bukkit/plugin/java/JavaPlugin", className);
72+
}
7473
}

recaf-core/src/main/java/software/coley/recaf/services/analysis/entry/VelocityPluginEntryPointDiscovery.java

Lines changed: 50 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -21,66 +21,65 @@
2121
/**
2222
* Discovery process for locating entry points in Velocity plugins.
2323
*
24-
* @author Matt Coley
2524
* @author TheWakz
2625
* @see <a href="https://docs.papermc.io/velocity/dev/api-basics/#create-the-plugin-class">Velocity plugin entry points</a>
2726
*/
2827
@ApplicationScoped
2928
public class VelocityPluginEntryPointDiscovery implements EntryPointDiscovery {
30-
private final InheritanceGraphService inheritanceGraphService;
29+
private final InheritanceGraphService inheritanceGraphService;
3130

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+
}
3635

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+
}
4241

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;
5150

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+
}
6463

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+
}
7877

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+
}
8685
}

0 commit comments

Comments
 (0)