Last active
August 4, 2022 16:46
-
-
Save Machine-Maker/5b3d1e9cff355d587d2672d2a47cf17e to your computer and use it in GitHub Desktop.
Combine Craftbukkit, Bukkit, Spigot, and Paper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rm -rf nms Paper | |
mkdir -p work && cd work | |
repo=https://github.com/PaperMC/Paper.git | |
if [[ -n $1 ]]; then | |
repo=https://github.com/$1.git | |
fi | |
branch=master | |
if [[ -n $2 ]]; then | |
branch=$2 | |
fi | |
# setup upstream | |
echo "Setting up BuildTools..." | |
if [[ ! -e BuildTools.jar ]]; then | |
curl -# -o "BuildTools.jar" "https://hub.spigotmc.org/jenkins/job/BuildTools/lastBuild/artifact/target/BuildTools.jar" | |
fi | |
rm -rf CraftBukkit | |
rm -rf Bukkit | |
java -jar BuildTools.jar --rev 1.19.1 --compile NONE | |
cd Spigot/Spigot-Server | |
# create patches for nms-specific stuff | |
echo "Creating Spigot NMS patches..." | |
git format-patch -q -o ../../../nms/spigot/ --no-stat -N origin/patched -- src/main/java/net/minecraft/ | |
cd ../../../nms/spigot | |
for file in *; do | |
mv $file `echo $file | sed -E 's/^[0-9]{4}-//'` | |
done | |
# setup Paper | |
echo "Setting up Paper..." | |
cd ../../work | |
if [[ ! -d Paper ]]; then | |
git clone https://github.com/PaperMC/Paper.git -b $branch --single-branch | |
fi | |
cd Paper | |
git reset --hard &>/dev/null | |
git checkout -q $branch &>/dev/null | |
git pull -q | |
git branch -D -q delete &>/dev/null | |
./gradlew applyPatches | |
cd Paper-Server | |
# create 0001-Initial.patch for the remap commit | |
echo "Created nms remap patch for CB source" | |
git format-patch -q -o ../.. --no-stat -N --zero-commit --full-index --no-signature -1 base | |
# create patches for nms-specific stuff | |
git format-patch -q -o ../../../nms/paper/ --no-stat -N --zero-commit --full-index --no-signature base -- src/main/java/net/minecraft | |
cd ../../../nms/paper | |
for file in *; do | |
mv $file `echo $file | sed -E 's/^[0-9]{4}-//'` | |
done | |
echo "Created Paper NMS patches" | |
# commit deletion of all unneeded files | |
cd ../../work/Paper | |
git checkout -q -b delete | |
rm -rf patches work | |
rm .gitmodules | |
git add patches work .gitmodules &>/dev/null | |
git commit -q -m "OWW! THAT FORK IS HARD" | |
git checkout -q $branch | |
# CraftBukkit | |
cd ../CraftBukkit | |
git checkout -q -b work | |
# apply spigot's server patches | |
mkdir -p nms-patches/spigot | |
num=1 | |
for file in ../Spigot/Craftbukkit-Patches/*; do | |
git am --ignore-whitespace --exclude="src/main/java/net/minecraft/*" $file | |
patch=`echo $file | sed -E 's/..\/Spigot\/Craftbukkit-Patches\/[0-9]{4}-//'` | |
if [[ -e ../../nms/spigot/$patch ]]; then | |
new_file=`echo "$(printf '%0*d' 4 $num)-${patch}"` | |
mv ../../nms/spigot/$patch nms-patches/spigot/$new_file | |
git add nms-patches/spigot/$new_file | |
git commit -q --amend --no-edit | |
((num++)) | |
fi | |
done | |
# rewrite craftbukkit commits' authors and messages | |
git filter-repo --refs work --path-glob="*.java" --path="nms-patches/" --path=".gitignore" --path="src/main/resources/" --path="pom.xml" --force --commit-callback " | |
commit.message = bytes(commit.message.decode('utf-8') + '(' + commit.author_name.decode('utf-8') + ' <' + commit.author_email.decode('utf-8') + '>)', 'utf-8') | |
commit.author_name = bytes('CraftBukkit', 'utf-8') | |
commit.author_email = bytes('craftbukkit@github.com', 'utf-8') | |
commit.committer_name = commit.author_name | |
commit.committer_email = commit.author_email | |
commit.committer_date = commit.author_date" | |
# apply remapping patch | |
# 0001-Initial.patch is just a patch of the commit that applies the mojmap remapping to the server | |
git am --exclude="src/main/java/net/minecraft/*" --exclude="nms-patches/*" --exclude=CONTRIBUTING.md --exclude=applyPatches.sh --exclude=makePatches.sh --exclude=README.md ../0001-Initial.patch | |
# apply paper's server patches | |
mkdir -p nms-patches/paper | |
num=1 | |
for file in ../Paper/patches/server/*; do | |
git am --ignore-whitespace --exclude="src/main/java/net/minecraft/*" $file | |
patch=`echo $file | sed -E 's/..\/Paper\/patches\/server\/[0-9]{4}-//'` | |
if [[ -e ../../nms/paper/$patch ]]; then | |
new_file=`echo "$(printf '%0*d' 4 $num)-${patch}"` | |
mv ../../nms/paper/$patch nms-patches/paper/$new_file | |
git add nms-patches/paper/$new_file | |
git commit -q --amend --no-edit | |
((num++)) | |
fi | |
done | |
# move to "server" directory | |
git filter-repo --refs work --to-subdirectory-filter server --force --commit-callback " | |
commit.committer_name = commit.author_name | |
commit.committer_email = commit.author_email | |
commit.committer_date = commit.author_date" | |
# Bukkit | |
cd ../Bukkit | |
git checkout -b work | |
# apply spigot's api patches | |
git am ../Spigot/Bukkit-Patches/*.patch | |
# filter out unimportant history | |
git filter-repo --refs work --use-base-name --path-glob="*.java" --path=".gitignore" --path="pom.xml" --force | |
# rewrite bukkit commits' authors and messages | |
git filter-repo --refs work --force --commit-callback " | |
commit.message = bytes(commit.message.decode('utf-8') + '(' + commit.author_name.decode('utf-8') + ' <' + commit.author_email.decode('utf-8') + '>)', 'utf-8') | |
commit.author_name = bytes('CraftBukkit', 'utf-8') | |
commit.author_email = bytes('craftbukkit@github.com', 'utf-8') | |
commit.committer_name = commit.author_name | |
commit.committer_email = commit.author_email | |
commit.committer_date = commit.author_date" | |
# apply paper's api patches | |
git am --ignore-whitespace ../Paper/patches/api/*.patch | |
# move to "api" directory | |
git filter-repo --refs work --to-subdirectory-filter api --force --commit-callback " | |
commit.committer_name = commit.author_name | |
commit.committer_email = commit.author_email | |
commit.committer_date = commit.author_date" | |
# setup final Paper repo | |
cd ../.. | |
mkdir Paper && cd Paper && git init -q | |
git remote add bukkit ../work/Bukkit | |
git remote add craftbukkit ../work/CraftBukkit | |
git remote add paper ../work/Paper | |
git fetch bukkit && git fetch craftbukkit && git fetch paper | |
git merge bukkit/work --no-edit --allow-unrelated-histories | |
git merge craftbukkit/work --no-edit --allow-unrelated-histories | |
git merge paper/delete --no-edit --allow-unrelated-histories | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment