mirror of
https://github.com/GeyserExtensionists/GeyserUtils.git
synced 2025-12-19 15:09:24 +00:00
register channel
This commit is contained in:
@@ -1,11 +1,7 @@
|
|||||||
package me.zimzaza4.geyserutils.geyser;
|
package me.zimzaza4.geyserutils.geyser;
|
||||||
|
|
||||||
import com.github.steveice10.mc.protocol.data.game.entity.type.EntityType;
|
|
||||||
import com.github.steveice10.mc.protocol.packet.common.clientbound.ClientboundCustomPayloadPacket;
|
import com.github.steveice10.mc.protocol.packet.common.clientbound.ClientboundCustomPayloadPacket;
|
||||||
import com.github.steveice10.mc.protocol.packet.common.serverbound.ServerboundCustomPayloadPacket;
|
import com.github.steveice10.mc.protocol.packet.common.serverbound.ServerboundCustomPayloadPacket;
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundLoginPacket;
|
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.ClientboundDamageEventPacket;
|
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.spawn.ClientboundAddEntityPacket;
|
|
||||||
import com.github.steveice10.packetlib.Session;
|
import com.github.steveice10.packetlib.Session;
|
||||||
import com.github.steveice10.packetlib.event.session.PacketSendingEvent;
|
import com.github.steveice10.packetlib.event.session.PacketSendingEvent;
|
||||||
import com.github.steveice10.packetlib.event.session.SessionAdapter;
|
import com.github.steveice10.packetlib.event.session.SessionAdapter;
|
||||||
@@ -34,7 +30,7 @@ import org.cloudburstmc.protocol.bedrock.packet.*;
|
|||||||
import org.geysermc.event.subscribe.Subscribe;
|
import org.geysermc.event.subscribe.Subscribe;
|
||||||
import org.geysermc.geyser.GeyserImpl;
|
import org.geysermc.geyser.GeyserImpl;
|
||||||
import org.geysermc.geyser.api.bedrock.camera.CameraShake;
|
import org.geysermc.geyser.api.bedrock.camera.CameraShake;
|
||||||
import org.geysermc.geyser.api.event.bedrock.SessionJoinEvent;
|
import org.geysermc.geyser.api.event.bedrock.SessionLoginEvent;
|
||||||
import org.geysermc.geyser.api.event.lifecycle.GeyserPostInitializeEvent;
|
import org.geysermc.geyser.api.event.lifecycle.GeyserPostInitializeEvent;
|
||||||
import org.geysermc.geyser.api.extension.Extension;
|
import org.geysermc.geyser.api.extension.Extension;
|
||||||
import org.geysermc.geyser.entity.type.Entity;
|
import org.geysermc.geyser.entity.type.Entity;
|
||||||
@@ -43,6 +39,7 @@ import org.geysermc.geyser.registry.Registries;
|
|||||||
import org.geysermc.geyser.session.GeyserSession;
|
import org.geysermc.geyser.session.GeyserSession;
|
||||||
import org.geysermc.geyser.skin.SkinProvider;
|
import org.geysermc.geyser.skin.SkinProvider;
|
||||||
import org.geysermc.geyser.util.DimensionUtils;
|
import org.geysermc.geyser.util.DimensionUtils;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
@@ -52,6 +49,7 @@ 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.TimeUnit;
|
||||||
|
|
||||||
public class GeyserUtils implements Extension {
|
public class GeyserUtils implements Extension {
|
||||||
|
|
||||||
@@ -74,6 +72,7 @@ public class GeyserUtils implements Extension {
|
|||||||
loadSkins();
|
loadSkins();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void loadSkins() {
|
public void loadSkins() {
|
||||||
LOADED_SKIN_DATA.clear();
|
LOADED_SKIN_DATA.clear();
|
||||||
File folder = this.dataFolder().resolve("skins").toFile();
|
File folder = this.dataFolder().resolve("skins").toFile();
|
||||||
@@ -117,9 +116,12 @@ public class GeyserUtils implements Extension {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onSessionJoin(SessionJoinEvent event) {
|
public void onSessionJoin(SessionLoginEvent event) {
|
||||||
if (event.connection() instanceof GeyserSession session) {
|
if (event.connection() instanceof GeyserSession session) {
|
||||||
session.getDownstream().getSession().addListener(new SessionAdapter() {
|
GeyserImpl.getInstance().getScheduledThread()
|
||||||
|
.schedule(() -> session.getDownstream().getSession().addListener(new SessionAdapter() {
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void packetSending(PacketSendingEvent event) {
|
public void packetSending(PacketSendingEvent event) {
|
||||||
Packet packet = event.getPacket();
|
Packet packet = event.getPacket();
|
||||||
@@ -132,13 +134,11 @@ public class GeyserUtils implements Extension {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void packetReceived(Session tcpSession, Packet packet) {
|
public void packetReceived(Session tcpSession, Packet packet) {
|
||||||
|
|
||||||
if (packet instanceof ClientboundCustomPayloadPacket payloadPacket) {
|
if (packet instanceof ClientboundCustomPayloadPacket payloadPacket) {
|
||||||
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()]);
|
event.connection().camera().shakeCamera(cameraShakePacket.getIntensity(), cameraShakePacket.getDuration(), CameraShake.values()[cameraShakePacket.getType()]);
|
||||||
@@ -188,13 +188,7 @@ public class GeyserUtils implements Extension {
|
|||||||
form.createAndSend(session);
|
form.createAndSend(session);
|
||||||
|
|
||||||
} else if (customPacket instanceof AnimateEntityCustomPayloadPacket animateEntityCustomPayloadPacket) {
|
} else if (customPacket instanceof AnimateEntityCustomPayloadPacket animateEntityCustomPayloadPacket) {
|
||||||
AnimateEntityPacket animateEntityPacket = new AnimateEntityPacket();
|
AnimateEntityPacket animateEntityPacket = getAnimateEntityPacket(animateEntityCustomPayloadPacket);
|
||||||
animateEntityPacket.setAnimation(animateEntityCustomPayloadPacket.getAnimation());
|
|
||||||
animateEntityPacket.setController(animateEntityCustomPayloadPacket.getController());
|
|
||||||
animateEntityPacket.setBlendOutTime(animateEntityCustomPayloadPacket.getBlendOutTime());
|
|
||||||
animateEntityPacket.setNextState(animateEntityCustomPayloadPacket.getNextState());
|
|
||||||
animateEntityPacket.setStopExpressionVersion(animateEntityCustomPayloadPacket.getStopExpressionVersion());
|
|
||||||
animateEntityPacket.setStopExpression(animateEntityCustomPayloadPacket.getStopExpression());
|
|
||||||
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) {
|
||||||
@@ -238,8 +232,19 @@ public class GeyserUtils implements Extension {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private static AnimateEntityPacket getAnimateEntityPacket(AnimateEntityCustomPayloadPacket animateEntityCustomPayloadPacket) {
|
||||||
|
AnimateEntityPacket animateEntityPacket = new AnimateEntityPacket();
|
||||||
|
animateEntityPacket.setAnimation(animateEntityCustomPayloadPacket.getAnimation());
|
||||||
|
animateEntityPacket.setController(animateEntityCustomPayloadPacket.getController());
|
||||||
|
animateEntityPacket.setBlendOutTime(animateEntityCustomPayloadPacket.getBlendOutTime());
|
||||||
|
animateEntityPacket.setNextState(animateEntityCustomPayloadPacket.getNextState());
|
||||||
|
animateEntityPacket.setStopExpressionVersion(animateEntityCustomPayloadPacket.getStopExpressionVersion());
|
||||||
|
animateEntityPacket.setStopExpression(animateEntityCustomPayloadPacket.getStopExpression());
|
||||||
|
return animateEntityPacket;
|
||||||
|
}
|
||||||
|
}), 100, TimeUnit.MILLISECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user