Initial work on reflection, pulls version from resources.
This commit is contained in:
parent
e64b563190
commit
56f337110f
11 changed files with 161 additions and 58 deletions
55
build.gradle
55
build.gradle
|
|
@ -1,55 +0,0 @@
|
||||||
plugins {
|
|
||||||
id 'java'
|
|
||||||
id("xyz.jpenilla.run-paper") version "2.3.1"
|
|
||||||
}
|
|
||||||
|
|
||||||
group = 'io.github.adrianvic'
|
|
||||||
version = '1.0.2-SNAPSHOT'
|
|
||||||
|
|
||||||
repositories {
|
|
||||||
mavenCentral()
|
|
||||||
maven {
|
|
||||||
name = "papermc-repo"
|
|
||||||
url = "https://repo.papermc.io/repository/maven-public/"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
compileOnly("io.papermc.paper:paper-api:1.21.10-R0.1-SNAPSHOT")
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks {
|
|
||||||
runServer {
|
|
||||||
// Configure the Minecraft version for our task.
|
|
||||||
// This is the only required configuration besides applying the plugin.
|
|
||||||
// Your plugin's jar (or shadowJar if present) will be used automatically.
|
|
||||||
minecraftVersion("1.21")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def targetJavaVersion = 21
|
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
93
build.gradle.kts
Normal file
93
build.gradle.kts
Normal file
|
|
@ -0,0 +1,93 @@
|
||||||
|
plugins {
|
||||||
|
java
|
||||||
|
id("xyz.jpenilla.run-paper") version "2.3.1"
|
||||||
|
}
|
||||||
|
|
||||||
|
group = "io.github.adrianvic"
|
||||||
|
version = "1.0.2-SNAPSHOT"
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
maven("https://repo.papermc.io/repository/maven-public/")
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ----------------------------------------- */
|
||||||
|
/* SUPPORTED VERSIONS */
|
||||||
|
/* ----------------------------------------- */
|
||||||
|
|
||||||
|
val mcVersions = listOf(
|
||||||
|
"b1_7_3",
|
||||||
|
"r1_21"
|
||||||
|
)
|
||||||
|
|
||||||
|
/* ----------------------------------------- */
|
||||||
|
/* CREATE SOURCE SET PER VERSION */
|
||||||
|
/* ----------------------------------------- */
|
||||||
|
|
||||||
|
mcVersions.forEach { ver ->
|
||||||
|
val ss = sourceSets.create(ver) {
|
||||||
|
java.srcDir("src/$ver/java")
|
||||||
|
|
||||||
|
resources.setSrcDirs(listOf("src/$ver/resources", "src/main/resources"))
|
||||||
|
|
||||||
|
compileClasspath += sourceSets["main"].output
|
||||||
|
runtimeClasspath += output + compileClasspath
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.withType<ProcessResources> {
|
||||||
|
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
||||||
|
}
|
||||||
|
|
||||||
|
configurations[ss.implementationConfigurationName]
|
||||||
|
.extendsFrom(configurations["implementation"])
|
||||||
|
|
||||||
|
configurations[ss.compileOnlyConfigurationName]
|
||||||
|
.extendsFrom(configurations["compileOnly"])
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ----------------------------------------- */
|
||||||
|
/* DEPENDENCIES */
|
||||||
|
/* ----------------------------------------- */
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
add("compileOnly", "io.papermc.paper:paper-api:1.21.10-R0.1-SNAPSHOT")
|
||||||
|
add("r1_21CompileOnly", "io.papermc.paper:paper-api:1.21.10-R0.1-SNAPSHOT")
|
||||||
|
add("b1_7_3CompileOnly", files("libs/beta173-api.jar"))
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ----------------------------------------- */
|
||||||
|
/* BUILD TASKS */
|
||||||
|
/* ----------------------------------------- */
|
||||||
|
|
||||||
|
mcVersions.forEach { ver ->
|
||||||
|
tasks.register<Jar>("jar${ver.replace(".", "_").replace("-", "_").replace("/", "_").capitalize()}") {
|
||||||
|
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
||||||
|
from(sourceSets["main"].output)
|
||||||
|
from(sourceSets[ver].output)
|
||||||
|
archiveClassifier.set(ver)
|
||||||
|
|
||||||
|
manifest {
|
||||||
|
attributes(
|
||||||
|
"Nemesis-Impl-Version" to ver
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ----------------------------------------- */
|
||||||
|
/* JAVA SETTINGS */
|
||||||
|
/* ----------------------------------------- */
|
||||||
|
|
||||||
|
java {
|
||||||
|
toolchain.languageVersion.set(JavaLanguageVersion.of(21))
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.withType<JavaCompile> {
|
||||||
|
options.encoding = "UTF-8"
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.runServer {
|
||||||
|
minecraftVersion("1.21")
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
package io.github.adrianvic.nemesiseye.impl;
|
||||||
|
|
||||||
|
import io.github.adrianvic.nemesiseye.reflection.Glimmer;
|
||||||
|
|
||||||
|
public class b1_7_3 implements Glimmer {
|
||||||
|
}
|
||||||
5
src/b1_7_3/resources/plugin.yml
Normal file
5
src/b1_7_3/resources/plugin.yml
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
name: "Eye-of-Nemesis"
|
||||||
|
version: '1.0.2-SNAPSHOT'
|
||||||
|
main: io.github.adrianvic.nemesiseye.Nemesis
|
||||||
|
author: 'Adrian Victor'
|
||||||
|
description: "Change what players can do based in custom criteria."
|
||||||
1
src/b1_7_3/resources/version.properties
Normal file
1
src/b1_7_3/resources/version.properties
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
impl.version=b1_7_3
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package io.github.adrianvic.nemesiseye;
|
package io.github.adrianvic.nemesiseye;
|
||||||
|
|
||||||
import io.github.adrianvic.nemesiseye.policy.Policy;
|
import io.github.adrianvic.nemesiseye.policy.Policy;
|
||||||
import io.github.adrianvic.nemesiseye.policy.PolicyParser;
|
|
||||||
import io.github.adrianvic.nemesiseye.policy.PolicyParsers;
|
import io.github.adrianvic.nemesiseye.policy.PolicyParsers;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,67 @@
|
||||||
package io.github.adrianvic.nemesiseye;
|
package io.github.adrianvic.nemesiseye;
|
||||||
|
|
||||||
import io.github.adrianvic.nemesiseye.commands.Eye;
|
import io.github.adrianvic.nemesiseye.commands.Eye;
|
||||||
|
import io.github.adrianvic.nemesiseye.reflection.Glimmer;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
public final class Nemesis extends JavaPlugin {
|
public final class Nemesis extends JavaPlugin {
|
||||||
|
private Glimmer glim;
|
||||||
|
private static final String VERSION_PROP = "impl.version";
|
||||||
|
private static Nemesis instance;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
|
instance = this;
|
||||||
|
glim = loadGlim();
|
||||||
getServer().getPluginManager().registerEvents(new EventListener(), this);
|
getServer().getPluginManager().registerEvents(new EventListener(), this);
|
||||||
Config.getInstance().load();
|
Config.getInstance().load();
|
||||||
getCommand("eye").setExecutor(new Eye());
|
getCommand("eye").setExecutor(new Eye());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String readImplVersion() {
|
||||||
|
Properties props = new Properties();
|
||||||
|
try (InputStream is = getClass().getClassLoader()
|
||||||
|
.getResourceAsStream("version.properties")) {
|
||||||
|
if (is == null) {
|
||||||
|
throw new IllegalStateException("version.properties not found on classpath.");
|
||||||
|
}
|
||||||
|
props.load(is);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new IllegalStateException("Failed to load version.properties", e);
|
||||||
|
}
|
||||||
|
String version = props.getProperty(VERSION_PROP);
|
||||||
|
if (version == null || version.isBlank()) {
|
||||||
|
throw new IllegalStateException(VERSION_PROP + " property missing in version.properties.");
|
||||||
|
}
|
||||||
|
return version.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Glimmer loadGlim() {
|
||||||
|
String implVersion = readImplVersion();
|
||||||
|
String className = "io.github.adrianvic.nemesiseye.impl." + implVersion;
|
||||||
|
|
||||||
|
try {
|
||||||
|
Class<?> clazz = Class.forName(className, true, getClass().getClassLoader());
|
||||||
|
if (!Glimmer.class.isAssignableFrom(clazz)) {
|
||||||
|
throw new IllegalStateException(className + " does not implement Glimmer.");
|
||||||
|
}
|
||||||
|
return (Glimmer) clazz.getDeclaredConstructor().newInstance();
|
||||||
|
} catch (ReflectiveOperationException e) {
|
||||||
|
throw new IllegalStateException("Failed to instantiate " + className, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
// Plugin shutdown logic
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Nemesis getInstance() {
|
public static Nemesis getInstance() {
|
||||||
return getPlugin(Nemesis.class);
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Glimmer getGlimmer() { return glim; }
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
package io.github.adrianvic.nemesiseye.reflection;
|
||||||
|
|
||||||
|
public interface Glimmer {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
package io.github.adrianvic.nemesiseye.impl;
|
||||||
|
|
||||||
|
public class r1_21 {
|
||||||
|
}
|
||||||
1
src/r1_21/resources/version.properties
Normal file
1
src/r1_21/resources/version.properties
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
impl.version=r1_21
|
||||||
Loading…
Add table
Add a link
Reference in a new issue