2020-07-15 20:49:36 +02:00
#!/usr/bin/env bash
2020-08-03 18:48:42 +02:00
#maintask=$2
#if [[ $maintask == "0" ]]; then
# TASKTITLE="Import Sources"
#else
# TASKTITLE="Import Sources (Subtask)"
#fi
2020-07-15 20:49:36 +02:00
# SCRIPT HEADER start
basedir = $1
2020-08-03 18:48:42 +02:00
echo " $2 "
2020-07-15 20:49:36 +02:00
source " $basedir /scripts/functions.sh "
echo " "
echo "----------------------------------------"
echo " $( bashcolor 1 32) Task $( bashcolorend) - $TASKTITLE "
echo " This will import unimported newly added/mod sources to Paper workspace"
echo "----------------------------------------"
# SCRIPT HEADER end
# For a description of this script, see updateUpstream.sh.
paperworkdir = " $basedir /Tuinity/Paper/work "
2020-08-03 18:48:42 +02:00
forkname = " $2 "
paperserverdir = " $basedir /Yatopia-Server "
papersrcdir = " $basedir /Yatopia-Server/src/main/java "
2020-07-15 20:49:36 +02:00
papernmsdir = " $papersrcdir /net/minecraft/server "
(
2020-09-02 11:45:06 +02:00
# fast-fail if Paper not set
if [ ! -d " $papernmsdir " ] ; then
echo " $( bashcolor 1 31) Exception $( bashcolorend) - Paper sources not generated, run updateUpstream.sh to setup. "
exit 1
fi
2020-07-15 20:49:36 +02:00
)
minecraftversion = $( cat " $basedir " /Tuinity/Paper/work/BuildData/info.json | grep minecraftVersion | cut -d '"' -f 4)
decompiledir = $paperworkdir /Minecraft/$minecraftversion /spigot
nms = "net/minecraft/server"
export IMPORT_LOG = "" # for commit message, list all files and source for libs
basedir
2020-09-02 11:45:06 +02:00
function importToPaperWorkspace( ) {
if [ -f " $papernmsdir / $1 .java " ] ; then
return 0
fi
2020-07-15 20:49:36 +02:00
2020-09-02 11:45:06 +02:00
file = " $1 .java "
target = " $papernmsdir / $file "
base = " $decompiledir / $nms / $file "
2020-07-15 20:49:36 +02:00
2020-09-02 11:45:06 +02:00
if [ [ ! -f " $target " ] ] ; then
export IMPORT_LOG = " $IMPORT_LOG Import: $file \n "
echo " Import: $file "
cp " $base " " $target "
fi
2020-07-15 20:49:36 +02:00
}
2020-09-02 11:45:06 +02:00
function importLibraryToPaperWorkspace( ) {
group = $1
lib = $2
prefix = $3
shift 3
for file in " $@ " ; do
file = " $prefix / $file "
target = " $papersrcdir / $file "
targetdir = $( dirname " $target " )
mkdir -p " ${ targetdir } "
base = " $paperworkdir /Minecraft/ $minecraftversion /libraries/ ${ group } / ${ lib } / $file "
if [ ! -f " $base " ] ; then
echo " $( bashcolor 1 31) Exception $( bashcolorend) - Cannot find file $file .java of lib $lib in group $group to import, re-decomplie or remove the import. "
exit 1
fi
export IMPORT_LOG = " $IMPORT_LOG Import: $file from lib $lib \n "
echo " Import: $file ( $lib ) "
sed 's/\r$//' " $base " >" $target " || exit 1
done
2020-07-15 20:49:36 +02:00
}
(
2020-09-02 11:45:06 +02:00
# Reset to last NORMAL commit if already have imported before
cd " $paperserverdir "
lastcommit = $( git log -1 --pretty= oneline --abbrev-commit)
if [ [ " $lastcommit " = = *" Extra dev imports of $forkname " * ] ] ; then
git reset --hard HEAD^
fi
2020-07-15 20:49:36 +02:00
)
# Filter and import every files which have patch to modify
2020-08-03 18:48:42 +02:00
if [ [ $forkname != "Yatopia" ] ] ; then
2020-09-02 11:45:06 +02:00
if [ [ $forkname != null ] ] ; then
echo " test: $forkname == Purpur "
patchedFiles = $( cat patches/$forkname /server/* | grep "+++ b/src/main/java/net/minecraft/server/" | sort | uniq | sed 's/\+\+\+ b\/src\/main\/java\/net\/minecraft\/server\///g' | sed 's/.java//g' )
patchedFilesNonNMS = $( cat patches/$forkname /server/* | grep "create mode " | grep -Po "src/main/java/net/minecraft/server/(.*?).java" | sort | uniq | sed 's/src\/main\/java\/net\/minecraft\/server\///g' | sed 's/.java//g' )
else
2020-08-03 18:48:42 +02:00
echo " test: $forkname == Yatopia "
2020-09-02 11:45:06 +02:00
patchedFiles = $( cat patches/server/* | grep "+++ b/src/main/java/net/minecraft/server/" | sort | uniq | sed 's/\+\+\+ b\/src\/main\/java\/net\/minecraft\/server\///g' | sed 's/.java//g' )
patchedFilesNonNMS = $( cat patches/server/* | grep "create mode " | grep -Po "src/main/java/net/minecraft/server/(.*?).java" | sort | uniq | sed 's/src\/main\/java\/net\/minecraft\/server\///g' | sed 's/.java//g' )
fi
else
echo " test: $forkname == Yatopia "
patchedFiles = $( cat patches/server/* | grep "+++ b/src/main/java/net/minecraft/server/" | sort | uniq | sed 's/\+\+\+ b\/src\/main\/java\/net\/minecraft\/server\///g' | sed 's/.java//g' )
patchedFilesNonNMS = $( cat patches/server/* | grep "create mode " | grep -Po "src/main/java/net/minecraft/server/(.*?).java" | sort | uniq | sed 's/src\/main\/java\/net\/minecraft\/server\///g' | sed 's/.java//g' )
2020-08-03 18:48:42 +02:00
fi
2020-07-15 20:49:36 +02:00
(
2020-09-02 11:45:06 +02:00
cd " $paperserverdir "
2020-07-15 20:49:36 +02:00
)
basedir
for f in $patchedFiles ; do
2020-09-02 11:45:06 +02:00
containsElement " $f " ${ patchedFilesNonNMS [@] }
if [ " $? " = = "1" ] ; then
if [ ! -f " $papersrcdir / $nms / $f .java " ] ; then
if [ ! -f " $decompiledir / $nms / $f .java " ] ; then
echo " $( bashcolor 1 31) Exception $( bashcolorend) - Cannot find NMS file $f .java to import, re-decomplie or remove the import. "
exit 1
else
importToPaperWorkspace $f
fi
2020-07-15 20:49:36 +02:00
fi
2020-09-02 11:45:06 +02:00
fi
2020-07-15 20:49:36 +02:00
done
# NMS import format:
# importToPaperWorkspace MinecraftServer
2020-08-03 18:48:42 +02:00
2020-07-15 20:49:36 +02:00
# Library import format (multiple files are supported):
2020-09-02 11:45:06 +02:00
# NOTE: Imported libraries aren't a temporary change, YOU NEED TO LEAVE THEM AS IS!!!!
2020-07-15 20:49:36 +02:00
# importLibraryToPaperWorkspace com.mojang datafixerupper com/mojang/datafixers/util Either.java
# Submit imports by commit with file descriptions
(
2020-09-02 11:45:06 +02:00
cd " $paperserverdir "
# rm -rf nms-patches
git add . & >/dev/null
echo -e " Extra dev imports of $forkname \n\n $IMPORT_LOG "
git commit -m " Extra dev imports of $forkname "
echo " $( bashcolor 1 32) Succeed $( bashcolorend) - Sources have been imported to Paper/Paper-Server (branch upstream) "
if [ [ $maintask != "0" ] ] ; then # this is magical
echo "----------------------------------------"
echo " Subtask finished"
echo "----------------------------------------"
fi
2020-07-15 20:49:36 +02:00
)