Skip to content

Commit c9b76e7

Browse files
authored
Feat: support 1.20.2 (#10)
* feat: support 1.20.2 * fix: buildtools missing 1.20.2 * fix: mvn missing 1.20.1 import
1 parent e977503 commit c9b76e7

File tree

6 files changed

+177
-7
lines changed

6 files changed

+177
-7
lines changed

.github/workflows/buildtools.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@ checkVersion () {
2828
checkVersion "1.19" "17"
2929
checkVersion "1.19.3" "17"
3030
checkVersion "1.19.4" "17"
31-
checkVersion "1.20" "17"
31+
checkVersion "1.20.1" "17"
32+
checkVersion "1.20.2" "17"

zip-nms/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@
1616
<module>zip-nms-v1_19_R2</module>
1717
<module>zip-nms-v1_19_R3</module>
1818
<module>zip-nms-v1_20_R1</module>
19+
<module>zip-nms-v1_20_R2</module>
1920
</modules>
2021
</project>

zip-nms/zip-nms-v1_20_R1/pom.xml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
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">
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
24
<modelVersion>4.0.0</modelVersion>
35

46
<parent>
@@ -20,7 +22,7 @@
2022
<dependency>
2123
<groupId>org.spigotmc</groupId>
2224
<artifactId>spigot</artifactId>
23-
<version>1.20-R0.1-SNAPSHOT</version>
25+
<version>1.20.1-R0.1-SNAPSHOT</version>
2426
<classifier>remapped-mojang</classifier>
2527
<scope>provided</scope>
2628
</dependency>
@@ -40,9 +42,9 @@
4042
</goals>
4143
<id>remap-obf</id>
4244
<configuration>
43-
<srgIn>org.spigotmc:minecraft-server:1.20-R0.1-SNAPSHOT:txt:maps-mojang</srgIn>
45+
<srgIn>org.spigotmc:minecraft-server:1.20.1-R0.1-SNAPSHOT:txt:maps-mojang</srgIn>
4446
<reverse>true</reverse>
45-
<remappedDependencies>org.spigotmc:spigot:1.20-R0.1-SNAPSHOT:jar:remapped-mojang</remappedDependencies>
47+
<remappedDependencies>org.spigotmc:spigot:1.20.1-R0.1-SNAPSHOT:jar:remapped-mojang</remappedDependencies>
4648
<remappedArtifactAttached>true</remappedArtifactAttached>
4749
<remappedClassifierName>remapped-obf</remappedClassifierName>
4850
</configuration>
@@ -55,8 +57,8 @@
5557
<id>remap-spigot</id>
5658
<configuration>
5759
<inputFile>${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar</inputFile>
58-
<srgIn>org.spigotmc:minecraft-server:1.20-R0.1-SNAPSHOT:csrg:maps-spigot</srgIn>
59-
<remappedDependencies>org.spigotmc:spigot:1.20-R0.1-SNAPSHOT:jar:remapped-obf</remappedDependencies>
60+
<srgIn>org.spigotmc:minecraft-server:1.20.1-R0.1-SNAPSHOT:csrg:maps-spigot</srgIn>
61+
<remappedDependencies>org.spigotmc:spigot:1.20.1-R0.1-SNAPSHOT:jar:remapped-obf</remappedDependencies>
6062
</configuration>
6163
</execution>
6264
</executions>

zip-nms/zip-nms-v1_20_R2/pom.xml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<parent>
7+
<groupId>net.imprex</groupId>
8+
<artifactId>zip-nms</artifactId>
9+
<version>${revision}</version>
10+
</parent>
11+
12+
<artifactId>zip-nms-v1_20_R2</artifactId>
13+
<packaging>jar</packaging>
14+
15+
<dependencies>
16+
<dependency>
17+
<groupId>net.imprex</groupId>
18+
<artifactId>zip-nms-api</artifactId>
19+
<version>${revision}</version>
20+
<scope>provided</scope>
21+
</dependency>
22+
<dependency>
23+
<groupId>org.spigotmc</groupId>
24+
<artifactId>spigot</artifactId>
25+
<version>1.20.2-R0.1-SNAPSHOT</version>
26+
<classifier>remapped-mojang</classifier>
27+
<scope>provided</scope>
28+
</dependency>
29+
</dependencies>
30+
31+
<build>
32+
<plugins>
33+
<plugin>
34+
<groupId>net.md-5</groupId>
35+
<artifactId>specialsource-maven-plugin</artifactId>
36+
<version>${plugin.specialsource.version}</version>
37+
<executions>
38+
<execution>
39+
<phase>package</phase>
40+
<goals>
41+
<goal>remap</goal>
42+
</goals>
43+
<id>remap-obf</id>
44+
<configuration>
45+
<srgIn>org.spigotmc:minecraft-server:1.20.2-R0.1-SNAPSHOT:txt:maps-mojang</srgIn>
46+
<reverse>true</reverse>
47+
<remappedDependencies>org.spigotmc:spigot:1.20.2-R0.1-SNAPSHOT:jar:remapped-mojang</remappedDependencies>
48+
<remappedArtifactAttached>true</remappedArtifactAttached>
49+
<remappedClassifierName>remapped-obf</remappedClassifierName>
50+
</configuration>
51+
</execution>
52+
<execution>
53+
<phase>package</phase>
54+
<goals>
55+
<goal>remap</goal>
56+
</goals>
57+
<id>remap-spigot</id>
58+
<configuration>
59+
<inputFile>${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar</inputFile>
60+
<srgIn>org.spigotmc:minecraft-server:1.20.2-R0.1-SNAPSHOT:csrg:maps-spigot</srgIn>
61+
<remappedDependencies>org.spigotmc:spigot:1.20.2-R0.1-SNAPSHOT:jar:remapped-obf</remappedDependencies>
62+
</configuration>
63+
</execution>
64+
</executions>
65+
</plugin>
66+
</plugins>
67+
</build>
68+
</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_20_R2;
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_20_R2.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
@@ -71,5 +71,11 @@
7171
<version>${revision}</version>
7272
<scope>compile</scope>
7373
</dependency>
74+
<dependency>
75+
<groupId>net.imprex</groupId>
76+
<artifactId>zip-nms-v1_20_R2</artifactId>
77+
<version>${revision}</version>
78+
<scope>compile</scope>
79+
</dependency>
7480
</dependencies>
7581
</project>

0 commit comments

Comments
 (0)