Skip to content

Commit 2b41056

Browse files
authored
feat: 1.21.5 support (#39)
* feat: 1.21.5 support * fix: github actions outdated
1 parent 5657d6d commit 2b41056

File tree

7 files changed

+241
-8
lines changed

7 files changed

+241
-8
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@ jobs:
1111

1212
steps:
1313
- name: Checkout
14-
uses: actions/checkout@v3
14+
uses: actions/checkout@v4
1515
with:
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
1919
- name: Maven cache
20-
uses: actions/cache@v3
20+
uses: actions/cache@v4
2121
with:
2222
path: ~/.m2/repository
2323
key: ${{ runner.os }}-maven-${{ env.CACHE_VERSION }}-${{ hashFiles('./.github/workflows/buildtools.sh') }}
2424
restore-keys: |
2525
${{ runner.os }}-maven-${{ env.CACHE_VERSION }}-
2626
- name: Set up JDK 21
27-
uses: actions/setup-java@v3
27+
uses: actions/setup-java@v4
2828
with:
2929
distribution: 'temurin'
3030
java-version: 21
@@ -36,7 +36,7 @@ jobs:
3636
mvn clean package -pl zip-plugin --batch-mode --also-make -Drevision=$BUILD_VERSION
3737
mv zip-plugin/target/zip-*.jar ./
3838
- name: Upload artifacts
39-
uses: actions/upload-artifact@v3
39+
uses: actions/upload-artifact@v4
4040
with:
4141
name: zero-inventory-problems-plugin
4242
path: ./zip-*.jar

.github/workflows/buildtools.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@ checkVersion "1.20.4" "17"
3434
checkVersion "1.20.6" "21"
3535
checkVersion "1.21" "21"
3636
checkVersion "1.21.3" "21"
37-
checkVersion "1.21.4" "21"
37+
checkVersion "1.21.4" "21"
38+
checkVersion "1.21.5" "21"

.github/workflows/release.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@ jobs:
1111

1212
steps:
1313
- name: Checkout
14-
uses: actions/checkout@v3
14+
uses: actions/checkout@v4
1515
with:
1616
fetch-depth: 0
1717
- name: Set RELEASE_VERSION
1818
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
1919
- name: Maven cache
20-
uses: actions/cache@v3
20+
uses: actions/cache@v4
2121
with:
2222
path: ~/.m2/repository
2323
key: ${{ runner.os }}-maven-${{ env.CACHE_VERSION }}-${{ hashFiles('./.github/workflows/buildtools.sh') }}
2424
restore-keys: |
2525
${{ runner.os }}-maven-${{ env.CACHE_VERSION }}-
2626
- name: Set up JDK 21
27-
uses: actions/setup-java@v3
27+
uses: actions/setup-java@v4
2828
with:
2929
distribution: 'temurin'
3030
java-version: 21

zip-nms/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@
2222
<module>zip-nms-v1_21_R1</module>
2323
<module>zip-nms-v1_21_R2</module>
2424
<module>zip-nms-v1_21_R3</module>
25+
<module>zip-nms-v1_21_R4</module>
2526
</modules>
2627
</project>

zip-nms/zip-nms-v1_21_R4/pom.xml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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_21_R4</artifactId>
11+
12+
<dependencies>
13+
<dependency>
14+
<groupId>net.imprex</groupId>
15+
<artifactId>zip-nms-api</artifactId>
16+
<version>${revision}</version>
17+
<scope>provided</scope>
18+
</dependency>
19+
<dependency>
20+
<groupId>org.spigotmc</groupId>
21+
<artifactId>spigot</artifactId>
22+
<version>1.21.5-R0.1-SNAPSHOT</version>
23+
<classifier>remapped-mojang</classifier>
24+
<scope>provided</scope>
25+
</dependency>
26+
</dependencies>
27+
28+
<build>
29+
<plugins>
30+
<plugin>
31+
<groupId>net.md-5</groupId>
32+
<artifactId>specialsource-maven-plugin</artifactId>
33+
<version>${plugin.specialsource.version}</version>
34+
<executions>
35+
<execution>
36+
<phase>package</phase>
37+
<goals>
38+
<goal>remap</goal>
39+
</goals>
40+
<id>remap-obf</id>
41+
<configuration>
42+
<srgIn>
43+
org.spigotmc:minecraft-server:1.21.5-R0.1-SNAPSHOT:txt:maps-mojang</srgIn>
44+
<reverse>true</reverse>
45+
<remappedDependencies>
46+
org.spigotmc:spigot:1.21.5-R0.1-SNAPSHOT:jar:remapped-mojang</remappedDependencies>
47+
<remappedArtifactAttached>true</remappedArtifactAttached>
48+
<remappedClassifierName>remapped-obf</remappedClassifierName>
49+
</configuration>
50+
</execution>
51+
<execution>
52+
<phase>package</phase>
53+
<goals>
54+
<goal>remap</goal>
55+
</goals>
56+
<id>remap-spigot</id>
57+
<configuration>
58+
<inputFile>
59+
${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar</inputFile>
60+
<srgIn>
61+
org.spigotmc:minecraft-server:1.21.5-R0.1-SNAPSHOT:csrg:maps-spigot</srgIn>
62+
<remappedDependencies>
63+
org.spigotmc:spigot:1.21.5-R0.1-SNAPSHOT:jar:remapped-obf</remappedDependencies>
64+
</configuration>
65+
</execution>
66+
</executions>
67+
</plugin>
68+
</plugins>
69+
</build>
70+
</project>
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
package net.imprex.zip.nms.v1_21_R4;
2+
3+
import java.io.ByteArrayInputStream;
4+
import java.io.ByteArrayOutputStream;
5+
import java.lang.reflect.InvocationTargetException;
6+
import java.lang.reflect.Method;
7+
import java.util.ArrayList;
8+
import java.util.List;
9+
import java.util.Optional;
10+
import java.util.UUID;
11+
import java.util.function.BiConsumer;
12+
13+
import org.bukkit.Material;
14+
import org.bukkit.craftbukkit.v1_21_R4.CraftRegistry;
15+
import org.bukkit.craftbukkit.v1_21_R4.inventory.CraftItemStack;
16+
import org.bukkit.inventory.ItemStack;
17+
import org.bukkit.inventory.meta.SkullMeta;
18+
19+
import com.mojang.authlib.GameProfile;
20+
import com.mojang.authlib.properties.Property;
21+
22+
import net.imprex.zip.common.ReflectionUtil;
23+
import net.imprex.zip.nms.api.NmsManager;
24+
import net.minecraft.core.RegistryAccess;
25+
import net.minecraft.nbt.CompoundTag;
26+
import net.minecraft.nbt.ListTag;
27+
import net.minecraft.nbt.NbtAccounter;
28+
import net.minecraft.nbt.NbtIo;
29+
import net.minecraft.nbt.Tag;
30+
import net.minecraft.world.item.component.ResolvableProfile;
31+
32+
public class ZipNmsManager implements NmsManager {
33+
34+
private static final BiConsumer<SkullMeta, GameProfile> SET_PROFILE;
35+
36+
private static final RegistryAccess DEFAULT_REGISTRY = CraftRegistry.getMinecraftRegistry();
37+
38+
private static final CompoundTag NBT_EMPTY_ITEMSTACK = new CompoundTag();
39+
40+
static {
41+
NBT_EMPTY_ITEMSTACK.putString("id", "minecraft:air");
42+
43+
BiConsumer<SkullMeta, GameProfile> setProfile = (meta, profile) -> {
44+
throw new NullPointerException("Unable to find 'setProfile' method!");
45+
};
46+
47+
Class<?> craftMetaSkullClass = new ItemStack(Material.PLAYER_HEAD)
48+
.getItemMeta()
49+
.getClass();
50+
51+
Method setResolvableProfileMethod = ReflectionUtil.searchMethod(craftMetaSkullClass, void.class, ResolvableProfile.class);
52+
if (setResolvableProfileMethod != null) {
53+
setProfile = (meta, profile) -> {
54+
try {
55+
setResolvableProfileMethod.invoke(meta, new ResolvableProfile(profile));
56+
} catch (IllegalAccessException | InvocationTargetException e) {
57+
e.printStackTrace();
58+
}
59+
};
60+
} else {
61+
Method setProfileMethod = ReflectionUtil.searchMethod(craftMetaSkullClass, void.class, GameProfile.class);
62+
if (setProfileMethod != null) {
63+
setProfile = (meta, profile) -> {
64+
try {
65+
setProfileMethod.invoke(meta, profile);
66+
} catch (IllegalAccessException | InvocationTargetException e) {
67+
e.printStackTrace();
68+
}
69+
};
70+
}
71+
}
72+
73+
SET_PROFILE = setProfile;
74+
}
75+
76+
public byte[] nbtToBinary(CompoundTag compound) {
77+
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
78+
NbtIo.writeCompressed(compound, outputStream);
79+
return outputStream.toByteArray();
80+
} catch (Exception e) {
81+
e.printStackTrace();
82+
}
83+
return null;
84+
}
85+
86+
public CompoundTag binaryToNBT(byte[] binary) {
87+
try (ByteArrayInputStream inputStream = new ByteArrayInputStream(binary)) {
88+
return NbtIo.readCompressed(inputStream, NbtAccounter.unlimitedHeap());
89+
} catch (Exception e) {
90+
e.printStackTrace();
91+
}
92+
return new CompoundTag();
93+
}
94+
95+
@Override
96+
public byte[] itemstackToBinary(ItemStack[] items) {
97+
CompoundTag inventory = new CompoundTag();
98+
ListTag list = new ListTag();
99+
for (ItemStack itemStack : items) {
100+
if (itemStack == null || itemStack.getType() == Material.AIR) {
101+
list.add(NBT_EMPTY_ITEMSTACK);
102+
} else {
103+
net.minecraft.world.item.ItemStack craftItem = CraftItemStack.asNMSCopy(itemStack);
104+
Tag tag = craftItem.save(DEFAULT_REGISTRY);
105+
list.add(tag);
106+
}
107+
}
108+
inventory.put("i", list);
109+
return nbtToBinary(inventory);
110+
}
111+
112+
@Override
113+
public List<ItemStack> binaryToItemStack(byte[] binary) {
114+
CompoundTag nbt = binaryToNBT(binary);
115+
List<ItemStack> items = new ArrayList<>();
116+
if (nbt.contains("i")) {
117+
Optional<ListTag> list = nbt.getList("i");
118+
if (list.isEmpty()) {
119+
return items;
120+
}
121+
122+
for (Tag base : list.get()) {
123+
if (base instanceof CompoundTag itemTag) {
124+
String itemType = itemTag.getString("id").orElse("");
125+
if (itemType.equals("minecraft:air")) {
126+
items.add(new ItemStack(Material.AIR));
127+
} else {
128+
Optional<net.minecraft.world.item.ItemStack> optional = net.minecraft.world.item.ItemStack.parse(DEFAULT_REGISTRY, itemTag);
129+
if (optional.isPresent()) {
130+
items.add(CraftItemStack.asBukkitCopy(optional.get()));
131+
}
132+
}
133+
}
134+
}
135+
}
136+
return items;
137+
}
138+
139+
@Override
140+
public void setSkullProfile(SkullMeta meta, String texture) {
141+
try {
142+
GameProfile gameProfile = new GameProfile(UUID.randomUUID(), "");
143+
gameProfile.getProperties().put("textures", new Property("textures", texture));
144+
145+
SET_PROFILE.accept(meta, gameProfile);
146+
} catch (Exception e) {
147+
e.printStackTrace();
148+
}
149+
}
150+
151+
@Override
152+
public boolean isAir(Material material) {
153+
return material == null || material == Material.AIR;
154+
}
155+
}

zip-plugin/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,5 +107,11 @@
107107
<version>${revision}</version>
108108
<scope>compile</scope>
109109
</dependency>
110+
<dependency>
111+
<groupId>net.imprex</groupId>
112+
<artifactId>zip-nms-v1_21_R4</artifactId>
113+
<version>${revision}</version>
114+
<scope>compile</scope>
115+
</dependency>
110116
</dependencies>
111117
</project>

0 commit comments

Comments
 (0)