3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-26 08:10:11 +01:00

Add emote offhand workaround (#2163)

This commit add a new config option, `emote-offhand-workaround`. If set to a value, emoting will perform the offhand swap action.
Dieser Commit ist enthalten in:
Camotoy 2021-04-26 16:10:32 -04:00 committet von GitHub
Ursprung 17ad18f450
Commit 48fcb4733d
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
9 geänderte Dateien mit 122 neuen und 12 gelöschten Zeilen

Datei anzeigen

@ -25,7 +25,6 @@
package org.geysermc.connector.command.defaults; package org.geysermc.connector.command.defaults;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position;
import com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction; import com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction;
import com.github.steveice10.mc.protocol.data.game.world.block.BlockFace; import com.github.steveice10.mc.protocol.data.game.world.block.BlockFace;
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerActionPacket; import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerActionPacket;
@ -33,6 +32,7 @@ import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.command.CommandSender; import org.geysermc.connector.command.CommandSender;
import org.geysermc.connector.command.GeyserCommand; import org.geysermc.connector.command.GeyserCommand;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.utils.BlockUtils;
public class OffhandCommand extends GeyserCommand { public class OffhandCommand extends GeyserCommand {
@ -46,7 +46,7 @@ public class OffhandCommand extends GeyserCommand {
return; return;
} }
ClientPlayerActionPacket releaseItemPacket = new ClientPlayerActionPacket(PlayerAction.SWAP_HANDS, new Position(0,0,0), ClientPlayerActionPacket releaseItemPacket = new ClientPlayerActionPacket(PlayerAction.SWAP_HANDS, BlockUtils.POSITION_ZERO,
BlockFace.DOWN); BlockFace.DOWN);
session.sendDownstreamPacket(releaseItemPacket); session.sendDownstreamPacket(releaseItemPacket);
} }

Datei anzeigen

