move moduleloader to ModuleLoader.zip

This commit is contained in:
p2vman 2025-02-17 20:46:41 +02:00
parent e2e68201ac
commit d71cfbafdf
32 changed files with 43 additions and 847 deletions

BIN
ModuleLoader.zip Normal file

Binary file not shown.

View File

@ -1,27 +0,0 @@
plugins {
id 'java'
}
group = 'org.example'
version = '1.3'
repositories {
mavenCentral()
maven {
name = "papermc-repo"
url = "https://repo.papermc.io/repository/maven-public/"
}
maven {
name = "sonatype"
url = "https://oss.sonatype.org/content/groups/public/"
}
}
dependencies {
compileOnly "io.papermc.paper:paper-api:1.18.2-R0.1-SNAPSHOT"
implementation(files("D:\\Users\\User\\IdeaProjects\\EptaListProject\\ModuleLoader\\build\\libs\\ModuleLoader-1.0-SNAPSHOT.jar"))
}
jar {
}

View File

@ -1 +0,0 @@
rootProject.name = 'Exemplemodule'

View File

@ -1,7 +0,0 @@
package org.example;
public class ExempleClass {
public static void test() {
System.out.println("Local class get");
}
}

View File

@ -1,21 +0,0 @@
package org.example;
import io.papermc.paper.event.player.AsyncChatEvent;
import net.kyori.adventure.text.Component;
import opg.p2vman.moduleloader.module.JavaModule;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
public class ExempleModule extends JavaModule implements Listener {
@Override
public void onEnable() {
getLogger().info("Hi from module");
ExempleClass.test();
getServer().getPluginManager().registerEvents(this, getPlugin());
}
@EventHandler
public static void chatevent(AsyncChatEvent event) {
event.message(Component.text("AAAAAAAAAAAAAa"));
}
}

View File

@ -1,4 +0,0 @@
{
"main_class": "org.example.ExempleModule",
"name": "ExempleModule"
}

View File

@ -1,51 +0,0 @@
plugins {
// id 'java'
id 'java-library'
}
group = 'opg.eptalist'
version = '1.0-SNAPSHOT'
repositories {
mavenCentral()
maven {
name = "papermc-repo"
url = "https://repo.papermc.io/repository/maven-public/"
}
maven {
name = "sonatype"
url = "https://oss.sonatype.org/content/groups/public/"
}
}
dependencies {
compileOnly "io.papermc.paper:paper-api:1.18.2-R0.1-SNAPSHOT"
implementation 'org.ow2.asm:asm:9.6'
}
def targetJavaVersion = 17
java {
def javaVersion = JavaVersion.toVersion(targetJavaVersion)
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
if (JavaVersion.current() < javaVersion) {
toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion)
}
}
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) {
options.release.set(targetJavaVersion)
}
}
processResources {
def props = [version: version]
inputs.properties props
filteringCharset 'UTF-8'
filesMatching('plugin.yml') {
expand props
}
}

Binary file not shown.

View File

@ -1,7 +0,0 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

View File

@ -1 +0,0 @@
rootProject.name = 'ModuleLoader'

View File

@ -1,4 +0,0 @@
package m.dict;
public interface Lock {
}

View File

@ -1,45 +0,0 @@
package opg.p2vman.moduleloader;
import opg.p2vman.moduleloader.module.JavaModule;
import opg.p2vman.moduleloader.module.ModuleMannager;
import opg.p2vman.moduleloader.profiling.ExempleProfiler;
import opg.p2vman.moduleloader.profiling.Profiler;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.util.Optional;
public final class ModuleLoader extends JavaPlugin {
private Optional<ModuleMannager> loader = Optional.empty();
@Override
public void onEnable() {
Profiler profiler = new ExempleProfiler();
profiler.push("start_module_loader");
try {
ModuleMannager moduleLoader = new ModuleMannager();
File modules_dir = new File(getDataFolder(), "modules");
if (!modules_dir.exists()) {
modules_dir.mkdirs();
}
moduleLoader.loadModules(modules_dir).forEach((javaModule -> {
javaModule.enable();
System.out.printf("Module enabled %s", javaModule.getName());
}));
loader = Optional.of(moduleLoader);
} catch (Throwable throwable) {
throwable.printStackTrace();
}
System.out.printf("modules loaded %dms%n", profiler.getElapsedTimeAndRemove(profiler.pop()));
}
@Override
public void onDisable() {
JavaModule.MODULES.forEach(JavaModule::disable);
}
public Optional<ModuleMannager> getModuleLoader() {
return loader;
}
}

