Fix #50 Crash server on startup

This commit is contained in:
marcin212 committed 2017-05-09 11:29:06 +02:00
1 parent 96e4814ae3
commit 8986256b12
1 file changed
+34 -2
+34 -2
View File
@@ -13,15 +13,19 @@ import net.minecraft.world.WorldSettings;
import net.minecraft.world.WorldSettings.GameType;
import net.minecraft.world.WorldType;
import net.minecraft.world.chunk.IChunkProvider;
import sun.reflect.ReflectionFactory;
import java.lang.reflect.Constructor;
public class FakeWorld extends World {
public static FakeWorld instance = new FakeWorld();
public static FakeWorld instance = SilentObjectCreator.create(FakeWorld.class);
protected Block block;
protected int metadata;
protected TileEntity te;
public FakeWorld() {
//It is never called.
private FakeWorld() {
super(null, "", null, new WorldSettings(Long.MAX_VALUE, GameType.NOT_SET, false, false, WorldType.FLAT), null);
}
@@ -100,4 +104,32 @@ public class FakeWorld extends World {
return null;
}
public static class SilentObjectCreator {
/**
* Creating objects without calling constructors.
*/
public static <T> T create(Class<T> clazz) {
return create(clazz, Object.class);
}
/**
* Creating objects without calling constructors.
*/
public static <T> T create(Class<T> clazz,
Class<? super T> parent) {
try {
ReflectionFactory rf =
ReflectionFactory.getReflectionFactory();
Constructor objDef = parent.getDeclaredConstructor();
Constructor intConstr = rf.newConstructorForSerialization(
clazz, objDef
);
return clazz.cast(intConstr.newInstance());
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new IllegalStateException("Cannot create object", e);
}
}
}
}