diff --git a/ModuleLoader.zip b/ModuleLoader.zip new file mode 100644 index 0000000..e0928d4 Binary files /dev/null and b/ModuleLoader.zip differ diff --git a/ModuleLoader/Exemplemodule/build.gradle b/ModuleLoader/Exemplemodule/build.gradle deleted file mode 100644 index c454989..0000000 --- a/ModuleLoader/Exemplemodule/build.gradle +++ /dev/null @@ -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 { - -} diff --git a/ModuleLoader/Exemplemodule/settings.gradle b/ModuleLoader/Exemplemodule/settings.gradle deleted file mode 100644 index fc44232..0000000 --- a/ModuleLoader/Exemplemodule/settings.gradle +++ /dev/null @@ -1 +0,0 @@ -rootProject.name = 'Exemplemodule' \ No newline at end of file diff --git a/ModuleLoader/Exemplemodule/src/main/java/org/example/ExempleClass.java b/ModuleLoader/Exemplemodule/src/main/java/org/example/ExempleClass.java deleted file mode 100644 index e987a49..0000000 --- a/ModuleLoader/Exemplemodule/src/main/java/org/example/ExempleClass.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.example; - -public class ExempleClass { - public static void test() { - System.out.println("Local class get"); - } -} diff --git a/ModuleLoader/Exemplemodule/src/main/java/org/example/ExempleModule.java b/ModuleLoader/Exemplemodule/src/main/java/org/example/ExempleModule.java deleted file mode 100644 index 391c697..0000000 --- a/ModuleLoader/Exemplemodule/src/main/java/org/example/ExempleModule.java +++ /dev/null @@ -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")); - } -} diff --git a/ModuleLoader/Exemplemodule/src/main/resources/module.json b/ModuleLoader/Exemplemodule/src/main/resources/module.json deleted file mode 100644 index 04793d5..0000000 --- a/ModuleLoader/Exemplemodule/src/main/resources/module.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "main_class": "org.example.ExempleModule", - "name": "ExempleModule" -} \ No newline at end of file diff --git a/ModuleLoader/build.gradle b/ModuleLoader/build.gradle deleted file mode 100644 index 2f94c56..0000000 --- a/ModuleLoader/build.gradle +++ /dev/null @@ -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 - } -} diff --git a/ModuleLoader/gradle.properties b/ModuleLoader/gradle.properties deleted file mode 100644 index e69de29..0000000 diff --git a/ModuleLoader/gradle/wrapper/gradle-wrapper.jar b/ModuleLoader/gradle/wrapper/gradle-wrapper.jar deleted file mode 100644 index e644113..0000000 Binary files a/ModuleLoader/gradle/wrapper/gradle-wrapper.jar and /dev/null differ diff --git a/ModuleLoader/gradle/wrapper/gradle-wrapper.properties b/ModuleLoader/gradle/wrapper/gradle-wrapper.properties deleted file mode 100644 index b82aa23..0000000 --- a/ModuleLoader/gradle/wrapper/gradle-wrapper.properties +++ /dev/null @@ -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 diff --git a/ModuleLoader/settings.gradle b/ModuleLoader/settings.gradle deleted file mode 100644 index 423d429..0000000 --- a/ModuleLoader/settings.gradle +++ /dev/null @@ -1 +0,0 @@ -rootProject.name = 'ModuleLoader' \ No newline at end of file diff --git a/ModuleLoader/src/main/java/m/dict/Lock.java b/ModuleLoader/src/main/java/m/dict/Lock.java deleted file mode 100644 index ec59d1c..0000000 --- a/ModuleLoader/src/main/java/m/dict/Lock.java +++ /dev/null @@ -1,4 +0,0 @@ -package m.dict; - -public interface Lock { -} diff --git a/ModuleLoader/src/main/java/opg/p2vman/moduleloader/ModuleLoader.java b/ModuleLoader/src/main/java/opg/p2vman/moduleloader/ModuleLoader.java deleted file mode 100644 index 3ea561b..0000000 --- a/ModuleLoader/src/main/java/opg/p2vman/moduleloader/ModuleLoader.java +++ /dev/null @@ -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 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 getModuleLoader() { - return loader; - } -} diff --git a/ModuleLoader/src/main/java/opg/p2vman/moduleloader/api/Identifier.java b/ModuleLoader/src/main/java/opg/p2vman/moduleloader/api/Identifier.java deleted file mode 100644 index a4d3ba0..0000000 --- a/ModuleLoader/src/main/java/opg/p2vman/moduleloader/api/Identifier.java +++ /dev/null @@ -1,156 +0,0 @@ -package opg.p2vman.moduleloader.api; - -public class Identifier implements Comparable { - 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; - } - } -} \ No newline at end of file diff --git a/ModuleLoader/src/main/java/opg/p2vman/moduleloader/api/Module.java b/ModuleLoader/src/main/java/opg/p2vman/moduleloader/api/Module.java deleted file mode 100644 index d568e18..0000000 --- a/ModuleLoader/src/main/java/opg/p2vman/moduleloader/api/Module.java +++ /dev/null @@ -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(); -} diff --git a/ModuleLoader/src/main/java/opg/p2vman/moduleloader/api/RemapedClass.java b/ModuleLoader/src/main/java/opg/p2vman/moduleloader/api/RemapedClass.java deleted file mode 100644 index 5238c85..0000000 --- a/ModuleLoader/src/main/java/opg/p2vman/moduleloader/api/RemapedClass.java +++ /dev/null @@ -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(); -} diff --git a/ModuleLoader/src/main/java/opg/p2vman/moduleloader/api/ResourceMannager.java b/ModuleLoader/src/main/java/opg/p2vman/moduleloader/api/ResourceMannager.java deleted file mode 100644 index f3e5873..0000000 --- a/ModuleLoader/src/main/java/opg/p2vman/moduleloader/api/ResourceMannager.java +++ /dev/null @@ -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); -} diff --git a/ModuleLoader/src/main/java/opg/p2vman/moduleloader/api/ServicesManager.java b/ModuleLoader/src/main/java/opg/p2vman/moduleloader/api/ServicesManager.java deleted file mode 100644 index 4061f04..0000000 --- a/ModuleLoader/src/main/java/opg/p2vman/moduleloader/api/ServicesManager.java +++ /dev/null @@ -1,21 +0,0 @@ -package opg.p2vman.moduleloader.api; - -import java.util.HashMap; -import java.util.Map; - -public class ServicesManager { - - private final Map, Object> services = new HashMap<>(); - - public void registerService(Class serviceClass, T serviceInstance) { - services.put(serviceClass, serviceInstance); - } - - public T getService(Class serviceClass) { - return (T) services.get(serviceClass); - } - - public boolean hasService(Class serviceClass) { - return services.containsKey(serviceClass); - } -} diff --git a/ModuleLoader/src/main/java/opg/p2vman/moduleloader/module/JavaModule.java b/ModuleLoader/src/main/java/opg/p2vman/moduleloader/module/JavaModule.java deleted file mode 100644 index b19d5d9..0000000 --- a/ModuleLoader/src/main/java/opg/p2vman/moduleloader/module/JavaModule.java +++ /dev/null @@ -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 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 getModule(Class 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); - } -} diff --git a/ModuleLoader/src/main/java/opg/p2vman/moduleloader/module/ModuleContainer.java b/ModuleLoader/src/main/java/opg/p2vman/moduleloader/module/ModuleContainer.java deleted file mode 100644 index e2f0cf3..0000000 --- a/ModuleLoader/src/main/java/opg/p2vman/moduleloader/module/ModuleContainer.java +++ /dev/null @@ -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; - } -} diff --git a/ModuleLoader/src/main/java/opg/p2vman/moduleloader/module/ModuleLogger.java b/ModuleLoader/src/main/java/opg/p2vman/moduleloader/module/ModuleLogger.java deleted file mode 100644 index 8d43fcc..0000000 --- a/ModuleLoader/src/main/java/opg/p2vman/moduleloader/module/ModuleLogger.java +++ /dev/null @@ -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); - } -} \ No newline at end of file diff --git a/ModuleLoader/src/main/java/opg/p2vman/moduleloader/module/ModuleMannager.java b/ModuleLoader/src/main/java/opg/p2vman/moduleloader/module/ModuleMannager.java deleted file mode 100644 index 30859a0..0000000 --- a/ModuleLoader/src/main/java/opg/p2vman/moduleloader/module/ModuleMannager.java +++ /dev/null @@ -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 classNameMap = new HashMap<>(); - - public ModuleMannager() throws IllegalAccessException { - lookup = MethodHandles.privateLookupIn(Lock.class, MethodHandles.lookup()); - GSON = new Gson(); - } - - public List loadModules(File dir) { - List 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 loadModule(File plugin) { - synchronized (lookup) { - classNameMap.clear(); - List> classes = new ArrayList<>(); - Optional module = Optional.empty(); - - try (JarFile jarFile = new JarFile(plugin)) { - Enumeration 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> 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 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); - } -} diff --git a/ModuleLoader/src/main/java/opg/p2vman/moduleloader/module/ModuleMeta.java b/ModuleLoader/src/main/java/opg/p2vman/moduleloader/module/ModuleMeta.java deleted file mode 100644 index be4e16b..0000000 --- a/ModuleLoader/src/main/java/opg/p2vman/moduleloader/module/ModuleMeta.java +++ /dev/null @@ -1,6 +0,0 @@ -package opg.p2vman.moduleloader.module; - -public class ModuleMeta { - public String main_class; - public String name; -} diff --git a/ModuleLoader/src/main/java/opg/p2vman/moduleloader/module/ModuleResourceMannager.java b/ModuleLoader/src/main/java/opg/p2vman/moduleloader/module/ModuleResourceMannager.java deleted file mode 100644 index 68f4984..0000000 --- a/ModuleLoader/src/main/java/opg/p2vman/moduleloader/module/ModuleResourceMannager.java +++ /dev/null @@ -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())); - } -} diff --git a/ModuleLoader/src/main/java/opg/p2vman/moduleloader/profiling/ExempleProfiler.java b/ModuleLoader/src/main/java/opg/p2vman/moduleloader/profiling/ExempleProfiler.java deleted file mode 100644 index 3d03c9d..0000000 --- a/ModuleLoader/src/main/java/opg/p2vman/moduleloader/profiling/ExempleProfiler.java +++ /dev/null @@ -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 totalTimes = new HashMap<>(); - private final Stack stack = new Stack<>(); - private final Map 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; - } -} \ No newline at end of file diff --git a/ModuleLoader/src/main/java/opg/p2vman/moduleloader/profiling/Profiler.java b/ModuleLoader/src/main/java/opg/p2vman/moduleloader/profiling/Profiler.java deleted file mode 100644 index d9dd5af..0000000 --- a/ModuleLoader/src/main/java/opg/p2vman/moduleloader/profiling/Profiler.java +++ /dev/null @@ -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); -} \ No newline at end of file diff --git a/ModuleLoader/src/main/resources/plugin.yml b/ModuleLoader/src/main/resources/plugin.yml deleted file mode 100644 index 70cb320..0000000 --- a/ModuleLoader/src/main/resources/plugin.yml +++ /dev/null @@ -1,4 +0,0 @@ -name: ModuleLoader -version: '${version}' -main: opg.p2vman.moduleloader.ModuleLoader -api-version: '1.18' diff --git a/boungecord/src/main/resources/bungee.yml b/boungecord/src/main/resources/bungee.yml index 28a1161..dc14aa7 100644 --- a/boungecord/src/main/resources/bungee.yml +++ b/boungecord/src/main/resources/bungee.yml @@ -1,3 +1,5 @@ name: EptaList version: '${version}' -main: org.eptalist.bounge.Boungecord \ No newline at end of file +main: org.eptalist.bounge.Boungecord +authors: + - p2vman \ No newline at end of file diff --git a/gradlew b/gradlew index 1b6c787..1aa94a4 100644 --- a/gradlew +++ b/gradlew @@ -55,7 +55,7 @@ # Darwin, MinGW, and NonStop. # # (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. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -80,13 +80,11 @@ do esac done -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -APP_NAME="Gradle" +# This is normally unused +# shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -133,22 +131,29 @@ location of your Java installation." fi else 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 location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( 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 ) || warn "Could not query maximum file descriptor limit" esac case $MAX_FD in #( '' | 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" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -193,11 +198,15 @@ if "$cygwin" || "$msys" ; then done fi -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# 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 -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ @@ -205,6 +214,12 @@ set -- \ 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. # # With -n1 it outputs one arg per line, with the quotes and backslashes removed. diff --git a/gradlew.bat b/gradlew.bat index 107acd3..93e3f59 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -14,7 +14,7 @@ @rem limitations under the License. @rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,7 +25,8 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -40,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute +if %ERRORLEVEL% equ 0 goto execute echo. 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 @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/spigot/src/main/resources/plugin.yml b/spigot/src/main/resources/plugin.yml index 0bfaa65..3a49770 100644 --- a/spigot/src/main/resources/plugin.yml +++ b/spigot/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: EptaList version: "${version}" main: org.eptalist.spigot.EptaList -softdepend: - - ModuleLoader \ No newline at end of file +authors: + - p2vman \ No newline at end of file diff --git a/velocity/src/main/java/org/eptalist/velocity/Velocity.java b/velocity/src/main/java/org/eptalist/velocity/Velocity.java index c467206..ea0f215 100644 --- a/velocity/src/main/java/org/eptalist/velocity/Velocity.java +++ b/velocity/src/main/java/org/eptalist/velocity/Velocity.java @@ -30,7 +30,7 @@ import java.util.List; import java.util.Map; 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 { private static Metrics metrics; public static final Profiler profiler = new ExempleProfiler();