mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-04 23:47:59 +01:00
Delete outdated packets
This commit is contained in:
parent
17fc62632d
commit
b3692f4f3f
@ -459,8 +459,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
||||
|
||||
// #buildDeathScreenText can return null, check here
|
||||
if (deathText != null) {
|
||||
CombatEventPacket deathPacket = CombatEventPacket.death(this, null, deathText);
|
||||
playerConnection.sendPacket(deathPacket);
|
||||
playerConnection.sendPacket(DeathCombatEventPacket.of(getEntityId(), -1, deathText));
|
||||
}
|
||||
|
||||
// #buildDeathMessage can return null, check here
|
||||
|
@ -8,9 +8,7 @@ import net.minestom.server.inventory.PlayerInventory;
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.network.packet.client.play.ClientClickWindowPacket;
|
||||
import net.minestom.server.network.packet.client.play.ClientCloseWindowPacket;
|
||||
import net.minestom.server.network.packet.client.play.ClientWindowConfirmationPacket;
|
||||
import net.minestom.server.network.packet.server.play.SetSlotPacket;
|
||||
import net.minestom.server.network.packet.server.play.WindowConfirmationPacket;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@ -99,13 +97,6 @@ public class WindowListener {
|
||||
inventory.update(player);
|
||||
}
|
||||
}
|
||||
|
||||
WindowConfirmationPacket windowConfirmationPacket = new WindowConfirmationPacket();
|
||||
windowConfirmationPacket.windowId = windowId;
|
||||
windowConfirmationPacket.actionNumber = actionNumber;
|
||||
windowConfirmationPacket.accepted = successful;
|
||||
|
||||
player.getPlayerConnection().sendPacket(windowConfirmationPacket);
|
||||
}
|
||||
|
||||
public static void closeWindowListener(ClientCloseWindowPacket packet, Player player) {
|
||||
@ -120,10 +111,6 @@ public class WindowListener {
|
||||
player.openInventory(newInventory);
|
||||
}
|
||||
|
||||
public static void windowConfirmationListener(ClientWindowConfirmationPacket packet, Player player) {
|
||||
// Empty
|
||||
}
|
||||
|
||||
/**
|
||||
* @param player the player to refresh the cursor item
|
||||
* @param inventory the player open inventory, null if not any (could be player inventory)
|
||||
|
@ -28,7 +28,6 @@ public final class PacketListenerManager {
|
||||
setListener(ClientChatMessagePacket.class, ChatMessageListener::listener);
|
||||
setListener(ClientClickWindowPacket.class, WindowListener::clickWindowListener);
|
||||
setListener(ClientCloseWindowPacket.class, WindowListener::closeWindowListener);
|
||||
setListener(ClientWindowConfirmationPacket.class, WindowListener::windowConfirmationListener);
|
||||
setListener(ClientEntityActionPacket.class, EntityActionListener::listener);
|
||||
setListener(ClientHeldItemChangePacket.class, PlayerHeldListener::heldListener);
|
||||
setListener(ClientPlayerBlockPlacementPacket.class, BlockPlacementListener::listener);
|
||||
|
@ -1,27 +0,0 @@
|
||||
package net.minestom.server.network.packet.client.play;
|
||||
|
||||
import net.minestom.server.network.packet.client.ClientPlayPacket;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ClientWindowConfirmationPacket extends ClientPlayPacket {
|
||||
|
||||
public byte windowId;
|
||||
public short actionNumber;
|
||||
public boolean accepted;
|
||||
|
||||
@Override
|
||||
public void read(@NotNull BinaryReader reader) {
|
||||
this.windowId = reader.readByte();
|
||||
this.actionNumber = reader.readShort();
|
||||
this.accepted = reader.readBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeByte(windowId);
|
||||
writer.writeShort(actionNumber);
|
||||
writer.writeBoolean(accepted);
|
||||
}
|
||||
}
|
@ -1,129 +0,0 @@
|
||||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.entity.Entity;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.network.packet.server.ComponentHoldingServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
/**
|
||||
* Packet sent during combat to a {@link Player}.
|
||||
* Only death is supported for the moment (other events are ignored anyway as of 1.15.2)
|
||||
*/
|
||||
public class CombatEventPacket implements ComponentHoldingServerPacket {
|
||||
|
||||
private EventType type = EventType.ENTER_COMBAT;
|
||||
private int duration;
|
||||
private int opponent;
|
||||
private int playerID;
|
||||
private Component deathMessage;
|
||||
|
||||
private CombatEventPacket() {
|
||||
}
|
||||
|
||||
public static CombatEventPacket enter() {
|
||||
CombatEventPacket packet = new CombatEventPacket();
|
||||
packet.type = EventType.ENTER_COMBAT;
|
||||
return packet;
|
||||
}
|
||||
|
||||
public static CombatEventPacket end(int durationInTicks, Entity opponent) {
|
||||
CombatEventPacket packet = new CombatEventPacket();
|
||||
packet.type = EventType.END_COMBAT;
|
||||
packet.duration = durationInTicks;
|
||||
packet.opponent = opponent != null ? opponent.getEntityId() : -1;
|
||||
return packet;
|
||||
}
|
||||
|
||||
public static CombatEventPacket death(Player player, Entity killer, Component message) {
|
||||
CombatEventPacket packet = new CombatEventPacket();
|
||||
packet.type = EventType.DEATH;
|
||||
packet.playerID = player.getEntityId();
|
||||
packet.opponent = killer != null ? killer.getEntityId() : -1;
|
||||
packet.deathMessage = message;
|
||||
return packet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeVarInt(type.ordinal());
|
||||
switch (type) {
|
||||
case ENTER_COMBAT:
|
||||
// nothing to add
|
||||
break;
|
||||
|
||||
case END_COMBAT:
|
||||
writer.writeVarInt(duration);
|
||||
writer.writeInt(opponent);
|
||||
break;
|
||||
|
||||
case DEATH:
|
||||
writer.writeVarInt(playerID);
|
||||
writer.writeInt(opponent);
|
||||
writer.writeComponent(deathMessage);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(@NotNull BinaryReader reader) {
|
||||
type = EventType.values()[reader.readVarInt()];
|
||||
switch (type) {
|
||||
case ENTER_COMBAT:
|
||||
// nothing to add
|
||||
break;
|
||||
|
||||
case END_COMBAT:
|
||||
duration = reader.readVarInt();
|
||||
opponent = reader.readInt();
|
||||
break;
|
||||
|
||||
case DEATH:
|
||||
playerID = reader.readVarInt();
|
||||
opponent = reader.readInt();
|
||||
deathMessage = reader.readComponent(Integer.MAX_VALUE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return ServerPacketIdentifier.COMBAT_EVENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Collection<Component> components() {
|
||||
if (this.type == EventType.DEATH) {
|
||||
return Collections.singleton(deathMessage);
|
||||
} else {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ServerPacket copyWithOperator(@NotNull UnaryOperator<Component> operator) {
|
||||
if (this.type == EventType.DEATH) {
|
||||
CombatEventPacket packet = new CombatEventPacket();
|
||||
packet.type = type;
|
||||
packet.playerID = playerID;
|
||||
packet.opponent = opponent;
|
||||
packet.deathMessage = deathMessage;
|
||||
return packet;
|
||||
} else {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public enum EventType {
|
||||
ENTER_COMBAT, END_COMBAT, // both ignored by Notchian client
|
||||
DEATH,
|
||||
}
|
||||
}
|
@ -13,6 +13,14 @@ public class DeathCombatEventPacket implements ServerPacket {
|
||||
public int entityId;
|
||||
public Component message = Component.empty();
|
||||
|
||||
public static DeathCombatEventPacket of(int playerId, int entityId, Component message) {
|
||||
DeathCombatEventPacket packet = new DeathCombatEventPacket();
|
||||
packet.playerId = playerId;
|
||||
packet.entityId = entityId;
|
||||
packet.message = message;
|
||||
return packet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(@NotNull BinaryReader reader) {
|
||||
this.playerId = reader.readVarInt();
|
||||
|
@ -1,38 +0,0 @@
|
||||
package net.minestom.server.network.packet.server.play;
|
||||
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class WindowConfirmationPacket implements ServerPacket {
|
||||
|
||||
public byte windowId;
|
||||
public short actionNumber;
|
||||
public boolean accepted;
|
||||
|
||||
/**
|
||||
* Default constructor, required for reflection operations.
|
||||
*/
|
||||
public WindowConfirmationPacket() {}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeByte(windowId);
|
||||
writer.writeShort(actionNumber);
|
||||
writer.writeBoolean(accepted);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(@NotNull BinaryReader reader) {
|
||||
windowId = reader.readByte();
|
||||
actionNumber = reader.readShort();
|
||||
accepted = reader.readBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return ServerPacketIdentifier.WINDOW_CONFIRMATION;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user