From 93c3d3ce473e7bdafdd76f280735d7d32a91675b Mon Sep 17 00:00:00 2001 From: tastybento Date: Fri, 3 Aug 2018 23:31:02 -0700 Subject: [PATCH] Removed code smells. --- .../world/bentobox/bentobox/Constants.java | 3 +++ .../bentobox/api/addons/AddonClassLoader.java | 22 +++++++++---------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/main/java/world/bentobox/bentobox/Constants.java b/src/main/java/world/bentobox/bentobox/Constants.java index 305b98307..4b4cd83a9 100644 --- a/src/main/java/world/bentobox/bentobox/Constants.java +++ b/src/main/java/world/bentobox/bentobox/Constants.java @@ -5,6 +5,9 @@ package world.bentobox.bentobox; * @author tastybento */ public class Constants { + + private Constants() {} + // The spawn command (Essentials spawn for example) public static final String SPAWNCOMMAND = "spawn"; } \ No newline at end of file diff --git a/src/main/java/world/bentobox/bentobox/api/addons/AddonClassLoader.java b/src/main/java/world/bentobox/bentobox/api/addons/AddonClassLoader.java index b9819df77..8e8d15ca3 100644 --- a/src/main/java/world/bentobox/bentobox/api/addons/AddonClassLoader.java +++ b/src/main/java/world/bentobox/bentobox/api/addons/AddonClassLoader.java @@ -103,25 +103,23 @@ public class AddonClassLoader extends URLClassLoader { * @return Class - class if found */ public Class findClass(String name, boolean checkGlobal) { - if (name.startsWith("us.tastybento.")) { + if (name.startsWith("world.bentobox.")) { return null; } - Class result = classes.get(name); - if (result == null) { - if (checkGlobal) { - result = loader.getClassByName(name); - } - if (result == null) { + + Class result = classes.computeIfAbsent(name, k -> { + if (checkGlobal && loader.getClassByName(name) != null) { + return loader.getClassByName(name); + } else { try { - result = super.findClass(name); + return super.findClass(name); } catch (ClassNotFoundException e) { return null; } - if (result != null) { - loader.setClass(name, result); - } - classes.put(name, result); } + }); + if (result != null) { + loader.setClass(name, result); } return result; }