Skip to content

Commit 7d0f42a

Browse files
properly using the preprocessor system
1 parent f7bf715 commit 7d0f42a

4 files changed

Lines changed: 32 additions & 9 deletions

File tree

.github/workflows/publish.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ jobs:
2424
run: echo "WLIB_BUILD_DATE=$(date +'%Y-%m-%d_%H-%M-%S')" >> "$GITHUB_ENV"
2525
- name: Get snapshot number
2626
run: echo "WLIB_SNAPSHOT_NUMBER=$((${{ github.run_number }}+${{ github.run_attempt }}))" >> $GITHUB_ENV
27-
- name: "Skip NMS if needed"
28-
if: ${{ github.event_name != 'release' }}
29-
run: echo "WLIB_SKIP_NMS=true" >> "$GITHUB_ENV"
3027
- uses: actions/checkout@v4
3128
- name: Set up JDK 21
3229
uses: actions/setup-java@v4
@@ -36,7 +33,12 @@ jobs:
3633
- name: Setup Gradle
3734
uses: gradle/actions/setup-gradle@v4
3835
- name: Build
39-
run: ./gradlew build
36+
run: |
37+
if [ "${{ github.event_name }}" != "release" ]; then
38+
./gradlew build -Pskip_nms=true
39+
else
40+
./gradlew build
41+
fi
4042
- name: Upload results
4143
uses: actions/upload-artifact@v4
4244
with:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
**/build/
22
.idea/
33
.gradle/
4+
/build.properties

core/build.gradle

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ dependencies {
2525
project(':bukkit-utils'),
2626
)
2727

28-
if (System.getenv("WLIB_SKIP_NMS") == null) {
28+
if (!"true".equals(properties.get("skip_nms"))) {
2929
implementation(project(":versions:v1_20_R4"))
3030
implementation(project(":versions:v1_21_R1"))
3131
implementation(project(":versions:v1_21_R3"))
@@ -52,10 +52,18 @@ tasks {
5252
archiveFileName = 'WLib-' + project.version + '.jar'
5353
relocate("com.github.sisyphsu", "com.wizardlybump17.wlib.libs.com.github.sisyphsu")
5454
}
55+
}
56+
57+
def preprocessors() {
58+
StringBuilder preprocessors = new StringBuilder()
5559

56-
tasks.withType(JavaCompile) {
57-
if (System.getenv("WLIB_SKIP_NMS") == null)
58-
options.compilerArgs += ["-Awlib_include_nms"]
60+
if ("true".equals(properties.get("skip_nms"))) {
61+
preprocessors.append("WLIB_INCLUDE_NMS=0")
62+
} else {
63+
preprocessors.append("WLIB_INCLUDE_NMS=1")
5964
}
65+
66+
new File(rootProject.projectDir, "build.properties").text = preprocessors.toString()
6067
}
6168

69+
preprocessors()

core/src/main/java/com/wizardlybump17/wlib/WLib.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
import com.google.gson.Gson;
44
import com.google.gson.GsonBuilder;
5+
import com.wizardlybump17.wlib.adapter.AttributeAdapter;
6+
import com.wizardlybump17.wlib.adapter.ItemAdapter;
7+
import com.wizardlybump17.wlib.adapter.command.CommandMapAdapter;
8+
import com.wizardlybump17.wlib.adapter.player.PlayerAdapter;
59
import com.wizardlybump17.wlib.command.WLibCommandExecutor;
610
import com.wizardlybump17.wlib.command.extractor.method.MethodCommandExtractor;
711
import com.wizardlybump17.wlib.command.extractor.method.factory.OfflinePlayerMethodCommandNodeFactory;
@@ -154,7 +158,13 @@ private void initAdapters() {
154158
}
155159

156160
private void setupAdapters() {
157-
#if WLIB_INCLUDE_NMS
161+
//keep IntelliJ from removing the import
162+
ItemAdapter.class.toString();
163+
PlayerAdapter.class.toString();
164+
AttributeAdapter.class.toString();
165+
CommandMapAdapter.class.toString();
166+
167+
#if WLIB_INCLUDE_NMS == 1
158168
String version = Bukkit.getMinecraftVersion();
159169
switch (version) {
160170
case "1.20.5", "1.20.6" -> {
@@ -183,6 +193,8 @@ private void setupAdapters() {
183193
}
184194
default -> getLogger().severe("The server version (" + version + ") is not supported by WLib yet.");
185195
}
196+
#else
197+
getLogger().severe("The NMS integration was disabled during compile, probably because of the presence of the \"skip_nms\" property and it was set to \"true\". The following systems are expected to not work: ItemAdapter, PlayerAdapter, AttributeAdapter, CommandMapAdapter.");
186198
#endif
187199
}
188200

0 commit comments

Comments
 (0)