testserver/scripts/importmcdev.sh

81 lines
2.2 KiB
Bash
Raw Normal View History

2016-03-31 00:50:23 +00:00
#!/usr/bin/env bash
(
set -e
2016-03-31 00:50:23 +00:00
nms="net/minecraft/server"
export MODLOG=""
PS1="$"
basedir="$(cd "$1" && pwd -P)"
source "$basedir/scripts/functions.sh"
gitcmd="git -c commit.gpgsign=false"
2016-03-31 00:50:23 +00:00
2016-04-02 03:55:54 +00:00
workdir="$basedir/work"
minecraftversion=$(cat "$workdir/BuildData/info.json" | grep minecraftVersion | cut -d '"' -f 4)
decompiledir="$workdir/Minecraft/$minecraftversion"
2016-03-31 00:50:23 +00:00
export importedmcdev=""
function import {
export importedmcdev="$importedmcdev $1"
file="${1}.java"
target="$workdir/Spigot/Spigot-Server/src/main/java/$nms/$file"
base="$decompiledir/$nms/$file"
2016-03-31 00:50:23 +00:00
if [[ ! -f "$target" ]]; then
export MODLOG="$MODLOG Imported $file from mc-dev\n";
#echo "Copying $base to $target"
cp "$base" "$target" || exit 1
else
echo "UN-NEEDED IMPORT: $file"
fi
2016-03-31 00:50:23 +00:00
}
(
cd "$workdir/Spigot/Spigot-Server/"
lastlog=$($gitcmd log -1 --oneline)
if [[ "$lastlog" = *"mc-dev Imports"* ]]; then
$gitcmd reset --hard HEAD^
fi
2016-03-31 00:50:23 +00:00
)
files=$(cat "$basedir/Spigot-Server-Patches/"* | grep "+++ b/src/main/java/net/minecraft/server/" | sort | uniq | sed 's/\+\+\+ b\/src\/main\/java\/net\/minecraft\/server\///g' | sed 's/.java//g')
nonnms=$(cat "$basedir/Spigot-Server-Patches/"* | 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' ;
# TODO: Fix non nms to work for Paper, hard code these for now
echo "KeyedObject" ;
echo "MCUtil" ;
echo "PaperLightingQueue"
)
function containsElement {
local e
for e in "${@:2}"; do
[[ "$e" == "$1" ]] && return 0;
done
return 1
}
set +e
for f in $files; do
containsElement "$f" ${nonnms[@]}
if [ "$?" == "1" ]; then
if [ ! -f "$workdir/Spigot/Spigot-Server/src/main/java/net/minecraft/server/$f.java" ]; then
if [ ! -f "$decompiledir/$nms/$f.java" ]; then
echo "$(color 1 31) ERROR!!! Missing NMS$(color 1 34) $f $(colorend)";
else
import $f
fi
fi
fi
done
import NBTList
import NBTBase
set -e
cd "$workdir/Spigot/Spigot-Server/"
rm -rf nms-patches applyPatches.sh makePatches.sh >/dev/null 2>&1
$gitcmd add . -A >/dev/null 2>&1
echo -e "mc-dev Imports\n\n$MODLOG" | $gitcmd commit . -F -
2016-03-31 00:50:23 +00:00
)