Skip to content

Commit 425ef2b

Browse files
authored
Support 1.19.4 (#6)
* feat: added 1.19.4 support * feat: removed codemc * feat: added buildtools for self building nms dependencies
1 parent 94170b5 commit 425ef2b

File tree

9 files changed

+216
-5
lines changed

9 files changed

+216
-5
lines changed

.github/workflows/build.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,21 @@ jobs:
1616
fetch-depth: 0
1717
- name: Set BUILD_VERSION
1818
run: echo "BUILD_VERSION=$(git describe --tags $(git rev-list --tags --max-count=1))-b$GITHUB_RUN_NUMBER" >> $GITHUB_ENV
19+
- name: Maven cache
20+
uses: actions/cache@v3
21+
with:
22+
path: ~/.m2/repository
23+
key: ${{ runner.os }}-maven-${{ env.CACHE_VERSION }}-${{ hashFiles('./.github/workflows/buildtools.sh') }}
24+
restore-keys: |
25+
${{ runner.os }}-maven-${{ env.CACHE_VERSION }}-
1926
- name: Set up JDK 17
2027
uses: actions/setup-java@v3
2128
with:
2229
distribution: 'temurin'
2330
java-version: 17
31+
- name: Run BuildTools
32+
run: |
33+
bash ./.github/workflows/buildtools.sh
2434
- name: Build
2535
run: |
2636
mvn clean package -pl zip-plugin --batch-mode --also-make -Drevision=$BUILD_VERSION

.github/workflows/buildtools.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
# Source: https://github.com/Imprex-Development/orebfuscator/blob/master/.github/workflows/buildtools.sh
3+
4+
build () {
5+
JAVA_PATH=$"JAVA_HOME_$2_X64"
6+
export JAVA_HOME=${!JAVA_PATH}
7+
8+
echo "Building v$1 with java-$2 ($JAVA_HOME)"
9+
10+
rm -rf $1
11+
mkdir $1
12+
cd $1
13+
14+
curl -o BuildTools.jar https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar
15+
"$JAVA_HOME/bin/java" -jar BuildTools.jar --rev $1 --remapped
16+
17+
cd ..
18+
}
19+
20+
checkVersion () {
21+
echo Checking version $1
22+
23+
if [ ! -d ~/.m2/repository/org/spigotmc/spigot/$1-R0.1-SNAPSHOT ]; then
24+
build $1 $2
25+
fi
26+
}
27+
28+
checkVersion "1.19" "17"
29+
checkVersion "1.19.3" "17"
30+
checkVersion "1.19.4" "17"

.github/workflows/release.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,21 @@ jobs:
1616
fetch-depth: 0
1717
- name: Set RELEASE_VERSION
1818
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
19+
- name: Maven cache
20+
uses: actions/cache@v3
21+
with:
22+
path: ~/.m2/repository
23+
key: ${{ runner.os }}-maven-${{ env.CACHE_VERSION }}-${{ hashFiles('./.github/workflows/buildtools.sh') }}
24+
restore-keys: |
25+
${{ runner.os }}-maven-${{ env.CACHE_VERSION }}-
1926
- name: Set up JDK 17
2027
uses: actions/setup-java@v3
2128
with:
2229
distribution: 'temurin'
2330
java-version: 17
31+
- name: Run BuildTools
32+
run: |
33+
bash ./.github/workflows/buildtools.sh
2434
- name: Build
2535
run: |
2636
mvn package --batch-mode -Drevision=$RELEASE_VERSION

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<img align="right" src="https://user-images.githubusercontent.com/13753840/213902224-92f7e6ec-bc7e-4fea-8c45-154a202004dd.jpg" height="200" width="200">
1+
<img align="right" src="https://user-images.githubusercontent.com/13753840/213946932-635d40a3-a278-427c-9e9c-245a89ed12a9.png" height="200" width="200">
22

33
# Zero Inventory Problems - ZIP
44
[![Release Status](https://github.com/Imprex-Development/zero-inventory-problems/workflows/Releases/badge.svg)](https://github.com/Imprex-Development/zero-inventory-problems/releases/latest) [![Build Status](https://github.com/Imprex-Development/zero-inventory-problems/workflows/Build/badge.svg)](https://github.com/Imprex-Development/zero-inventory-problems/actions?query=workflow%3ABuild)

pom.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@
4141
<id>spigot-repo</id>
4242
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
4343
</repository>
44-
<repository>
45-
<id>nms-repo</id>
46-
<url>https://repo.codemc.io/repository/nms/</url>
47-
</repository>
4844
</repositories>
4945

5046
<build>

zip-nms/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@
1414
<module>zip-nms-api</module>
1515
<module>zip-nms-v1_19_R1</module>
1616
<module>zip-nms-v1_19_R2</module>
17+
<module>zip-nms-v1_19_R3</module>
1718
</modules>
1819
</project>

zip-nms/zip-nms-v1_19_R3/pom.xml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<modelVersion>4.0.0</modelVersion>
3+
4+
<parent>
5+
<groupId>net.imprex</groupId>
6+
<artifactId>zip-nms</artifactId>
7+
<version>${revision}</version>
8+
</parent>
9+
10+
<artifactId>zip-nms-v1_19_R3</artifactId>
11+
<packaging>jar</packaging>
12+
13+
<dependencies>
14+
<dependency>
15+
<groupId>net.imprex</groupId>
16+
<artifactId>zip-nms-api</artifactId>
17+
<version>${revision}</version>
18+
<scope>provided</scope>
19+
</dependency>
20+
<dependency>
21+
<groupId>org.spigotmc</groupId>
22+
<artifactId>spigot</artifactId>
23+
<version>1.19.4-R0.1-SNAPSHOT</version>
24+
<classifier>remapped-mojang</classifier>
25+
<scope>provided</scope>
26+
</dependency>
27+
</dependencies>
28+
29+
<build>
30+
<plugins>
31+
<plugin>
32+
<groupId>net.md-5</groupId>
33+
<artifactId>specialsource-maven-plugin</artifactId>
34+
<version>${plugin.specialsource.version}</version>
35+
<executions>
36+
<execution>
37+
<phase>package</phase>
38+
<goals>
39+
<goal>remap</goal>
40+
</goals>
41+
<id>remap-obf</id>
42+
<configuration>
43+
<srgIn>org.spigotmc:minecraft-server:1.19.4-R0.1-SNAPSHOT:txt:maps-mojang</srgIn>
44+
<reverse>true</reverse>
45+
<remappedDependencies>org.spigotmc:spigot:1.19.4-R0.1-SNAPSHOT:jar:remapped-mojang</remappedDependencies>
46+
<remappedArtifactAttached>true</remappedArtifactAttached>
47+
<remappedClassifierName>remapped-obf</remappedClassifierName>
48+
</configuration>
49+
</execution>
50+
<execution>
51+
<phase>package</phase>
52+
<goals>
53+
<goal>remap</goal>
54+
</goals>
55+
<id>remap-spigot</id>
56+
<configuration>
57+
<inputFile>${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar</inputFile>
58+
<srgIn>org.spigotmc:minecraft-server:1.19.4-R0.1-SNAPSHOT:csrg:maps-spigot</srgIn>
59+
<remappedDependencies>org.spigotmc:spigot:1.19.4-R0.1-SNAPSHOT:jar:remapped-obf</remappedDependencies>
60+
</configuration>
61+
</execution>
62+
</executions>
63+
</plugin>
64+
</plugins>
65+
</build>
66+
</project>
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package net.imprex.zip.nms.v1_19_R3;
2+
3+
import java.io.ByteArrayInputStream;
4+
import java.io.ByteArrayOutputStream;
5+
import java.lang.reflect.Method;
6+
import java.util.ArrayList;
7+
import java.util.List;
8+
import java.util.UUID;
9+
10+
import org.bukkit.Material;
11+
import org.bukkit.craftbukkit.v1_19_R3.inventory.CraftItemStack;
12+
import org.bukkit.inventory.ItemStack;
13+
import org.bukkit.inventory.meta.SkullMeta;
14+
15+
import com.mojang.authlib.GameProfile;
16+
import com.mojang.authlib.properties.Property;
17+
18+
import net.imprex.zip.common.ReflectionUtil;
19+
import net.imprex.zip.nms.api.NmsManager;
20+
import net.minecraft.nbt.CompoundTag;
21+
import net.minecraft.nbt.ListTag;
22+
import net.minecraft.nbt.NbtIo;
23+
import net.minecraft.nbt.Tag;
24+
25+
public class ZipNmsManager implements NmsManager {
26+
27+
private static final Class<?> CRAFTMETASKULL_CLASS = ReflectionUtil.getCraftBukkitClass("inventory.CraftMetaSkull");
28+
private static final Method CRAFTMETASKULL_SET_PROFILE = ReflectionUtil.getMethod(CRAFTMETASKULL_CLASS,
29+
"setProfile", GameProfile.class);
30+
31+
public byte[] nbtToBinary(CompoundTag compound) {
32+
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
33+
NbtIo.writeCompressed(compound, outputStream);
34+
return outputStream.toByteArray();
35+
} catch (Exception e) {
36+
e.printStackTrace();
37+
}
38+
return null;
39+
}
40+
41+
public CompoundTag binaryToNBT(byte[] binary) {
42+
try (ByteArrayInputStream inputStream = new ByteArrayInputStream(binary)) {
43+
return NbtIo.readCompressed(inputStream);
44+
} catch (Exception e) {
45+
e.printStackTrace();
46+
}
47+
return new CompoundTag();
48+
}
49+
50+
@Override
51+
public byte[] itemstackToBinary(ItemStack[] items) {
52+
CompoundTag inventory = new CompoundTag();
53+
ListTag list = new ListTag();
54+
for (ItemStack itemStack : items) {
55+
net.minecraft.world.item.ItemStack craftItem = CraftItemStack.asNMSCopy(itemStack);
56+
list.add(craftItem.save(new CompoundTag()));
57+
}
58+
inventory.put("i", list);
59+
return nbtToBinary(inventory);
60+
}
61+
62+
@Override
63+
public List<ItemStack> binaryToItemStack(byte[] binary) {
64+
CompoundTag nbt = binaryToNBT(binary);
65+
List<ItemStack> items = new ArrayList<>();
66+
if (nbt.contains("i", 9)) {
67+
ListTag list = nbt.getList("i", 10);
68+
for (Tag base : list) {
69+
if (base instanceof CompoundTag) {
70+
items.add(CraftItemStack.asBukkitCopy(net.minecraft.world.item.ItemStack.of((CompoundTag) base)));
71+
}
72+
}
73+
}
74+
return items;
75+
}
76+
77+
@Override
78+
public void setSkullProfile(SkullMeta meta, String texture) {
79+
try {
80+
GameProfile gameProfile = new GameProfile(UUID.randomUUID(), "");
81+
gameProfile.getProperties().put("textures", new Property("textures", texture));
82+
CRAFTMETASKULL_SET_PROFILE.invoke(meta, gameProfile);
83+
} catch (Exception e) {
84+
throw new ClassCastException("Error by setting skull profile");
85+
}
86+
}
87+
88+
@Override
89+
public boolean isAir(Material material) {
90+
return material == null || material == Material.AIR;
91+
}
92+
}

zip-plugin/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,11 @@
5959
<version>${revision}</version>
6060
<scope>compile</scope>
6161
</dependency>
62+
<dependency>
63+
<groupId>net.imprex</groupId>
64+
<artifactId>zip-nms-v1_19_R3</artifactId>
65+
<version>${revision}</version>
66+
<scope>compile</scope>
67+
</dependency>
6268
</dependencies>
6369
</project>

0 commit comments

Comments
 (0)