Skip to content

Commit 3ba08cd

Browse files
author
lukas81298
committed
Merge branch 'master' into 1.20
# Conflicts: # README.md # pom.xml
2 parents 1bb39ba + 847bd66 commit 3ba08cd

File tree

119 files changed

+1272
-276
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

119 files changed

+1272
-276
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Enter PacketWrapper. It contains wrapper classes for all known packets in 1.19.4
1616

1717
#### Maven:
1818

19-
First, add this repository
19+
First add my repository to your pom.xml so Maven can find the library.
2020

2121
```
2222
<repositories>
@@ -27,7 +27,7 @@ First, add this repository
2727
</repositories>
2828
```
2929

30-
Then, include the actual dependency
30+
First add my repository so Gradle can find the dependency:
3131

3232
```
3333
<dependencies>
@@ -60,7 +60,7 @@ Then add the actual dependency:
6060
```
6161
dependencies {
6262
...
63-
compile 'com.comphenix.packetwrapper:PacketWrapper:1.20-2.2.0-SNAPSHOT'
63+
compile 'com.comphenix.packetwrapper:PacketWrapper:1.20-2.2.0'
6464
}
6565
```
6666

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>com.comphenix.packetwrapper</groupId>
66
<artifactId>PacketWrapper</artifactId>
7-
<version>1.20-2.1.1-SNAPSHOT</version>
7+
<version>1.20-2.2.0-SNAPSHOT</version>
88

99
<name>PacketWrapper</name>
1010

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.comphenix.packetwrapper.util;
2+
3+
import com.comphenix.protocol.reflect.FuzzyReflection;
4+
import com.comphenix.protocol.reflect.accessors.Accessors;
5+
import com.comphenix.protocol.reflect.accessors.MethodAccessor;
6+
import com.comphenix.protocol.utility.MinecraftReflection;
7+
import com.comphenix.protocol.wrappers.WrappedChatComponent;
8+
9+
public class ReflectiveAdventureComponentConverter {
10+
private static final Class<?> COMPONENT_CLASS = MinecraftReflection.getLibraryClass("net.kyori.adventure.text.Component");
11+
private static final Class<?> GSON_COMPONENT_SERIALIZER_CLASS = MinecraftReflection.getLibraryClass("net.kyori.adventure.text.serializer.gson.GsonComponentSerializer");
12+
private static final Class<?> COMPONENT_SERIALIZER_CLASS = MinecraftReflection.getLibraryClass("net.kyori.adventure.text.serializer.ComponentSerializer");
13+
14+
private static final MethodAccessor GET_GSON_SERIALIZER_METHOD = Accessors.getMethodAccessor(GSON_COMPONENT_SERIALIZER_CLASS, "gson");
15+
private static final MethodAccessor DESERIALIZE_METHOD = Accessors.getMethodAccessor(FuzzyReflection.fromClass(COMPONENT_SERIALIZER_CLASS, false).getMethodByName("deserializeOrNull"));
16+
private static final MethodAccessor SERIALIZE_METHOD = Accessors.getMethodAccessor(FuzzyReflection.fromClass(COMPONENT_SERIALIZER_CLASS, false).getMethodByName("serialize"));
17+
18+
private static Object GSON_SERIALIZER;
19+
20+
private static Object getGsonSerializer() {
21+
if(GSON_SERIALIZER == null) {
22+
GSON_SERIALIZER = GET_GSON_SERIALIZER_METHOD.invoke(null);
23+
}
24+
return GSON_SERIALIZER;
25+
}
26+
27+
public static Object fromWrapper(WrappedChatComponent wrapper) {
28+
return DESERIALIZE_METHOD.invoke(getGsonSerializer(), wrapper.getJson());
29+
}
30+
31+
public static WrappedChatComponent fromComponent(Object component) {
32+
return WrappedChatComponent.fromJson((String)SERIALIZE_METHOD.invoke(getGsonSerializer(), component));
33+
}
34+
35+
public static String componentToString(Object component) {
36+
return (String)SERIALIZE_METHOD.invoke(getGsonSerializer(), component);
37+
}
38+
39+
public static Class<?> getComponentClass() {
40+
return COMPONENT_CLASS;
41+
}
42+
}

src/main/java/com/comphenix/packetwrapper/wrappers/handshaking/WrapperHandshakingClientSetProtocol.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
public class WrapperHandshakingClientSetProtocol extends AbstractPacket {
99

10+
/**
11+
* The packet type that is wrapped by this wrapper.
12+
*/
1013
public static final PacketType TYPE = PacketType.Handshake.Client.SET_PROTOCOL;
1114

1215
public WrapperHandshakingClientSetProtocol() {

src/main/java/com/comphenix/packetwrapper/wrappers/play/clientbound/WrapperPlayServerAbilities.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
import com.comphenix.protocol.events.PacketContainer;
66

77
public class WrapperPlayServerAbilities extends AbstractPacket {
8-
8+
/**
9+
* The packet type that is wrapped by this wrapper.
10+
*/
911
public static final PacketType TYPE = PacketType.Play.Server.ABILITIES;
1012

1113
/**
@@ -17,6 +19,7 @@ public WrapperPlayServerAbilities() {
1719

1820
/**
1921
* Constructors a new wrapper for the specified packet
22+
*
2023
* @param packet the packet to wrap
2124
*/
2225
public WrapperPlayServerAbilities(PacketContainer packet) {

src/main/java/com/comphenix/packetwrapper/wrappers/play/clientbound/WrapperPlayServerAdvancements.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
import java.util.Set;
1111

1212
public class WrapperPlayServerAdvancements extends AbstractPacket {
13-
13+
/**
14+
* The packet type that is wrapped by this wrapper.
15+
*/
1416
public static final PacketType TYPE = PacketType.Play.Server.ADVANCEMENTS;
1517

1618
/**
@@ -22,6 +24,7 @@ public WrapperPlayServerAdvancements() {
2224

2325
/**
2426
* Constructors a new wrapper for the specified packet
27+
*
2528
* @param packet the packet to wrap
2629
*/
2730
public WrapperPlayServerAdvancements(PacketContainer packet) {

src/main/java/com/comphenix/packetwrapper/wrappers/play/clientbound/WrapperPlayServerAnimation.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
*/
1212
public class WrapperPlayServerAnimation extends AbstractPacket {
1313

14+
/**
15+
* The packet type that is wrapped by this wrapper.
16+
*/
1417
public static final PacketType TYPE = PacketType.Play.Server.ANIMATION;
1518

1619
/**
@@ -22,6 +25,7 @@ public WrapperPlayServerAnimation() {
2225

2326
/**
2427
* Constructors a new wrapper for the specified packet
28+
*
2529
* @param packet the packet to wrap
2630
*/
2731
public WrapperPlayServerAnimation(PacketContainer packet) {
@@ -66,14 +70,13 @@ public Animation getAction() {
6670
}
6771

6872

69-
7073
/**
7174
* Sets the numerical index of the corresponding animation
7275
*
7376
* @param value New value for field 'action'
7477
*/
7578
public void setActionId(int value) {
76-
this.handle.getIntegers().write(1, value);
79+
this.handle.getIntegers().write(1, value);
7780
}
7881

7982
/**

src/main/java/com/comphenix/packetwrapper/wrappers/play/clientbound/WrapperPlayServerAttachEntity.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
public class WrapperPlayServerAttachEntity extends AbstractPacket {
88

9+
/**
10+
* The packet type that is wrapped by this wrapper.
11+
*/
912
public static final PacketType TYPE = PacketType.Play.Server.ATTACH_ENTITY;
1013

1114
/**
@@ -17,6 +20,7 @@ public WrapperPlayServerAttachEntity() {
1720

1821
/**
1922
* Constructors a new wrapper for the specified packet
23+
*
2024
* @param packet the packet to wrap
2125
*/
2226
public WrapperPlayServerAttachEntity(PacketContainer packet) {

src/main/java/com/comphenix/packetwrapper/wrappers/play/clientbound/WrapperPlayServerAutoRecipe.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
public class WrapperPlayServerAutoRecipe extends AbstractPacket {
99

10+
/**
11+
* The packet type that is wrapped by this wrapper.
12+
*/
1013
public static final PacketType TYPE = PacketType.Play.Server.AUTO_RECIPE;
1114

1215
/**
@@ -18,6 +21,7 @@ public WrapperPlayServerAutoRecipe() {
1821

1922
/**
2023
* Constructors a new wrapper for the specified packet
24+
*
2125
* @param packet the packet to wrap
2226
*/
2327
public WrapperPlayServerAutoRecipe(PacketContainer packet) {

src/main/java/com/comphenix/packetwrapper/wrappers/play/clientbound/WrapperPlayServerBlockAction.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
*/
1414
public class WrapperPlayServerBlockAction extends AbstractPacket {
1515

16+
/**
17+
* The packet type that is wrapped by this wrapper.
18+
*/
1619
public static final PacketType TYPE = PacketType.Play.Server.BLOCK_ACTION;
1720

1821
/**
@@ -24,6 +27,7 @@ public WrapperPlayServerBlockAction() {
2427

2528
/**
2629
* Constructors a new wrapper for the specified packet
30+
*
2731
* @param packet the packet to wrap
2832
*/
2933
public WrapperPlayServerBlockAction(PacketContainer packet) {

0 commit comments

Comments
 (0)