Skip to content

Commit 5bed29b

Browse files
Code improvements
1 parent 1b8b4ea commit 5bed29b

File tree

2 files changed

+13
-26
lines changed

2 files changed

+13
-26
lines changed

src/main/java/world/bentobox/bentobox/api/addons/AddonClassLoader.java

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -218,31 +218,19 @@ public Class<?> findClass(String name, boolean checkGlobal) {
218218
if (name.startsWith("world.bentobox.bentobox")) {
219219
return null;
220220
}
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);
221+
return classes.computeIfAbsent(name, key -> {
222+
Class<?> resolved = checkGlobal ? loader.getClassByName(key) : null;
223+
if (resolved != null) {
224+
return resolved;
227225
}
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-
}
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.
241232
}
242-
// Add the class to the local cache.
243-
classes.put(name, result);
244-
}
245-
return result;
233+
});
246234
}
247235

248236
/**

src/main/java/world/bentobox/bentobox/api/user/User.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -439,8 +439,7 @@ private int iteratePerms(List<String> permissions, String permPrefix, int defaul
439439
String[] spl = permission.split(permPrefix);
440440
if (spl.length > 1) {
441441
if (!NumberUtils.isCreatable(spl[1])) {
442-
plugin.logError("Player " + player.getName() + " has permission: '" + permission
443-
+ "' <-- the last part MUST be a number! Ignoring...");
442+
plugin.logError("Player " + player.getName() + " has permission: '" + permission);
444443
} else {
445444
int v = Integer.parseInt(spl[1]);
446445
if (v < 0) {
@@ -979,7 +978,7 @@ public String toString() {
979978
+ (offlinePlayer != null ? "offlinePlayer=" + offlinePlayer + ", " : "")
980979
+ (playerUUID != null ? "playerUUID=" + playerUUID + ", " : "")
981980
+ (sender != null ? "sender=" + sender + ", " : "") + (addon != null ? "addon=" + addon + ", " : "")
982-
+ (getLocation() != null ? "getLocation()=" + getLocation() + ", " : "") + "isPlayer()=" + isPlayer()
981+
+ "getLocation()=" + getLocation() + "isPlayer()=" + isPlayer()
983982
+ "]";
984983
}
985984

0 commit comments

Comments
 (0)