use of net.minecraft.network.protocol.game.ServerboundClientCommandPacket in project SpongeCommon by SpongePowered.
the class PacketPhase method setupPacketToStateMapping.
private void setupPacketToStateMapping() {
this.packetTranslationMap.put(ServerboundKeepAlivePacket.class, packet -> PacketPhase.General.IGNORED);
this.packetTranslationMap.put(ServerboundChatPacket.class, packet -> PacketPhase.General.CHAT_COMMAND);
this.packetTranslationMap.put(ServerboundInteractPacket.class, packet -> {
final ServerboundInteractPacket useEntityPacket = (ServerboundInteractPacket) packet;
final ServerboundInteractPacket.Action action = useEntityPacket.getAction();
if (action == ServerboundInteractPacket.Action.INTERACT) {
return PacketPhase.General.INTERACT_ENTITY;
} else if (action == ServerboundInteractPacket.Action.ATTACK) {
return PacketPhase.General.ATTACK_ENTITY;
} else if (action == ServerboundInteractPacket.Action.INTERACT_AT) {
return PacketPhase.General.INTERACT_AT_ENTITY;
} else {
return PacketPhase.General.INVALID;
}
});
this.packetTranslationMap.put(ServerboundMovePlayerPacket.class, packet -> PacketPhase.General.MOVEMENT);
this.packetTranslationMap.put(ServerboundMovePlayerPacket.Pos.class, packet -> PacketPhase.General.MOVEMENT);
this.packetTranslationMap.put(ServerboundMovePlayerPacket.Rot.class, packet -> PacketPhase.General.MOVEMENT);
this.packetTranslationMap.put(ServerboundMovePlayerPacket.PosRot.class, packet -> PacketPhase.General.MOVEMENT);
this.packetTranslationMap.put(ServerboundPlayerActionPacket.class, packet -> {
final ServerboundPlayerActionPacket playerDigging = (ServerboundPlayerActionPacket) packet;
final ServerboundPlayerActionPacket.Action action = playerDigging.getAction();
final IPhaseState<? extends PacketContext<?>> state = PacketPhase.INTERACTION_ACTION_MAPPINGS.get(action);
return state == null ? PacketPhase.General.UNKNOWN : state;
});
this.packetTranslationMap.put(ServerboundUseItemOnPacket.class, packet -> {
// Note that CPacketPlayerTryUseItem is swapped with CPacketPlayerBlockPlacement
final ServerboundUseItemOnPacket blockPlace = (ServerboundUseItemOnPacket) packet;
final BlockPos blockPos = blockPlace.getHitResult().getBlockPos();
final Direction front = blockPlace.getHitResult().getDirection();
final MinecraftServer server = SpongeCommon.server();
if (blockPos.getY() < server.getMaxBuildHeight() - 1 || front != Direction.UP && blockPos.getY() < server.getMaxBuildHeight()) {
return PacketPhase.General.PLACE_BLOCK;
}
return PacketPhase.General.INVALID;
});
this.packetTranslationMap.put(ServerboundUseItemPacket.class, packet -> PacketPhase.General.USE_ITEM);
this.packetTranslationMap.put(ServerboundSetCarriedItemPacket.class, packet -> PacketPhase.Inventory.SET_CARRIED_ITEM);
this.packetTranslationMap.put(ServerboundSwingPacket.class, packet -> PacketPhase.General.ANIMATION);
this.packetTranslationMap.put(ServerboundPlayerCommandPacket.class, packet -> {
final ServerboundPlayerCommandPacket playerAction = (ServerboundPlayerCommandPacket) packet;
final ServerboundPlayerCommandPacket.Action action = playerAction.getAction();
return PacketPhase.PLAYER_ACTION_MAPPINGS.get(action);
});
this.packetTranslationMap.put(ServerboundPlayerInputPacket.class, packet -> PacketPhase.General.HANDLED_EXTERNALLY);
this.packetTranslationMap.put(ServerboundContainerClosePacket.class, packet -> PacketPhase.General.CLOSE_WINDOW);
this.packetTranslationMap.put(ServerboundContainerClickPacket.class, packet -> PacketPhase.fromWindowPacket((ServerboundContainerClickPacket) packet));
this.packetTranslationMap.put(ServerboundContainerAckPacket.class, packet -> PacketPhase.General.UNKNOWN);
this.packetTranslationMap.put(ServerboundSetCreativeModeSlotPacket.class, packet -> PacketPhase.General.CREATIVE_INVENTORY);
this.packetTranslationMap.put(ServerboundContainerButtonClickPacket.class, packet -> PacketPhase.Inventory.ENCHANT_ITEM);
this.packetTranslationMap.put(ServerboundSignUpdatePacket.class, packet -> PacketPhase.General.UPDATE_SIGN);
this.packetTranslationMap.put(ServerboundPlayerAbilitiesPacket.class, packet -> PacketPhase.General.IGNORED);
this.packetTranslationMap.put(ServerboundCommandSuggestionPacket.class, packet -> PacketPhase.General.TAB_COMPLETE);
this.packetTranslationMap.put(ServerboundClientCommandPacket.class, packet -> {
final ServerboundClientCommandPacket clientStatus = (ServerboundClientCommandPacket) packet;
final ServerboundClientCommandPacket.Action status = clientStatus.getAction();
if (status == ServerboundClientCommandPacket.Action.PERFORM_RESPAWN) {
return PacketPhase.General.REQUEST_RESPAWN;
}
return PacketPhase.General.IGNORED;
});
this.packetTranslationMap.put(ServerboundCustomPayloadPacket.class, packet -> PacketPhase.General.HANDLED_EXTERNALLY);
this.packetTranslationMap.put(ServerboundTeleportToEntityPacket.class, packet -> PacketPhase.General.IGNORED);
this.packetTranslationMap.put(ServerboundResourcePackPacket.class, packet -> PacketPhase.General.RESOURCE_PACK);
this.packetTranslationMap.put(ServerboundPlaceRecipePacket.class, packet -> PacketPhase.Inventory.PLACE_RECIPE);
}
use of net.minecraft.network.protocol.game.ServerboundClientCommandPacket in project SpongeCommon by SpongePowered.
the class PacketPhaseUtil method onProcessPacket.
@SuppressWarnings({ "rawtypes", "unchecked", "deprecation" })
public static void onProcessPacket(final Packet packetIn, final PacketListener netHandler) {
if (netHandler instanceof ServerGamePacketListenerImpl) {
net.minecraft.server.level.ServerPlayer packetPlayer = ((ServerGamePacketListenerImpl) netHandler).player;
// Only process the CustomPayload & Respawn packets from players if they are dead.
if (!packetPlayer.isAlive() && (!(packetIn instanceof ServerboundCustomPayloadPacket) && (!(packetIn instanceof ServerboundClientCommandPacket) || ((ServerboundClientCommandPacket) packetIn).getAction() != ServerboundClientCommandPacket.Action.PERFORM_RESPAWN))) {
return;
}
try (final CauseStackManager.StackFrame frame = PhaseTracker.getCauseStackManager().pushCauseFrame()) {
frame.pushCause(packetPlayer);
// Don't process movement capture logic if player hasn't moved
boolean ignoreMovementCapture;
if (packetIn instanceof ServerboundMovePlayerPacket) {
final ServerboundMovePlayerPacket movingPacket = ((ServerboundMovePlayerPacket) packetIn);
if (movingPacket instanceof ServerboundMovePlayerPacket.Rot) {
ignoreMovementCapture = true;
} else if (packetPlayer.getX() == ((ServerboundMovePlayerPacketAccessor) movingPacket).accessor$x() && packetPlayer.getY() == ((ServerboundMovePlayerPacketAccessor) movingPacket).accessor$y() && packetPlayer.getZ() == ((ServerboundMovePlayerPacketAccessor) movingPacket).accessor$z()) {
ignoreMovementCapture = true;
} else {
ignoreMovementCapture = false;
}
// we cannot ignore movement capture
if (ignoreMovementCapture) {
// Basically, we need to sanity check the nearby blocks because if they have
// any positional logic, we need to run captures
final AABB boundingBox = packetPlayer.getBoundingBox();
final BlockPos min = new BlockPos(boundingBox.minX + 0.001D, boundingBox.minY + 0.001D, boundingBox.minZ + 0.001D);
final BlockPos max = new BlockPos(boundingBox.maxX - 0.001D, boundingBox.maxY - 0.001D, boundingBox.maxZ - 0.001D);
final BlockPos.MutableBlockPos pos = new BlockPos.MutableBlockPos();
if (packetPlayer.level.hasChunksAt(min, max)) {
for (int x = min.getX(); x <= max.getX(); ++x) {
for (int y = min.getY(); y <= max.getY(); ++y) {
for (int z = min.getZ(); z <= max.getZ(); ++z) {
pos.set(x, y, z);
final Block block = packetPlayer.level.getBlockState(pos).getBlock();
if (((TrackableBlockBridge) block).bridge$hasEntityInsideLogic()) {
ignoreMovementCapture = false;
}
}
}
}
}
}
} else {
ignoreMovementCapture = false;
}
if (ignoreMovementCapture || (packetIn instanceof ServerboundClientInformationPacket)) {
packetIn.handle(netHandler);
} else {
final IPhaseState<? extends PacketContext<?>> packetState = PacketPhase.getInstance().getStateForPacket(packetIn);
// At the very least make an unknown packet state case.
final PacketContext<?> context = packetState.createPhaseContext(PhaseTracker.SERVER);
context.source(packetPlayer).packetPlayer(packetPlayer).packet(packetIn);
if (!PacketPhase.getInstance().isPacketInvalid(packetIn, packetPlayer, packetState)) {
PacketPhase.getInstance().populateContext(packetIn, packetPlayer, packetState, context);
context.creator(((ServerPlayer) packetPlayer).uniqueId());
context.notifier(((ServerPlayer) packetPlayer).uniqueId());
}
try (final PhaseContext<?> packetContext = context) {
packetContext.buildAndSwitch();
packetIn.handle(netHandler);
}
}
}
} else {
// client
packetIn.handle(netHandler);
}
}
Aggregations