Code refactors
- Refactor LauncherFactory.LauncherProvider to LauncherFactory - Refactor all launcher related components to launcher package - some basic code cleanup - Rename all, allSafe -> getList and first, firstSafe -> getString - Rename Utils -> LegacyUtils Signed-off-by: solonovamax <solonovamax@12oclockpoint.com>
This commit is contained in:
@ -16,34 +16,39 @@
|
||||
|
||||
package org.prismlauncher.utils;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
public final class Utils {
|
||||
|
||||
private Utils() {}
|
||||
|
||||
public final class LegacyUtils {
|
||||
|
||||
private LegacyUtils() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a field that looks like a Minecraft base folder in a supplied class
|
||||
*
|
||||
* @param clazz the class to scan
|
||||
*/
|
||||
public static Field getMinecraftGameDirField(Class<?> clazz) {
|
||||
for (Field f : clazz.getDeclaredFields()) {
|
||||
// Field we're looking for is always
|
||||
// private static File obfuscatedName = null;
|
||||
for (Field field : clazz.getDeclaredFields()) {
|
||||
// Has to be File
|
||||
if (f.getType() != File.class)
|
||||
if (field.getType() != File.class)
|
||||
continue;
|
||||
|
||||
|
||||
// And Private Static.
|
||||
if (!Modifier.isStatic(f.getModifiers()) || !Modifier.isPrivate(f.getModifiers()))
|
||||
if (!Modifier.isStatic(field.getModifiers()) || !Modifier.isPrivate(field.getModifiers()))
|
||||
continue;
|
||||
|
||||
return f;
|
||||
|
||||
return field;
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -39,39 +39,39 @@ public final class Parameters {
|
||||
params.add(value);
|
||||
}
|
||||
|
||||
public List<String> all(String key) throws ParameterNotFoundException {
|
||||
public List<String> getList(String key) throws ParameterNotFoundException {
|
||||
List<String> params = map.get(key);
|
||||
|
||||
|
||||
if (params == null)
|
||||
throw new ParameterNotFoundException(key);
|
||||
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
public List<String> allSafe(String key, List<String> def) {
|
||||
|
||||
public List<String> getList(String key, List<String> def) {
|
||||
List<String> params = map.get(key);
|
||||
|
||||
|
||||
if (params == null || params.isEmpty())
|
||||
return def;
|
||||
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
public String first(String key) throws ParameterNotFoundException {
|
||||
List<String> list = all(key);
|
||||
|
||||
|
||||
public String getString(String key) throws ParameterNotFoundException {
|
||||
List<String> list = getList(key);
|
||||
|
||||
if (list.isEmpty())
|
||||
throw new ParameterNotFoundException(key);
|
||||
|
||||
|
||||
return list.get(0);
|
||||
}
|
||||
|
||||
public String firstSafe(String key, String def) {
|
||||
|
||||
public String getString(String key, String def) {
|
||||
List<String> params = map.get(key);
|
||||
|
||||
|
||||
if (params == null || params.isEmpty())
|
||||
return def;
|
||||
|
||||
|
||||
return params.get(0);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user