Skip to content

Commit

Permalink
build: simplify Paper spigot process by using Reflection
Browse files Browse the repository at this point in the history
  • Loading branch information
timbru31 committed Mar 13, 2022
1 parent 8b427d6 commit 9152efa
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 115 deletions.
47 changes: 1 addition & 46 deletions .github/workflows/maven-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
java -version
mvn --version
- name: Build Spigot and Paper versions
- name: Build Spigot versions
# See https://issues.apache.org/jira/browse/MDEP-568 and https://github.com/apache/maven-dependency-plugin/pull/2
run: |
mvn com.offbytwo.maven.plugins:maven-dependency-plugin:3.1.1.MDEP568:go-offline -DexcludeGroupIds=de.dustplanet -B || rm -r ~/.m2/repository/org/
Expand All @@ -44,50 +44,5 @@ jobs:
[ -f ~/.m2/repository/org/spigotmc/spigot/1.9.4-R0.1-SNAPSHOT/spigot-1.9.4-R0.1-SNAPSHOT.jar ] || java -jar BuildTools.jar --rev 1.9.4
[ -f ~/.m2/repository/org/spigotmc/spigot/1.8.8-R0.1-SNAPSHOT/spigot-1.8.8-R0.1-SNAPSHOT.jar ] || java -jar BuildTools.jar --rev 1.8.8
[ -f ~/.m2/repository/org/spigotmc/spigot/1.8-R0.1-SNAPSHOT/spigot-1.8-R0.1-SNAPSHOT.jar ] || java -jar BuildTools.jar --rev 1.8
cd ..
git clone https://github.com/PaperMC/Paper.git
cd Paper
if [ ! -f ~/.m2/repository/com/destroystokyo/paper/paper/1.16.5-R0.1-SNAPSHOT/paper-1.16.5-R0.1-SNAPSHOT.jar ]; then
git checkout ver/1.16.5
git clean -xfd
git submodule foreach --recursive git clean -xfd
git reset --hard
git submodule foreach --recursive git reset --hard
git submodule update --init --recursive
./paper jar
fi
if [ ! -f ~/.m2/repository/com/destroystokyo/paper/paper/1.16.3-R0.1-SNAPSHOT/paper-1.16.3-R0.1-SNAPSHOT.jar ]; then
git checkout 4bcebab1675d88d144d2896734f4a940345f76c2
git clean -xfd
git submodule foreach --recursive git clean -xfd
git reset --hard
git submodule foreach --recursive git reset --hard
git submodule update --init --recursive
./paper jar
fi
if [ ! -f ~/.m2/repository/com/destroystokyo/paper/paper/1.16.1-R0.1-SNAPSHOT/paper-1.16.1-R0.1-SNAPSHOT.jar ]; then
git checkout 627f4b8561115d40d6a39587d1ad94b0104f7e14
git clean -xfd
git submodule foreach --recursive git clean -xfd
git reset --hard
git submodule foreach --recursive git reset --hard
git submodule update --init --recursive
./paper jar
fi
if [ ! -f ~/.m2/repository/com/destroystokyo/paper/paper/1.15.2-R0.1-SNAPSHOT/paper-1.15.2-R0.1-SNAPSHOT.jar ]; then
git checkout ver/1.15.2
git clean -xfd
git submodule foreach --recursive git clean -xfd
git reset --hard
git submodule foreach --recursive git reset --hard
git submodule update --init --recursive
./paper jar
fi
- name: Build with Maven
run: mvn -D"http.keepAlive=false" -D"maven.wagon.http.pool=false" -D"maven.wagon.httpconnectionManager.ttlSeconds=120" "-Dhttps.protocols=TLSv1.2" -DskipTests=true "-Dmaven.javadoc.skip=true" -B clean package
45 changes: 2 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -308,12 +308,13 @@ Please follow the Sun Coding Guidelines, thanks!
## Building
Unfortunately, I can't give access to https://repo.dustplanet.de/artifactory/private due to the DMCA of CraftBukkit and the prohibiton to distribute those or Spigot's nor Paper's binaries. To successfully build SilkSpawners using Maven, you must first run Spigot's BuildTools and Paper for several versions in order to compile each module - this will populate the local `.m2` cache of yours.
Unfortunately, I can't give access to https://repo.dustplanet.de/artifactory/private due to the DMCA of CraftBukkit and the prohibiton to distribute those or Spigot's binaries. To successfully build SilkSpawners using Maven, you must first run Spigot's BuildTools for several versions in order to compile each module - this will populate the local `.m2` cache of yours.

