mirror of
https://github.com/GeyserExtensionists/GeyserUtils.git
synced 2025-12-20 07:29:22 +00:00
fix
This commit is contained in:
@@ -79,13 +79,13 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.geysermc.geyser</groupId>
|
<groupId>org.geysermc.geyser</groupId>
|
||||||
<artifactId>api</artifactId>
|
<artifactId>api</artifactId>
|
||||||
<version>2.2.2-SNAPSHOT</version>
|
<version>2.2.3-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.geysermc.geyser</groupId>
|
<groupId>org.geysermc.geyser</groupId>
|
||||||
<artifactId>core</artifactId>
|
<artifactId>core</artifactId>
|
||||||
<version>2.2.2-SNAPSHOT</version>
|
<version>2.2.3-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import com.github.steveice10.packetlib.event.session.SessionAdapter;
|
|||||||
import com.github.steveice10.packetlib.packet.Packet;
|
import com.github.steveice10.packetlib.packet.Packet;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
import it.unimi.dsi.fastutil.bytes.ByteArrays;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import me.zimzaza4.geyserutils.common.camera.data.CameraPreset;
|
import me.zimzaza4.geyserutils.common.camera.data.CameraPreset;
|
||||||
import me.zimzaza4.geyserutils.common.camera.instruction.ClearInstruction;
|
import me.zimzaza4.geyserutils.common.camera.instruction.ClearInstruction;
|
||||||
@@ -49,6 +48,8 @@ import java.io.IOException;
|
|||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class GeyserUtils implements Extension {
|
public class GeyserUtils implements Extension {
|
||||||
@@ -61,15 +62,21 @@ public class GeyserUtils implements Extension {
|
|||||||
@Getter
|
@Getter
|
||||||
public static Map<String, SkinProvider.SkinData> LOADED_SKIN_DATA = new HashMap<>();
|
public static Map<String, SkinProvider.SkinData> LOADED_SKIN_DATA = new HashMap<>();
|
||||||
|
|
||||||
static final SkinProvider.Cape EMPTY_CAPE = new SkinProvider.Cape("", "no-cape", ByteArrays.EMPTY_ARRAY, -1, true);
|
static SkinProvider.Cape EMPTY_CAPE = new SkinProvider.Cape("", "no-cape", new byte[0], -1, true);
|
||||||
|
;
|
||||||
|
|
||||||
|
public static final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(2);
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onLoad(GeyserPostInitializeEvent event) {
|
public void onLoad(GeyserPostInitializeEvent event) {
|
||||||
|
|
||||||
packetManager = new PacketManager();
|
packetManager = new PacketManager();
|
||||||
CameraPreset.load();
|
|
||||||
Registries.BEDROCK_PACKET_TRANSLATORS.register(NpcRequestPacket.class, new NPCFormResponseTranslator());
|
Registries.BEDROCK_PACKET_TRANSLATORS.register(NpcRequestPacket.class, new NPCFormResponseTranslator());
|
||||||
|
logger().info("Loading Skins:");
|
||||||
loadSkins();
|
loadSkins();
|
||||||
|
|
||||||
|
CameraPreset.load();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -106,7 +113,7 @@ public class GeyserUtils implements Extension {
|
|||||||
}
|
}
|
||||||
String geoName = "{\"geometry\" :{\"default\" :\"" + geoId + "\"}}";
|
String geoName = "{\"geometry\" :{\"default\" :\"" + geoId + "\"}}";
|
||||||
SkinProvider.SkinGeometry geometry = new SkinProvider.SkinGeometry(geoName, Files.readString(geometryFile.toPath()), false);
|
SkinProvider.SkinGeometry geometry = new SkinProvider.SkinGeometry(geoName, Files.readString(geometryFile.toPath()), false);
|
||||||
LOADED_SKIN_DATA.put(file.getName(), new SkinProvider.SkinData(skin, EMPTY_CAPE, geometry));
|
LOADED_SKIN_DATA.put(file.getName(), new SkinProvider.SkinData(skin, getEmptyCapeData(), geometry));
|
||||||
this.logger().info("Loaded skin: " + file.getName() + "| geo:" + geoName);
|
this.logger().info("Loaded skin: " + file.getName() + "| geo:" + geoName);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -118,9 +125,19 @@ public class GeyserUtils implements Extension {
|
|||||||
@Subscribe
|
@Subscribe
|
||||||
public void onSessionJoin(SessionLoginEvent event) {
|
public void onSessionJoin(SessionLoginEvent event) {
|
||||||
if (event.connection() instanceof GeyserSession session) {
|
if (event.connection() instanceof GeyserSession session) {
|
||||||
GeyserImpl.getInstance().getScheduledThread()
|
registerPacketListener(session);
|
||||||
.schedule(() -> session.getDownstream().getSession().addListener(new SessionAdapter() {
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void registerPacketListener(GeyserSession session) {
|
||||||
|
|
||||||
|
scheduler.schedule(() -> {
|
||||||
|
if (session.getDownstream() == null) {
|
||||||
|
registerPacketListener(session);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
session.getDownstream().getSession().addListener(new SessionAdapter() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void packetSending(PacketSendingEvent event) {
|
public void packetSending(PacketSendingEvent event) {
|
||||||
@@ -141,7 +158,7 @@ public class GeyserUtils implements Extension {
|
|||||||
if (payloadPacket.getChannel().equals(GeyserUtilsChannels.MAIN)) {
|
if (payloadPacket.getChannel().equals(GeyserUtilsChannels.MAIN)) {
|
||||||
CustomPayloadPacket customPacket = packetManager.decodePacket(payloadPacket.getData());
|
CustomPayloadPacket customPacket = packetManager.decodePacket(payloadPacket.getData());
|
||||||
if (customPacket instanceof CameraShakeCustomPayloadPacket cameraShakePacket) {
|
if (customPacket instanceof CameraShakeCustomPayloadPacket cameraShakePacket) {
|
||||||
event.connection().camera().shakeCamera(cameraShakePacket.getIntensity(), cameraShakePacket.getDuration(), CameraShake.values()[cameraShakePacket.getType()]);
|
session.camera().shakeCamera(cameraShakePacket.getIntensity(), cameraShakePacket.getDuration(), CameraShake.values()[cameraShakePacket.getType()]);
|
||||||
} else if (customPacket instanceof NpcDialogueFormDataCustomPayloadPacket formData) {
|
} else if (customPacket instanceof NpcDialogueFormDataCustomPayloadPacket formData) {
|
||||||
|
|
||||||
if (formData.action().equals("CLOSE")) {
|
if (formData.action().equals("CLOSE")) {
|
||||||
@@ -192,7 +209,14 @@ public class GeyserUtils implements Extension {
|
|||||||
for (int id : animateEntityCustomPayloadPacket.getEntityJavaIds()) {
|
for (int id : animateEntityCustomPayloadPacket.getEntityJavaIds()) {
|
||||||
Entity entity = session.getEntityCache().getEntityByJavaId(id);
|
Entity entity = session.getEntityCache().getEntityByJavaId(id);
|
||||||
if (entity != null) {
|
if (entity != null) {
|
||||||
animateEntityPacket.getRuntimeEntityIds().add(entity.getGeyserId());
|
try {
|
||||||
|
// because of shaded jar
|
||||||
|
Object object = AnimateEntityPacket.class.getMethod("getRuntimeEntityIds").invoke(animateEntityPacket);
|
||||||
|
object.getClass().getMethod("add", Long.class).invoke(object, entity.getGeyserId());
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
session.sendUpstreamPacket(animateEntityPacket);
|
session.sendUpstreamPacket(animateEntityPacket);
|
||||||
@@ -233,6 +257,11 @@ public class GeyserUtils implements Extension {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
}, 80, TimeUnit.MILLISECONDS);
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static AnimateEntityPacket getAnimateEntityPacket(AnimateEntityCustomPayloadPacket animateEntityCustomPayloadPacket) {
|
private static AnimateEntityPacket getAnimateEntityPacket(AnimateEntityCustomPayloadPacket animateEntityCustomPayloadPacket) {
|
||||||
AnimateEntityPacket animateEntityPacket = new AnimateEntityPacket();
|
AnimateEntityPacket animateEntityPacket = new AnimateEntityPacket();
|
||||||
@@ -244,11 +273,6 @@ public class GeyserUtils implements Extension {
|
|||||||
animateEntityPacket.setStopExpression(animateEntityCustomPayloadPacket.getStopExpression());
|
animateEntityPacket.setStopExpression(animateEntityCustomPayloadPacket.getStopExpression());
|
||||||
return animateEntityPacket;
|
return animateEntityPacket;
|
||||||
}
|
}
|
||||||
}), 100, TimeUnit.MILLISECONDS);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void sendSkinPacket(GeyserSession session, PlayerEntity entity, SkinProvider.SkinData skinData) {
|
public static void sendSkinPacket(GeyserSession session, PlayerEntity entity, SkinProvider.SkinData skinData) {
|
||||||
SkinProvider.Skin skin = skinData.skin();
|
SkinProvider.Skin skin = skinData.skin();
|
||||||
@@ -308,5 +332,9 @@ public class GeyserUtils implements Extension {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static SkinProvider.Cape getEmptyCapeData() {
|
||||||
|
return EMPTY_CAPE;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user