View File

@ -1,156 +0,0 @@
package opg.p2vman.moduleloader.api;
public class Identifier implements Comparable<Identifier> {
public static final char NAMESPACE_SEPARATOR = ':';
public static final String DEFAULT_NAMESPACE = "minecraft";
private final String namespace;
private final String path;
public Identifier(String namespace, String path) {
this.namespace = namespace;
this.path = path;
}
private Identifier(String[] id) {
this(id[0], id[1]);
}
public Identifier(String id) {
this(split(id, NAMESPACE_SEPARATOR));
}
public static Identifier splitOn(String id, char delimiter) {
return new Identifier(split(id, delimiter));
}
public static Identifier tryParse(String id) {
try {
return new Identifier(id);
} catch (RuntimeException var2) {
return null;
}
}
public static Identifier of(String namespace, String path) {
try {
return new Identifier(namespace, path);
} catch (RuntimeException var3) {
return null;
}
}
protected static String[] split(String id, char delimiter) {
String[] strings = new String[]{DEFAULT_NAMESPACE, id};
int i = id.indexOf(delimiter);
if (i >= 0) {
strings[1] = id.substring(i + 1);
if (i >= 1) {
strings[0] = id.substring(0, i);
}
}
return strings;
}
public String getPath() {
return this.path;
}
public String getNamespace() {
return this.namespace;
}
public String toString() {
return this.namespace + NAMESPACE_SEPARATOR + this.path;
}
public boolean equals(Object o) {
if (this == o) {
return true;
} else if (!(o instanceof Identifier)) {
return false;
} else {
Identifier identifier = (Identifier)o;
return this.namespace.equals(identifier.namespace) && this.path.equals(identifier.path);
}
}
public int hashCode() {
return 31 * this.namespace.hashCode() + this.path.hashCode();
}
public int compareTo(Identifier identifier) {
int i = this.path.compareTo(identifier.path);
if (i == 0) {
i = this.namespace.compareTo(identifier.namespace);
}
return i;
}
public String toUnderscoreSeparatedString() {
return this.toString().replace('/', '_').replace(NAMESPACE_SEPARATOR, '_');
}
public String toTranslationKey() {
return this.namespace + "." + this.path;
}
public String toShortTranslationKey() {
return this.namespace.equals(DEFAULT_NAMESPACE) ? this.path : this.toTranslationKey();
}
public String toTranslationKey(String prefix) {
return prefix + "." + this.toTranslationKey();
}
public String toTranslationKey(String prefix, String suffix) {
return prefix + "." + this.toTranslationKey() + "." + suffix;
}
public static boolean isCharValid(char c) {
return c >= '0' && c <= '9' || c >= 'a' && c <= 'z' || c == '_' || c == ':' || c == '/' || c == '.' || c == '-';
}
public static boolean isPathValid(String path) {
for(int i = 0; i < path.length(); ++i) {
if (!isPathCharacterValid(path.charAt(i))) {
return false;
}
}
return true;
}
public static boolean isNamespaceValid(String namespace) {
for(int i = 0; i < namespace.length(); ++i) {
if (!isNamespaceCharacterValid(namespace.charAt(i))) {
return false;
}
}
return true;
}
private static String validateNamespace(String namespace, String path) {
if (!isNamespaceValid(namespace)) {
throw new RuntimeException("Non [a-z0-9_.-] character in namespace of location: " + namespace + NAMESPACE_SEPARATOR + path);
} else {
return namespace;
}
}
public static boolean isPathCharacterValid(char character) {
return character == '_' || character == '-' || character >= 'a' && character <= 'z' || character >= '0' && character <= '9' || character == '/' || character == '.';
}
private static boolean isNamespaceCharacterValid(char character) {
return character == '_' || character == '-' || character >= 'a' && character <= 'z' || character >= '0' && character <= '9' || character == '.';
}
private static String validatePath(String namespace, String path) {
if (!isPathValid(path)) {
throw new RuntimeException("Non [a-z0-9/._-] character in path of location: " + namespace + NAMESPACE_SEPARATOR + path);
} else {
return path;
}
}
}

View File

