Setup multi project structure

This commit is contained in:
FlorianMichael 2024-07-21 13:24:06 +02:00
parent 41b9ebab8e
commit 9d48917307
No known key found for this signature in database
GPG Key ID: C2FB87E71C425126
46 changed files with 606 additions and 86 deletions

6
.gitignore vendored
View File

@ -11,6 +11,6 @@ hs_err_pid*
# Project files
/.idea/*
!/.idea/copyright/
/.gradle/
/build/
/out/
.gradle/
build/
out/

View File

@ -1,8 +1,7 @@
# ViaAprilFools
ViaVersion addon to add support for some notable Minecraft snapshots.
ViaAprilFools is not usable by itself as a standalone software, as it is an addon for ViaVersion which adds more protocol translators.
ViaAprilFools is intended to be implemented in a ViaVersion based protocol translator.
ViaAprilFools itself runs on Paper and Velocity servers and can be implemented in any other platform which supports ViaVersion.
If you are looking to implement ViaAprilFools in your own software you can start by reading the [Usage](#usage) section.
If you just want to use ViaAprilFools yourself you can check out some projects which implement it in the [Projects](#projects-implementing-viaaprilfools) section.
@ -19,6 +18,7 @@ If you just want to use ViaAprilFools yourself you can check out some projects w
### Projects implementing ViaAprilFools
- [ViaProxy](https://github.com/ViaVersion/ViaProxy): Standalone proxy which uses ViaVersion to translate between Minecraft versions. Allows Minecraft 1.7+ clients to join to any version server.
- [ViaFabricPlus](https://github.com/ViaVersion/ViaFabricPlus): Fabric mod for the latest Minecraft version with QoL fixes and enhancements to the gameplay.
- [ViaFabric](https://github.com/ViaVersion/ViaFabric): Client-side and server-side ViaVersion implementation for Fabric
## Releases
### Gradle/Maven

7
build-logic/build.gradle Normal file
View File

@ -0,0 +1,7 @@
plugins {
id "groovy-gradle-plugin"
}
repositories {
gradlePluginPortal()
}

View File

@ -0,0 +1,89 @@
plugins {
id "java-library"
id "maven-publish"
id "idea"
}
repositories {
mavenCentral()
maven {
name = "ViaVersion"
url "https://repo.viaversion.com"
}
maven {
name = "SpigotMC"
url "https://hub.spigotmc.org/nexus/content/repositories/snapshots/"
}
maven {
name = "SpongePowered"
url "https://repo.spongepowered.org/repository/maven-public/"
}
maven {
name = "VelocityPowered"
url "https://nexus.velocitypowered.com/repository/maven-public/"
}
}
base {
java.toolchain.languageVersion = JavaLanguageVersion.of(17)
compileJava.options.encoding = compileTestJava.options.encoding = javadoc.options.encoding = "UTF-8"
archivesName = project.name
group = rootProject.maven_group
version = rootProject.maven_version
description = "ViaVersion addon to add support for some notable Minecraft snapshots"
}
dependencies {
compileOnly "com.viaversion:viaversion-common:5.0.0"
compileOnly "com.viaversion:viabackwards-common:5.0.0"
}
publishing {
repositories {
maven {
name = "Via"
url = "https://repo.viaversion.com/"
credentials(PasswordCredentials)
authentication {
basic(BasicAuthentication)
}
}
}
publications {
maven(MavenPublication) {
groupId = project.maven_group
artifactId = project.name
version = project.maven_version
from components.java
pom {
name = "ViaAprilFools"
description = project.description
url = "https://github.com/ViaVersion/ViaAprilFools"
licenses {
license {
name = "GPL-3.0 License"
url = "https://github.com/ViaVersion/ViaAprilFools/blob/main/LICENSE"
}
}
developers {
developer {
id = "RK_01"
}
developer {
id = "FlorianMichael/EnZaXD"
}
}
scm {
connection = "scm:git:git://github.com/ViaVersion/ViaAprilFools.git"
developerConnection = "scm:git:ssh://github.com/ViaVersion/ViaAprilFools.git"
url = "https://github.com/ViaVersion/ViaAprilFools.git"
}
}
}
}
}

View File

@ -0,0 +1,7 @@
plugins {
id "vaf.base-conventions"
}
dependencies {
compileOnly project(":viaaprilfools-common")
}

View File

@ -1,99 +1,50 @@
plugins {
id "java-library"
id "maven-publish"
id "idea"
id "net.raphimc.class-token-replacer" version "1.1.2"
id "vaf.base-conventions"
id "io.papermc.hangar-publish-plugin" version "0.1.2"
id "com.modrinth.minotaur" version "2.+"
}
base {
java.toolchain.languageVersion = JavaLanguageVersion.of(17)
compileJava.options.encoding = compileTestJava.options.encoding = javadoc.options.encoding = "UTF-8"
group = project.maven_group ?: rootProject.maven_group
archivesName = project.maven_name ?: rootProject.maven_name
version = project.maven_version ?: rootProject.maven_version
archivesName = "ViaAprilFools"
}
repositories {
mavenCentral()
maven {
name = "ViaVersion"
url "https://repo.viaversion.com"
}
configurations {
publishInclude
}
dependencies {
compileOnly "com.viaversion:viaversion-common:5.0.0"
compileOnly "com.viaversion:viabackwards-common:5.0.0"
compileOnly "org.yaml:snakeyaml:2.2"
compileOnly "com.google.guava:guava:33.2.1-jre"
compileOnly "io.netty:netty-handler:4.1.111.Final"
}
sourceSets {
main {
classTokenReplacer {
property("\${version}", project.version)
property("\${impl_version}", "git-${project.name}-${project.version}:${project.latestCommitHash()}")
}
}
publishInclude project(":viaaprilfools-common")
publishInclude project(":viaaprilfools-bukkit")
publishInclude project(":viaaprilfools-fabric")
publishInclude project(":viaaprilfools-velocity")
}
java {
withSourcesJar()
withJavadocJar()
}
jar {
dependsOn configurations.publishInclude
from {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
configurations.publishInclude.collect {
zipTree(it)
}
} {
exclude "META-INF/*.RSA", "META-INF/*.SF", "META-INF/*.DSA"
}
manifest {
attributes(
"paperweight-mappings-namespace": "mojang"
)
}
from("LICENSE") {
rename { "${it}_${project.name ?: rootProject.name}" }
}
}
publishing {
repositories {
maven {
name = "Via"
url = "https://repo.viaversion.com/"
credentials(PasswordCredentials)
authentication {
basic(BasicAuthentication)
}
}
}
publications {
maven(MavenPublication) {
groupId = project.maven_group
artifactId = project.maven_name
version = project.maven_version
from components.java
pom {
name = "ViaAprilFools"
description = "ViaVersion addon to add support for some notable Minecraft snapshots"
url = "https://github.com/ViaVersion/ViaAprilFools"
licenses {
license {
name = "GPL-3.0 License"
url = "https://github.com/ViaVersion/ViaAprilFools/blob/main/LICENSE"
}
}
developers {
developer {
id = "RK_01"
}
}
scm {
connection = "scm:git:git://github.com/ViaVersion/ViaAprilFools.git"
developerConnection = "scm:git:ssh://github.com/ViaVersion/ViaAprilFools.git"
url = "https://github.com/ViaVersion/ViaAprilFools.git"
}
}
}
}
}
idea {
module {
["run"].each {
@ -102,11 +53,102 @@ idea {
}
}
String latestCommitHash() {
def stdout = new ByteArrayOutputStream()
// -----------------------------------------------------
// Publishing
def latestCommitHash() {
def byteOut = new ByteArrayOutputStream()
exec {
commandLine "git", "rev-parse", "--short", "HEAD"
standardOutput = stdout
commandLine 'git', 'rev-parse', '--short', 'HEAD'
standardOutput = byteOut
}
return stdout.toString().trim()
return byteOut.toString('UTF-8').trim()
}
def latestCommitMessage() {
def byteOut = new ByteArrayOutputStream()
exec {
commandLine 'git', 'log', '-1', '--pretty=%B'
standardOutput = byteOut
}
return byteOut.toString('UTF-8').trim()
}
def branchName() {
def byteOut = new ByteArrayOutputStream()
exec {
commandLine 'git', 'rev-parse', '--abbrev-ref', 'HEAD'
standardOutput = byteOut
}
return byteOut.toString('UTF-8').trim()
}
def branch = branchName()
def baseVersion = project.maven_version
def isRelease = !baseVersion.contains('-')
if (!isRelease) { // Only publish releases from the main branch
def suffixedVersion = isRelease ? baseVersion : baseVersion + "+" + System.getenv("GITHUB_RUN_NUMBER")
def commitHash = latestCommitHash()
def changelogContent = "[${commitHash}](https://github.com/ViaVersion/ViaAprilFools/commit/${commitHash}) ${latestCommitMessage()}"
modrinth {
def mcVersions = project.mcVersions
.split(',')
.collect { it.trim() }
token.set(System.getenv("MODRINTH_TOKEN"))
projectId.set("viaaprilfools")
versionType.set(isRelease ? "release" : "beta")
versionNumber.set(suffixedVersion)
versionName.set(suffixedVersion)
changelog.set(changelogContent)
uploadFile.set(jar.archiveFile)
gameVersions.set(mcVersions)
loaders.add("fabric")
loaders.add("paper")
loaders.add("folia")
loaders.add("velocity")
autoAddDependsOn.set(false)
detectLoaders.set(false)
dependencies {
required.project("viaversion")
required.project("viabackwards")
optional.project("viafabric")
}
}
hangarPublish {
publications.register("plugin") {
version = suffixedVersion
id = "ViaAprilFools"
channel = isRelease ? "Release" : "Snapshot"
changelog = changelogContent
apiKey = System.getenv("HANGAR_TOKEN")
platforms {
PAPER {
jar = project.jar.archiveFile
platformVersions = [property('mcVersionRange') as String]
dependencies {
hangar("ViaVersion") {
required = true
}
hangar("ViaBackwards") {
required = true
}
}
}
VELOCITY {
jar = project.jar.archiveFile
platformVersions = [property("velocityVersion") as String]
dependencies {
hangar("ViaVersion") {
required = true
}
hangar("ViaBackwards") {
required = true
}
}
}
}
}
}
}

13
bukkit/build.gradle Normal file
View File

@ -0,0 +1,13 @@
plugins {
id "vaf.platform-conventions"
}
dependencies {
compileOnly(annotationProcessor("org.spigotmc:spigot-api:1.12.2-R0.1-SNAPSHOT"))
}
processResources {
filesMatching("plugin.yml") {
expand("version": project.version, "description": project.description)
}
}

View File

@ -0,0 +1,32 @@
/*
* This file is part of ViaAprilFools - https://github.com/RaphiMC/ViaAprilFools
* Copyright (C) 2021-2024 RK_01/RaphiMC and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.raphimc.viaaprilfools;
import com.viaversion.viaversion.api.Via;
import net.raphimc.viaaprilfools.platform.ViaAprilFoolsPlatform;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
public class BukkitPlugin extends JavaPlugin implements ViaAprilFoolsPlatform {
public BukkitPlugin() {
Via.getManager().addEnableListener(() -> this.init(new File(getDataFolder(), "config.yml")));
}
}

View File

@ -0,0 +1,10 @@
name: ViaAprilFools
main: net.raphimc.viaaprilfools.BukkitPlugin
authors: [RK_01, FlorianMichael/EnZaXD]
version: ${version}
description: ${description}
website: https://viaversion.com/aprilfools
api-version: 1.13
folia-supported: true
load: STARTUP
depend: [ViaVersion, ViaBackwards]

29
common/build.gradle Normal file
View File

@ -0,0 +1,29 @@
plugins {
id "vaf.base-conventions"
id "net.raphimc.class-token-replacer" version "1.1.2"
}
dependencies {
compileOnly "org.yaml:snakeyaml:2.2"
compileOnly "com.google.guava:guava:33.2.1-jre"
compileOnly "io.netty:netty-handler:4.1.111.Final"
}
sourceSets {
main {
classTokenReplacer {
property("\${version}", project.version)
property("\${impl_version}", "git-${rootProject.name}-${project.version}:${project.latestCommitHash()}")
}
}
}
String latestCommitHash() {
def stdout = new ByteArrayOutputStream()
exec {
commandLine "git", "rev-parse", "--short", "HEAD"
standardOutput = stdout
}
return stdout.toString().trim()
}

14
fabric/build.gradle Normal file
View File

@ -0,0 +1,14 @@
plugins {
id "vaf.platform-conventions"
}
dependencies {
compileOnly(annotationProcessor("net.fabricmc:fabric-loader:0.11.3"))
compileOnly(annotationProcessor("org.apache.logging.log4j:log4j-api:2.17.1"))
}
processResources {
filesMatching("fabric.mod.json") {
expand("version": project.version, "description": project.description)
}
}

View File

@ -0,0 +1,51 @@
/*
* This file is part of ViaAprilFools - https://github.com/RaphiMC/ViaAprilFools
* Copyright (C) 2021-2024 RK_01/RaphiMC and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.raphimc.viaaprilfools;
import net.fabricmc.loader.api.FabricLoader;
import net.raphimc.viaaprilfools.fabric.util.LoggerWrapper;
import net.raphimc.viaaprilfools.platform.ViaAprilFoolsPlatform;
import org.apache.logging.log4j.LogManager;
import java.io.File;
import java.nio.file.Path;
import java.util.logging.Logger;
public class ViaFabricAddon implements ViaAprilFoolsPlatform, Runnable {
private final Logger logger = new LoggerWrapper(LogManager.getLogger("ViaRewind"));
private File configDir;
@Override
public void run() {
final Path configDirPath = FabricLoader.getInstance().getConfigDir().resolve("ViaAprilFools");
this.configDir = configDirPath.toFile();
this.init(new File(getDataFolder(), "config.yml"));
}
@Override
public File getDataFolder() {
return this.configDir;
}
@Override
public Logger getLogger() {
return this.logger;
}
}

View File

@ -0,0 +1,91 @@
/*
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
* Copyright (C) 2018-2024 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.raphimc.viaaprilfools.fabric.util;
import java.text.MessageFormat;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
public class LoggerWrapper extends Logger {
private final org.apache.logging.log4j.Logger base;
public LoggerWrapper(org.apache.logging.log4j.Logger logger) {
super("logger", null);
this.base = logger;
}
@Override
public void log(LogRecord record) {
this.log(record.getLevel(), record.getMessage());
}
@Override
public void log(Level level, String msg) {
if (level == Level.FINE) {
this.base.debug(msg);
} else if (level == Level.WARNING) {
this.base.warn(msg);
} else if (level == Level.SEVERE) {
this.base.error(msg);
} else if (level == Level.INFO) {
this.base.info(msg);
} else {
this.base.trace(msg);
}
}
@Override
public void log(Level level, String msg, Object param1) {
if (level == Level.FINE) {
this.base.debug(msg, param1);
} else if (level == Level.WARNING) {
this.base.warn(msg, param1);
} else if (level == Level.SEVERE) {
this.base.error(msg, param1);
} else if (level == Level.INFO) {
this.base.info(msg, param1);
} else {
this.base.trace(msg, param1);
}
}
@Override
public void log(Level level, String msg, Object[] params) {
log(level, MessageFormat.format(msg, params));
}
@Override
public void log(Level level, String msg, Throwable params) {
if (level == Level.FINE) {
this.base.debug(msg, params);
} else if (level == Level.WARNING) {
this.base.warn(msg, params);
} else if (level == Level.SEVERE) {
this.base.error(msg, params);
} else if (level == Level.INFO) {
this.base.info(msg, params);
} else {
this.base.trace(msg, params);
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

View File

@ -0,0 +1,36 @@
{
"schemaVersion": 1,
"id": "viaaprilfools",
"name": "ViaAprilFools",
"version": "${version}",
"description": "${description}",
"license": "GPL-3.0",
"contact": {
"homepage": "https://viaversion.com/aprilfools",
"issues": "https://github.com/ViaVersion/ViaAprilFools/issues",
"sources": "https://github.com/ViaVersion/ViaAprilFools"
},
"icon": "assets/viaaprilfools/textures/icon.png",
"environment": "*",
"authors": [
"RK_01",
"FlorianMichael/EnZaXD"
],
"entrypoints": {
"viafabric:via_api_initialized": [
"net.raphimc.viaaprilfools.ViaFabricAddon"
]
},
"depends": {
"fabricloader": ">=0.14.0",
"viafabric": ">=0.4.10",
"viabackwards": ">=5.0.0"
},
"custom": {
"modmenu:api": true,
"modmenu": {
"badges": [ "library" ],
"parent": "viafabric"
}
}
}

View File

@ -5,3 +5,8 @@ org.gradle.configureondemand=true
maven_group=net.raphimc
maven_name=ViaAprilFools
maven_version=3.0.1-SNAPSHOT
# Smile emoji
mcVersions=1.21, 1.20.6, 1.20.5, 1.20.4, 1.20.3, 1.20.2, 1.20.1, 1.20, 1.19.4, 1.19.3, 1.19.2, 1.19.1, 1.19, 1.18.2, 1.18.1, 1.18, 1.17.1, 1.17, 1.16.5, 1.16.4, 1.16.3, 1.16.2, 1.16.1, 1.16, 1.15.2, 1.15.1, 1.15, 1.14.4, 1.14.3, 1.14.2, 1.14.1, 1.14, 1.13.2, 1.13.1, 1.13, 1.12.2, 1.12.1, 1.12, 1.11.2, 1.11.1, 1.11, 1.10.2, 1.10.1, 1.10, 1.9.4, 1.9.3, 1.9.2, 1.9.1, 1.9, 1.8.9, 1.8.8
mcVersionRange=1.8-1.21
velocityVersion=3.3

View File

@ -9,4 +9,18 @@ plugins {
id "org.gradle.toolchains.foojay-resolver-convention" version "0.8.0"
}
rootProject.name = "ViaAprilFools"
rootProject.name = "viaaprilfools"
includeBuild("build-logic")
setupViaSubproject("common")
setupViaSubproject("bukkit")
setupViaSubproject("fabric")
setupViaSubproject("velocity")
void setupViaSubproject(String name) {
var pName = "viaaprilfools-" + name
include pName
project(":" + pName).projectDir = file(name)
}

8
velocity/build.gradle Normal file
View File

@ -0,0 +1,8 @@
plugins {
id "vaf.platform-conventions"
}
dependencies {
compileOnly("com.viaversion:viaversion-velocity:5.0.0") // Needed for logger wrapper
compileOnly(annotationProcessor("com.velocitypowered:velocity-api:3.1.1"))
}

View File

@ -0,0 +1,72 @@
/*
* This file is part of ViaAprilFools - https://github.com/RaphiMC/ViaAprilFools
* Copyright (C) 2021-2024 RK_01/RaphiMC and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.raphimc.viaaprilfools;
import com.google.inject.Inject;
import com.velocitypowered.api.event.PostOrder;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
import com.velocitypowered.api.plugin.Dependency;
import com.velocitypowered.api.plugin.Plugin;
import com.velocitypowered.api.plugin.annotation.DataDirectory;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.velocity.util.LoggerWrapper;
import net.raphimc.viaaprilfools.platform.ViaAprilFoolsPlatform;
import java.io.File;
import java.nio.file.Path;
import java.util.logging.Logger;
@Plugin(id = "viaaprilfools",
name = "ViaAprilFools",
version = ViaAprilFools.VERSION,
authors = {"RK_01", "FlorianMichael/EnZaXD"},
description = "ViaVersion addon to add support for some notable Minecraft snapshots",
dependencies = {
@Dependency(id = "viaversion"),
@Dependency(id = "viabackwards")
},
url = "https://viaversion.com/aprilfools"
)
public class VelocityPlugin implements ViaAprilFoolsPlatform {
private Logger logger;
@Inject
private org.slf4j.Logger loggerSlf4j;
@Inject
@DataDirectory
private Path configPath;
@Subscribe(order = PostOrder.LATE)
public void onProxyStart(ProxyInitializeEvent e) {
this.logger = new LoggerWrapper(loggerSlf4j);
Via.getManager().addEnableListener(() -> this.init(new File(getDataFolder(), "config.yml")));
}
@Override
public File getDataFolder() {
return configPath.toFile();
}
@Override
public Logger getLogger() {
return this.logger;
}
}