```sh
mkdir -p BuildTools
cd BuildTools
wget -q https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar
java -jar BuildTools.jar --rev 1.18.2 --remapped
java -jar BuildTools.jar --rev 1.18.1 --remapped
java -jar BuildTools.jar --rev 1.17.1 --remapped
java -jar BuildTools.jar --rev 1.14.4
Expand All @@ -326,48 +327,6 @@ java -jar BuildTools.jar --rev 1.8.8
java -jar BuildTools.jar --rev 1.8
```

For Minecraft 1.15 and newer, Paper is required to be present (there is currently an exception for 1.17+):

```sh
git clone https://github.com/PaperMC/Paper.git
cd Paper
# 1.16.5 (v1_16_R3)
git checkout ver/1.16.5
git clean -xfd
git submodule foreach --recursive git clean -xfd
git reset --hard
git submodule foreach --recursive git reset --hard
git submodule update --init --recursive
./paper jar
# 1.16.3 (v1_16_R2)
git checkout 4bcebab1675d88d144d2896734f4a940345f76c2
git clean -xfd
git submodule foreach --recursive git clean -xfd
git reset --hard
git submodule foreach --recursive git reset --hard
git submodule update --init --recursive
./paper jar
# 1.16.1 (v1_16_R1)
git checkout 627f4b8561115d40d6a39587d1ad94b0104f7e14
git clean -xfd
git submodule foreach --recursive git clean -xfd
git reset --hard
git submodule foreach --recursive git reset --hard
git submodule update --init --recursive
./paper jar
# 1.15.2 (v1_15_R1)
git checkout ver/1.15.2
git clean -xfd
git submodule foreach --recursive git clean -xfd
git reset --hard
git submodule foreach --recursive git reset --hard
git submodule update --init --recursive
./paper jar
```

The final `SilkSpawners.jar` can now be generated by invoking `mvn clean package`. The location of this output can be found in the `modules/SilkSpawners/target` folder.

## Usage statistics
Expand Down
4 changes: 2 additions & 2 deletions modules/v1_15_R1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

<dependencies>
<dependency>
<groupId>com.destroystokyo.paper</groupId>
<artifactId>paper</artifactId>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.15.2-R0.1-SNAPSHOT</version>
<exclusions>
<exclusion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.bukkit.scheduler.BukkitRunnable;
import org.spigotmc.SpigotWorldConfig;

import com.destroystokyo.paper.PaperWorldConfig;
import com.google.common.base.CaseFormat;
import com.mojang.authlib.GameProfile;

Expand Down Expand Up @@ -98,12 +97,17 @@ public NMSHandler(final boolean checkForNerfFlags) {
}

try {
final PaperWorldConfig paperConfig = handle.paperConfig;
if (!paperConfig.ironGolemsCanSpawnInAir) {
final Field paperConfigField = World.class.getDeclaredField("paperConfig");
paperConfigField.setAccessible(true);

final Field ironGolemsCanSpawnInAirField = paperConfigField.getType().getDeclaredField("ironGolemsCanSpawnInAir");
ironGolemsCanSpawnInAirField.setAccessible(true);
if (!ironGolemsCanSpawnInAirField.getBoolean(paperConfigField.get(handle))) {
Bukkit.getLogger().warning(
"[SilkSpawners] Warning! \"iron-golems-can-spawn-in-air\" is set to false in the paper.yml! Iron Golem farms might not work!");
}
} catch (@SuppressWarnings("unused") final NoSuchFieldError e) {
} catch (@SuppressWarnings("unused") final NoSuchFieldError | IllegalArgumentException | IllegalAccessException
| NoSuchFieldException | SecurityException e) {
// Silence
}
}
Expand Down
4 changes: 2 additions & 2 deletions modules/v1_16_R1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

<dependencies>
<dependency>
<groupId>com.destroystokyo.paper</groupId>
<artifactId>paper</artifactId>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.16.1-R0.1-SNAPSHOT</version>
<exclusions>
<exclusion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.bukkit.scheduler.BukkitRunnable;
import org.spigotmc.SpigotWorldConfig;

import com.destroystokyo.paper.PaperWorldConfig;
import com.google.common.base.CaseFormat;
import com.mojang.authlib.GameProfile;

Expand Down Expand Up @@ -97,12 +96,17 @@ public NMSHandler(final boolean checkForNerfFlags) {
}

