-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finally added paper plugin manager support
- Loading branch information
Showing
7 changed files
with
160 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
/.gradle/ | ||
.gradle/ | ||
/.idea/ | ||
/.vscode/ | ||
/bin/ | ||
/build/ | ||
build/ | ||
/out/ | ||
*.iml | ||
/run |
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,30 @@ | ||
plugins { | ||
id "java" | ||
id "maven-publish" | ||
id "io.papermc.paperweight.userdev" version "1.5.5" | ||
} | ||
|
||
java.toolchain.languageVersion = JavaLanguageVersion.of(17) | ||
compileJava.options.encoding = "UTF-8" | ||
|
||
archivesBaseName = "PaperSupport" | ||
group = project.maven_group | ||
version = project.maven_version | ||
|
||
repositories { | ||
mavenCentral() | ||
mavenLocal() | ||
} | ||
|
||
dependencies { | ||
paperweight.paperDevBundle("1.20-R0.1-SNAPSHOT") | ||
} | ||
|
||
java { | ||
withSourcesJar() | ||
withJavadocJar() | ||
} | ||
|
||
javadoc { | ||
failOnError = false | ||
} |
72 changes: 72 additions & 0 deletions
72
...Support/src/main/java/net/lenni0451/spm/storage/SingularRuntimePluginProviderStorage.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,72 @@ | ||
package net.lenni0451.spm.storage; | ||
|
||
import com.destroystokyo.paper.util.SneakyThrow; | ||
import com.google.common.collect.ImmutableList; | ||
import io.papermc.paper.plugin.entrypoint.Entrypoint; | ||
import io.papermc.paper.plugin.entrypoint.LaunchEntryPointHandler; | ||
import io.papermc.paper.plugin.provider.PluginProvider; | ||
import io.papermc.paper.plugin.provider.type.paper.PaperPluginParent; | ||
import io.papermc.paper.plugin.storage.ServerPluginProviderStorage; | ||
import org.bukkit.plugin.InvalidPluginException; | ||
import org.bukkit.plugin.PluginDescriptionFile; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
|
||
import java.lang.reflect.Field; | ||
import java.util.Optional; | ||
|
||
public class SingularRuntimePluginProviderStorage extends ServerPluginProviderStorage { | ||
|
||
private PluginProvider<JavaPlugin> lastProvider; | ||
private JavaPlugin singleLoaded; | ||
|
||
@Override | ||
public void register(PluginProvider<JavaPlugin> provider) { | ||
super.register(provider); | ||
if (this.lastProvider != null) { | ||
SneakyThrow.sneaky(new InvalidPluginException("Plugin registered two JavaPlugins")); | ||
} | ||
if (provider instanceof PaperPluginParent.PaperServerPluginProvider) { | ||
throw new IllegalStateException("Cannot register paper plugins during runtime!"); | ||
} | ||
this.lastProvider = provider; | ||
// Register the provider into the server entrypoint, this allows it to show in /plugins correctly. | ||
// Generally it might be better in the future to make a separate storage, as putting it into the entrypoint handlers doesn't make much sense. | ||
LaunchEntryPointHandler.INSTANCE.register(Entrypoint.PLUGIN, provider); | ||
} | ||
|
||
@Override | ||
public void enter() { | ||
PluginProvider<JavaPlugin> provider = this.lastProvider; | ||
if (provider == null) { | ||
return; | ||
} | ||
// Manually validate dependencies, LEGACY BEHAVIOR. | ||
// Normally it is logged, but manually adding one plugin will cause it to actually throw exceptions. | ||
PluginDescriptionFile descriptionFile = (PluginDescriptionFile) provider.getMeta(); | ||
try { | ||
Field depend = descriptionFile.getClass().getDeclaredField("depend"); | ||
depend.setAccessible(true); | ||
depend.set(descriptionFile, ImmutableList.of()); | ||
} catch (IllegalAccessException | NoSuchFieldException e) { | ||
SneakyThrow.sneaky(e); | ||
} | ||
// Go through normal plugin loading logic | ||
super.enter(); | ||
} | ||
|
||
@Override | ||
public void processProvided(PluginProvider<JavaPlugin> provider, JavaPlugin provided) { | ||
super.processProvided(provider, provided); | ||
this.singleLoaded = provided; | ||
} | ||
|
||
@Override | ||
public boolean throwOnCycle() { | ||
return false; | ||
} | ||
|
||
public Optional<JavaPlugin> getSingleLoaded() { | ||
return Optional.ofNullable(this.singleLoaded); | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
PaperSupport/src/main/java/net/lenni0451/spm/utils/PaperSupport.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,36 @@ | ||
package net.lenni0451.spm.utils; | ||
|
||
import io.papermc.paper.plugin.entrypoint.Entrypoint; | ||
import io.papermc.paper.plugin.entrypoint.EntrypointHandler; | ||
import io.papermc.paper.plugin.provider.type.PluginFileType; | ||
import io.papermc.paper.plugin.storage.ProviderStorage; | ||
import net.lenni0451.spm.storage.SingularRuntimePluginProviderStorage; | ||
import org.bukkit.plugin.Plugin; | ||
|
||
import java.io.File; | ||
import java.lang.reflect.Constructor; | ||
import java.lang.reflect.Method; | ||
import java.util.jar.JarFile; | ||
|
||
public class PaperSupport { | ||
|
||
public static Plugin loadPlugin(final File targetFile) throws Exception { | ||
Class<?> RuntimePluginEntrypointHandler = Class.forName("io.papermc.paper.plugin.manager.RuntimePluginEntrypointHandler"); | ||
|
||
Constructor<?> constructor = RuntimePluginEntrypointHandler.getDeclaredConstructor(ProviderStorage.class); | ||
constructor.setAccessible(true); | ||
SingularRuntimePluginProviderStorage storage = new SingularRuntimePluginProviderStorage(); | ||
EntrypointHandler handler = (EntrypointHandler) constructor.newInstance(storage); | ||
|
||
JarFile file = new JarFile(targetFile); | ||
PluginFileType<?, ?> type = PluginFileType.guessType(file); | ||
type.register(handler, file, targetFile.toPath()); | ||
|
||
handler.enter(Entrypoint.PLUGIN); | ||
Method getProviderStorage = RuntimePluginEntrypointHandler.getDeclaredMethod("getPluginProviderStorage"); | ||
getProviderStorage.setAccessible(true); | ||
SingularRuntimePluginProviderStorage providerStorage = (SingularRuntimePluginProviderStorage) getProviderStorage.invoke(handler); | ||
return providerStorage.getSingleLoaded().get(); | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,5 @@ pluginManagement { | |
} | ||
|
||
rootProject.name = 'SpigotPluginManager' | ||
|
||
include(":PaperSupport") |
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