2019-07-10 06:34:10 +00:00
|
|
|
/*
|
2021-01-01 15:10:36 +00:00
|
|
|
* Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
|
2019-07-10 06:34:10 +00:00
|
|
|
*
|
2019-07-11 21:30:35 +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:
|
2019-07-10 06:34:10 +00:00
|
|
|
*
|
2019-07-11 21:30:35 +00:00
|
|
|
* 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.
|
2019-07-10 06:34:10 +00:00
|
|
|
*
|
|
|
|
* @author GeyserMC
|
|
|
|
* @link https://github.com/GeyserMC/Geyser
|
|
|
|
*/
|
|
|
|
|
|
|
|
package org.geysermc.connector.network.session;
|
|
|
|
|
2021-01-11 20:52:02 +00:00
|
|
|
import com.github.steveice10.mc.auth.exception.request.AuthPendingException;
|
2020-04-05 09:42:02 +00:00
|
|
|
import com.github.steveice10.mc.auth.exception.request.InvalidCredentialsException;
|
2019-07-24 06:29:54 +00:00
|
|
|
import com.github.steveice10.mc.auth.exception.request.RequestException;
|
2021-01-11 20:52:02 +00:00
|
|
|
import com.github.steveice10.mc.auth.service.AuthenticationService;
|
|
|
|
import com.github.steveice10.mc.auth.service.MojangAuthenticationService;
|
|
|
|
import com.github.steveice10.mc.auth.service.MsaAuthenticationService;
|
2020-09-29 18:15:11 +00:00
|
|
|
import com.github.steveice10.mc.protocol.MinecraftConstants;
|
2019-07-10 06:34:10 +00:00
|
|
|
import com.github.steveice10.mc.protocol.MinecraftProtocol;
|
2020-05-05 15:51:43 +00:00
|
|
|
import com.github.steveice10.mc.protocol.data.SubProtocol;
|
2021-04-12 04:35:53 +00:00
|
|
|
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Pose;
|
2019-10-27 09:56:47 +00:00
|
|
|
import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
|
2020-10-16 23:25:05 +00:00
|
|
|
import com.github.steveice10.mc.protocol.data.game.recipe.Recipe;
|
2020-12-24 16:23:47 +00:00
|
|
|
import com.github.steveice10.mc.protocol.data.game.statistic.Statistic;
|
2019-11-30 12:34:45 +00:00
|
|
|
import com.github.steveice10.mc.protocol.packet.handshake.client.HandshakePacket;
|
2021-07-28 17:21:18 +00:00
|
|
|
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerAbilitiesPacket;
|
2021-01-05 23:41:20 +00:00
|
|
|
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerPositionPacket;
|
2020-11-20 19:56:39 +00:00
|
|
|
import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerPositionRotationPacket;
|
2020-05-06 21:50:01 +00:00
|
|
|
import com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientTeleportConfirmPacket;
|
2021-03-03 00:02:34 +00:00
|
|
|
import com.github.steveice10.mc.protocol.packet.login.client.LoginPluginResponsePacket;
|
2020-12-24 01:47:29 +00:00
|
|
|
import com.github.steveice10.packetlib.BuiltinFlags;
|
2019-11-30 12:34:45 +00:00
|
|
|
import com.github.steveice10.packetlib.event.session.*;
|
2019-08-06 02:09:45 +00:00
|
|
|
import com.github.steveice10.packetlib.packet.Packet;
|
2021-05-23 19:55:01 +00:00
|
|
|
import com.github.steveice10.packetlib.tcp.TcpClientSession;
|
2020-02-11 22:42:02 +00:00
|
|
|
import com.nukkitx.math.GenericMath;
|
2020-05-04 06:06:08 +00:00
|
|
|
import com.nukkitx.math.vector.*;
|
2020-05-05 15:51:43 +00:00
|
|
|
import com.nukkitx.protocol.bedrock.BedrockPacket;
|
2019-07-10 06:34:10 +00:00
|
|
|
import com.nukkitx.protocol.bedrock.BedrockServerSession;
|
2020-06-08 12:13:25 +00:00
|
|
|
import com.nukkitx.protocol.bedrock.data.*;
|
2020-08-08 22:41:12 +00:00
|
|
|
import com.nukkitx.protocol.bedrock.data.command.CommandPermission;
|
2021-04-12 04:35:53 +00:00
|
|
|
import com.nukkitx.protocol.bedrock.data.entity.EntityData;
|
|
|
|
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
|
2019-12-04 18:13:49 +00:00
|
|
|
import com.nukkitx.protocol.bedrock.packet.*;
|
2021-08-19 16:37:14 +00:00
|
|
|
import io.netty.channel.Channel;
|
2021-08-17 00:39:29 +00:00
|
|
|
import io.netty.channel.EventLoop;
|
2021-07-28 00:29:27 +00:00
|
|
|
import it.unimi.dsi.fastutil.ints.*;
|
2020-06-15 18:24:52 +00:00
|
|
|
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
|
|
|
|
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
2021-06-08 12:57:03 +00:00
|
|
|
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
|
|
|
import it.unimi.dsi.fastutil.objects.ObjectIterator;
|
|
|
|
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
|
2020-10-16 23:25:05 +00:00
|
|
|
import lombok.AccessLevel;
|
2019-07-10 06:34:10 +00:00
|
|
|
import lombok.Getter;
|
2020-10-24 22:33:49 +00:00
|
|
|
import lombok.NonNull;
|
2019-08-06 02:09:45 +00:00
|
|
|
import lombok.Setter;
|
2021-07-31 16:52:49 +00:00
|
|
|
import org.geysermc.common.PlatformType;
|
2019-07-10 06:34:10 +00:00
|
|
|
import org.geysermc.connector.GeyserConnector;
|
2019-12-21 17:35:48 +00:00
|
|
|
import org.geysermc.connector.command.CommandSender;
|
2020-06-28 22:38:27 +00:00
|
|
|
import org.geysermc.connector.common.AuthType;
|
2021-04-26 20:10:32 +00:00
|
|
|
import org.geysermc.connector.configuration.EmoteOffhandWorkaroundOption;
|
2020-05-23 21:39:17 +00:00
|
|
|
import org.geysermc.connector.entity.Entity;
|
2021-05-09 19:44:41 +00:00
|
|
|
import org.geysermc.connector.entity.ItemFrameEntity;
|
2021-02-12 19:39:41 +00:00
|
|
|
import org.geysermc.connector.entity.Tickable;
|
2021-07-08 02:44:53 +00:00
|
|
|
import org.geysermc.connector.entity.attribute.GeyserAttributeType;
|
2020-11-20 19:56:39 +00:00
|
|
|
import org.geysermc.connector.entity.player.SessionPlayerEntity;
|
2020-12-09 16:30:59 +00:00
|
|
|
import org.geysermc.connector.entity.player.SkullPlayerEntity;
|
2020-10-16 23:25:05 +00:00
|
|
|
import org.geysermc.connector.inventory.Inventory;
|
2019-08-06 02:09:45 +00:00
|
|
|
import org.geysermc.connector.inventory.PlayerInventory;
|
2019-12-21 17:35:48 +00:00
|
|
|
import org.geysermc.connector.network.session.auth.AuthData;
|
2019-11-30 12:34:45 +00:00
|
|
|
import org.geysermc.connector.network.session.auth.BedrockClientData;
|
2019-09-13 10:49:18 +00:00
|
|
|
import org.geysermc.connector.network.session.cache.*;
|
2020-05-25 01:07:05 +00:00
|
|
|
import org.geysermc.connector.network.translators.PacketTranslatorRegistry;
|
2020-12-09 16:30:59 +00:00
|
|
|
import org.geysermc.connector.network.translators.chat.MessageTranslator;
|
2020-11-20 19:56:39 +00:00
|
|
|
import org.geysermc.connector.network.translators.collision.CollisionManager;
|
2020-12-26 17:20:59 +00:00
|
|
|
import org.geysermc.connector.network.translators.inventory.InventoryTranslator;
|
2021-07-13 01:19:40 +00:00
|
|
|
import org.geysermc.connector.registry.Registries;
|
|
|
|
import org.geysermc.connector.registry.type.BlockMappings;
|
|
|
|
import org.geysermc.connector.registry.type.ItemMappings;
|
2021-02-12 21:22:45 +00:00
|
|
|
import org.geysermc.connector.skin.FloodgateSkinUploader;
|
2020-06-21 02:24:45 +00:00
|
|
|
import org.geysermc.connector.utils.*;
|
2020-12-10 21:57:48 +00:00
|
|
|
import org.geysermc.cumulus.Form;
|
|
|
|
import org.geysermc.cumulus.util.FormBuilder;
|
2020-09-12 13:29:18 +00:00
|
|
|
import org.geysermc.floodgate.crypto.FloodgateCipher;
|
2019-11-30 12:34:45 +00:00
|
|
|
import org.geysermc.floodgate.util.BedrockData;
|
2019-07-10 06:34:10 +00:00
|
|
|
|
2021-02-17 23:25:41 +00:00
|
|
|
import java.net.InetAddress;
|
2019-09-13 13:37:31 +00:00
|
|
|
import java.net.InetSocketAddress;
|
2021-03-25 00:03:51 +00:00
|
|
|
import java.nio.charset.StandardCharsets;
|
2020-08-08 22:41:12 +00:00
|
|
|
import java.util.*;
|
2021-08-17 00:39:29 +00:00
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
|
import java.util.concurrent.CompletionException;
|
|
|
|
import java.util.concurrent.ScheduledFuture;
|
|
|
|
import java.util.concurrent.TimeUnit;
|
2020-02-06 04:21:09 +00:00
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
2019-08-06 02:09:45 +00:00
|
|
|
|
|
|
|
@Getter
|
2019-12-21 17:35:48 +00:00
|
|
|
public class GeyserSession implements CommandSender {
|
2019-09-30 16:44:25 +00:00
|
|
|
|
2019-09-13 13:37:31 +00:00
|
|
|
private final GeyserConnector connector;
|
2019-10-02 20:45:29 +00:00
|
|
|
private final UpstreamSession upstream;
|
2021-08-17 00:39:29 +00:00
|
|
|
/**
|
|
|
|
* The loop where all packets and ticking is processed to prevent concurrency issues.
|
2021-08-18 00:57:46 +00:00
|
|
|
* If this is manually called, ensure that any exceptions are properly handled.
|
2021-08-17 00:39:29 +00:00
|
|
|
*/
|
|
|
|
private final EventLoop eventLoop;
|
2021-05-23 19:55:01 +00:00
|
|
|
private TcpClientSession downstream;
|
2020-04-29 16:06:25 +00:00
|
|
|
@Setter
|
|
|
|
private AuthData authData;
|
|
|
|
@Setter
|
|
|
|
private BedrockClientData clientData;
|
2019-07-23 23:16:25 +00:00
|
|
|
|
2021-03-17 15:15:57 +00:00
|
|
|
/* Setter for GeyserConnect */
|
|
|
|
@Setter
|
|
|
|
private String remoteAddress;
|
|
|
|
@Setter
|
|
|
|
private int remotePort;
|
|
|
|
@Setter
|
|
|
|
private AuthType remoteAuthType;
|
|
|
|
/* Setter for GeyserConnect */
|
|
|
|
|
2021-01-11 20:52:02 +00:00
|
|
|
@Deprecated
|
|
|
|
@Setter
|
|
|
|
private boolean microsoftAccount;
|
|
|
|
|
2020-11-20 19:56:39 +00:00
|
|
|
private final SessionPlayerEntity playerEntity;
|
2019-07-29 22:20:48 +00:00
|
|
|
|
2021-01-12 02:23:09 +00:00
|
|
|
private AdvancementsCache advancementsCache;
|
2021-01-08 00:40:34 +00:00
|
|
|
private BookEditCache bookEditCache;
|
2019-09-15 23:34:14 +00:00
|
|
|
private ChunkCache chunkCache;
|
2019-08-06 02:09:45 +00:00
|
|
|
private EntityCache entityCache;
|
2020-11-20 19:56:39 +00:00
|
|
|
private EntityEffectCache effectCache;
|
2021-06-05 22:53:58 +00:00
|
|
|
private final FormCache formCache;
|
2021-08-31 23:49:55 +00:00
|
|
|
private final LodestoneCache lodestoneCache;
|
2021-09-10 01:20:25 +00:00
|
|
|
private final PistonCache pistonCache;
|
2021-05-15 02:48:34 +00:00
|
|
|
private final PreferencesCache preferencesCache;
|
2021-05-03 01:47:11 +00:00
|
|
|
private final TagCache tagCache;
|
2020-08-08 22:41:12 +00:00
|
|
|
private WorldCache worldCache;
|
2021-07-28 00:29:27 +00:00
|
|
|
|
2020-11-20 19:56:39 +00:00
|
|
|
private final Int2ObjectMap<TeleportCache> teleportMap = new Int2ObjectOpenHashMap<>();
|
|
|
|
|
2020-10-16 23:25:05 +00:00
|
|
|
private final PlayerInventory playerInventory;
|
|
|
|
@Setter
|
|
|
|
private Inventory openInventory;
|
2021-02-25 05:14:01 +00:00
|
|
|
@Setter
|
|
|
|
private boolean closingInventory;
|
2020-10-16 23:25:05 +00:00
|
|
|
|
2020-12-26 17:20:59 +00:00
|
|
|
@Setter
|
|
|
|
private InventoryTranslator inventoryTranslator = InventoryTranslator.PLAYER_INVENTORY_TRANSLATOR;
|
|
|
|
|
2020-12-26 21:41:50 +00:00
|
|
|
/**
|
|
|
|
* Use {@link #getNextItemNetId()} instead for consistency
|
|
|
|
*/
|
|
|
|
@Getter(AccessLevel.NONE)
|
2021-02-21 04:52:49 +00:00
|
|
|
private final AtomicInteger itemNetId = new AtomicInteger(2);
|
2020-10-16 23:25:05 +00:00
|
|
|
|
2021-01-14 04:40:01 +00:00
|
|
|
@Setter
|
|
|
|
private ScheduledFuture<?> craftingGridFuture;
|
|
|
|
|
2020-11-20 19:56:39 +00:00
|
|
|
/**
|
|
|
|
* Stores session collision
|
|
|
|
*/
|
|
|
|
private final CollisionManager collisionManager;
|
2019-07-30 02:57:43 +00:00
|
|
|
|
2021-03-09 17:51:48 +00:00
|
|
|
/**
|
2021-07-13 01:19:40 +00:00
|
|
|
* Stores the block mappings for this specific version.
|
2021-03-09 17:51:48 +00:00
|
|
|
*/
|
|
|
|
@Setter
|
2021-07-13 01:19:40 +00:00
|
|
|
private BlockMappings blockMappings;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stores the item translations for this specific version.
|
|
|
|
*/
|
|
|
|
@Setter
|
|
|
|
private ItemMappings itemMappings;
|
2021-03-09 17:51:48 +00:00
|
|
|
|
2021-08-17 00:39:29 +00:00
|
|
|
private final Map<Vector3i, SkullPlayerEntity> skullCache = new Object2ObjectOpenHashMap<>();
|
|
|
|
private final Long2ObjectMap<ClientboundMapItemDataPacket> storedMaps = new Long2ObjectOpenHashMap<>();
|
2020-06-15 18:24:52 +00:00
|
|
|
|
2021-07-28 00:29:27 +00:00
|
|
|
/**
|
2021-08-15 18:57:02 +00:00
|
|
|
* Stores the map between Java and Bedrock biome network IDs.
|
2021-07-28 00:29:27 +00:00
|
|
|
*/
|
|
|
|
private final Int2IntMap biomeTranslations = new Int2IntOpenHashMap();
|
|
|
|
|
2020-05-02 20:44:05 +00:00
|
|
|
/**
|
2021-05-09 19:44:41 +00:00
|
|
|
* A map of Vector3i positions to Java entities.
|
2020-05-02 20:44:05 +00:00
|
|
|
* Used for translating Bedrock block actions to Java entity actions.
|
|
|
|
*/
|
2021-05-09 19:44:41 +00:00
|
|
|
private final Map<Vector3i, ItemFrameEntity> itemFrameCache = new Object2ObjectOpenHashMap<>();
|
2020-05-02 20:44:05 +00:00
|
|
|
|
2020-12-28 05:29:27 +00:00
|
|
|
/**
|
|
|
|
* Stores a list of all lectern locations and their block entity tags.
|
|
|
|
* See {@link org.geysermc.connector.network.translators.world.WorldManager#getLecternDataAt(GeyserSession, int, int, int, boolean)}
|
|
|
|
* for more information.
|
|
|
|
*/
|
2021-02-27 02:53:24 +00:00
|
|
|
private final Set<Vector3i> lecternCache = new ObjectOpenHashSet<>();
|
2020-12-28 05:29:27 +00:00
|
|
|
|
|
|
|
@Setter
|
|
|
|
private boolean droppingLecternBook;
|
|
|
|
|
2020-03-06 01:26:36 +00:00
|
|
|
@Setter
|
|
|
|
private Vector2i lastChunkPosition = null;
|
2019-09-21 07:42:44 +00:00
|
|
|
private int renderDistance;
|
2019-09-13 10:49:18 +00:00
|
|
|
|
2019-07-24 06:29:54 +00:00
|
|
|
private boolean loggedIn;
|
2019-09-21 07:42:44 +00:00
|
|
|
private boolean loggingIn;
|
2019-07-24 06:29:54 +00:00
|
|
|
|
2019-08-06 02:09:45 +00:00
|
|
|
@Setter
|
|
|
|
private boolean spawned;
|
2021-08-24 13:31:19 +00:00
|
|
|
/**
|
|
|
|
* Accessed on the initial Java and Bedrock packet processing threads
|
|
|
|
*/
|
|
|
|
private volatile boolean closed;
|
2019-07-10 06:34:10 +00:00
|
|
|
|
2019-09-30 16:44:25 +00:00
|
|
|
@Setter
|
2019-10-27 09:56:47 +00:00
|
|
|
private GameMode gameMode = GameMode.SURVIVAL;
|
2019-09-30 16:44:25 +00:00
|
|
|
|
2021-01-04 00:06:20 +00:00
|
|
|
/**
|
|
|
|
* Keeps track of the world name for respawning.
|
|
|
|
*/
|
|
|
|
@Setter
|
|
|
|
private String worldName = null;
|
2020-04-30 05:21:02 +00:00
|
|
|
|
|
|
|
private boolean sneaking;
|
|
|
|
|
2021-04-12 04:35:53 +00:00
|
|
|
/**
|
|
|
|
* Stores the Java pose that the server and/or Geyser believes the player currently has.
|
|
|
|
*/
|
|
|
|
@Setter
|
|
|
|
private Pose pose = Pose.STANDING;
|
|
|
|
|
2019-12-27 11:29:46 +00:00
|
|
|
@Setter
|
2020-02-16 18:40:54 +00:00
|
|
|
private boolean sprinting;
|
|
|
|
|
2021-04-12 04:35:53 +00:00
|
|
|
/**
|
|
|
|
* Whether the player is swimming in water.
|
|
|
|
* Used to update speed when crawling.
|
|
|
|
*/
|
|
|
|
@Setter
|
|
|
|
private boolean swimmingInWater;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tracks the original speed attribute.
|
|
|
|
*
|
|
|
|
* We need to do this in order to emulate speeds when sneaking under 1.5-blocks-tall areas if the player isn't sneaking,
|
|
|
|
* and when crawling.
|
|
|
|
*/
|
|
|
|
@Setter
|
|
|
|
private float originalSpeedAttribute;
|
|
|
|
|
2020-11-12 00:28:45 +00:00
|
|
|
/**
|
|
|
|
* The dimension of the player.
|
|
|
|
* As all entities are in the same world, this can be safely applied to all other entities.
|
|
|
|
*/
|
|
|
|
@Setter
|
|
|
|
private String dimension = DimensionUtils.OVERWORLD;
|
|
|
|
|
2020-04-23 04:40:49 +00:00
|
|
|
@Setter
|
2020-06-19 01:44:50 +00:00
|
|
|
private int breakingBlock;
|
2020-04-23 04:40:49 +00:00
|
|
|
|
|
|
|
@Setter
|
|
|
|
private Vector3i lastBlockPlacePosition;
|
|
|
|
|
2020-04-23 06:01:33 +00:00
|
|
|
@Setter
|
|
|
|
private String lastBlockPlacedId;
|
|
|
|
|
2020-04-30 05:21:02 +00:00
|
|
|
@Setter
|
|
|
|
private boolean interacting;
|
|
|
|
|
2020-09-24 16:54:18 +00:00
|
|
|
/**
|
|
|
|
* Stores the last position of the block the player interacted with. This can either be a block that the client
|
|
|
|
* placed or an existing block the player interacted with (for example, a chest). <br>
|
|
|
|
* Initialized as (0, 0, 0) so it is always not-null.
|
|
|
|
*/
|
2020-04-30 05:21:02 +00:00
|
|
|
@Setter
|
2021-02-12 19:39:41 +00:00
|
|
|
private Vector3i lastInteractionBlockPosition = Vector3i.ZERO;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stores the position of the player the last time they interacted.
|
|
|
|
* Used to verify that the player did not move since their last interaction. <br>
|
|
|
|
* Initialized as (0, 0, 0) so it is always not-null.
|
|
|
|
*/
|
|
|
|
@Setter
|
|
|
|
private Vector3f lastInteractionPlayerPosition = Vector3f.ZERO;
|
2020-04-30 05:21:02 +00:00
|
|
|
|
2020-05-23 21:39:17 +00:00
|
|
|
@Setter
|
|
|
|
private Entity ridingVehicleEntity;
|
|
|
|
|
2021-03-18 05:11:21 +00:00
|
|
|
/**
|
|
|
|
* The entity that the client is currently looking at.
|
|
|
|
*/
|
|
|
|
@Setter
|
|
|
|
private Entity mouseoverEntity;
|
|
|
|
|
2020-10-16 23:25:05 +00:00
|
|
|
@Setter
|
|
|
|
private Int2ObjectMap<Recipe> craftingRecipes;
|
2021-01-04 02:54:26 +00:00
|
|
|
private final Set<String> unlockedRecipes;
|
2021-02-12 19:39:41 +00:00
|
|
|
private final AtomicInteger lastRecipeNetId;
|
2020-08-21 00:53:47 +00:00
|
|
|
|
2020-12-24 16:23:47 +00:00
|
|
|
/**
|
|
|
|
* Saves a list of all stonecutter recipes, for use in a stonecutter inventory.
|
2020-12-24 23:29:25 +00:00
|
|
|
* The key is the Java ID of the item; the values are all the possible outputs' Java IDs sorted by their string identifier
|
2020-12-24 16:23:47 +00:00
|
|
|
*/
|
|
|
|
@Setter
|
2020-12-24 23:29:25 +00:00
|
|
|
private Int2ObjectMap<IntList> stonecutterRecipes;
|
2020-12-24 16:23:47 +00:00
|
|
|
|
2020-06-17 00:03:28 +00:00
|
|
|
/**
|
|
|
|
* The current attack speed of the player. Used for sending proper cooldown timings.
|
2020-10-19 23:03:31 +00:00
|
|
|
* Setting a default fixes cooldowns not showing up on a fresh world.
|
2020-06-17 00:03:28 +00:00
|
|
|
*/
|
|
|
|
@Setter
|
2020-10-19 23:03:31 +00:00
|
|
|
private double attackSpeed = 4.0d;
|
2020-06-17 00:03:28 +00:00
|
|
|
/**
|
|
|
|
* The time of the last hit. Used to gauge how long the cooldown is taking.
|
|
|
|
* This is a session variable in order to prevent more scheduled threads than necessary.
|
|
|
|
*/
|
|
|
|
@Setter
|
|
|
|
private long lastHitTime;
|
|
|
|
|
2020-12-15 18:09:40 +00:00
|
|
|
/**
|
|
|
|
* Saves if the client is steering left on a boat.
|
|
|
|
*/
|
|
|
|
@Setter
|
|
|
|
private boolean steeringLeft;
|
|
|
|
/**
|
|
|
|
* Saves if the client is steering right on a boat.
|
|
|
|
*/
|
|
|
|
@Setter
|
|
|
|
private boolean steeringRight;
|
|
|
|
|
2020-09-24 16:54:18 +00:00
|
|
|
/**
|
|
|
|
* Store the last time the player interacted. Used to fix a right-click spam bug.
|
|
|
|
* See https://github.com/GeyserMC/Geyser/issues/503 for context.
|
|
|
|
*/
|
|
|
|
@Setter
|
|
|
|
private long lastInteractionTime;
|
|
|
|
|
2020-10-13 00:02:41 +00:00
|
|
|
/**
|
|
|
|
* Stores a future interaction to place a bucket. Will be cancelled if the client instead intended to
|
|
|
|
* interact with a block.
|
|
|
|
*/
|
|
|
|
@Setter
|
|
|
|
private ScheduledFuture<?> bucketScheduledFuture;
|
|
|
|
|
2020-11-02 21:04:08 +00:00
|
|
|
/**
|
2021-01-05 23:41:20 +00:00
|
|
|
* Used to send a movement packet every three seconds if the player hasn't moved. Prevents timeouts when AFK in certain instances.
|
2020-11-02 21:04:08 +00:00
|
|
|
*/
|
|
|
|
@Setter
|
2021-01-05 23:41:20 +00:00
|
|
|
private long lastMovementTimestamp = System.currentTimeMillis();
|
2020-11-02 21:04:08 +00:00
|
|
|
|
2021-04-15 19:31:03 +00:00
|
|
|
/**
|
|
|
|
* Used to send a ClientVehicleMovePacket for every PlayerInputPacket after idling on a boat/horse for more than 100ms
|
|
|
|
*/
|
|
|
|
@Setter
|
|
|
|
private long lastVehicleMoveTimestamp = System.currentTimeMillis();
|
|
|
|
|
2020-12-21 01:41:07 +00:00
|
|
|
/**
|
|
|
|
* Controls whether the daylight cycle gamerule has been sent to the client, so the sun/moon remain motionless.
|
|
|
|
*/
|
|
|
|
private boolean daylightCycle = true;
|
|
|
|
|
2020-08-08 22:41:12 +00:00
|
|
|
private boolean reducedDebugInfo = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The op permission level set by the server
|
|
|
|
*/
|
|
|
|
@Setter
|
|
|
|
private int opPermissionLevel = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If the current player can fly
|
|
|
|
*/
|
|
|
|
@Setter
|
|
|
|
private boolean canFly = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If the current player is flying
|
|
|
|
*/
|
|
|
|
private boolean flying = false;
|
|
|
|
|
2020-08-16 17:43:16 +00:00
|
|
|
/**
|
|
|
|
* Caches current rain status.
|
|
|
|
*/
|
|
|
|
@Setter
|
|
|
|
private boolean raining = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Caches current thunder status.
|
|
|
|
*/
|
|
|
|
@Setter
|
|
|
|
private boolean thunder = false;
|
|
|
|
|
2020-09-02 04:38:36 +00:00
|
|
|
/**
|
|
|
|
* Stores the last text inputted into a sign.
|
2020-10-29 23:58:17 +00:00
|
|
|
* <p>
|
2020-09-02 04:38:36 +00:00
|
|
|
* Bedrock sends packets every time you update the sign, Java only wants the final packet.
|
|
|
|
* Until we determine that the user has finished editing, we save the sign's current status.
|
|
|
|
*/
|
|
|
|
@Setter
|
|
|
|
private String lastSignMessage;
|
|
|
|
|
2020-10-24 22:33:49 +00:00
|
|
|
/**
|
|
|
|
* Stores a map of all statistics sent from the server.
|
|
|
|
* The server only sends new statistics back to us, so in order to show all statistics we need to cache existing ones.
|
|
|
|
*/
|
|
|
|
private final Map<Statistic, Integer> statistics = new HashMap<>();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether we're expecting statistics to be sent back to us.
|
|
|
|
*/
|
|
|
|
@Setter
|
|
|
|
private boolean waitingForStatistics = false;
|
|
|
|
|
2021-04-26 20:10:32 +00:00
|
|
|
private final Set<UUID> emotes;
|
2020-10-23 06:25:24 +00:00
|
|
|
|
2021-01-05 23:41:20 +00:00
|
|
|
/**
|
|
|
|
* The thread that will run every 50 milliseconds - one Minecraft tick.
|
|
|
|
*/
|
|
|
|
private ScheduledFuture<?> tickThread = null;
|
|
|
|
|
2020-08-21 00:53:47 +00:00
|
|
|
private MinecraftProtocol protocol;
|
|
|
|
|
2021-08-17 00:39:29 +00:00
|
|
|
public GeyserSession(GeyserConnector connector, BedrockServerSession bedrockServerSession, EventLoop eventLoop) {
|
2019-07-10 06:34:10 +00:00
|
|
|
this.connector = connector;
|
2019-10-02 20:45:29 +00:00
|
|
|
this.upstream = new UpstreamSession(bedrockServerSession);
|
2021-08-17 00:39:29 +00:00
|
|
|
this.eventLoop = eventLoop;
|
2019-07-23 23:16:25 +00:00
|
|
|
|
2021-01-12 02:23:09 +00:00
|
|
|
this.advancementsCache = new AdvancementsCache(this);
|
2021-01-08 00:40:34 +00:00
|
|
|
this.bookEditCache = new BookEditCache(this);
|
2019-09-15 23:34:14 +00:00
|
|
|
this.chunkCache = new ChunkCache(this);
|
2019-08-06 02:09:45 +00:00
|
|
|
this.entityCache = new EntityCache(this);
|
2020-11-20 19:56:39 +00:00
|
|
|
this.effectCache = new EntityEffectCache();
|
2021-06-05 22:53:58 +00:00
|
|
|
this.formCache = new FormCache(this);
|
2021-08-31 23:49:55 +00:00
|
|
|
this.lodestoneCache = new LodestoneCache();
|
2021-09-10 01:20:25 +00:00
|
|
|
this.pistonCache = new PistonCache(this);
|
2021-05-15 02:48:34 +00:00
|
|
|
this.preferencesCache = new PreferencesCache(this);
|
2021-05-03 01:47:11 +00:00
|
|
|
this.tagCache = new TagCache();
|
2020-08-08 22:41:12 +00:00
|
|
|
this.worldCache = new WorldCache(this);
|
2019-07-30 02:57:43 +00:00
|
|
|
|
2020-11-20 19:56:39 +00:00
|
|
|
this.collisionManager = new CollisionManager(this);
|
|
|
|
|
|
|
|
this.playerEntity = new SessionPlayerEntity(this);
|
2021-04-12 04:35:53 +00:00
|
|
|
collisionManager.updatePlayerBoundingBox(this.playerEntity.getPosition());
|
2020-10-16 23:25:05 +00:00
|
|
|
|
|
|
|
this.playerInventory = new PlayerInventory();
|
|
|
|
this.openInventory = null;
|
|
|
|
this.craftingRecipes = new Int2ObjectOpenHashMap<>();
|
2021-01-04 02:54:26 +00:00
|
|
|
this.unlockedRecipes = new ObjectOpenHashSet<>();
|
2021-01-09 02:01:31 +00:00
|
|
|
this.lastRecipeNetId = new AtomicInteger(1);
|
2019-08-06 02:09:45 +00:00
|
|
|
|
|
|
|
this.spawned = false;
|
2019-07-24 06:29:54 +00:00
|
|
|
this.loggedIn = false;
|
2019-08-06 02:09:45 +00:00
|
|
|
|
2021-04-26 20:10:32 +00:00
|
|
|
if (connector.getConfig().getEmoteOffhandWorkaround() != EmoteOffhandWorkaroundOption.NO_EMOTES) {
|
|
|
|
this.emotes = new HashSet<>();
|
|
|
|
// Make a copy to prevent ConcurrentModificationException
|
|
|
|
final List<GeyserSession> tmpPlayers = new ArrayList<>(connector.getPlayers());
|
|
|
|
tmpPlayers.forEach(player -> this.emotes.addAll(player.getEmotes()));
|
|
|
|
} else {
|
|
|
|
this.emotes = null;
|
|
|
|
}
|
2020-10-23 06:25:24 +00:00
|
|
|
|
2020-07-07 01:11:34 +00:00
|
|
|
bedrockServerSession.addDisconnectHandler(disconnectReason -> {
|
2021-02-17 23:25:41 +00:00
|
|
|
InetAddress address = bedrockServerSession.getRealAddress().getAddress();
|
|
|
|
connector.getLogger().info(LanguageUtils.getLocaleStringLog("geyser.network.disconnect", address, disconnectReason));
|
2020-07-07 01:11:34 +00:00
|
|
|
|
|
|
|
disconnect(disconnectReason.name());
|
|
|
|
connector.removePlayer(this);
|
|
|
|
});
|
2019-07-10 06:34:10 +00:00
|
|
|
}
|
|
|
|
|
2021-03-17 15:15:57 +00:00
|
|
|
/**
|
|
|
|
* Send all necessary packets to load Bedrock into the server
|
|
|
|
*/
|
|
|
|
public void connect() {
|
2019-07-24 06:29:54 +00:00
|
|
|
startGame();
|
2021-03-17 15:15:57 +00:00
|
|
|
this.remoteAddress = connector.getConfig().getRemote().getAddress();
|
|
|
|
this.remotePort = connector.getConfig().getRemote().getPort();
|
2021-07-28 23:44:09 +00:00
|
|
|
this.remoteAuthType = connector.getConfig().getRemote().getAuthType();
|
2019-11-06 00:55:59 +00:00
|
|
|
|
2020-12-09 16:30:59 +00:00
|
|
|
// Set the hardcoded shield ID to the ID we just defined in StartGamePacket
|
2021-07-13 01:19:40 +00:00
|
|
|
upstream.getSession().getHardcodedBlockingId().set(this.itemMappings.getStoredItems().shield().getBedrockId());
|
2020-12-09 16:30:59 +00:00
|
|
|
|
2021-07-13 01:19:40 +00:00
|
|
|
if (this.itemMappings.getFurnaceMinecartData() != null) {
|
2021-03-31 18:06:05 +00:00
|
|
|
ItemComponentPacket componentPacket = new ItemComponentPacket();
|
2021-07-13 01:19:40 +00:00
|
|
|
componentPacket.getItems().add(this.itemMappings.getFurnaceMinecartData());
|
2021-03-31 18:06:05 +00:00
|
|
|
upstream.sendPacket(componentPacket);
|
|
|
|
}
|
|
|
|
|
2019-12-29 03:17:00 +00:00
|
|
|
ChunkUtils.sendEmptyChunks(this, playerEntity.getPosition().toInt(), 0, false);
|
2019-11-06 00:55:59 +00:00
|
|
|
|
2020-03-06 02:53:58 +00:00
|
|
|
BiomeDefinitionListPacket biomeDefinitionListPacket = new BiomeDefinitionListPacket();
|
2021-07-28 00:29:27 +00:00
|
|
|
biomeDefinitionListPacket.setDefinitions(Registries.BIOMES_NBT.get());
|
2020-03-06 02:53:58 +00:00
|
|
|
upstream.sendPacket(biomeDefinitionListPacket);
|
2019-11-16 04:21:26 +00:00
|
|
|
|
2019-11-14 02:26:45 +00:00
|
|
|
AvailableEntityIdentifiersPacket entityPacket = new AvailableEntityIdentifiersPacket();
|
2021-07-13 01:19:40 +00:00
|
|
|
entityPacket.setIdentifiers(Registries.ENTITY_IDENTIFIERS.get());
|
2019-11-14 02:26:45 +00:00
|
|
|
upstream.sendPacket(entityPacket);
|
2019-11-10 22:53:01 +00:00
|
|
|
|
2020-06-27 15:35:02 +00:00
|
|
|
CreativeContentPacket creativePacket = new CreativeContentPacket();
|
2021-07-13 01:19:40 +00:00
|
|
|
creativePacket.setContents(this.itemMappings.getCreativeItems());
|
2019-11-15 23:55:15 +00:00
|
|
|
upstream.sendPacket(creativePacket);
|
|
|
|
|
2019-11-06 00:55:59 +00:00
|
|
|
PlayStatusPacket playStatusPacket = new PlayStatusPacket();
|
|
|
|
playStatusPacket.setStatus(PlayStatusPacket.Status.PLAYER_SPAWN);
|
|
|
|
upstream.sendPacket(playStatusPacket);
|
2020-06-08 12:13:25 +00:00
|
|
|
|
|
|
|
UpdateAttributesPacket attributesPacket = new UpdateAttributesPacket();
|
|
|
|
attributesPacket.setRuntimeEntityId(getPlayerEntity().getGeyserId());
|
|
|
|
// Default move speed
|
|
|
|
// Bedrock clients move very fast by default until they get an attribute packet correcting the speed
|
2021-03-31 18:15:55 +00:00
|
|
|
attributesPacket.setAttributes(Collections.singletonList(
|
|
|
|
new AttributeData("minecraft:movement", 0.0f, 1024f, 0.1f, 0.1f)));
|
2020-06-08 12:13:25 +00:00
|
|
|
upstream.sendPacket(attributesPacket);
|
2020-08-08 21:50:49 +00:00
|
|
|
|
2020-09-02 04:37:24 +00:00
|
|
|
GameRulesChangedPacket gamerulePacket = new GameRulesChangedPacket();
|
2020-08-08 21:50:49 +00:00
|
|
|
// Only allow the server to send health information
|
|
|
|
// Setting this to false allows natural regeneration to work false but doesn't break it being true
|
|
|
|
gamerulePacket.getGameRules().add(new GameRuleData<>("naturalregeneration", false));
|
2020-09-02 04:37:24 +00:00
|
|
|
// Don't let the client modify the inventory on death
|
|
|
|
// Setting this to true allows keep inventory to work if enabled but doesn't break functionality being false
|
|
|
|
gamerulePacket.getGameRules().add(new GameRuleData<>("keepinventory", true));
|
2020-12-12 07:22:57 +00:00
|
|
|
// Ensure client doesn't try and do anything funky; the server handles this for us
|
|
|
|
gamerulePacket.getGameRules().add(new GameRuleData<>("spawnradius", 0));
|
2020-08-08 21:50:49 +00:00
|
|
|
upstream.sendPacket(gamerulePacket);
|
2019-07-24 06:29:54 +00:00
|
|
|
}
|
2019-07-10 06:34:10 +00:00
|
|
|
|
2020-04-11 18:33:06 +00:00
|
|
|
public void login() {
|
2021-03-17 15:15:57 +00:00
|
|
|
if (this.remoteAuthType != AuthType.ONLINE) {
|
|
|
|
if (this.remoteAuthType == AuthType.OFFLINE) {
|
2020-07-05 23:35:51 +00:00
|
|
|
connector.getLogger().info(LanguageUtils.getLocaleStringLog("geyser.auth.login.offline"));
|
|
|
|
} else {
|
|
|
|
connector.getLogger().info(LanguageUtils.getLocaleStringLog("geyser.auth.login.floodgate"));
|
|
|
|
}
|
2020-04-11 18:33:06 +00:00
|
|
|
authenticate(authData.getName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-24 06:29:54 +00:00
|
|
|
public void authenticate(String username) {
|
|
|
|
authenticate(username, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
public void authenticate(String username, String password) {
|
|
|
|
if (loggedIn) {
|
2020-07-05 23:35:51 +00:00
|
|
|
connector.getLogger().severe(LanguageUtils.getLocaleStringLog("geyser.auth.already_loggedin", username));
|
2019-07-24 06:29:54 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-07-10 06:34:10 +00:00
|
|
|
|
2020-04-11 18:53:27 +00:00
|
|
|
loggingIn = true;
|
2021-07-18 22:04:16 +00:00
|
|
|
|
|
|
|
// Use a future to prevent timeouts as all the authentication is handled sync
|
|
|
|
// This will be changed with the new protocol library.
|
|
|
|
CompletableFuture.supplyAsync(() -> {
|
2019-09-21 07:42:44 +00:00
|
|
|
try {
|
|
|
|
if (password != null && !password.isEmpty()) {
|
2021-01-11 20:52:02 +00:00
|
|
|
AuthenticationService authenticationService;
|
|
|
|
if (microsoftAccount) {
|
|
|
|
authenticationService = new MsaAuthenticationService(GeyserConnector.OAUTH_CLIENT_ID);
|
|
|
|
} else {
|
|
|
|
authenticationService = new MojangAuthenticationService();
|
|
|
|
}
|
|
|
|
authenticationService.setUsername(username);
|
|
|
|
authenticationService.setPassword(password);
|
|
|
|
authenticationService.login();
|
|
|
|
|
2021-05-23 19:55:01 +00:00
|
|
|
protocol = new MinecraftProtocol(authenticationService.getSelectedProfile(), authenticationService.getAccessToken());
|
2019-09-21 07:42:44 +00:00
|
|
|
} else {
|
2021-05-29 22:22:11 +00:00
|
|
|
// always replace spaces when using Floodgate,
|
2021-05-29 22:51:04 +00:00
|
|
|
// as usernames with spaces cause issues with Bungeecord's login cycle.
|
|
|
|
// However, this doesn't affect the final username as Floodgate is still in charge of that.
|
|
|
|
// So if you have (for example) replace spaces enabled on Floodgate the spaces will re-appear.
|
2021-05-29 22:22:11 +00:00
|
|
|
String validUsername = username;
|
|
|
|
if (remoteAuthType == AuthType.FLOODGATE) {
|
|
|
|
validUsername = username.replace(' ', '_');
|
|
|
|
}
|
|
|
|
|
|
|
|
protocol = new MinecraftProtocol(validUsername);
|
2019-07-24 06:29:54 +00:00
|
|
|
}
|
2021-01-11 20:52:02 +00:00
|
|
|
} catch (InvalidCredentialsException | IllegalArgumentException e) {
|
|
|
|
connector.getLogger().info(LanguageUtils.getLocaleStringLog("geyser.auth.login.invalid", username));
|
|
|
|
disconnect(LanguageUtils.getPlayerLocaleString("geyser.auth.login.invalid.kick", getClientData().getLanguageCode()));
|
|
|
|
} catch (RequestException ex) {
|
|
|
|
ex.printStackTrace();
|
2021-08-12 18:35:26 +00:00
|
|
|
disconnect(ex.getMessage());
|
2021-01-11 20:52:02 +00:00
|
|
|
}
|
2021-07-18 22:04:16 +00:00
|
|
|
return null;
|
2021-08-12 18:35:26 +00:00
|
|
|
}).whenComplete((aVoid, ex) -> {
|
|
|
|
if (this.closed) {
|
|
|
|
// Client disconnected during the authentication attempt
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
connectDownstream();
|
|
|
|
});
|
2021-01-11 20:52:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Present a form window to the user asking to log in with another web browser
|
|
|
|
*/
|
|
|
|
public void authenticateWithMicrosoftCode() {
|
|
|
|
if (loggedIn) {
|
|
|
|
connector.getLogger().severe(LanguageUtils.getLocaleStringLog("geyser.auth.already_loggedin", getAuthData().getName()));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
loggingIn = true;
|
|
|
|
|
2021-07-22 02:39:30 +00:00
|
|
|
// This just looks cool
|
|
|
|
SetTimePacket packet = new SetTimePacket();
|
|
|
|
packet.setTime(16000);
|
|
|
|
sendUpstreamPacket(packet);
|
2021-01-11 20:52:02 +00:00
|
|
|
|
2021-07-22 02:39:30 +00:00
|
|
|
// new thread so clients don't timeout
|
|
|
|
MsaAuthenticationService msaAuthenticationService = new MsaAuthenticationService(GeyserConnector.OAUTH_CLIENT_ID);
|
2021-01-11 20:52:02 +00:00
|
|
|
|
2021-07-22 02:39:30 +00:00
|
|
|
// Use a future to prevent timeouts as all the authentication is handled sync
|
|
|
|
// This will be changed with the new protocol library.
|
|
|
|
CompletableFuture.supplyAsync(() -> {
|
|
|
|
try {
|
|
|
|
return msaAuthenticationService.getAuthCode();
|
|
|
|
} catch (RequestException e) {
|
|
|
|
throw new CompletionException(e);
|
|
|
|
}
|
|
|
|
}).whenComplete((response, ex) -> {
|
|
|
|
if (ex != null) {
|
2021-01-11 20:52:02 +00:00
|
|
|
ex.printStackTrace();
|
2021-07-22 02:39:30 +00:00
|
|
|
return;
|
2021-01-11 20:52:02 +00:00
|
|
|
}
|
2021-07-22 02:39:30 +00:00
|
|
|
LoginEncryptionUtils.buildAndShowMicrosoftCodeWindow(this, response);
|
|
|
|
attemptCodeAuthentication(msaAuthenticationService);
|
|
|
|
});
|
2021-01-11 20:52:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Poll every second to see if the user has successfully signed in
|
|
|
|
*/
|
|
|
|
private void attemptCodeAuthentication(MsaAuthenticationService msaAuthenticationService) {
|
|
|
|
if (loggedIn || closed) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
msaAuthenticationService.login();
|
2021-05-23 19:55:01 +00:00
|
|
|
protocol = new MinecraftProtocol(msaAuthenticationService.getSelectedProfile(), msaAuthenticationService.getAccessToken());
|
2021-01-11 20:52:02 +00:00
|
|
|
|
|
|
|
connectDownstream();
|
|
|
|
} catch (RequestException e) {
|
|
|
|
if (!(e instanceof AuthPendingException)) {
|
2021-09-08 14:13:46 +00:00
|
|
|
connector.getLogger().error("Failed to log in with Microsoft code!", e);
|
|
|
|
disconnect(e.toString());
|
2021-01-11 20:52:02 +00:00
|
|
|
} else {
|
|
|
|
// Wait one second before trying again
|
|
|
|
connector.getGeneralThreadPool().schedule(() -> attemptCodeAuthentication(msaAuthenticationService), 1, TimeUnit.SECONDS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* After getting whatever credentials needed, we attempt to join the Java server.
|
|
|
|
*/
|
|
|
|
private void connectDownstream() {
|
2021-03-17 15:15:57 +00:00
|
|
|
boolean floodgate = this.remoteAuthType == AuthType.FLOODGATE;
|
2021-01-11 20:52:02 +00:00
|
|
|
|
|
|
|
// Start ticking
|
2021-08-17 00:39:29 +00:00
|
|
|
tickThread = eventLoop.scheduleAtFixedRate(this::tick, 50, 50, TimeUnit.MILLISECONDS);
|
2021-01-11 20:52:02 +00:00
|
|
|
|
2021-05-23 19:55:01 +00:00
|
|
|
downstream = new TcpClientSession(this.remoteAddress, this.remotePort, protocol);
|
2021-03-17 15:15:57 +00:00
|
|
|
disableSrvResolving();
|
2021-01-11 20:52:02 +00:00
|
|
|
if (connector.getConfig().getRemote().isUseProxyProtocol()) {
|
2021-05-23 19:55:01 +00:00
|
|
|
downstream.setFlag(BuiltinFlags.ENABLE_CLIENT_PROXY_PROTOCOL, true);
|
|
|
|
downstream.setFlag(BuiltinFlags.CLIENT_PROXIED_ADDRESS, upstream.getAddress());
|
2021-01-11 20:52:02 +00:00
|
|
|
}
|
2021-02-10 17:18:31 +00:00
|
|
|
if (connector.getConfig().isForwardPlayerPing()) {
|
|
|
|
// Let Geyser handle sending the keep alive
|
2021-05-23 19:55:01 +00:00
|
|
|
downstream.setFlag(MinecraftConstants.AUTOMATIC_KEEP_ALIVE_MANAGEMENT, false);
|
2021-02-10 17:18:31 +00:00
|
|
|
}
|
2021-05-23 19:55:01 +00:00
|
|
|
downstream.addListener(new SessionAdapter() {
|
2021-01-11 20:52:02 +00:00
|
|
|
@Override
|
|
|
|
public void packetSending(PacketSendingEvent event) {
|
|
|
|
//todo move this somewhere else
|
2021-04-21 18:55:08 +00:00
|
|
|
if (event.getPacket() instanceof HandshakePacket) {
|
|
|
|
String addressSuffix;
|
|
|
|
if (floodgate) {
|
2021-05-01 10:16:25 +00:00
|
|
|
byte[] encryptedData;
|
|
|
|
|
2021-04-21 18:55:08 +00:00
|
|
|
try {
|
2021-05-01 10:16:25 +00:00
|
|
|
FloodgateSkinUploader skinUploader = connector.getSkinUploader();
|
|
|
|
FloodgateCipher cipher = connector.getCipher();
|
|
|
|
|
|
|
|
encryptedData = cipher.encryptFromString(BedrockData.of(
|
2021-04-21 18:55:08 +00:00
|
|
|
clientData.getGameVersion(),
|
|
|
|
authData.getName(),
|
|
|
|
authData.getXboxUUID(),
|
2021-05-01 10:16:25 +00:00
|
|
|
clientData.getDeviceOs().ordinal(),
|
2021-04-21 18:55:08 +00:00
|
|
|
clientData.getLanguageCode(),
|
2021-05-01 10:16:25 +00:00
|
|
|
clientData.getUiProfile().ordinal(),
|
2021-04-21 18:55:08 +00:00
|
|
|
clientData.getCurrentInputMode().ordinal(),
|
2021-05-01 10:16:25 +00:00
|
|
|
upstream.getAddress().getAddress().getHostAddress(),
|
|
|
|
skinUploader.getId(),
|
2021-05-25 23:55:58 +00:00
|
|
|
skinUploader.getVerifyCode(),
|
|
|
|
connector.getTimeSyncer()
|
2021-05-01 10:16:25 +00:00
|
|
|
).toString());
|
2021-05-26 18:20:59 +00:00
|
|
|
|
|
|
|
if (!connector.getTimeSyncer().hasUsefulOffset()) {
|
|
|
|
connector.getLogger().warning(
|
|
|
|
"We couldn't make sure that your system clock is accurate. " +
|
|
|
|
"This can cause issues with logging in."
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-04-21 18:55:08 +00:00
|
|
|
} catch (Exception e) {
|
|
|
|
connector.getLogger().error(LanguageUtils.getLocaleStringLog("geyser.auth.floodgate.encrypt_fail"), e);
|
2021-05-01 10:16:25 +00:00
|
|
|
disconnect(LanguageUtils.getPlayerLocaleString("geyser.auth.floodgate.encryption_fail", getClientData().getLanguageCode()));
|
|
|
|
return;
|
2021-04-21 18:55:08 +00:00
|
|
|
}
|
|
|
|
|
2021-05-01 10:16:25 +00:00
|
|
|
addressSuffix = '\0' + new String(encryptedData, StandardCharsets.UTF_8);
|
2021-04-21 18:55:08 +00:00
|
|
|
} else {
|
|
|
|
addressSuffix = "";
|
2019-11-30 12:34:45 +00:00
|
|
|
}
|
|
|
|
|
2021-01-11 20:52:02 +00:00
|
|
|
HandshakePacket handshakePacket = event.getPacket();
|
2021-04-21 18:55:08 +00:00
|
|
|
|
|
|
|
String address;
|
|
|
|
if (connector.getConfig().getRemote().isForwardHost()) {
|
|
|
|
address = clientData.getServerAddress().split(":")[0];
|
|
|
|
} else {
|
|
|
|
address = handshakePacket.getHostname();
|
|
|
|
}
|
|
|
|
|
2021-01-11 20:52:02 +00:00
|
|
|
event.setPacket(new HandshakePacket(
|
|
|
|
handshakePacket.getProtocolVersion(),
|
2021-04-21 18:55:08 +00:00
|
|
|
address + addressSuffix,
|
2021-01-11 20:52:02 +00:00
|
|
|
handshakePacket.getPort(),
|
|
|
|
handshakePacket.getIntent()
|
|
|
|
));
|
2019-11-30 17:38:09 +00:00
|
|
|
}
|
2021-01-11 20:52:02 +00:00
|
|
|
}
|
2019-11-30 17:38:09 +00:00
|
|
|
|
2021-01-11 20:52:02 +00:00
|
|
|
@Override
|
|
|
|
public void connected(ConnectedEvent event) {
|
|
|
|
loggingIn = false;
|
|
|
|
loggedIn = true;
|
|
|
|
if (protocol.getProfile() == null) {
|
|
|
|
// Java account is offline
|
|
|
|
disconnect(LanguageUtils.getPlayerLocaleString("geyser.network.remote.invalid_account", clientData.getLanguageCode()));
|
|
|
|
return;
|
2020-12-24 01:47:29 +00:00
|
|
|
}
|
2021-07-31 16:52:49 +00:00
|
|
|
|
|
|
|
if (downstream.isInternallyConnecting()) {
|
|
|
|
// Connected directly to the server
|
|
|
|
connector.getLogger().info(LanguageUtils.getLocaleStringLog("geyser.network.remote.connect_internal",
|
|
|
|
authData.getName(), protocol.getProfile().getName()));
|
|
|
|
} else {
|
|
|
|
// Connected to an IP address
|
|
|
|
connector.getLogger().info(LanguageUtils.getLocaleStringLog("geyser.network.remote.connect",
|
|
|
|
authData.getName(), protocol.getProfile().getName(), remoteAddress));
|
|
|
|
}
|
|
|
|
|
2021-03-25 00:03:51 +00:00
|
|
|
UUID uuid = protocol.getProfile().getId();
|
|
|
|
if (uuid == null) {
|
|
|
|
// Set what our UUID *probably* is going to be
|
|
|
|
if (remoteAuthType == AuthType.FLOODGATE) {
|
|
|
|
uuid = new UUID(0, Long.parseLong(authData.getXboxUUID()));
|
|
|
|
} else {
|
|
|
|
uuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + protocol.getProfile().getName()).getBytes(StandardCharsets.UTF_8));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
playerEntity.setUuid(uuid);
|
2021-01-11 20:52:02 +00:00
|
|
|
playerEntity.setUsername(protocol.getProfile().getName());
|
2019-09-21 07:42:44 +00:00
|
|
|
|
2021-01-11 20:52:02 +00:00
|
|
|
String locale = clientData.getLanguageCode();
|
2020-04-09 16:21:51 +00:00
|
|
|
|
2021-01-11 20:52:02 +00:00
|
|
|
// Let the user know there locale may take some time to download
|
|
|
|
// as it has to be extracted from a JAR
|
2021-03-31 18:15:55 +00:00
|
|
|
if (locale.equalsIgnoreCase("en_us") && !LocaleUtils.LOCALE_MAPPINGS.containsKey("en_us")) {
|
2021-01-11 20:52:02 +00:00
|
|
|
// This should probably be left hardcoded as it will only show for en_us clients
|
|
|
|
sendMessage("Loading your locale (en_us); if this isn't already downloaded, this may take some time");
|
|
|
|
}
|
2020-04-09 16:06:17 +00:00
|
|
|
|
2021-01-11 20:52:02 +00:00
|
|
|
// Download and load the language for the player
|
|
|
|
LocaleUtils.downloadAndLoadLocale(locale);
|
|
|
|
}
|
2019-09-21 07:42:44 +00:00
|
|
|
|
2021-01-11 20:52:02 +00:00
|
|
|
@Override
|
|
|
|
public void disconnected(DisconnectedEvent event) {
|
|
|
|
loggingIn = false;
|
|
|
|
loggedIn = false;
|
2021-07-31 16:52:49 +00:00
|
|
|
if (downstream != null && downstream.isInternallyConnecting()) {
|
|
|
|
connector.getLogger().info(LanguageUtils.getLocaleStringLog("geyser.network.remote.disconnect_internal", authData.getName(), event.getReason()));
|
|
|
|
} else {
|
|
|
|
connector.getLogger().info(LanguageUtils.getLocaleStringLog("geyser.network.remote.disconnect", authData.getName(), remoteAddress, event.getReason()));
|
|
|
|
}
|
2021-01-11 20:52:02 +00:00
|
|
|
if (event.getCause() != null) {
|
|
|
|
event.getCause().printStackTrace();
|
|
|
|
}
|
2020-06-28 22:38:27 +00:00
|
|
|
|
2021-01-11 20:52:02 +00:00
|
|
|
upstream.disconnect(MessageTranslator.convertMessageLenient(event.getReason()));
|
|
|
|
}
|
2019-09-21 07:42:44 +00:00
|
|
|
|
2021-01-11 20:52:02 +00:00
|
|
|
@Override
|
|
|
|
public void packetReceived(PacketReceivedEvent event) {
|
2021-08-18 00:57:46 +00:00
|
|
|
Packet packet = event.getPacket();
|
|
|
|
PacketTranslatorRegistry.JAVA_TRANSLATOR.translate(packet.getClass(), packet, GeyserSession.this);
|
2021-01-11 20:52:02 +00:00
|
|
|
}
|
2019-09-21 07:42:44 +00:00
|
|
|
|
2021-01-11 20:52:02 +00:00
|
|
|
@Override
|
|
|
|
public void packetError(PacketErrorEvent event) {
|
|
|
|
connector.getLogger().warning(LanguageUtils.getLocaleStringLog("geyser.network.downstream_error", event.getCause().getMessage()));
|
2021-06-08 12:57:03 +00:00
|
|
|
if (connector.getConfig().isDebugMode())
|
2021-01-11 20:52:02 +00:00
|
|
|
event.getCause().printStackTrace();
|
|
|
|
event.setSuppress(true);
|
2019-09-21 07:42:44 +00:00
|
|
|
}
|
2021-01-11 20:52:02 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
if (!daylightCycle) {
|
|
|
|
setDaylightCycle(true);
|
|
|
|
}
|
2021-07-31 16:52:49 +00:00
|
|
|
boolean internalConnect = false;
|
|
|
|
if (connector.getBootstrap().getSocketAddress() != null) {
|
|
|
|
try {
|
|
|
|
// Only affects Waterfall, but there is no sure way to differentiate between a proxy with this patch and a proxy without this patch
|
|
|
|
// Patch causing the issue: https://github.com/PaperMC/Waterfall/blob/7e6af4cef64d5d377a6ffd00a534379e6efa94cf/BungeeCord-Patches/0045-Don-t-use-a-bytebuf-for-packet-decoding.patch
|
|
|
|
// If native compression is enabled, then this line is tripped up if a heap buffer is sent over in such a situation
|
|
|
|
// as a new direct buffer is not created with that patch (HeapByteBufs throw an UnsupportedOperationException here):
|
|
|
|
// https://github.com/SpigotMC/BungeeCord/blob/a283aaf724d4c9a815540cd32f3aafaa72df9e05/native/src/main/java/net/md_5/bungee/jni/zlib/NativeZlib.java#L43
|
|
|
|
// This issue could be mitigated down the line by preventing Bungee from setting compression
|
|
|
|
downstream.setFlag(BuiltinFlags.USE_ONLY_DIRECT_BUFFERS, connector.getPlatformType() == PlatformType.BUNGEECORD);
|
|
|
|
|
2021-08-31 23:57:56 +00:00
|
|
|
downstream.connectInternal(connector.getBootstrap().getSocketAddress(), upstream.getAddress().getAddress().getHostAddress());
|
2021-07-31 16:52:49 +00:00
|
|
|
internalConnect = true;
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!internalConnect) {
|
|
|
|
downstream.connect();
|
|
|
|
}
|
2021-01-11 20:52:02 +00:00
|
|
|
connector.addPlayer(this);
|
2019-07-10 06:34:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void disconnect(String reason) {
|
|
|
|
if (!closed) {
|
2019-07-24 06:29:54 +00:00
|
|
|
loggedIn = false;
|
2021-05-23 19:55:01 +00:00
|
|
|
if (downstream != null) {
|
|
|
|
downstream.disconnect(reason);
|
2019-08-02 20:54:40 +00:00
|
|
|
}
|
2019-09-13 13:37:31 +00:00
|
|
|
if (upstream != null && !upstream.isClosed()) {
|
2020-07-07 01:11:34 +00:00
|
|
|
connector.getPlayers().remove(this);
|
2019-08-02 20:54:40 +00:00
|
|
|
upstream.disconnect(reason);
|
|
|
|
}
|
2019-07-10 06:34:10 +00:00
|
|
|
}
|
2019-08-06 02:09:45 +00:00
|
|
|
|
2021-01-06 04:28:31 +00:00
|
|
|
if (tickThread != null) {
|
|
|
|
tickThread.cancel(true);
|
|
|
|
}
|
2021-01-05 23:41:20 +00:00
|
|
|
|
2021-01-12 02:23:09 +00:00
|
|
|
this.advancementsCache = null;
|
2021-01-08 00:40:34 +00:00
|
|
|
this.bookEditCache = null;
|
2020-04-29 20:01:53 +00:00
|
|
|
this.chunkCache = null;
|
|
|
|
this.entityCache = null;
|
2020-11-20 19:56:39 +00:00
|
|
|
this.effectCache = null;
|
2020-08-08 22:41:12 +00:00
|
|
|
this.worldCache = null;
|
2020-04-25 22:53:35 +00:00
|
|
|
|
2019-08-06 02:09:45 +00:00
|
|
|
closed = true;
|
2019-07-10 06:34:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void close() {
|
2020-07-05 23:35:51 +00:00
|
|
|
disconnect(LanguageUtils.getPlayerLocaleString("geyser.network.close", getClientData().getLanguageCode()));
|
2019-07-10 06:34:10 +00:00
|
|
|
}
|
|
|
|
|
2021-08-18 00:57:46 +00:00
|
|
|
/**
|
|
|
|
* Executes a task and prints a stack trace if an error occurs.
|
|
|
|
*/
|
|
|
|
public void executeInEventLoop(Runnable runnable) {
|
|
|
|
eventLoop.execute(() -> {
|
|
|
|
try {
|
|
|
|
runnable.run();
|
|
|
|
} catch (Throwable e) {
|
2021-08-21 23:38:13 +00:00
|
|
|
connector.getLogger().error("Error thrown in " + getName() + "'s event loop!", e);
|
2021-08-18 00:57:46 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Schedules a task and prints a stack trace if an error occurs.
|
|
|
|
*/
|
|
|
|
public ScheduledFuture<?> scheduleInEventLoop(Runnable runnable, long duration, TimeUnit timeUnit) {
|
|
|
|
return eventLoop.schedule(() -> {
|
|
|
|
try {
|
|
|
|
runnable.run();
|
|
|
|
} catch (Throwable e) {
|
2021-08-21 23:38:13 +00:00
|
|
|
connector.getLogger().error("Error thrown in " + getName() + "'s event loop!", e);
|
2021-08-18 00:57:46 +00:00
|
|
|
}
|
|
|
|
}, duration, timeUnit);
|
|
|
|
}
|
|
|
|
|
2021-01-05 23:41:20 +00:00
|
|
|
/**
|
|
|
|
* Called every 50 milliseconds - one Minecraft tick.
|
|
|
|
*/
|
2021-04-26 18:15:24 +00:00
|
|
|
protected void tick() {
|
2021-08-18 02:44:33 +00:00
|
|
|
try {
|
2021-09-10 01:20:25 +00:00
|
|
|
pistonCache.tick();
|
2021-08-18 02:44:33 +00:00
|
|
|
// Check to see if the player's position needs updating - a position update should be sent once every 3 seconds
|
|
|
|
if (spawned && (System.currentTimeMillis() - lastMovementTimestamp) > 3000) {
|
|
|
|
// Recalculate in case something else changed position
|
|
|
|
Vector3d position = collisionManager.adjustBedrockPosition(playerEntity.getPosition(), playerEntity.isOnGround());
|
|
|
|
// A null return value cancels the packet
|
|
|
|
if (position != null) {
|
|
|
|
ClientPlayerPositionPacket packet = new ClientPlayerPositionPacket(playerEntity.isOnGround(),
|
|
|
|
position.getX(), position.getY(), position.getZ());
|
|
|
|
sendDownstreamPacket(packet);
|
|
|
|
}
|
|
|
|
lastMovementTimestamp = System.currentTimeMillis();
|
2021-01-05 23:41:20 +00:00
|
|
|
}
|
|
|
|
|
2021-08-18 02:44:33 +00:00
|
|
|
for (Tickable entity : entityCache.getTickableEntities()) {
|
|
|
|
entity.tick(this);
|
|
|
|
}
|
|
|
|
} catch (Throwable throwable) {
|
|
|
|
throwable.printStackTrace();
|
2021-01-05 23:41:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-23 23:16:25 +00:00
|
|
|
public void setAuthenticationData(AuthData authData) {
|
2019-12-21 17:35:48 +00:00
|
|
|
this.authData = authData;
|
2019-07-10 06:34:10 +00:00
|
|
|
}
|
|
|
|
|
2020-11-20 19:56:39 +00:00
|
|
|
public void setSneaking(boolean sneaking) {
|
|
|
|
this.sneaking = sneaking;
|
2021-04-12 04:35:53 +00:00
|
|
|
|
|
|
|
// Update pose and bounding box on our end
|
2021-07-08 02:44:53 +00:00
|
|
|
AttributeData speedAttribute;
|
|
|
|
if (!sneaking && (speedAttribute = adjustSpeed()) != null) {
|
2021-04-12 04:35:53 +00:00
|
|
|
// Update attributes since we're still "sneaking" under a 1.5-block-tall area
|
2021-07-08 02:44:53 +00:00
|
|
|
UpdateAttributesPacket attributesPacket = new UpdateAttributesPacket();
|
|
|
|
attributesPacket.setRuntimeEntityId(playerEntity.getGeyserId());
|
|
|
|
attributesPacket.setAttributes(Collections.singletonList(speedAttribute));
|
|
|
|
sendUpstreamPacket(attributesPacket);
|
2021-04-12 04:35:53 +00:00
|
|
|
// the server *should* update our pose once it has returned to normal
|
|
|
|
} else {
|
2021-04-12 16:42:42 +00:00
|
|
|
if (!flying) {
|
|
|
|
// The pose and bounding box should not be updated if the player is flying
|
|
|
|
setSneakingPose(sneaking);
|
|
|
|
}
|
2021-04-12 04:35:53 +00:00
|
|
|
collisionManager.updateScaffoldingFlags(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
playerEntity.updateBedrockMetadata(this);
|
2021-03-18 05:11:21 +00:00
|
|
|
|
|
|
|
if (mouseoverEntity != null) {
|
|
|
|
// Horses, etc can change their property depending on if you're sneaking
|
|
|
|
InteractiveTagManager.updateTag(this, mouseoverEntity);
|
|
|
|
}
|
2020-11-20 19:56:39 +00:00
|
|
|
}
|
|
|
|
|
2021-04-12 16:42:42 +00:00
|
|
|
private void setSneakingPose(boolean sneaking) {
|
|
|
|
this.pose = sneaking ? Pose.SNEAKING : Pose.STANDING;
|
|
|
|
playerEntity.getMetadata().put(EntityData.BOUNDING_BOX_HEIGHT, sneaking ? 1.5f : playerEntity.getEntityType().getHeight());
|
|
|
|
playerEntity.getMetadata().getFlags().setFlag(EntityFlag.SNEAKING, sneaking);
|
|
|
|
|
|
|
|
collisionManager.updatePlayerBoundingBox();
|
|
|
|
}
|
|
|
|
|
2021-04-12 04:35:53 +00:00
|
|
|
public void setSwimming(boolean swimming) {
|
|
|
|
this.pose = swimming ? Pose.SWIMMING : Pose.STANDING;
|
|
|
|
playerEntity.getMetadata().put(EntityData.BOUNDING_BOX_HEIGHT, swimming ? 0.6f : playerEntity.getEntityType().getHeight());
|
|
|
|
playerEntity.getMetadata().getFlags().setFlag(EntityFlag.SWIMMING, swimming);
|
|
|
|
playerEntity.updateBedrockMetadata(this);
|
|
|
|
}
|
|
|
|
|
2021-04-12 16:42:42 +00:00
|
|
|
public void setFlying(boolean flying) {
|
|
|
|
this.flying = flying;
|
|
|
|
|
|
|
|
if (sneaking) {
|
|
|
|
// update bounding box as it is not reduced when flying
|
|
|
|
setSneakingPose(!flying);
|
|
|
|
playerEntity.updateBedrockMetadata(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-12 04:35:53 +00:00
|
|
|
/**
|
|
|
|
* Adjusts speed if the player is crawling.
|
|
|
|
*
|
2021-07-08 02:44:53 +00:00
|
|
|
* @return not null if attributes should be updated.
|
2021-04-12 04:35:53 +00:00
|
|
|
*/
|
2021-07-08 02:44:53 +00:00
|
|
|
public AttributeData adjustSpeed() {
|
|
|
|
AttributeData currentPlayerSpeed = playerEntity.getAttributes().get(GeyserAttributeType.MOVEMENT_SPEED);
|
2021-04-12 04:35:53 +00:00
|
|
|
if (currentPlayerSpeed != null) {
|
|
|
|
if ((pose.equals(Pose.SNEAKING) && !sneaking && collisionManager.isUnderSlab()) ||
|
|
|
|
(!swimmingInWater && playerEntity.getMetadata().getFlags().getFlag(EntityFlag.SWIMMING) && !collisionManager.isPlayerInWater())) {
|
|
|
|
// Either of those conditions means that Bedrock goes zoom when they shouldn't be
|
2021-07-08 02:44:53 +00:00
|
|
|
AttributeData speedAttribute = GeyserAttributeType.MOVEMENT_SPEED.getAttribute(originalSpeedAttribute / 3.32f);
|
|
|
|
playerEntity.getAttributes().put(GeyserAttributeType.MOVEMENT_SPEED, speedAttribute);
|
|
|
|
return speedAttribute;
|
2021-04-12 04:35:53 +00:00
|
|
|
} else if (originalSpeedAttribute != currentPlayerSpeed.getValue()) {
|
|
|
|
// Speed has reset to normal
|
2021-07-08 02:44:53 +00:00
|
|
|
AttributeData speedAttribute = GeyserAttributeType.MOVEMENT_SPEED.getAttribute(originalSpeedAttribute);
|
|
|
|
playerEntity.getAttributes().put(GeyserAttributeType.MOVEMENT_SPEED, speedAttribute);
|
|
|
|
return speedAttribute;
|
2021-04-12 04:35:53 +00:00
|
|
|
}
|
|
|
|
}
|
2021-07-08 02:44:53 +00:00
|
|
|
return null;
|
2021-04-12 04:35:53 +00:00
|
|
|
}
|
|
|
|
|
2021-03-17 15:15:57 +00:00
|
|
|
/**
|
|
|
|
* Will be overwritten for GeyserConnect.
|
|
|
|
*/
|
|
|
|
protected void disableSrvResolving() {
|
2021-05-23 19:55:01 +00:00
|
|
|
this.downstream.setFlag(BuiltinFlags.ATTEMPT_SRV_RESOLVE, false);
|
2021-03-17 15:15:57 +00:00
|
|
|
}
|
|
|
|
|
2019-07-22 00:52:20 +00:00
|
|
|
@Override
|
|
|
|
public String getName() {
|
2019-12-21 17:35:48 +00:00
|
|
|
return authData.getName();
|
2019-07-22 00:52:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void sendMessage(String message) {
|
|
|
|
TextPacket textPacket = new TextPacket();
|
|
|
|
textPacket.setPlatformChatId("");
|
|
|
|
textPacket.setSourceName("");
|
|
|
|
textPacket.setXuid("");
|
|
|
|
textPacket.setType(TextPacket.Type.CHAT);
|
|
|
|
textPacket.setNeedsTranslation(false);
|
|
|
|
textPacket.setMessage(message);
|
|
|
|
|
|
|
|
upstream.sendPacket(textPacket);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-03-05 02:44:42 +00:00
|
|
|
public boolean isConsole() {
|
|
|
|
return false;
|
2019-07-22 00:52:20 +00:00
|
|
|
}
|
|
|
|
|
2021-07-08 02:44:53 +00:00
|
|
|
@Override
|
|
|
|
public String getLocale() {
|
2020-10-29 22:30:52 +00:00
|
|
|
return clientData.getLanguageCode();
|
|
|
|
}
|
|
|
|
|
2020-02-06 04:32:33 +00:00
|
|
|
public void setRenderDistance(int renderDistance) {
|
2020-06-09 12:50:21 +00:00
|
|
|
renderDistance = GenericMath.ceil(++renderDistance * MathUtils.SQRT_OF_TWO); //square to circle
|
2020-02-06 04:32:33 +00:00
|
|
|
this.renderDistance = renderDistance;
|
|
|
|
|
|
|
|
ChunkRadiusUpdatedPacket chunkRadiusUpdatedPacket = new ChunkRadiusUpdatedPacket();
|
|
|
|
chunkRadiusUpdatedPacket.setRadius(renderDistance);
|
|
|
|
upstream.sendPacket(chunkRadiusUpdatedPacket);
|
|
|
|
}
|
|
|
|
|
2019-09-13 13:37:31 +00:00
|
|
|
public InetSocketAddress getSocketAddress() {
|
|
|
|
return this.upstream.getAddress();
|
|
|
|
}
|
|
|
|
|
2020-12-10 21:57:48 +00:00
|
|
|
public void sendForm(Form form) {
|
2020-10-29 23:58:17 +00:00
|
|
|
formCache.showForm(form);
|
|
|
|
}
|
|
|
|
|
2020-11-26 22:00:43 +00:00
|
|
|
public void sendForm(FormBuilder<?, ?> formBuilder) {
|
2020-10-29 23:58:17 +00:00
|
|
|
formCache.showForm(formBuilder.build());
|
2019-07-10 06:34:10 +00:00
|
|
|
}
|
2019-07-24 06:29:54 +00:00
|
|
|
|
|
|
|
private void startGame() {
|
|
|
|
StartGamePacket startGamePacket = new StartGamePacket();
|
2019-08-06 02:09:45 +00:00
|
|
|
startGamePacket.setUniqueEntityId(playerEntity.getGeyserId());
|
|
|
|
startGamePacket.setRuntimeEntityId(playerEntity.getGeyserId());
|
2020-06-23 00:11:09 +00:00
|
|
|
startGamePacket.setPlayerGameType(GameType.SURVIVAL);
|
2019-10-09 18:39:38 +00:00
|
|
|
startGamePacket.setPlayerPosition(Vector3f.from(0, 69, 0));
|
|
|
|
startGamePacket.setRotation(Vector2f.from(1, 1));
|
2019-07-24 06:29:54 +00:00
|
|
|
|
2019-11-10 22:53:01 +00:00
|
|
|
startGamePacket.setSeed(-1);
|
2020-11-12 00:28:45 +00:00
|
|
|
startGamePacket.setDimensionId(DimensionUtils.javaToBedrock(dimension));
|
2019-08-06 02:09:45 +00:00
|
|
|
startGamePacket.setGeneratorId(1);
|
2020-06-23 00:11:09 +00:00
|
|
|
startGamePacket.setLevelGameType(GameType.SURVIVAL);
|
2019-07-24 06:29:54 +00:00
|
|
|
startGamePacket.setDifficulty(1);
|
2019-10-09 18:39:38 +00:00
|
|
|
startGamePacket.setDefaultSpawn(Vector3i.ZERO);
|
2020-11-07 00:52:09 +00:00
|
|
|
startGamePacket.setAchievementsDisabled(!connector.getConfig().isXboxAchievementsEnabled());
|
2020-06-23 00:11:09 +00:00
|
|
|
startGamePacket.setCurrentTick(-1);
|
2019-11-10 22:53:01 +00:00
|
|
|
startGamePacket.setEduEditionOffers(0);
|
2019-07-24 06:29:54 +00:00
|
|
|
startGamePacket.setEduFeaturesEnabled(false);
|
|
|
|
startGamePacket.setRainLevel(0);
|
|
|
|
startGamePacket.setLightningLevel(0);
|
|
|
|
startGamePacket.setMultiplayerGame(true);
|
|
|
|
startGamePacket.setBroadcastingToLan(true);
|
|
|
|
startGamePacket.setPlatformBroadcastMode(GamePublishSetting.PUBLIC);
|
|
|
|
startGamePacket.setXblBroadcastMode(GamePublishSetting.PUBLIC);
|
2020-11-07 00:52:09 +00:00
|
|
|
startGamePacket.setCommandsEnabled(!connector.getConfig().isXboxAchievementsEnabled());
|
2019-07-24 06:29:54 +00:00
|
|
|
startGamePacket.setTexturePacksRequired(false);
|
|
|
|
startGamePacket.setBonusChestEnabled(false);
|
|
|
|
startGamePacket.setStartingWithMap(false);
|
|
|
|
startGamePacket.setTrustingPlayers(true);
|
2020-03-21 22:59:16 +00:00
|
|
|
startGamePacket.setDefaultPlayerPermission(PlayerPermission.MEMBER);
|
2019-07-24 06:29:54 +00:00
|
|
|
startGamePacket.setServerChunkTickRange(4);
|
|
|
|
startGamePacket.setBehaviorPackLocked(false);
|
|
|
|
startGamePacket.setResourcePackLocked(false);
|
|
|
|
startGamePacket.setFromLockedWorldTemplate(false);
|
|
|
|
startGamePacket.setUsingMsaGamertagsOnly(false);
|
|
|
|
startGamePacket.setFromWorldTemplate(false);
|
|
|
|
startGamePacket.setWorldTemplateOptionLocked(false);
|
|
|
|
|
2020-08-25 13:29:55 +00:00
|
|
|
String serverName = connector.getConfig().getBedrock().getServerName();
|
|
|
|
startGamePacket.setLevelId(serverName);
|
|
|
|
startGamePacket.setLevelName(serverName);
|
|
|
|
|
2019-07-24 06:29:54 +00:00
|
|
|
startGamePacket.setPremiumWorldTemplateId("00000000-0000-0000-0000-000000000000");
|
2019-11-10 22:53:01 +00:00
|
|
|
// startGamePacket.setCurrentTick(0);
|
2019-07-24 06:29:54 +00:00
|
|
|
startGamePacket.setEnchantmentSeed(0);
|
|
|
|
startGamePacket.setMultiplayerCorrelationId("");
|
2021-07-13 01:19:40 +00:00
|
|
|
startGamePacket.setItemEntries(this.itemMappings.getItemEntries());
|
2019-12-21 05:05:20 +00:00
|
|
|
startGamePacket.setVanillaVersion("*");
|
2020-10-16 23:25:05 +00:00
|
|
|
startGamePacket.setInventoriesServerAuthoritative(true);
|
2021-06-02 01:12:58 +00:00
|
|
|
startGamePacket.setServerEngine(""); // Do we want to fill this in?
|
2021-02-17 23:00:53 +00:00
|
|
|
|
|
|
|
SyncedPlayerMovementSettings settings = new SyncedPlayerMovementSettings();
|
|
|
|
settings.setMovementMode(AuthoritativeMovementMode.CLIENT);
|
|
|
|
settings.setRewindHistorySize(0);
|
|
|
|
settings.setServerAuthoritativeBlockBreaking(false);
|
|
|
|
startGamePacket.setPlayerMovementSettings(settings);
|
|
|
|
|
2021-07-14 00:48:45 +00:00
|
|
|
if (connector.getConfig().isExtendedWorldHeight()) {
|
|
|
|
startGamePacket.getExperiments().add(new ExperimentData("caves_and_cliffs", true));
|
|
|
|
}
|
|
|
|
|
2019-07-24 06:29:54 +00:00
|
|
|
upstream.sendPacket(startGamePacket);
|
|
|
|
}
|
2020-04-29 16:06:25 +00:00
|
|
|
|
2020-12-26 21:41:50 +00:00
|
|
|
/**
|
|
|
|
* @return the next Bedrock item network ID to use for a new item
|
|
|
|
*/
|
|
|
|
public int getNextItemNetId() {
|
|
|
|
return itemNetId.getAndIncrement();
|
|
|
|
}
|
|
|
|
|
2020-11-20 19:56:39 +00:00
|
|
|
public void addTeleport(TeleportCache teleportCache) {
|
|
|
|
teleportMap.put(teleportCache.getTeleportConfirmId(), teleportCache);
|
|
|
|
|
|
|
|
ObjectIterator<Int2ObjectMap.Entry<TeleportCache>> it = teleportMap.int2ObjectEntrySet().iterator();
|
|
|
|
|
|
|
|
// Remove any teleports with a higher number - maybe this is a world change that reset the ID to 0?
|
|
|
|
while (it.hasNext()) {
|
|
|
|
Int2ObjectMap.Entry<TeleportCache> entry = it.next();
|
|
|
|
int nextID = entry.getValue().getTeleportConfirmId();
|
|
|
|
if (nextID > teleportCache.getTeleportConfirmId()) {
|
|
|
|
it.remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-18 14:58:08 +00:00
|
|
|
public void confirmTeleport(Vector3d position) {
|
2020-11-20 19:56:39 +00:00
|
|
|
if (teleportMap.size() == 0) {
|
2021-07-18 14:58:08 +00:00
|
|
|
return;
|
2020-11-20 19:56:39 +00:00
|
|
|
}
|
|
|
|
int teleportID = -1;
|
|
|
|
|
|
|
|
for (Int2ObjectMap.Entry<TeleportCache> entry : teleportMap.int2ObjectEntrySet()) {
|
|
|
|
if (entry.getValue().canConfirm(position)) {
|
|
|
|
if (entry.getValue().getTeleportConfirmId() > teleportID) {
|
|
|
|
teleportID = entry.getValue().getTeleportConfirmId();
|
|
|
|
}
|
2020-04-29 16:06:25 +00:00
|
|
|
}
|
|
|
|
}
|
2020-11-20 19:56:39 +00:00
|
|
|
|
|
|
|
if (teleportID != -1) {
|
2021-08-15 18:57:02 +00:00
|
|
|
ObjectIterator<Int2ObjectMap.Entry<TeleportCache>> it = teleportMap.int2ObjectEntrySet().iterator();
|
|
|
|
|
2020-11-20 19:56:39 +00:00
|
|
|
// Confirm the current teleport and any earlier ones
|
|
|
|
while (it.hasNext()) {
|
|
|
|
TeleportCache entry = it.next().getValue();
|
|
|
|
int nextID = entry.getTeleportConfirmId();
|
|
|
|
if (nextID <= teleportID) {
|
|
|
|
ClientTeleportConfirmPacket teleportConfirmPacket = new ClientTeleportConfirmPacket(nextID);
|
|
|
|
sendDownstreamPacket(teleportConfirmPacket);
|
|
|
|
// Servers (especially ones like Hypixel) expect exact coordinates given back to them.
|
|
|
|
ClientPlayerPositionRotationPacket positionPacket = new ClientPlayerPositionRotationPacket(playerEntity.isOnGround(),
|
|
|
|
entry.getX(), entry.getY(), entry.getZ(), entry.getYaw(), entry.getPitch());
|
|
|
|
sendDownstreamPacket(positionPacket);
|
|
|
|
it.remove();
|
|
|
|
connector.getLogger().debug("Confirmed teleport " + nextID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (teleportMap.size() > 0) {
|
|
|
|
int resendID = -1;
|
|
|
|
for (Int2ObjectMap.Entry<TeleportCache> entry : teleportMap.int2ObjectEntrySet()) {
|
|
|
|
TeleportCache teleport = entry.getValue();
|
|
|
|
teleport.incrementUnconfirmedFor();
|
|
|
|
if (teleport.shouldResend()) {
|
|
|
|
if (teleport.getTeleportConfirmId() >= resendID) {
|
|
|
|
resendID = teleport.getTeleportConfirmId();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (resendID != -1) {
|
|
|
|
connector.getLogger().debug("Resending teleport " + resendID);
|
|
|
|
TeleportCache teleport = teleportMap.get(resendID);
|
|
|
|
getPlayerEntity().moveAbsolute(this, Vector3f.from(teleport.getX(), teleport.getY(), teleport.getZ()),
|
|
|
|
teleport.getYaw(), teleport.getPitch(), playerEntity.isOnGround(), true);
|
|
|
|
}
|
|
|
|
}
|
2020-04-29 16:06:25 +00:00
|
|
|
}
|
2020-05-05 15:51:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Queue a packet to be sent to player.
|
|
|
|
*
|
|
|
|
* @param packet the bedrock packet from the NukkitX protocol lib
|
|
|
|
*/
|
|
|
|
public void sendUpstreamPacket(BedrockPacket packet) {
|
2021-07-14 00:48:45 +00:00
|
|
|
upstream.sendPacket(packet);
|
2020-05-05 15:51:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send a packet immediately to the player.
|
2020-11-20 19:56:39 +00:00
|
|
|
*
|
2020-05-05 15:51:43 +00:00
|
|
|
* @param packet the bedrock packet from the NukkitX protocol lib
|
|
|
|
*/
|
|
|
|
public void sendUpstreamPacketImmediately(BedrockPacket packet) {
|
2021-07-14 00:48:45 +00:00
|
|
|
upstream.sendPacketImmediately(packet);
|
2020-05-05 15:51:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send a packet to the remote server.
|
|
|
|
*
|
|
|
|
* @param packet the java edition packet from MCProtocolLib
|
|
|
|
*/
|
|
|
|
public void sendDownstreamPacket(Packet packet) {
|
2021-08-17 00:39:29 +00:00
|
|
|
if (!closed && this.downstream != null) {
|
2021-08-19 16:37:14 +00:00
|
|
|
Channel channel = this.downstream.getChannel();
|
|
|
|
if (channel == null) {
|
2021-08-31 23:57:56 +00:00
|
|
|
// Channel is only null before the connection has initialized
|
|
|
|
connector.getLogger().warning("Tried to send a packet to the Java server too early!");
|
|
|
|
if (connector.getConfig().isDebugMode()) {
|
|
|
|
Thread.dumpStack();
|
|
|
|
}
|
2021-08-19 16:37:14 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
EventLoop eventLoop = channel.eventLoop();
|
2021-08-17 00:39:29 +00:00
|
|
|
if (eventLoop.inEventLoop()) {
|
|
|
|
sendDownstreamPacket0(packet);
|
|
|
|
} else {
|
|
|
|
eventLoop.execute(() -> sendDownstreamPacket0(packet));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void sendDownstreamPacket0(Packet packet) {
|
|
|
|
if (protocol.getSubProtocol().equals(SubProtocol.GAME) || packet.getClass() == LoginPluginResponsePacket.class) {
|
2021-05-23 19:55:01 +00:00
|
|
|
downstream.send(packet);
|
2020-05-05 15:51:43 +00:00
|
|
|
} else {
|
|
|
|
connector.getLogger().debug("Tried to send downstream packet " + packet.getClass().getSimpleName() + " before connected to the server");
|
|
|
|
}
|
|
|
|
}
|
2020-08-08 22:41:12 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the cached value for the reduced debug info gamerule.
|
2021-04-21 20:57:01 +00:00
|
|
|
* If enabled, also hides the player's coordinates.
|
2020-08-08 22:41:12 +00:00
|
|
|
*
|
|
|
|
* @param value The new value for reducedDebugInfo
|
|
|
|
*/
|
|
|
|
public void setReducedDebugInfo(boolean value) {
|
|
|
|
reducedDebugInfo = value;
|
2021-04-21 20:57:01 +00:00
|
|
|
// Set the showCoordinates data. This is done because updateShowCoordinates() uses this gamerule as a variable.
|
2021-05-15 02:48:34 +00:00
|
|
|
preferencesCache.updateShowCoordinates();
|
2020-08-08 22:41:12 +00:00
|
|
|
}
|
|
|
|
|
2021-01-11 20:52:02 +00:00
|
|
|
/**
|
|
|
|
* Changes the daylight cycle gamerule on the client
|
|
|
|
* This is used in the login screen along-side normal usage
|
|
|
|
*
|
|
|
|
* @param doCycle If the cycle should continue
|
|
|
|
*/
|
|
|
|
public void setDaylightCycle(boolean doCycle) {
|
|
|
|
sendGameRule("dodaylightcycle", doCycle);
|
|
|
|
// Save the value so we don't have to constantly send a daylight cycle gamerule update
|
|
|
|
this.daylightCycle = doCycle;
|
|
|
|
}
|
|
|
|
|
2020-08-08 22:41:12 +00:00
|
|
|
/**
|
|
|
|
* Send a gamerule value to the client
|
|
|
|
*
|
|
|
|
* @param gameRule The gamerule to send
|
2020-10-29 23:58:17 +00:00
|
|
|
* @param value The value of the gamerule
|
2020-08-08 22:41:12 +00:00
|
|
|
*/
|
|
|
|
public void sendGameRule(String gameRule, Object value) {
|
|
|
|
GameRulesChangedPacket gameRulesChangedPacket = new GameRulesChangedPacket();
|
|
|
|
gameRulesChangedPacket.getGameRules().add(new GameRuleData<>(gameRule, value));
|
|
|
|
upstream.sendPacket(gameRulesChangedPacket);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-08-08 22:56:15 +00:00
|
|
|
* Checks if the given session's player has a permission
|
|
|
|
*
|
|
|
|
* @param permission The permission node to check
|
|
|
|
* @return true if the player has the requested permission, false if not
|
2020-08-08 22:41:12 +00:00
|
|
|
*/
|
|
|
|
public Boolean hasPermission(String permission) {
|
|
|
|
return connector.getWorldManager().hasPermission(this, permission);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send an AdventureSettingsPacket to the client with the latest flags
|
|
|
|
*/
|
|
|
|
public void sendAdventureSettings() {
|
|
|
|
AdventureSettingsPacket adventureSettingsPacket = new AdventureSettingsPacket();
|
|
|
|
adventureSettingsPacket.setUniqueEntityId(playerEntity.getGeyserId());
|
2020-09-05 20:22:31 +00:00
|
|
|
// Set command permission if OP permission level is high enough
|
|
|
|
// This allows mobile players access to a GUI for doing commands. The commands there do not change above OPERATOR
|
|
|
|
// and all commands there are accessible with OP permission level 2
|
|
|
|
adventureSettingsPacket.setCommandPermission(opPermissionLevel >= 2 ? CommandPermission.OPERATOR : CommandPermission.NORMAL);
|
2020-09-15 00:54:19 +00:00
|
|
|
// Required to make command blocks destroyable
|
|
|
|
adventureSettingsPacket.setPlayerPermission(opPermissionLevel >= 2 ? PlayerPermission.OPERATOR : PlayerPermission.MEMBER);
|
2020-08-08 22:41:12 +00:00
|
|
|
|
2020-09-28 21:43:50 +00:00
|
|
|
// Update the noClip and worldImmutable values based on the current gamemode
|
2021-07-28 17:21:18 +00:00
|
|
|
boolean spectator = gameMode == GameMode.SPECTATOR;
|
|
|
|
boolean worldImmutable = gameMode == GameMode.ADVENTURE || spectator;
|
2020-09-28 21:43:50 +00:00
|
|
|
|
2021-03-31 18:15:55 +00:00
|
|
|
Set<AdventureSetting> flags = adventureSettingsPacket.getSettings();
|
2021-07-28 17:21:18 +00:00
|
|
|
if (canFly || spectator) {
|
2020-08-08 22:41:12 +00:00
|
|
|
flags.add(AdventureSetting.MAY_FLY);
|
|
|
|
}
|
|
|
|
|
2021-07-28 17:21:18 +00:00
|
|
|
if (flying || spectator) {
|
|
|
|
if (spectator && !flying) {
|
|
|
|
// We're "flying locked" in this gamemode
|
|
|
|
flying = true;
|
|
|
|
ClientPlayerAbilitiesPacket abilitiesPacket = new ClientPlayerAbilitiesPacket(true);
|
|
|
|
sendDownstreamPacket(abilitiesPacket);
|
|
|
|
}
|
2020-08-08 22:41:12 +00:00
|
|
|
flags.add(AdventureSetting.FLYING);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (worldImmutable) {
|
|
|
|
flags.add(AdventureSetting.WORLD_IMMUTABLE);
|
|
|
|
}
|
|
|
|
|
2021-07-28 17:21:18 +00:00
|
|
|
if (spectator) {
|
2020-08-08 22:41:12 +00:00
|
|
|
flags.add(AdventureSetting.NO_CLIP);
|
|
|
|
}
|
|
|
|
|
|
|
|
flags.add(AdventureSetting.AUTO_JUMP);
|
|
|
|
|
|
|
|
sendUpstreamPacket(adventureSettingsPacket);
|
|
|
|
}
|
2020-10-23 06:25:24 +00:00
|
|
|
|
2020-10-24 22:33:49 +00:00
|
|
|
/**
|
|
|
|
* Used for updating statistic values since we only get changes from the server
|
|
|
|
*
|
|
|
|
* @param statistics Updated statistics values
|
|
|
|
*/
|
|
|
|
public void updateStatistics(@NonNull Map<Statistic, Integer> statistics) {
|
|
|
|
this.statistics.putAll(statistics);
|
|
|
|
}
|
|
|
|
|
2020-10-23 06:25:24 +00:00
|
|
|
public void refreshEmotes(List<UUID> emotes) {
|
|
|
|
this.emotes.addAll(emotes);
|
|
|
|
for (GeyserSession player : connector.getPlayers()) {
|
|
|
|
List<UUID> pieces = new ArrayList<>();
|
|
|
|
for (UUID piece : emotes) {
|
|
|
|
if (!player.getEmotes().contains(piece)) {
|
2020-10-23 06:36:34 +00:00
|
|
|
pieces.add(piece);
|
2020-10-23 06:25:24 +00:00
|
|
|
}
|
2020-10-23 06:36:34 +00:00
|
|
|
player.getEmotes().add(piece);
|
2020-10-23 06:25:24 +00:00
|
|
|
}
|
|
|
|
EmoteListPacket emoteList = new EmoteListPacket();
|
|
|
|
emoteList.setRuntimeEntityId(player.getPlayerEntity().getGeyserId());
|
|
|
|
emoteList.getPieceIds().addAll(pieces);
|
|
|
|
player.sendUpstreamPacket(emoteList);
|
|
|
|
}
|
|
|
|
}
|
2019-08-24 03:49:48 +00:00
|
|
|
}
|