@ -0,0 +1,53 @@
/*
* Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
*
* 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:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* 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.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.connector.configuration;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import java.io.IOException;
public enum EmoteOffhandWorkaroundOption {
NO_EMOTES,
EMOTES_AND_OFFHAND,
DISABLED;
public static class Deserializer extends JsonDeserializer<EmoteOffhandWorkaroundOption> {
@Override
public EmoteOffhandWorkaroundOption deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
String value = p.getValueAsString();
switch (value) {
case "no-emotes":
return NO_EMOTES;
case "emotes-and-offhand":
return EMOTES_AND_OFFHAND;
default:
return DISABLED;
}
}
}
}

Datei anzeigen

@ -77,6 +77,8 @@ public interface GeyserConfiguration {
boolean isShowCoordinates(); boolean isShowCoordinates();
EmoteOffhandWorkaroundOption getEmoteOffhandWorkaround();
String getDefaultLocale(); String getDefaultLocale();
Path getFloodgateKeyPath(); Path getFloodgateKeyPath();

Datei anzeigen

@ -28,6 +28,7 @@ package org.geysermc.connector.configuration;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.GeyserConnector;
@ -100,6 +101,10 @@ public abstract class GeyserJacksonConfiguration implements GeyserConfiguration
@JsonProperty("show-coordinates") @JsonProperty("show-coordinates")
private boolean showCoordinates = true; private boolean showCoordinates = true;
@JsonDeserialize(using = EmoteOffhandWorkaroundOption.Deserializer.class)
@JsonProperty("emote-offhand-workaround")
private EmoteOffhandWorkaroundOption emoteOffhandWorkaround = EmoteOffhandWorkaroundOption.DISABLED;
@JsonProperty("allow-third-party-ears") @JsonProperty("allow-third-party-ears")
private boolean allowThirdPartyEars = false; private boolean allowThirdPartyEars = false;

Datei anzeigen

@ -79,6 +79,7 @@ import org.geysermc.common.window.FormWindow;
import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.command.CommandSender; import org.geysermc.connector.command.CommandSender;
import org.geysermc.connector.common.AuthType; import org.geysermc.connector.common.AuthType;
import org.geysermc.connector.configuration.EmoteOffhandWorkaroundOption;
import org.geysermc.connector.entity.Entity; import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.entity.Tickable; import org.geysermc.connector.entity.Tickable;
import org.geysermc.connector.entity.attribute.Attribute; import org.geysermc.connector.entity.attribute.Attribute;
@ -433,9 +434,7 @@ public class GeyserSession implements CommandSender {
@Setter @Setter
private boolean waitingForStatistics = false; private boolean waitingForStatistics = false;
@Setter private final Set<UUID> emotes;
private List<UUID> selectedEmotes = new ArrayList<>();
private final Set<UUID> emotes = new HashSet<>();
/** /**
* The thread that will run every 50 milliseconds - one Minecraft tick. * The thread that will run every 50 milliseconds - one Minecraft tick.
@ -471,9 +470,14 @@ public class GeyserSession implements CommandSender {
this.spawned = false; this.spawned = false;
this.loggedIn = false; this.loggedIn = false;
if (connector.getConfig().getEmoteOffhandWorkaround() != EmoteOffhandWorkaroundOption.NO_EMOTES) {
this.emotes = new HashSet<>();
// Make a copy to prevent ConcurrentModificationException // Make a copy to prevent ConcurrentModificationException
final List<GeyserSession> tmpPlayers = new ArrayList<>(connector.getPlayers()); final List<GeyserSession> tmpPlayers = new ArrayList<>(connector.getPlayers());
tmpPlayers.forEach(player -> this.emotes.addAll(player.getEmotes())); tmpPlayers.forEach(player -> this.emotes.addAll(player.getEmotes()));
} else {
this.emotes = null;
}
bedrockServerSession.addDisconnectHandler(disconnectReason -> { bedrockServerSession.addDisconnectHandler(disconnectReason -> {
InetAddress address = bedrockServerSession.getRealAddress().getAddress(); InetAddress address = bedrockServerSession.getRealAddress().getAddress();
@ -1306,7 +1310,6 @@ public class GeyserSession implements CommandSender {
} }
public void refreshEmotes(List<UUID> emotes) { public void refreshEmotes(List<UUID> emotes) {
this.selectedEmotes = emotes;
this.emotes.addAll(emotes); this.emotes.addAll(emotes);
for (GeyserSession player : connector.getPlayers()) { for (GeyserSession player : connector.getPlayers()) {
List<UUID> pieces = new ArrayList<>(); List<UUID> pieces = new ArrayList<>();

Datei anzeigen

@ -26,6 +26,7 @@
package org.geysermc.connector.network.translators.bedrock; package org.geysermc.connector.network.translators.bedrock;
import com.nukkitx.protocol.bedrock.packet.EmoteListPacket; import com.nukkitx.protocol.bedrock.packet.EmoteListPacket;
import org.geysermc.connector.configuration.EmoteOffhandWorkaroundOption;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator; import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.Translator; import org.geysermc.connector.network.translators.Translator;
@ -35,6 +36,10 @@ public class BedrockEmoteListTranslator extends PacketTranslator<EmoteListPacket
@Override @Override
public void translate(EmoteListPacket packet, GeyserSession session) { public void translate(EmoteListPacket packet, GeyserSession session) {
if (session.getConnector().getConfig().getEmoteOffhandWorkaround() == EmoteOffhandWorkaroundOption.NO_EMOTES) {
return;
}
session.refreshEmotes(packet.getPieceIds()); session.refreshEmotes(packet.getPieceIds());
} }
} }

Datei anzeigen

@ -25,25 +25,43 @@
package org.geysermc.connector.network.translators.bedrock.entity.player; package org.geysermc.connector.network.translators.bedrock.entity.player;
import com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction;
import com.github.steveice10.mc.protocol.data.game.world.block.BlockFace;
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerActionPacket;
import com.nukkitx.protocol.bedrock.packet.EmotePacket; import com.nukkitx.protocol.bedrock.packet.EmotePacket;
import org.geysermc.connector.configuration.EmoteOffhandWorkaroundOption;
import org.geysermc.connector.entity.Entity; import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator; import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.Translator; import org.geysermc.connector.network.translators.Translator;
import org.geysermc.connector.utils.BlockUtils;
@Translator(packet = EmotePacket.class) @Translator(packet = EmotePacket.class)
public class BedrockEmoteTranslator extends PacketTranslator<EmotePacket> { public class BedrockEmoteTranslator extends PacketTranslator<EmotePacket> {
@Override @Override
public void translate(EmotePacket packet, GeyserSession session) { public void translate(EmotePacket packet, GeyserSession session) {
if (session.getConnector().getConfig().getEmoteOffhandWorkaround() != EmoteOffhandWorkaroundOption.DISABLED) {
// Activate the workaround - we should trigger the offhand now
ClientPlayerActionPacket swapHandsPacket = new ClientPlayerActionPacket(PlayerAction.SWAP_HANDS, BlockUtils.POSITION_ZERO,
BlockFace.DOWN);
session.sendDownstreamPacket(swapHandsPacket);
if (session.getConnector().getConfig().getEmoteOffhandWorkaround() == EmoteOffhandWorkaroundOption.NO_EMOTES) {
return;
}
}
long javaId = session.getPlayerEntity().getEntityId(); long javaId = session.getPlayerEntity().getEntityId();
for (GeyserSession otherSession : session.getConnector().getPlayers()) { for (GeyserSession otherSession : session.getConnector().getPlayers()) {
if (otherSession != session) { if (otherSession != session) {
if (otherSession.isClosed()) continue; if (otherSession.isClosed()) continue;
Entity otherEntity = otherSession.getEntityCache().getEntityByJavaId(javaId); Entity otherEntity = otherSession.getEntityCache().getEntityByJavaId(javaId);
if (otherEntity == null) continue; if (otherEntity == null) continue;
packet.setRuntimeEntityId(otherEntity.getGeyserId()); EmotePacket otherEmotePacket = new EmotePacket();
otherSession.sendUpstreamPacket(packet); otherEmotePacket.setEmoteId(packet.getEmoteId());
otherEmotePacket.setRuntimeEntityId(otherEntity.getGeyserId());
otherSession.sendUpstreamPacket(otherEmotePacket);
} }
} }
} }

Datei anzeigen

@ -30,12 +30,14 @@ import com.nukkitx.protocol.bedrock.data.SoundEvent;
import com.nukkitx.protocol.bedrock.data.LevelEventType; import com.nukkitx.protocol.bedrock.data.LevelEventType;
import com.nukkitx.protocol.bedrock.data.entity.EntityData; import com.nukkitx.protocol.bedrock.data.entity.EntityData;
import com.nukkitx.protocol.bedrock.data.entity.EntityEventType; import com.nukkitx.protocol.bedrock.data.entity.EntityEventType;
import com.nukkitx.protocol.bedrock.data.inventory.ItemData;
import com.nukkitx.protocol.bedrock.packet.EntityEventPacket; import com.nukkitx.protocol.bedrock.packet.EntityEventPacket;
import com.nukkitx.protocol.bedrock.packet.LevelEventPacket; import com.nukkitx.protocol.bedrock.packet.LevelEventPacket;
import com.nukkitx.protocol.bedrock.packet.LevelSoundEvent2Packet; import com.nukkitx.protocol.bedrock.packet.LevelSoundEvent2Packet;
import com.nukkitx.protocol.bedrock.packet.SetEntityDataPacket; import com.nukkitx.protocol.bedrock.packet.SetEntityDataPacket;
import com.nukkitx.protocol.bedrock.packet.SetEntityMotionPacket; import com.nukkitx.protocol.bedrock.packet.SetEntityMotionPacket;
import org.geysermc.connector.entity.Entity; import org.geysermc.connector.entity.Entity;
import org.geysermc.connector.entity.LivingEntity;
import org.geysermc.connector.entity.type.EntityType; import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator; import org.geysermc.connector.network.translators.PacketTranslator;
@ -47,9 +49,11 @@ public class JavaEntityStatusTranslator extends PacketTranslator<ServerEntitySta
@Override @Override
public void translate(ServerEntityStatusPacket packet, GeyserSession session) { public void translate(ServerEntityStatusPacket packet, GeyserSession session) {
Entity entity = session.getEntityCache().getEntityByJavaId(packet.getEntityId()); Entity entity;
if (packet.getEntityId() == session.getPlayerEntity().getEntityId()) { if (packet.getEntityId() == session.getPlayerEntity().getEntityId()) {
entity = session.getPlayerEntity(); entity = session.getPlayerEntity();
} else {
entity = session.getEntityCache().getEntityByJavaId(packet.getEntityId());
} }
if (entity == null) if (entity == null)
return; return;
@ -196,6 +200,19 @@ public class JavaEntityStatusTranslator extends PacketTranslator<ServerEntitySta
equipmentBreakPacket.setIdentifier(""); equipmentBreakPacket.setIdentifier("");
session.sendUpstreamPacket(equipmentBreakPacket); session.sendUpstreamPacket(equipmentBreakPacket);
return; return;
case PLAYER_SWAP_SAME_ITEM: // Not just used for players
if (entity instanceof LivingEntity) {
LivingEntity livingEntity = (LivingEntity) entity;
ItemData newMainHand = livingEntity.getOffHand();
livingEntity.setOffHand(livingEntity.getHand());
livingEntity.setHand(newMainHand);
livingEntity.updateMainHand(session);
livingEntity.updateOffHand(session);
} else {
session.getConnector().getLogger().debug("Got status message to swap hands for a non-living entity.");
}
return;
} }
session.sendUpstreamPacket(entityEventPacket); session.sendUpstreamPacket(entityEventPacket);

Datei anzeigen

@ -124,6 +124,13 @@ show-cooldown: title
# Controls if coordinates are shown to players. # Controls if coordinates are shown to players.
show-coordinates: true show-coordinates: true
# If set, when a Bedrock player performs any emote, it will swap the offhand and mainhand items, just like the Java Edition keybind
# There are three options this can be set to:
# disabled - the default/fallback, which doesn't apply this workaround
# no-emotes - emotes will NOT be sent to other Bedrock clients and offhand will be swapped. This effectively disables all emotes from being seen.
# emotes-and-offhand - emotes will be sent to Bedrock clients and offhand will be swapped
emote-offhand-workaround: "disabled"
# The default locale if we dont have the one the client requested. Uncomment to not use the default system language. # The default locale if we dont have the one the client requested. Uncomment to not use the default system language.
# default-locale: en_us # default-locale: en_us