From 31597cc81cec519349b005448004f1cdb9c868aa Mon Sep 17 00:00:00 2001 From: Gravit Date: Wed, 19 Sep 2018 20:53:27 +0700 Subject: [PATCH] IDEA Refractoring --- .../ru/gravit/launchserver/ProguardConf.java | 2 +- .../auth/handler/CachedAuthHandler.java | 1 - .../auth/hwid/AcceptHWIDHandler.java | 3 ++- .../auth/hwid/JsonHWIDHandler.java | 4 ++-- .../auth/hwid/MysqlHWIDHandler.java | 2 +- .../binary/JARLauncherBinary.java | 2 +- .../manangers/ModulesManager.java | 15 ------------ .../response/auth/AuthResponse.java | 5 +--- .../launcher/client/ClientLauncher.java | 6 ++--- .../launcher/client/ClientModuleManager.java | 3 --- .../buttons/RingProgressIndicatorSkin.java | 24 +++++-------------- .../gui/choosebox/CheckBitSetModelBase.java | 4 ++-- .../launcher/gui/choosebox/CheckModel.java | 18 +++++++------- .../gui/choosebox/IndexedCheckModel.java | 16 ++++++------- .../launcher/server/ModulesManager.java | 15 ------------ .../gravit/launcher/server/ServerWrapper.java | 1 - .../ru/gravit/launcher/AutogenConfig.java | 1 + .../java/ru/gravit/launcher/Launcher.java | 2 +- .../launcher/modules/SimpleModuleManager.java | 4 +--- .../launcher/profiles/ClientProfile.java | 5 ---- 20 files changed, 39 insertions(+), 94 deletions(-) diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/ProguardConf.java b/LaunchServer/src/main/java/ru/gravit/launchserver/ProguardConf.java index acfc311a..1d2f37c2 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/ProguardConf.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/ProguardConf.java @@ -19,7 +19,7 @@ public class ProguardConf { private static final String charsFirst = "aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ"; private static final String chars = "1aAbBcC2dDeEfF3gGhHiI4jJkKl5mMnNoO6pPqQrR7sStT8uUvV9wWxX0yYzZ"; private static String generateString(SecureRandom rand, int il) { - StringBuffer sb = new StringBuffer(il); + StringBuilder sb = new StringBuilder(il); sb.append(charsFirst.charAt(rand.nextInt(charsFirst.length()))); for (int i = 0; i < il - 1; i++) sb.append(chars.charAt(rand.nextInt(chars.length()))); return sb.toString(); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/CachedAuthHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/CachedAuthHandler.java index 1ec06080..df930118 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/CachedAuthHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/CachedAuthHandler.java @@ -10,7 +10,6 @@ import ru.gravit.launcher.NeedGarbageCollection; import ru.gravit.launcher.managers.GarbageManager; import ru.gravit.launcher.serialize.config.entry.BooleanConfigEntry; -import ru.gravit.launcher.serialize.config.entry.StringConfigEntry; import ru.gravit.utils.helper.CommonHelper; import ru.gravit.utils.helper.SecurityHelper; import ru.gravit.utils.helper.VerifyHelper; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/AcceptHWIDHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/AcceptHWIDHandler.java index f2c7ca50..b6abbd47 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/AcceptHWIDHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/AcceptHWIDHandler.java @@ -1,6 +1,7 @@ package ru.gravit.launchserver.auth.hwid; import java.util.Arrays; +import java.util.Collections; import java.util.List; import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry; @@ -28,7 +29,7 @@ public void close() { @Override public List getHwid(String username) { - return Arrays.asList(nullHWID); + return Collections.singletonList(nullHWID); } @Override diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/JsonHWIDHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/JsonHWIDHandler.java index 1d403ff5..bba4ed57 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/JsonHWIDHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/JsonHWIDHandler.java @@ -100,7 +100,7 @@ public JsonObject request(JsonObject request, URL url) throws HWIDException, IOE @Override public void check0(HWID hwid, String username) throws HWIDException { JsonObject request = Json.object().add(loginKeyName,username).add(hddKeyName,hwid.getHwid_hdd()).add(cpuKeyName,hwid.getHwid_cpu()).add(biosKeyName,hwid.getHwid_bios()); - JsonObject response = null; + JsonObject response; try { response = request(request,url); } catch (IOException e) { @@ -130,7 +130,7 @@ public List getHwid(String username) throws HWIDException { ArrayList hwids = new ArrayList<>(); for(JsonValue i : array) { - long hdd=0,cpu=0,bios=0; + long hdd,cpu,bios; JsonObject object = i.asObject(); hdd = object.getLong(hddKeyName,0); cpu = object.getLong(cpuKeyName,0); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/MysqlHWIDHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/MysqlHWIDHandler.java index fe93a014..63178d31 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/MysqlHWIDHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/hwid/MysqlHWIDHandler.java @@ -172,7 +172,7 @@ public List getHwid(String username) throws HWIDException { try (ResultSet set = s.executeQuery()) { if(!set.next()) { LogHelper.error(new HWIDException("HWID not found")); - return new ArrayList(); + return new ArrayList<>(); } hdd = set.getLong(hddName); cpu = set.getLong(cpuName); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JARLauncherBinary.java b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JARLauncherBinary.java index f366a523..e82278d5 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JARLauncherBinary.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/JARLauncherBinary.java @@ -101,7 +101,7 @@ public void build() throws IOException { // ProGuard Configuration proguard_cfg = new Configuration(); ConfigurationParser parser = new ConfigurationParser( - server.proguardConf.confStrs.toArray(new String[server.proguardConf.confStrs.size()]), + server.proguardConf.confStrs.toArray(new String[0]), server.proguardConf.proguard.toFile(), System.getProperties()); try { parser.parse(proguard_cfg); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ModulesManager.java b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ModulesManager.java index 086ecdf9..2efef5f9 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ModulesManager.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/ModulesManager.java @@ -1,25 +1,10 @@ package ru.gravit.launchserver.manangers; -import java.io.IOException; -import java.net.URISyntaxException; import java.net.URL; -import java.nio.file.FileVisitResult; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.SimpleFileVisitor; -import java.nio.file.attribute.BasicFileAttributes; import java.util.ArrayList; -import java.util.jar.JarFile; -import java.util.jar.Manifest; -import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.LauncherClassLoader; import ru.gravit.launcher.modules.SimpleModuleManager; -import ru.gravit.utils.helper.IOHelper; -import ru.gravit.utils.helper.LogHelper; -import ru.gravit.launcher.modules.Module; -import ru.gravit.launcher.modules.ModulesManagerInterface; import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.modules.CoreModule; import ru.gravit.launchserver.modules.LaunchServerModuleContext; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/AuthResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/AuthResponse.java index 75b6aacd..1bd51d3a 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/AuthResponse.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/response/auth/AuthResponse.java @@ -73,10 +73,7 @@ public void reply() throws Exception { if(!p.object.isWhitelistContains(login)) throw new AuthException(server.config.whitelistRejectString); server.config.hwidHandler.check(HWID.gen(hwid_hdd, hwid_bios, hwid_cpu), result.username); - } catch (AuthException e) { - requestError(e.getMessage()); - return; - } catch (HWIDException e) { + } catch (AuthException | HWIDException e) { requestError(e.getMessage()); return; } catch (Exception e) { diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java b/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java index 566177ed..0513dc36 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java @@ -321,7 +321,7 @@ public static Process launch( // Fill CLI arguments List args = new LinkedList<>(); boolean wrapper = isUsingWrapper(); - Path javaBin = null; + Path javaBin; if (wrapper) javaBin = JVMHelper.JVM_BITS == 64 ? AvanguardStarter.wrap64: AvanguardStarter.wrap32; else javaBin = Paths.get(System.getProperty("java.home") + IOHelper.PLATFORM_SEPARATOR + "bin" + IOHelper.PLATFORM_SEPARATOR + "java"); args.add(javaBin.toString()); @@ -465,7 +465,7 @@ private static URL[] resolveClassPath(Path clientDir, String... classPath) throw } private static LinkedList resolveClassPathList(Path clientDir, String... classPath) throws IOException { - Collection result = new LinkedList<>(); + LinkedList result = new LinkedList<>(); for (String classPathEntry : classPath) { Path path = clientDir.resolve(IOHelper.toPath(classPathEntry)); if (IOHelper.isDir(path)) { // Recursive walking and adding @@ -474,7 +474,7 @@ private static LinkedList resolveClassPathList(Path clientDir, String... c } result.add(path); } - return (LinkedList) result; + return result; } @LauncherAPI diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/ClientModuleManager.java b/Launcher/src/main/java/ru/gravit/launcher/client/ClientModuleManager.java index bddce498..6f100167 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/ClientModuleManager.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/ClientModuleManager.java @@ -5,9 +5,6 @@ import ru.gravit.launcher.LauncherEngine; import ru.gravit.launcher.modules.SimpleModuleManager; -import ru.gravit.utils.helper.LogHelper; -import ru.gravit.launcher.modules.Module; -import ru.gravit.launcher.modules.ModulesManagerInterface; public class ClientModuleManager extends SimpleModuleManager { public ClientModuleManager(LauncherEngine engine) diff --git a/Launcher/src/main/java/ru/gravit/launcher/gui/buttons/RingProgressIndicatorSkin.java b/Launcher/src/main/java/ru/gravit/launcher/gui/buttons/RingProgressIndicatorSkin.java index e5f43dcc..61e29e80 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/gui/buttons/RingProgressIndicatorSkin.java +++ b/Launcher/src/main/java/ru/gravit/launcher/gui/buttons/RingProgressIndicatorSkin.java @@ -34,33 +34,21 @@ public RingProgressIndicatorSkin(final RingProgressIndicator indicator) { this.indicator = indicator; initContainer(indicator); initFillerArc(); - container.widthProperty().addListener((o, oldVal, newVal) -> { - fillerArc.setCenterX(newVal.intValue() / 2); - }); - container.heightProperty().addListener((o, oldVal, newVal) -> { - fillerArc.setCenterY(newVal.intValue() / 2); - }); + container.widthProperty().addListener((o, oldVal, newVal) -> fillerArc.setCenterX(newVal.intValue() / 2)); + container.heightProperty().addListener((o, oldVal, newVal) -> fillerArc.setCenterY(newVal.intValue() / 2)); innerCircle.getStyleClass().add("ringindicator-inner-circle"); outerCircle.getStyleClass().add("ringindicator-outer-circle-secondary"); updateRadii(); - this.indicator.indeterminateProperty().addListener((o, oldVal, newVal) -> { - initIndeterminate(newVal); - }); + this.indicator.indeterminateProperty().addListener((o, oldVal, newVal) -> initIndeterminate(newVal)); this.indicator.progressProperty().addListener((o, oldVal, newVal) -> { if (newVal.intValue() >= 0) { fillerArc.setLength(newVal.doubleValue() * -360); } }); - this.indicator.ringWidthProperty().addListener((o, oldVal, newVal) -> { - updateRadii(); - }); - innerCircle.strokeWidthProperty().addListener((e) -> { - updateRadii(); - }); - innerCircle.radiusProperty().addListener((e) -> { - updateRadii(); - }); + this.indicator.ringWidthProperty().addListener((o, oldVal, newVal) -> updateRadii()); + innerCircle.strokeWidthProperty().addListener((e) -> updateRadii()); + innerCircle.radiusProperty().addListener((e) -> updateRadii()); initTransition(); initIndeterminate(indicator.isIndeterminate()); indicator.visibleProperty().addListener((o, oldVal, newVal) -> { diff --git a/Launcher/src/main/java/ru/gravit/launcher/gui/choosebox/CheckBitSetModelBase.java b/Launcher/src/main/java/ru/gravit/launcher/gui/choosebox/CheckBitSetModelBase.java index 703dfdf3..6c7b77cb 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/gui/choosebox/CheckBitSetModelBase.java +++ b/Launcher/src/main/java/ru/gravit/launcher/gui/choosebox/CheckBitSetModelBase.java @@ -73,7 +73,7 @@ public int size() { } }; - final MappingChange.Map map = f -> getItem(f); + final MappingChange.Map map = this::getItem; checkedIndicesList.addListener((ListChangeListener) c -> { boolean hasRealChangeOccurred = false; @@ -218,7 +218,7 @@ protected void updateMap() { final BooleanProperty booleanProperty = new SimpleBooleanProperty(item, "selected", false); //$NON-NLS-1$ itemBooleanMap.put(item, booleanProperty); - booleanProperty.addListener((InvalidationListener) o -> { + booleanProperty.addListener(o -> { if (booleanProperty.get()) { checkedIndices.set(index); final int changeIndex1 = checkedIndicesList.indexOf(index); diff --git a/Launcher/src/main/java/ru/gravit/launcher/gui/choosebox/CheckModel.java b/Launcher/src/main/java/ru/gravit/launcher/gui/choosebox/CheckModel.java index 4ee84137..43cc6b0c 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/gui/choosebox/CheckModel.java +++ b/Launcher/src/main/java/ru/gravit/launcher/gui/choosebox/CheckModel.java @@ -5,29 +5,29 @@ public interface CheckModel { @LauncherAPI - public void check(T item); + void check(T item); @LauncherAPI - public void checkAll(); + void checkAll(); @LauncherAPI - public void clearCheck(T item); + void clearCheck(T item); @LauncherAPI - public void clearChecks(); + void clearChecks(); @LauncherAPI - public ObservableList getCheckedItems(); + ObservableList getCheckedItems(); @LauncherAPI - public int getItemCount(); + int getItemCount(); @LauncherAPI - public boolean isChecked(T item); + boolean isChecked(T item); @LauncherAPI - public boolean isEmpty(); + boolean isEmpty(); @LauncherAPI - public void toggleCheckState(T item); + void toggleCheckState(T item); } diff --git a/Launcher/src/main/java/ru/gravit/launcher/gui/choosebox/IndexedCheckModel.java b/Launcher/src/main/java/ru/gravit/launcher/gui/choosebox/IndexedCheckModel.java index 7d10c62e..51695b2e 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/gui/choosebox/IndexedCheckModel.java +++ b/Launcher/src/main/java/ru/gravit/launcher/gui/choosebox/IndexedCheckModel.java @@ -5,27 +5,27 @@ public interface IndexedCheckModel extends CheckModel { @LauncherAPI - public void check(int index); + void check(int index); @LauncherAPI - public void checkIndices(int... indices); + void checkIndices(int... indices); @LauncherAPI - public void clearCheck(int index); + void clearCheck(int index); @LauncherAPI - public ObservableList getCheckedIndices(); + ObservableList getCheckedIndices(); @LauncherAPI - public T getItem(int index); + T getItem(int index); @LauncherAPI - public int getItemIndex(T item); + int getItemIndex(T item); @LauncherAPI - public boolean isChecked(int index); + boolean isChecked(int index); @LauncherAPI - public void toggleCheckState(int index); + void toggleCheckState(int index); } \ No newline at end of file diff --git a/Launcher/src/main/java/ru/gravit/launcher/server/ModulesManager.java b/Launcher/src/main/java/ru/gravit/launcher/server/ModulesManager.java index 8ef4d80b..40bd46ff 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/server/ModulesManager.java +++ b/Launcher/src/main/java/ru/gravit/launcher/server/ModulesManager.java @@ -1,25 +1,10 @@ package ru.gravit.launcher.server; -import java.io.IOException; -import java.net.URISyntaxException; import java.net.URL; -import java.nio.file.FileVisitResult; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.SimpleFileVisitor; -import java.nio.file.attribute.BasicFileAttributes; import java.util.ArrayList; -import java.util.jar.JarFile; -import java.util.jar.Manifest; -import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.LauncherClassLoader; import ru.gravit.launcher.modules.SimpleModuleManager; -import ru.gravit.utils.helper.IOHelper; -import ru.gravit.utils.helper.LogHelper; -import ru.gravit.launcher.modules.Module; -import ru.gravit.launcher.modules.ModulesManagerInterface; public class ModulesManager extends SimpleModuleManager { public ModulesManager(ServerWrapper wrapper) { diff --git a/Launcher/src/main/java/ru/gravit/launcher/server/ServerWrapper.java b/Launcher/src/main/java/ru/gravit/launcher/server/ServerWrapper.java index b78f4258..5858a366 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/server/ServerWrapper.java +++ b/Launcher/src/main/java/ru/gravit/launcher/server/ServerWrapper.java @@ -1,7 +1,6 @@ package ru.gravit.launcher.server; -import java.io.InputStream; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodType; diff --git a/libLauncher/src/main/java/ru/gravit/launcher/AutogenConfig.java b/libLauncher/src/main/java/ru/gravit/launcher/AutogenConfig.java index 25d75d7e..14a51321 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/AutogenConfig.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/AutogenConfig.java @@ -8,6 +8,7 @@ public class AutogenConfig { AutogenConfig() { } + @SuppressWarnings("UnnecessaryReturnStatement") public void initModules() { if(isInitModules) return; diff --git a/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java b/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java index b94fe521..c0b5151d 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java @@ -78,7 +78,7 @@ public static URL getResourceURL(String name) throws IOException { @LauncherAPI @SuppressWarnings({"SameReturnValue", "MethodReturnAlwaysConstant"}) public static String getVersion() { - return VERSION; // Because Java constants are known at compile-time + return LauncherVersion.getVersion().toString(); // Because Java constants are known at compile-time } @LauncherAPI diff --git a/libLauncher/src/main/java/ru/gravit/launcher/modules/SimpleModuleManager.java b/libLauncher/src/main/java/ru/gravit/launcher/modules/SimpleModuleManager.java index c53a96fc..91861b24 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/modules/SimpleModuleManager.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/modules/SimpleModuleManager.java @@ -52,9 +52,7 @@ public void sort() modules.sort((m1,m2) -> { int p1 = m1.getPriority(); int p2 = m2.getPriority(); - if(p1 < p2) return 1; - else if(p1 > p2) return -1; - else return 0; + return Integer.compare(p2, p1); }); } diff --git a/libLauncher/src/main/java/ru/gravit/launcher/profiles/ClientProfile.java b/libLauncher/src/main/java/ru/gravit/launcher/profiles/ClientProfile.java index 372006b5..ee11f8ac 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/profiles/ClientProfile.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/profiles/ClientProfile.java @@ -11,11 +11,6 @@ import ru.gravit.utils.helper.VerifyHelper; import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.config.ConfigObject; -import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry; -import ru.gravit.launcher.serialize.config.entry.BooleanConfigEntry; -import ru.gravit.launcher.serialize.config.entry.IntegerConfigEntry; -import ru.gravit.launcher.serialize.config.entry.ListConfigEntry; -import ru.gravit.launcher.serialize.config.entry.StringConfigEntry; import ru.gravit.launcher.serialize.stream.StreamObject; import ru.gravit.launcher.serialize.config.entry.*;