IDEA Refractoring

This commit is contained in:
Gravit 2018-09-19 20:53:27 +07:00
parent f53ed9be52
commit 31597cc81c
20 changed files with 39 additions and 94 deletions

View file

@ -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();

View file

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

View file

@ -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<HWID> getHwid(String username) {
return Arrays.asList(nullHWID);
return Collections.singletonList(nullHWID);
}
@Override

View file

@ -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<HWID> getHwid(String username) throws HWIDException {
ArrayList<HWID> 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);

View file

@ -172,7 +172,7 @@ public List<HWID> getHwid(String username) throws HWIDException {
try (ResultSet set = s.executeQuery()) {
if(!set.next()) {
LogHelper.error(new HWIDException("HWID not found"));
return new ArrayList<HWID>();
return new ArrayList<>();
}
hdd = set.getLong(hddName);
cpu = set.getLong(cpuName);

View file

@ -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);

View file

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

View file

@ -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) {

View file

@ -321,7 +321,7 @@ public static Process launch(
// Fill CLI arguments
List<String> 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<Path> resolveClassPathList(Path clientDir, String... classPath) throws IOException {
Collection<Path> result = new LinkedList<>();
LinkedList<Path> 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<Path> resolveClassPathList(Path clientDir, String... c
}
result.add(path);
}
return (LinkedList<Path>) result;
return result;
}
@LauncherAPI

View file

@ -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)

View file

@ -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) -> {

View file

@ -73,7 +73,7 @@ public int size() {
}
};
final MappingChange.Map<Integer, T> map = f -> getItem(f);
final MappingChange.Map<Integer, T> map = this::getItem;
checkedIndicesList.addListener((ListChangeListener<Integer>) 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);

View file

@ -5,29 +5,29 @@
public interface CheckModel<T> {
@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<T> getCheckedItems();
ObservableList<T> 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);
}

View file

@ -5,27 +5,27 @@
public interface IndexedCheckModel<T> extends CheckModel<T> {
@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<Integer> getCheckedIndices();
ObservableList<Integer> 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);
}

View file

@ -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) {

View file

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

View file

@ -8,6 +8,7 @@ public class AutogenConfig {
AutogenConfig() {
}
@SuppressWarnings("UnnecessaryReturnStatement")
public void initModules()
{
if(isInitModules) return;

View file

@ -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

View file

@ -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);
});
}

View file

@ -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.*;