Skip to content

Commit

Permalink
Resolve config loading issues (#124)
Browse files Browse the repository at this point in the history
* Resolve config loading issue

* remove unused common dependency, uncomment mavenLocal()

* Use timestamped floodgate core dependency

* use isTransitive instead of manual exclusions
  • Loading branch information
onebeastchris authored May 8, 2024
1 parent 3548ae5 commit fdd816d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 6 deletions.
10 changes: 5 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ dependencies {
modImplementation("net.fabricmc.fabric-api:fabric-api:0.97.6+1.20.5")

// Base Floodgate
implementation("org.geysermc.floodgate:core:2.2.3-SNAPSHOT")
shadow("org.geysermc.floodgate:core:2.2.3-SNAPSHOT") { isTransitive = false }
shadow("org.geysermc.floodgate:api:2.2.3-SNAPSHOT") { isTransitive = false }
implementation("org.geysermc.floodgate:core:2.2.3-20240508.151752-4")
shadow("org.geysermc.floodgate:core:2.2.3-20240508.151752-4") { isTransitive = false }
shadow("org.geysermc.floodgate:api:2.2.3-20240508.151752-4") { isTransitive = false }

// Requires relocation
shadow("org.bstats:bstats-base:3.0.2")
Expand All @@ -50,7 +50,7 @@ dependencies {
include("org.lanternpowered", "lmbda", "2.0.0") // used in events

// Geyser dependency for the fun injector mixin :)))
modImplementation("org.geysermc.geyser:fabric:2.2.3-SNAPSHOT")
modCompileOnly("org.geysermc.geyser:fabric:2.2.3-SNAPSHOT") { isTransitive = false }

// cloud
include("org.incendo:cloud-fabric:2.0.0-SNAPSHOT")
Expand All @@ -62,7 +62,7 @@ dependencies {
}

repositories {
//mavenLocal()
// mavenLocal()
mavenCentral()
maven("https://maven.fabricmc.net/")
maven("https://repo.opencollab.dev/main/")
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/geysermc/floodgate/FabricMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.fabricmc.loader.api.FabricLoader;
import org.geysermc.floodgate.api.logger.FloodgateLogger;
import org.geysermc.floodgate.module.*;
import org.geysermc.floodgate.util.FabricTemplateReader;

public class FabricMod implements ModInitializer {

Expand All @@ -20,7 +21,7 @@ public void onInitialize() {
FabricInjector.setInstance(new FabricInjector());

Injector injector = Guice.createInjector(
new ServerCommonModule(FabricLoader.getInstance().getConfigDir().resolve("floodgate")),
new ServerCommonModule(FabricLoader.getInstance().getConfigDir().resolve("floodgate"), new FabricTemplateReader()),
new FabricPlatformModule()
);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.geysermc.floodgate.util;

import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.ModContainer;
import org.geysermc.configutils.file.template.TemplateReader;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.Optional;

public class FabricTemplateReader implements TemplateReader {

private final ModContainer container;

public FabricTemplateReader() {
container = FabricLoader.getInstance().getModContainer("floodgate").orElseThrow();
}

@Override
public BufferedReader read(String configName) {
Optional<Path> optional = container.findPath(configName);
if (optional.isPresent()) {
try {
InputStream stream = optional.get().getFileSystem()
.provider()
.newInputStream(optional.get());
return new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8));
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
return null;
}
}

0 comments on commit fdd816d

Please sign in to comment.