File tree Expand file tree Collapse file tree 1 file changed +23
-11
lines changed
src/main/java/world/bentobox/bentobox/api/addons Expand file tree Collapse file tree 1 file changed +23
-11
lines changed Original file line number Diff line number Diff line change @@ -218,19 +218,31 @@ public Class<?> findClass(String name, boolean checkGlobal) {
218218 if (name .startsWith ("world.bentobox.bentobox" )) {
219219 return null ;
220220 }
221- return classes .computeIfAbsent (name , key -> {
222- Class <?> resolved = checkGlobal ? loader .getClassByName (key ) : null ;
223- if (resolved != null ) {
224- return resolved ;
221+ // Check local cache first.
222+ Class <?> result = classes .get (name );
223+ if (result == null ) {
224+ // Check global cache for classes from other addons.
225+ if (checkGlobal ) {
226+ result = loader .getClassByName (name );
225227 }
226- try {
227- resolved = AddonClassLoader .super .findClass (key );
228- loader .setClass (key , resolved );
229- return resolved ;
230- } catch (ClassNotFoundException | NoClassDefFoundError e ) {
231- return null ; // Not found locally.
228+
229+ if (result == null ) {
230+ // Try to find the class in this addon's jar.
231+ try {
232+ result = super .findClass (name );
233+ } catch (ClassNotFoundException | NoClassDefFoundError e ) {
234+ // Do nothing. The class is not in this jar.
235+ }
236+ if (result != null ) {
237+ // Class found in this addon's jar, so add it to the global cache.
238+ loader .setClass (name , result );
239+
240+ }
232241 }
233- });
242+ // Add the class to the local cache.
243+ classes .put (name , result );
244+ }
245+ return result ;
234246 }
235247
236248 /**
You can’t perform that action at this time.
0 commit comments