mirror of
https://github.com/GeyserExtensionists/GeyserUtils.git
synced 2025-12-19 15:09:24 +00:00
fix
This commit is contained in:
@@ -79,13 +79,13 @@
|
||||
<dependency>
|
||||
<groupId>org.geysermc.geyser</groupId>
|
||||
<artifactId>api</artifactId>
|
||||
<version>2.2.2-SNAPSHOT</version>
|
||||
<version>2.2.3-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geysermc.geyser</groupId>
|
||||
<artifactId>core</artifactId>
|
||||
<version>2.2.2-SNAPSHOT</version>
|
||||
<version>2.2.3-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
||||
@@ -8,7 +8,6 @@ import com.github.steveice10.packetlib.event.session.SessionAdapter;
|
||||
import com.github.steveice10.packetlib.packet.Packet;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParser;
|
||||
import it.unimi.dsi.fastutil.bytes.ByteArrays;
|
||||
import lombok.Getter;
|
||||
import me.zimzaza4.geyserutils.common.camera.data.CameraPreset;
|
||||
import me.zimzaza4.geyserutils.common.camera.instruction.ClearInstruction;
|
||||
@@ -49,6 +48,8 @@ import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class GeyserUtils implements Extension {
|
||||
@@ -61,15 +62,21 @@ public class GeyserUtils implements Extension {
|
||||
@Getter
|
||||
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
|
||||
public void onLoad(GeyserPostInitializeEvent event) {
|
||||
|
||||
packetManager = new PacketManager();
|
||||
CameraPreset.load();
|
||||
Registries.BEDROCK_PACKET_TRANSLATORS.register(NpcRequestPacket.class, new NPCFormResponseTranslator());
|
||||
logger().info("Loading Skins:");
|
||||
loadSkins();
|
||||
|
||||
CameraPreset.load();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -106,7 +113,7 @@ public class GeyserUtils implements Extension {
|
||||
}
|
||||
String geoName = "{\"geometry\" :{\"default\" :\"" + geoId + "\"}}";
|
||||
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);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@@ -118,9 +125,19 @@ public class GeyserUtils implements Extension {
|
||||
@Subscribe
|
||||
public void onSessionJoin(SessionLoginEvent event) {
|
||||
if (event.connection() instanceof GeyserSession session) {
|
||||
GeyserImpl.getInstance().getScheduledThread()
|
||||
.schedule(() -> session.getDownstream().getSession().addListener(new SessionAdapter() {
|
||||
registerPacketListener(session);
|
||||
}
|
||||
}
|
||||
|
||||
public void registerPacketListener(GeyserSession session) {
|
||||
|
||||
scheduler.schedule(() -> {
|
||||
if (session.getDownstream() == null) {
|
||||
registerPacketListener(session);
|
||||
return;
|
||||
}
|
||||
|
||||
session.getDownstream().getSession().addListener(new SessionAdapter() {
|
||||
|
||||
@Override
|
||||
public void packetSending(PacketSendingEvent event) {
|
||||
@@ -141,7 +158,7 @@ public class GeyserUtils implements Extension {
|
||||
if (payloadPacket.getChannel().equals(GeyserUtilsChannels.MAIN)) {
|
||||
CustomPayloadPacket customPacket = packetManager.decodePacket(payloadPacket.getData());
|
||||
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) {
|
||||
|
||||
if (formData.action().equals("CLOSE")) {
|
||||
@@ -192,7 +209,14 @@ public class GeyserUtils implements Extension {
|
||||
for (int id : animateEntityCustomPayloadPacket.getEntityJavaIds()) {
|
||||
Entity entity = session.getEntityCache().getEntityByJavaId(id);
|
||||
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);
|
||||
@@ -233,6 +257,11 @@ public class GeyserUtils implements Extension {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
}, 80, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static AnimateEntityPacket getAnimateEntityPacket(AnimateEntityCustomPayloadPacket animateEntityCustomPayloadPacket) {
|
||||
AnimateEntityPacket animateEntityPacket = new AnimateEntityPacket();
|
||||
@@ -244,11 +273,6 @@ public class GeyserUtils implements Extension {
|
||||
animateEntityPacket.setStopExpression(animateEntityCustomPayloadPacket.getStopExpression());
|
||||
return animateEntityPacket;
|
||||
}
|
||||
}), 100, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static void sendSkinPacket(GeyserSession session, PlayerEntity entity, SkinProvider.SkinData skinData) {
|
||||
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