@ -1,15 +0,0 @@
package opg.p2vman.moduleloader.api;
import org.bukkit.Server;
import java.util.logging.Logger;
public interface Module {
void onLoad();
void onEnable();
void onDisable();
String getName();
ResourceMannager getResourceMannager();
Server getServer();
Logger getLogger();
}

View File

@ -1,12 +0,0 @@
package opg.p2vman.moduleloader.api;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface RemapedClass {
String value();
}

View File

@ -1,13 +0,0 @@
package opg.p2vman.moduleloader.api;
import java.io.InputStream;
import java.net.URL;
public interface ResourceMannager {
InputStream getResourceAsStream(String name);
URL getResource(String name);
InputStream getResourceAsStream(Identifier identifier);
URL getResource(Identifier identifier);
URL findResource(final String name);
URL findResource(final Identifier identifier);
}

View File

@ -1,21 +0,0 @@
package opg.p2vman.moduleloader.api;
import java.util.HashMap;
import java.util.Map;
public class ServicesManager {
private final Map<Class<?>, Object> services = new HashMap<>();
public <T> void registerService(Class<T> serviceClass, T serviceInstance) {
services.put(serviceClass, serviceInstance);
}
public <T> T getService(Class<T> serviceClass) {
return (T) services.get(serviceClass);
}
public boolean hasService(Class<?> serviceClass) {
return services.containsKey(serviceClass);
}
}

View File

@ -1,100 +0,0 @@
package opg.p2vman.moduleloader.module;
import opg.p2vman.moduleloader.ModuleLoader;
import opg.p2vman.moduleloader.api.Module;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.ArrayList;
import java.util.List;
public class JavaModule implements Module {
private boolean isEnabled = false;
public static final List<JavaModule> MODULES = new ArrayList<>();
private ModuleContainer container;
private ModuleResourceMannager resourceMannager;
private ModuleLogger logger;
public JavaModule() {
}
public final void init(ModuleContainer container, ModuleResourceMannager resourceMannager, ModuleLogger logger) {
for (JavaModule module : MODULES) if (this.getClass().isInstance(module)) {
throw new RuntimeException();
}
this.resourceMannager = resourceMannager;
this.container = container;
this.logger = logger;
MODULES.add(this);
}
public static <T extends JavaModule> T getModule(Class<T> cls) {
for (JavaModule module : MODULES) if (cls.isInstance(module)) {
return (T) module;
}
return null;
}
@Override
public String getName() {
return container.meta.name;
}
@Override
public void onDisable() {
}
@Override
public void onEnable() {
}
@Override
public void onLoad() {
}
public void enable() {
if (isEnabled) throw new RuntimeException();
try {
this.onEnable();
} catch (Exception e) {
e.printStackTrace();
} finally {
isEnabled = true;
}
}
public void disable() {
if (!isEnabled) throw new RuntimeException();
try {
this.onDisable();
MODULES.remove(this);
} catch (Exception e) {
e.printStackTrace();
} finally {
isEnabled = false;
}
}
@Override
public ModuleResourceMannager getResourceMannager() {
return resourceMannager;
}
@Override
public Server getServer() {
return Bukkit.getServer();
}
@Override
public ModuleLogger getLogger() {
return logger;
}
public JavaPlugin getPlugin() {
return ModuleLoader.getPlugin(ModuleLoader.class);
}
}

View File

@ -1,13 +0,0 @@
package opg.p2vman.moduleloader.module;
import java.io.File;
public class ModuleContainer {
public final File module_file;
public final ModuleMeta meta;
public ModuleContainer(ModuleMeta meta, File module_file) {
this.meta = meta;
this.module_file = module_file;
}
}

View File

@ -1,30 +0,0 @@
package opg.p2vman.moduleloader.module;
import org.bukkit.Bukkit;
import org.jetbrains.annotations.NotNull;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
public class ModuleLogger extends Logger {
private String name;
/**
* Creates a new ModuleLogger that extracts the name from a module.
*
* @param context A reference to the module
*/
public ModuleLogger(@NotNull ModuleContainer context) {
super(context.getClass().getCanonicalName(), null);
name = new StringBuilder().append("[").append(context.meta.name).append("] ").toString();
setParent(Bukkit.getServer().getLogger());
setLevel(Level.ALL);
}
@Override
public void log(@NotNull LogRecord logRecord) {
logRecord.setMessage(name + logRecord.getMessage());
super.log(logRecord);
}
}

View File

