Add Fabric as a platform type (#1376)

* PlatformType: Add Fabric as a platform

* Don't use XML reflections on Fabric
This commit is contained in:
Camotoy 2020-10-07 18:51:36 -04:00 committed by GitHub
parent 90656a9846
commit 172a5a6db8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 14 additions and 12 deletions

View file

@ -312,15 +312,16 @@ public class GeyserConnector {
} }
/** /**
* Get the production status of the current runtime. * Whether to use XML reflections in the jar or manually find the reflections.
* Will return true if the version number is not 'DEV'. * Will return true if the version number is not 'DEV' and the platform is not Fabric.
* Should only happen in compiled jars. * On Fabric - it complains about being unable to create a default XMLReader.
* On other platforms this should only be true in compiled jars.
* *
* @return If we are in a production build/environment * @return whether to use XML reflections
*/ */
public boolean isProduction() { public boolean useXmlReflections() {
//noinspection ConstantConditions //noinspection ConstantConditions
return !"DEV".equals(GeyserConnector.VERSION); return !this.getPlatformType().equals(PlatformType.FABRIC) && !"DEV".equals(GeyserConnector.VERSION);
} }
public static GeyserConnector getInstance() { public static GeyserConnector getInstance() {

View file

@ -34,10 +34,11 @@ public enum PlatformType {
ANDROID("Android"), ANDROID("Android"),
BUNGEECORD("BungeeCord"), BUNGEECORD("BungeeCord"),
FABRIC("Fabric"),
SPIGOT("Spigot"), SPIGOT("Spigot"),
SPONGE("Sponge"), SPONGE("Sponge"),
STANDALONE("Standalone"), STANDALONE("Standalone"),
VELOCITY("Velocity"); VELOCITY("Velocity");
private String platformName; private final String platformName;
} }

View file

@ -48,7 +48,7 @@ public class PacketTranslatorRegistry<T> {
private static final ObjectArrayList<Class<?>> IGNORED_PACKETS = new ObjectArrayList<>(); private static final ObjectArrayList<Class<?>> IGNORED_PACKETS = new ObjectArrayList<>();
static { static {
Reflections ref = GeyserConnector.getInstance().isProduction() ? FileUtils.getReflections("org.geysermc.connector.network.translators") : new Reflections("org.geysermc.connector.network.translators"); Reflections ref = GeyserConnector.getInstance().useXmlReflections() ? FileUtils.getReflections("org.geysermc.connector.network.translators") : new Reflections("org.geysermc.connector.network.translators");
for (Class<?> clazz : ref.getTypesAnnotatedWith(Translator.class)) { for (Class<?> clazz : ref.getTypesAnnotatedWith(Translator.class)) {
Class<?> packet = clazz.getAnnotation(Translator.class).packet(); Class<?> packet = clazz.getAnnotation(Translator.class).packet();

View file

@ -64,7 +64,7 @@ public abstract class ItemTranslator {
static { static {
/* Load item translators */ /* Load item translators */
Reflections ref = GeyserConnector.getInstance().isProduction() ? FileUtils.getReflections("org.geysermc.connector.network.translators.item") : new Reflections("org.geysermc.connector.network.translators.item"); Reflections ref = GeyserConnector.getInstance().useXmlReflections() ? FileUtils.getReflections("org.geysermc.connector.network.translators.item") : new Reflections("org.geysermc.connector.network.translators.item");
Map<NbtItemStackTranslator, Integer> loadedNbtItemTranslators = new HashMap<>(); Map<NbtItemStackTranslator, Integer> loadedNbtItemTranslators = new HashMap<>();
for (Class<?> clazz : ref.getTypesAnnotatedWith(ItemRemapper.class)) { for (Class<?> clazz : ref.getTypesAnnotatedWith(ItemRemapper.class)) {

View file

@ -40,7 +40,7 @@ public class SoundHandlerRegistry {
static final Map<SoundHandler, SoundInteractionHandler<?>> INTERACTION_HANDLERS = new HashMap<>(); static final Map<SoundHandler, SoundInteractionHandler<?>> INTERACTION_HANDLERS = new HashMap<>();
static { static {
Reflections ref = GeyserConnector.getInstance().isProduction() ? FileUtils.getReflections("org.geysermc.connector.network.translators.sound") : new Reflections("org.geysermc.connector.network.translators.sound"); Reflections ref = GeyserConnector.getInstance().useXmlReflections() ? FileUtils.getReflections("org.geysermc.connector.network.translators.sound") : new Reflections("org.geysermc.connector.network.translators.sound");
for (Class<?> clazz : ref.getTypesAnnotatedWith(SoundHandler.class)) { for (Class<?> clazz : ref.getTypesAnnotatedWith(SoundHandler.class)) {
try { try {
SoundInteractionHandler<?> interactionHandler = (SoundInteractionHandler<?>) clazz.newInstance(); SoundInteractionHandler<?> interactionHandler = (SoundInteractionHandler<?>) clazz.newInstance();

View file

@ -113,7 +113,7 @@ public class BlockTranslator {
addedStatesMap.defaultReturnValue(-1); addedStatesMap.defaultReturnValue(-1);
List<NbtMap> paletteList = new ArrayList<>(); List<NbtMap> paletteList = new ArrayList<>();
Reflections ref = GeyserConnector.getInstance().isProduction() ? FileUtils.getReflections("org.geysermc.connector.network.translators.world.block.entity") : new Reflections("org.geysermc.connector.network.translators.world.block.entity"); Reflections ref = GeyserConnector.getInstance().useXmlReflections() ? FileUtils.getReflections("org.geysermc.connector.network.translators.world.block.entity") : new Reflections("org.geysermc.connector.network.translators.world.block.entity");
ref.getTypesAnnotatedWith(BlockEntity.class); ref.getTypesAnnotatedWith(BlockEntity.class);
int waterRuntimeId = -1; int waterRuntimeId = -1;

View file

@ -68,7 +68,7 @@ public abstract class BlockEntityTranslator {
} }
static { static {
Reflections ref = GeyserConnector.getInstance().isProduction() ? FileUtils.getReflections("org.geysermc.connector.network.translators.world.block.entity") : new Reflections("org.geysermc.connector.network.translators.world.block.entity"); Reflections ref = GeyserConnector.getInstance().useXmlReflections() ? FileUtils.getReflections("org.geysermc.connector.network.translators.world.block.entity") : new Reflections("org.geysermc.connector.network.translators.world.block.entity");
for (Class<?> clazz : ref.getTypesAnnotatedWith(BlockEntity.class)) { for (Class<?> clazz : ref.getTypesAnnotatedWith(BlockEntity.class)) {
GeyserConnector.getInstance().getLogger().debug("Found annotated block entity: " + clazz.getCanonicalName()); GeyserConnector.getInstance().getLogger().debug("Found annotated block entity: " + clazz.getCanonicalName());