Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

Commit

Permalink
Mohist libraries offline mode #3311
Browse files Browse the repository at this point in the history
  • Loading branch information
Mgazul committed Aug 20, 2024
1 parent 304473b commit 615db15
Show file tree
Hide file tree
Showing 16 changed files with 386 additions and 33 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

[![](https://img.shields.io/jenkins/build?jobUrl=https%3A%2F%2Fci.codemc.io%2Fjob%2FMohistMC%2Fjob%2FMohist-1.20.1)](https://ci.codemc.io/job/MohistMC/job/Mohist-1.20.1)
[![](https://img.shields.io/github/stars/MohistMC/Mohist.svg?label=Stars&logo=github)](https://github.com/MohistMC/Mohist/stargazers)
[![](https://img.shields.io/badge/Forge-1.20.1--47.3.5-brightgreen.svg?colorB=26303d&logo=Conda-Forge)](https://files.minecraftforge.net/net/minecraftforge/forge/index_1.20.1.html)
[![](https://img.shields.io/badge/NeoForge-1.20.1--47.1.79-brightgreen.svg?colorB=26303d)](https://neoforged.net/)
[![](https://img.shields.io/badge/Forge-1.20.1--47.3.6-brightgreen.svg?colorB=26303d&logo=Conda-Forge)](https://files.minecraftforge.net/net/minecraftforge/forge/index_1.20.1.html)
[![](https://img.shields.io/badge/NeoForge-1.20.1--47.1.106-brightgreen.svg?colorB=26303d)](https://neoforged.net/)
[![](https://img.shields.io/badge/JDK-17.0.10-brightgreen.svg?colorB=469C00&logo=java)](https://www.azul.com/downloads/?version=java-17-lts#zulu)
[![](https://img.shields.io/badge/Gradle-8.3-brightgreen.svg?colorB=469C00&logo=gradle)](https://docs.gradle.org/8.3/release-notes.html)
[![](https://img.shields.io/bstats/servers/6762?label=bStats)](https://bstats.org/plugin/server-implementation/Mohist/6762)
Expand All @@ -21,7 +21,7 @@
Progress
------

- [x] Rectify Forge([**361e99805**](https://github.com/MinecraftForge/MinecraftForge/commit/361e99805))
- [x] Rectify Forge([**25bc8679b**](https://github.com/MinecraftForge/MinecraftForge/commit/25bc8679b))
- [x] Rectify NeoForge([**e7ac32353**](https://github.com/neoforged/NeoForge/commit/e7ac32353))
- [x] Start patch
* [x] Bukkit([**997de31d**](https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/commits/997de31d))
Expand Down
80 changes: 73 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ plugins {
id 'com.github.ben-manes.versions' version '0.46.0'
id 'net.minecraftforge.gradleutils' version '[2.2,2.3)'
id 'eclipse'
id 'de.undercouch.download' version '5.4.0'
id 'net.minecraftforge.gradle.patcher' version '[6.0.11,6.2)' apply false
id 'net.minecraftforge.gradle.mcp' version '[6.0.11,6.2)' apply false
id 'de.undercouch.download' version '5.6.0'
id 'net.minecraftforge.gradle.patcher' version '[6.0.16,6.2)' apply false
id 'net.minecraftforge.gradle.mcp' version '[6.0.16,6.2)' apply false
}

init() //Init all our extension methods!
Expand Down Expand Up @@ -152,6 +152,30 @@ project(':clean') {
}
}

def mohistDeps = {
mohist "com.nothome:javaxdelta:2.0.1"
mohist "com.github.jponge:lzma-java:1.3"
mohist "commons-collections:commons-collections:3.2.2"
mohist "com.opencsv:opencsv:4.4"
mohist "de.siegmar:fastcsv:2.0.0"
mohist "net.minecraftforge:installertools:1.4.1"
mohist 'net.minecraftforge:binarypatcher:1.1.1'
mohist "net.minecraftforge:JarJarFileSystems:0.3.19"
mohist "net.minecraftforge:ForgeAutoRenamingTool:0.1.22:all"
mohist "net.minecraftforge:srgutils:0.5.4"
mohist "net.minecraftforge:jarsplitter:1.1.4"
mohist 'com.google.errorprone:error_prone_annotations:2.1.3'
mohist 'org.apache.commons:commons-text:1.3'
mohist 'org.apache.commons:commons-collections4:4.2'
mohist 'commons-beanutils:commons-beanutils:1.9.3'
mohist "trove:trove:1.0.2"
mohist "org.codehaus.mojo:animal-sniffer-annotations:1.14"
mohist "com.google.j2objc:j2objc-annotations:1.1"
mohist "cpw.mods:bootstraplauncher:1.1.2"
mohist "com.google.code.findbugs:jsr305:3.0.2"
mohist 'org.checkerframework:checker-qual:2.0.0'
}

def sharedDeps = {
moduleonly "cpw.mods:securejarhandler:${SECUREJARHANDLER_VERSION}"
moduleonly "org.ow2.asm:asm:${ASM_VERSION}"
Expand All @@ -162,7 +186,7 @@ def sharedDeps = {
moduleonly "cpw.mods:bootstraplauncher:${BOOTSTRAPLAUNCHER_VERSION}"
moduleonly "net.minecraftforge:JarJarFileSystems:${JARJAR_VERSION}"

installer "cpw.mods:securejarhandler:${SECUREJARHANDLER_VERSION}"
compileOnly "cpw.mods:securejarhandler:${SECUREJARHANDLER_VERSION}" // Mmohist TODO
installer "org.ow2.asm:asm:${ASM_VERSION}"
installer "org.ow2.asm:asm-commons:${ASM_VERSION}"
installer "org.ow2.asm:asm-tree:${ASM_VERSION}"
Expand Down Expand Up @@ -234,7 +258,6 @@ def sharedDeps = {
installer "com.mohistmc:eventbus:${EVENTBUS_VERSION}"
installer 'com.ibm.icu:icu4j:71.1' // Forge 1.20.1


compileOnly 'me.clip:placeholderapi:2.11.5'

installer 'com.google.guava:failureaccess:1.0.1'
Expand Down Expand Up @@ -417,6 +440,10 @@ project(':mohist') {
// Don't pull all libraries, if we're missing something, add it to the installer list so the installer knows to download it.
transitive = false
}
mohist {
// Don't pull all libraries, if we're missing something, add it to the installer list so the installer knows to download it.
transitive = false
}
moduleonly
api.extendsFrom(installer)
}
Expand All @@ -426,6 +453,13 @@ project(':mohist') {
into 'libraries'
}

task downloadMultipleFiles(type: Download) {
src([
'https://maven.mohistmc.com/libraries/1.20.1/mohist/libraries.zip'
])
dest layout.buildDirectory.dir("libraries")
}

dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
testImplementation 'org.junit.vintage:junit-vintage-engine:5.+'
Expand All @@ -439,6 +473,7 @@ project(':mohist') {
runtimeOnly "cpw.mods:bootstraplauncher:${BOOTSTRAPLAUNCHER_VERSION}"
}
dependencies sharedDeps
dependencies mohistDeps

patcher {
excs.from file("$rootDir/src/main/resources/forge.exc")
Expand Down Expand Up @@ -541,7 +576,7 @@ project(':mohist') {
'Specification-Vendor' : 'SpigotMC',
'Specification-Version' : '1.20.1',
'Implementation-Title' : 'Spigot',
'Implementation-Version': bukkit_version + '-' + craftbukkit_version + '-' + spigot_version + '-' + neoforge_version ,
'Implementation-Version': bukkit_version + '-' + craftbukkit_version + '-' + spigot_version + '-' + neoforge_version,
'Implementation-Vendor' : 'SpigotMC'
] as LinkedHashMap
]
Expand Down Expand Up @@ -685,7 +720,29 @@ project(':mohist') {
}
}

task mohistJar(type: Jar, dependsOn: [genServerBinPatches, project(':mohistlauncher').tasks.jar]) {
task packageLibraries(type: Zip, dependsOn: [downloadMultipleFiles]) {
archiveFileName = 'libraries.zip'
destinationDirectory = file("build/distributions")
outputs.upToDateWhen {
false // TODO: Not 100% sure how to make this task re-run when libraries are changed...
}

configurations.mohist.resolvedConfiguration.resolvedArtifacts.collect {
def moduleVersion = it.moduleVersion
from (it.file) {
into ("${moduleVersion.id.group.replace('.', '/')}/${moduleVersion.id.name}/${moduleVersion.id.version}/")
}
}

configurations.installer.resolvedConfiguration.resolvedArtifacts.collect {
def moduleVersion = it.moduleVersion
from (it.file) {
into ("${moduleVersion.id.group.replace('.', '/')}/${moduleVersion.id.name}/${moduleVersion.id.version}/")
}
}
}

task mohistJar(type: Jar, dependsOn: [packageLibraries, genServerBinPatches, project(':mohistlauncher').tasks.jar]) {
archiveClassifier = 'server'
archiveExtension = 'jar'
archiveBaseName = 'mohist'
Expand All @@ -697,6 +754,7 @@ project(':mohist') {
'libraries/' + getMavenPath(rootProject.tasks.findByPath(':fmlloader:jar')),
"libraries/net/minecraft/server/${MC_VERSION}-${MCP_VERSION}/server-${MC_VERSION}-${MCP_VERSION}-extra.jar",
"libraries/cpw/mods/bootstraplauncher/1.1.2/bootstraplauncher-1.1.2.jar",
"libraries/cpw/mods/securejarhandler/mohist-2.1.11/securejarhandler-mohist-2.1.11.jar",
"libraries/net/minecraftforge/installertools/1.4.1/installertools-1.4.1.jar",
"libraries/io/netty/netty-transport-native-epoll/4.1.82.Final/netty-transport-native-epoll-4.1.82.Final-linux-x86_64.jar",
"libraries/io/netty/netty-transport-native-epoll/4.1.82.Final/netty-transport-native-epoll-4.1.82.Final-linux-aarch_64.jar"
Expand Down Expand Up @@ -760,6 +818,14 @@ project(':mohist') {
into ""
}

from(zipTree(packageLibraries.outputs.getFiles().asPath)) {
into 'META-INF/libraries'
}

from(zipTree(downloadMultipleFiles.outputs.getFiles().asPath)) {
into 'META-INF/libraries'
}

from(rootProject.file('server_files/version.txt')) {
filter(ReplaceTokens, tokens: [VERSION: MOHIST_VERSION])
rename { 'versions/mohist.txt' }
Expand Down
5 changes: 3 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ org.gradle.daemon=false
bukkit_version=997de31d
craftbukkit_version=ddc9a2dad
spigot_version=d2eba2c8
forge_version=47.3.5
neoforge_version=47.1.105
forge_version=47.3.6
neoforge_version=47.1.106
mohist_group_id=com.mohistmc

#systemProp.http.proxyHost=127.0.0.1
#systemProp.http.proxyPort=7890
Expand Down
2 changes: 0 additions & 2 deletions mohistlauncher/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ dependencies {
implementation 'com.mohistmc:i18n:0.6'
implementation 'com.mohistmc:json:0.5'
implementation 'com.mohistmc:tools:0.5.1'
implementation 'com.mohistmc:libraries:0.5'
implementation "cpw.mods:bootstraplauncher:1.1.2"
implementation 'me.tongfei:progressbar:0.10.0'
implementation 'org.jline:jline:3.25.1'
Expand All @@ -32,7 +31,6 @@ shadowJar {
include(dependency('com.mohistmc:i18n'))
include(dependency('com.mohistmc:json'))
include(dependency('com.mohistmc:tools'))
include(dependency('com.mohistmc:libraries'))
include(dependency('me.tongfei:progressbar'))
include(dependency('org.jline:jline'))
}
Expand Down
3 changes: 3 additions & 0 deletions mohistlauncher/src/main/java/com/mohistmc/MohistMCStart.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package com.mohistmc;

import com.mohistmc.action.ZipTree;
import com.mohistmc.action.v_1_20_1;
import com.mohistmc.config.MohistConfigUtil;
import com.mohistmc.feature.AutoDeleteMods;
Expand Down Expand Up @@ -77,6 +78,8 @@ public static void main(String[] args) throws Exception {
UpdateUtils.versionCheck();
}

ZipTree.init();

if (MohistConfigUtil.INSTALLATIONFINISHED() && MohistConfigUtil.CHECK_LIBRARIES()) {
DefaultLibraries.run();
}
Expand Down
33 changes: 33 additions & 0 deletions mohistlauncher/src/main/java/com/mohistmc/action/ZipTree.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.mohistmc.action;

import com.mohistmc.MohistMCStart;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class ZipTree {

public static void init() throws IOException {
InputStream is = MohistMCStart.class.getClassLoader().getResourceAsStream("META-INF/libraries");
getFileContent(is);
}

public static void getFileContent(Object fileInPath) throws IOException {
BufferedReader br = null;
if (fileInPath == null) {
return;
}
if (fileInPath instanceof String) {
br = new BufferedReader(new FileReader((String) fileInPath));
} else if (fileInPath instanceof InputStream) {
br = new BufferedReader(new InputStreamReader((InputStream) fileInPath));
}
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
br.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,12 @@
public class DefaultLibraries {

public static void run() {
String config = MohistConfigUtil.LIBRARIES_DOWNLOADSOURCE();
String ds = System.getProperty("downloadsource") == null ? config : System.getProperty("downloadsource");
String downloadSource = config;
if (!Objects.equals(config, ds) && ConnectionUtil.isValid(ds)) {
downloadSource = ds;
}

LibrariesDownloadQueue queue = LibrariesDownloadQueue.create()
.inputStream(DefaultLibraries.class.getClassLoader().getResourceAsStream("libraries.txt"))
.downloadSource(downloadSource)
.build();

System.out.println(I18n.as("libraries.checking.start"));
if (queue.needDownload()) {
System.out.println(I18n.as("libraries.downloadsource", queue.downloadSource.name()));
System.out.println(I18n.as("libraries.global.percentage"));
queue.progressBar();
for (Libraries libraries : queue.need_download) {
Expand Down
43 changes: 43 additions & 0 deletions mohistlauncher/src/main/java/com/mohistmc/libraries/Libraries.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Mohist - MohistMC
* Copyright (C) 2018-2024.
*
* 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 <https://www.gnu.org/licenses/>.
*/

package com.mohistmc.libraries;

import com.mohistmc.tools.MD5Util;
import java.io.File;
import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
public class Libraries {

String path;
String md5;
long size;
boolean installer;

public static Libraries from(String line) {
String[] parts = line.split("\\|");
return new Libraries(parts[0], parts[1], Long.parseLong(parts[2]), Boolean.parseBoolean(parts[3]));
}

public static Libraries from(File file) {
return new Libraries(file.getAbsolutePath(), MD5Util.get(file), file.length(), false);
}
}
Loading

0 comments on commit 615db15

Please sign in to comment.