@ -1,193 +0,0 @@
package opg.p2vman.moduleloader.module;
import com.google.gson.Gson;
import m.dict.Lock;
import org.objectweb.asm.*;
import java.io.*;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.security.SecureRandom;
import java.util.*;
import java.util.function.Supplier;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
public class ModuleMannager {
public static final FilenameFilter MODULEFILTER = (File dir, String name) -> name.endsWith(".jar") || name.endsWith(".zip") || name.endsWith(".ear");
private final MethodHandles.Lookup lookup;
private final Gson GSON;
private final SecureRandom random = new SecureRandom();
private final Map<String, String> classNameMap = new HashMap<>();
public ModuleMannager() throws IllegalAccessException {
lookup = MethodHandles.privateLookupIn(Lock.class, MethodHandles.lookup());
GSON = new Gson();
}
public List<JavaModule> loadModules(File dir) {
List<JavaModule> modules = new ArrayList<>();
for (File file : Objects.requireNonNull(dir.listFiles(MODULEFILTER))) {
try {
modules.add(loadModule(file).get());
} catch (Exception e) {
e.printStackTrace();
}
}
return modules;
}
public Supplier<JavaModule> loadModule(File plugin) {
synchronized (lookup) {
classNameMap.clear();
List<Class<?>> classes = new ArrayList<>();
Optional<JavaModule> module = Optional.empty();
try (JarFile jarFile = new JarFile(plugin)) {
Enumeration<JarEntry> entries = jarFile.entries();
while (entries.hasMoreElements()) {
JarEntry entry = entries.nextElement();
if (entry.getName().endsWith(".class")) {
try (InputStream is = jarFile.getInputStream(entry)) {
Class<?> cls = transformClass(is.readAllBytes());
classes.add(cls);
System.out.println("Loaded: " + cls.getName());
} catch (Exception e) {
throw new AssertionError(e);
}
}
}
try (InputStream is = jarFile.getInputStream(jarFile.getEntry("module.json"))) {
ModuleMeta meta = GSON.fromJson(new InputStreamReader(is), ModuleMeta.class);
ModuleContainer container = new ModuleContainer(meta, plugin);
ModuleResourceMannager resourceMannager = new ModuleResourceMannager(container);
ModuleLogger logger = new ModuleLogger(container);
String newMainClass = classNameMap.get(container.meta.main_class.replace('.', '/')).replace('/', '.');
JavaModule module1 = (JavaModule) lookup.findConstructor(lookup.findClass(newMainClass), MethodType.methodType(void.class)).invoke();
module1.init(container, resourceMannager, logger);
module = Optional.of(module1);
} catch (Throwable e) {
throw new AssertionError(e);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
final JavaModule module1 = module.orElseThrow();
return () -> {
module1.onLoad();
return module1;
};
}
}
private final Map<String, Class<?>> classCache = new HashMap<>();
private Class<?> transformClass(byte[] classBytes) {
ClassReader reader = new ClassReader(classBytes);
ClassWriter writer = new ClassWriter(reader, ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
String oldName = reader.getClassName();
String newName = "m/dict/" + generateRandomName();
while (classCache.containsKey(newName)) {
newName = "m/dict/" + generateRandomName();
}
classNameMap.put(oldName, newName);
final String finalnewName = newName;
reader.accept(new ClassVisitor(Opcodes.ASM9, writer) {
@Override
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
super.visit(version, access, finalnewName, signature, superName, interfaces);
AnnotationVisitor annotationVisitor = super.visitAnnotation("Lopg/eptalist/moduleloader/api/RemapedClass;", true);
annotationVisitor.visit("value", oldName);
annotationVisitor.visitEnd();
}
@Override
public FieldVisitor visitField(int access, String name, String descriptor, String signature, Object value) {
return super.visitField(access, name, updateDescriptor(descriptor), signature, value);
}
@Override
public AnnotationVisitor visitAnnotation(String descriptor, boolean visible) {
return super.visitAnnotation(updateDescriptor(descriptor), visible);
}
@Override
public AnnotationVisitor visitTypeAnnotation(int typeRef, TypePath typePath, String descriptor, boolean visible) {
return super.visitTypeAnnotation(typeRef, typePath, updateDescriptor(descriptor), visible);
}
@Override
public RecordComponentVisitor visitRecordComponent(String name, String descriptor, String signature) {
return super.visitRecordComponent(name, updateDescriptor(descriptor), signature);
}
@Override
public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) {
MethodVisitor mv = super.visitMethod(access, name, updateDescriptor(descriptor), signature, exceptions);
return new MethodVisitor(Opcodes.ASM9, mv) {
@Override
public void visitFieldInsn(int opcode, String owner, String name, String descriptor) {
super.visitFieldInsn(opcode, remapClass(owner), name, updateDescriptor(descriptor));
}
@Override
public void visitMethodInsn(int opcode, String owner, String name, String descriptor, boolean isInterface) {
super.visitMethodInsn(opcode, remapClass(owner), name, updateDescriptor(descriptor), isInterface);
}
@Override
public void visitTypeInsn(int opcode, String type) {
super.visitTypeInsn(opcode, remapClass(type));
}
@Override
public void visitLdcInsn(Object value) {
if (value instanceof String && classNameMap.containsKey(value)) {
value = classNameMap.get(value);
}
super.visitLdcInsn(value);
}
};
}
}, 0);
byte[] transformedBytes = writer.toByteArray();
if (!classCache.containsKey(newName)) {
try {
classCache.put(newName, lookup.defineClass(transformedBytes));
} catch (Throwable e) {
e.printStackTrace();
}
}
return classCache.get(newName);
}
private String remapClass(String className) {
return classNameMap.getOrDefault(className, className);
}
private String updateDescriptor(String descriptor) {
if (descriptor == null) return null;
for (Map.Entry<String, String> entry : classNameMap.entrySet()) {
descriptor = descriptor.replace("L" + entry.getKey() + ";", "L" + entry.getValue() + ";");
}
return descriptor;
}
private String generateRandomName() {
byte[] bytes = new byte[8];
random.nextBytes(bytes);
return Base64.getUrlEncoder().withoutPadding().encodeToString(bytes);
}
}

View File

@ -1,6 +0,0 @@
package opg.p2vman.moduleloader.module;
public class ModuleMeta {
public String main_class;
public String name;
}

View File

@ -1,31 +0,0 @@
package opg.p2vman.moduleloader.module;
import opg.p2vman.moduleloader.api.Identifier;
import opg.p2vman.moduleloader.api.ResourceMannager;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
public class ModuleResourceMannager extends URLClassLoader implements ResourceMannager {
private ModuleContainer container;
public ModuleResourceMannager(ModuleContainer container) throws MalformedURLException {
super(new URL[]{container.module_file.toURI().toURL()});
this.container = container;
}
@Override
public URL getResource(Identifier identifier) {
return getResource(String.format("assets/%s/%s", identifier.getNamespace(), identifier.getPath()));
}
@Override
public InputStream getResourceAsStream(Identifier identifier) {
return getResourceAsStream(String.format("assets/%s/%s", identifier.getNamespace(), identifier.getPath()));
}
@Override
public URL findResource(Identifier identifier) {
return findResource(String.format("assets/%s/%s", identifier.getNamespace(), identifier.getPath()));
}
}

View File

@ -1,53 +0,0 @@
package opg.p2vman.moduleloader.profiling;
import java.util.HashMap;
import java.util.Map;
import java.util.Stack;
public class ExempleProfiler implements Profiler {
private final Map<String, Long> totalTimes = new HashMap<>();
private final Stack<String> stack = new Stack<>();
private final Map<String, Long> startTimes = new HashMap<>();
public void push(String name) {
stack.push(name);
startTimes.put(name, System.nanoTime());
}
public String pop() {
if (stack.isEmpty()) {
throw new IllegalStateException("Нет активных блоков для остановки.");
}
String name = stack.pop();
Long startTime = startTimes.remove(name);
if (startTime == null) {
throw new IllegalStateException("Блок " + name + " не был запущен.");
}
long elapsedTime = System.nanoTime() - startTime;
totalTimes.put(name, totalTimes.getOrDefault(name, 0L) + elapsedTime);
return name;
}
public String peek() {
if (stack.isEmpty()) {
throw new IllegalStateException("Нет активных блоков.");
}
return stack.peek();
}
public long getElapsedTimeAndRemove(String name) {
Long elapsedTime = totalTimes.remove(name);
if (elapsedTime == null) {
throw new IllegalStateException("Блок " + name + " не найден.");
}
return elapsedTime / 1_000_000;
}
public long getElapsedTime(String name) {
Long elapsedTime = totalTimes.get(name);
if (elapsedTime == null) {
throw new IllegalStateException("Блок " + name + " не найден.");
}
return elapsedTime / 1_000_000;
}
}

View File

@ -1,9 +0,0 @@
package opg.p2vman.moduleloader.profiling;
public interface Profiler {
void push(String name);
String pop();
String peek();
long getElapsedTimeAndRemove(String name);
long getElapsedTime(String name);
}

View File

@ -1,4 +0,0 @@
name: ModuleLoader
version: '${version}'
main: opg.p2vman.moduleloader.ModuleLoader
api-version: '1.18'

View File

@ -1,3 +1,5 @@
name: EptaList name: EptaList
version: '${version}' version: '${version}'
main: org.eptalist.bounge.Boungecord main: org.eptalist.bounge.Boungecord
authors:
- p2vman

41
gradlew vendored
View File

@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop. # Darwin, MinGW, and NonStop.
# #
# (3) This script is generated from the Groovy template # (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project. # within the Gradle project.
# #
# You can find Gradle at https://github.com/gradle/gradle/. # You can find Gradle at https://github.com/gradle/gradle/.
@ -80,13 +80,11 @@ do
esac esac
done done
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit # This is normally unused
# shellcheck disable=SC2034
APP_NAME="Gradle"
APP_BASE_NAME=${0##*/} APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value. # Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum MAX_FD=maximum
@ -133,22 +131,29 @@ location of your Java installation."
fi fi
else else
JAVACMD=java JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the Please set the JAVA_HOME variable in your environment to match the
location of your Java installation." location of your Java installation."
fi
fi fi
# Increase the maximum file descriptors if we can. # Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #( case $MAX_FD in #(
max*) max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) || MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit" warn "Could not query maximum file descriptor limit"
esac esac
case $MAX_FD in #( case $MAX_FD in #(
'' | soft) :;; #( '' | soft) :;; #(
*) *)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" || ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD" warn "Could not set maximum file descriptor limit to $MAX_FD"
esac esac
@ -193,11 +198,15 @@ if "$cygwin" || "$msys" ; then
done done
fi fi
# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
# shell script including quotes and variable substitutions, so put them in DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded. # Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.
set -- \ set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \ "-Dorg.gradle.appname=$APP_BASE_NAME" \
@ -205,6 +214,12 @@ set -- \
org.gradle.wrapper.GradleWrapperMain \ org.gradle.wrapper.GradleWrapperMain \
"$@" "$@"
# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi
# Use "xargs" to parse quoted args. # Use "xargs" to parse quoted args.
# #
# With -n1 it outputs one arg per line, with the quotes and backslashes removed. # With -n1 it outputs one arg per line, with the quotes and backslashes removed.

