-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
136 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
plugin/src/main/java/io/github/addoncommunity/galactifun/Galactifun2Loader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package io.github.addoncommunity.galactifun; | ||
|
||
import com.google.gson.Gson; | ||
import io.papermc.paper.plugin.loader.PluginClasspathBuilder; | ||
import io.papermc.paper.plugin.loader.PluginLoader; | ||
import io.papermc.paper.plugin.loader.library.impl.MavenLibraryResolver; | ||
import org.eclipse.aether.artifact.DefaultArtifact; | ||
import org.eclipse.aether.graph.Dependency; | ||
import org.eclipse.aether.repository.RemoteRepository; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Stream; | ||
|
||
@SuppressWarnings("UnstableApiUsage") | ||
public class Galactifun2Loader implements PluginLoader { | ||
|
||
@Override | ||
public void classloader(@NotNull PluginClasspathBuilder classpathBuilder) { | ||
MavenLibraryResolver resolver = new MavenLibraryResolver(); | ||
PluginLibraries pluginLibraries = load(); | ||
pluginLibraries.asDependencies().forEach(resolver::addDependency); | ||
pluginLibraries.asRepositories().forEach(resolver::addRepository); | ||
classpathBuilder.addLibrary(resolver); | ||
} | ||
|
||
private PluginLibraries load() { | ||
try (var in = getClass().getResourceAsStream("/paper-libraries.json")) { | ||
assert in != null; | ||
return new Gson().fromJson(new InputStreamReader(in, StandardCharsets.UTF_8), PluginLibraries.class); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
private record PluginLibraries(Map<String, String> repositories, List<String> dependencies) { | ||
public Stream<Dependency> asDependencies() { | ||
return dependencies.stream() | ||
.map(d -> new Dependency(new DefaultArtifact(d), null)); | ||
} | ||
|
||
public Stream<RemoteRepository> asRepositories() { | ||
return repositories.entrySet().stream() | ||
.map(e -> new RemoteRepository.Builder(e.getKey(), "default", e.getValue()).build()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
plugin/src/main/kotlin/io/github/addoncommunity/galactifun/Galactifun2Bootstrapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package io.github.addoncommunity.galactifun | ||
|
||
import io.papermc.paper.plugin.bootstrap.BootstrapContext | ||
import io.papermc.paper.plugin.bootstrap.PluginBootstrap | ||
import io.papermc.paper.plugin.bootstrap.PluginProviderContext | ||
import org.bukkit.plugin.java.JavaPlugin | ||
|
||
@Suppress("UnstableApiUsage") | ||
class Galactifun2Bootstrapper : PluginBootstrap { | ||
|
||
override fun bootstrap(context: BootstrapContext) { | ||
// Nothing to do here | ||
} | ||
|
||
override fun createPlugin(context: PluginProviderContext): JavaPlugin { | ||
return Galactifun2 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.