2019-07-24 20:12:42 +00:00
|
|
|
/*
|
2022-01-01 19:03:05 +00:00
|
|
|
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
|
2019-07-24 20:12:42 +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:
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2021-11-20 23:29:46 +00:00
|
|
|
package org.geysermc.geyser.translator.protocol.java;
|
2019-07-24 20:12:42 +00:00
|
|
|
|
2021-11-13 03:44:15 +00:00
|
|
|
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundLoginPacket;
|
|
|
|
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundCustomPayloadPacket;
|
2020-07-30 20:31:12 +00:00
|
|
|
import com.nukkitx.protocol.bedrock.data.GameRuleData;
|
2020-03-24 04:24:17 +00:00
|
|
|
import com.nukkitx.protocol.bedrock.data.PlayerPermission;
|
2022-01-16 01:29:00 +00:00
|
|
|
import com.nukkitx.protocol.bedrock.packet.AdventureSettingsPacket;
|
|
|
|
import com.nukkitx.protocol.bedrock.packet.GameRulesChangedPacket;
|
|
|
|
import com.nukkitx.protocol.bedrock.packet.SetPlayerGameTypePacket;
|
2022-03-20 00:56:34 +00:00
|
|
|
import org.geysermc.floodgate.pluginmessage.PluginMessageChannels;
|
2021-11-20 23:29:46 +00:00
|
|
|
import org.geysermc.geyser.entity.type.player.PlayerEntity;
|
2022-05-24 23:16:40 +00:00
|
|
|
import org.geysermc.geyser.level.JavaDimension;
|
2021-11-22 19:52:26 +00:00
|
|
|
import org.geysermc.geyser.session.GeyserSession;
|
2022-01-16 01:29:00 +00:00
|
|
|
import org.geysermc.geyser.session.auth.AuthType;
|
|
|
|
import org.geysermc.geyser.translator.level.BiomeTranslator;
|
2021-11-20 23:29:46 +00:00
|
|
|
import org.geysermc.geyser.translator.protocol.PacketTranslator;
|
|
|
|
import org.geysermc.geyser.translator.protocol.Translator;
|
|
|
|
import org.geysermc.geyser.util.PluginMessageUtils;
|
2020-03-24 04:24:17 +00:00
|
|
|
|
2022-05-24 23:16:40 +00:00
|
|
|
import java.util.Map;
|
|
|
|
|
2021-11-13 03:44:15 +00:00
|
|
|
@Translator(packet = ClientboundLoginPacket.class)
|
2021-11-13 04:01:45 +00:00
|
|
|
public class JavaLoginTranslator extends PacketTranslator<ClientboundLoginPacket> {
|
2019-07-24 20:12:42 +00:00
|
|
|
|
|
|
|
@Override
|
2021-11-22 19:52:26 +00:00
|
|
|
public void translate(GeyserSession session, ClientboundLoginPacket packet) {
|
2019-12-27 11:29:46 +00:00
|
|
|
PlayerEntity entity = session.getPlayerEntity();
|
|
|
|
entity.setEntityId(packet.getEntityId());
|
2021-06-08 03:09:42 +00:00
|
|
|
|
2022-05-24 23:16:40 +00:00
|
|
|
Map<String, JavaDimension> dimensions = session.getDimensions();
|
|
|
|
dimensions.clear();
|
|
|
|
|
2020-07-05 23:33:05 +00:00
|
|
|
// If the player is already initialized and a join game packet is sent, they
|
|
|
|
// are swapping servers
|
2022-05-24 23:16:40 +00:00
|
|
|
//String newDimension = DimensionUtils.getNewDimension(packet.getDimension());
|
2020-07-05 23:33:05 +00:00
|
|
|
if (session.isSpawned()) {
|
2022-05-24 23:16:40 +00:00
|
|
|
//String fakeDim = DimensionUtils.getTemporaryDimension(session.getDimension(), newDimension);
|
|
|
|
//DimensionUtils.switchDimension(session, fakeDim);
|
2020-07-06 13:10:36 +00:00
|
|
|
|
2020-08-08 22:41:12 +00:00
|
|
|
session.getWorldCache().removeScoreboard();
|
2020-07-05 23:33:05 +00:00
|
|
|
}
|
2021-01-04 00:06:20 +00:00
|
|
|
session.setWorldName(packet.getWorldName());
|
2019-12-27 11:29:46 +00:00
|
|
|
|
2021-07-28 00:29:27 +00:00
|
|
|
BiomeTranslator.loadServerBiomes(session, packet.getDimensionCodec());
|
2021-05-03 01:47:11 +00:00
|
|
|
session.getTagCache().clear();
|
|
|
|
|
2021-11-13 16:03:55 +00:00
|
|
|
session.setGameMode(packet.getGameMode());
|
|
|
|
|
|
|
|
boolean needsSpawnPacket = !session.isSentSpawnPacket();
|
|
|
|
if (needsSpawnPacket) {
|
|
|
|
// The player has yet to spawn so let's do that using some of the information in this Java packet
|
2022-05-24 23:16:40 +00:00
|
|
|
//session.setDimension(newDimension);
|
2021-11-13 16:03:55 +00:00
|
|
|
session.connect();
|
|
|
|
}
|
|
|
|
|
2019-07-24 20:12:42 +00:00
|
|
|
AdventureSettingsPacket bedrockPacket = new AdventureSettingsPacket();
|
2019-08-03 06:51:05 +00:00
|
|
|
bedrockPacket.setUniqueEntityId(session.getPlayerEntity().getGeyserId());
|
2020-03-27 04:00:52 +00:00
|
|
|
bedrockPacket.setPlayerPermission(PlayerPermission.MEMBER);
|
2020-05-05 15:51:43 +00:00
|
|
|
session.sendUpstreamPacket(bedrockPacket);
|
2019-07-24 20:12:42 +00:00
|
|
|
|
2021-11-13 16:03:55 +00:00
|
|
|
if (!needsSpawnPacket) {
|
|
|
|
SetPlayerGameTypePacket playerGameTypePacket = new SetPlayerGameTypePacket();
|
|
|
|
playerGameTypePacket.setGamemode(packet.getGameMode().ordinal());
|
|
|
|
session.sendUpstreamPacket(playerGameTypePacket);
|
|
|
|
}
|
2019-09-16 01:25:16 +00:00
|
|
|
|
2021-11-19 01:44:03 +00:00
|
|
|
entity.updateBedrockMetadata();
|
2019-09-16 01:25:16 +00:00
|
|
|
|
2020-07-30 20:31:12 +00:00
|
|
|
// Send if client should show respawn screen
|
|
|
|
GameRulesChangedPacket gamerulePacket = new GameRulesChangedPacket();
|
|
|
|
gamerulePacket.getGameRules().add(new GameRuleData<>("doimmediaterespawn", !packet.isEnableRespawnScreen()));
|
|
|
|
session.sendUpstreamPacket(gamerulePacket);
|
|
|
|
|
2021-04-21 20:57:01 +00:00
|
|
|
session.setReducedDebugInfo(packet.isReducedDebugInfo());
|
|
|
|
|
2022-01-16 01:29:00 +00:00
|
|
|
session.setServerRenderDistance(packet.getViewDistance());
|
2019-12-28 13:35:21 +00:00
|
|
|
|
2021-11-14 04:49:31 +00:00
|
|
|
// TODO customize
|
2022-01-16 01:29:00 +00:00
|
|
|
session.sendJavaClientSettings();
|
2020-05-05 02:32:37 +00:00
|
|
|
|
2021-11-13 03:44:15 +00:00
|
|
|
session.sendDownstreamPacket(new ServerboundCustomPayloadPacket("minecraft:brand", PluginMessageUtils.getGeyserBrandData()));
|
2020-09-21 20:06:25 +00:00
|
|
|
|
2020-11-18 18:38:49 +00:00
|
|
|
// register the plugin messaging channels used in Floodgate
|
2021-07-28 23:44:09 +00:00
|
|
|
if (session.getRemoteAuthType() == AuthType.FLOODGATE) {
|
2022-03-20 00:56:34 +00:00
|
|
|
session.sendDownstreamPacket(new ServerboundCustomPayloadPacket("minecraft:register", PluginMessageChannels.getFloodgateRegisterData()));
|
2020-11-18 18:38:49 +00:00
|
|
|
}
|
|
|
|
|
2022-05-24 23:16:40 +00:00
|
|
|
// if (!newDimension.equals(session.getDimension())) {
|
|
|
|
// DimensionUtils.switchDimension(session, newDimension);
|
|
|
|
// } else if (DimensionUtils.isCustomBedrockNetherId() && newDimension.equalsIgnoreCase(DimensionUtils.NETHER)) {
|
|
|
|
// // If the player is spawning into the "fake" nether, send them some fog
|
|
|
|
// session.sendFog("minecraft:fog_hell");
|
|
|
|
// }
|
2021-07-15 01:46:56 +00:00
|
|
|
|
2022-05-24 23:16:40 +00:00
|
|
|
//ChunkUtils.loadDimensionTag(session, packet.getDimension());
|
2019-07-24 20:12:42 +00:00
|
|
|
}
|
|
|
|
}
|