How to cancel shift input (1.20.6 -> 1.21.3)
TheCalypso opened this issue ยท 1 comments
Make sure you're doing the following
- You're using the latest build for your server version
- This isn't an issue caused by another plugin
- You've checked for duplicate issues
- You didn't use
/reload
Hello everyone !
I have a problem, I cannot cancel the output of my player when he presses the sneak key.
To give context, the player is on a sheep that is moving on its own and I want to cancel the dismount.
Could you help me?
Thanks again for your help <3
Old code (1.20.6):
class MPackets {
static void disablePL() {
ProtocolLibrary.getProtocolManager().removePacketListeners(GMoutrun.getPlugin());
}
static void packetListeners() {
ProtocolLibrary.getProtocolManager().addPacketListener(
new PacketAdapter(GMoutrun.getPlugin(), PacketType.Play.Client.STEER_VEHICLE) {
@Override
public void onPacketReceiving(PacketEvent event) {
var packet = event.getPacket();
var sheepController = SheepController.get(event.getPlayer());
if(sheepController==null) return;
event.setCancelled(true);
packet.getModifier().writeDefaults();
sheepController.setSideway(packet.getFloat().read(0));
}
});
}
}
New code for 1.21.3 :
class MPackets {
static void disablePL() {
ProtocolLibrary.getProtocolManager().removePacketListeners(GMoutrun.getPlugin());
}
static void packetListeners() {
ProtocolLibrary.getProtocolManager().addPacketListener(
new PacketAdapter(GMoutrun.getPlugin(), PacketType.Play.Client.STEER_VEHICLE) {
@Override
public void onPacketReceiving(PacketEvent event) {
PacketContainer packet = event.getPacket();
var sheepController = SheepController.get(event.getPlayer());
if(sheepController == null) return;
event.setCancelled(true);
InternalStructure input = packet.getStructures().read(0);
boolean left = input.getBooleans().read(2);
boolean right = input.getBooleans().read(3);
boolean space = input.getBooleans().read(4);
boolean shift = input.getBooleans().read(5);
float sideway = 0;
if (left) sideway++;
if (right) sideway--;
input.getBooleans().write(5, false);
packet.getModifier().writeDefaults();
sheepController.setSideway(sideway);
}
});
}
}