Add implementation for ClientEmoteEvent

Also, a few random changes I've stored since forever.
This commit is contained in:
Camotoy 2023-02-15 00:17:14 -05:00
parent 6a6a601efc
commit ee754c529b
No known key found for this signature in database
GPG key ID: 7EEFB66FE798081F
10 changed files with 27 additions and 30 deletions

View file

@ -33,11 +33,11 @@ import org.geysermc.geyser.api.event.connection.ConnectionEvent;
/**
* Called whenever a Bedrock player performs an emote on their end, before it is broadcasted to the rest of the server.
*/
public final class BedrockEmoteEvent extends ConnectionEvent implements Cancellable {
public final class ClientEmoteEvent extends ConnectionEvent implements Cancellable {
private final String emoteId;
private boolean cancelled;
public BedrockEmoteEvent(@NonNull GeyserConnection connection, @NonNull String emoteId) {
public ClientEmoteEvent(@NonNull GeyserConnection connection, @NonNull String emoteId) {
super(connection);
this.emoteId = emoteId;
}

View file

@ -25,10 +25,6 @@
package org.geysermc.geyser.command.defaults;
import com.github.steveice10.mc.protocol.data.game.entity.object.Direction;
import com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction;
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundPlayerActionPacket;
import com.nukkitx.math.vector.Vector3i;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.command.GeyserCommand;
import org.geysermc.geyser.command.GeyserCommandSource;
@ -46,9 +42,7 @@ public class OffhandCommand extends GeyserCommand {
return;
}
ServerboundPlayerActionPacket releaseItemPacket = new ServerboundPlayerActionPacket(PlayerAction.SWAP_HANDS, Vector3i.ZERO,
Direction.DOWN, 0);
session.sendDownstreamPacket(releaseItemPacket);
session.requestOffhandSwap();
}
@Override

View file

@ -37,7 +37,7 @@ public enum ToolTier {
DIAMOND(8),
NETHERITE(9);
public static final ToolTier[] VALUES = values();
private static final ToolTier[] VALUES = values();
private final int speed;

View file

@ -29,9 +29,7 @@ import com.nukkitx.nbt.NbtMap;
import com.nukkitx.nbt.NbtMapBuilder;
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import org.geysermc.geyser.level.block.BlockStateValues;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.session.cache.ChunkCache;
import org.geysermc.geyser.translator.inventory.LecternInventoryTranslator;
public class GeyserWorldManager extends WorldManager {
@ -39,11 +37,7 @@ public class GeyserWorldManager extends WorldManager {
@Override
public int getBlockAt(GeyserSession session, int x, int y, int z) {
ChunkCache chunkCache = session.getChunkCache();
if (chunkCache != null) { // Chunk cache can be null if the session is closed asynchronously
return chunkCache.getBlockAt(x, y, z);
}
return BlockStateValues.JAVA_AIR_ID;
return session.getChunkCache().getBlockAt(x, y, z);
}
@Override

View file

@ -33,7 +33,7 @@ public enum PistonBehavior {
DESTROY,
PUSH_ONLY;
public static final PistonBehavior[] VALUES = values();
private static final PistonBehavior[] VALUES = values();
public static PistonBehavior getByName(String name) {
String upperCase = name.toUpperCase(Locale.ROOT);

View file

@ -28,12 +28,13 @@ package org.geysermc.geyser.registry.type;
import com.nukkitx.protocol.bedrock.data.LevelEventType;
import org.geysermc.geyser.session.GeyserSession;
import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNullableByDefault;
@ParametersAreNullableByDefault
public record ParticleMapping(LevelEventType levelEventType, String identifier) {
public int getParticleId(GeyserSession session) {
public int getParticleId(@Nonnull GeyserSession session) {
if (this.levelEventType == null) {
return -1;
}

View file

@ -180,7 +180,7 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
private final AdvancementsCache advancementsCache;
private final BookEditCache bookEditCache;
private final ChunkCache chunkCache;
private @org.checkerframework.checker.nullness.qual.NonNull final ChunkCache chunkCache;
private final EntityCache entityCache;
private final EntityEffectCache effectCache;
private final FormCache formCache;
@ -1354,6 +1354,12 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
return false;
}
public void requestOffhandSwap() {
ServerboundPlayerActionPacket swapHandsPacket = new ServerboundPlayerActionPacket(PlayerAction.SWAP_HANDS, Vector3i.ZERO,
Direction.DOWN, 0);
sendDownstreamPacket(swapHandsPacket);
}
/**
* Will be overwritten for GeyserConnect.
*/

View file

@ -73,8 +73,7 @@ public final class LodestoneCache {
}
}
for (Int2ObjectMap.Entry<LodestonePos> entry : this.lodestones.int2ObjectEntrySet()) {
LodestonePos pos = entry.getValue();
for (LodestonePos pos : this.lodestones.values()) {
if (pos.equals(x, y, z, dim)) {
// Use this existing position instead
this.activeLodestones.put(itemStack, pos);

View file

@ -43,6 +43,7 @@ import org.geysermc.geyser.inventory.updater.UIInventoryUpdater;
import org.geysermc.geyser.session.GeyserSession;
import java.util.Arrays;
import java.util.Locale;
public class EnchantingInventoryTranslator extends AbstractBlockInventoryTranslator {
public EnchantingInventoryTranslator() {
@ -71,7 +72,7 @@ public class EnchantingInventoryTranslator extends AbstractBlockInventoryTransla
// The Bedrock index might need changed, so let's look it up and see.
int bedrockIndex = value;
if (bedrockIndex != -1) {
Enchantment enchantment = Enchantment.getByJavaIdentifier("minecraft:" + Enchantment.JavaEnchantment.of(bedrockIndex).name().toLowerCase());
Enchantment enchantment = Enchantment.getByJavaIdentifier("minecraft:" + Enchantment.JavaEnchantment.of(bedrockIndex).name().toLowerCase(Locale.ROOT));
if (enchantment != null) {
// Convert the Java enchantment index to Bedrock's
bedrockIndex = enchantment.ordinal();

View file

@ -25,11 +25,8 @@
package org.geysermc.geyser.translator.protocol.bedrock.entity.player;
import com.github.steveice10.mc.protocol.data.game.entity.object.Direction;
import com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction;
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundPlayerActionPacket;
import com.nukkitx.math.vector.Vector3i;
import com.nukkitx.protocol.bedrock.packet.EmotePacket;
import org.geysermc.geyser.api.event.bedrock.ClientEmoteEvent;
import org.geysermc.geyser.configuration.EmoteOffhandWorkaroundOption;
import org.geysermc.geyser.entity.type.Entity;
import org.geysermc.geyser.session.GeyserSession;
@ -43,15 +40,20 @@ public class BedrockEmoteTranslator extends PacketTranslator<EmotePacket> {
public void translate(GeyserSession session, EmotePacket packet) {
if (session.getGeyser().getConfig().getEmoteOffhandWorkaround() != EmoteOffhandWorkaroundOption.DISABLED) {
// Activate the workaround - we should trigger the offhand now
ServerboundPlayerActionPacket swapHandsPacket = new ServerboundPlayerActionPacket(PlayerAction.SWAP_HANDS, Vector3i.ZERO,
Direction.DOWN, 0);
session.sendDownstreamPacket(swapHandsPacket);
session.requestOffhandSwap();
if (session.getGeyser().getConfig().getEmoteOffhandWorkaround() == EmoteOffhandWorkaroundOption.NO_EMOTES) {
return;
}
}
// For the future: could have a method that exposes which players will see the emote
ClientEmoteEvent event = new ClientEmoteEvent(session, packet.getEmoteId());
session.getGeyser().eventBus().fire(event);
if (event.isCancelled()) {
return;
}
int javaId = session.getPlayerEntity().getEntityId();
for (GeyserSession otherSession : session.getGeyser().getSessionManager().getSessions().values()) {
if (otherSession != session) {