Fill ViaVersion platform dump data

This commit is contained in:
RaphiMC 2023-10-09 12:39:56 +02:00
parent 0197c6098c
commit 4353ebfa7f
No known key found for this signature in database
GPG Key ID: 0F6BB0657A03AC94
4 changed files with 62 additions and 1 deletions

View File

@ -122,6 +122,7 @@ sourceSets {
main {
classTokenReplacer {
property("\${version}", project.version)
property("\${impl_version}", "git-${project.name}-${project.version}:${project.latestCommitHash()}")
}
}
}
@ -210,3 +211,12 @@ tasks.register("java8Jar", DowngradeJarTask) {
copyRuntimeClasses = false
}.get().dependsOn("build")
build.finalizedBy("java8Jar")
String latestCommitHash() {
def stdout = new ByteArrayOutputStream()
exec {
commandLine "git", "rev-parse", "--short", "HEAD"
standardOutput = stdout
}
return stdout.toString().trim()
}

View File

@ -59,6 +59,7 @@ import java.lang.instrument.Instrumentation;
public class ViaProxy {
public static final String VERSION = "${version}";
public static final String IMPL_VERSION = "${impl_version}";
private static Instrumentation instrumentation;
public static SaveManager saveManager;

View File

@ -24,6 +24,7 @@ import net.raphimc.vialoader.impl.platform.ViaBedrockPlatformImpl;
import net.raphimc.vialoader.impl.platform.ViaRewindPlatformImpl;
import net.raphimc.viaproxy.plugins.PluginManager;
import net.raphimc.viaproxy.plugins.events.ProtocolHackInitEvent;
import net.raphimc.viaproxy.protocolhack.impl.ViaProxyVLInjector;
import net.raphimc.viaproxy.protocolhack.impl.ViaProxyVLLoader;
import net.raphimc.viaproxy.protocolhack.impl.ViaProxyViaLegacyPlatformImpl;
import net.raphimc.viaproxy.protocolhack.impl.ViaProxyViaVersionPlatformImpl;
@ -38,7 +39,7 @@ public class ProtocolHack {
public static void init() {
patchConfigs();
final Supplier<?>[] platformSuppliers = PluginManager.EVENT_MANAGER.call(new ProtocolHackInitEvent(ViaBackwardsPlatformImpl::new, ViaRewindPlatformImpl::new, ViaProxyViaLegacyPlatformImpl::new, ViaAprilFoolsPlatformImpl::new, ViaBedrockPlatformImpl::new)).getPlatformSuppliers().toArray(new Supplier[0]);
ViaLoader.init(new ViaProxyViaVersionPlatformImpl(), new ViaProxyVLLoader(), null, null, platformSuppliers);
ViaLoader.init(new ViaProxyViaVersionPlatformImpl(), new ViaProxyVLLoader(), new ViaProxyVLInjector(), null, platformSuppliers);
}
private static void patchConfigs() {

View File

@ -0,0 +1,49 @@
/*
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
* Copyright (C) 2023 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.viaproxy.protocolhack.impl;
import com.viaversion.viaversion.libs.gson.JsonArray;
import com.viaversion.viaversion.libs.gson.JsonObject;
import net.raphimc.vialoader.impl.viaversion.VLInjector;
import net.raphimc.viaproxy.ViaProxy;
import net.raphimc.viaproxy.plugins.PluginManager;
import net.raphimc.viaproxy.plugins.ViaProxyPlugin;
public class ViaProxyVLInjector extends VLInjector {
@Override
public JsonObject getDump() {
final JsonObject root = new JsonObject();
root.addProperty("version", ViaProxy.VERSION);
root.addProperty("impl_version", ViaProxy.IMPL_VERSION);
final JsonArray plugins = new JsonArray();
for (ViaProxyPlugin plugin : PluginManager.getPlugins()) {
final JsonObject pluginObj = new JsonObject();
pluginObj.addProperty("name", plugin.getName());
pluginObj.addProperty("version", plugin.getVersion());
pluginObj.addProperty("author", plugin.getAuthor());
plugins.add(pluginObj);
}
root.add("plugins", plugins);
return root;
}
}