mirror of
https://github.com/GeyserExtensionists/GeyserUtils.git
synced 2025-12-19 15:09:24 +00:00
well
This commit is contained in:
@@ -17,6 +17,42 @@
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.4.1</version>
|
||||
<configuration>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>com.fasterxml.jackson</pattern>
|
||||
<shadedPattern>me.zimzaza4.geyserutils.relocations.jackson</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
@@ -26,9 +62,14 @@
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.esotericsoftware</groupId>
|
||||
<artifactId>kryo</artifactId>
|
||||
<version>5.5.0</version>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-core</artifactId>
|
||||
<version>2.15.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.15.2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.util.List;
|
||||
@Setter
|
||||
@Getter
|
||||
@Accessors( fluent = true )
|
||||
public class NpcDialogueButton implements Serializable {
|
||||
public class NpcDialogueButton {
|
||||
private String text;
|
||||
private List<String> commands;
|
||||
private ButtonMode mode;
|
||||
|
||||
@@ -1,41 +1,41 @@
|
||||
package me.zimzaza4.geyserutils.common.manager;
|
||||
|
||||
import com.esotericsoftware.kryo.Kryo;
|
||||
import com.esotericsoftware.kryo.io.Input;
|
||||
import com.esotericsoftware.kryo.io.Output;
|
||||
import me.zimzaza4.geyserutils.common.packet.CameraShakeCustomPayloadPacket;
|
||||
import me.zimzaza4.geyserutils.common.packet.CustomPayloadPacket;
|
||||
import me.zimzaza4.geyserutils.common.packet.NpcDialogueFormDataCustomPayloadPacket;
|
||||
|
||||
import java.io.*;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.jsontype.BasicPolymorphicTypeValidator;
|
||||
import com.fasterxml.jackson.databind.jsontype.PolymorphicTypeValidator;
|
||||
import me.zimzaza4.geyserutils.common.packet.CustomPayloadPacket;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class PacketManager {
|
||||
|
||||
private final Kryo kryo = new Kryo();
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
public PacketManager() {
|
||||
init();
|
||||
objectMapper = new ObjectMapper();
|
||||
objectMapper.enableDefaultTyping(ObjectMapper.DefaultTyping.EVERYTHING, JsonTypeInfo.As.PROPERTY);
|
||||
}
|
||||
|
||||
public void init() {
|
||||
kryo.setRegistrationRequired(false);
|
||||
}
|
||||
public void registerPacket(Class<? extends CustomPayloadPacket> clazz) {
|
||||
kryo.register(clazz);
|
||||
}
|
||||
|
||||
public byte[] encodePacket(CustomPayloadPacket packet) {
|
||||
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
||||
try (Output output = new Output()) {
|
||||
kryo.writeObject(output, packet);
|
||||
return byteArrayOutputStream.toByteArray();
|
||||
|
||||
try {
|
||||
return objectMapper.writeValueAsBytes(packet);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public CustomPayloadPacket decodePacket(byte[] bytes) {
|
||||
try (Input input = new Input(bytes)) {
|
||||
return kryo.readObject(input, CustomPayloadPacket.class);
|
||||
try {
|
||||
return objectMapper.readValue(bytes, CustomPayloadPacket.class);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,11 @@ package me.zimzaza4.geyserutils.common.packet;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class CameraShakeCustomPayloadPacket extends CustomPayloadPacket {
|
||||
|
||||
float intensity;
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
package me.zimzaza4.geyserutils.common.packet;
|
||||
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public abstract class CustomPayloadPacket implements Serializable {
|
||||
public abstract class CustomPayloadPacket {
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package me.zimzaza4.geyserutils.common.packet;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.Accessors;
|
||||
import me.zimzaza4.geyserutils.common.form.element.NpcDialogueButton;
|
||||
@@ -9,6 +10,7 @@ import me.zimzaza4.geyserutils.common.form.element.NpcDialogueButton;
|
||||
import java.util.List;
|
||||
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Accessors(fluent = true)
|
||||
@Getter
|
||||
@Setter
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
package me.zimzaza4.geyserutils.common.util;
|
||||
|
||||
import com.esotericsoftware.kryo.Kryo;
|
||||
import me.zimzaza4.geyserutils.common.packet.CustomPayloadPacket;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public class CustomPayloadPacketUtils {
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user