15
gradlew.bat vendored
View File

@ -14,7 +14,7 @@
@rem limitations under the License. @rem limitations under the License.
@rem @rem
@if "%DEBUG%" == "" @echo off @if "%DEBUG%"=="" @echo off
@rem ########################################################################## @rem ##########################################################################
@rem @rem
@rem Gradle startup script for Windows @rem Gradle startup script for Windows
@ -25,7 +25,8 @@
if "%OS%"=="Windows_NT" setlocal if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0 set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=. if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0 set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME% set APP_HOME=%DIRNAME%
@ -40,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1 %JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute if %ERRORLEVEL% equ 0 goto execute
echo. echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
:end :end
@rem End local scope for the variables with windows NT shell @rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd if %ERRORLEVEL% equ 0 goto mainEnd
:fail :fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code! rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 set EXIT_CODE=%ERRORLEVEL%
exit /b 1 if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%
:mainEnd :mainEnd
if "%OS%"=="Windows_NT" endlocal if "%OS%"=="Windows_NT" endlocal

View File

@ -1,5 +1,5 @@
name: EptaList name: EptaList
version: "${version}" version: "${version}"
main: org.eptalist.spigot.EptaList main: org.eptalist.spigot.EptaList
softdepend: authors:
- ModuleLoader - p2vman

View File

@ -30,7 +30,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.logging.Level; import java.util.logging.Level;
@Plugin(id = "eptalist", name = "Eptalist", version = BuildConstants.VERSION) @Plugin(id = "eptalist", name = "Eptalist", version = BuildConstants.VERSION, authors = "p2vman")
public class Velocity { public class Velocity {
private static Metrics metrics; private static Metrics metrics;
public static final Profiler profiler = new ExempleProfiler(); public static final Profiler profiler = new ExempleProfiler();