mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2026-11-20 07:39:40 +00:00
Sponge use jar-in-jar loader
This commit is contained in:
1 parent
5c8b0a604e
commit
b235234633
7 files changed
+145
-88
No files matched your search
@@ -26,9 +26,13 @@
|
||||
package me.lucko.luckperms.sponge;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
import me.lucko.luckperms.common.loader.LoaderBootstrap;
|
||||
import me.lucko.luckperms.common.plugin.bootstrap.BootstrappedWithLoader;
|
||||
import me.lucko.luckperms.common.plugin.bootstrap.LuckPermsBootstrap;
|
||||
import me.lucko.luckperms.common.plugin.classpath.ClassPathAppender;
|
||||
import me.lucko.luckperms.common.plugin.classpath.JarInJarClassPathAppender;
|
||||
import me.lucko.luckperms.common.plugin.logging.Log4jPluginLogger;
|
||||
import me.lucko.luckperms.common.plugin.logging.PluginLogger;
|
||||
import me.lucko.luckperms.common.util.MoreFiles;
|
||||
@@ -42,13 +46,8 @@ import org.spongepowered.api.Server;
|
||||
import org.spongepowered.api.config.ConfigDir;
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
import org.spongepowered.api.entity.living.player.server.ServerPlayer;
|
||||
import org.spongepowered.api.event.Listener;
|
||||
import org.spongepowered.api.event.Order;
|
||||
import org.spongepowered.api.event.lifecycle.ConstructPluginEvent;
|
||||
import org.spongepowered.api.event.lifecycle.StoppingEngineEvent;
|
||||
import org.spongepowered.api.profile.GameProfile;
|
||||
import org.spongepowered.plugin.PluginContainer;
|
||||
import org.spongepowered.plugin.builtin.jvm.Plugin;
|
||||
import org.spongepowered.plugin.metadata.PluginMetadata;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -62,12 +61,13 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Bootstrap plugin for LuckPerms running on Sponge.
|
||||
*/
|
||||
@Plugin("luckperms")
|
||||
public class LPSpongeBootstrap implements LuckPermsBootstrap {
|
||||
public class LPSpongeBootstrap implements LuckPermsBootstrap, LoaderBootstrap, BootstrappedWithLoader {
|
||||
private final Object loader;
|
||||
|
||||
/**
|
||||
* The plugin logger
|
||||
@@ -111,22 +111,31 @@ public class LPSpongeBootstrap implements LuckPermsBootstrap {
|
||||
/**
|
||||
* Injected configuration directory for the plugin
|
||||
*/
|
||||
private final Path configDirectory;
|
||||
|
||||
@Inject
|
||||
public LPSpongeBootstrap(Logger logger, Game game, PluginContainer pluginContainer, @ConfigDir(sharedRoot = false) Path configDirectory) {
|
||||
this.logger = new Log4jPluginLogger(logger);
|
||||
this.game = game;
|
||||
this.pluginContainer = pluginContainer;
|
||||
this.configDirectory = configDirectory;
|
||||
@ConfigDir(sharedRoot = false)
|
||||
private Path configDirectory;
|
||||
|
||||
public LPSpongeBootstrap(Supplier<Injector> loader) {
|
||||
this.loader = loader;
|
||||
|
||||
Injector injector = loader.get();
|
||||
this.logger = new Log4jPluginLogger(injector.getInstance(Logger.class));
|
||||
this.game = injector.getInstance(Game.class);
|
||||
this.pluginContainer = injector.getInstance(PluginContainer.class);
|
||||
injector.injectMembers(this);
|
||||
|
||||
this.schedulerAdapter = new SpongeSchedulerAdapter(this.game, this.pluginContainer);
|
||||
this.classPathAppender = new SpongeClassPathAppender(this);
|
||||
this.classPathAppender = new JarInJarClassPathAppender(getClass().getClassLoader());
|
||||
this.plugin = new LPSpongePlugin(this);
|
||||
}
|
||||
|
||||
// provide adapters
|
||||
|
||||
@Override
|
||||
public Object getLoader() {
|
||||
return this.loader;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PluginLogger getPluginLogger() {
|
||||
return this.logger;
|
||||
@@ -143,15 +152,18 @@ public class LPSpongeBootstrap implements LuckPermsBootstrap {
|
||||
}
|
||||
|
||||
// lifecycle
|
||||
@Listener(order = Order.FIRST)
|
||||
public void onEnable(ConstructPluginEvent event) {
|
||||
this.startTime = Instant.now();
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
try {
|
||||
this.plugin.load();
|
||||
} finally {
|
||||
this.loadLatch.countDown();
|
||||
}
|
||||
}
|
||||
|
||||
public void onEnable() {
|
||||
this.startTime = Instant.now();
|
||||
try {
|
||||
this.plugin.enable();
|
||||
} finally {
|
||||
@@ -159,8 +171,7 @@ public class LPSpongeBootstrap implements LuckPermsBootstrap {
|
||||
}
|
||||
}
|
||||
|
||||
@Listener
|
||||
public void onDisable(StoppingEngineEvent<Server> event) {
|
||||
public void onDisable() {
|
||||
this.plugin.disable();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
* This file is part of LuckPerms, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) lucko (Luck) <[email protected]>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package me.lucko.luckperms.sponge;
|
||||
|
||||
import me.lucko.luckperms.common.plugin.bootstrap.LuckPermsBootstrap;
|
||||
import me.lucko.luckperms.common.plugin.classpath.ReflectionClassPathAppender;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.URLClassLoader;
|
||||
|
||||
public class SpongeClassPathAppender extends ReflectionClassPathAppender {
|
||||
|
||||
private static URLClassLoader extractClassLoaderFromBootstrap(LuckPermsBootstrap bootstrap) {
|
||||
ClassLoader classLoader = bootstrap.getClass().getClassLoader();
|
||||
|
||||
// try to cast directly to URLClassLoader in case things change in the future
|
||||
if (classLoader instanceof URLClassLoader) {
|
||||
return (URLClassLoader) classLoader;
|
||||
}
|
||||
|
||||
Class<? extends ClassLoader> classLoaderClass = classLoader.getClass();
|
||||
|
||||
if (!classLoaderClass.getName().equals("cpw.mods.modlauncher.TransformingClassLoader")) {
|
||||
throw new IllegalStateException("ClassLoader is not instance of TransformingClassLoader: " + classLoaderClass.getName());
|
||||
}
|
||||
|
||||
try {
|
||||
Field delegatedClassLoaderField = classLoaderClass.getDeclaredField("delegatedClassLoader");
|
||||
delegatedClassLoaderField.setAccessible(true);
|
||||
Object delegatedClassLoader = delegatedClassLoaderField.get(classLoader);
|
||||
return (URLClassLoader) delegatedClassLoader;
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public SpongeClassPathAppender(LuckPermsBootstrap bootstrap) throws IllegalStateException {
|
||||
super(extractClassLoaderFromBootstrap(bootstrap));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
{
|
||||
"loader": {
|
||||
"name": "java_plain",
|
||||
"version": "1.0"
|
||||
},
|
||||
"license": "MIT",
|
||||
"plugins": [
|
||||
{
|
||||
"id": "luckperms",
|
||||
"name": "LuckPerms",
|
||||
"version": "${pluginVersion}",
|
||||
"entrypoint": "me.lucko.luckperms.sponge.LPSpongeBootstrap",
|
||||
"description": "A permissions plugin",
|
||||
"links": {
|
||||
"homepage": "https://luckperms.net"
|
||||
},
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Luck",
|
||||
"description": "Developer"
|
||||
}
|
||||
],
|
||||
"dependencies": [
|
||||
{
|
||||
"id": "spongeapi",
|
||||
"version": "8.0.0"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in new issue
Block a user