Merge pull request #286 from toolbox4minecraft/switched-to-eclipse-neon

Switched to Eclipse Neon
master
Stefan Dollase 2016-11-20 23:38:43 +01:00 committed by GitHub
commit 97b6296880
124 changed files with 1066 additions and 711 deletions

File diff suppressed because one or more lines are too long

View File

@ -42,11 +42,9 @@ public class Amidst {
private static void parseCommandLineArgumentsAndRun(String[] args) {
CommandLineParameters parameters = new CommandLineParameters();
AmidstMetaData metadata = createMetadata();
CmdLineParser parser = new CmdLineParser(parameters, ParserProperties
.defaults()
.withShowDefaults(false)
.withUsageWidth(120)
.withOptionSorter(null));
CmdLineParser parser = new CmdLineParser(
parameters,
ParserProperties.defaults().withShowDefaults(false).withUsageWidth(120).withOptionSorter(null));
try {
parser.parseArgument(args);
run(parameters, metadata, parser);
@ -174,12 +172,11 @@ public class Amidst {
} catch (DotMinecraftDirectoryNotFoundException e) {
Log.w(e.getMessage());
e.printStackTrace();
JOptionPane
.showMessageDialog(
null,
"Amidst is not able to find your '.minecraft' directory, but it requires a working Minecraft installation.",
"Please install Minecraft",
JOptionPane.ERROR_MESSAGE);
JOptionPane.showMessageDialog(
null,
"Amidst is not able to find your '.minecraft' directory, but it requires a working Minecraft installation.",
"Please install Minecraft",
JOptionPane.ERROR_MESSAGE);
} catch (Exception e) {
handleCrash(e, Thread.currentThread());
}

View File

@ -34,7 +34,8 @@ public class Application {
@CalledOnlyBy(AmidstThread.EDT)
public Application(CommandLineParameters parameters, AmidstMetaData metadata, AmidstSettings settings)
throws DotMinecraftDirectoryNotFoundException, LocalMinecraftInterfaceCreationException {
throws DotMinecraftDirectoryNotFoundException,
LocalMinecraftInterfaceCreationException {
this.parameters = parameters;
this.metadata = metadata;
this.settings = settings;
@ -45,11 +46,12 @@ public class Application {
}
@CalledOnlyBy(AmidstThread.EDT)
private MojangApi createMojangApi() throws DotMinecraftDirectoryNotFoundException,
private MojangApi createMojangApi()
throws DotMinecraftDirectoryNotFoundException,
LocalMinecraftInterfaceCreationException {
return new MojangApiBuilder(new WorldBuilder(
new PlayerInformationCacheImpl(),
SeedHistoryLogger.from(parameters.seedHistoryFile)), parameters).construct();
return new MojangApiBuilder(
new WorldBuilder(new PlayerInformationCacheImpl(), SeedHistoryLogger.from(parameters.seedHistoryFile)),
parameters).construct();
}
@CalledOnlyBy(AmidstThread.EDT)
@ -89,25 +91,22 @@ public class Application {
@CalledOnlyBy(AmidstThread.EDT)
public void displayMainWindow() {
setMainWindow(new MainWindow(
this,
metadata,
settings,
mojangApi,
biomeProfileDirectory,
viewerFacadeBuilder,
threadMaster));
setMainWindow(
new MainWindow(
this,
metadata,
settings,
mojangApi,
biomeProfileDirectory,
viewerFacadeBuilder,
threadMaster));
setProfileSelectWindow(null);
}
@CalledOnlyBy(AmidstThread.EDT)
public void displayProfileSelectWindow() {
setProfileSelectWindow(new ProfileSelectWindow(
this,
metadata,
threadMaster.getWorkerExecutor(),
mojangApi,
settings));
setProfileSelectWindow(
new ProfileSelectWindow(this, metadata, threadMaster.getWorkerExecutor(), mojangApi, settings));
setMainWindow(null);
}

View File

@ -26,8 +26,11 @@ public enum Classes {
public static Map<String, SymbolicClass> createSymbolicClassMap(
File jarFile,
URLClassLoader classLoader,
ClassTranslator translator) throws FileNotFoundException, JarFileParsingException,
SymbolicClassGraphCreationException, ClassNotFoundException {
ClassTranslator translator)
throws FileNotFoundException,
JarFileParsingException,
SymbolicClassGraphCreationException,
ClassNotFoundException {
Log.i("Reading " + jarFile.getName());
List<RealClass> realClasses = RealClasses.fromJarFile(jarFile);
Log.i("Jar load complete.");
@ -42,11 +45,12 @@ public enum Classes {
}
public static Map<SymbolicClassDeclaration, Integer> countMatches(File jarFile, ClassTranslator translator)
throws FileNotFoundException, JarFileParsingException {
throws FileNotFoundException,
JarFileParsingException {
Log.i("Checking " + jarFile.getName());
List<RealClass> realClasses = RealClasses.fromJarFile(jarFile);
Map<SymbolicClassDeclaration, List<RealClass>> map = translator.translateToAllMatching(realClasses);
Map<SymbolicClassDeclaration, Integer> result = new HashMap<SymbolicClassDeclaration, Integer>();
Map<SymbolicClassDeclaration, Integer> result = new HashMap<>();
for (Entry<SymbolicClassDeclaration, List<RealClass>> entry : map.entrySet()) {
result.put(entry.getKey(), entry.getValue().size());
if (entry.getValue().isEmpty()) {
@ -56,8 +60,10 @@ public enum Classes {
for (RealClass realClass : entry.getValue()) {
builder.append(", ").append(realClass.getRealClassName());
}
Log.w(entry.getKey().getSymbolicClassName() + " has multiple matching classes: "
+ builder.toString().substring(2));
Log
.w(
entry.getKey().getSymbolicClassName() + " has multiple matching classes: "
+ builder.toString().substring(2));
}
}
return result;

View File

@ -13,7 +13,7 @@ import amidst.documentation.Immutable;
@Immutable
public class RealClass {
private static Map<Character, String> createPrimitiveTypeConversionMap() {
Map<Character, String> result = new HashMap<Character, String>();
Map<Character, String> result = new HashMap<>();
result.put('B', "byte");
result.put('C', "char");
result.put('D', "double");
@ -219,7 +219,7 @@ public class RealClass {
}
private String[] readArguments(String arguments) {
List<String> result = new ArrayList<String>();
List<String> result = new ArrayList<>();
String args = arguments.substring(1).split("\\)")[0];
Matcher matcher = ARG_PATTERN.matcher(args);
while (matcher.find()) {

View File

@ -26,11 +26,11 @@ public class RealClassBuilder {
int cpSize = readCpSize(stream);
int[] constantTypes = new int[cpSize];
RealClassConstant<?>[] constants = new RealClassConstant<?>[cpSize];
List<String> utf8Constants = new ArrayList<String>();
List<Float> floatConstants = new ArrayList<Float>();
List<Long> longConstants = new ArrayList<Long>();
List<Integer> stringIndices = new ArrayList<Integer>();
List<ReferenceIndex> methodIndices = new ArrayList<ReferenceIndex>();
List<String> utf8Constants = new ArrayList<>();
List<Float> floatConstants = new ArrayList<>();
List<Long> longConstants = new ArrayList<>();
List<Integer> stringIndices = new ArrayList<>();
List<ReferenceIndex> methodIndices = new ArrayList<>();
readConstants(
stream,
cpSize,
@ -148,7 +148,7 @@ public class RealClassBuilder {
throws IOException {
String value = readStringValue(stream);
utf8Constants.add(value);
return new RealClassConstant<String>(type, value);
return new RealClassConstant<>(type, value);
}
private String readStringValue(DataInputStream stream) throws IOException {
@ -161,31 +161,31 @@ public class RealClassBuilder {
private RealClassConstant<Integer> readInteger(DataInputStream stream, byte type) throws IOException {
int value = stream.readInt();
return new RealClassConstant<Integer>(type, value);
return new RealClassConstant<>(type, value);
}
private RealClassConstant<Float> readFloat(DataInputStream stream, byte type, List<Float> floatConstants)
throws IOException {
float value = stream.readFloat();
floatConstants.add(value);
return new RealClassConstant<Float>(type, value);
return new RealClassConstant<>(type, value);
}
private RealClassConstant<Long> readLong(DataInputStream stream, byte type, List<Long> longConstants)
throws IOException {
long value = stream.readLong();
longConstants.add(value);
return new RealClassConstant<Long>(type, value);
return new RealClassConstant<>(type, value);
}
private RealClassConstant<Double> readDouble(DataInputStream stream, byte type) throws IOException {
double value = stream.readDouble();
return new RealClassConstant<Double>(type, value);
return new RealClassConstant<>(type, value);
}
private RealClassConstant<Integer> readClassReference(DataInputStream stream, byte type) throws IOException {
int value = stream.readUnsignedShort();
return new RealClassConstant<Integer>(type, value);
return new RealClassConstant<>(type, value);
}
private RealClassConstant<Integer> readStringReference(
@ -194,13 +194,13 @@ public class RealClassBuilder {
List<Integer> stringIndices) throws IOException {
int value = stream.readUnsignedShort();
stringIndices.add(value);
return new RealClassConstant<Integer>(type, value);
return new RealClassConstant<>(type, value);
}
private RealClassConstant<ReferenceIndex> readAnotherReference(DataInputStream stream, byte type)
throws IOException {
ReferenceIndex value = readReferenceIndex(stream);
return new RealClassConstant<ReferenceIndex>(type, value);
return new RealClassConstant<>(type, value);
}
private int readAccessFlags(DataInputStream stream) throws IOException {

View File

@ -1,31 +1,25 @@
package amidst.clazz.real;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import amidst.documentation.Immutable;
@Immutable
@FunctionalInterface
public interface RealClassDetector {
public default RealClass firstMatching(List<RealClass> realClasses) {
for (RealClass realClass : realClasses) {
if (detect(realClass)) {
return realClass;
}
}
return null;
public class RealClassDetector {
private final Predicate<RealClass> predicate;
public RealClassDetector(Predicate<RealClass> predicate) {
this.predicate = predicate;
}
public default List<RealClass> allMatching(List<RealClass> realClasses) {
List<RealClass> result = new ArrayList<RealClass>();
for (RealClass realClass : realClasses) {
if (detect(realClass)) {
result.add(realClass);
}
}
return result;
public Optional<RealClass> firstMatching(List<RealClass> realClasses) {
return realClasses.stream().filter(predicate).findFirst();
}
public boolean detect(RealClass realClass);
public List<RealClass> allMatching(List<RealClass> realClasses) {
return realClasses.stream().filter(predicate).collect(Collectors.toList());
}
}

View File

@ -16,14 +16,15 @@ import amidst.documentation.Immutable;
public enum RealClasses {
;
private static final int MAXIMUM_CLASS_BYTES = 16*1024;
private static final int MAXIMUM_CLASS_BYTES = 16 * 1024;
private static final RealClassBuilder REAL_CLASS_BUILDER = new RealClassBuilder();
public static List<RealClass> fromJarFile(File jarFile) throws FileNotFoundException, JarFileParsingException {
return readRealClassesFromJarFile(jarFile);
}
private static List<RealClass> readRealClassesFromJarFile(File jarFile) throws JarFileParsingException,
private static List<RealClass> readRealClassesFromJarFile(File jarFile)
throws JarFileParsingException,
FileNotFoundException {
if (!jarFile.exists()) {
throw new FileNotFoundException("Attempted to load jar file at: " + jarFile + " but it does not exist.");
@ -39,7 +40,7 @@ public enum RealClasses {
private static List<RealClass> readJarFile(ZipFile zipFile) throws IOException, RealClassCreationException {
Enumeration<? extends ZipEntry> enu = zipFile.entries();
List<RealClass> result = new ArrayList<RealClass>();
List<RealClass> result = new ArrayList<>();
while (enu.hasMoreElements()) {
RealClass entry = readJarFileEntry(zipFile, enu.nextElement());
if (entry != null) {
@ -49,7 +50,8 @@ public enum RealClasses {
return result;
}
private static RealClass readJarFileEntry(ZipFile zipFile, ZipEntry entry) throws IOException,
private static RealClass readJarFileEntry(ZipFile zipFile, ZipEntry entry)
throws IOException,
RealClassCreationException {
String realClassName = getFileNameWithoutExtension(entry.getName(), "class");
if (!entry.isDirectory() && realClassName != null) {
@ -59,7 +61,8 @@ public enum RealClasses {
}
}
private static RealClass readRealClass(String realClassName, BufferedInputStream stream) throws IOException,
private static RealClass readRealClass(String realClassName, BufferedInputStream stream)
throws IOException,
RealClassCreationException {
try (BufferedInputStream theStream = stream) {
// TODO: Double check that this filter won't mess anything up.

View File

@ -59,22 +59,30 @@ public class SymbolicClass {
return fieldsBySymbolicName.get(symbolicName) != null;
}
public SymbolicObject callConstructor(String symbolicName, Object... parameters) throws InstantiationException,
IllegalAccessException, IllegalArgumentException, InvocationTargetException {
public SymbolicObject callConstructor(String symbolicName, Object... parameters)
throws InstantiationException,
IllegalAccessException,
IllegalArgumentException,
InvocationTargetException {
return constructorsBySymbolicName.get(symbolicName).call(parameters);
}
public Object callMethod(String symbolicName, SymbolicObject symbolicObject, Object... parameters)
throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
throws IllegalAccessException,
IllegalArgumentException,
InvocationTargetException {
return methodsBySymbolicName.get(symbolicName).call(symbolicObject, parameters);
}
public Object callStaticMethod(String symbolicName, Object... parameters) throws IllegalAccessException,
IllegalArgumentException, InvocationTargetException {
public Object callStaticMethod(String symbolicName, Object... parameters)
throws IllegalAccessException,
IllegalArgumentException,
InvocationTargetException {
return methodsBySymbolicName.get(symbolicName).callStatic(parameters);
}
public Object getFieldValue(String symbolicName, SymbolicObject symbolicObject) throws IllegalArgumentException,
public Object getFieldValue(String symbolicName, SymbolicObject symbolicObject)
throws IllegalArgumentException,
IllegalAccessException {
return fieldsBySymbolicName.get(symbolicName).getValue(symbolicObject);
}

View File

@ -19,7 +19,7 @@ import amidst.documentation.NotThreadSafe;
@NotThreadSafe
public class SymbolicClassBuilder {
private static Map<String, Class<?>> createPrimitivesMap() {
Map<String, Class<?>> result = new HashMap<String, Class<?>>();
Map<String, Class<?>> result = new HashMap<>();
result.put("byte", byte.class);
result.put("int", int.class);
result.put("float", float.class);
@ -34,9 +34,9 @@ public class SymbolicClassBuilder {
private static final Map<String, Class<?>> PRIMITIVES_MAP = createPrimitivesMap();
private final Map<String, SymbolicConstructor> constructorsBySymbolicName = new HashMap<String, SymbolicConstructor>();
private final Map<String, SymbolicMethod> methodsBySymbolicName = new HashMap<String, SymbolicMethod>();
private final Map<String, SymbolicField> fieldsBySymbolicName = new HashMap<String, SymbolicField>();
private final Map<String, SymbolicConstructor> constructorsBySymbolicName = new HashMap<>();
private final Map<String, SymbolicMethod> methodsBySymbolicName = new HashMap<>();
private final Map<String, SymbolicField> fieldsBySymbolicName = new HashMap<>();
private final ClassLoader classLoader;
private final Map<String, String> realClassNamesBySymbolicClassName;
@ -94,14 +94,16 @@ public class SymbolicClassBuilder {
}
private SymbolicConstructor createConstructor(SymbolicConstructorDeclaration declaration)
throws ClassNotFoundException, NoSuchMethodException {
throws ClassNotFoundException,
NoSuchMethodException {
String symbolicName = declaration.getSymbolicName();
Class<?>[] parameterClasses = getParameterClasses(declaration.getParameters().getDeclarations());
Constructor<?> constructor = getConstructor(product.getClazz(), parameterClasses);
return new SymbolicConstructor(product, symbolicName, constructor);
}
private SymbolicMethod createMethod(SymbolicMethodDeclaration declaration) throws ClassNotFoundException,
private SymbolicMethod createMethod(SymbolicMethodDeclaration declaration)
throws ClassNotFoundException,
NoSuchMethodException {
String symbolicName = declaration.getSymbolicName();
String realName = declaration.getRealName();
@ -125,7 +127,8 @@ public class SymbolicClassBuilder {
return result;
}
private Method getMethod(Class<?> clazz, String realName, Class<?>[] parameterClasses) throws NoSuchMethodException {
private Method getMethod(Class<?> clazz, String realName, Class<?>[] parameterClasses)
throws NoSuchMethodException {
Method result = clazz.getDeclaredMethod(realName, parameterClasses);
result.setAccessible(true);
return result;

View File

@ -24,9 +24,9 @@ public class SymbolicClassGraphBuilder {
}
public Map<String, SymbolicClass> construct() throws SymbolicClassGraphCreationException {
Map<String, String> realClassNamesBySymbolicClassName = new HashMap<String, String>();
Map<String, SymbolicClass> symbolicClassesByRealClassName = new HashMap<String, SymbolicClass>();
Map<SymbolicClassDeclaration, SymbolicClassBuilder> symbolicClassBuildersBySymbolicClassDeclaration = new HashMap<SymbolicClassDeclaration, SymbolicClassBuilder>();
Map<String, String> realClassNamesBySymbolicClassName = new HashMap<>();
Map<String, SymbolicClass> symbolicClassesByRealClassName = new HashMap<>();
Map<SymbolicClassDeclaration, SymbolicClassBuilder> symbolicClassBuildersBySymbolicClassDeclaration = new HashMap<>();
createSymbolicClasses(
realClassNamesBySymbolicClassName,
symbolicClassesByRealClassName,
@ -97,7 +97,7 @@ public class SymbolicClassGraphBuilder {
private Map<String, SymbolicClass> createProduct(
Map<SymbolicClassDeclaration, SymbolicClassBuilder> symbolicClassBuildersBySymbolicClassDeclaration) {
Map<String, SymbolicClass> result = new HashMap<String, SymbolicClass>();
Map<String, SymbolicClass> result = new HashMap<>();
for (Entry<SymbolicClassDeclaration, SymbolicClassBuilder> entry : symbolicClassBuildersBySymbolicClassDeclaration
.entrySet()) {
result.put(entry.getKey().getSymbolicClassName(), entry.getValue().getProduct());

View File

@ -17,13 +17,19 @@ public class SymbolicConstructor {
this.constructor = constructor;
}
public SymbolicObject call(Object... parameters) throws InstantiationException, IllegalAccessException,
IllegalArgumentException, InvocationTargetException {
public SymbolicObject call(Object... parameters)
throws InstantiationException,
IllegalAccessException,
IllegalArgumentException,
InvocationTargetException {
return new SymbolicObject(parent, newInstance(parameters));
}
private Object newInstance(Object... parameters) throws InstantiationException, IllegalAccessException,
IllegalArgumentException, InvocationTargetException {
private Object newInstance(Object... parameters)
throws InstantiationException,
IllegalAccessException,
IllegalArgumentException,
InvocationTargetException {
return constructor.newInstance(parameters);
}

View File

@ -34,18 +34,24 @@ public class SymbolicMethod {
return realName;
}
public Object call(SymbolicObject symbolicObject, Object... parameters) throws IllegalAccessException,
IllegalArgumentException, InvocationTargetException {
public Object call(SymbolicObject symbolicObject, Object... parameters)
throws IllegalAccessException,
IllegalArgumentException,
InvocationTargetException {
return callFromObject(symbolicObject.getObject(), parameters);
}
public Object callStatic(Object... parameters) throws IllegalAccessException, IllegalArgumentException,
public Object callStatic(Object... parameters)
throws IllegalAccessException,
IllegalArgumentException,
InvocationTargetException {
return callFromObject(null, parameters);
}
private Object callFromObject(Object object, Object... parameters) throws IllegalAccessException,
IllegalArgumentException, InvocationTargetException {
private Object callFromObject(Object object, Object... parameters)
throws IllegalAccessException,
IllegalArgumentException,
InvocationTargetException {
Object value = invoke(object, parameters);
if (isReturnTypeSymbolicClass()) {
return new SymbolicObject(returnType, value);
@ -53,7 +59,9 @@ public class SymbolicMethod {
return value;
}
private Object invoke(Object object, Object... parameters) throws IllegalAccessException, IllegalArgumentException,
private Object invoke(Object object, Object... parameters)
throws IllegalAccessException,
IllegalArgumentException,
InvocationTargetException {
return method.invoke(object, parameters);
}

View File

@ -34,8 +34,10 @@ public class SymbolicObject {
return type.hasField(symbolicName);
}
public Object callMethod(String symbolicName, Object... parameters) throws IllegalAccessException,
IllegalArgumentException, InvocationTargetException {
public Object callMethod(String symbolicName, Object... parameters)
throws IllegalAccessException,
IllegalArgumentException,
InvocationTargetException {
return type.callMethod(symbolicName, this, parameters);
}

View File

@ -60,8 +60,8 @@ public class SymbolicClassDeclaration {
if (isOptional) {
Log.i("Missing class " + symbolicClassName);
} else {
throw new ClassNotFoundException("cannot find a real class matching the symbolic class "
+ symbolicClassName);
throw new ClassNotFoundException(
"cannot find a real class matching the symbolic class " + symbolicClassName);
}
}

View File

@ -15,7 +15,7 @@ public class SymbolicParameterDeclarationList {
@Immutable
public static class SymbolicParameterDeclarationListBuilder<T> {
private final T nextBuilder;
private final List<SymbolicParameterDeclaration> declarations = new ArrayList<SymbolicParameterDeclaration>();
private final List<SymbolicParameterDeclaration> declarations = new ArrayList<>();
private final ExecuteOnEnd executeOnEnd;
public SymbolicParameterDeclarationListBuilder(T nextBuilder, ExecuteOnEnd executeOnEnd) {

View File

@ -4,7 +4,9 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Predicate;
import amidst.clazz.real.RealClass;
import amidst.clazz.real.RealClassDetector;
import amidst.clazz.symbolic.declaration.SymbolicClassDeclaration;
import amidst.clazz.symbolic.declaration.SymbolicConstructorDeclaration;
@ -24,9 +26,9 @@ public class CTBuilder {
public class SCDBuilder {
private String symbolicClassName;
private boolean isOptional;
private final List<SymbolicConstructorDeclaration> constructors = new ArrayList<SymbolicConstructorDeclaration>();
private final List<SymbolicMethodDeclaration> methods = new ArrayList<SymbolicMethodDeclaration>();
private final List<SymbolicFieldDeclaration> fields = new ArrayList<SymbolicFieldDeclaration>();
private final List<SymbolicConstructorDeclaration> constructors = new ArrayList<>();
private final List<SymbolicMethodDeclaration> methods = new ArrayList<>();
private final List<SymbolicFieldDeclaration> fields = new ArrayList<>();
private void init(String symbolicClassName, boolean isOptional) {
this.symbolicClassName = symbolicClassName;
@ -56,7 +58,7 @@ public class CTBuilder {
private SymbolicParameterDeclarationListBuilder<SCDBuilder> constructor(
final String symbolicName,
final boolean isOptional) {
return new SymbolicParameterDeclarationListBuilder<SCDBuilder>(this, new ExecuteOnEnd() {
return new SymbolicParameterDeclarationListBuilder<>(this, new ExecuteOnEnd() {
@Override
public void run(SymbolicParameterDeclarationList parameters) {
constructors.add(new SymbolicConstructorDeclaration(symbolicName, isOptional, parameters));
@ -64,11 +66,15 @@ public class CTBuilder {
});
}
public SymbolicParameterDeclarationListBuilder<SCDBuilder> requiredMethod(String symbolicName, String realName) {
public SymbolicParameterDeclarationListBuilder<SCDBuilder> requiredMethod(
String symbolicName,
String realName) {
return method(symbolicName, realName, false);
}
public SymbolicParameterDeclarationListBuilder<SCDBuilder> optionalMethod(String symbolicName, String realName) {
public SymbolicParameterDeclarationListBuilder<SCDBuilder> optionalMethod(
String symbolicName,
String realName) {
return method(symbolicName, realName, true);
}
@ -76,7 +82,7 @@ public class CTBuilder {
final String symbolicName,
final String realName,
final boolean isOptional) {
return new SymbolicParameterDeclarationListBuilder<SCDBuilder>(this, new ExecuteOnEnd() {
return new SymbolicParameterDeclarationListBuilder<>(this, new ExecuteOnEnd() {
@Override
public void run(SymbolicParameterDeclarationList parameters) {
methods.add(new SymbolicMethodDeclaration(symbolicName, realName, isOptional, parameters));
@ -111,11 +117,11 @@ public class CTBuilder {
this.previous = previous;
}
public CTBuilder ifDetect(RealClassDetector detector) {
this.detector = detector;
public CTBuilder ifDetect(Predicate<RealClass> predicate) {
this.detector = new RealClassDetector(predicate);
return this;
}
public SCDBuilder thenDeclareRequired(String symbolicClassName) {
return thenDeclare(symbolicClassName, false);
}
@ -125,10 +131,11 @@ public class CTBuilder {
}
private SCDBuilder thenDeclare(String symbolicClassName, boolean isOptional) {
if(detector == null)
if (detector == null) {
throw new IllegalStateException("can't declare a symbolic class without calling ifDetect before");
CTBuilder.this.declarationBuilder.init(symbolicClassName, isOptional);
return CTBuilder.this.declarationBuilder;
}
declarationBuilder.init(symbolicClassName, isOptional);
return declarationBuilder;
}
public ClassTranslator construct() {
@ -145,7 +152,7 @@ public class CTBuilder {
if (previous != null) {
return previous.constructResult();
} else {
return new HashMap<RealClassDetector, SymbolicClassDeclaration>();
return new HashMap<>();
}
}
}

View File

@ -4,6 +4,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import amidst.clazz.real.RealClass;
import amidst.clazz.real.RealClassDetector;
@ -23,7 +24,7 @@ public class ClassTranslator {
}
public Map<SymbolicClassDeclaration, List<RealClass>> translateToAllMatching(List<RealClass> realClasses) {
Map<SymbolicClassDeclaration, List<RealClass>> result = new HashMap<SymbolicClassDeclaration, List<RealClass>>();
Map<SymbolicClassDeclaration, List<RealClass>> result = new HashMap<>();
for (Entry<RealClassDetector, SymbolicClassDeclaration> entry : translations.entrySet()) {
SymbolicClassDeclaration declaration = entry.getValue();
List<RealClass> allMatching = entry.getKey().allMatching(realClasses);
@ -37,14 +38,12 @@ public class ClassTranslator {
}
public Map<SymbolicClassDeclaration, String> translate(List<RealClass> realClasses) throws ClassNotFoundException {
Map<SymbolicClassDeclaration, String> result = new HashMap<SymbolicClassDeclaration, String>();
Map<SymbolicClassDeclaration, String> result = new HashMap<>();
for (Entry<RealClassDetector, SymbolicClassDeclaration> entry : translations.entrySet()) {
RealClass firstMatching = entry.getKey().firstMatching(realClasses);
String realClassName = null;
if (firstMatching != null) {
realClassName = firstMatching.getRealClassName();
}
addResult(result, entry.getValue(), realClassName);
addResult(
result,
entry.getValue(),
entry.getKey().firstMatching(realClasses).map(RealClass::getRealClassName));
}
return result;
}
@ -52,14 +51,14 @@ public class ClassTranslator {
private void addResult(
Map<SymbolicClassDeclaration, String> result,
SymbolicClassDeclaration declaration,
String realClassName) throws ClassNotFoundException {
if (realClassName == null) {
Optional<String> realClassName) throws ClassNotFoundException {
if (!realClassName.isPresent()) {
declaration.handleNoMatch();
} else if (result.containsKey(declaration)) {
declaration.handleMultipleMatches(result.get(declaration), realClassName);
declaration.handleMultipleMatches(result.get(declaration), realClassName.get());
} else {
declaration.handleMatch(realClassName);
result.put(declaration, realClassName);
declaration.handleMatch(realClassName.get());
result.put(declaration, realClassName.get());
}
}
}

View File

@ -89,8 +89,8 @@ public class Fragment {
private final AtomicReferenceArray<List<WorldIcon>> worldIcons;
public Fragment(int numberOfLayers) {
this.images = new AtomicReferenceArray<BufferedImage>(numberOfLayers);
this.worldIcons = new AtomicReferenceArray<List<WorldIcon>>(numberOfLayers);
this.images = new AtomicReferenceArray<>(numberOfLayers);
this.worldIcons = new AtomicReferenceArray<>(numberOfLayers);
}
public void setAlpha(float alpha) {

View File

@ -14,7 +14,7 @@ import amidst.logging.Log;
public class FragmentCache {
private static final int NEW_FRAGMENTS_PER_REQUEST = 1024;
private final List<Fragment> cache = new LinkedList<Fragment>();
private final List<Fragment> cache = new LinkedList<>();
private volatile int cacheSize = 0;
private final ConcurrentLinkedQueue<Fragment> availableQueue;
@ -36,8 +36,10 @@ public class FragmentCache {
@CalledOnlyBy(AmidstThread.EDT)
public synchronized void increaseSize() {
Log.i("increasing fragment cache size from " + cache.size() + " to "
+ (cache.size() + NEW_FRAGMENTS_PER_REQUEST));
Log
.i(
"increasing fragment cache size from " + cache.size() + " to "
+ (cache.size() + NEW_FRAGMENTS_PER_REQUEST));
requestNewFragments();
Log.i("fragment cache size increased to " + cache.size());
}

View File

@ -47,12 +47,8 @@ public class FragmentGraph implements Iterable<FragmentGraphItem> {
public void adjust(int newLeft, int newAbove, int newRight, int newBelow) {
fragmentsPerRow = fragmentsPerRow + newLeft + newRight;
fragmentsPerColumn = fragmentsPerColumn + newAbove + newBelow;
topLeftFragment.replaceWithValue(f -> f.adjustRowsAndColumns(
newAbove,
newBelow,
newLeft,
newRight,
fragmentManager));
topLeftFragment
.replaceWithValue(f -> f.adjustRowsAndColumns(newAbove, newBelow, newLeft, newRight, fragmentManager));
}
@CalledOnlyBy(AmidstThread.EDT)

View File

@ -13,9 +13,9 @@ import amidst.settings.Setting;
@NotThreadSafe
public class FragmentManager {
private final ConcurrentLinkedQueue<Fragment> availableQueue = new ConcurrentLinkedQueue<Fragment>();
private final ConcurrentLinkedQueue<Fragment> loadingQueue = new ConcurrentLinkedQueue<Fragment>();
private final ConcurrentLinkedQueue<Fragment> recycleQueue = new ConcurrentLinkedQueue<Fragment>();
private final ConcurrentLinkedQueue<Fragment> availableQueue = new ConcurrentLinkedQueue<>();
private final ConcurrentLinkedQueue<Fragment> loadingQueue = new ConcurrentLinkedQueue<>();
private final ConcurrentLinkedQueue<Fragment> recycleQueue = new ConcurrentLinkedQueue<>();
private final FragmentCache cache;
@CalledOnlyBy(AmidstThread.EDT)

View File

@ -30,7 +30,6 @@ public class TheEndColorProvider implements ColorProvider {
public int getColorAt(Dimension dimension, Fragment fragment, long cornerX, long cornerY, int x, int y) {
long xAsQuarter = cornerX + x;
long yAsQuarter = cornerY + y;
// @formatter:off
return getColorAt(
(int) (xAsQuarter << 2),
(int) (yAsQuarter << 2),
@ -39,7 +38,6 @@ public class TheEndColorProvider implements ColorProvider {
(int) (x % TEXTURES_WIDTH),
(int) (y % TEXTURES_HEIGHT),
fragment.getEndIslands());
// @formatter:on
}
private int getColorAt(

View File

@ -33,7 +33,6 @@ import amidst.gui.main.viewer.Zoom;
import amidst.mojangapi.world.Dimension;
import amidst.mojangapi.world.World;
import amidst.mojangapi.world.coordinates.Resolution;
import amidst.mojangapi.world.oracle.EndIsland;
import amidst.mojangapi.world.versionfeatures.VersionFeatures;
import amidst.settings.Setting;
import amidst.settings.Settings;
@ -50,14 +49,12 @@ public class LayerBuilder {
* This also defines the construction order.
*/
private Iterable<FragmentConstructor> createConstructors() {
// @formatter:off
return Collections.unmodifiableList(Arrays.asList(
new BiomeDataConstructor(Resolution.QUARTER),
new EndIslandsConstructor(),
new ImageConstructor( Resolution.QUARTER, LayerIds.BACKGROUND),
new ImageConstructor( Resolution.CHUNK, LayerIds.SLIME)
));
// @formatter:on
return Collections.unmodifiableList(
Arrays.asList(
new BiomeDataConstructor(Resolution.QUARTER),
new EndIslandsConstructor(),
new ImageConstructor(Resolution.QUARTER, LayerIds.BACKGROUND),
new ImageConstructor(Resolution.CHUNK, LayerIds.SLIME)));
}
public Iterable<FragmentConstructor> getConstructors() {
@ -75,13 +72,13 @@ public class LayerBuilder {
WorldIconSelection worldIconSelection,
Zoom zoom,
Graphics2DAccelerationCounter accelerationCounter) {
// @formatter:off
List<LayerDeclaration> declarations = createDeclarations(settings, world.getVersionFeatures());
return new LayerManager(
declarations,
new LayerLoader(createLoaders(declarations, world, biomeSelection, settings), LayerIds.NUMBER_OF_LAYERS),
new LayerLoader(
createLoaders(declarations, world, biomeSelection, settings),
LayerIds.NUMBER_OF_LAYERS),
createDrawers(declarations, zoom, worldIconSelection, accelerationCounter));
// @formatter:on
}
private List<LayerDeclaration> createDeclarations(AmidstSettings settings, VersionFeatures versionFeatures) {
@ -133,20 +130,20 @@ public class LayerBuilder {
AmidstSettings settings) {
// @formatter:off
return Collections.unmodifiableList(Arrays.asList(
new AlphaInitializer( declarations.get(LayerIds.ALPHA), settings.fragmentFading),
new BiomeDataLoader( declarations.get(LayerIds.BIOME_DATA), world.getBiomeDataOracle()),
new EndIslandsLoader( declarations.get(LayerIds.END_ISLANDS), world.getEndIslandOracle()),
new ImageLoader( declarations.get(LayerIds.BACKGROUND), Resolution.QUARTER, new BackgroundColorProvider(new BiomeColorProvider(biomeSelection, settings.biomeProfileSelection), new TheEndColorProvider())),
new ImageLoader( declarations.get(LayerIds.SLIME), Resolution.CHUNK, new SlimeColorProvider(world.getSlimeChunkOracle())),
new WorldIconLoader<Void>( declarations.get(LayerIds.SPAWN), world.getSpawnProducer()),
new WorldIconLoader<Void>( declarations.get(LayerIds.STRONGHOLD), world.getStrongholdProducer()),
new WorldIconLoader<Void>( declarations.get(LayerIds.PLAYER), world.getPlayerProducer()),
new WorldIconLoader<Void>( declarations.get(LayerIds.VILLAGE), world.getVillageProducer()),
new WorldIconLoader<Void>( declarations.get(LayerIds.TEMPLE), world.getTempleProducer()),
new WorldIconLoader<Void>( declarations.get(LayerIds.MINESHAFT), world.getMineshaftProducer()),
new WorldIconLoader<Void>( declarations.get(LayerIds.OCEAN_MONUMENT), world.getOceanMonumentProducer()),
new WorldIconLoader<Void>( declarations.get(LayerIds.NETHER_FORTRESS), world.getNetherFortressProducer()),
new WorldIconLoader<List<EndIsland>>(declarations.get(LayerIds.END_CITY), world.getEndCityProducer(), Fragment::getEndIslands)
new AlphaInitializer( declarations.get(LayerIds.ALPHA), settings.fragmentFading),
new BiomeDataLoader( declarations.get(LayerIds.BIOME_DATA), world.getBiomeDataOracle()),
new EndIslandsLoader( declarations.get(LayerIds.END_ISLANDS), world.getEndIslandOracle()),
new ImageLoader( declarations.get(LayerIds.BACKGROUND), Resolution.QUARTER, new BackgroundColorProvider(new BiomeColorProvider(biomeSelection, settings.biomeProfileSelection), new TheEndColorProvider())),
new ImageLoader( declarations.get(LayerIds.SLIME), Resolution.CHUNK, new SlimeColorProvider(world.getSlimeChunkOracle())),
new WorldIconLoader<>(declarations.get(LayerIds.SPAWN), world.getSpawnProducer()),
new WorldIconLoader<>(declarations.get(LayerIds.STRONGHOLD), world.getStrongholdProducer()),
new WorldIconLoader<>(declarations.get(LayerIds.PLAYER), world.getPlayerProducer()),
new WorldIconLoader<>(declarations.get(LayerIds.VILLAGE), world.getVillageProducer()),
new WorldIconLoader<>(declarations.get(LayerIds.TEMPLE), world.getTempleProducer()),
new WorldIconLoader<>(declarations.get(LayerIds.MINESHAFT), world.getMineshaftProducer()),
new WorldIconLoader<>(declarations.get(LayerIds.OCEAN_MONUMENT), world.getOceanMonumentProducer()),
new WorldIconLoader<>(declarations.get(LayerIds.NETHER_FORTRESS), world.getNetherFortressProducer()),
new WorldIconLoader<>(declarations.get(LayerIds.END_CITY), world.getEndCityProducer(), Fragment::getEndIslands)
));
// @formatter:on
}

View File

@ -19,8 +19,7 @@ public class LayerDeclaration {
private volatile boolean isVisible;
/**
* @param dimension
* Can be null to enable for all dimensions.
* @param dimension Can be null to enable for all dimensions.
*/
public LayerDeclaration(
int layerId,

View File

@ -20,7 +20,10 @@ public class LayerManager {
private final LayerLoader layerLoader;
private final Iterable<FragmentDrawer> drawers;
public LayerManager(List<LayerDeclaration> declarations, LayerLoader layerLoader, Iterable<FragmentDrawer> drawers) {
public LayerManager(
List<LayerDeclaration> declarations,
LayerLoader layerLoader,
Iterable<FragmentDrawer> drawers) {
this.declarations = declarations;
this.layerLoader = layerLoader;
this.drawers = drawers;

View File

@ -13,10 +13,10 @@ import javax.swing.JTextField;
import javax.swing.ScrollPaneConstants;
import javax.swing.border.LineBorder;
import net.miginfocom.swing.MigLayout;
import amidst.documentation.AmidstThread;
import amidst.documentation.CalledOnlyBy;
import amidst.documentation.NotThreadSafe;
import net.miginfocom.swing.MigLayout;
@NotThreadSafe
public enum CrashWindow {

View File

@ -15,9 +15,9 @@ import javax.swing.border.LineBorder;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import net.miginfocom.swing.MigLayout;
import amidst.AmidstMetaData;
import amidst.documentation.Immutable;
import net.miginfocom.swing.MigLayout;
@Immutable
public class LicenseWindow {
@ -64,7 +64,7 @@ public class LicenseWindow {
}
private JList<License> createLicenseList(License[] licenses, final JTextArea textArea) {
final JList<License> result = new JList<License>(licenses);
final JList<License> result = new JList<>(licenses);
result.setBorder(new LineBorder(Color.darkGray, 1));
result.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
result.addListSelectionListener(new ListSelectionListener() {

View File

@ -129,10 +129,8 @@ public class Actions {
public void goToStronghold() {
ViewerFacade viewerFacade = this.viewerFacade.get();
if (viewerFacade != null) {
WorldIcon stronghold = mainWindow.askForOptions(
"Go to",
"Select Stronghold:",
viewerFacade.getStrongholdWorldIcons());
WorldIcon stronghold = mainWindow
.askForOptions("Go to", "Select Stronghold:", viewerFacade.getStrongholdWorldIcons());
if (stronghold != null) {
viewerFacade.centerOn(stronghold);
}
@ -214,15 +212,16 @@ public class Actions {
if (file != null) {
file = appendPNGFileExtensionIfNecessary(file);
if (file.exists() && !file.isFile()) {
mainWindow
.displayError("Unable to write capture image, because the target exists but is not a file: "
mainWindow.displayError(
"Unable to write capture image, because the target exists but is not a file: "
+ file.getAbsolutePath());
} else if (!canWriteToFile(file)) {
mainWindow.displayError("Unable to write capture image, because you have no writing permissions: "
+ file.getAbsolutePath());
} else if (!file.exists()
|| mainWindow.askToConfirm("Replace file?", "File already exists. Do you want to replace it?\n"
+ file.getAbsolutePath() + "")) {
mainWindow.displayError(
"Unable to write capture image, because you have no writing permissions: "
+ file.getAbsolutePath());
} else if (!file.exists() || mainWindow.askToConfirm(
"Replace file?",
"File already exists. Do you want to replace it?\n" + file.getAbsolutePath() + "")) {
saveImageToFile(image, file);
}
}
@ -251,9 +250,11 @@ public class Actions {
@CalledOnlyBy(AmidstThread.EDT)
public void about() {
mainWindow.displayMessage("About", "Amidst - Advanced Minecraft Interfacing and Data/Structure Tracking\n\n"
+ "Author: Skidoodle aka skiphs\n" + "Mail: toolbox4minecraft+amidst@gmail.com\n"
+ "Project Page: https://github.com/toolbox4minecraft/amidst");
mainWindow.displayMessage(
"About",
"Amidst - Advanced Minecraft Interfacing and Data/Structure Tracking\n\n"
+ "Author: Skidoodle aka skiphs\n" + "Mail: toolbox4minecraft+amidst@gmail.com\n"
+ "Project Page: https://github.com/toolbox4minecraft/amidst");
}
@CalledOnlyBy(AmidstThread.EDT)
@ -285,10 +286,8 @@ public class Actions {
ViewerFacade viewerFacade = this.viewerFacade.get();
if (viewerFacade != null) {
if (viewerFacade.canSavePlayerLocations()) {
new MovePlayerPopupMenu(this, viewerFacade.getMovablePlayerList(), targetCoordinates).show(
component,
x,
y);
new MovePlayerPopupMenu(this, viewerFacade.getMovablePlayerList(), targetCoordinates)
.show(component, x, y);
}
}
}

View File

@ -55,7 +55,7 @@ public class MainWindow {
private final AmidstMenu menuBar;
private final SeedSearcherWindow seedSearcherWindow;
private final AtomicReference<ViewerFacade> viewerFacade = new AtomicReference<ViewerFacade>();
private final AtomicReference<ViewerFacade> viewerFacade = new AtomicReference<>();
@CalledOnlyBy(AmidstThread.EDT)
public MainWindow(
@ -86,10 +86,11 @@ public class MainWindow {
@CalledOnlyBy(AmidstThread.EDT)
private JFrame createFrame() {
JFrame frame = new JFrame();
frame.setTitle(createVersionString(
mojangApi.getVersionId(),
mojangApi.getRecognisedVersionName(),
mojangApi.getProfileName()));
frame.setTitle(
createVersionString(
mojangApi.getVersionId(),
mojangApi.getRecognisedVersionName(),
mojangApi.getProfileName()));
frame.setSize(1000, 800);
frame.setIconImages(metadata.getIcons());
return frame;
@ -122,10 +123,10 @@ public class MainWindow {
@CalledOnlyBy(AmidstThread.EDT)
private SeedSearcherWindow createSeedSearcherWindow() {
return new SeedSearcherWindow(metadata, this, new SeedSearcher(
return new SeedSearcherWindow(
metadata,
this,
mojangApi,
threadMaster.getWorkerExecutor()));
new SeedSearcher(this, mojangApi, threadMaster.getWorkerExecutor()));
}
@CalledOnlyBy(AmidstThread.EDT)
@ -316,7 +317,8 @@ public class MainWindow {
@CalledOnlyBy(AmidstThread.EDT)
public boolean askToConfirm(String title, String message) {
return JOptionPane.showConfirmDialog(frame, message, title, JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION;
return JOptionPane
.showConfirmDialog(frame, message, title, JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION;
}
@CalledOnlyBy(AmidstThread.EDT)
@ -333,14 +335,8 @@ public class MainWindow {
@SuppressWarnings("unchecked")
public <T> T askForOptions(String title, String message, List<T> choices) {
Object[] choicesArray = choices.toArray();
return (T) JOptionPane.showInputDialog(
frame,
message,
title,
JOptionPane.PLAIN_MESSAGE,
null,
choicesArray,
choicesArray[0]);
return (T) JOptionPane
.showInputDialog(frame, message, title, JOptionPane.PLAIN_MESSAGE, null, choicesArray, choicesArray[0]);
}
@CalledOnlyBy(AmidstThread.EDT)

View File

@ -14,10 +14,10 @@ import javax.swing.event.AncestorListener;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import net.miginfocom.swing.MigLayout;
import amidst.documentation.NotThreadSafe;
import amidst.mojangapi.world.WorldSeed;
import amidst.mojangapi.world.WorldSeed.WorldSeedType;
import net.miginfocom.swing.MigLayout;
@NotThreadSafe
public class SeedPrompt {

View File

@ -3,14 +3,14 @@ package amidst.gui.main;
import java.io.IOException;
import java.io.Reader;
import amidst.documentation.Immutable;
import amidst.documentation.NotNull;
import amidst.mojangapi.file.URIUtils;
import com.google.gson.Gson;
import com.google.gson.JsonIOException;
import com.google.gson.JsonSyntaxException;
import amidst.documentation.Immutable;
import amidst.documentation.NotNull;
import amidst.mojangapi.file.URIUtils;
@Immutable
public enum UpdateInformationRetriever {
;

View File

@ -28,31 +28,39 @@ public class UpdatePrompt {
WorkerExecutor workerExecutor,
MainWindow mainWindow,
boolean silent) {
// @formatter:off
if (mainWindow != null) {
if (silent) {
return new UpdatePrompt(currentVersion, workerExecutor,
NOOP_CONSUMER, NOOP,
message -> mainWindow.askToConfirm(TITLE, message));
return new UpdatePrompt(
currentVersion,
workerExecutor,
NOOP_CONSUMER,
NOOP,
message -> mainWindow.askToConfirm(TITLE, message));
} else {
return new UpdatePrompt(currentVersion, workerExecutor,
return new UpdatePrompt(
currentVersion,
workerExecutor,
exception -> mainWindow.displayException(exception),
() -> mainWindow.displayMessage(TITLE, NO_UPDATES_AVAILABLE),
message -> mainWindow.askToConfirm(TITLE, message));
() -> mainWindow.displayMessage(TITLE, NO_UPDATES_AVAILABLE),
message -> mainWindow.askToConfirm(TITLE, message));
}
} else {
if (silent) {
return new UpdatePrompt(currentVersion, workerExecutor,
NOOP_CONSUMER, NOOP,
message -> askToConfirmDirectly(message));
return new UpdatePrompt(
currentVersion,
workerExecutor,
NOOP_CONSUMER,
NOOP,
message -> askToConfirmDirectly(message));
} else {
return new UpdatePrompt(currentVersion, workerExecutor,
return new UpdatePrompt(
currentVersion,
workerExecutor,
exception -> displayExceptionDirectly(exception),
() -> displayMessageDirectly(NO_UPDATES_AVAILABLE),
message -> askToConfirmDirectly(message));
() -> displayMessageDirectly(NO_UPDATES_AVAILABLE),
message -> askToConfirmDirectly(message));
}
}
// @formatter:on
}
@CalledOnlyBy(AmidstThread.EDT)

View File

@ -20,8 +20,8 @@ import amidst.settings.biomeprofile.BiomeProfileVisitor;
public class BiomeProfileMenuFactory {
@NotThreadSafe
private static class BiomeProfileVisitorImpl implements BiomeProfileVisitor {
private final List<JCheckBoxMenuItem> allCheckBoxes = new ArrayList<JCheckBoxMenuItem>();
private final List<JMenu> menuStack = new ArrayList<JMenu>();
private final List<JCheckBoxMenuItem> allCheckBoxes = new ArrayList<>();
private final List<JMenu> menuStack = new ArrayList<>();
private ActionListener firstListener;
private boolean isFirstContainer = true;

View File

@ -26,8 +26,8 @@ public class LayersMenu {
private final AmidstSettings settings;
private final Setting<Dimension> dimensionSetting;
private final Setting<Boolean> enableAllLayersSetting;
private final List<JMenuItem> overworldMenuItems = new LinkedList<JMenuItem>();
private final List<JMenuItem> endMenuItems = new LinkedList<JMenuItem>();
private final List<JMenuItem> overworldMenuItems = new LinkedList<>();
private final List<JMenuItem> endMenuItems = new LinkedList<>();
private volatile ViewerFacade viewerFacade;
private volatile boolean showEnableAllLayers;

View File

@ -134,14 +134,7 @@ public enum Menus {
}
public static KeyStroke getAcceleratorKeyStroke(String accelerator) {
boolean addMenuMask;
if (accelerator.contains("menu")) {
accelerator = accelerator.replace("menu", "");
addMenuMask = true;
} else {
addMenuMask = false;
}
return getPlatformSpecificKeyStroke(accelerator, addMenuMask);
return getPlatformSpecificKeyStroke(accelerator.replace("menu", ""), accelerator.contains("menu"));
}
private static KeyStroke getPlatformSpecificKeyStroke(String accelerator, boolean addMenuMask) {

View File

@ -84,11 +84,9 @@ public class Drawer {
this.drawers = drawers;
this.dimensionSetting = dimensionSetting;
this.accelerationCounter = accelerationCounter;
this.voidTexturePaint = new TexturePaint(VOID_TEXTURE, new Rectangle(
0,
0,
VOID_TEXTURE.getWidth(),
VOID_TEXTURE.getHeight()));
this.voidTexturePaint = new TexturePaint(
VOID_TEXTURE,
new Rectangle(0, 0, VOID_TEXTURE.getWidth(), VOID_TEXTURE.getHeight()));
}
@CalledOnlyBy(AmidstThread.EDT)

View File

@ -44,18 +44,12 @@ public class ViewerFacadeBuilder {
Graphics2DAccelerationCounter accelerationCounter = new Graphics2DAccelerationCounter();
Movement movement = new Movement(settings.smoothScrolling);
WorldIconSelection worldIconSelection = new WorldIconSelection();
LayerManager layerManager = layerBuilder.create(
settings,
world,
biomeSelection,
worldIconSelection,
zoom,
accelerationCounter);
LayerManager layerManager = layerBuilder
.create(settings, world, biomeSelection, worldIconSelection, zoom, accelerationCounter);
FragmentGraph graph = new FragmentGraph(layerManager.getDeclarations(), fragmentManager);
FragmentGraphToScreenTranslator translator = new FragmentGraphToScreenTranslator(graph, zoom);
FragmentQueueProcessor fragmentQueueProcessor = fragmentManager.createQueueProcessor(
layerManager,
settings.dimension);
FragmentQueueProcessor fragmentQueueProcessor = fragmentManager
.createQueueProcessor(layerManager, settings.dimension);
LayerReloader layerReloader = layerManager.createLayerReloader(world);
WorldExporterFactory worldExporterFactory = new WorldExporterFactory(workerExecutor, world);
WidgetBuilder widgetBuilder = new WidgetBuilder(
@ -80,13 +74,9 @@ public class ViewerFacadeBuilder {
layerManager.getDrawers(),
settings.dimension,
accelerationCounter);
Viewer viewer = new Viewer(new ViewerMouseListener(
new WidgetManager(widgets),
graph,
translator,
zoom,
movement,
actions), drawer);
Viewer viewer = new Viewer(
new ViewerMouseListener(new WidgetManager(widgets), graph, translator, zoom, movement, actions),
drawer);
return new ViewerFacade(
world,
graph,

View File

@ -113,9 +113,8 @@ public class ViewerMouseListener implements MouseListener, MouseWheelListener {
@CalledOnlyBy(AmidstThread.EDT)
private void doMouseClicked(Point mousePosition) {
actions.selectWorldIcon(graph.getClosestWorldIcon(
translator.screenToWorld(mousePosition),
zoom.screenToWorld(50)));
actions.selectWorldIcon(
graph.getClosestWorldIcon(translator.screenToWorld(mousePosition), zoom.screenToWorld(50)));
}
@CalledOnlyBy(AmidstThread.EDT)

View File

@ -35,7 +35,7 @@ public class BiomeWidget extends Widget {
private final LayerReloader layerReloader;
private final BiomeProfileSelection biomeProfileSelection;
private List<Biome> biomes = new ArrayList<Biome>();
private List<Biome> biomes = new ArrayList<>();
private int maxNameWidth = 0;
private int biomeListHeight;
private boolean isInitialized = false;
@ -137,7 +137,8 @@ public class BiomeWidget extends Widget {
float listHeight = biomeListHeight;
if (scrollbarGrabbed) {
if (mousePosition != null) {
biomeListYOffset = (int) ((listHeight / boxHeight) * (-scrollbarYOnGrab - (mousePosition.y - mouseYOnGrab)));
biomeListYOffset = (int) ((listHeight / boxHeight)
* (-scrollbarYOnGrab - (mousePosition.y - mouseYOnGrab)));
updateBiomeListYOffset();
} else {
scrollbarGrabbed = false;
@ -264,9 +265,8 @@ public class BiomeWidget extends Widget {
return false;
}
if (isInBoundsOfInnerBox(mouseX, mouseY)) {
biomeListYOffset = Math.min(
0,
Math.max(-biomeListHeight + innerBox.height, biomeListYOffset - notches * 35));
biomeListYOffset = Math
.min(0, Math.max(-biomeListHeight + innerBox.height, biomeListYOffset - notches * 35));
}
return true;
}

View File

@ -38,7 +38,6 @@ public class DebugWidget extends TextWidget {
if (isVisibleSetting.get()) {
int columns = graph.getFragmentsPerRow();
int rows = graph.getFragmentsPerColumn();
// @formatter:off
return Arrays.asList(
"Fragment Manager:",
"Cache Size: " + fragmentManager.getCacheSize(),
@ -48,9 +47,7 @@ public class DebugWidget extends TextWidget {
"",
"Viewer:",
"Size: " + columns + "x" + rows + " [" + (columns * rows) + "]",
String.format("Acceleration: %1$.1f%%", accelerationCounter.getAcceleratedPercentage())
);
// @formatter:on
String.format("Acceleration: %1$.1f%%", accelerationCounter.getAcceleratedPercentage()));
} else {
return null;
}

View File

@ -21,8 +21,7 @@ public class WidgetManager {
@CalledOnlyBy(AmidstThread.EDT)
public boolean mouseWheelMoved(Point mousePosition, int notches) {
for (Widget widget : widgets) {
if (widget.isVisible()
&& widget.isInBounds(mousePosition)
if (widget.isVisible() && widget.isInBounds(mousePosition)
&& widget.onMouseWheelMoved(
widget.translateXToWidgetCoordinates(mousePosition),
widget.translateYToWidgetCoordinates(mousePosition),
@ -36,8 +35,7 @@ public class WidgetManager {
@CalledOnlyBy(AmidstThread.EDT)
public boolean mouseClicked(Point mousePosition) {
for (Widget widget : widgets) {
if (widget.isVisible()
&& widget.isInBounds(mousePosition)
if (widget.isVisible() && widget.isInBounds(mousePosition)
&& widget.onClick(
widget.translateXToWidgetCoordinates(mousePosition),
widget.translateYToWidgetCoordinates(mousePosition))) {
@ -50,8 +48,7 @@ public class WidgetManager {
@CalledOnlyBy(AmidstThread.EDT)
public boolean mousePressed(Point mousePosition) {
for (Widget widget : widgets) {
if (widget.isVisible()
&& widget.isInBounds(mousePosition)
if (widget.isVisible() && widget.isInBounds(mousePosition)
&& widget.onMousePressed(
widget.translateXToWidgetCoordinates(mousePosition),
widget.translateYToWidgetCoordinates(mousePosition))) {

View File

@ -82,11 +82,16 @@ public class LocalProfileComponent extends ProfileComponent {
private boolean tryLoad() {
// TODO: Replace with proper handling for modded profiles.
try {
Log.i("using minecraft launcher profile '" + getProfileName() + "' with versionId '" + getVersionName() + "'");
Log
.i(
"using minecraft launcher profile '" + getProfileName() + "' with versionId '"
+ getVersionName() + "'");
String possibleModProfiles = ".*(optifine|forge).*";
if (Pattern.matches(possibleModProfiles, getVersionName().toLowerCase(Locale.ENGLISH))) {
Log.e("Amidst does not support modded Minecraft profiles! Please select or create an unmodded Minecraft profile via the Minecraft Launcher.");
Log
.e(
"Amidst does not support modded Minecraft profiles! Please select or create an unmodded Minecraft profile via the Minecraft Launcher.");
return false;
}

View File

@ -17,11 +17,11 @@ import java.util.List;
import javax.swing.JPanel;
import net.miginfocom.swing.MigLayout;
import amidst.documentation.AmidstThread;
import amidst.documentation.CalledOnlyBy;
import amidst.documentation.NotThreadSafe;
import amidst.settings.Setting;
import net.miginfocom.swing.MigLayout;
@NotThreadSafe
public class ProfileSelectPanel {
@ -94,7 +94,7 @@ public class ProfileSelectPanel {
private final Setting<String> lastProfileSetting;
private final Component component;
private final List<ProfileComponent> profileComponents = new ArrayList<ProfileComponent>();
private final List<ProfileComponent> profileComponents = new ArrayList<>();
private ProfileComponent selected = null;
private int selectedIndex = INVALID_INDEX;

View File

@ -11,7 +11,6 @@ import javax.swing.JScrollPane;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
import net.miginfocom.swing.MigLayout;
import amidst.AmidstMetaData;
import amidst.AmidstSettings;
import amidst.Application;
@ -24,6 +23,7 @@ import amidst.mojangapi.file.MojangApiParsingException;
import amidst.mojangapi.file.json.launcherprofiles.LauncherProfileJson;
import amidst.mojangapi.file.json.launcherprofiles.LauncherProfilesJson;
import amidst.threading.WorkerExecutor;
import net.miginfocom.swing.MigLayout;
@NotThreadSafe
public class ProfileSelectWindow {

View File

@ -77,7 +77,8 @@ public class SeedSearcher {
@CalledOnlyBy(AmidstThread.WORKER)
private void doSearch(ProgressReporter<WorldSeed> reporter, SeedSearcherConfiguration configuration)
throws IllegalStateException, MinecraftInterfaceException {
throws IllegalStateException,
MinecraftInterfaceException {
do {
doSearchOne(reporter, configuration);
} while (configuration.isSearchContinuously() && !isStopRequested);

View File

@ -13,7 +13,6 @@ import javax.swing.JTextArea;
import javax.swing.ScrollPaneConstants;
import javax.swing.border.LineBorder;
import net.miginfocom.swing.MigLayout;
import amidst.AmidstMetaData;
import amidst.documentation.AmidstThread;
import amidst.documentation.CalledOnlyBy;
@ -23,6 +22,7 @@ import amidst.mojangapi.file.json.filter.WorldFilterJson_MatchAll;
import amidst.mojangapi.world.WorldSeed;
import amidst.mojangapi.world.WorldType;
import amidst.mojangapi.world.filter.WorldFilter;
import net.miginfocom.swing.MigLayout;
@NotThreadSafe
public class SeedSearcherWindow {
@ -61,7 +61,7 @@ public class SeedSearcherWindow {
@CalledOnlyBy(AmidstThread.EDT)
private JComboBox<WorldType> createWorldTypeComboBox() {
return new JComboBox<WorldType>(WorldType.getSelectableArray());
return new JComboBox<>(WorldType.getSelectableArray());
}
@CalledOnlyBy(AmidstThread.EDT)

View File

@ -17,7 +17,7 @@ import amidst.documentation.NotThreadSafe;
@NotThreadSafe
public class FileLogger implements Logger {
private final ConcurrentLinkedQueue<String> logMessageQueue = new ConcurrentLinkedQueue<String>();
private final ConcurrentLinkedQueue<String> logMessageQueue = new ConcurrentLinkedQueue<>();
private final File file;
private final ScheduledExecutorService executor;

View File

@ -19,7 +19,7 @@ public class Log {
private static final boolean IS_USING_ALERTS = true;
private static final boolean IS_SHOWING_DEBUG = true;
private static final Map<String, Logger> LOGGER = new HashMap<String, Logger>();
private static final Map<String, Logger> LOGGER = new HashMap<>();
static {
addListener("console", CONSOLE_LOGGER);

View File

@ -123,7 +123,8 @@ public class MojangApi {
* one world at a time. Creating a new world will break all previously
* created world objects.
*/
public World createWorldFromSeed(WorldSeed worldSeed, WorldType worldType) throws IllegalStateException,
public World createWorldFromSeed(WorldSeed worldSeed, WorldType worldType)
throws IllegalStateException,
MinecraftInterfaceException {
MinecraftInterface minecraftInterface = this.minecraftInterface;
if (minecraftInterface != null) {
@ -138,8 +139,12 @@ public class MojangApi {
* one world at a time. Creating a new world will break all previously
* created world objects.
*/
public World createWorldFromSaveGame(File file) throws FileNotFoundException, IOException, IllegalStateException,
MinecraftInterfaceException, MojangApiParsingException {
public World createWorldFromSaveGame(File file)
throws FileNotFoundException,
IOException,
IllegalStateException,
MinecraftInterfaceException,
MojangApiParsingException {
MinecraftInterface minecraftInterface = this.minecraftInterface;
if (minecraftInterface != null) {
return worldBuilder.fromSaveGame(minecraftInterface, SaveDirectory.from(file));

View File

@ -24,15 +24,19 @@ public class MojangApiBuilder {
}
@NotNull
public MojangApi construct() throws DotMinecraftDirectoryNotFoundException,
public MojangApi construct()
throws DotMinecraftDirectoryNotFoundException,
LocalMinecraftInterfaceCreationException {
DotMinecraftDirectory dotMinecraftDirectory = createDotMinecraftDirectory();
if (dotMinecraftDirectory.isValid()) {
Log.i("using '.minecraft' directory at: '" + dotMinecraftDirectory.getRoot() + "', libraries: '"
+ dotMinecraftDirectory.getLibraries() + "'");
Log
.i(
"using '.minecraft' directory at: '" + dotMinecraftDirectory.getRoot() + "', libraries: '"
+ dotMinecraftDirectory.getLibraries() + "'");
} else {
throw new DotMinecraftDirectoryNotFoundException("invalid '.minecraft' directory at: '"
+ dotMinecraftDirectory.getRoot() + "', libraries: '" + dotMinecraftDirectory.getLibraries() + "'");
throw new DotMinecraftDirectoryNotFoundException(
"invalid '.minecraft' directory at: '" + dotMinecraftDirectory.getRoot() + "', libraries: '"
+ dotMinecraftDirectory.getLibraries() + "'");
}
MojangApi result = new MojangApi(worldBuilder, dotMinecraftDirectory);
result.set(null, null, createVersionDirectory(result));
@ -55,12 +59,18 @@ public class MojangApiBuilder {
File json = new File(parameters.minecraftJsonFile);
VersionDirectory result = mojangApi.createVersionDirectory(jar, json);
if (result.isValid()) {
Log.i("using minecraft version directory. versionId: '" + result.getVersionId() + "', jar file: '"
+ result.getJar() + "', json file: '" + result.getJson() + "'");
Log
.i(
"using minecraft version directory. versionId: '" + result.getVersionId()
+ "', jar file: '" + result.getJar() + "', json file: '" + result.getJson()
+ "'");
return result;
} else {
Log.w("invalid minecraft version directory. versionId: '" + result.getVersionId() + "', jar file: '"
+ result.getJar() + "', json file: '" + result.getJson() + "'");
Log
.w(
"invalid minecraft version directory. versionId: '" + result.getVersionId()
+ "', jar file: '" + result.getJar() + "', json file: '" + result.getJson()
+ "'");
}
}
return null;

View File

@ -18,8 +18,10 @@ public enum DotMinecraftDirectoryFinder {
if (result.isDirectory()) {
return result;
} else {
Log.w("Unable to set Minecraft directory to: " + result
+ " as that location does not exist or is not a folder.");
Log
.w(
"Unable to set Minecraft directory to: " + result
+ " as that location does not exist or is not a folder.");
}
}
return getMinecraftDirectory();

View File

@ -18,7 +18,7 @@ public enum LibraryFinder {
@NotNull
public static List<URL> getLibraryUrls(File librariesDirectory, List<LibraryJson> libraries) {
List<URL> result = new ArrayList<URL>();
List<URL> result = new ArrayList<>();
for (LibraryJson library : libraries) {
File libraryFile = getLibraryFile(librariesDirectory, library);
if (libraryFile != null) {

View File

@ -156,7 +156,7 @@ public class SaveDirectory {
*/
@NotNull
public List<PlayerNbt> createMultiplayerPlayerNbts() {
List<PlayerNbt> result = new ArrayList<PlayerNbt>();
List<PlayerNbt> result = new ArrayList<>();
for (File playerdataFile : getPlayerdataFiles()) {
if (playerdataFile.isFile()) {
result.add(createPlayerdataPlayerNbt(getPlayerUUIDFromPlayerdataFile(playerdataFile)));

View File

@ -79,7 +79,7 @@ public class VersionDirectory {
return readVersionJson().getLibraryUrls(dotMinecraftDirectory.getLibraries());
} catch (IOException | MojangApiParsingException e) {
Log.w("Invalid jar profile loaded. Library loading will be skipped. (Path: " + json + ")");
return new ArrayList<URL>();
return new ArrayList<>();
}
}

View File

@ -6,6 +6,10 @@ import java.io.IOException;
import java.io.Reader;
import java.net.URL;
import com.google.gson.Gson;
import com.google.gson.JsonIOException;
import com.google.gson.JsonSyntaxException;
import amidst.ResourceLoader;
import amidst.documentation.Immutable;
import amidst.documentation.NotNull;
@ -18,10 +22,6 @@ import amidst.mojangapi.file.json.player.SimplePlayerJson;
import amidst.mojangapi.file.json.version.VersionJson;
import amidst.mojangapi.file.json.versionlist.VersionListJson;
import com.google.gson.Gson;
import com.google.gson.JsonIOException;
import com.google.gson.JsonSyntaxException;
/**
* This is a utility class used to read JSON data. Please use this class only to
* read JSON data provided by Mojang, because it throws a
@ -89,7 +89,8 @@ public enum JsonReader {
}
@NotNull
public static LauncherProfilesJson readLauncherProfilesFrom(File file) throws MojangApiParsingException,
public static LauncherProfilesJson readLauncherProfilesFrom(File file)
throws MojangApiParsingException,
IOException {
return read(URIUtils.newReader(file), LauncherProfilesJson.class);
}
@ -116,7 +117,8 @@ public enum JsonReader {
}
@NotNull
public static SimplePlayerJson readSimplePlayerFromPlayerName(String playerName) throws IOException,
public static SimplePlayerJson readSimplePlayerFromPlayerName(String playerName)
throws IOException,
MojangApiParsingException {
return read(URIUtils.newReader(PLAYERNAME_TO_UUID + playerName), SimplePlayerJson.class);
}

View File

@ -1,12 +1,11 @@
package amidst.mojangapi.file.json;
import amidst.documentation.Immutable;
import com.google.gson.annotations.SerializedName;
import amidst.documentation.Immutable;
@Immutable
public enum ReleaseType {
// @formatter:off
@SerializedName("snapshot")
SNAPSHOT("snapshot", "S"),
@SerializedName("release")
@ -15,7 +14,6 @@ public enum ReleaseType {
OLD_BETA("old_beta", "B"),
@SerializedName("old_alpha")
OLD_ALPHA("old_alpha", "A");
// @formatter:on
private final String name;
private final String typeChar;

View File

@ -6,15 +6,15 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import amidst.documentation.GsonConstructor;
import amidst.documentation.Immutable;
import amidst.logging.Log;
import amidst.mojangapi.world.filter.WorldFilter;
import amidst.mojangapi.world.filter.WorldFilter_MatchAll;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
@Immutable
public class WorldFilterJson_MatchAll {
public static Optional<WorldFilterJson_MatchAll> from(String queryString) {
@ -62,7 +62,7 @@ public class WorldFilterJson_MatchAll {
}
private List<WorldFilter> createFilterList() {
List<WorldFilter> filters = new ArrayList<WorldFilter>();
List<WorldFilter> filters = new ArrayList<>();
for (WorldFilterJson_Biome biomeFilterJson : biomeFilters) {
filters.add(biomeFilterJson.createBiomeFilter());
}

View File

@ -55,8 +55,8 @@ public class LauncherProfileJson {
if (result.isValid()) {
return result;
} else {
throw new FileNotFoundException("cannot find valid profile directory for launcher profile '" + name
+ "': " + gameDir);
throw new FileNotFoundException(
"cannot find valid profile directory for launcher profile '" + name + "': " + gameDir);
}
} else {
return new ProfileDirectory(mojangApi.getDotMinecraftDirectory().getRoot());

View File

@ -21,7 +21,9 @@ public class VersionListJson {
return versions;
}
public VersionDirectory tryFindFirstValidVersionDirectory(List<ReleaseType> allowedReleaseTypes, MojangApi mojangApi) {
public VersionDirectory tryFindFirstValidVersionDirectory(
List<ReleaseType> allowedReleaseTypes,
MojangApi mojangApi) {
for (VersionListEntryJson version : versions) {
if (allowedReleaseTypes.contains(version.getType())) {
VersionDirectory versionDirectory = version.createVersionDirectory(mojangApi);

View File

@ -43,8 +43,8 @@ public enum NBTUtils {
if (value instanceof Number) {
return ((Number) value).longValue();
} else {
throw new IllegalArgumentException("cannot read long value from the class '" + tag.getClass().getName()
+ "'");
throw new IllegalArgumentException(
"cannot read long value from the class '" + tag.getClass().getName() + "'");
}
}
}

View File

@ -44,13 +44,11 @@ public enum PlayerLocationLoader {
private static PlayerCoordinates readPlayerCoordinates(CompoundTag tag) {
int dimensionId = getTagDimension(tag).getValue();
List<Tag> posList = getTagPos(tag).getValue();
// @formatter:off
return PlayerCoordinates.fromNBTFile(
(long) (double) (Double) posList.get(0).getValue(),
(long) (double) (Double) posList.get(1).getValue(),
(long) (double) (Double) posList.get(2).getValue(),
dimensionId);
// @formatter:on
}
private static IntTag getTagDimension(CompoundTag tag) {

View File

@ -51,7 +51,7 @@ public enum PlayerLocationSaver {
private static Map<String, Tag> modifyPositionInBaseMapSinglePlayer(
Map<String, Tag> baseMap,
PlayerCoordinates coordinates) {
Map<String, Tag> result = new HashMap<String, Tag>();
Map<String, Tag> result = new HashMap<>();
CompoundTag dataTag = (CompoundTag) baseMap.get(NBTTagKeys.TAG_KEY_DATA);
CompoundTag modifiedDataTag = modifyPositionInDataTagSinglePlayer(dataTag, coordinates);
result.put(NBTTagKeys.TAG_KEY_DATA, modifiedDataTag);
@ -67,7 +67,7 @@ public enum PlayerLocationSaver {
private static Map<String, Tag> modifyPositionInDataMapSinglePlayer(
Map<String, Tag> dataMap,
PlayerCoordinates coordinates) {
Map<String, Tag> result = new HashMap<String, Tag>(dataMap);
Map<String, Tag> result = new HashMap<>(dataMap);
CompoundTag playerTag = (CompoundTag) dataMap.get(NBTTagKeys.TAG_KEY_PLAYER);
CompoundTag modifiedPlayerTag = modifyPositionInPlayerTagSinglePlayer(playerTag, coordinates);
result.put(NBTTagKeys.TAG_KEY_PLAYER, modifiedPlayerTag);
@ -88,8 +88,10 @@ public enum PlayerLocationSaver {
return new CompoundTag(NBTTagKeys.TAG_KEY_DATA, modifiedPlayerMap);
}
private static Map<String, Tag> modifyPositionInPlayerMap(Map<String, Tag> playerMap, PlayerCoordinates coordinates) {
Map<String, Tag> result = new HashMap<String, Tag>(playerMap);
private static Map<String, Tag> modifyPositionInPlayerMap(
Map<String, Tag> playerMap,
PlayerCoordinates coordinates) {
Map<String, Tag> result = new HashMap<>(playerMap);
ListTag posTag = (ListTag) playerMap.get(NBTTagKeys.TAG_KEY_POS);
ListTag modifiedPosTag = modifyPositionInPosTag(posTag, coordinates);
result.put(NBTTagKeys.TAG_KEY_POS, modifiedPosTag);
@ -103,7 +105,7 @@ public enum PlayerLocationSaver {
}
private static List<Tag> modifyPositionInPosList(List<Tag> posList, PlayerCoordinates coordinates) {
List<Tag> result = new ArrayList<Tag>(posList);
List<Tag> result = new ArrayList<>(posList);
result.set(0, new DoubleTag("x", coordinates.getXForNBTFile()));
result.set(1, new DoubleTag("y", coordinates.getYForNBTFile()));
result.set(2, new DoubleTag("z", coordinates.getZForNBTFile()));

View File

@ -32,8 +32,8 @@ public class PlayerdataPlayerNbt extends PlayerNbt {
@Override
public PlayerCoordinates readCoordinates() throws IOException, MojangApiParsingException {
return PlayerLocationLoader.readFromPlayerFile(NBTUtils.readTagFromFile(saveDirectory
.getPlayerdataFile(playerUUID)));
return PlayerLocationLoader
.readFromPlayerFile(NBTUtils.readTagFromFile(saveDirectory.getPlayerdataFile(playerUUID)));
}
@Override

View File

@ -32,8 +32,8 @@ public class PlayersPlayerNbt extends PlayerNbt {
@Override
public PlayerCoordinates readCoordinates() throws IOException, MojangApiParsingException {
return PlayerLocationLoader.readFromPlayerFile(NBTUtils.readTagFromFile(saveDirectory
.getPlayersFile(playerName)));
return PlayerLocationLoader
.readFromPlayerFile(NBTUtils.readTagFromFile(saveDirectory.getPlayersFile(playerName)));
}
@Override

View File

@ -15,12 +15,11 @@ import amidst.mojangapi.world.WorldType;
@ThreadSafe
public interface MinecraftInterface {
/**
* @param useQuarterResolution
* Minecraft calculates biomes at quarter-resolution, then
* noisily interpolates the biome-map up to 1:1 resolution when
* needed, set useQuarterResolutionMap to true to read from the
* quarter-resolution map, or false to read values that have been
* interpolated up to full resolution.
* @param useQuarterResolution Minecraft calculates biomes at
* quarter-resolution, then noisily interpolates the biome-map up
* to 1:1 resolution when needed, set useQuarterResolutionMap to
* true to read from the quarter-resolution map, or false to read
* values that have been interpolated up to full resolution.
*
* When useQuarterResolution is true, the x, y, width, and height
* paramaters must all correspond to a quarter of the Minecraft

View File

@ -187,8 +187,10 @@ public enum RecognisedVersion {
}
private static void logFound(RecognisedVersion recognisedVersion) {
Log.i("Recognised Minecraft Version " + recognisedVersion.name + " with the magic string \""
+ recognisedVersion.magicString + "\".");
Log
.i(
"Recognised Minecraft Version " + recognisedVersion.name + " with the magic string \""
+ recognisedVersion.magicString + "\".");
}
public static boolean isNewerOrEqualTo(RecognisedVersion version1, RecognisedVersion version2) {
@ -218,12 +220,13 @@ public enum RecognisedVersion {
}
public static Map<String, RecognisedVersion> generateNameToRecognisedVersionMap() {
Map<String, RecognisedVersion> result = new LinkedHashMap<String, RecognisedVersion>();
Map<String, RecognisedVersion> result = new LinkedHashMap<>();
for (RecognisedVersion recognisedVersion : RecognisedVersion.values()) {
if (result.containsKey(recognisedVersion.getName())) {
RecognisedVersion colliding = result.get(recognisedVersion.getName());
throw new RuntimeException("name collision for the recognised versions " + recognisedVersion.getName()
+ " and " + colliding.getName());
throw new RuntimeException(
"name collision for the recognised versions " + recognisedVersion.getName() + " and "
+ colliding.getName());
} else {
result.put(recognisedVersion.getName(), recognisedVersion);
}
@ -232,12 +235,13 @@ public enum RecognisedVersion {
}
public static Map<String, RecognisedVersion> generateMagicStringToRecognisedVersionMap() {
Map<String, RecognisedVersion> result = new LinkedHashMap<String, RecognisedVersion>();
Map<String, RecognisedVersion> result = new LinkedHashMap<>();
for (RecognisedVersion recognisedVersion : RecognisedVersion.values()) {
if (result.containsKey(recognisedVersion.getMagicString())) {
RecognisedVersion colliding = result.get(recognisedVersion.getMagicString());
throw new RuntimeException("magic string collision for the recognised versions "
+ recognisedVersion.getName() + " and " + colliding.getName());
throw new RuntimeException(
"magic string collision for the recognised versions " + recognisedVersion.getName() + " and "
+ colliding.getName());
} else {
result.put(recognisedVersion.getMagicString(), recognisedVersion);
}

View File

@ -79,7 +79,6 @@ public enum DefaultClassTranslator {
.requiredMethod(SymbolicNames.METHOD_GEN_OPTIONS_FACTORY_JSON_TO_FACTORY, "a").real("String").end()
.construct();
}
// @formatter:on
private int[] createIntCacheWildcardBytes() {
return new int[] { 0x11, 0x01, 0x00, 0xB3, 0x00, WILDCARD, 0xBB, 0x00, WILDCARD, 0x59, 0xB7, 0x00, WILDCARD,
@ -87,4 +86,5 @@ public enum DefaultClassTranslator {
0x00, WILDCARD, 0x59, 0xB7, 0x00, WILDCARD, 0xB3, 0x00, WILDCARD, 0xBB, 0x00, WILDCARD, 0x59, 0xB7,
0x00, WILDCARD, 0xB3, 0x00, WILDCARD, 0xB1 };
}
// @formatter:on
}

View File

@ -51,13 +51,13 @@ public class LocalMinecraftInterface implements MinecraftInterface {
this.recognisedVersion = recognisedVersion;
}
// @formatter:off
@Override
public synchronized int[] getBiomeData(int x, int y, int width, int height, boolean useQuarterResolution)
throws MinecraftInterfaceException {
try {
intCacheClass.callStaticMethod(SymbolicNames.METHOD_INT_CACHE_RESET_INT_CACHE);
return (int[]) getBiomeGenerator(useQuarterResolution).callMethod(SymbolicNames.METHOD_GEN_LAYER_GET_INTS, x, y, width, height);
return (int[]) getBiomeGenerator(useQuarterResolution)
.callMethod(SymbolicNames.METHOD_GEN_LAYER_GET_INTS, x, y, width, height);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
throw new MinecraftInterfaceException("unable to get biome data", e);
}
@ -90,37 +90,51 @@ public class LocalMinecraftInterface implements MinecraftInterface {
* Minecraft 1.8 and higher require block initialization to be called before
* creating a biome generator.
*/
private void initializeBlock()
throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
private void initializeBlock() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
if (blockInitClass != null) {
blockInitClass.callStaticMethod(SymbolicNames.METHOD_BLOCK_INIT_INITIALIZE);
}
}
private Object[] getGenLayers(long seed, WorldType worldType, String generatorOptions)
throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
throws IllegalAccessException,
IllegalArgumentException,
InvocationTargetException {
if (worldTypeClass == null) {
return (Object[]) genLayerClass.callStaticMethod(SymbolicNames.METHOD_GEN_LAYER_INITIALIZE_ALL_BIOME_GENERATORS_1, seed);
return (Object[]) genLayerClass
.callStaticMethod(SymbolicNames.METHOD_GEN_LAYER_INITIALIZE_ALL_BIOME_GENERATORS_1, seed);
} else if (genLayerClass.hasMethod(SymbolicNames.METHOD_GEN_LAYER_INITIALIZE_ALL_BIOME_GENERATORS_4)) {
return (Object[]) genLayerClass.callStaticMethod(SymbolicNames.METHOD_GEN_LAYER_INITIALIZE_ALL_BIOME_GENERATORS_4, seed, getWorldType(worldType).getObject(), getGeneratorOptions(generatorOptions).getObject());
return (Object[]) genLayerClass.callStaticMethod(
SymbolicNames.METHOD_GEN_LAYER_INITIALIZE_ALL_BIOME_GENERATORS_4,
seed,
getWorldType(worldType).getObject(),
getGeneratorOptions(generatorOptions).getObject());
} else if (genLayerClass.hasMethod(SymbolicNames.METHOD_GEN_LAYER_INITIALIZE_ALL_BIOME_GENERATORS_3)) {
return (Object[]) genLayerClass.callStaticMethod(SymbolicNames.METHOD_GEN_LAYER_INITIALIZE_ALL_BIOME_GENERATORS_3, seed, getWorldType(worldType).getObject(), generatorOptions);
return (Object[]) genLayerClass.callStaticMethod(
SymbolicNames.METHOD_GEN_LAYER_INITIALIZE_ALL_BIOME_GENERATORS_3,
seed,
getWorldType(worldType).getObject(),
generatorOptions);
} else {
return (Object[]) genLayerClass.callStaticMethod(SymbolicNames.METHOD_GEN_LAYER_INITIALIZE_ALL_BIOME_GENERATORS_2, seed, getWorldType(worldType).getObject());
return (Object[]) genLayerClass.callStaticMethod(
SymbolicNames.METHOD_GEN_LAYER_INITIALIZE_ALL_BIOME_GENERATORS_2,
seed,
getWorldType(worldType).getObject());
}
}
private SymbolicObject getGeneratorOptions(String generatorOptions)
throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
SymbolicObject factory = (SymbolicObject) genOptionsFactoryClass.callStaticMethod(SymbolicNames.METHOD_GEN_OPTIONS_FACTORY_JSON_TO_FACTORY, generatorOptions);
throws IllegalAccessException,
IllegalArgumentException,
InvocationTargetException {
SymbolicObject factory = (SymbolicObject) genOptionsFactoryClass
.callStaticMethod(SymbolicNames.METHOD_GEN_OPTIONS_FACTORY_JSON_TO_FACTORY, generatorOptions);
return (SymbolicObject) factory.callMethod(SymbolicNames.METHOD_GEN_OPTIONS_FACTORY_BUILD);
}
private SymbolicObject getWorldType(WorldType worldType)
throws IllegalArgumentException, IllegalAccessException {
private SymbolicObject getWorldType(WorldType worldType) throws IllegalArgumentException, IllegalAccessException {
return (SymbolicObject) worldTypeClass.getStaticFieldValue(worldType.getSymbolicFieldName());
}
// @formatter:on
@Override
public RecognisedVersion getRecognisedVersion() {

View File

@ -26,14 +26,13 @@ public class LocalMinecraftInterfaceBuilder {
}
@NotNull
public MinecraftInterface create(VersionDirectory versionDirectory) throws LocalMinecraftInterfaceCreationException {
public MinecraftInterface create(VersionDirectory versionDirectory)
throws LocalMinecraftInterfaceCreationException {
try {
URLClassLoader classLoader = versionDirectory.createClassLoader();
RecognisedVersion recognisedVersion = RecognisedVersion.from(classLoader);
Map<String, SymbolicClass> symbolicClassMap = Classes.createSymbolicClassMap(
versionDirectory.getJar(),
classLoader,
translator);
Map<String, SymbolicClass> symbolicClassMap = Classes
.createSymbolicClassMap(versionDirectory.getJar(), classLoader, translator);
Log.i("Minecraft load complete.");
return new LocalMinecraftInterface(
symbolicClassMap.get(SymbolicNames.CLASS_INT_CACHE),
@ -42,7 +41,11 @@ public class LocalMinecraftInterfaceBuilder {
symbolicClassMap.get(SymbolicNames.CLASS_WORLD_TYPE),
symbolicClassMap.get(SymbolicNames.CLASS_GEN_OPTIONS_FACTORY),
recognisedVersion);
} catch (MalformedURLException | ClassNotFoundException | FileNotFoundException | JarFileParsingException
} catch (
MalformedURLException
| ClassNotFoundException
| FileNotFoundException
| JarFileParsingException
| SymbolicClassGraphCreationException e) {
throw new LocalMinecraftInterfaceCreationException("unable to create local minecraft interface", e);
}

View File

@ -1,7 +1,6 @@
package amidst.mojangapi.world;
import java.io.IOException;
import java.util.List;
import amidst.documentation.Immutable;
import amidst.mojangapi.file.MojangApiParsingException;
@ -23,7 +22,6 @@ import amidst.mojangapi.world.icon.type.EndCityWorldIconTypeProvider;
import amidst.mojangapi.world.icon.type.ImmutableWorldIconTypeProvider;
import amidst.mojangapi.world.icon.type.TempleWorldIconTypeProvider;
import amidst.mojangapi.world.oracle.BiomeDataOracle;
import amidst.mojangapi.world.oracle.EndIsland;
import amidst.mojangapi.world.oracle.EndIslandOracle;
import amidst.mojangapi.world.oracle.HeuristicWorldSpawnOracle;
import amidst.mojangapi.world.oracle.ImmutableWorldSpawnOracle;
@ -69,12 +67,16 @@ public class WorldBuilder {
MovablePlayerList.dummy(),
versionFeatures,
biomeDataOracle,
new HeuristicWorldSpawnOracle(worldSeed.getLong(), biomeDataOracle, versionFeatures
.getValidBiomesForStructure_Spawn()));
new HeuristicWorldSpawnOracle(
worldSeed.getLong(),
biomeDataOracle,
versionFeatures.getValidBiomesForStructure_Spawn()));
}
public World fromSaveGame(MinecraftInterface minecraftInterface, SaveDirectory saveDirectory) throws IOException,
MinecraftInterfaceException, MojangApiParsingException {
public World fromSaveGame(MinecraftInterface minecraftInterface, SaveDirectory saveDirectory)
throws IOException,
MinecraftInterfaceException,
MojangApiParsingException {
VersionFeatures versionFeatures = DefaultVersionFeatures.create(minecraftInterface.getRecognisedVersion());
LevelDatNbt levelDat = saveDirectory.createLevelDat();
MovablePlayerList movablePlayerList = new MovablePlayerList(
@ -102,7 +104,6 @@ public class WorldBuilder {
VersionFeatures versionFeatures,
BiomeDataOracle biomeDataOracle,
WorldSpawnOracle worldSpawnOracle) throws MinecraftInterfaceException {
// @formatter:off
RecognisedVersion recognisedVersion = minecraftInterface.getRecognisedVersion();
seedHistoryLogger.log(recognisedVersion, worldSeed);
long seed = worldSeed.getLong();
@ -115,55 +116,65 @@ public class WorldBuilder {
recognisedVersion,
versionFeatures,
biomeDataOracle,
EndIslandOracle.from( seed),
new SlimeChunkOracle( seed),
EndIslandOracle.from(seed),
new SlimeChunkOracle(seed),
new SpawnProducer(worldSpawnOracle),
versionFeatures.getStrongholdProducerFactory().apply(seed, biomeDataOracle, versionFeatures.getValidBiomesAtMiddleOfChunk_Stronghold()),
versionFeatures.getStrongholdProducerFactory().apply(
seed,
biomeDataOracle,
versionFeatures.getValidBiomesAtMiddleOfChunk_Stronghold()),
new PlayerProducer(movablePlayerList),
new StructureProducer<Void>(
new StructureProducer<>(
Resolution.CHUNK,
4,
new VillageLocationChecker(seed, biomeDataOracle, versionFeatures.getValidBiomesForStructure_Village()),
new VillageLocationChecker(
seed,
biomeDataOracle,
versionFeatures.getValidBiomesForStructure_Village()),
new ImmutableWorldIconTypeProvider(DefaultWorldIconTypes.VILLAGE),
Dimension.OVERWORLD,
false
), new StructureProducer<Void>(
false),
new StructureProducer<>(
Resolution.CHUNK,
8,
new TempleLocationChecker(seed, biomeDataOracle, versionFeatures.getValidBiomesAtMiddleOfChunk_Temple()),
new TempleLocationChecker(
seed,
biomeDataOracle,
versionFeatures.getValidBiomesAtMiddleOfChunk_Temple()),
new TempleWorldIconTypeProvider(biomeDataOracle),
Dimension.OVERWORLD,
false
), new StructureProducer<Void>(
false),
new StructureProducer<>(
Resolution.CHUNK,
8,
versionFeatures.getMineshaftAlgorithmFactory().apply(seed),
new ImmutableWorldIconTypeProvider(DefaultWorldIconTypes.MINESHAFT),
Dimension.OVERWORLD,
false
), new StructureProducer<Void>(
false),
new StructureProducer<>(
Resolution.CHUNK,
8,
versionFeatures.getOceanMonumentLocationCheckerFactory().apply(seed, biomeDataOracle, versionFeatures.getValidBiomesAtMiddleOfChunk_OceanMonument(), versionFeatures.getValidBiomesForStructure_OceanMonument()),
versionFeatures.getOceanMonumentLocationCheckerFactory().apply(
seed,
biomeDataOracle,
versionFeatures.getValidBiomesAtMiddleOfChunk_OceanMonument(),
versionFeatures.getValidBiomesForStructure_OceanMonument()),
new ImmutableWorldIconTypeProvider(DefaultWorldIconTypes.OCEAN_MONUMENT),
Dimension.OVERWORLD,
false
), new StructureProducer<Void>(
false),
new StructureProducer<>(
Resolution.NETHER_CHUNK,
88,
new NetherFortressAlgorithm(seed),
new ImmutableWorldIconTypeProvider(DefaultWorldIconTypes.NETHER_FORTRESS),
Dimension.NETHER,
false
), new StructureProducer<List<EndIsland>>(
false),
new StructureProducer<>(
Resolution.CHUNK,
8,
new EndCityLocationChecker(seed),
new EndCityWorldIconTypeProvider(),
Dimension.END,
false
)
);
// @formatter:on
false));
}
}

View File

@ -19,26 +19,20 @@ public enum WorldType {
public static final String PROMPT_EACH_TIME = "Prompt each time";
// @formatter:off
private static final WorldType[] SELECTABLE_WORLD_TYPES_ARRAY = new WorldType[] {
WorldType.DEFAULT,
WorldType.FLAT,
WorldType.LARGE_BIOMES,
WorldType.AMPLIFIED
};
// @formatter:on
WorldType.AMPLIFIED };
private static final List<WorldType> SELECTABLE_WORLD_TYPES = Arrays.asList(SELECTABLE_WORLD_TYPES_ARRAY);
// @formatter:off
private static final String[] WORLD_TYPE_SETTING_AVAILABLE_VALUES = new String[] {
PROMPT_EACH_TIME,
WorldType.DEFAULT.getName(),
WorldType.FLAT.getName(),
WorldType.LARGE_BIOMES.getName(),
WorldType.AMPLIFIED.getName()
};
// @formatter:on
WorldType.AMPLIFIED.getName() };
public static List<WorldType> getSelectable() {
return SELECTABLE_WORLD_TYPES;

View File

@ -46,7 +46,7 @@ public class Biome {
}
// @formatter:off
private static final Map<String, Biome> biomeMap = new HashMap<String, Biome>();
private static final Map<String, Biome> biomeMap = new HashMap<>();
private static final Biome[] biomes = new Biome[256];
public static final Biome ocean = new Biome("Ocean", 0, BiomeColor.from( 0, 0, 112), BiomeType.OCEAN);

View File

@ -9,17 +9,14 @@ public class EndCityLocationChecker extends AllValidLocationChecker {
private static final boolean USE_TWO_VALUES_FOR_UPDATE = true;
public EndCityLocationChecker(long seed) {
// @formatter:off
super(new StructureAlgorithm(
super(
new StructureAlgorithm(
seed,
MAGIC_NUMBER_FOR_SEED_1,
MAGIC_NUMBER_FOR_SEED_2,
MAGIC_NUMBER_FOR_SEED_3,
MAX_DISTANCE_BETWEEN_SCATTERED_FEATURES,
MIN_DISTANCE_BETWEEN_SCATTERED_FEATURES,
USE_TWO_VALUES_FOR_UPDATE
)
);
// @formatter:on
USE_TWO_VALUES_FOR_UPDATE));
}
}

View File

@ -59,25 +59,16 @@ public class OceanMonumentLocationChecker_Fixed extends AllValidLocationChecker
BiomeDataOracle biomeDataOracle,
List<Biome> validBiomesAtMiddleOfChunk,
List<Biome> validBiomesForStructure) {
// @formatter:off
super(new StructureAlgorithm(
super(
new StructureAlgorithm(
seed,
MAGIC_NUMBER_FOR_SEED_1,
MAGIC_NUMBER_FOR_SEED_2,
MAGIC_NUMBER_FOR_SEED_3,
MAX_DISTANCE_BETWEEN_SCATTERED_FEATURES,
MIN_DISTANCE_BETWEEN_SCATTERED_FEATURES,
USE_TWO_VALUES_FOR_UPDATE
), new StructureBiomeLocationChecker(
biomeDataOracle,
STRUCTURE_CENTER_SIZE,
validBiomesAtMiddleOfChunk
), new StructureBiomeLocationChecker(
biomeDataOracle,
STRUCTURE_SIZE,
validBiomesForStructure
)
);
// @formatter:on
USE_TWO_VALUES_FOR_UPDATE),
new StructureBiomeLocationChecker(biomeDataOracle, STRUCTURE_CENTER_SIZE, validBiomesAtMiddleOfChunk),
new StructureBiomeLocationChecker(biomeDataOracle, STRUCTURE_SIZE, validBiomesForStructure));
}
}

View File

@ -21,24 +21,16 @@ public class OceanMonumentLocationChecker_Original extends AllValidLocationCheck
BiomeDataOracle biomeDataOracle,
List<Biome> validBiomesAtMiddleOfChunk,
List<Biome> validBiomesForStructure) {
// @formatter:off
super(new StructureAlgorithm(
super(
new StructureAlgorithm(
seed,
MAGIC_NUMBER_FOR_SEED_1,
MAGIC_NUMBER_FOR_SEED_2,
MAGIC_NUMBER_FOR_SEED_3,
MAX_DISTANCE_BETWEEN_SCATTERED_FEATURES,
MIN_DISTANCE_BETWEEN_SCATTERED_FEATURES,
USE_TWO_VALUES_FOR_UPDATE
), new BiomeLocationChecker(
biomeDataOracle,
validBiomesAtMiddleOfChunk
), new StructureBiomeLocationChecker(
biomeDataOracle,
STRUCTURE_SIZE,
validBiomesForStructure
)
);
// @formatter:on
USE_TWO_VALUES_FOR_UPDATE),
new BiomeLocationChecker(biomeDataOracle, validBiomesAtMiddleOfChunk),
new StructureBiomeLocationChecker(biomeDataOracle, STRUCTURE_SIZE, validBiomesForStructure));
}
}

View File

@ -64,13 +64,13 @@ public class StructureAlgorithm implements LocationChecker {
}
private int updateValue(Random random, int value) {
value *= maxDistanceBetweenScatteredFeatures;
int result = value * maxDistanceBetweenScatteredFeatures;
if (useTwoValuesForUpdate) {
value += (random.nextInt(distanceBetweenScatteredFeaturesRange) + random
.nextInt(distanceBetweenScatteredFeaturesRange)) / 2;
result += (random.nextInt(distanceBetweenScatteredFeaturesRange)
+ random.nextInt(distanceBetweenScatteredFeaturesRange)) / 2;
} else {
value += random.nextInt(distanceBetweenScatteredFeaturesRange);
result += random.nextInt(distanceBetweenScatteredFeaturesRange);
}
return value;
return result;
}
}

View File

@ -16,20 +16,15 @@ public class TempleLocationChecker extends AllValidLocationChecker {
private static final boolean USE_TWO_VALUES_FOR_UPDATE = false;
public TempleLocationChecker(long seed, BiomeDataOracle biomeDataOracle, List<Biome> validBiomesAtMiddleOfChunk) {
// @formatter:off
super(new StructureAlgorithm(
super(
new StructureAlgorithm(
seed,
MAGIC_NUMBER_FOR_SEED_1,
MAGIC_NUMBER_FOR_SEED_2,
MAGIC_NUMBER_FOR_SEED_3,
MAX_DISTANCE_BETWEEN_SCATTERED_FEATURES,
MIN_DISTANCE_BETWEEN_SCATTERED_FEATURES,
USE_TWO_VALUES_FOR_UPDATE
), new BiomeLocationChecker(
biomeDataOracle,
validBiomesAtMiddleOfChunk
)
);
// @formatter:on
USE_TWO_VALUES_FOR_UPDATE),
new BiomeLocationChecker(biomeDataOracle, validBiomesAtMiddleOfChunk));
}
}

View File

@ -17,24 +17,16 @@ public class VillageLocationChecker extends AllValidLocationChecker {
private static final int STRUCTURE_SIZE = 0;
public VillageLocationChecker(long seed, BiomeDataOracle biomeDataOracle, List<Biome> validBiomesForStructure) {
// @formatter:off
super(new StructureAlgorithm(
super(
new StructureAlgorithm(
seed,
MAGIC_NUMBER_FOR_SEED_1,
MAGIC_NUMBER_FOR_SEED_2,
MAGIC_NUMBER_FOR_SEED_3,
MAX_DISTANCE_BETWEEN_SCATTERED_FEATURES,
MIN_DISTANCE_BETWEEN_SCATTERED_FEATURES,
USE_TWO_VALUES_FOR_UPDATE
), new StructureBiomeLocationChecker(
biomeDataOracle,
STRUCTURE_SIZE,
validBiomesForStructure
), new VillageAlgorithm(
biomeDataOracle,
validBiomesForStructure
)
);
// @formatter:on
USE_TWO_VALUES_FOR_UPDATE),
new StructureBiomeLocationChecker(biomeDataOracle, STRUCTURE_SIZE, validBiomesForStructure),
new VillageAlgorithm(biomeDataOracle, validBiomesForStructure));
}
}

View File

@ -19,15 +19,16 @@ public class PlayerProducer extends CachedWorldIconProducer {
@Override
protected List<WorldIcon> doCreateCache() {
List<WorldIcon> result = new LinkedList<WorldIcon>();
List<WorldIcon> result = new LinkedList<>();
for (Player player : movablePlayerList) {
PlayerCoordinates coordinates = player.getPlayerCoordinates();
result.add(new WorldIcon(
coordinates.getCoordinatesInWorld(),
player.getPlayerName(),
player.getHead(),
coordinates.getDimension(),
true));
result.add(
new WorldIcon(
coordinates.getCoordinatesInWorld(),
player.getPlayerName(),
player.getHead(),
coordinates.getDimension(),
true));
}
return result;
}

View File

@ -38,8 +38,8 @@ public class StrongholdProducer_128Algorithm extends StrongholdProducer_Buggy128
@Override
protected double getNextValue_distance(int currentRing, Random random) {
return (4.0 * DISTANCE_IN_CHUNKS) + (6.0 * currentRing * DISTANCE_IN_CHUNKS) + (random.nextDouble() - 0.5)
* (DISTANCE_IN_CHUNKS * 2.5);
return (4.0 * DISTANCE_IN_CHUNKS) + (6.0 * currentRing * DISTANCE_IN_CHUNKS)
+ (random.nextDouble() - 0.5) * (DISTANCE_IN_CHUNKS * 2.5);
}
@Override

View File

@ -29,7 +29,7 @@ public abstract class StrongholdProducer_Base extends CachedWorldIconProducer {
@Override
protected List<WorldIcon> doCreateCache() {
List<WorldIcon> result = new LinkedList<WorldIcon>();
List<WorldIcon> result = new LinkedList<>();
Random random = new Random(seed);
int ring = getInitialValue_ring();
int structuresPerRing = STRUCTURES_ON_FIRST_RING;
@ -48,8 +48,11 @@ public abstract class StrongholdProducer_Base extends CachedWorldIconProducer {
// begin placing strongholds on the next ring.
ring = getNextValue_ring(ring);
currentRingStructureCount = getNextValue_currentRingStructureCount(currentRingStructureCount);
structuresPerRing = getNextValue_structuresPerRing(structuresPerRing, ring, getTotalStructureCount()
- i, random);
structuresPerRing = getNextValue_structuresPerRing(
structuresPerRing,
ring,
getTotalStructureCount() - i,
random);
angle = getNextValue_startAngle(angle, random);
}
}

View File

@ -59,12 +59,13 @@ public class StructureProducer<T> extends WorldIconProducer<T> {
DefaultWorldIconTypes worldIconType = provider.get(x, y, additionalData);
if (worldIconType != null) {
CoordinatesInWorld coordinates = createCoordinates(corner, xRelativeToFragment, yRelativeToFragment);
consumer.accept(new WorldIcon(
coordinates,
worldIconType.getLabel(),
worldIconType.getImage(),
dimension,
displayDimension));
consumer.accept(
new WorldIcon(
coordinates,
worldIconType.getLabel(),
worldIconType.getImage(),
dimension,
displayDimension));
}
}
}

View File

@ -20,7 +20,7 @@ public class WorldIconCollector implements Consumer<WorldIcon> {
private void initListIfNecessary() {
if (worldIcons == null) {
worldIcons = new LinkedList<WorldIcon>();
worldIcons = new LinkedList<>();
}
}

View File

@ -34,7 +34,7 @@ public enum DefaultWorldIconTypes {
private static final Map<String, DefaultWorldIconTypes> typeMap = createTypeMap();
private static Map<String, DefaultWorldIconTypes> createTypeMap() {
Map<String, DefaultWorldIconTypes> result = new HashMap<String, DefaultWorldIconTypes>();
Map<String, DefaultWorldIconTypes> result = new HashMap<>();
for (DefaultWorldIconTypes iconType : EnumSet.allOf(DefaultWorldIconTypes.class)) {
result.put(iconType.getName(), iconType);
}

View File

@ -146,7 +146,8 @@ public class BiomeDataOracle {
return coordinate * 16 + 8;
}
public Biome getBiomeAtMiddleOfChunk(int chunkX, int chunkY) throws UnknownBiomeIndexException,
public Biome getBiomeAtMiddleOfChunk(int chunkX, int chunkY)
throws UnknownBiomeIndexException,
MinecraftInterfaceException {
return getBiomeAt(getMiddleOfChunk(chunkX), getMiddleOfChunk(chunkY));
}
@ -161,7 +162,8 @@ public class BiomeDataOracle {
return Biome.getByIndex(biomeData[0]);
}
private int[] getQuarterResolutionBiomeData(int x, int y, int width, int height) throws MinecraftInterfaceException {
private int[] getQuarterResolutionBiomeData(int x, int y, int width, int height)
throws MinecraftInterfaceException {
return getBiomeData(x, y, width, height, true);
}

View File

@ -69,13 +69,12 @@ public class EndIslandOracle {
}
public List<EndIsland> getAt(CoordinatesInWorld corner) {
// @formatter:off
int steps = Resolution.CHUNK.getStepsPerFragment();
return findSurroundingIslands(
(int) corner.getXAs(Resolution.CHUNK),
(int) corner.getYAs(Resolution.CHUNK),
steps, steps);
// @formatter:on
steps,
steps);
}
/**
@ -86,7 +85,7 @@ public class EndIslandOracle {
int chunkY,
int chunksPerFragmentX,
int chunksPerFragmentY) {
List<EndIsland> result = new LinkedList<EndIsland>();
List<EndIsland> result = new LinkedList<>();
for (int y = -SURROUNDING_CHUNKS; y <= chunksPerFragmentY + SURROUNDING_CHUNKS; y++) {
for (int x = -SURROUNDING_CHUNKS; x <= chunksPerFragmentX + SURROUNDING_CHUNKS; x++) {
EndIsland island = tryCreateEndIsland(chunkX + x, chunkY + y);

View File

@ -24,7 +24,7 @@ public class MovablePlayerList implements Iterable<Player> {
private final boolean isSaveEnabled;
private volatile WorldPlayerType worldPlayerType;
private volatile ConcurrentLinkedQueue<Player> players = new ConcurrentLinkedQueue<Player>();
private volatile ConcurrentLinkedQueue<Player> players = new ConcurrentLinkedQueue<>();
public MovablePlayerList(
PlayerInformationCache playerInformationCache,
@ -52,7 +52,7 @@ public class MovablePlayerList implements Iterable<Player> {
public void load(WorkerExecutor workerExecutor, Runnable onPlayerFinishedLoading) {
if (saveDirectory != null) {
Log.i("loading player locations");
ConcurrentLinkedQueue<Player> players = new ConcurrentLinkedQueue<Player>();
ConcurrentLinkedQueue<Player> players = new ConcurrentLinkedQueue<>();
this.players = players;
loadPlayersLater(players, workerExecutor, onPlayerFinishedLoading);
}

View File

@ -43,8 +43,10 @@ public class Player {
if (saveLocation()) {
return true;
} else {
Log.w("skipping to save player location, because the backup file cannot be created for player: "
+ getPlayerName());
Log
.w(
"skipping to save player location, because the backup file cannot be created for player: "
+ getPlayerName());
return false;
}
} catch (MojangApiParsingException e) {

View File

@ -16,19 +16,19 @@ import amidst.logging.Log;
*/
@ThreadSafe
public class PlayerInformationCacheImpl implements PlayerInformationCache {
private final Map<String, PlayerInformation> byUUID = new ConcurrentHashMap<String, PlayerInformation>();
private final Map<String, PlayerInformation> byName = new ConcurrentHashMap<String, PlayerInformation>();
private final Map<String, PlayerInformation> byUUID = new ConcurrentHashMap<>();
private final Map<String, PlayerInformation> byName = new ConcurrentHashMap<>();
@NotNull
@Override
public PlayerInformation getByUUID(String uuid) {
uuid = getCleanUUID(uuid);
PlayerInformation result = byUUID.get(uuid);
String cleanUUID = getCleanUUID(uuid);
PlayerInformation result = byUUID.get(cleanUUID);
if (result != null) {
return result;
} else {
Log.i("requesting player information for uuid: " + uuid);
result = PlayerInformation.fromUUID(uuid);
Log.i("requesting player information for uuid: " + cleanUUID);
result = PlayerInformation.fromUUID(cleanUUID);
put(result);
return result;
}

View File

@ -53,7 +53,7 @@ public enum WorldPlayerType {
@NotNull
public List<PlayerNbt> createPlayerNbts(SaveDirectory saveDirectory) {
if (this == BOTH) {
List<PlayerNbt> result = new ArrayList<PlayerNbt>();
List<PlayerNbt> result = new ArrayList<>();
result.addAll(saveDirectory.createSingleplayerPlayerNbts());
result.addAll(saveDirectory.createMultiplayerPlayerNbts());
return result;

View File

@ -25,7 +25,6 @@ public enum DefaultVersionFeatures {
INSTANCE;
public static VersionFeatures create(RecognisedVersion version) {
// @formatter:off
return new VersionFeatures(
INSTANCE.enabledLayers.getValue(version),
INSTANCE.validBiomesForStructure_Spawn.getValue(version),
@ -36,9 +35,7 @@ public enum DefaultVersionFeatures {
INSTANCE.mineshaftAlgorithmFactory.getValue(version),
INSTANCE.oceanMonumentLocationCheckerFactory.getValue(version),
INSTANCE.validBiomesAtMiddleOfChunk_OceanMonument.getValue(version),
INSTANCE.validBiomesForStructure_OceanMonument.getValue(version)
);
// @formatter:on
INSTANCE.validBiomesForStructure_OceanMonument.getValue(version));
}
private final VersionFeature<List<Integer>> enabledLayers;
@ -187,7 +184,7 @@ public enum DefaultVersionFeatures {
}
private static List<Biome> getValidBiomesForStrongholdSinceV13w36a() {
List<Biome> result = new ArrayList<Biome>();
List<Biome> result = new ArrayList<>();
for (Biome biome : Biome.allBiomes()) {
if (biome.getType().getBiomeDepth() > 0) {
result.add(biome);

View File

@ -13,7 +13,7 @@ import amidst.mojangapi.minecraftinterface.RecognisedVersion;
@NotThreadSafe
public class ListVersionFeatureBuilder<V> {
private static <V> List<V> concat(List<V> values, List<V> additionalValues) {
List<V> result = new ArrayList<V>(values.size() + additionalValues.size());
List<V> result = new ArrayList<>(values.size() + additionalValues.size());
result.addAll(values);
result.addAll(additionalValues);
return result;
@ -22,8 +22,8 @@ public class ListVersionFeatureBuilder<V> {
private List<V> defaultValue = null;
private RecognisedVersion previous = null;
private RecognisedVersion previousExact = null;
private final List<VersionFeatureEntry<List<V>>> exactMatches = new LinkedList<VersionFeatureEntry<List<V>>>();
private final List<VersionFeatureEntry<List<V>>> entriesNewestFirst = new LinkedList<VersionFeatureEntry<List<V>>>();
private final List<VersionFeatureEntry<List<V>>> exactMatches = new LinkedList<>();
private final List<VersionFeatureEntry<List<V>>> entriesNewestFirst = new LinkedList<>();
@SafeVarargs
public final ListVersionFeatureBuilder<V> init(V... defaultValues) {
@ -56,7 +56,7 @@ public class ListVersionFeatureBuilder<V> {
throw new IllegalStateException("you have to specify all exact matches before the first since");
} else {
previousExact = version;
exactMatches.add(0, new VersionFeatureEntry<List<V>>(version, Collections.unmodifiableList(value)));
exactMatches.add(0, new VersionFeatureEntry<>(version, Collections.unmodifiableList(value)));
return this;
}
}
@ -81,7 +81,7 @@ public class ListVersionFeatureBuilder<V> {
throw new IllegalStateException("you have to specify versions in ascending order");
} else {
previous = version;
entriesNewestFirst.add(0, new VersionFeatureEntry<List<V>>(version, Collections.unmodifiableList(value)));
entriesNewestFirst.add(0, new VersionFeatureEntry<>(version, Collections.unmodifiableList(value)));
return this;
}
}
@ -97,7 +97,7 @@ public class ListVersionFeatureBuilder<V> {
}
public VersionFeature<List<V>> construct() {
return new VersionFeature<List<V>>(
return new VersionFeature<>(
defaultValue,
Collections.unmodifiableList(exactMatches),
Collections.unmodifiableList(entriesNewestFirst));

View File

@ -8,11 +8,11 @@ import amidst.mojangapi.minecraftinterface.RecognisedVersion;
@Immutable
public class VersionFeature<V> {
public static <V> VersionFeatureBuilder<V> builder() {
return new VersionFeatureBuilder<V>();
return new VersionFeatureBuilder<>();
}
public static <V> ListVersionFeatureBuilder<V> listBuilder() {
return new ListVersionFeatureBuilder<V>();
return new ListVersionFeatureBuilder<>();
}
private final V defaultValue;

View File

@ -13,8 +13,8 @@ public class VersionFeatureBuilder<V> {
private V defaultValue = null;
private RecognisedVersion previous = null;
private RecognisedVersion previousExact = null;
private final List<VersionFeatureEntry<V>> exactMatches = new LinkedList<VersionFeatureEntry<V>>();
private final List<VersionFeatureEntry<V>> entriesNewestFirst = new LinkedList<VersionFeatureEntry<V>>();
private final List<VersionFeatureEntry<V>> exactMatches = new LinkedList<>();
private final List<VersionFeatureEntry<V>> entriesNewestFirst = new LinkedList<>();
public VersionFeatureBuilder<V> init(V defaultValue) {
if (this.defaultValue == null) {
@ -37,7 +37,7 @@ public class VersionFeatureBuilder<V> {
throw new IllegalStateException("you have to specify all exact matches before the first since");
} else {
previousExact = version;
exactMatches.add(0, new VersionFeatureEntry<V>(version, value));
exactMatches.add(0, new VersionFeatureEntry<>(version, value));
return this;
}
}
@ -52,13 +52,13 @@ public class VersionFeatureBuilder<V> {
throw new IllegalStateException("you have to specify versions in ascending order");
} else {
previous = version;
entriesNewestFirst.add(0, new VersionFeatureEntry<V>(version, value));
entriesNewestFirst.add(0, new VersionFeatureEntry<>(version, value));
return this;
}
}
public VersionFeature<V> construct() {
return new VersionFeature<V>(
return new VersionFeature<>(
defaultValue,
Collections.unmodifiableList(exactMatches),
Collections.unmodifiableList(entriesNewestFirst));

View File

@ -11,39 +11,33 @@ public enum Settings {
;
public static <T> Setting<T> createImmutable(T value) {
return new ImmutableSetting<T>(value);
return new ImmutableSetting<>(value);
}
public static Setting<String> createString(Preferences preferences, String key, @NotNull String defaultValue) {
// @formatter:off
return new SettingBase<String>(defaultValue,
return new SettingBase<>(
defaultValue,
value -> preferences.get(key, value),
value -> preferences.put(key, value));
// @formatter:on
}
public static Setting<Boolean> createBoolean(Preferences preferences, String key, boolean defaultValue) {
// @formatter:off
return new SettingBase<Boolean>(defaultValue,
return new SettingBase<>(
defaultValue,
value -> preferences.getBoolean(key, value),
value -> preferences.putBoolean(key, value));
// @formatter:on
}
public static Setting<Dimension> createDimension(Preferences preferences, String key, Dimension defaultValue) {
// @formatter:off
return new SettingBase<Dimension>(defaultValue,
return new SettingBase<>(
defaultValue,
value -> Dimension.from(preferences.getInt(key, value.getId())),
value -> preferences.putInt(key, value.getId()));
// @formatter:on
}
public static <T> Setting<T> createDummy(T defaultValue) {
// @formatter:off
return new SettingBase<T>(defaultValue,
value -> value,
value -> {});
// @formatter:on
return new SettingBase<>(defaultValue, value -> value, value -> {
});
}
public static <T> Setting<T> createDummyWithListener(T defaultValue, Runnable listener) {

View File

@ -20,7 +20,7 @@ import amidst.mojangapi.world.biome.BiomeColor;
@Immutable
public class BiomeProfile {
private static Map<String, BiomeColorJson> createDefaultColorMap() {
Map<String, BiomeColorJson> result = new HashMap<String, BiomeColorJson>();
Map<String, BiomeColorJson> result = new HashMap<>();
for (Biome biome : Biome.allBiomes()) {
result.put(biome.getName(), biome.getDefaultColor().createBiomeColorJson());
}
@ -105,7 +105,7 @@ public class BiomeProfile {
}
private Set<Entry<String, BiomeColorJson>> getSortedColorMapEntries() {
SortedMap<String, BiomeColorJson> result = new TreeMap<String, BiomeColorJson>(Biome::compareByIndex);
SortedMap<String, BiomeColorJson> result = new TreeMap<>(Biome::compareByIndex);
result.putAll(colorMap);
return result.entrySet();
}

View File

@ -5,13 +5,13 @@ import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import amidst.documentation.Immutable;
import amidst.logging.Log;
import com.google.gson.Gson;
import com.google.gson.JsonIOException;
import com.google.gson.JsonSyntaxException;
import amidst.documentation.Immutable;
import amidst.logging.Log;
@Immutable
public class BiomeProfileDirectory {
public static BiomeProfileDirectory create(String root) {

View File

@ -10,7 +10,7 @@ import amidst.documentation.ThreadSafe;
*/
@ThreadSafe
public class TaskQueue {
private final ConcurrentLinkedQueue<Runnable> tasks = new ConcurrentLinkedQueue<Runnable>();
private final ConcurrentLinkedQueue<Runnable> tasks = new ConcurrentLinkedQueue<>();
/**
* Executes all tasks. Returns true, if at least one task was executed.

View File

@ -102,7 +102,10 @@ public class WorkerExecutor {
});
}
public <R, P> void run(ProgressReportingWorkerWithResult<R, P> main, Consumer<P> onProgress, Consumer<R> onFinished) {
public <R, P> void run(
ProgressReportingWorkerWithResult<R, P> main,
Consumer<P> onProgress,
Consumer<R> onFinished) {
runInWorker(() -> {
R output = main.run(progressReporter(onProgress));
runInEDT(() -> onFinished.accept(output));

Some files were not shown because too many files have changed in this diff Show More