2020-07-08 15:06:58 +00:00
|
|
|
/*
|
2021-01-01 15:10:36 +00:00
|
|
|
* Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
|
2020-07-08 15:06:58 +00:00
|
|
|
*
|
2020-07-30 20:10:15 +00:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
2020-07-08 15:06:58 +00:00
|
|
|
*
|
2020-07-30 20:10:15 +00:00
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
2020-07-08 15:06:58 +00:00
|
|
|
*
|
2020-07-30 20:10:15 +00:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
2020-07-08 15:06:58 +00:00
|
|
|
*
|
2020-07-30 20:10:15 +00:00
|
|
|
* @author GeyserMC
|
|
|
|
* @link https://github.com/GeyserMC/Geyser
|
2020-07-08 15:06:58 +00:00
|
|
|
*/
|
|
|
|
|
2021-11-20 23:29:46 +00:00
|
|
|
package org.geysermc.geyser.translator.protocol.bedrock.entity.player;
|
2020-07-08 15:06:58 +00:00
|
|
|
|
2021-11-18 03:02:38 +00:00
|
|
|
import com.github.steveice10.mc.protocol.data.game.entity.object.Direction;
|
2021-04-26 20:10:32 +00:00
|
|
|
import com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction;
|
2021-11-13 03:44:15 +00:00
|
|
|
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundPlayerActionPacket;
|
2020-07-08 15:06:58 +00:00
|
|
|
import com.nukkitx.protocol.bedrock.packet.EmotePacket;
|
2021-11-20 21:34:30 +00:00
|
|
|
import org.geysermc.geyser.configuration.EmoteOffhandWorkaroundOption;
|
2021-11-20 23:29:46 +00:00
|
|
|
import org.geysermc.geyser.entity.type.Entity;
|
2021-11-22 19:52:26 +00:00
|
|
|
import org.geysermc.geyser.session.GeyserSession;
|
2021-11-20 23:29:46 +00:00
|
|
|
import org.geysermc.geyser.translator.protocol.PacketTranslator;
|
|
|
|
import org.geysermc.geyser.translator.protocol.Translator;
|
|
|
|
import org.geysermc.geyser.util.BlockUtils;
|
2020-07-08 15:06:58 +00:00
|
|
|
|
|
|
|
@Translator(packet = EmotePacket.class)
|
|
|
|
public class BedrockEmoteTranslator extends PacketTranslator<EmotePacket> {
|
|
|
|
|
|
|
|
@Override
|
2021-11-22 19:52:26 +00:00
|
|
|
public void translate(GeyserSession session, EmotePacket packet) {
|
2021-11-20 21:34:30 +00:00
|
|
|
if (session.getGeyser().getConfig().getEmoteOffhandWorkaround() != EmoteOffhandWorkaroundOption.DISABLED) {
|
2021-04-26 20:10:32 +00:00
|
|
|
// Activate the workaround - we should trigger the offhand now
|
2021-11-13 03:44:15 +00:00
|
|
|
ServerboundPlayerActionPacket swapHandsPacket = new ServerboundPlayerActionPacket(PlayerAction.SWAP_HANDS, BlockUtils.POSITION_ZERO,
|
2021-11-18 03:02:38 +00:00
|
|
|
Direction.DOWN);
|
2021-04-26 20:10:32 +00:00
|
|
|
session.sendDownstreamPacket(swapHandsPacket);
|
|
|
|
|
2021-11-20 21:34:30 +00:00
|
|
|
if (session.getGeyser().getConfig().getEmoteOffhandWorkaround() == EmoteOffhandWorkaroundOption.NO_EMOTES) {
|
2021-04-26 20:10:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-08 15:06:58 +00:00
|
|
|
long javaId = session.getPlayerEntity().getEntityId();
|
2021-11-22 19:52:26 +00:00
|
|
|
for (GeyserSession otherSession : session.getGeyser().getSessionManager().getSessions().values()) {
|
2020-07-08 15:06:58 +00:00
|
|
|
if (otherSession != session) {
|
2020-08-24 14:26:37 +00:00
|
|
|
if (otherSession.isClosed()) continue;
|
2021-08-21 13:54:52 +00:00
|
|
|
if (otherSession.getEventLoop().inEventLoop()) {
|
|
|
|
playEmote(otherSession, javaId, packet.getEmoteId());
|
|
|
|
} else {
|
|
|
|
session.executeInEventLoop(() -> playEmote(otherSession, javaId, packet.getEmoteId()));
|
|
|
|
}
|
2020-07-08 15:06:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-08-21 13:54:52 +00:00
|
|
|
|
2021-11-22 19:52:26 +00:00
|
|
|
private void playEmote(GeyserSession otherSession, long javaId, String emoteId) {
|
2021-08-21 13:54:52 +00:00
|
|
|
Entity otherEntity = otherSession.getEntityCache().getEntityByJavaId(javaId); // Must be ran on same thread
|
|
|
|
if (otherEntity == null) return;
|
|
|
|
EmotePacket otherEmotePacket = new EmotePacket();
|
|
|
|
otherEmotePacket.setEmoteId(emoteId);
|
|
|
|
otherEmotePacket.setRuntimeEntityId(otherEntity.getGeyserId());
|
|
|
|
otherSession.sendUpstreamPacket(otherEmotePacket);
|
|
|
|
}
|
2020-07-08 15:06:58 +00:00
|
|
|
}
|