try {
final PaperWorldConfig paperConfig = handle.paperConfig;
if (!paperConfig.ironGolemsCanSpawnInAir) {
final Field paperConfigField = World.class.getDeclaredField("paperConfig");
paperConfigField.setAccessible(true);

final Field ironGolemsCanSpawnInAirField = paperConfigField.getType().getDeclaredField("ironGolemsCanSpawnInAir");
ironGolemsCanSpawnInAirField.setAccessible(true);
if (!ironGolemsCanSpawnInAirField.getBoolean(paperConfigField.get(handle))) {
Bukkit.getLogger().warning(
"[SilkSpawners] Warning! \"iron-golems-can-spawn-in-air\" is set to false in the paper.yml! Iron Golem farms might not work!");
}
} catch (@SuppressWarnings("unused") final NoSuchFieldError e) {
} catch (@SuppressWarnings("unused") final NoSuchFieldError | IllegalArgumentException | IllegalAccessException
| NoSuchFieldException | SecurityException e) {
// Silence
}
}
Expand Down
6 changes: 3 additions & 3 deletions modules/v1_16_R2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@

<dependencies>
<dependency>
<groupId>com.destroystokyo.paper</groupId>
<artifactId>paper</artifactId>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.16.3-R0.1-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>io.papermc</groupId>
<groupId>org.spigotmc</groupId>
<artifactId>minecraft-server</artifactId>
</exclusion>
</exclusions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.bukkit.scheduler.BukkitRunnable;
import org.spigotmc.SpigotWorldConfig;

import com.destroystokyo.paper.PaperWorldConfig;
import com.google.common.base.CaseFormat;
import com.mojang.authlib.GameProfile;

Expand Down Expand Up @@ -97,12 +96,17 @@ public NMSHandler(final boolean checkForNerfFlags) {
}

try {
final PaperWorldConfig paperConfig = handle.paperConfig;
if (!paperConfig.ironGolemsCanSpawnInAir) {
final Field paperConfigField = World.class.getDeclaredField("paperConfig");
paperConfigField.setAccessible(true);

final Field ironGolemsCanSpawnInAirField = paperConfigField.getType().getDeclaredField("ironGolemsCanSpawnInAir");
ironGolemsCanSpawnInAirField.setAccessible(true);
if (!ironGolemsCanSpawnInAirField.getBoolean(paperConfigField.get(handle))) {
Bukkit.getLogger().warning(
"[SilkSpawners] Warning! \"iron-golems-can-spawn-in-air\" is set to false in the paper.yml! Iron Golem farms might not work!");
}
} catch (@SuppressWarnings("unused") final NoSuchFieldError e) {
} catch (@SuppressWarnings("unused") final NoSuchFieldError | IllegalArgumentException | IllegalAccessException
| NoSuchFieldException | SecurityException e) {
// Silence
}
}
Expand Down
6 changes: 3 additions & 3 deletions modules/v1_16_R3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@

<dependencies>
<dependency>
<groupId>com.destroystokyo.paper</groupId>
<artifactId>paper</artifactId>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>1.16.5-R0.1-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>io.papermc</groupId>
<groupId>org.spigotmc</groupId>
<artifactId>minecraft-server</artifactId>
</exclusion>
</exclusions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.bukkit.scheduler.BukkitRunnable;
import org.spigotmc.SpigotWorldConfig;

import com.destroystokyo.paper.PaperWorldConfig;
import com.google.common.base.CaseFormat;
import com.mojang.authlib.GameProfile;

Expand Down Expand Up @@ -97,12 +96,17 @@ public NMSHandler(final boolean checkForNerfFlags) {
}

try {
final PaperWorldConfig paperConfig = handle.paperConfig;
if (!paperConfig.ironGolemsCanSpawnInAir) {
final Field paperConfigField = World.class.getDeclaredField("paperConfig");
paperConfigField.setAccessible(true);

final Field ironGolemsCanSpawnInAirField = paperConfigField.getType().getDeclaredField("ironGolemsCanSpawnInAir");
ironGolemsCanSpawnInAirField.setAccessible(true);
if (!ironGolemsCanSpawnInAirField.getBoolean(paperConfigField.get(handle))) {
Bukkit.getLogger().warning(
"[SilkSpawners] Warning! \"iron-golems-can-spawn-in-air\" is set to false in the paper.yml! Iron Golem farms might not work!");
}
} catch (@SuppressWarnings("unused") final NoSuchFieldError e) {
} catch (@SuppressWarnings("unused") final NoSuchFieldError | IllegalArgumentException | IllegalAccessException
| NoSuchFieldException | SecurityException e) {
// Silence
}
}
Expand Down

0 comments on commit 9152efa

Please sign in to comment.