From 223e94a31d46d0f8a3f2c118d95dd9c1009f36e5 Mon Sep 17 00:00:00 2001 From: AJ Ferguson Date: Thu, 5 Mar 2020 10:45:50 -0900 Subject: [PATCH 01/79] Revert non-full chunk fix This fix causes far too much lag on big non-full chunk updates --- .../java/world/JavaChunkDataTranslator.java | 84 +++++++------------ 1 file changed, 29 insertions(+), 55 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaChunkDataTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaChunkDataTranslator.java index f570bb0b0..b531b6f37 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaChunkDataTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaChunkDataTranslator.java @@ -25,10 +25,7 @@ package org.geysermc.connector.network.translators.java.world; -import com.github.steveice10.mc.protocol.data.game.chunk.Chunk; -import com.github.steveice10.mc.protocol.data.game.world.block.BlockState; import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerChunkDataPacket; -import com.nukkitx.math.vector.Vector3i; import com.nukkitx.network.VarInts; import com.nukkitx.protocol.bedrock.packet.LevelChunkPacket; @@ -49,60 +46,37 @@ public class JavaChunkDataTranslator extends PacketTranslator { try { - if (packet.getColumn().getBiomeData() != null) { //Full chunk - ChunkUtils.ChunkData chunkData = ChunkUtils.translateToBedrock(packet.getColumn()); - ByteBuf byteBuf = Unpooled.buffer(32); - ChunkSection[] sections = chunkData.sections; + ChunkUtils.ChunkData chunkData = ChunkUtils.translateToBedrock(packet.getColumn()); + ByteBuf byteBuf = Unpooled.buffer(32); + ChunkSection[] sections = chunkData.sections; - int sectionCount = sections.length - 1; - while (sectionCount >= 0 && sections[sectionCount].isEmpty()) { - sectionCount--; - } - sectionCount++; - - for (int i = 0; i < sectionCount; i++) { - ChunkSection section = chunkData.sections[i]; - section.writeToNetwork(byteBuf); - } - - byte[] bedrockBiome = BiomeTranslator.toBedrockBiome(packet.getColumn().getBiomeData()); - - byteBuf.writeBytes(bedrockBiome); // Biomes - 256 bytes - byteBuf.writeByte(0); // Border blocks - Edu edition only - VarInts.writeUnsignedInt(byteBuf, 0); // extra data length, 0 for now - - byte[] payload = new byte[byteBuf.writerIndex()]; - byteBuf.readBytes(payload); - - LevelChunkPacket levelChunkPacket = new LevelChunkPacket(); - levelChunkPacket.setSubChunksLength(sectionCount); - levelChunkPacket.setCachingEnabled(false); - levelChunkPacket.setChunkX(packet.getColumn().getX()); - levelChunkPacket.setChunkZ(packet.getColumn().getZ()); - levelChunkPacket.setData(payload); - session.getUpstream().sendPacket(levelChunkPacket); - } else { - final int xOffset = packet.getColumn().getX() << 4; - final int zOffset = packet.getColumn().getZ() << 4; - Chunk[] chunks = packet.getColumn().getChunks(); - for (int i = 0; i < chunks.length; i++) { - Chunk chunk = chunks[i]; - if (chunk == null) continue; - final int yOffset = i * 16; - for (int x = 0; x < 16; x++) { - for (int y = 0; y < 16; y++) { - for (int z = 0; z < 16; z++) { - BlockState blockState = chunk.get(x, y, z); - Vector3i pos = Vector3i.from( - x + xOffset, - y + yOffset, - z + zOffset); - ChunkUtils.updateBlock(session, blockState, pos); - } - } - } - } + int sectionCount = sections.length - 1; + while (sectionCount >= 0 && sections[sectionCount].isEmpty()) { + sectionCount--; } + sectionCount++; + + for (int i = 0; i < sectionCount; i++) { + ChunkSection section = chunkData.sections[i]; + section.writeToNetwork(byteBuf); + } + + byte[] bedrockBiome = BiomeTranslator.toBedrockBiome(packet.getColumn().getBiomeData()); + + byteBuf.writeBytes(bedrockBiome); // Biomes - 256 bytes + byteBuf.writeByte(0); // Border blocks - Edu edition only + VarInts.writeUnsignedInt(byteBuf, 0); // extra data length, 0 for now + + byte[] payload = new byte[byteBuf.writerIndex()]; + byteBuf.readBytes(payload); + + LevelChunkPacket levelChunkPacket = new LevelChunkPacket(); + levelChunkPacket.setSubChunksLength(sectionCount); + levelChunkPacket.setCachingEnabled(false); + levelChunkPacket.setChunkX(packet.getColumn().getX()); + levelChunkPacket.setChunkZ(packet.getColumn().getZ()); + levelChunkPacket.setData(payload); + session.getUpstream().sendPacket(levelChunkPacket); } catch (Exception ex) { ex.printStackTrace(); } From eaf45ff6f72b20947519d5014798c32da9baed06 Mon Sep 17 00:00:00 2001 From: AJ Ferguson Date: Thu, 5 Mar 2020 16:26:36 -0900 Subject: [PATCH 02/79] Fix chunk view position bugs on some servers --- .../connector/network/session/GeyserSession.java | 3 +++ .../JavaPlayerPositionRotationTranslator.java | 3 +++ .../java/world/JavaChunkDataTranslator.java | 4 ++++ .../world/JavaUpdateViewPositionTranslator.java | 9 ++++----- .../org/geysermc/connector/utils/ChunkUtils.java | 16 ++++++++++++++++ .../geysermc/connector/utils/DimensionUtils.java | 1 + 6 files changed, 31 insertions(+), 5 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java index a2d8a7263..d4e86079e 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java @@ -38,6 +38,7 @@ import com.github.steveice10.packetlib.tcp.TcpSessionFactory; import com.nukkitx.math.GenericMath; import com.nukkitx.math.TrigMath; import com.nukkitx.math.vector.Vector2f; +import com.nukkitx.math.vector.Vector2i; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3i; import com.nukkitx.nbt.tag.CompoundTag; @@ -96,6 +97,8 @@ public class GeyserSession implements CommandSender { private DataCache javaPacketCache; + @Setter + private Vector2i lastChunkPosition = null; private int renderDistance; private boolean loggedIn; diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerPositionRotationTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerPositionRotationTranslator.java index 0c6b9258a..dccd6f54a 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerPositionRotationTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerPositionRotationTranslator.java @@ -38,6 +38,7 @@ import org.geysermc.connector.entity.Entity; import org.geysermc.connector.entity.type.EntityType; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.utils.ChunkUtils; public class JavaPlayerPositionRotationTranslator extends PacketTranslator { @@ -84,6 +85,8 @@ public class JavaPlayerPositionRotationTranslator extends PacketTranslator { try { diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUpdateViewPositionTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUpdateViewPositionTranslator.java index ebe9062fa..ef0df721e 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUpdateViewPositionTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUpdateViewPositionTranslator.java @@ -27,17 +27,16 @@ package org.geysermc.connector.network.translators.java.world; import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerUpdateViewPositionPacket; import com.nukkitx.math.vector.Vector3i; -import com.nukkitx.protocol.bedrock.packet.NetworkChunkPublisherUpdatePacket; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.utils.ChunkUtils; public class JavaUpdateViewPositionTranslator extends PacketTranslator { @Override public void translate(ServerUpdateViewPositionPacket packet, GeyserSession session) { - NetworkChunkPublisherUpdatePacket chunkPublisherUpdatePacket = new NetworkChunkPublisherUpdatePacket(); - chunkPublisherUpdatePacket.setPosition(Vector3i.from(packet.getChunkX() << 4, 0, packet.getChunkZ() << 4)); - chunkPublisherUpdatePacket.setRadius(session.getRenderDistance() << 4); - session.getUpstream().sendPacket(chunkPublisherUpdatePacket); + if (!session.isSpawned() && session.getLastChunkPosition() == null) { + ChunkUtils.updateChunkPosition(session, Vector3i.from(packet.getChunkX() << 4, 64, packet.getChunkZ() << 4)); + } } } diff --git a/connector/src/main/java/org/geysermc/connector/utils/ChunkUtils.java b/connector/src/main/java/org/geysermc/connector/utils/ChunkUtils.java index 1a6296c02..743e934b2 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/ChunkUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/ChunkUtils.java @@ -29,8 +29,10 @@ import com.github.steveice10.mc.protocol.data.game.chunk.Chunk; import com.github.steveice10.mc.protocol.data.game.chunk.Column; import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position; import com.github.steveice10.mc.protocol.data.game.world.block.BlockState; +import com.nukkitx.math.vector.Vector2i; import com.nukkitx.math.vector.Vector3i; import com.nukkitx.protocol.bedrock.packet.LevelChunkPacket; +import com.nukkitx.protocol.bedrock.packet.NetworkChunkPublisherUpdatePacket; import com.nukkitx.protocol.bedrock.packet.UpdateBlockPacket; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.TranslatorsInit; @@ -74,6 +76,20 @@ public class ChunkUtils { return chunkData; } + public static void updateChunkPosition(GeyserSession session, Vector3i position) { + Vector2i chunkPos = session.getLastChunkPosition(); + Vector2i newChunkPos = Vector2i.from(position.getX() >> 4, position.getZ() >> 4); + + if (chunkPos == null || !chunkPos.equals(newChunkPos)) { + NetworkChunkPublisherUpdatePacket chunkPublisherUpdatePacket = new NetworkChunkPublisherUpdatePacket(); + chunkPublisherUpdatePacket.setPosition(position); + chunkPublisherUpdatePacket.setRadius(session.getRenderDistance() << 4); + session.getUpstream().sendPacket(chunkPublisherUpdatePacket); + + session.setLastChunkPosition(newChunkPos); + } + } + public static void updateBlock(GeyserSession session, BlockState blockState, Position position) { Vector3i pos = Vector3i.from(position.getX(), position.getY(), position.getZ()); updateBlock(session, blockState, pos); diff --git a/connector/src/main/java/org/geysermc/connector/utils/DimensionUtils.java b/connector/src/main/java/org/geysermc/connector/utils/DimensionUtils.java index c7ecaafb4..199c5a5c6 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/DimensionUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/DimensionUtils.java @@ -52,6 +52,7 @@ public class DimensionUtils { player.setDimension(bedrockDimension); player.setPosition(pos.toFloat()); session.setSpawned(false); + session.setLastChunkPosition(null); //let java server handle portal travel sound StopSoundPacket stopSoundPacket = new StopSoundPacket(); From f71c70224b813ad717fb9c8bc71e93f12cad6a39 Mon Sep 17 00:00:00 2001 From: AJ Ferguson Date: Thu, 5 Mar 2020 17:55:22 -0900 Subject: [PATCH 03/79] Only translate full chunks --- .../translators/java/world/JavaChunkDataTranslator.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaChunkDataTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaChunkDataTranslator.java index 7f8de40af..936f422df 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaChunkDataTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaChunkDataTranslator.java @@ -47,6 +47,9 @@ public class JavaChunkDataTranslator extends PacketTranslator { try { From 5222232e720cc590ad20640949e94d0355b52ba1 Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Thu, 26 Mar 2020 23:00:52 -0500 Subject: [PATCH 04/79] Add rest of fixes for operator bug --- .../org/geysermc/connector/network/session/GeyserSession.java | 2 +- .../network/translators/java/JavaJoinGameTranslator.java | 2 +- .../java/entity/player/JavaPlayerAbilitiesTranslator.java | 2 +- .../translators/java/world/JavaNotifyClientTranslator.java | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java index a2d8a7263..4a6f43826 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java @@ -381,7 +381,7 @@ public class GeyserSession implements CommandSender { startGamePacket.setBonusChestEnabled(false); startGamePacket.setStartingWithMap(false); startGamePacket.setTrustingPlayers(true); - startGamePacket.setDefaultPlayerPermission(PlayerPermission.OPERATOR); + startGamePacket.setDefaultPlayerPermission(PlayerPermission.MEMBER); startGamePacket.setServerChunkTickRange(4); startGamePacket.setBehaviorPackLocked(false); startGamePacket.setResourcePackLocked(false); diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaJoinGameTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaJoinGameTranslator.java index 1abe1940c..0d6caaed0 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaJoinGameTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaJoinGameTranslator.java @@ -49,7 +49,7 @@ public class JavaJoinGameTranslator extends PacketTranslator Date: Thu, 26 Mar 2020 23:29:16 -0500 Subject: [PATCH 05/79] Fix null potion type message in console (Addresses #227) --- .../java/org/geysermc/connector/entity/type/EntityType.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java b/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java index 873c85345..f6af511cd 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java +++ b/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java @@ -123,7 +123,7 @@ public enum EntityType { PAINTING(PaintingEntity.class, 83, 0f), MINECART(MinecartEntity.class, 84, 0f), FIREBALL(ItemedFireballEntity.class, 85, 0f), - SPLASH_POTION(ThrowableEntity.class, 86, 0f), + POTION(ThrowableEntity.class, 86, 0f), ENDER_PEARL(ThrowableEntity.class, 87, 0f), LEASH_KNOT(Entity.class, 88, 0f), WITHER_SKULL(Entity.class, 89, 0f), From 9b487d7d034fc97acf80ca020fc9dfcd7b93414e Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Fri, 3 Apr 2020 17:20:14 -0500 Subject: [PATCH 06/79] Fix combat by sending the animate packet after damage (Closes #260) --- .../translators/bedrock/BedrockAnimateTranslator.java | 10 ++++++++-- .../bedrock/BedrockInventoryTransactionTranslator.java | 6 +++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockAnimateTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockAnimateTranslator.java index 33eea7651..7ccb24262 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockAnimateTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockAnimateTranslator.java @@ -33,6 +33,8 @@ import com.github.steveice10.mc.protocol.data.game.entity.player.Hand; import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerSwingArmPacket; import com.nukkitx.protocol.bedrock.packet.AnimatePacket; +import java.util.concurrent.TimeUnit; + @Translator(packet = AnimatePacket.class) public class BedrockAnimateTranslator extends PacketTranslator { @@ -40,8 +42,12 @@ public class BedrockAnimateTranslator extends PacketTranslator { public void translate(AnimatePacket packet, GeyserSession session) { switch (packet.getAction()) { case SWING_ARM: - ClientPlayerSwingArmPacket swingArmPacket = new ClientPlayerSwingArmPacket(Hand.MAIN_HAND); - session.getDownstream().getSession().send(swingArmPacket); + // Delay so entity damage can be processed first + session.getConnector().getGeneralThreadPool().schedule(() -> + session.getDownstream().getSession().send(new ClientPlayerSwingArmPacket(Hand.MAIN_HAND)), + 25, + TimeUnit.MILLISECONDS + ); break; } } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInventoryTransactionTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInventoryTransactionTranslator.java index cc399f107..de23b8a05 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInventoryTransactionTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInventoryTransactionTranslator.java @@ -61,7 +61,11 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator Date: Sat, 4 Apr 2020 01:27:34 -0500 Subject: [PATCH 07/79] Add support for team prefixes, suffixes, and colors (Fixes #150) --- .../connector/entity/PlayerEntity.java | 28 ++++++++++ .../java/scoreboard/JavaTeamTranslator.java | 2 + .../geysermc/connector/scoreboard/Team.java | 3 +- .../connector/utils/MessageUtils.java | 54 ++++++++++--------- 4 files changed, 61 insertions(+), 26 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/entity/PlayerEntity.java b/connector/src/main/java/org/geysermc/connector/entity/PlayerEntity.java index 56d59ec3d..fb48871b3 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/PlayerEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/PlayerEntity.java @@ -26,8 +26,11 @@ package org.geysermc.connector.entity; import com.github.steveice10.mc.auth.data.GameProfile; +import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; +import com.github.steveice10.mc.protocol.data.message.TextMessage; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.data.CommandPermission; +import com.nukkitx.protocol.bedrock.data.EntityData; import com.nukkitx.protocol.bedrock.data.PlayerPermission; import com.nukkitx.protocol.bedrock.packet.AddPlayerPacket; import com.nukkitx.protocol.bedrock.packet.MovePlayerPacket; @@ -39,6 +42,8 @@ import lombok.Setter; import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.entity.type.EntityType; import org.geysermc.connector.network.session.GeyserSession; +import org.geysermc.connector.scoreboard.Team; +import org.geysermc.connector.utils.MessageUtils; import org.geysermc.connector.utils.SkinUtils; import java.util.UUID; @@ -152,4 +157,27 @@ public class PlayerEntity extends LivingEntity { public void setPosition(Vector3f position) { this.position = position.add(0, entityType.getOffset(), 0); } + + @Override + public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) { + super.updateBedrockMetadata(entityMetadata, session); + + if (entityMetadata.getId() == 2) { + // System.out.println(session.getScoreboardCache().getScoreboard().getObjectives().keySet()); + for (Team team : session.getScoreboardCache().getScoreboard().getTeams().values()) { + // session.getConnector().getLogger().info("team name " + team.getName()); + // session.getConnector().getLogger().info("team entities " + team.getEntities()); + } + String username = this.username; + TextMessage name = (TextMessage) entityMetadata.getValue(); + if (name != null) { + username = MessageUtils.getBedrockMessage(name); + } + Team team = session.getScoreboardCache().getScoreboard().getTeamFor(username); + if (team != null) { + // session.getConnector().getLogger().info("team name es " + team.getName() + " with prefix " + team.getPrefix() + " and suffix " + team.getSuffix()); + metadata.put(EntityData.NAMETAG, team.getPrefix() + MessageUtils.toChatColor(team.getColor()) + username + team.getSuffix()); + } + } + } } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaTeamTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaTeamTranslator.java index a832f3d71..c9d1ccfe2 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaTeamTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaTeamTranslator.java @@ -52,12 +52,14 @@ public class JavaTeamTranslator extends PacketTranslator { case CREATE: scoreboard.registerNewTeam(packet.getTeamName(), toPlayerSet(packet.getPlayers())) .setName(MessageUtils.getBedrockMessage(packet.getDisplayName())) + .setColor(packet.getColor()) .setPrefix(MessageUtils.getBedrockMessage(packet.getPrefix())) .setSuffix(MessageUtils.getBedrockMessage(packet.getSuffix())); break; case UPDATE: scoreboard.getTeam(packet.getTeamName()) .setName(MessageUtils.getBedrockMessage(packet.getDisplayName())) + .setColor(packet.getColor()) .setPrefix(MessageUtils.getBedrockMessage(packet.getPrefix())) .setSuffix(MessageUtils.getBedrockMessage(packet.getSuffix())) .setUpdateType(UpdateType.UPDATE); diff --git a/connector/src/main/java/org/geysermc/connector/scoreboard/Team.java b/connector/src/main/java/org/geysermc/connector/scoreboard/Team.java index bf4b78532..c2fcc02c8 100644 --- a/connector/src/main/java/org/geysermc/connector/scoreboard/Team.java +++ b/connector/src/main/java/org/geysermc/connector/scoreboard/Team.java @@ -25,6 +25,7 @@ package org.geysermc.connector.scoreboard; +import com.github.steveice10.mc.protocol.data.game.scoreboard.TeamColor; import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; import lombok.Getter; import lombok.Setter; @@ -44,10 +45,10 @@ public class Team { private UpdateType updateType = UpdateType.ADD; private String name; private String prefix; + private TeamColor color; private String suffix; private Set entities = new ObjectOpenHashSet<>(); - public Team(Scoreboard scoreboard, String id) { this.scoreboard = scoreboard; this.id = id; diff --git a/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java b/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java index b5260ab75..7b4c84a7e 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java @@ -25,6 +25,7 @@ package org.geysermc.connector.utils; +import com.github.steveice10.mc.protocol.data.game.scoreboard.TeamColor; import com.github.steveice10.mc.protocol.data.message.ChatColor; import com.github.steveice10.mc.protocol.data.message.ChatFormat; import com.github.steveice10.mc.protocol.data.message.Message; @@ -36,20 +37,19 @@ import com.google.gson.JsonParser; import com.google.gson.JsonPrimitive; import java.util.ArrayList; +import java.util.Collections; import java.util.List; public class MessageUtils { public static List getTranslationParams(Message[] messages) { - List strings = new ArrayList(); - for (int i = 0; i < messages.length; i++) { - if (messages[i] instanceof TranslationMessage) { - TranslationMessage translation = (TranslationMessage) messages[i]; + List strings = new ArrayList<>(); + for (Message message : messages) { + if (message instanceof TranslationMessage) { + TranslationMessage translation = (TranslationMessage) message; - StringBuilder builder = new StringBuilder(""); - builder.append("%"); - builder.append(translation.getTranslationKey()); - strings.add(builder.toString()); + String builder = "%" + translation.getTranslationKey(); + strings.add(builder); if (translation.getTranslationKey().equals("commands.gamemode.success.other")) { strings.add(""); @@ -59,15 +59,12 @@ public class MessageUtils { strings.add(" - no permission or invalid command!"); } - for (int j = 0; j < getTranslationParams(translation.getTranslationParams()).size(); j++) { - strings.add(getTranslationParams(translation.getTranslationParams()).get(j)); - } + strings.addAll(getTranslationParams(translation.getTranslationParams())); } else { - StringBuilder builder = new StringBuilder(""); - builder.append(getFormat(messages[i].getStyle().getFormats())); - builder.append(getColor(messages[i].getStyle().getColor())); - builder.append(getBedrockMessage(messages[i])); - strings.add(builder.toString()); + String builder = getFormat(message.getStyle().getFormats()) + + getColor(message.getStyle().getColor()) + + getBedrockMessage(message); + strings.add(builder); } } @@ -75,12 +72,8 @@ public class MessageUtils { } public static String getTranslationText(TranslationMessage message) { - StringBuilder builder = new StringBuilder(""); - builder.append(getFormat(message.getStyle().getFormats())); - builder.append(getColor(message.getStyle().getColor())); - builder.append("%"); - builder.append(message.getTranslationKey()); - return builder.toString(); + return getFormat(message.getStyle().getFormats()) + getColor(message.getStyle().getColor()) + + "%" + message.getTranslationKey(); } public static String getBedrockMessage(Message message) { @@ -98,7 +91,6 @@ public class MessageUtils { builder.append(getBedrockMessage(msg)); } } - return builder.toString(); } @@ -206,7 +198,6 @@ public class MessageUtils { } catch (Exception ex) { return false; } - return true; } @@ -231,7 +222,20 @@ public class MessageUtils { formatJson((JsonObject) a.get(i)); } } - return object; } + + public static String toChatColor(TeamColor teamColor) { + for (ChatColor color : ChatColor.values()) { + if (color.name().equals(teamColor.name())) { + return getColor(color); + } + } + for (ChatFormat format : ChatFormat.values()) { + if (format.name().equals(teamColor.name())) { + return getFormat(Collections.singletonList(format)); + } + } + return ""; + } } From b6c2592b5c3d95d53497103399a42cfda85afbb5 Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Sat, 4 Apr 2020 02:08:23 -0500 Subject: [PATCH 08/79] Add missing import --- .../java/entity/player/JavaPlayerPositionRotationTranslator.java | 1 + 1 file changed, 1 insertion(+) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerPositionRotationTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerPositionRotationTranslator.java index 9d4e158c8..b76b4b55d 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerPositionRotationTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerPositionRotationTranslator.java @@ -39,6 +39,7 @@ import com.nukkitx.protocol.bedrock.packet.EntityEventPacket; import com.nukkitx.protocol.bedrock.packet.MovePlayerPacket; import com.nukkitx.protocol.bedrock.packet.RespawnPacket; import com.nukkitx.protocol.bedrock.packet.SetEntityDataPacket; +import org.geysermc.connector.utils.ChunkUtils; @Translator(packet = ServerPlayerPositionRotationPacket.class) public class JavaPlayerPositionRotationTranslator extends PacketTranslator { From 54fe7989cf29ec134d998a43d5766e5fa3638a9b Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Sat, 4 Apr 2020 02:08:50 -0500 Subject: [PATCH 09/79] Nitpicks --- .../entity/player/JavaPlayerPositionRotationTranslator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerPositionRotationTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerPositionRotationTranslator.java index b76b4b55d..cfeb2371f 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerPositionRotationTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/player/JavaPlayerPositionRotationTranslator.java @@ -30,6 +30,7 @@ import org.geysermc.connector.entity.type.EntityType; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; import org.geysermc.connector.network.translators.Translator; +import org.geysermc.connector.utils.ChunkUtils; import com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientTeleportConfirmPacket; import com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerPositionRotationPacket; @@ -39,7 +40,6 @@ import com.nukkitx.protocol.bedrock.packet.EntityEventPacket; import com.nukkitx.protocol.bedrock.packet.MovePlayerPacket; import com.nukkitx.protocol.bedrock.packet.RespawnPacket; import com.nukkitx.protocol.bedrock.packet.SetEntityDataPacket; -import org.geysermc.connector.utils.ChunkUtils; @Translator(packet = ServerPlayerPositionRotationPacket.class) public class JavaPlayerPositionRotationTranslator extends PacketTranslator { From 65277dc82aea3e53a5f24789efb51af62b8cf277 Mon Sep 17 00:00:00 2001 From: rtm516 Date: Sat, 4 Apr 2020 17:25:38 +0100 Subject: [PATCH 10/79] Added java -> bedrock lang conversions --- .../translators/java/JavaChatTranslator.java | 2 +- .../connector/utils/MessageUtils.java | 36 +++++++++++++++++-- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaChatTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaChatTranslator.java index 226bd9714..c787b8ede 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaChatTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaChatTranslator.java @@ -62,7 +62,7 @@ public class JavaChatTranslator extends PacketTranslator { textPacket.setType(TextPacket.Type.TRANSLATION); textPacket.setNeedsTranslation(true); textPacket.setParameters(MessageUtils.getTranslationParams(((TranslationMessage) packet.getMessage()).getTranslationParams())); - textPacket.setMessage(MessageUtils.getBedrockMessage(packet.getMessage())); + textPacket.setMessage(MessageUtils.getBedrockMessageWithTranslate(packet.getMessage(), true)); } else { textPacket.setNeedsTranslation(false); textPacket.setMessage(MessageUtils.getBedrockMessage(packet.getMessage())); diff --git a/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java b/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java index 7b4c84a7e..50d29beb0 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java @@ -76,14 +76,19 @@ public class MessageUtils { + "%" + message.getTranslationKey(); } - public static String getBedrockMessage(Message message) { + public static String getBedrockMessageWithTranslate(Message message, boolean convertLangStrings) { JsonParser parser = new JsonParser(); if (isMessage(message.getText())) { JsonObject object = parser.parse(message.getText()).getAsJsonObject(); message = Message.fromJson(formatJson(object)); } - StringBuilder builder = new StringBuilder(message.getText()); + String messageText = message.getText(); + if (convertLangStrings) { + messageText = getLangConversion(messageText); + } + + StringBuilder builder = new StringBuilder(messageText); for (Message msg : message.getExtra()) { builder.append(getFormat(msg.getStyle().getFormats())); builder.append(getColor(msg.getStyle().getColor())); @@ -94,6 +99,33 @@ public class MessageUtils { return builder.toString(); } + private static String getLangConversion(String messageText) { + switch (messageText) { + case "block.minecraft.bed.occupied": + return "tile.bed.occupied"; + case "block.minecraft.bed.too_far_away": + return "tile.bed.tooFar"; + case "block.minecraft.bed.not_safe": + return "tile.bed.notSafe"; + case "block.minecraft.bed.no_sleep": + return "tile.bed.noSleep"; + case "block.minecraft.bed.not_valid": + return "tile.bed.notValid"; + case "block.minecraft.bed.set_spawn": + return "tile.bed.respawnSet"; + + case "chat.type.advancement.task": + return "chat.type.achievement"; + + default: + return messageText; + } + } + + public static String getBedrockMessage(Message message) { + return getBedrockMessageWithTranslate(message, false); + } + private static String getColor(ChatColor color) { String base = "\u00a7"; switch (color) { From 7298e2ff3f760d24b23b34d669ba52bf489f8a6a Mon Sep 17 00:00:00 2001 From: rtm516 Date: Sat, 4 Apr 2020 17:44:41 +0100 Subject: [PATCH 11/79] Added a few more lang string translations --- .../java/org/geysermc/connector/utils/MessageUtils.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java b/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java index 50d29beb0..aeaed6920 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java @@ -115,8 +115,15 @@ public class MessageUtils { return "tile.bed.respawnSet"; case "chat.type.advancement.task": + case "chat.type.advancement.challenge": + case "chat.type.advancement.goal": return "chat.type.achievement"; + case "commands.teleport.success.entity.single": + return "commands.tp.success"; + case "commands.teleport.success.location.single": + return "commands.tp.success.coordinates"; + default: return messageText; } From c1e00e3614e80bb922cf3c9b655100be16406622 Mon Sep 17 00:00:00 2001 From: rtm516 Date: Sat, 4 Apr 2020 19:39:14 +0100 Subject: [PATCH 12/79] Moved to json file lang mapping --- .../connector/utils/MessageUtils.java | 52 ++++++++----------- 1 file changed, 22 insertions(+), 30 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java b/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java index aeaed6920..978f15c07 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java @@ -25,6 +25,7 @@ package org.geysermc.connector.utils; +import com.fasterxml.jackson.databind.JsonNode; import com.github.steveice10.mc.protocol.data.game.scoreboard.TeamColor; import com.github.steveice10.mc.protocol.data.message.ChatColor; import com.github.steveice10.mc.protocol.data.message.ChatFormat; @@ -36,11 +37,28 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.google.gson.JsonPrimitive; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; +import java.io.InputStream; +import java.util.*; public class MessageUtils { + private static final HashMap LANG_MAPPINGS = new HashMap<>(); + + static { + /* Load the language mappings */ + InputStream stream = Toolbox.getResource("mappings/lang.json"); + JsonNode lang; + try { + lang = Toolbox.JSON_MAPPER.readTree(stream); + } catch (Exception e) { + throw new AssertionError("Unable to load Java lang mappings", e); + } + + Iterator> langIterator = lang.fields(); + while (langIterator.hasNext()) { + Map.Entry entry = langIterator.next(); + LANG_MAPPINGS.put(entry.getKey(), entry.getValue().asText()); + } + } public static List getTranslationParams(Message[] messages) { List strings = new ArrayList<>(); @@ -100,33 +118,7 @@ public class MessageUtils { } private static String getLangConversion(String messageText) { - switch (messageText) { - case "block.minecraft.bed.occupied": - return "tile.bed.occupied"; - case "block.minecraft.bed.too_far_away": - return "tile.bed.tooFar"; - case "block.minecraft.bed.not_safe": - return "tile.bed.notSafe"; - case "block.minecraft.bed.no_sleep": - return "tile.bed.noSleep"; - case "block.minecraft.bed.not_valid": - return "tile.bed.notValid"; - case "block.minecraft.bed.set_spawn": - return "tile.bed.respawnSet"; - - case "chat.type.advancement.task": - case "chat.type.advancement.challenge": - case "chat.type.advancement.goal": - return "chat.type.achievement"; - - case "commands.teleport.success.entity.single": - return "commands.tp.success"; - case "commands.teleport.success.location.single": - return "commands.tp.success.coordinates"; - - default: - return messageText; - } + return LANG_MAPPINGS.getOrDefault(messageText, messageText); } public static String getBedrockMessage(Message message) { From de370464660a18eda6901fd600a41b3bae980d75 Mon Sep 17 00:00:00 2001 From: MrPowerGamerBR Date: Sat, 4 Apr 2020 17:23:02 -0300 Subject: [PATCH 13/79] Add map item translators --- .../bedrock/BedrockMapInfoRequestPacket.java | 37 +++ .../translators/item/ItemTranslator.java | 11 +- .../java/world/JavaMapDataTranslator.java | 68 +++++ .../geysermc/connector/utils/MapColor.java | 244 ++++++++++++++++++ 4 files changed, 359 insertions(+), 1 deletion(-) create mode 100644 connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockMapInfoRequestPacket.java create mode 100644 connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaMapDataTranslator.java create mode 100644 connector/src/main/java/org/geysermc/connector/utils/MapColor.java diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockMapInfoRequestPacket.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockMapInfoRequestPacket.java new file mode 100644 index 000000000..67db2017d --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockMapInfoRequestPacket.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2019-2020 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.network.translators.bedrock; + +import com.nukkitx.protocol.bedrock.packet.MapInfoRequestPacket; +import org.geysermc.connector.network.session.GeyserSession; +import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; + +@Translator(packet = MapInfoRequestPacket.class) +public class BedrockMapInfoRequestPacket extends PacketTranslator { + @Override + public void translate(MapInfoRequestPacket packet, GeyserSession session) {} +} diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemTranslator.java index 99d416bba..0da776dcf 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemTranslator.java @@ -72,7 +72,16 @@ public class ItemTranslator { if (stack.getNbt() == null) { return ItemData.of(bedrockItem.getBedrockId(), (short) bedrockItem.getBedrockData(), stack.getAmount()); } - return ItemData.of(bedrockItem.getBedrockId(), (short) bedrockItem.getBedrockData(), stack.getAmount(), translateToBedrockNBT(stack.getNbt())); + + // TODO: Create proper transformers instead of shoving everything here + CompoundTag tag = stack.getNbt(); + IntTag mapId = tag.get("map"); + + if (mapId != null) + tag.put(new StringTag("map_uuid", mapId.getValue().toString())); + + + return ItemData.of(bedrockItem.getBedrockId(), (short) bedrockItem.getBedrockData(), stack.getAmount(), translateToBedrockNBT(tag)); } public ItemEntry getItem(ItemStack stack) { diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaMapDataTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaMapDataTranslator.java new file mode 100644 index 000000000..ccf3e2090 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaMapDataTranslator.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2019-2020 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.network.translators.java.world; + +import com.github.steveice10.mc.protocol.data.game.world.map.MapData; +import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerMapDataPacket; +import com.nukkitx.protocol.bedrock.packet.ClientboundMapItemDataPacket; +import org.geysermc.connector.network.session.GeyserSession; +import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; +import org.geysermc.connector.utils.MapColor; + +@Translator(packet = ServerMapDataPacket.class) +public class JavaMapDataTranslator extends PacketTranslator { + @Override + public void translate(ServerMapDataPacket packet, GeyserSession session) { + ClientboundMapItemDataPacket mapItemDataPacket = new ClientboundMapItemDataPacket(); + + mapItemDataPacket.setUniqueMapId(packet.getMapId()); + mapItemDataPacket.setDimensionId(session.getLastDimPacket().getDimension()); + mapItemDataPacket.setLocked(packet.isLocked()); + mapItemDataPacket.setScale(packet.getScale()); + + MapData data = packet.getData(); + if (data != null) { + mapItemDataPacket.setXOffset(data.getX()); + mapItemDataPacket.setYOffset(data.getY()); + mapItemDataPacket.setWidth(data.getColumns()); + mapItemDataPacket.setHeight(data.getRows()); + + // Every int entry is an ARGB color + int[] colors = new int[data.getData().length]; + + int idx = 0; + for (byte colorId : data.getData()) { + colors[idx] = MapColor.fromId(colorId).toARGB(); + idx++; + } + + mapItemDataPacket.setColors(colors); + } + + session.getUpstream().getSession().sendPacket(mapItemDataPacket); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/utils/MapColor.java b/connector/src/main/java/org/geysermc/connector/utils/MapColor.java new file mode 100644 index 000000000..2c4a13b9f --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/utils/MapColor.java @@ -0,0 +1,244 @@ +package org.geysermc.connector.utils; + +import java.util.Arrays; + +public enum MapColor { + COLOR_0(-1, -1, -1), + COLOR_1(-1, -1, -1), + COLOR_2(-1, -1, -1), + COLOR_3(-1, -1, -1), + COLOR_4(89, 125, 39), + COLOR_5(109, 153, 48), + COLOR_6(127, 178, 56), + COLOR_7(67, 94, 29), + COLOR_8(174, 164, 115), + COLOR_9(213, 201, 140), + COLOR_10(247, 233, 163), + COLOR_11(130, 123, 86), + COLOR_12(140, 140, 140), + COLOR_13(171, 171, 171), + COLOR_14(199, 199, 199), + COLOR_15(105, 105, 105), + COLOR_16(180, 0, 0), + COLOR_17(220, 0, 0), + COLOR_18(255, 0, 0), + COLOR_19(135, 0, 0), + COLOR_20(112, 112, 180), + COLOR_21(138, 138, 220), + COLOR_22(160, 160, 255), + COLOR_23(84, 84, 135), + COLOR_24(117, 117, 117), + COLOR_25(144, 144, 144), + COLOR_26(167, 167, 167), + COLOR_27(88, 88, 88), + COLOR_28(0, 87, 0), + COLOR_29(0, 106, 0), + COLOR_30(0, 124, 0), + COLOR_31(0, 65, 0), + COLOR_32(180, 180, 180), + COLOR_33(220, 220, 220), + COLOR_34(255, 255, 255), + COLOR_35(135, 135, 135), + COLOR_36(115, 118, 129), + COLOR_37(141, 144, 158), + COLOR_38(164, 168, 184), + COLOR_39(86, 88, 97), + COLOR_40(106, 76, 54), + COLOR_41(130, 94, 66), + COLOR_42(151, 109, 77), + COLOR_43(79, 57, 40), + COLOR_44(79, 79, 79), + COLOR_45(96, 96, 96), + COLOR_46(112, 112, 112), + COLOR_47(59, 59, 59), + COLOR_48(45, 45, 180), + COLOR_49(55, 55, 220), + COLOR_50(64, 64, 255), + COLOR_51(33, 33, 135), + COLOR_52(100, 84, 50), + COLOR_53(123, 102, 62), + COLOR_54(143, 119, 72), + COLOR_55(75, 63, 38), + COLOR_56(180, 177, 172), + COLOR_57(220, 217, 211), + COLOR_58(255, 252, 245), + COLOR_59(135, 133, 129), + COLOR_60(152, 89, 36), + COLOR_61(186, 109, 44), + COLOR_62(216, 127, 51), + COLOR_63(114, 67, 27), + COLOR_64(125, 53, 152), + COLOR_65(153, 65, 186), + COLOR_66(178, 76, 216), + COLOR_67(94, 40, 114), + COLOR_68(72, 108, 152), + COLOR_69(88, 132, 186), + COLOR_70(102, 153, 216), + COLOR_71(54, 81, 114), + COLOR_72(161, 161, 36), + COLOR_73(197, 197, 44), + COLOR_74(229, 229, 51), + COLOR_75(121, 121, 27), + COLOR_76(89, 144, 17), + COLOR_77(109, 176, 21), + COLOR_78(127, 204, 25), + COLOR_79(67, 108, 13), + COLOR_80(170, 89, 116), + COLOR_81(208, 109, 142), + COLOR_82(242, 127, 165), + COLOR_83(128, 67, 87), + COLOR_84(53, 53, 53), + COLOR_85(65, 65, 65), + COLOR_86(76, 76, 76), + COLOR_87(40, 40, 40), + COLOR_88(108, 108, 108), + COLOR_89(132, 132, 132), + COLOR_90(153, 153, 153), + COLOR_91(81, 81, 81), + COLOR_92(53, 89, 108), + COLOR_93(65, 109, 132), + COLOR_94(76, 127, 153), + COLOR_95(40, 67, 81), + COLOR_96(89, 44, 125), + COLOR_97(109, 54, 153), + COLOR_98(127, 63, 178), + COLOR_99(67, 33, 94), + COLOR_100(36, 53, 125), + COLOR_101(44, 65, 153), + COLOR_102(51, 76, 178), + COLOR_103(27, 40, 94), + COLOR_104(72, 53, 36), + COLOR_105(88, 65, 44), + COLOR_106(102, 76, 51), + COLOR_107(54, 40, 27), + COLOR_108(72, 89, 36), + COLOR_109(88, 109, 44), + COLOR_110(102, 127, 51), + COLOR_111(54, 67, 27), + COLOR_112(108, 36, 36), + COLOR_113(132, 44, 44), + COLOR_114(153, 51, 51), + COLOR_115(81, 27, 27), + COLOR_116(17, 17, 17), + COLOR_117(21, 21, 21), + COLOR_118(25, 25, 25), + COLOR_119(13, 13, 13), + COLOR_120(176, 168, 54), + COLOR_121(215, 205, 66), + COLOR_122(250, 238, 77), + COLOR_123(132, 126, 40), + COLOR_124(64, 154, 150), + COLOR_125(79, 188, 183), + COLOR_126(92, 219, 213), + COLOR_127(48, 115, 112), + COLOR_128(52, 90, 180), + COLOR_129(63, 110, 220), + COLOR_130(74, 128, 255), + COLOR_131(39, 67, 135), + COLOR_132(0, 153, 40), + COLOR_133(0, 187, 50), + COLOR_134(0, 217, 58), + COLOR_135(0, 114, 30), + COLOR_136(91, 60, 34), + COLOR_137(111, 74, 42), + COLOR_138(129, 86, 49), + COLOR_139(68, 45, 25), + COLOR_140(79, 1, 0), + COLOR_141(96, 1, 0), + COLOR_142(112, 2, 0), + COLOR_143(59, 1, 0), + COLOR_144(147, 124, 113), + COLOR_145(180, 152, 138), + COLOR_146(209, 177, 161), + COLOR_147(110, 93, 85), + COLOR_148(112, 57, 25), + COLOR_149(137, 70, 31), + COLOR_150(159, 82, 36), + COLOR_151(84, 43, 19), + COLOR_152(105, 61, 76), + COLOR_153(128, 75, 93), + COLOR_154(149, 87, 108), + COLOR_155(78, 46, 57), + COLOR_156(79, 76, 97), + COLOR_157(96, 93, 119), + COLOR_158(112, 108, 138), + COLOR_159(59, 57, 73), + COLOR_160(131, 93, 25), + COLOR_161(160, 114, 31), + COLOR_162(186, 133, 36), + COLOR_163(98, 70, 19), + COLOR_164(72, 82, 37), + COLOR_165(88, 100, 45), + COLOR_166(103, 117, 53), + COLOR_167(54, 61, 28), + COLOR_168(112, 54, 55), + COLOR_169(138, 66, 67), + COLOR_170(160, 77, 78), + COLOR_171(84, 40, 41), + COLOR_172(40, 28, 24), + COLOR_173(49, 35, 30), + COLOR_174(57, 41, 35), + COLOR_175(30, 21, 18), + COLOR_176(95, 75, 69), + COLOR_177(116, 92, 84), + COLOR_178(135, 107, 98), + COLOR_179(71, 56, 51), + COLOR_180(61, 64, 64), + COLOR_181(75, 79, 79), + COLOR_182(87, 92, 92), + COLOR_183(46, 48, 48), + COLOR_184(86, 51, 62), + COLOR_185(105, 62, 75), + COLOR_186(122, 73, 88), + COLOR_187(64, 38, 46), + COLOR_188(53, 43, 64), + COLOR_189(65, 53, 79), + COLOR_190(76, 62, 92), + COLOR_191(40, 32, 48), + COLOR_192(53, 35, 24), + COLOR_193(65, 43, 30), + COLOR_194(76, 50, 35), + COLOR_195(40, 26, 18), + COLOR_196(53, 57, 29), + COLOR_197(65, 70, 36), + COLOR_198(76, 82, 42), + COLOR_199(40, 43, 22), + COLOR_200(100, 42, 32), + COLOR_201(122, 51, 39), + COLOR_202(142, 60, 46), + COLOR_203(75, 31, 24), + COLOR_204(26, 15, 11), + COLOR_205(31, 18, 13), + COLOR_206(37, 22, 16), + COLOR_207(19, 11, 8); + + private final int red; + private final int green; + private final int blue; + + MapColor(int red, int green, int blue) { + this.red = red; + this.green = green; + this.blue = blue; + } + + int getId() { + return ordinal(); + } + + public static MapColor fromId(int id) { + return Arrays.stream(values()).filter(color -> color.getId() == id).findFirst().get(); + } + + public int toARGB() { + int alpha = 255; + if (red == -1 && green == -1 && blue == -1) + alpha = 0; // transparent + + long result = red & 0xff; + result |= (green & 0xff) << 8; + result |= (blue & 0xff) << 16; + result |= (alpha & 0xff) << 24; + return (int) (result & 0xFFFFFFFFL); + } +} \ No newline at end of file From 3094fedd541631c80f2accb11d6383b23f605aab Mon Sep 17 00:00:00 2001 From: MrPowerGamerBR Date: Sat, 4 Apr 2020 17:28:59 -0300 Subject: [PATCH 14/79] Remove unused map info request translator This was used for debugging purposes, to check if the map was correctly remapped to the client because, if it wasn't, it would've returned -1 as the map ID --- .../bedrock/BedrockMapInfoRequestPacket.java | 37 ------------------- 1 file changed, 37 deletions(-) delete mode 100644 connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockMapInfoRequestPacket.java diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockMapInfoRequestPacket.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockMapInfoRequestPacket.java deleted file mode 100644 index 67db2017d..000000000 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockMapInfoRequestPacket.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2019-2020 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.network.translators.bedrock; - -import com.nukkitx.protocol.bedrock.packet.MapInfoRequestPacket; -import org.geysermc.connector.network.session.GeyserSession; -import org.geysermc.connector.network.translators.PacketTranslator; -import org.geysermc.connector.network.translators.Translator; - -@Translator(packet = MapInfoRequestPacket.class) -public class BedrockMapInfoRequestPacket extends PacketTranslator { - @Override - public void translate(MapInfoRequestPacket packet, GeyserSession session) {} -} From e504d0f46701ce7f4ca3701761a6a6fb529746e0 Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Sat, 4 Apr 2020 18:00:30 -0500 Subject: [PATCH 15/79] Don't minimize the jar for plugin versions (Actually fixes #265) --- bootstrap/bukkit/pom.xml | 1 - bootstrap/bungeecord/pom.xml | 1 - bootstrap/sponge/pom.xml | 1 - bootstrap/velocity/pom.xml | 3 --- 4 files changed, 6 deletions(-) diff --git a/bootstrap/bukkit/pom.xml b/bootstrap/bukkit/pom.xml index 0e5dd3df7..fd2ecbf0d 100644 --- a/bootstrap/bukkit/pom.xml +++ b/bootstrap/bukkit/pom.xml @@ -54,7 +54,6 @@ org.geysermc.platform.bukkit.shaded.fastutil - true diff --git a/bootstrap/bungeecord/pom.xml b/bootstrap/bungeecord/pom.xml index 317e80cb5..0f6de3faa 100644 --- a/bootstrap/bungeecord/pom.xml +++ b/bootstrap/bungeecord/pom.xml @@ -54,7 +54,6 @@ org.geysermc.platform.bungeecord.shaded.netty - true diff --git a/bootstrap/sponge/pom.xml b/bootstrap/sponge/pom.xml index 83c070aed..696721d20 100644 --- a/bootstrap/sponge/pom.xml +++ b/bootstrap/sponge/pom.xml @@ -58,7 +58,6 @@ org.geysermc.platform.sponge.shaded.fastutil - true diff --git a/bootstrap/velocity/pom.xml b/bootstrap/velocity/pom.xml index 22fe92115..74d42e002 100644 --- a/bootstrap/velocity/pom.xml +++ b/bootstrap/velocity/pom.xml @@ -43,9 +43,6 @@ shade - - true - From 7f1fb3d43caf3456988b86caef70aebc55e5ec84 Mon Sep 17 00:00:00 2001 From: rtm516 Date: Sun, 5 Apr 2020 02:36:25 +0100 Subject: [PATCH 16/79] Added new locale loading system --- .../connector/network/translators/java/JavaChatTranslator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaChatTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaChatTranslator.java index c787b8ede..5db4a44ee 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaChatTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaChatTranslator.java @@ -62,7 +62,7 @@ public class JavaChatTranslator extends PacketTranslator { textPacket.setType(TextPacket.Type.TRANSLATION); textPacket.setNeedsTranslation(true); textPacket.setParameters(MessageUtils.getTranslationParams(((TranslationMessage) packet.getMessage()).getTranslationParams())); - textPacket.setMessage(MessageUtils.getBedrockMessageWithTranslate(packet.getMessage(), true)); + textPacket.setMessage(MessageUtils.getBedrockMessageWithTranslate(packet.getMessage(), session.getClientData().getLanguageCode())); } else { textPacket.setNeedsTranslation(false); textPacket.setMessage(MessageUtils.getBedrockMessage(packet.getMessage())); From b5ce83bbe23bec035ff595b65a9383801aed93ef Mon Sep 17 00:00:00 2001 From: rtm516 Date: Sun, 5 Apr 2020 02:37:39 +0100 Subject: [PATCH 17/79] Missed changes --- .../connector/utils/MessageUtils.java | 57 ++++++++++++++----- .../org/geysermc/connector/utils/Toolbox.java | 2 +- 2 files changed, 43 insertions(+), 16 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java b/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java index 978f15c07..0872d0762 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java @@ -36,27 +36,43 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.google.gson.JsonPrimitive; +import org.geysermc.connector.GeyserConnector; import java.io.InputStream; import java.util.*; public class MessageUtils { - private static final HashMap LANG_MAPPINGS = new HashMap<>(); + private static final HashMap> LOCALE_MAPPINGS = new HashMap<>(); static { /* Load the language mappings */ - InputStream stream = Toolbox.getResource("mappings/lang.json"); - JsonNode lang; + InputStream languagesStream = Toolbox.getResource("mappings/locales.json"); + JsonNode locales; try { - lang = Toolbox.JSON_MAPPER.readTree(stream); + locales = Toolbox.JSON_MAPPER.readTree(languagesStream); } catch (Exception e) { - throw new AssertionError("Unable to load Java lang mappings", e); + throw new AssertionError("Unable to load Java locale list", e); } - Iterator> langIterator = lang.fields(); - while (langIterator.hasNext()) { - Map.Entry entry = langIterator.next(); - LANG_MAPPINGS.put(entry.getKey(), entry.getValue().asText()); + for (JsonNode localeNode : locales.get("locales")) { + String currentLocale = localeNode.asText(); + + InputStream stream = Toolbox.getResource("mappings/lang/" + currentLocale + ".json"); + JsonNode lang; + try { + lang = Toolbox.JSON_MAPPER.readTree(stream); + } catch (Exception e) { + throw new AssertionError("Unable to load Java lang map for " + currentLocale, e); + } + + Iterator> langIterator = lang.fields(); + HashMap langMap = new HashMap<>(); + while (langIterator.hasNext()) { + Map.Entry entry = langIterator.next(); + langMap.put(entry.getKey(), entry.getValue().asText()); + } + + LOCALE_MAPPINGS.put(currentLocale.toLowerCase(), langMap); } } @@ -94,7 +110,7 @@ public class MessageUtils { + "%" + message.getTranslationKey(); } - public static String getBedrockMessageWithTranslate(Message message, boolean convertLangStrings) { + public static String getBedrockMessageWithTranslate(Message message, String locale) { JsonParser parser = new JsonParser(); if (isMessage(message.getText())) { JsonObject object = parser.parse(message.getText()).getAsJsonObject(); @@ -102,8 +118,8 @@ public class MessageUtils { } String messageText = message.getText(); - if (convertLangStrings) { - messageText = getLangConversion(messageText); + if (locale != null) { + messageText = getLocaleString(messageText, locale); } StringBuilder builder = new StringBuilder(messageText); @@ -117,12 +133,23 @@ public class MessageUtils { return builder.toString(); } - private static String getLangConversion(String messageText) { - return LANG_MAPPINGS.getOrDefault(messageText, messageText); + public static String getBedrockMessageWithTranslate(Message message) { + return getBedrockMessageWithTranslate(message, null); + } + + private static String getLocaleString(String messageText, String locale) { + HashMap localeStrings = LOCALE_MAPPINGS.get(locale.toLowerCase()); + if (localeStrings == null) + localeStrings = LOCALE_MAPPINGS.get("en_us"); + + String newLocaleString = localeStrings.getOrDefault(messageText, messageText); + + GeyserConnector.getInstance().getLogger().info("Converting '" + messageText + "' -> '" + newLocaleString + "'"); + return newLocaleString; } public static String getBedrockMessage(Message message) { - return getBedrockMessageWithTranslate(message, false); + return getBedrockMessageWithTranslate(message); } private static String getColor(ChatColor color) { diff --git a/connector/src/main/java/org/geysermc/connector/utils/Toolbox.java b/connector/src/main/java/org/geysermc/connector/utils/Toolbox.java index 45802196b..b48d5b547 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/Toolbox.java +++ b/connector/src/main/java/org/geysermc/connector/utils/Toolbox.java @@ -40,7 +40,7 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.network.translators.item.ItemEntry; -import java.io.InputStream; +import java.io.*; import java.util.*; public class Toolbox { From 845c914492a23698ca090c44e9253bd5b0dafec1 Mon Sep 17 00:00:00 2001 From: rtm516 Date: Sun, 5 Apr 2020 02:58:23 +0100 Subject: [PATCH 18/79] Moved loading and added default locale config option --- .../bukkit/GeyserBukkitConfiguration.java | 3 ++ .../bungeecord/GeyserBungeeConfiguration.java | 3 ++ .../sponge/GeyserSpongeConfiguration.java | 3 ++ .../standalone/GeyserConfiguration.java | 3 ++ .../velocity/GeyserVelocityConfiguration.java | 3 ++ .../geysermc/common/IGeyserConfiguration.java | 2 + .../connector/utils/MessageUtils.java | 37 +------------------ .../org/geysermc/connector/utils/Toolbox.java | 32 ++++++++++++++++ connector/src/main/resources/config.yml | 3 ++ 9 files changed, 54 insertions(+), 35 deletions(-) diff --git a/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitConfiguration.java b/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitConfiguration.java index e38a982db..a99ac1e50 100644 --- a/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitConfiguration.java +++ b/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitConfiguration.java @@ -101,6 +101,9 @@ public class GeyserBukkitConfiguration implements IGeyserConfiguration { return config.getBoolean("allow-third-party-capes", true); } + @Override + public String getDefaultLocale() { return config.getString("default-locale", "en_us"); } + @Override public Path getFloodgateKeyFile() { return Paths.get(dataFolder.toString(), config.getString("floodgate-key-file", "public-key.pem")); diff --git a/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeeConfiguration.java b/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeeConfiguration.java index 94580e583..17a6ae0cf 100644 --- a/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeeConfiguration.java +++ b/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeeConfiguration.java @@ -102,6 +102,9 @@ public class GeyserBungeeConfiguration implements IGeyserConfiguration { return config.getBoolean("allow-third-party-capes", true); } + @Override + public String getDefaultLocale() { return config.getString("default-locale", "en_us"); } + @Override public Path getFloodgateKeyFile() { return Paths.get(dataFolder.toString(), config.getString("floodgate-key-file", "public-key.pem")); diff --git a/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongeConfiguration.java b/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongeConfiguration.java index dbc83fbea..18fb73081 100644 --- a/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongeConfiguration.java +++ b/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongeConfiguration.java @@ -105,6 +105,9 @@ public class GeyserSpongeConfiguration implements IGeyserConfiguration { return node.getNode("allow-third-party-capes").getBoolean(true); } + @Override + public String getDefaultLocale() { return node.getNode("default-locale").getString("en_us"); } + @Override public Path getFloodgateKeyFile() { return Paths.get(dataFolder.toString(), node.getNode("floodgate-key-file").getString("public-key.pem")); diff --git a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserConfiguration.java b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserConfiguration.java index 06cb711c1..a1362c7a7 100644 --- a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserConfiguration.java +++ b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserConfiguration.java @@ -63,6 +63,9 @@ public class GeyserConfiguration implements IGeyserConfiguration { @JsonProperty("allow-third-party-capes") private boolean allowThirdPartyCapes; + @JsonProperty("default-locale") + private String defaultLocale; + private MetricsInfo metrics; @Override diff --git a/bootstrap/velocity/src/main/java/org/geysermc/platform/velocity/GeyserVelocityConfiguration.java b/bootstrap/velocity/src/main/java/org/geysermc/platform/velocity/GeyserVelocityConfiguration.java index 2fab448d9..920c65379 100644 --- a/bootstrap/velocity/src/main/java/org/geysermc/platform/velocity/GeyserVelocityConfiguration.java +++ b/bootstrap/velocity/src/main/java/org/geysermc/platform/velocity/GeyserVelocityConfiguration.java @@ -63,6 +63,9 @@ public class GeyserVelocityConfiguration implements IGeyserConfiguration { @JsonProperty("allow-third-party-capes") private boolean allowThirdPartyCapes; + @JsonProperty("default-locale") + private String defaultLocale; + private MetricsInfo metrics; @Override diff --git a/common/src/main/java/org/geysermc/common/IGeyserConfiguration.java b/common/src/main/java/org/geysermc/common/IGeyserConfiguration.java index db5d831b1..41534457e 100644 --- a/common/src/main/java/org/geysermc/common/IGeyserConfiguration.java +++ b/common/src/main/java/org/geysermc/common/IGeyserConfiguration.java @@ -46,6 +46,8 @@ public interface IGeyserConfiguration { boolean isAllowThirdPartyCapes(); + String getDefaultLocale(); + Path getFloodgateKeyFile(); IMetricsInfo getMetrics(); diff --git a/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java b/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java index 0872d0762..854b3c1a2 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java @@ -42,39 +42,6 @@ import java.io.InputStream; import java.util.*; public class MessageUtils { - private static final HashMap> LOCALE_MAPPINGS = new HashMap<>(); - - static { - /* Load the language mappings */ - InputStream languagesStream = Toolbox.getResource("mappings/locales.json"); - JsonNode locales; - try { - locales = Toolbox.JSON_MAPPER.readTree(languagesStream); - } catch (Exception e) { - throw new AssertionError("Unable to load Java locale list", e); - } - - for (JsonNode localeNode : locales.get("locales")) { - String currentLocale = localeNode.asText(); - - InputStream stream = Toolbox.getResource("mappings/lang/" + currentLocale + ".json"); - JsonNode lang; - try { - lang = Toolbox.JSON_MAPPER.readTree(stream); - } catch (Exception e) { - throw new AssertionError("Unable to load Java lang map for " + currentLocale, e); - } - - Iterator> langIterator = lang.fields(); - HashMap langMap = new HashMap<>(); - while (langIterator.hasNext()) { - Map.Entry entry = langIterator.next(); - langMap.put(entry.getKey(), entry.getValue().asText()); - } - - LOCALE_MAPPINGS.put(currentLocale.toLowerCase(), langMap); - } - } public static List getTranslationParams(Message[] messages) { List strings = new ArrayList<>(); @@ -138,9 +105,9 @@ public class MessageUtils { } private static String getLocaleString(String messageText, String locale) { - HashMap localeStrings = LOCALE_MAPPINGS.get(locale.toLowerCase()); + HashMap localeStrings = Toolbox.LOCALE_MAPPINGS.get(locale.toLowerCase()); if (localeStrings == null) - localeStrings = LOCALE_MAPPINGS.get("en_us"); + localeStrings = Toolbox.LOCALE_MAPPINGS.get(GeyserConnector.getInstance().getConfig().getDefaultLocale()); String newLocaleString = localeStrings.getOrDefault(messageText, messageText); diff --git a/connector/src/main/java/org/geysermc/connector/utils/Toolbox.java b/connector/src/main/java/org/geysermc/connector/utils/Toolbox.java index b48d5b547..8ccd3aa3a 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/Toolbox.java +++ b/connector/src/main/java/org/geysermc/connector/utils/Toolbox.java @@ -52,6 +52,8 @@ public class Toolbox { public static final Int2ObjectMap ITEM_ENTRIES = new Int2ObjectOpenHashMap<>(); + public static final HashMap> LOCALE_MAPPINGS = new HashMap<>(); + static { /* Load biomes */ InputStream biomestream = GeyserConnector.class.getClassLoader().getResourceAsStream("bedrock/biome_definitions.dat"); @@ -103,6 +105,36 @@ public class Toolbox { entry.getValue().get("bedrock_id").intValue(), entry.getValue().get("bedrock_data").intValue())); itemIndex++; } + + /* Load the language mappings */ + stream = Toolbox.getResource("mappings/locales.json"); + JsonNode locales; + try { + locales = Toolbox.JSON_MAPPER.readTree(stream); + } catch (Exception e) { + throw new AssertionError("Unable to load Java locale list", e); + } + + for (JsonNode localeNode : locales.get("locales")) { + String currentLocale = localeNode.asText(); + + InputStream localeStream = Toolbox.getResource("mappings/lang/" + currentLocale + ".json"); + JsonNode locale; + try { + locale = Toolbox.JSON_MAPPER.readTree(localeStream); + } catch (Exception e) { + throw new AssertionError("Unable to load Java lang map for " + currentLocale, e); + } + + Iterator> localeIterator = locale.fields(); + HashMap langMap = new HashMap<>(); + while (localeIterator.hasNext()) { + Map.Entry entry = localeIterator.next(); + langMap.put(entry.getKey(), entry.getValue().asText()); + } + + LOCALE_MAPPINGS.put(currentLocale.toLowerCase(), langMap); + } } public static InputStream getResource(String resource) { diff --git a/connector/src/main/resources/config.yml b/connector/src/main/resources/config.yml index ba5700e27..ae0cbed8d 100644 --- a/connector/src/main/resources/config.yml +++ b/connector/src/main/resources/config.yml @@ -57,6 +57,9 @@ general-thread-pool: 32 # OptiFine capes, LabyMod capes, 5Zig capes and MinecraftCapes allow-third-party-capes: true +# The default locale if we dont have the one the client requested +default-locale: en_us + # bStats is a stat tracker that is entirely anonymous and tracks only basic information # about Geyser, such as how many people are online, how many servers are using Geyser, # what OS is being used, etc. You can learn more about bStats here: https://bstats.org/. From a77c08b084a269cf4a28e0978370e0e2e15e80ed Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Sun, 5 Apr 2020 00:44:23 -0500 Subject: [PATCH 19/79] Relocate fastutil for velocity version to fix NoClassDefFoundError --- bootstrap/velocity/pom.xml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/bootstrap/velocity/pom.xml b/bootstrap/velocity/pom.xml index 74d42e002..075aedc32 100644 --- a/bootstrap/velocity/pom.xml +++ b/bootstrap/velocity/pom.xml @@ -43,6 +43,14 @@ shade + + + + it.unimi.dsi.fastutil + org.geysermc.platform.velocity.shaded.fastutil + + + From 41f6d991a4b8e4b36b29a6fa8eb454ea9e836bc3 Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Sun, 5 Apr 2020 00:47:04 -0500 Subject: [PATCH 20/79] Fix improperly named bedrock packet translator --- ...r.java => BedrockSetLocalPlayerAsInitializedTranslator.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename connector/src/main/java/org/geysermc/connector/network/translators/bedrock/{BedrockPlayerInitializedTranslator.java => BedrockSetLocalPlayerAsInitializedTranslator.java} (95%) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockPlayerInitializedTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockSetLocalPlayerAsInitializedTranslator.java similarity index 95% rename from connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockPlayerInitializedTranslator.java rename to connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockSetLocalPlayerAsInitializedTranslator.java index fda2cade2..54a5112d4 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockPlayerInitializedTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockSetLocalPlayerAsInitializedTranslator.java @@ -34,7 +34,7 @@ import org.geysermc.connector.utils.SkinUtils; import com.nukkitx.protocol.bedrock.packet.SetLocalPlayerAsInitializedPacket; @Translator(packet = SetLocalPlayerAsInitializedPacket.class) -public class BedrockPlayerInitializedTranslator extends PacketTranslator { +public class BedrockSetLocalPlayerAsInitializedTranslator extends PacketTranslator { @Override public void translate(SetLocalPlayerAsInitializedPacket packet, GeyserSession session) { if (session.getPlayerEntity().getGeyserId() == packet.getRuntimeEntityId()) { From de22248fe0a0a9e7dcfaeb7694145d0988f8bac9 Mon Sep 17 00:00:00 2001 From: Redned Date: Sun, 5 Apr 2020 01:19:57 -0500 Subject: [PATCH 21/79] Update bug report issue template --- .github/ISSUE_TEMPLATE/bug_report.md | 38 +++++++++++++++------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index af9314c60..8001187ca 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -7,30 +7,34 @@ assignees: '' --- + + + + **Describe the bug** -A clear and concise description of what the bug is. + **To Reproduce** -Steps to reproduce the behavior: -1. Go to '...' -2. Click on '....' -3. Scroll down to '....' -4. See error + + + + + **Expected behavior** -A clear and concise description of what you expected to happen. + -**Screenshots** -If applicable, add screenshots to help explain your problem. +**Screenshots / Videos** + -**Server version** -run /version +**Server Version** + -**Geyser version** -Jenkins +**Geyser Version** + -**Bedrock version** -The version of your Minecraft pe +**Minecraft: Bedrock Edition Version** + -**Additional context** -Add any other context about the problem here. +**Additional Context** + From c809ddb6183a31dc30953fa914283263c0718e53 Mon Sep 17 00:00:00 2001 From: rtm516 Date: Sun, 5 Apr 2020 10:13:47 +0100 Subject: [PATCH 22/79] Renamed translation method and cleaned up variable declaration --- .../platform/bukkit/GeyserBukkitConfiguration.java | 4 +++- .../bungeecord/GeyserBungeeConfiguration.java | 4 +++- .../platform/sponge/GeyserSpongeConfiguration.java | 4 +++- .../network/translators/java/JavaChatTranslator.java | 2 +- .../org/geysermc/connector/utils/MessageUtils.java | 12 +++++------- .../java/org/geysermc/connector/utils/Toolbox.java | 4 ++-- 6 files changed, 17 insertions(+), 13 deletions(-) diff --git a/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitConfiguration.java b/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitConfiguration.java index a99ac1e50..1ddda6528 100644 --- a/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitConfiguration.java +++ b/bootstrap/bukkit/src/main/java/org/geysermc/platform/bukkit/GeyserBukkitConfiguration.java @@ -102,7 +102,9 @@ public class GeyserBukkitConfiguration implements IGeyserConfiguration { } @Override - public String getDefaultLocale() { return config.getString("default-locale", "en_us"); } + public String getDefaultLocale() { + return config.getString("default-locale", "en_us"); + } @Override public Path getFloodgateKeyFile() { diff --git a/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeeConfiguration.java b/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeeConfiguration.java index 17a6ae0cf..420f8347e 100644 --- a/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeeConfiguration.java +++ b/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeeConfiguration.java @@ -103,7 +103,9 @@ public class GeyserBungeeConfiguration implements IGeyserConfiguration { } @Override - public String getDefaultLocale() { return config.getString("default-locale", "en_us"); } + public String getDefaultLocale() { + return config.getString("default-locale", "en_us"); + } @Override public Path getFloodgateKeyFile() { diff --git a/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongeConfiguration.java b/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongeConfiguration.java index 18fb73081..7b6a89f15 100644 --- a/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongeConfiguration.java +++ b/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongeConfiguration.java @@ -106,7 +106,9 @@ public class GeyserSpongeConfiguration implements IGeyserConfiguration { } @Override - public String getDefaultLocale() { return node.getNode("default-locale").getString("en_us"); } + public String getDefaultLocale() { + return node.getNode("default-locale").getString("en_us"); + } @Override public Path getFloodgateKeyFile() { diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaChatTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaChatTranslator.java index 5db4a44ee..f58c61c9a 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaChatTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaChatTranslator.java @@ -62,7 +62,7 @@ public class JavaChatTranslator extends PacketTranslator { textPacket.setType(TextPacket.Type.TRANSLATION); textPacket.setNeedsTranslation(true); textPacket.setParameters(MessageUtils.getTranslationParams(((TranslationMessage) packet.getMessage()).getTranslationParams())); - textPacket.setMessage(MessageUtils.getBedrockMessageWithTranslate(packet.getMessage(), session.getClientData().getLanguageCode())); + textPacket.setMessage(MessageUtils.getTranslatedBedrockMessage(packet.getMessage(), session.getClientData().getLanguageCode())); } else { textPacket.setNeedsTranslation(false); textPacket.setMessage(MessageUtils.getBedrockMessage(packet.getMessage())); diff --git a/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java b/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java index 854b3c1a2..8b32f0000 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java @@ -25,7 +25,6 @@ package org.geysermc.connector.utils; -import com.fasterxml.jackson.databind.JsonNode; import com.github.steveice10.mc.protocol.data.game.scoreboard.TeamColor; import com.github.steveice10.mc.protocol.data.message.ChatColor; import com.github.steveice10.mc.protocol.data.message.ChatFormat; @@ -38,7 +37,6 @@ import com.google.gson.JsonParser; import com.google.gson.JsonPrimitive; import org.geysermc.connector.GeyserConnector; -import java.io.InputStream; import java.util.*; public class MessageUtils { @@ -77,7 +75,7 @@ public class MessageUtils { + "%" + message.getTranslationKey(); } - public static String getBedrockMessageWithTranslate(Message message, String locale) { + public static String getTranslatedBedrockMessage(Message message, String locale) { JsonParser parser = new JsonParser(); if (isMessage(message.getText())) { JsonObject object = parser.parse(message.getText()).getAsJsonObject(); @@ -100,12 +98,12 @@ public class MessageUtils { return builder.toString(); } - public static String getBedrockMessageWithTranslate(Message message) { - return getBedrockMessageWithTranslate(message, null); + public static String getTranslatedBedrockMessage(Message message) { + return getTranslatedBedrockMessage(message, null); } private static String getLocaleString(String messageText, String locale) { - HashMap localeStrings = Toolbox.LOCALE_MAPPINGS.get(locale.toLowerCase()); + Map localeStrings = Toolbox.LOCALE_MAPPINGS.get(locale.toLowerCase()); if (localeStrings == null) localeStrings = Toolbox.LOCALE_MAPPINGS.get(GeyserConnector.getInstance().getConfig().getDefaultLocale()); @@ -116,7 +114,7 @@ public class MessageUtils { } public static String getBedrockMessage(Message message) { - return getBedrockMessageWithTranslate(message); + return getTranslatedBedrockMessage(message); } private static String getColor(ChatColor color) { diff --git a/connector/src/main/java/org/geysermc/connector/utils/Toolbox.java b/connector/src/main/java/org/geysermc/connector/utils/Toolbox.java index 8ccd3aa3a..674a8bf7b 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/Toolbox.java +++ b/connector/src/main/java/org/geysermc/connector/utils/Toolbox.java @@ -52,7 +52,7 @@ public class Toolbox { public static final Int2ObjectMap ITEM_ENTRIES = new Int2ObjectOpenHashMap<>(); - public static final HashMap> LOCALE_MAPPINGS = new HashMap<>(); + public static final Map> LOCALE_MAPPINGS = new HashMap<>(); static { /* Load biomes */ @@ -127,7 +127,7 @@ public class Toolbox { } Iterator> localeIterator = locale.fields(); - HashMap langMap = new HashMap<>(); + Map langMap = new HashMap<>(); while (localeIterator.hasNext()) { Map.Entry entry = localeIterator.next(); langMap.put(entry.getKey(), entry.getValue().asText()); From 55b2fd02591317d763eb8aae3043993b21e24102 Mon Sep 17 00:00:00 2001 From: rtm516 Date: Sun, 5 Apr 2020 10:42:02 +0100 Subject: [PATCH 23/79] Kick the user on incorrect login info --- .../org/geysermc/connector/network/session/GeyserSession.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java index 7ce1f4c66..b398285b8 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java @@ -26,6 +26,7 @@ package org.geysermc.connector.network.session; import com.github.steveice10.mc.auth.data.GameProfile; +import com.github.steveice10.mc.auth.exception.request.InvalidCredentialsException; import com.github.steveice10.mc.auth.exception.request.RequestException; import com.github.steveice10.mc.protocol.MinecraftProtocol; import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode; @@ -281,6 +282,9 @@ public class GeyserSession implements CommandSender { downstream.getSession().connect(); connector.addPlayer(this); + } catch (InvalidCredentialsException e) { + connector.getLogger().info("User '" + username + "' entered invalid login info, kicking."); + disconnect("Invalid/incorrect login info"); } catch (RequestException ex) { ex.printStackTrace(); } From 18311e3c1cf6b682f9c08e0d04d7aa03ff52dfeb Mon Sep 17 00:00:00 2001 From: rtm516 Date: Sun, 5 Apr 2020 12:19:20 +0100 Subject: [PATCH 24/79] Added argument parsing to serverside language processing --- .../translators/java/JavaChatTranslator.java | 17 ++++++++-- .../connector/utils/MessageUtils.java | 31 ++++++++++++++++--- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaChatTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaChatTranslator.java index f58c61c9a..017e0178e 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaChatTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaChatTranslator.java @@ -34,6 +34,8 @@ import com.github.steveice10.mc.protocol.data.message.TranslationMessage; import com.github.steveice10.mc.protocol.packet.ingame.server.ServerChatPacket; import com.nukkitx.protocol.bedrock.packet.TextPacket; +import java.util.List; + @Translator(packet = ServerChatPacket.class) public class JavaChatTranslator extends PacketTranslator { @@ -61,10 +63,21 @@ public class JavaChatTranslator extends PacketTranslator { if (packet.getMessage() instanceof TranslationMessage) { textPacket.setType(TextPacket.Type.TRANSLATION); textPacket.setNeedsTranslation(true); - textPacket.setParameters(MessageUtils.getTranslationParams(((TranslationMessage) packet.getMessage()).getTranslationParams())); - textPacket.setMessage(MessageUtils.getTranslatedBedrockMessage(packet.getMessage(), session.getClientData().getLanguageCode())); + + String locale = session.getClientData().getLanguageCode(); + + List paramsTranslated = MessageUtils.getTranslationParams(((TranslationMessage) packet.getMessage()).getTranslationParams(), locale); + textPacket.setParameters(paramsTranslated); + + textPacket.setMessage(MessageUtils.insertParams(MessageUtils.getTranslatedBedrockMessage(packet.getMessage(), locale), paramsTranslated)); } else { textPacket.setNeedsTranslation(false); + + // This make every message get translated which fixes alot of formatting issues + // but also causes players to be able to send translation strings as messages + // if thats all they send + // textPacket.setMessage(MessageUtils.getTranslatedBedrockMessage(packet.getMessage(), session.getClientData().getLanguageCode())); + textPacket.setMessage(MessageUtils.getBedrockMessage(packet.getMessage())); } diff --git a/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java b/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java index 8b32f0000..48ac8ab7b 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java @@ -41,14 +41,16 @@ import java.util.*; public class MessageUtils { - public static List getTranslationParams(Message[] messages) { + public static List getTranslationParams(Message[] messages, String locale) { List strings = new ArrayList<>(); for (Message message : messages) { if (message instanceof TranslationMessage) { TranslationMessage translation = (TranslationMessage) message; - String builder = "%" + translation.getTranslationKey(); - strings.add(builder); + if (locale == null) { + String builder = "%" + translation.getTranslationKey(); + strings.add(builder); + } if (translation.getTranslationKey().equals("commands.gamemode.success.other")) { strings.add(""); @@ -58,7 +60,12 @@ public class MessageUtils { strings.add(" - no permission or invalid command!"); } - strings.addAll(getTranslationParams(translation.getTranslationParams())); + List furtherParams = getTranslationParams(translation.getTranslationParams()); + if (locale != null) { + strings.add(insertParams(getLocaleString(translation.getTranslationKey(), locale), furtherParams)); + }else{ + strings.addAll(furtherParams); + } } else { String builder = getFormat(message.getStyle().getFormats()) + getColor(message.getStyle().getColor()) + @@ -70,6 +77,10 @@ public class MessageUtils { return strings; } + public static List getTranslationParams(Message[] messages) { + return getTranslationParams(messages, null); + } + public static String getTranslationText(TranslationMessage message) { return getFormat(message.getStyle().getFormats()) + getColor(message.getStyle().getColor()) + "%" + message.getTranslationKey(); @@ -92,7 +103,7 @@ public class MessageUtils { builder.append(getFormat(msg.getStyle().getFormats())); builder.append(getColor(msg.getStyle().getColor())); if (!(msg.getText() == null)) { - builder.append(getBedrockMessage(msg)); + builder.append(getTranslatedBedrockMessage(msg, locale)); } } return builder.toString(); @@ -117,6 +128,16 @@ public class MessageUtils { return getTranslatedBedrockMessage(message); } + public static String insertParams(String message, List params) { + String newMessage = message; + + for (String text : params) { + newMessage = newMessage.replaceFirst("%s", text); + } + + return newMessage; + } + private static String getColor(ChatColor color) { String base = "\u00a7"; switch (color) { From 49df48fcf087106abb14708d34573af7764e24d5 Mon Sep 17 00:00:00 2001 From: rtm516 Date: Sun, 5 Apr 2020 22:47:03 +0100 Subject: [PATCH 25/79] Fixed some strings getting missed --- .../java/org/geysermc/connector/utils/MessageUtils.java | 8 ++++++-- connector/src/main/resources/mappings | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java b/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java index 48ac8ab7b..06ba81043 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java @@ -68,8 +68,12 @@ public class MessageUtils { } } else { String builder = getFormat(message.getStyle().getFormats()) + - getColor(message.getStyle().getColor()) + - getBedrockMessage(message); + getColor(message.getStyle().getColor()); + if (locale != null) { + builder += getTranslatedBedrockMessage(message, locale); + }else { + builder += getBedrockMessage(message); + } strings.add(builder); } } diff --git a/connector/src/main/resources/mappings b/connector/src/main/resources/mappings index 278c73449..c1745b639 160000 --- a/connector/src/main/resources/mappings +++ b/connector/src/main/resources/mappings @@ -1 +1 @@ -Subproject commit 278c73449aeeb4064c7513a68f98a49a5f463f0a +Subproject commit c1745b639500e8a9434c2239074acc36784f7c40 From 9a6b537e8919117467cf9af13571a8fb98baded5 Mon Sep 17 00:00:00 2001 From: rtm516 Date: Sun, 5 Apr 2020 22:49:10 +0100 Subject: [PATCH 26/79] Removed debugging line --- .../main/java/org/geysermc/connector/utils/MessageUtils.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java b/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java index 06ba81043..572c00fc7 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java @@ -122,10 +122,7 @@ public class MessageUtils { if (localeStrings == null) localeStrings = Toolbox.LOCALE_MAPPINGS.get(GeyserConnector.getInstance().getConfig().getDefaultLocale()); - String newLocaleString = localeStrings.getOrDefault(messageText, messageText); - - GeyserConnector.getInstance().getLogger().info("Converting '" + messageText + "' -> '" + newLocaleString + "'"); - return newLocaleString; + return localeStrings.getOrDefault(messageText, messageText); } public static String getBedrockMessage(Message message) { From 28217adfdfc9a6a77dffa220248c7320c6453d09 Mon Sep 17 00:00:00 2001 From: rtm516 Date: Sun, 5 Apr 2020 23:37:41 +0100 Subject: [PATCH 27/79] Added support for numbered param replacements --- .../org/geysermc/connector/utils/MessageUtils.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java b/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java index 572c00fc7..ef2a661da 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java @@ -38,6 +38,8 @@ import com.google.gson.JsonPrimitive; import org.geysermc.connector.GeyserConnector; import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; public class MessageUtils { @@ -132,6 +134,16 @@ public class MessageUtils { public static String insertParams(String message, List params) { String newMessage = message; + Pattern p = Pattern.compile("%([1-9])\\$s"); + Matcher m = p.matcher(message); + while (m.find()) { + try { + newMessage = newMessage.replaceFirst("%" + m.group(1) + "\\$s" , params.get(Integer.parseInt(m.group(1)) - 1)); + } catch (Exception e) { + // Couldnt find the param to replace + } + } + for (String text : params) { newMessage = newMessage.replaceFirst("%s", text); } From d4fa6514270fdc1c3e4198e982bdb8db9b0e5f5c Mon Sep 17 00:00:00 2001 From: rtm516 Date: Mon, 6 Apr 2020 14:33:36 +0100 Subject: [PATCH 28/79] Made the server kick all players before we shutdown and close the window when we finish on standalone. --- .../geysermc/connector/GeyserConnector.java | 38 +++++++++++++++++++ .../command/defaults/StopCommand.java | 5 +++ 2 files changed, 43 insertions(+) diff --git a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java index fb93a27de..5ed177b08 100644 --- a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java +++ b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java @@ -49,6 +49,7 @@ import java.net.InetSocketAddress; import java.text.DecimalFormat; import java.util.HashMap; import java.util.Map; +import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; @@ -141,6 +142,41 @@ public class GeyserConnector { bootstrap.getGeyserLogger().info("Shutting down Geyser."); shuttingDown = true; + if (players.size() >= 1) { + bootstrap.getGeyserLogger().info("Kicking " + players.size() + " players"); + + for (GeyserSession playerSession : players.values()) { + playerSession.disconnect("Geyser Proxy shutting down."); + } + + CompletableFuture future = CompletableFuture.runAsync(new Runnable() { + @Override + public void run() { + // Simulate a long-running Job + try { + while (true) { + bootstrap.getGeyserLogger().info("Current entries: " + players.size()); + if (players.size() == 0) { + return; + } + + TimeUnit.MILLISECONDS.sleep(100); + } + } catch (InterruptedException e) { + throw new IllegalStateException(e); + } + } + }); + + // Block and wait for the future to complete + try { + future.get(); + bootstrap.getGeyserLogger().info("Kicked all players"); + } catch (Exception e) { + // Quietly fail + } + } + generalThreadPool.shutdown(); bedrockServer.close(); players.clear(); @@ -148,6 +184,8 @@ public class GeyserConnector { authType = null; commandMap.getCommands().clear(); commandMap = null; + + bootstrap.getGeyserLogger().info("Geyser shutdown successfully."); } public void addPlayer(GeyserSession player) { diff --git a/connector/src/main/java/org/geysermc/connector/command/defaults/StopCommand.java b/connector/src/main/java/org/geysermc/connector/command/defaults/StopCommand.java index 4694d0fd0..2222cdef5 100644 --- a/connector/src/main/java/org/geysermc/connector/command/defaults/StopCommand.java +++ b/connector/src/main/java/org/geysermc/connector/command/defaults/StopCommand.java @@ -48,6 +48,11 @@ public class StopCommand extends GeyserCommand { if (!sender.isConsole() && connector.getPlatformType() == PlatformType.STANDALONE) { return; } + connector.shutdown(); + + if (connector.getPlatformType() == PlatformType.STANDALONE) { + System.exit(0); + } } } From c114f49e848fe446781e30a04ec9ee77e59a1b7e Mon Sep 17 00:00:00 2001 From: rtm516 Date: Mon, 6 Apr 2020 14:34:45 +0100 Subject: [PATCH 29/79] Fixed player count and removed debug code --- .../src/main/java/org/geysermc/connector/GeyserConnector.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java index 5ed177b08..90b107a5a 100644 --- a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java +++ b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java @@ -143,7 +143,7 @@ public class GeyserConnector { shuttingDown = true; if (players.size() >= 1) { - bootstrap.getGeyserLogger().info("Kicking " + players.size() + " players"); + bootstrap.getGeyserLogger().info("Kicking " + (players.size() / 3) + " players"); for (GeyserSession playerSession : players.values()) { playerSession.disconnect("Geyser Proxy shutting down."); @@ -155,7 +155,6 @@ public class GeyserConnector { // Simulate a long-running Job try { while (true) { - bootstrap.getGeyserLogger().info("Current entries: " + players.size()); if (players.size() == 0) { return; } From 41e0de44849e1d1ae6e696a5108a0aece6c8d484 Mon Sep 17 00:00:00 2001 From: rtm516 Date: Mon, 6 Apr 2020 14:35:18 +0100 Subject: [PATCH 30/79] Cleaned up language --- .../src/main/java/org/geysermc/connector/GeyserConnector.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java index 90b107a5a..3342fecd9 100644 --- a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java +++ b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java @@ -143,7 +143,7 @@ public class GeyserConnector { shuttingDown = true; if (players.size() >= 1) { - bootstrap.getGeyserLogger().info("Kicking " + (players.size() / 3) + " players"); + bootstrap.getGeyserLogger().info("Kicking " + (players.size() / 3) + " player(s)"); for (GeyserSession playerSession : players.values()) { playerSession.disconnect("Geyser Proxy shutting down."); From 90dc33e394938a1e72d091143a7202ec894a77eb Mon Sep 17 00:00:00 2001 From: rtm516 Date: Mon, 6 Apr 2020 14:47:07 +0100 Subject: [PATCH 31/79] Fixed support for ctrl+c shutdown --- .../org/geysermc/platform/standalone/console/GeyserLogger.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/console/GeyserLogger.java b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/console/GeyserLogger.java index 7df8a4efb..ac21215cb 100644 --- a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/console/GeyserLogger.java +++ b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/console/GeyserLogger.java @@ -52,7 +52,7 @@ public class GeyserLogger extends SimpleTerminalConsole implements IGeyserLogger @Override protected void shutdown() { - GeyserConnector.getInstance().shutdown(); + GeyserConnector.getInstance().getBootstrap().onDisable(); } @Override From 2d2b4704dcf70c9847b5011bbc1b3d3479cc6a7d Mon Sep 17 00:00:00 2001 From: DoctorMacc Date: Mon, 6 Apr 2020 20:57:26 -0400 Subject: [PATCH 32/79] Potential error spam fix --- .../translators/java/world/JavaMapDataTranslator.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaMapDataTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaMapDataTranslator.java index ccf3e2090..d38b881de 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaMapDataTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaMapDataTranslator.java @@ -40,7 +40,10 @@ public class JavaMapDataTranslator extends PacketTranslator ClientboundMapItemDataPacket mapItemDataPacket = new ClientboundMapItemDataPacket(); mapItemDataPacket.setUniqueMapId(packet.getMapId()); - mapItemDataPacket.setDimensionId(session.getLastDimPacket().getDimension()); + if (session.getLastDimPacket() == null) { + System.out.println("Dimension is null"); + mapItemDataPacket.setDimensionId(0); + } else mapItemDataPacket.setDimensionId(session.getLastDimPacket().getDimension()); mapItemDataPacket.setLocked(packet.isLocked()); mapItemDataPacket.setScale(packet.getScale()); From 9c282d2cb80bcfc4c772337d1a13aafebb6d600a Mon Sep 17 00:00:00 2001 From: DoctorMacc Date: Tue, 7 Apr 2020 13:54:08 -0400 Subject: [PATCH 33/79] Quick map fix --- .../translators/java/world/JavaMapDataTranslator.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaMapDataTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaMapDataTranslator.java index d38b881de..28022c16d 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaMapDataTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaMapDataTranslator.java @@ -40,10 +40,7 @@ public class JavaMapDataTranslator extends PacketTranslator ClientboundMapItemDataPacket mapItemDataPacket = new ClientboundMapItemDataPacket(); mapItemDataPacket.setUniqueMapId(packet.getMapId()); - if (session.getLastDimPacket() == null) { - System.out.println("Dimension is null"); - mapItemDataPacket.setDimensionId(0); - } else mapItemDataPacket.setDimensionId(session.getLastDimPacket().getDimension()); + mapItemDataPacket.setDimensionId(session.getPlayerEntity().getDimension()); mapItemDataPacket.setLocked(packet.isLocked()); mapItemDataPacket.setScale(packet.getScale()); From 8cab3cce2663a4ee66ec324ce6a8f0a1a6110f00 Mon Sep 17 00:00:00 2001 From: William Johnstone Date: Tue, 7 Apr 2020 20:45:59 +0100 Subject: [PATCH 34/79] Add falling blocks --- .../connector/entity/FallingBlockEntity.java | 17 ++++++++++++++ .../connector/entity/type/EntityType.java | 2 +- .../translators/block/BlockTranslator.java | 4 ++++ .../spawn/JavaSpawnObjectTranslator.java | 23 +++++++++++++++---- 4 files changed, 40 insertions(+), 6 deletions(-) create mode 100644 connector/src/main/java/org/geysermc/connector/entity/FallingBlockEntity.java diff --git a/connector/src/main/java/org/geysermc/connector/entity/FallingBlockEntity.java b/connector/src/main/java/org/geysermc/connector/entity/FallingBlockEntity.java new file mode 100644 index 000000000..5ce614a7a --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/entity/FallingBlockEntity.java @@ -0,0 +1,17 @@ +package org.geysermc.connector.entity; + +import com.nukkitx.math.vector.Vector3f; +import com.nukkitx.protocol.bedrock.data.EntityData; +import org.geysermc.connector.entity.type.EntityType; +import org.geysermc.connector.network.translators.block.BlockTranslator; + +public class FallingBlockEntity extends Entity { + + public FallingBlockEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation, int javaId) { + super(entityId, geyserId, entityType, position, motion, rotation); + + int bedrockId = BlockTranslator.getBedrockBlockId(javaId); + + this.metadata.put(EntityData.VARIANT, bedrockId); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java b/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java index f6af511cd..25ad52616 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java +++ b/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java @@ -103,7 +103,7 @@ public enum EntityType { PLAYER(PlayerEntity.class, 63, 1.8f, 0.6f, 0.6f, 1.62f), ITEM(ItemEntity.class, 64, 0.25f, 0.25f), TNT(Entity.class, 65, 0.98f, 0.98f), - FALLING_BLOCK(Entity.class, 66, 0.98f, 0.98f), + FALLING_BLOCK(FallingBlockEntity.class, 66, 0.98f, 0.98f), MOVING_BLOCK(Entity.class, 67, 0f), EXPERIENCE_BOTTLE(ThrowableEntity.class, 68, 0.25f, 0.25f), EXPERIENCE_ORB(ExpOrbEntity.class, 69, 0f), diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/block/BlockTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/block/BlockTranslator.java index c782e099a..98846e882 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/block/BlockTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/block/BlockTranslator.java @@ -177,6 +177,10 @@ public class BlockTranslator { return JAVA_TO_BEDROCK_BLOCK_MAP.get(state.getId()); } + public static int getBedrockBlockId(int javaId) { + return JAVA_TO_BEDROCK_BLOCK_MAP.get(javaId); + } + public static BlockState getJavaBlockState(int bedrockId) { return BEDROCK_TO_JAVA_BLOCK_MAP.get(bedrockId); } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnObjectTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnObjectTranslator.java index 15741c98e..827e24feb 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnObjectTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnObjectTranslator.java @@ -28,7 +28,9 @@ package org.geysermc.connector.network.translators.java.entity.spawn; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; +import com.github.steveice10.mc.protocol.data.game.entity.type.object.FallingBlockData; import org.geysermc.connector.entity.Entity; +import org.geysermc.connector.entity.FallingBlockEntity; import org.geysermc.connector.entity.type.EntityType; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; @@ -47,6 +49,11 @@ public class JavaSpawnObjectTranslator extends PacketTranslator entityClass = type.getEntityClass(); try { - Constructor entityConstructor = entityClass.getConstructor(long.class, long.class, EntityType.class, - Vector3f.class, Vector3f.class, Vector3f.class); + Entity entity; + if (packet.getType() == ObjectType.FALLING_BLOCK) { + entity = new FallingBlockEntity(packet.getEntityId(), session.getEntityCache().getNextEntityId().incrementAndGet(), + type, position, motion, rotation, javaId); + } else { + Constructor entityConstructor = entityClass.getConstructor(long.class, long.class, EntityType.class, + Vector3f.class, Vector3f.class, Vector3f.class); - Entity entity = entityConstructor.newInstance(packet.getEntityId(), session.getEntityCache().getNextEntityId().incrementAndGet(), - type, position, motion, rotation - ); + entity = entityConstructor.newInstance(packet.getEntityId(), session.getEntityCache().getNextEntityId().incrementAndGet(), + type, position, motion, rotation + ); + } session.getEntityCache().spawnEntity(entity); } catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException ex) { ex.printStackTrace(); From b8c1a1d0ba9a8115c7e6ab6391b5676df9811c7b Mon Sep 17 00:00:00 2001 From: DoctorMacc Date: Tue, 7 Apr 2020 16:12:55 -0400 Subject: [PATCH 35/79] Fix trader llamas not appearing; show llama variant --- .../living/animal/horse/LlamaEntity.java | 20 +++++++++++ .../animal/horse/TraderLlamaEntity.java | 36 +++++++++++++++++++ .../connector/entity/type/EntityType.java | 7 ++-- 3 files changed, 58 insertions(+), 5 deletions(-) create mode 100644 connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/TraderLlamaEntity.java diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/LlamaEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/LlamaEntity.java index dbf759f58..cdebd1fad 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/LlamaEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/LlamaEntity.java @@ -25,12 +25,32 @@ package org.geysermc.connector.entity.living.animal.horse; +import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; +import com.github.steveice10.mc.protocol.data.game.world.block.BlockState; import com.nukkitx.math.vector.Vector3f; +import com.nukkitx.protocol.bedrock.data.EntityData; +import com.nukkitx.protocol.bedrock.data.ItemData; +import com.nukkitx.protocol.bedrock.packet.MobArmorEquipmentPacket; import org.geysermc.connector.entity.type.EntityType; +import org.geysermc.connector.network.session.GeyserSession; +import org.geysermc.connector.network.translators.block.BlockTranslator; public class LlamaEntity extends ChestedHorseEntity { public LlamaEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) { super(entityId, geyserId, entityType, position, motion, rotation); } + + @Override + public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) { + // Strength + if (entityMetadata.getId() == 19) { + metadata.put(EntityData.STRENGTH, entityMetadata.getValue()); + } + // Color of the llama + else if (entityMetadata.getId() == 21) { + metadata.put(EntityData.VARIANT, entityMetadata.getValue()); + } + super.updateBedrockMetadata(entityMetadata, session); + } } diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/TraderLlamaEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/TraderLlamaEntity.java new file mode 100644 index 000000000..14e8f1bdd --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/TraderLlamaEntity.java @@ -0,0 +1,36 @@ +package org.geysermc.connector.entity.living.animal.horse; + +import com.nukkitx.math.vector.Vector3f; +import com.nukkitx.protocol.bedrock.data.EntityData; +import com.nukkitx.protocol.bedrock.packet.AddEntityPacket; +import org.geysermc.connector.entity.type.EntityType; +import org.geysermc.connector.network.session.GeyserSession; + +public class TraderLlamaEntity extends LlamaEntity { + + public TraderLlamaEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) { + super(entityId, geyserId, entityType, position, motion, rotation); + } + + @Override + public void spawnEntity(GeyserSession session) { + // The trader llama is a separate entity from the llama in Java but a normal llama with extra metadata in Bedrock. + AddEntityPacket addEntityPacket = new AddEntityPacket(); + addEntityPacket.setIdentifier("minecraft:llama"); + addEntityPacket.setRuntimeEntityId(geyserId); + addEntityPacket.setUniqueEntityId(geyserId); + addEntityPacket.setPosition(position); + addEntityPacket.setMotion(motion); + addEntityPacket.setRotation(getBedrockRotation()); + addEntityPacket.setEntityType(entityType.getType()); + addEntityPacket.getMetadata().putAll(metadata); + // Here's the difference + addEntityPacket.getMetadata().put(EntityData.MARK_VARIANT, 1); + + valid = true; + session.getUpstream().sendPacket(addEntityPacket); + + session.getConnector().getLogger().debug("Spawned entity " + entityType + " at location " + position + " with id " + geyserId + " (java id " + entityId + ")"); + } + +} diff --git a/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java b/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java index f6af511cd..baf6d59b6 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java +++ b/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java @@ -31,10 +31,7 @@ import org.geysermc.connector.entity.living.*; import org.geysermc.connector.entity.living.animal.*; import org.geysermc.connector.entity.living.animal.tameable.CatEntity; import org.geysermc.connector.entity.living.animal.tameable.TameableEntity; -import org.geysermc.connector.entity.living.animal.horse.AbstractHorseEntity; -import org.geysermc.connector.entity.living.animal.horse.ChestedHorseEntity; -import org.geysermc.connector.entity.living.animal.horse.HorseEntity; -import org.geysermc.connector.entity.living.animal.horse.LlamaEntity; +import org.geysermc.connector.entity.living.animal.horse.*; import org.geysermc.connector.entity.living.animal.tameable.WolfEntity; import org.geysermc.connector.entity.living.monster.*; import org.geysermc.connector.entity.living.monster.raid.AbstractIllagerEntity; @@ -64,7 +61,7 @@ public enum EntityType { ZOMBIE_HORSE(AbstractHorseEntity.class, 27, 1.6f, 1.3965f), POLAR_BEAR(PolarBearEntity.class, 28, 1.4f, 1.3f), LLAMA(LlamaEntity.class, 29, 1.87f, 0.9f), - TRADER_LLAMA(LlamaEntity.class, 29, 1.187f, 0.9f), + TRADER_LLAMA(TraderLlamaEntity.class, 29, 1.187f, 0.9f), PARROT(TameableEntity.class, 30, 0.9f, 0.5f), DOLPHIN(WaterEntity.class, 31, 0.6f, 0.9f), ZOMBIE(ZombieEntity.class, 32, 1.8f, 0.6f, 0.6f, 1.62f), From 588c89ded2e240321cd5227bfe5d326f54dd94d8 Mon Sep 17 00:00:00 2001 From: DoctorMacc Date: Tue, 7 Apr 2020 16:21:42 -0400 Subject: [PATCH 36/79] Fix requested changes --- .../living/animal/horse/LlamaEntity.java | 2 +- .../animal/horse/TraderLlamaEntity.java | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/LlamaEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/LlamaEntity.java index cdebd1fad..b4c958904 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/LlamaEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/LlamaEntity.java @@ -48,7 +48,7 @@ public class LlamaEntity extends ChestedHorseEntity { metadata.put(EntityData.STRENGTH, entityMetadata.getValue()); } // Color of the llama - else if (entityMetadata.getId() == 21) { + if (entityMetadata.getId() == 21) { metadata.put(EntityData.VARIANT, entityMetadata.getValue()); } super.updateBedrockMetadata(entityMetadata, session); diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/TraderLlamaEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/TraderLlamaEntity.java index 14e8f1bdd..5e591bc7c 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/TraderLlamaEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/TraderLlamaEntity.java @@ -1,3 +1,28 @@ +/* + * Copyright (c) 2019-2020 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.entity.living.animal.horse; import com.nukkitx.math.vector.Vector3f; From c44708cc220cc28bad14f11445e67926b17dd600 Mon Sep 17 00:00:00 2001 From: William Johnstone Date: Tue, 7 Apr 2020 21:22:10 +0100 Subject: [PATCH 37/79] Add requested changes --- .../connector/entity/FallingBlockEntity.java | 29 +++++++++++++++++-- .../spawn/JavaSpawnObjectTranslator.java | 7 +---- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/entity/FallingBlockEntity.java b/connector/src/main/java/org/geysermc/connector/entity/FallingBlockEntity.java index 5ce614a7a..5a0cac8f4 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/FallingBlockEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/FallingBlockEntity.java @@ -1,3 +1,28 @@ +/* + * Copyright (c) 2019-2020 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.entity; import com.nukkitx.math.vector.Vector3f; @@ -10,8 +35,6 @@ public class FallingBlockEntity extends Entity { public FallingBlockEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation, int javaId) { super(entityId, geyserId, entityType, position, motion, rotation); - int bedrockId = BlockTranslator.getBedrockBlockId(javaId); - - this.metadata.put(EntityData.VARIANT, bedrockId); + this.metadata.put(EntityData.VARIANT, BlockTranslator.getBedrockBlockId(javaId)); } } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnObjectTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnObjectTranslator.java index 827e24feb..c3998f870 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnObjectTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/spawn/JavaSpawnObjectTranslator.java @@ -49,11 +49,6 @@ public class JavaSpawnObjectTranslator extends PacketTranslator entityConstructor = entityClass.getConstructor(long.class, long.class, EntityType.class, Vector3f.class, Vector3f.class, Vector3f.class); From 03c611224bddecd0ce4201362d3fd30940e7c03b Mon Sep 17 00:00:00 2001 From: DoctorMacc Date: Tue, 7 Apr 2020 19:38:44 -0400 Subject: [PATCH 38/79] Add llama decoration support --- .../living/animal/horse/LlamaEntity.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/LlamaEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/LlamaEntity.java index b4c958904..e7e2f7825 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/LlamaEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/LlamaEntity.java @@ -47,6 +47,24 @@ public class LlamaEntity extends ChestedHorseEntity { if (entityMetadata.getId() == 19) { metadata.put(EntityData.STRENGTH, entityMetadata.getValue()); } + // Color equipped on the llama + if (entityMetadata.getId() == 20) { + // Bedrock treats llama decoration as armor + MobArmorEquipmentPacket equipmentPacket = new MobArmorEquipmentPacket(); + equipmentPacket.setRuntimeEntityId(getGeyserId()); + if ((int) entityMetadata.getValue() != -1) { + // The damage value is the dye color that Java sends us + // Always going to be a carpet so we can hardcode 171 + // The int then short conversion is required or we get a ClassCastException + equipmentPacket.setChestplate(ItemData.of(171, (short)((int) entityMetadata.getValue()), 1)); + } else equipmentPacket.setChestplate(ItemData.of(0, (short) 0, 0)); + // Required to fill out the rest of the equipment or Bedrock ignores it + equipmentPacket.setBoots(ItemData.of(0, (short) 0, 0)); + equipmentPacket.setHelmet(ItemData.of(0, (short) 0, 0)); + equipmentPacket.setLeggings(ItemData.of(0, (short) 0, 0)); + + session.getUpstream().sendPacket(equipmentPacket); + } // Color of the llama if (entityMetadata.getId() == 21) { metadata.put(EntityData.VARIANT, entityMetadata.getValue()); From bbf0baf948b27249307d652d0500cbe057256056 Mon Sep 17 00:00:00 2001 From: DoctorMacc Date: Tue, 7 Apr 2020 19:40:35 -0400 Subject: [PATCH 39/79] Additional explanation comment --- .../connector/entity/living/animal/horse/LlamaEntity.java | 1 + 1 file changed, 1 insertion(+) diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/LlamaEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/LlamaEntity.java index e7e2f7825..c6657602d 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/LlamaEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/LlamaEntity.java @@ -52,6 +52,7 @@ public class LlamaEntity extends ChestedHorseEntity { // Bedrock treats llama decoration as armor MobArmorEquipmentPacket equipmentPacket = new MobArmorEquipmentPacket(); equipmentPacket.setRuntimeEntityId(getGeyserId()); + // -1 means no armor if ((int) entityMetadata.getValue() != -1) { // The damage value is the dye color that Java sends us // Always going to be a carpet so we can hardcode 171 From ade40d5a8b34e848b9c71d16427317e429bc6f07 Mon Sep 17 00:00:00 2001 From: Redned Date: Tue, 7 Apr 2020 18:54:58 -0500 Subject: [PATCH 40/79] Only add the player to the players map once --- .../main/java/org/geysermc/connector/GeyserConnector.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java index fb93a27de..d33bda9a0 100644 --- a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java +++ b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java @@ -49,6 +49,7 @@ import java.net.InetSocketAddress; import java.text.DecimalFormat; import java.util.HashMap; import java.util.Map; +import java.util.UUID; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; @@ -61,7 +62,7 @@ public class GeyserConnector { public static final String NAME = "Geyser"; public static final String VERSION = "1.0-SNAPSHOT"; - private final Map players = new HashMap<>(); + private final Map players = new HashMap<>(); private static GeyserConnector instance; @@ -151,15 +152,11 @@ public class GeyserConnector { } public void addPlayer(GeyserSession player) { - players.put(player.getAuthData().getName(), player); players.put(player.getAuthData().getUUID(), player); - players.put(player.getSocketAddress(), player); } public void removePlayer(GeyserSession player) { - players.remove(player.getAuthData().getName()); players.remove(player.getAuthData().getUUID()); - players.remove(player.getSocketAddress()); } public static GeyserConnector start(PlatformType platformType, IGeyserBootstrap bootstrap) { From 20700998b1337aa69b2a617d033a6a52e66ab715 Mon Sep 17 00:00:00 2001 From: DoctorMacc Date: Tue, 7 Apr 2020 19:57:34 -0400 Subject: [PATCH 41/79] Fix requested changes; remove unused import --- .../entity/living/animal/horse/LlamaEntity.java | 13 +++++++------ .../network/translators/block/BlockTranslator.java | 3 +++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/LlamaEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/LlamaEntity.java index c6657602d..e20132c5e 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/LlamaEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/LlamaEntity.java @@ -26,7 +26,6 @@ package org.geysermc.connector.entity.living.animal.horse; import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; -import com.github.steveice10.mc.protocol.data.game.world.block.BlockState; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.data.EntityData; import com.nukkitx.protocol.bedrock.data.ItemData; @@ -57,12 +56,14 @@ public class LlamaEntity extends ChestedHorseEntity { // The damage value is the dye color that Java sends us // Always going to be a carpet so we can hardcode 171 // The int then short conversion is required or we get a ClassCastException - equipmentPacket.setChestplate(ItemData.of(171, (short)((int) entityMetadata.getValue()), 1)); - } else equipmentPacket.setChestplate(ItemData.of(0, (short) 0, 0)); + equipmentPacket.setChestplate(ItemData.of(BlockTranslator.LLAMA_ARMOR_ID, (short)((int) entityMetadata.getValue()), 1)); + } else { + equipmentPacket.setChestplate(ItemData.AIR); + } // Required to fill out the rest of the equipment or Bedrock ignores it - equipmentPacket.setBoots(ItemData.of(0, (short) 0, 0)); - equipmentPacket.setHelmet(ItemData.of(0, (short) 0, 0)); - equipmentPacket.setLeggings(ItemData.of(0, (short) 0, 0)); + equipmentPacket.setBoots(ItemData.AIR); + equipmentPacket.setHelmet(ItemData.AIR); + equipmentPacket.setLeggings(ItemData.AIR); session.getUpstream().sendPacket(equipmentPacket); } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/block/BlockTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/block/BlockTranslator.java index 98846e882..66d476702 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/block/BlockTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/block/BlockTranslator.java @@ -55,6 +55,9 @@ public class BlockTranslator { private static final Int2ObjectMap BEDROCK_TO_JAVA_BLOCK_MAP = new Int2ObjectOpenHashMap<>(); private static final IntSet WATERLOGGED = new IntOpenHashSet(); + // Carpet ID, used in LlamaEntity.java + public static final int LLAMA_ARMOR_ID = 171; + private static final int BLOCK_STATE_VERSION = 17760256; static { From 70975a1d3679a8ec19bc4cb343940889bfd57bb4 Mon Sep 17 00:00:00 2001 From: rtm516 Date: Wed, 8 Apr 2020 01:03:25 +0100 Subject: [PATCH 42/79] Updated player count for ade40d5 --- .../src/main/java/org/geysermc/connector/GeyserConnector.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java index 3342fecd9..7c518abc2 100644 --- a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java +++ b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java @@ -143,7 +143,7 @@ public class GeyserConnector { shuttingDown = true; if (players.size() >= 1) { - bootstrap.getGeyserLogger().info("Kicking " + (players.size() / 3) + " player(s)"); + bootstrap.getGeyserLogger().info("Kicking " + players.size() + " player(s)"); for (GeyserSession playerSession : players.values()) { playerSession.disconnect("Geyser Proxy shutting down."); From d4f23379ef3116c92c71bb1b59f0e9fe35c82cb3 Mon Sep 17 00:00:00 2001 From: DoctorMacc Date: Tue, 7 Apr 2020 20:06:20 -0400 Subject: [PATCH 43/79] Fix requested change; modify comments --- .../connector/entity/living/animal/horse/LlamaEntity.java | 6 +++--- .../network/translators/block/BlockTranslator.java | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/LlamaEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/LlamaEntity.java index e20132c5e..26c13a5ce 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/LlamaEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/horse/LlamaEntity.java @@ -54,13 +54,13 @@ public class LlamaEntity extends ChestedHorseEntity { // -1 means no armor if ((int) entityMetadata.getValue() != -1) { // The damage value is the dye color that Java sends us - // Always going to be a carpet so we can hardcode 171 + // Always going to be a carpet so we can hardcode 171 in BlockTranslator // The int then short conversion is required or we get a ClassCastException - equipmentPacket.setChestplate(ItemData.of(BlockTranslator.LLAMA_ARMOR_ID, (short)((int) entityMetadata.getValue()), 1)); + equipmentPacket.setChestplate(ItemData.of(BlockTranslator.CARPET, (short)((int) entityMetadata.getValue()), 1)); } else { equipmentPacket.setChestplate(ItemData.AIR); } - // Required to fill out the rest of the equipment or Bedrock ignores it + // Required to fill out the rest of the equipment or Bedrock ignores it, including above else statement if removing armor equipmentPacket.setBoots(ItemData.AIR); equipmentPacket.setHelmet(ItemData.AIR); equipmentPacket.setLeggings(ItemData.AIR); diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/block/BlockTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/block/BlockTranslator.java index 66d476702..906179d1f 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/block/BlockTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/block/BlockTranslator.java @@ -55,8 +55,8 @@ public class BlockTranslator { private static final Int2ObjectMap BEDROCK_TO_JAVA_BLOCK_MAP = new Int2ObjectOpenHashMap<>(); private static final IntSet WATERLOGGED = new IntOpenHashSet(); - // Carpet ID, used in LlamaEntity.java - public static final int LLAMA_ARMOR_ID = 171; + // Bedrock carpet ID, used in LlamaEntity.java for decoration + public static final int CARPET = 171; private static final int BLOCK_STATE_VERSION = 17760256; From 2cd5472ff0fe535509d2c2ddcd80b8627d004f42 Mon Sep 17 00:00:00 2001 From: rtm516 Date: Wed, 8 Apr 2020 21:11:56 +0100 Subject: [PATCH 44/79] Started work on the locale fetching and loading system --- .../geysermc/connector/utils/FileUtils.java | 19 ++ .../geysermc/connector/utils/LocaleUtils.java | 235 ++++++++++++++++++ .../connector/utils/MessageUtils.java | 12 +- .../org/geysermc/connector/utils/Toolbox.java | 31 +-- .../geysermc/connector/utils/WebUtils.java | 39 +++ connector/src/main/resources/mappings | 2 +- 6 files changed, 298 insertions(+), 40 deletions(-) create mode 100644 connector/src/main/java/org/geysermc/connector/utils/LocaleUtils.java create mode 100644 connector/src/main/java/org/geysermc/connector/utils/WebUtils.java diff --git a/connector/src/main/java/org/geysermc/connector/utils/FileUtils.java b/connector/src/main/java/org/geysermc/connector/utils/FileUtils.java index 3070e743d..0938fa7c0 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/FileUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/FileUtils.java @@ -65,4 +65,23 @@ public class FileUtils { return file; } + + public static void writeFile(File file, char[] data) throws IOException { + if (!file.exists()) { + file.createNewFile(); + } + + FileOutputStream fos = new FileOutputStream(file); + + for (char c : data) { + fos.write(c); + } + + fos.flush(); + fos.close(); + } + + public static void writeFile(String name, char[] data) throws IOException { + writeFile(new File(name), data); + } } diff --git a/connector/src/main/java/org/geysermc/connector/utils/LocaleUtils.java b/connector/src/main/java/org/geysermc/connector/utils/LocaleUtils.java new file mode 100644 index 000000000..55540ea39 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/utils/LocaleUtils.java @@ -0,0 +1,235 @@ +package org.geysermc.connector.utils; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.Getter; +import org.geysermc.connector.GeyserConnector; + +import java.io.*; +import java.time.OffsetDateTime; +import java.util.*; + +public class LocaleUtils { + + public static final Map> LOCALE_MAPPINGS = new HashMap<>(); + + static { + /* Load the language mappings */ + InputStream stream = Toolbox.getResource("mappings/locales.json"); + JsonNode locales; + try { + locales = Toolbox.JSON_MAPPER.readTree(stream); + } catch (Exception e) { + throw new AssertionError("Unable to load Java locale list", e); + } + + File localesFolder = new File("locales/"); + + if (!localesFolder.exists()) { + GeyserConnector.getInstance().getLogger().info("Locales not cached, downloading... (this may take some time depending on your internet connection)"); + ObjectMapper mapper = new ObjectMapper(); + try { + VersionManifest versionManifest = mapper.readValue(WebUtils.getBody("https://launchermeta.mojang.com/mc/game/version_manifest.json"), VersionManifest.class); + String latestInfoURL = ""; + for (Version version : versionManifest.getVersions()) { + if (version.getId().equals(versionManifest.getLatestVersion().getRelease())) { + latestInfoURL = version.getUrl(); + break; + } + } + + if (latestInfoURL.isEmpty()) { + throw new Exception("Unable to get latest Minecraft version"); + } + + VersionInfo versionInfo = mapper.readValue(WebUtils.getBody(latestInfoURL), VersionInfo.class); + JsonNode assets = mapper.readTree(WebUtils.getBody(versionInfo.getAssetIndex().getUrl())).get("objects"); + + localesFolder.mkdir(); + + for (JsonNode localeNode : locales.get("locales")) { + String currentLocale = localeNode.asText(); + + if (currentLocale.equals("en_us")) { continue; } + + GeyserConnector.getInstance().getLogger().info("Downloading locale: " + currentLocale); + Asset asset = mapper.treeToValue(assets.get("minecraft/lang/" + currentLocale + ".json"), Asset.class); + String hash = asset.getHash(); + FileUtils.writeFile("locales/" + currentLocale + ".json", WebUtils.getBody("http://resources.download.minecraft.net/" + hash.substring(0, 2) + "/" + hash).toCharArray()); + } + } catch (Exception e) { + GeyserConnector.getInstance().getLogger().info("Failed to load locales: " + (!e.getMessage().isEmpty() ? e.getMessage() : e.getStackTrace())); + } + } + + if (localesFolder.exists()) { + for (JsonNode localeNode : locales.get("locales")) { + String currentLocale = localeNode.asText(); + loadLocale(currentLocale); + } + } + } + + public static void downloadAndLoadLocale(String locale) { + downloadLocale(locale); + loadLocale(locale); + } + + private static void downloadLocale(String locale) { + + } + + private static void loadLocale(String locale) { + File localeFile = new File("locales/" + locale + ".json"); + + // Create the en_us locale + if (!localeFile.exists() && locale.equals("en_us")) { + try { + InputStreamReader isReader = new InputStreamReader(Toolbox.getResource("mappings/lang/en_us.json")); + BufferedReader reader = new BufferedReader(isReader); + StringBuffer sb = new StringBuffer(); + String str; + while((str = reader.readLine())!= null){ + sb.append(str); + } + + FileUtils.writeFile(localeFile, sb.toString().toCharArray()); + } catch (Exception e) { + throw new AssertionError("Unable to load en_us locale!", e); + } + } + + // Load the locale + if (localeFile.exists()) { + // Read the localefile + InputStream localeStream; + try { + localeStream = new FileInputStream(localeFile); + } catch (FileNotFoundException e) { + throw new AssertionError("Unable to load locale: " + locale + " (" + e.getMessage() + ")"); + } + + // Parse the file as json + JsonNode locale; + try { + locale = Toolbox.JSON_MAPPER.readTree(localeStream); + } catch (Exception e) { + throw new AssertionError("Unable to load Java lang map for " + locale, e); + } + + // Parse all the locale fields + Iterator> localeIterator = locale.fields(); + Map langMap = new HashMap<>(); + while (localeIterator.hasNext()) { + Map.Entry entry = localeIterator.next(); + langMap.put(entry.getKey(), entry.getValue().asText()); + } + + // Insert the locale into the mappings + LOCALE_MAPPINGS.put(locale.toLowerCase(), langMap); + } else { + GeyserConnector.getInstance().getLogger().warning("Missing locale file: " + locale); + } + } + + public static String getLocaleString(String messageText, String locale) { + Map localeStrings = LocaleUtils.LOCALE_MAPPINGS.get(locale.toLowerCase()); + if (localeStrings == null) + localeStrings = LocaleUtils.LOCALE_MAPPINGS.get(GeyserConnector.getInstance().getConfig().getDefaultLocale()); + + return localeStrings.getOrDefault(messageText, messageText); + } + + public static void init() { + // no-op + } +} + +@JsonIgnoreProperties(ignoreUnknown = true) +@Getter +class VersionManifest { + @JsonProperty("latest") + private LatestVersion latestVersion; + + @JsonProperty("versions") + private List versions; +} + +@JsonIgnoreProperties(ignoreUnknown = true) +@Getter +class LatestVersion { + @JsonProperty("release") + private String release; + + @JsonProperty("snapshot") + private String snapshot; +} + +@JsonIgnoreProperties(ignoreUnknown = true) +@Getter +class Version { + @JsonProperty("id") + private String id; + + @JsonProperty("type") + private String type; + + @JsonProperty("url") + private String url; + + @JsonProperty("time") + private String time; + + @JsonProperty("releaseTime") + private String releaseTime; +} + +@JsonIgnoreProperties(ignoreUnknown = true) +@Getter +class VersionInfo { + @JsonProperty("id") + private String id; + + @JsonProperty("type") + private String type; + + @JsonProperty("time") + private String time; + + @JsonProperty("releaseTime") + private String releaseTime; + + @JsonProperty("assetIndex") + private AssetIndex assetIndex; +} + +@JsonIgnoreProperties(ignoreUnknown = true) +@Getter +class AssetIndex { + @JsonProperty("id") + private String id; + + @JsonProperty("sha1") + private String sha1; + + @JsonProperty("size") + private int size; + + @JsonProperty("totalSize") + private int totalSize; + + @JsonProperty("url") + private String url; +} + +@JsonIgnoreProperties(ignoreUnknown = true) +@Getter +class Asset { + @JsonProperty("hash") + private String hash; + + @JsonProperty("size") + private int size; +} diff --git a/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java b/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java index ef2a661da..6e78321c6 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java @@ -64,7 +64,7 @@ public class MessageUtils { List furtherParams = getTranslationParams(translation.getTranslationParams()); if (locale != null) { - strings.add(insertParams(getLocaleString(translation.getTranslationKey(), locale), furtherParams)); + strings.add(insertParams(LocaleUtils.getLocaleString(translation.getTranslationKey(), locale), furtherParams)); }else{ strings.addAll(furtherParams); } @@ -101,7 +101,7 @@ public class MessageUtils { String messageText = message.getText(); if (locale != null) { - messageText = getLocaleString(messageText, locale); + messageText = LocaleUtils.getLocaleString(messageText, locale); } StringBuilder builder = new StringBuilder(messageText); @@ -119,14 +119,6 @@ public class MessageUtils { return getTranslatedBedrockMessage(message, null); } - private static String getLocaleString(String messageText, String locale) { - Map localeStrings = Toolbox.LOCALE_MAPPINGS.get(locale.toLowerCase()); - if (localeStrings == null) - localeStrings = Toolbox.LOCALE_MAPPINGS.get(GeyserConnector.getInstance().getConfig().getDefaultLocale()); - - return localeStrings.getOrDefault(messageText, messageText); - } - public static String getBedrockMessage(Message message) { return getTranslatedBedrockMessage(message); } diff --git a/connector/src/main/java/org/geysermc/connector/utils/Toolbox.java b/connector/src/main/java/org/geysermc/connector/utils/Toolbox.java index 674a8bf7b..9c1e10f6c 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/Toolbox.java +++ b/connector/src/main/java/org/geysermc/connector/utils/Toolbox.java @@ -106,35 +106,8 @@ public class Toolbox { itemIndex++; } - /* Load the language mappings */ - stream = Toolbox.getResource("mappings/locales.json"); - JsonNode locales; - try { - locales = Toolbox.JSON_MAPPER.readTree(stream); - } catch (Exception e) { - throw new AssertionError("Unable to load Java locale list", e); - } - - for (JsonNode localeNode : locales.get("locales")) { - String currentLocale = localeNode.asText(); - - InputStream localeStream = Toolbox.getResource("mappings/lang/" + currentLocale + ".json"); - JsonNode locale; - try { - locale = Toolbox.JSON_MAPPER.readTree(localeStream); - } catch (Exception e) { - throw new AssertionError("Unable to load Java lang map for " + currentLocale, e); - } - - Iterator> localeIterator = locale.fields(); - Map langMap = new HashMap<>(); - while (localeIterator.hasNext()) { - Map.Entry entry = localeIterator.next(); - langMap.put(entry.getKey(), entry.getValue().asText()); - } - - LOCALE_MAPPINGS.put(currentLocale.toLowerCase(), langMap); - } + // Load the locale data + LocaleUtils.init(); } public static InputStream getResource(String resource) { diff --git a/connector/src/main/java/org/geysermc/connector/utils/WebUtils.java b/connector/src/main/java/org/geysermc/connector/utils/WebUtils.java new file mode 100644 index 000000000..9a6556be9 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/utils/WebUtils.java @@ -0,0 +1,39 @@ +package org.geysermc.connector.utils; + +import org.geysermc.connector.GeyserConnector; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.URL; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; + +public class WebUtils { + + public static String getBody(String reqURL) { + URL url = null; + try { + url = new URL(reqURL); + HttpURLConnection con = (HttpURLConnection) url.openConnection(); + con.setRequestMethod("GET"); + + BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); + String inputLine; + StringBuffer content = new StringBuffer(); + + while ((inputLine = in.readLine()) != null) { + content.append(inputLine); + content.append("\n"); + } + + in.close(); + con.disconnect(); + + return content.toString(); + } catch (Exception e) { + return e.getMessage(); + } + } +} diff --git a/connector/src/main/resources/mappings b/connector/src/main/resources/mappings index c1745b639..1c45d021c 160000 --- a/connector/src/main/resources/mappings +++ b/connector/src/main/resources/mappings @@ -1 +1 @@ -Subproject commit c1745b639500e8a9434c2239074acc36784f7c40 +Subproject commit 1c45d021c69da23fdb68d1196365cad4f75b5d90 From c41740a9fa7c6f80cd826c4d8fbe90cefe2a4a96 Mon Sep 17 00:00:00 2001 From: DoctorMacc Date: Wed, 8 Apr 2020 17:58:07 -0400 Subject: [PATCH 45/79] Add entity flag for if bee has nectar --- .../org/geysermc/connector/entity/living/animal/BeeEntity.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/BeeEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/BeeEntity.java index db4858573..537a12511 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/BeeEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/BeeEntity.java @@ -42,6 +42,8 @@ public class BeeEntity extends AnimalEntity { if (entityMetadata.getId() == 16) { byte xd = (byte) entityMetadata.getValue(); metadata.getFlags().setFlag(EntityFlag.ANGRY, (xd & 0x02) == 0x02); + // If the bee has nectar or not + metadata.getFlags().setFlag(EntityFlag.POWERED, (xd & 0x08) == 0x08); } super.updateBedrockMetadata(entityMetadata, session); } From c61d87714be5fad45f71dacd60b5d3d5fe378cb7 Mon Sep 17 00:00:00 2001 From: rtm516 Date: Thu, 9 Apr 2020 00:20:41 +0100 Subject: [PATCH 46/79] On demand downloading and loading of language files --- .../network/session/GeyserSession.java | 4 + .../geysermc/connector/utils/LocaleUtils.java | 142 +++++++++++------- .../geysermc/connector/utils/WebUtils.java | 25 +++ 3 files changed, 116 insertions(+), 55 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java index 7ce1f4c66..7b133e489 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java @@ -64,6 +64,7 @@ import org.geysermc.connector.network.session.cache.*; import org.geysermc.connector.network.translators.Registry; import org.geysermc.connector.network.translators.block.BlockTranslator; import org.geysermc.connector.utils.ChunkUtils; +import org.geysermc.connector.utils.LocaleUtils; import org.geysermc.connector.utils.Toolbox; import org.geysermc.floodgate.util.BedrockData; import org.geysermc.floodgate.util.EncryptionUtil; @@ -251,6 +252,9 @@ public class GeyserSession implements CommandSender { connector.getLogger().info(authData.getName() + " (logged in as: " + protocol.getProfile().getName() + ")" + " has connected to remote java server on address " + remoteServer.getAddress()); playerEntity.setUuid(protocol.getProfile().getId()); playerEntity.setUsername(protocol.getProfile().getName()); + + // Download and load the language for the player + LocaleUtils.downloadAndLoadLocale(clientData.getLanguageCode()); } @Override diff --git a/connector/src/main/java/org/geysermc/connector/utils/LocaleUtils.java b/connector/src/main/java/org/geysermc/connector/utils/LocaleUtils.java index 55540ea39..c057d4f7d 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/LocaleUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/LocaleUtils.java @@ -1,3 +1,28 @@ +/* + * Copyright (c) 2019-2020 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.utils; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @@ -15,77 +40,70 @@ public class LocaleUtils { public static final Map> LOCALE_MAPPINGS = new HashMap<>(); + private static final Map ASSET_MAP = new HashMap<>(); + static { - /* Load the language mappings */ - InputStream stream = Toolbox.getResource("mappings/locales.json"); - JsonNode locales; - try { - locales = Toolbox.JSON_MAPPER.readTree(stream); - } catch (Exception e) { - throw new AssertionError("Unable to load Java locale list", e); - } - + // Create the locales folder File localesFolder = new File("locales/"); + localesFolder.mkdir(); - if (!localesFolder.exists()) { - GeyserConnector.getInstance().getLogger().info("Locales not cached, downloading... (this may take some time depending on your internet connection)"); - ObjectMapper mapper = new ObjectMapper(); - try { - VersionManifest versionManifest = mapper.readValue(WebUtils.getBody("https://launchermeta.mojang.com/mc/game/version_manifest.json"), VersionManifest.class); - String latestInfoURL = ""; - for (Version version : versionManifest.getVersions()) { - if (version.getId().equals(versionManifest.getLatestVersion().getRelease())) { - latestInfoURL = version.getUrl(); - break; - } + // Download the latest asset list and cache it + generateAssetCache(); + downloadAndLoadLocale(GeyserConnector.getInstance().getConfig().getDefaultLocale()); + } + + private static void generateAssetCache() { + try { + VersionManifest versionManifest = Toolbox.JSON_MAPPER.readValue(WebUtils.getBody("https://launchermeta.mojang.com/mc/game/version_manifest.json"), VersionManifest.class); + String latestInfoURL = ""; + for (Version version : versionManifest.getVersions()) { + if (version.getId().equals(versionManifest.getLatestVersion().getRelease())) { + latestInfoURL = version.getUrl(); + break; } - - if (latestInfoURL.isEmpty()) { - throw new Exception("Unable to get latest Minecraft version"); - } - - VersionInfo versionInfo = mapper.readValue(WebUtils.getBody(latestInfoURL), VersionInfo.class); - JsonNode assets = mapper.readTree(WebUtils.getBody(versionInfo.getAssetIndex().getUrl())).get("objects"); - - localesFolder.mkdir(); - - for (JsonNode localeNode : locales.get("locales")) { - String currentLocale = localeNode.asText(); - - if (currentLocale.equals("en_us")) { continue; } - - GeyserConnector.getInstance().getLogger().info("Downloading locale: " + currentLocale); - Asset asset = mapper.treeToValue(assets.get("minecraft/lang/" + currentLocale + ".json"), Asset.class); - String hash = asset.getHash(); - FileUtils.writeFile("locales/" + currentLocale + ".json", WebUtils.getBody("http://resources.download.minecraft.net/" + hash.substring(0, 2) + "/" + hash).toCharArray()); - } - } catch (Exception e) { - GeyserConnector.getInstance().getLogger().info("Failed to load locales: " + (!e.getMessage().isEmpty() ? e.getMessage() : e.getStackTrace())); } - } - if (localesFolder.exists()) { - for (JsonNode localeNode : locales.get("locales")) { - String currentLocale = localeNode.asText(); - loadLocale(currentLocale); + if (latestInfoURL.isEmpty()) { + throw new Exception("Unable to get latest Minecraft version"); } + + VersionInfo versionInfo = Toolbox.JSON_MAPPER.readValue(WebUtils.getBody(latestInfoURL), VersionInfo.class); + JsonNode assets = Toolbox.JSON_MAPPER.readTree(WebUtils.getBody(versionInfo.getAssetIndex().getUrl())).get("objects"); + + Iterator> assetIterator = assets.fields(); + while (assetIterator.hasNext()) { + Map.Entry entry = assetIterator.next(); + Asset asset = Toolbox.JSON_MAPPER.treeToValue(entry.getValue(), Asset.class); + ASSET_MAP.put(entry.getKey(), asset); + } + } catch (Exception e) { + GeyserConnector.getInstance().getLogger().info("Failed to load locale asset cache: " + (!e.getMessage().isEmpty() ? e.getMessage() : e.getStackTrace())); } } public static void downloadAndLoadLocale(String locale) { + locale = locale.toLowerCase(); + if (!ASSET_MAP.containsKey("minecraft/lang/" + locale + ".json") && !locale.equals("en_us")) { + GeyserConnector.getInstance().getLogger().warning("Invalid locale requested to download and load: " + locale); + return; + } + + GeyserConnector.getInstance().getLogger().debug("Downloading and loading locale: " + locale); + downloadLocale(locale); loadLocale(locale); } private static void downloadLocale(String locale) { - - } - - private static void loadLocale(String locale) { File localeFile = new File("locales/" + locale + ".json"); + if (localeFile.exists()) { + GeyserConnector.getInstance().getLogger().debug("Locale already downloaded: " + locale); + return; + } + // Create the en_us locale - if (!localeFile.exists() && locale.equals("en_us")) { + if (locale.equals("en_us")) { try { InputStreamReader isReader = new InputStreamReader(Toolbox.getResource("mappings/lang/en_us.json")); BufferedReader reader = new BufferedReader(isReader); @@ -99,8 +117,22 @@ public class LocaleUtils { } catch (Exception e) { throw new AssertionError("Unable to load en_us locale!", e); } + + return; } + String hash = ASSET_MAP.get("minecraft/lang/" + locale + ".json").getHash(); + + try { + FileUtils.writeFile("locales/" + locale + ".json", WebUtils.getBody("http://resources.download.minecraft.net/" + hash.substring(0, 2) + "/" + hash).toCharArray()); + } catch (Exception e) { + GeyserConnector.getInstance().getLogger().warning("Failed to download locale " + locale + ": " + (!e.getMessage().isEmpty() ? e.getMessage() : e.getStackTrace())); + } + } + + private static void loadLocale(String locale) { + File localeFile = new File("locales/" + locale + ".json"); + // Load the locale if (localeFile.exists()) { // Read the localefile @@ -112,15 +144,15 @@ public class LocaleUtils { } // Parse the file as json - JsonNode locale; + JsonNode localeObj; try { - locale = Toolbox.JSON_MAPPER.readTree(localeStream); + localeObj = Toolbox.JSON_MAPPER.readTree(localeStream); } catch (Exception e) { throw new AssertionError("Unable to load Java lang map for " + locale, e); } // Parse all the locale fields - Iterator> localeIterator = locale.fields(); + Iterator> localeIterator = localeObj.fields(); Map langMap = new HashMap<>(); while (localeIterator.hasNext()) { Map.Entry entry = localeIterator.next(); diff --git a/connector/src/main/java/org/geysermc/connector/utils/WebUtils.java b/connector/src/main/java/org/geysermc/connector/utils/WebUtils.java index 9a6556be9..17029fd94 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/WebUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/WebUtils.java @@ -1,3 +1,28 @@ +/* + * Copyright (c) 2019-2020 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.utils; import org.geysermc.connector.GeyserConnector; From 70a71b2ee8f9d8868565b4213e2bdb0ac9b833dc Mon Sep 17 00:00:00 2001 From: rtm516 Date: Thu, 9 Apr 2020 00:23:21 +0100 Subject: [PATCH 47/79] Updated mappings commit --- connector/src/main/resources/mappings | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connector/src/main/resources/mappings b/connector/src/main/resources/mappings index 1c45d021c..c25f11c56 160000 --- a/connector/src/main/resources/mappings +++ b/connector/src/main/resources/mappings @@ -1 +1 @@ -Subproject commit 1c45d021c69da23fdb68d1196365cad4f75b5d90 +Subproject commit c25f11c5653b1db06594218d7a1a31a3bfd68c6c From bc67675d160787e9f1cdfcdcd7cde6123ced57a4 Mon Sep 17 00:00:00 2001 From: rtm516 Date: Thu, 9 Apr 2020 01:30:27 +0100 Subject: [PATCH 48/79] Added translation of extra message parts --- .../translators/java/JavaChatTranslator.java | 13 ++++--------- .../geysermc/connector/utils/LocaleUtils.java | 6 ++++-- .../connector/utils/MessageUtils.java | 19 ++++++------------- 3 files changed, 14 insertions(+), 24 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaChatTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaChatTranslator.java index 017e0178e..ae58830c9 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaChatTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaChatTranslator.java @@ -60,25 +60,20 @@ public class JavaChatTranslator extends PacketTranslator { break; } + String locale = session.getClientData().getLanguageCode(); + if (packet.getMessage() instanceof TranslationMessage) { textPacket.setType(TextPacket.Type.TRANSLATION); textPacket.setNeedsTranslation(true); - String locale = session.getClientData().getLanguageCode(); - List paramsTranslated = MessageUtils.getTranslationParams(((TranslationMessage) packet.getMessage()).getTranslationParams(), locale); textPacket.setParameters(paramsTranslated); - textPacket.setMessage(MessageUtils.insertParams(MessageUtils.getTranslatedBedrockMessage(packet.getMessage(), locale), paramsTranslated)); + textPacket.setMessage(MessageUtils.insertParams(MessageUtils.getTranslatedBedrockMessage(packet.getMessage(), locale, false), paramsTranslated)); } else { textPacket.setNeedsTranslation(false); - // This make every message get translated which fixes alot of formatting issues - // but also causes players to be able to send translation strings as messages - // if thats all they send - // textPacket.setMessage(MessageUtils.getTranslatedBedrockMessage(packet.getMessage(), session.getClientData().getLanguageCode())); - - textPacket.setMessage(MessageUtils.getBedrockMessage(packet.getMessage())); + textPacket.setMessage(MessageUtils.getTranslatedBedrockMessage(packet.getMessage(), locale, false)); } session.getUpstream().sendPacket(textPacket); diff --git a/connector/src/main/java/org/geysermc/connector/utils/LocaleUtils.java b/connector/src/main/java/org/geysermc/connector/utils/LocaleUtils.java index c057d4f7d..3c6ca19bc 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/LocaleUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/LocaleUtils.java @@ -42,6 +42,8 @@ public class LocaleUtils { private static final Map ASSET_MAP = new HashMap<>(); + private static final String DEFAULT_LOCALE = (GeyserConnector.getInstance().getConfig().getDefaultLocale() != null ? GeyserConnector.getInstance().getConfig().getDefaultLocale() : "en_us"); + static { // Create the locales folder File localesFolder = new File("locales/"); @@ -49,7 +51,7 @@ public class LocaleUtils { // Download the latest asset list and cache it generateAssetCache(); - downloadAndLoadLocale(GeyserConnector.getInstance().getConfig().getDefaultLocale()); + downloadAndLoadLocale(DEFAULT_LOCALE); } private static void generateAssetCache() { @@ -169,7 +171,7 @@ public class LocaleUtils { public static String getLocaleString(String messageText, String locale) { Map localeStrings = LocaleUtils.LOCALE_MAPPINGS.get(locale.toLowerCase()); if (localeStrings == null) - localeStrings = LocaleUtils.LOCALE_MAPPINGS.get(GeyserConnector.getInstance().getConfig().getDefaultLocale()); + localeStrings = LocaleUtils.LOCALE_MAPPINGS.get(DEFAULT_LOCALE); return localeStrings.getOrDefault(messageText, messageText); } diff --git a/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java b/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java index 6e78321c6..76563dd6d 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java @@ -71,11 +71,7 @@ public class MessageUtils { } else { String builder = getFormat(message.getStyle().getFormats()) + getColor(message.getStyle().getColor()); - if (locale != null) { - builder += getTranslatedBedrockMessage(message, locale); - }else { - builder += getBedrockMessage(message); - } + builder += getTranslatedBedrockMessage(message, locale, false); strings.add(builder); } } @@ -92,7 +88,7 @@ public class MessageUtils { + "%" + message.getTranslationKey(); } - public static String getTranslatedBedrockMessage(Message message, String locale) { + public static String getTranslatedBedrockMessage(Message message, String locale, boolean shouldTranslate) { JsonParser parser = new JsonParser(); if (isMessage(message.getText())) { JsonObject object = parser.parse(message.getText()).getAsJsonObject(); @@ -100,7 +96,7 @@ public class MessageUtils { } String messageText = message.getText(); - if (locale != null) { + if (locale != null && shouldTranslate) { messageText = LocaleUtils.getLocaleString(messageText, locale); } @@ -109,18 +105,15 @@ public class MessageUtils { builder.append(getFormat(msg.getStyle().getFormats())); builder.append(getColor(msg.getStyle().getColor())); if (!(msg.getText() == null)) { - builder.append(getTranslatedBedrockMessage(msg, locale)); + boolean isTranslationMessage = (msg instanceof TranslationMessage); + builder.append(getTranslatedBedrockMessage(msg, locale, isTranslationMessage)); } } return builder.toString(); } - public static String getTranslatedBedrockMessage(Message message) { - return getTranslatedBedrockMessage(message, null); - } - public static String getBedrockMessage(Message message) { - return getTranslatedBedrockMessage(message); + return getTranslatedBedrockMessage(message, null, false); } public static String insertParams(String message, List params) { From c393dc9f2160c5696ad25af68f96740ccdb29091 Mon Sep 17 00:00:00 2001 From: DoctorMacc Date: Wed, 8 Apr 2020 21:29:33 -0400 Subject: [PATCH 49/79] Initial bow support --- .../BedrockInventoryTransactionTranslator.java | 18 +++++++++++++----- .../translators/block/BlockTranslator.java | 3 +++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInventoryTransactionTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInventoryTransactionTranslator.java index de23b8a05..3df0f6272 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInventoryTransactionTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInventoryTransactionTranslator.java @@ -41,6 +41,7 @@ import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlaye import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerUseItemPacket; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.packet.InventoryTransactionPacket; +import org.geysermc.connector.network.translators.block.BlockTranslator; @Translator(packet = InventoryTransactionPacket.class) public class BedrockInventoryTransactionTranslator extends PacketTranslator { @@ -61,11 +62,18 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator BEDROCK_TO_JAVA_BLOCK_MAP = new Int2ObjectOpenHashMap<>(); private static final IntSet WATERLOGGED = new IntOpenHashSet(); + // Bedrock bow ID, used in BedrockInventoryTransactionTranslator.java for bow support + public static final int BOW = 261; + // Bedrock carpet ID, used in LlamaEntity.java for decoration public static final int CARPET = 171; From 0521a30266df68c7cd3d798403c192cabb4faba6 Mon Sep 17 00:00:00 2001 From: DoctorMacc Date: Wed, 8 Apr 2020 22:17:29 -0400 Subject: [PATCH 50/79] Simplify --- .../BedrockInventoryTransactionTranslator.java | 13 ++----------- .../network/translators/block/BlockTranslator.java | 3 --- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInventoryTransactionTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInventoryTransactionTranslator.java index 3df0f6272..c9547514d 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInventoryTransactionTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockInventoryTransactionTranslator.java @@ -62,18 +62,9 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator BEDROCK_TO_JAVA_BLOCK_MAP = new Int2ObjectOpenHashMap<>(); private static final IntSet WATERLOGGED = new IntOpenHashSet(); - // Bedrock bow ID, used in BedrockInventoryTransactionTranslator.java for bow support - public static final int BOW = 261; - // Bedrock carpet ID, used in LlamaEntity.java for decoration public static final int CARPET = 171; From 1ef50cbb95f00dd315444c845425b032af1da134 Mon Sep 17 00:00:00 2001 From: rtm516 Date: Thu, 9 Apr 2020 14:36:32 +0100 Subject: [PATCH 51/79] Added automatic en_us download and extraction from JAR --- .../geysermc/connector/utils/LocaleUtils.java | 92 +++++++++++++++---- .../geysermc/connector/utils/WebUtils.java | 13 +++ connector/src/main/resources/mappings | 2 +- 3 files changed, 87 insertions(+), 20 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/utils/LocaleUtils.java b/connector/src/main/java/org/geysermc/connector/utils/LocaleUtils.java index 3c6ca19bc..d19c4672e 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/LocaleUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/LocaleUtils.java @@ -33,8 +33,13 @@ import lombok.Getter; import org.geysermc.connector.GeyserConnector; import java.io.*; +import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; import java.time.OffsetDateTime; import java.util.*; +import java.util.zip.ZipFile; public class LocaleUtils { @@ -44,6 +49,8 @@ public class LocaleUtils { private static final String DEFAULT_LOCALE = (GeyserConnector.getInstance().getConfig().getDefaultLocale() != null ? GeyserConnector.getInstance().getConfig().getDefaultLocale() : "en_us"); + private static String smallestURL = ""; + static { // Create the locales folder File localesFolder = new File("locales/"); @@ -51,6 +58,9 @@ public class LocaleUtils { // Download the latest asset list and cache it generateAssetCache(); + if (!DEFAULT_LOCALE.equals("en_us")) { + downloadAndLoadLocale("en_us"); + } downloadAndLoadLocale(DEFAULT_LOCALE); } @@ -70,6 +80,15 @@ public class LocaleUtils { } VersionInfo versionInfo = Toolbox.JSON_MAPPER.readValue(WebUtils.getBody(latestInfoURL), VersionInfo.class); + + int currentSize = Integer.MAX_VALUE; + for (VersionDownload download : versionInfo.getDownloads().values()) { + if (download.getUrl().endsWith(".jar") && download.getSize() < currentSize) { + smallestURL = download.getUrl(); + currentSize = download.getSize(); + } + } + JsonNode assets = Toolbox.JSON_MAPPER.readTree(WebUtils.getBody(versionInfo.getAssetIndex().getUrl())).get("objects"); Iterator> assetIterator = assets.fields(); @@ -106,30 +125,14 @@ public class LocaleUtils { // Create the en_us locale if (locale.equals("en_us")) { - try { - InputStreamReader isReader = new InputStreamReader(Toolbox.getResource("mappings/lang/en_us.json")); - BufferedReader reader = new BufferedReader(isReader); - StringBuffer sb = new StringBuffer(); - String str; - while((str = reader.readLine())!= null){ - sb.append(str); - } - - FileUtils.writeFile(localeFile, sb.toString().toCharArray()); - } catch (Exception e) { - throw new AssertionError("Unable to load en_us locale!", e); - } + downloadEN_US(localeFile); return; } + // Get the hash and download the locale String hash = ASSET_MAP.get("minecraft/lang/" + locale + ".json").getHash(); - - try { - FileUtils.writeFile("locales/" + locale + ".json", WebUtils.getBody("http://resources.download.minecraft.net/" + hash.substring(0, 2) + "/" + hash).toCharArray()); - } catch (Exception e) { - GeyserConnector.getInstance().getLogger().warning("Failed to download locale " + locale + ": " + (!e.getMessage().isEmpty() ? e.getMessage() : e.getStackTrace())); - } + WebUtils.downloadFile("http://resources.download.minecraft.net/" + hash.substring(0, 2) + "/" + hash, "locales/" + locale + ".json"); } private static void loadLocale(String locale) { @@ -168,6 +171,41 @@ public class LocaleUtils { } } + private static void downloadEN_US(File localeFile) { + try { + // Let the user know we are downloading the JAR + GeyserConnector.getInstance().getLogger().info("Downloading Minecraft JAR to extract en_us locale, please wait... (this may take some time depending on the speed of your internet connection)"); + GeyserConnector.getInstance().getLogger().debug("Download URL: " + smallestURL); + + // Download the smallest JAR (client or server) + WebUtils.downloadFile(smallestURL, "tmp_locale.jar"); + + // Load in the JAR as a zip and extract the file + ZipFile localeJar = new ZipFile("tmp_locale.jar"); + InputStream inputStream = localeJar.getInputStream(localeJar.getEntry("assets/minecraft/lang/en_us.json")); + FileOutputStream outputStream = new FileOutputStream(localeFile); + + // Write the file to the locale dir + int data = inputStream.read(); + while(data != -1){ + outputStream.write(data); + data = inputStream.read(); + } + + // Flush all changes to disk and cleanup + outputStream.flush(); + outputStream.close(); + + inputStream.close(); + localeJar.close(); + + // Delete the nolonger needed client/server jar + Files.delete(Paths.get("tmp_locale.jar")); + } catch (Exception e) { + throw new AssertionError("Unable to download and extract en_us locale!", e); + } + } + public static String getLocaleString(String messageText, String locale) { Map localeStrings = LocaleUtils.LOCALE_MAPPINGS.get(locale.toLowerCase()); if (localeStrings == null) @@ -237,6 +275,22 @@ class VersionInfo { @JsonProperty("assetIndex") private AssetIndex assetIndex; + + @JsonProperty("downloads") + private Map downloads; +} + +@JsonIgnoreProperties(ignoreUnknown = true) +@Getter +class VersionDownload { + @JsonProperty("sha1") + private String sha1; + + @JsonProperty("size") + private int size; + + @JsonProperty("url") + private String url; } @JsonIgnoreProperties(ignoreUnknown = true) diff --git a/connector/src/main/java/org/geysermc/connector/utils/WebUtils.java b/connector/src/main/java/org/geysermc/connector/utils/WebUtils.java index 17029fd94..a155f0b95 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/WebUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/WebUtils.java @@ -28,12 +28,16 @@ package org.geysermc.connector.utils; import org.geysermc.connector.GeyserConnector; import java.io.BufferedReader; +import java.io.InputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; public class WebUtils { @@ -61,4 +65,13 @@ public class WebUtils { return e.getMessage(); } } + + public static void downloadFile(String reqURL, String fileLocation) { + try { + InputStream in = new URL(reqURL).openStream(); + Files.copy(in, Paths.get(fileLocation), StandardCopyOption.REPLACE_EXISTING); + } catch (Exception e) { + throw new AssertionError("Unable to download and save file: " + fileLocation + " (" + reqURL + ")", e); + } + } } diff --git a/connector/src/main/resources/mappings b/connector/src/main/resources/mappings index c25f11c56..efc9db6b7 160000 --- a/connector/src/main/resources/mappings +++ b/connector/src/main/resources/mappings @@ -1 +1 @@ -Subproject commit c25f11c5653b1db06594218d7a1a31a3bfd68c6c +Subproject commit efc9db6b7d51bdf145230933ac23b321ac1c132d From b43a3e9abdfb34f35f878269af02165c9add88fe Mon Sep 17 00:00:00 2001 From: rtm516 Date: Thu, 9 Apr 2020 15:26:14 +0100 Subject: [PATCH 52/79] Fixed players not getting removed from the players map on disconnect --- .../main/java/org/geysermc/connector/GeyserConnector.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java index 714bd5aed..35f9085d0 100644 --- a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java +++ b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java @@ -63,7 +63,7 @@ public class GeyserConnector { public static final String NAME = "Geyser"; public static final String VERSION = "1.0-SNAPSHOT"; - private final Map players = new HashMap<>(); + private final Map players = new HashMap<>(); private static GeyserConnector instance; @@ -189,11 +189,11 @@ public class GeyserConnector { } public void addPlayer(GeyserSession player) { - players.put(player.getAuthData().getUUID(), player); + players.put(player.getSocketAddress(), player); } public void removePlayer(GeyserSession player) { - players.remove(player.getAuthData().getUUID()); + players.remove(player.getSocketAddress()); } public static GeyserConnector start(PlatformType platformType, IGeyserBootstrap bootstrap) { From 7465a980981039d80a587994426bd6d35ba3c204 Mon Sep 17 00:00:00 2001 From: rtm516 Date: Thu, 9 Apr 2020 16:46:59 +0100 Subject: [PATCH 53/79] Fixed DEBUG logs not showing in newer Java versions --- bootstrap/standalone/pom.xml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bootstrap/standalone/pom.xml b/bootstrap/standalone/pom.xml index 7c271339a..0a583fa7c 100644 --- a/bootstrap/standalone/pom.xml +++ b/bootstrap/standalone/pom.xml @@ -120,6 +120,9 @@ org.geysermc.platform.standalone.GeyserBootstrap + + true + @@ -130,4 +133,4 @@ - \ No newline at end of file + From 013bca024c1dfb93f62066f72a0a59cea06263ef Mon Sep 17 00:00:00 2001 From: rtm516 Date: Thu, 9 Apr 2020 17:06:17 +0100 Subject: [PATCH 54/79] Removed auto download and load of en_us --- .../org/geysermc/connector/network/session/GeyserSession.java | 3 +++ .../main/java/org/geysermc/connector/utils/LocaleUtils.java | 3 --- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java index b2421e4ee..36e3a5b0d 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java @@ -254,6 +254,9 @@ public class GeyserSession implements CommandSender { playerEntity.setUuid(protocol.getProfile().getId()); playerEntity.setUsername(protocol.getProfile().getName()); + // Should probably let the user know if there locale is + // en_us that it might take time to download it + // Download and load the language for the player LocaleUtils.downloadAndLoadLocale(clientData.getLanguageCode()); } diff --git a/connector/src/main/java/org/geysermc/connector/utils/LocaleUtils.java b/connector/src/main/java/org/geysermc/connector/utils/LocaleUtils.java index d19c4672e..b5329dff9 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/LocaleUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/LocaleUtils.java @@ -58,9 +58,6 @@ public class LocaleUtils { // Download the latest asset list and cache it generateAssetCache(); - if (!DEFAULT_LOCALE.equals("en_us")) { - downloadAndLoadLocale("en_us"); - } downloadAndLoadLocale(DEFAULT_LOCALE); } From 81c1533ee2c7952d8644b8d2c5d1691195395ad4 Mon Sep 17 00:00:00 2001 From: rtm516 Date: Thu, 9 Apr 2020 17:21:51 +0100 Subject: [PATCH 55/79] en_us user now gets a chat message if the locale isnt already loaded --- .../connector/network/session/GeyserSession.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java index 36e3a5b0d..9761f92e2 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java @@ -254,11 +254,17 @@ public class GeyserSession implements CommandSender { playerEntity.setUuid(protocol.getProfile().getId()); playerEntity.setUsername(protocol.getProfile().getName()); - // Should probably let the user know if there locale is - // en_us that it might take time to download it + String locale = clientData.getLanguageCode(); + + // Let the user know there locale may take some time to download + // as it has to be extracted from a JAR + if (locale.toLowerCase().equals("en_us") && !LocaleUtils.LOCALE_MAPPINGS.containsKey("en_us")) { + connector.getLogger().info("warning user"); + sendMessage("Downloading your locale (en_us) this may take some time"); + } // Download and load the language for the player - LocaleUtils.downloadAndLoadLocale(clientData.getLanguageCode()); + LocaleUtils.downloadAndLoadLocale(locale); } @Override From 78fdab209090cd5df3bb5d22b82e31fbf8def6f7 Mon Sep 17 00:00:00 2001 From: rtm516 Date: Thu, 9 Apr 2020 17:34:49 +0100 Subject: [PATCH 56/79] Removed left in debug line --- .../org/geysermc/connector/network/session/GeyserSession.java | 1 - 1 file changed, 1 deletion(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java index 9761f92e2..749dacb2c 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java @@ -259,7 +259,6 @@ public class GeyserSession implements CommandSender { // Let the user know there locale may take some time to download // as it has to be extracted from a JAR if (locale.toLowerCase().equals("en_us") && !LocaleUtils.LOCALE_MAPPINGS.containsKey("en_us")) { - connector.getLogger().info("warning user"); sendMessage("Downloading your locale (en_us) this may take some time"); } From da99bb16d55ceaf2f923df069e953e285d4d80f7 Mon Sep 17 00:00:00 2001 From: DoctorMacc Date: Thu, 9 Apr 2020 13:37:27 -0400 Subject: [PATCH 57/79] Cat work --- .../connector/entity/living/animal/tameable/CatEntity.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java index 5a8a1dcf2..964b82cf4 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java @@ -28,6 +28,7 @@ package org.geysermc.connector.entity.living.animal.tameable; import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.data.EntityData; +import com.nukkitx.protocol.bedrock.data.EntityFlag; import org.geysermc.connector.entity.type.EntityType; import org.geysermc.connector.network.session.GeyserSession; @@ -44,8 +45,11 @@ public class CatEntity extends TameableEntity { } if (entityMetadata.getId() == 21) { // FIXME: Colors the whole animal instead of just collar + System.out.println("Color: " + (int) entityMetadata.getValue()); + metadata.getFlags().setFlag(EntityFlag.TAMED, true); metadata.put(EntityData.COLOR, (byte) (int) entityMetadata.getValue()); } + System.out.println("ID: " + entityMetadata.getId() + " Value: " + entityMetadata.getValue()); super.updateBedrockMetadata(entityMetadata, session); } } From 1e1d2f00ae01511681f66fe1bd30ca3e7732ea27 Mon Sep 17 00:00:00 2001 From: rtm516 Date: Thu, 9 Apr 2020 19:46:45 +0100 Subject: [PATCH 58/79] Fixed language processing and chat colours being reset for no reason --- .../connector/network/translators/java/JavaChatTranslator.java | 2 +- .../main/java/org/geysermc/connector/utils/MessageUtils.java | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaChatTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaChatTranslator.java index ae58830c9..a527866c9 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaChatTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaChatTranslator.java @@ -69,7 +69,7 @@ public class JavaChatTranslator extends PacketTranslator { List paramsTranslated = MessageUtils.getTranslationParams(((TranslationMessage) packet.getMessage()).getTranslationParams(), locale); textPacket.setParameters(paramsTranslated); - textPacket.setMessage(MessageUtils.insertParams(MessageUtils.getTranslatedBedrockMessage(packet.getMessage(), locale, false), paramsTranslated)); + textPacket.setMessage(MessageUtils.insertParams(MessageUtils.getTranslatedBedrockMessage(packet.getMessage(), locale, true), paramsTranslated)); } else { textPacket.setNeedsTranslation(false); diff --git a/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java b/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java index 76563dd6d..85fb6eb93 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java @@ -188,7 +188,6 @@ public class MessageUtils { base += "f"; break; case RESET: - case NONE: base += "r"; break; default: From 9f1da99b71b23f7d862d0ba5023bb6a989e654a4 Mon Sep 17 00:00:00 2001 From: rtm516 Date: Thu, 9 Apr 2020 20:24:32 +0100 Subject: [PATCH 59/79] Fixed NONE colour formatting and cleaned up imports --- .../geysermc/connector/utils/LocaleUtils.java | 4 ---- .../connector/utils/MessageUtils.java | 23 ++++++++++++------- .../geysermc/connector/utils/WebUtils.java | 5 ---- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/utils/LocaleUtils.java b/connector/src/main/java/org/geysermc/connector/utils/LocaleUtils.java index b5329dff9..e8555eb02 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/LocaleUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/LocaleUtils.java @@ -28,16 +28,12 @@ package org.geysermc.connector.utils; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; import lombok.Getter; import org.geysermc.connector.GeyserConnector; import java.io.*; -import java.net.URL; import java.nio.file.Files; import java.nio.file.Paths; -import java.nio.file.StandardCopyOption; -import java.time.OffsetDateTime; import java.util.*; import java.util.zip.ZipFile; diff --git a/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java b/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java index 85fb6eb93..e58c5d74d 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java @@ -26,16 +26,12 @@ package org.geysermc.connector.utils; import com.github.steveice10.mc.protocol.data.game.scoreboard.TeamColor; -import com.github.steveice10.mc.protocol.data.message.ChatColor; -import com.github.steveice10.mc.protocol.data.message.ChatFormat; -import com.github.steveice10.mc.protocol.data.message.Message; -import com.github.steveice10.mc.protocol.data.message.TranslationMessage; +import com.github.steveice10.mc.protocol.data.message.*; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.google.gson.JsonPrimitive; -import org.geysermc.connector.GeyserConnector; import java.util.*; import java.util.regex.Matcher; @@ -70,7 +66,7 @@ public class MessageUtils { } } else { String builder = getFormat(message.getStyle().getFormats()) + - getColor(message.getStyle().getColor()); + getColorOrParent(message.getStyle()); builder += getTranslatedBedrockMessage(message, locale, false); strings.add(builder); } @@ -84,7 +80,7 @@ public class MessageUtils { } public static String getTranslationText(TranslationMessage message) { - return getFormat(message.getStyle().getFormats()) + getColor(message.getStyle().getColor()) + return getFormat(message.getStyle().getFormats()) + getColorOrParent(message.getStyle()) + "%" + message.getTranslationKey(); } @@ -103,7 +99,7 @@ public class MessageUtils { StringBuilder builder = new StringBuilder(messageText); for (Message msg : message.getExtra()) { builder.append(getFormat(msg.getStyle().getFormats())); - builder.append(getColor(msg.getStyle().getColor())); + builder.append(getColorOrParent(msg.getStyle())); if (!(msg.getText() == null)) { boolean isTranslationMessage = (msg instanceof TranslationMessage); builder.append(getTranslatedBedrockMessage(msg, locale, isTranslationMessage)); @@ -136,6 +132,16 @@ public class MessageUtils { return newMessage; } + private static String getColorOrParent(MessageStyle style) { + ChatColor chatColor = style.getColor(); + + if (chatColor == ChatColor.NONE) { + return getColor(style.getParent().getColor()); + } + + return getColor(chatColor); + } + private static String getColor(ChatColor color) { String base = "\u00a7"; switch (color) { @@ -188,6 +194,7 @@ public class MessageUtils { base += "f"; break; case RESET: + case NONE: base += "r"; break; default: diff --git a/connector/src/main/java/org/geysermc/connector/utils/WebUtils.java b/connector/src/main/java/org/geysermc/connector/utils/WebUtils.java index a155f0b95..065d683a0 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/WebUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/WebUtils.java @@ -25,16 +25,11 @@ package org.geysermc.connector.utils; -import org.geysermc.connector.GeyserConnector; - import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; -import java.net.MalformedURLException; import java.net.URL; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; import java.nio.file.StandardCopyOption; From af4edf159a61606060a12062b2643d09cba04a85 Mon Sep 17 00:00:00 2001 From: DoctorMacc Date: Thu, 9 Apr 2020 16:06:00 -0400 Subject: [PATCH 60/79] Add tameable entity features --- .../living/animal/tameable/CatEntity.java | 22 +++++++++++++----- .../living/animal/tameable/ParrotEntity.java | 23 +++++++++++++++++++ .../living/animal/tameable/WolfEntity.java | 10 ++++++-- .../connector/entity/type/EntityType.java | 6 ++--- 4 files changed, 49 insertions(+), 12 deletions(-) create mode 100644 connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/ParrotEntity.java diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java index 964b82cf4..6c7d73536 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java @@ -41,15 +41,25 @@ public class CatEntity extends TameableEntity { @Override public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) { if (entityMetadata.getId() == 18) { - metadata.put(EntityData.VARIANT, (int) entityMetadata.getValue()); + // Different colors in Java and Bedrock for some reason + if ((int) entityMetadata.getValue() == 0) { + metadata.put(EntityData.VARIANT, 8); + } else if ((int) entityMetadata.getValue() == 8) { + // Assumption, need to test + metadata.put(EntityData.VARIANT, 0); + } else if ((int) entityMetadata.getValue() == 9) { + metadata.put(EntityData.VARIANT, 7); + } else { + metadata.put(EntityData.VARIANT, (int) entityMetadata.getValue()); + } + System.out.println("Variant: " + entityMetadata.getValue()); } if (entityMetadata.getId() == 21) { - // FIXME: Colors the whole animal instead of just collar - System.out.println("Color: " + (int) entityMetadata.getValue()); - metadata.getFlags().setFlag(EntityFlag.TAMED, true); - metadata.put(EntityData.COLOR, (byte) (int) entityMetadata.getValue()); + // Needed or else wild cats are that color + if (metadata.getFlags().getFlag(EntityFlag.TAMED)) { + metadata.put(EntityData.COLOR, (byte) (int) entityMetadata.getValue()); + } } - System.out.println("ID: " + entityMetadata.getId() + " Value: " + entityMetadata.getValue()); super.updateBedrockMetadata(entityMetadata, session); } } diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/ParrotEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/ParrotEntity.java new file mode 100644 index 000000000..0ee13867b --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/ParrotEntity.java @@ -0,0 +1,23 @@ +package org.geysermc.connector.entity.living.animal.tameable; + +import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; +import com.nukkitx.math.vector.Vector3f; +import com.nukkitx.protocol.bedrock.data.EntityData; +import org.geysermc.connector.entity.type.EntityType; +import org.geysermc.connector.network.session.GeyserSession; + +public class ParrotEntity extends TameableEntity { + + public ParrotEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) { + super(entityId, geyserId, entityType, position, motion, rotation); + } + + @Override + public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) { + // Parrot color + if (entityMetadata.getId() == 18) { + metadata.put(EntityData.VARIANT, entityMetadata.getValue()); + } + super.updateBedrockMetadata(entityMetadata, session); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/WolfEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/WolfEntity.java index 6f6ab15f8..ac8ef6659 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/WolfEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/WolfEntity.java @@ -28,6 +28,7 @@ package org.geysermc.connector.entity.living.animal.tameable; import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.data.EntityData; +import com.nukkitx.protocol.bedrock.data.EntityFlag; import org.geysermc.connector.entity.type.EntityType; import org.geysermc.connector.network.session.GeyserSession; @@ -39,9 +40,14 @@ public class WolfEntity extends TameableEntity { @Override public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) { + System.out.println("ID: " + entityMetadata.getId() + ", " + entityMetadata.getValue()); + // "Begging" on wiki.vg, "Interested" in Nukkit - the tilt of the head + if (entityMetadata.getId() == 18) { + metadata.getFlags().setFlag(EntityFlag.INTERESTED, (boolean) entityMetadata.getValue()); + } if (entityMetadata.getId() == 19) { - // FIXME: Colors the whole animal instead of just collar - // metadata.put(EntityData.COLOR, (byte) (int) entityMetadata.getValue()); + metadata.put(EntityData.INTERACTIVE_TAG, "action.interact.dye"); + metadata.put(EntityData.COLOR, entityMetadata.getValue()); } super.updateBedrockMetadata(entityMetadata, session); } diff --git a/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java b/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java index 500aa1a2e..4af044701 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java +++ b/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java @@ -29,10 +29,8 @@ import lombok.Getter; import org.geysermc.connector.entity.*; import org.geysermc.connector.entity.living.*; import org.geysermc.connector.entity.living.animal.*; -import org.geysermc.connector.entity.living.animal.tameable.CatEntity; -import org.geysermc.connector.entity.living.animal.tameable.TameableEntity; import org.geysermc.connector.entity.living.animal.horse.*; -import org.geysermc.connector.entity.living.animal.tameable.WolfEntity; +import org.geysermc.connector.entity.living.animal.tameable.*; import org.geysermc.connector.entity.living.monster.*; import org.geysermc.connector.entity.living.monster.raid.AbstractIllagerEntity; import org.geysermc.connector.entity.living.monster.raid.RaidParticipantEntity; @@ -62,7 +60,7 @@ public enum EntityType { POLAR_BEAR(PolarBearEntity.class, 28, 1.4f, 1.3f), LLAMA(LlamaEntity.class, 29, 1.87f, 0.9f), TRADER_LLAMA(TraderLlamaEntity.class, 29, 1.187f, 0.9f), - PARROT(TameableEntity.class, 30, 0.9f, 0.5f), + PARROT(ParrotEntity.class, 30, 0.9f, 0.5f), DOLPHIN(WaterEntity.class, 31, 0.6f, 0.9f), ZOMBIE(ZombieEntity.class, 32, 1.8f, 0.6f, 0.6f, 1.62f), CREEPER(CreeperEntity.class, 33, 1.7f, 0.6f, 0.6f, 1.62f), From c2fc3a78738b15da3c9d73e5bc1d33263a02cd86 Mon Sep 17 00:00:00 2001 From: DoctorMacc Date: Thu, 9 Apr 2020 16:09:03 -0400 Subject: [PATCH 61/79] Add copyright --- .../living/animal/tameable/ParrotEntity.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/ParrotEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/ParrotEntity.java index 0ee13867b..e02b3e7be 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/ParrotEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/ParrotEntity.java @@ -1,3 +1,28 @@ +/* + * Copyright (c) 2019-2020 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.entity.living.animal.tameable; import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; From 369f1cf127af7d47adcb6e174bfede68c5750ce7 Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+DoctorMacc@users.noreply.github.com> Date: Thu, 9 Apr 2020 16:13:03 -0400 Subject: [PATCH 62/79] Add .gitignore for locales folder --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 9b233578c..6e0e8f49b 100644 --- a/.gitignore +++ b/.gitignore @@ -225,3 +225,4 @@ nbdist/ config.yml logs/ public-key.pem +locales/ From c1dbd64f12d1554ade12d9564d220633907f202e Mon Sep 17 00:00:00 2001 From: DoctorMacc Date: Thu, 9 Apr 2020 16:36:30 -0400 Subject: [PATCH 63/79] Add wolf collar support --- .../connector/entity/living/animal/tameable/CatEntity.java | 2 +- .../entity/living/animal/tameable/TameableEntity.java | 4 ++++ .../connector/entity/living/animal/tameable/WolfEntity.java | 4 +--- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java index 6c7d73536..f380360ca 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java @@ -55,7 +55,7 @@ public class CatEntity extends TameableEntity { System.out.println("Variant: " + entityMetadata.getValue()); } if (entityMetadata.getId() == 21) { - // Needed or else wild cats are that color + // Needed or else wild cats are a red color if (metadata.getFlags().getFlag(EntityFlag.TAMED)) { metadata.put(EntityData.COLOR, (byte) (int) entityMetadata.getValue()); } diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/TameableEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/TameableEntity.java index 2f212595b..19ac8178e 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/TameableEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/TameableEntity.java @@ -27,6 +27,7 @@ package org.geysermc.connector.entity.living.animal.tameable; import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.nukkitx.math.vector.Vector3f; +import com.nukkitx.protocol.bedrock.data.EntityData; import com.nukkitx.protocol.bedrock.data.EntityFlag; import org.geysermc.connector.entity.living.animal.AnimalEntity; import org.geysermc.connector.entity.type.EntityType; @@ -45,6 +46,9 @@ public class TameableEntity extends AnimalEntity { metadata.getFlags().setFlag(EntityFlag.SITTING, (xd & 0x01) == 0x01); metadata.getFlags().setFlag(EntityFlag.ANGRY, (xd & 0x02) == 0x02); metadata.getFlags().setFlag(EntityFlag.TAMED, (xd & 0x04) == 0x04); + if (metadata.getFlags().getFlag(EntityFlag.TAMED)) { + metadata.put(EntityData.OWNER_EID, session.getPlayerEntity().getGeyserId()); + } } super.updateBedrockMetadata(entityMetadata, session); } diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/WolfEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/WolfEntity.java index ac8ef6659..9796d364f 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/WolfEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/WolfEntity.java @@ -40,14 +40,12 @@ public class WolfEntity extends TameableEntity { @Override public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) { - System.out.println("ID: " + entityMetadata.getId() + ", " + entityMetadata.getValue()); // "Begging" on wiki.vg, "Interested" in Nukkit - the tilt of the head if (entityMetadata.getId() == 18) { metadata.getFlags().setFlag(EntityFlag.INTERESTED, (boolean) entityMetadata.getValue()); } if (entityMetadata.getId() == 19) { - metadata.put(EntityData.INTERACTIVE_TAG, "action.interact.dye"); - metadata.put(EntityData.COLOR, entityMetadata.getValue()); + metadata.put(EntityData.COLOR, (byte) (int) entityMetadata.getValue()); } super.updateBedrockMetadata(entityMetadata, session); } From c777641a9000a7ddedc794b86a28494298ef18be Mon Sep 17 00:00:00 2001 From: DoctorMacc Date: Thu, 9 Apr 2020 17:53:38 -0400 Subject: [PATCH 64/79] Changes? --- .../connector/entity/living/animal/tameable/CatEntity.java | 5 +++-- .../entity/living/animal/tameable/TameableEntity.java | 4 +++- .../connector/entity/living/animal/tameable/WolfEntity.java | 2 ++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java index f380360ca..dcfdf841e 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java @@ -45,10 +45,11 @@ public class CatEntity extends TameableEntity { if ((int) entityMetadata.getValue() == 0) { metadata.put(EntityData.VARIANT, 8); } else if ((int) entityMetadata.getValue() == 8) { - // Assumption, need to test metadata.put(EntityData.VARIANT, 0); } else if ((int) entityMetadata.getValue() == 9) { - metadata.put(EntityData.VARIANT, 7); + metadata.put(EntityData.VARIANT, 10); + } else if ((int) entityMetadata.getValue() == 10) { + metadata.put(EntityData.VARIANT, 9); } else { metadata.put(EntityData.VARIANT, (int) entityMetadata.getValue()); } diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/TameableEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/TameableEntity.java index 19ac8178e..2d3e0b1d1 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/TameableEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/TameableEntity.java @@ -46,9 +46,11 @@ public class TameableEntity extends AnimalEntity { metadata.getFlags().setFlag(EntityFlag.SITTING, (xd & 0x01) == 0x01); metadata.getFlags().setFlag(EntityFlag.ANGRY, (xd & 0x02) == 0x02); metadata.getFlags().setFlag(EntityFlag.TAMED, (xd & 0x04) == 0x04); + // Must be set for wolf collar color to work + // Extending it to all entities to prevent future bugs if (metadata.getFlags().getFlag(EntityFlag.TAMED)) { metadata.put(EntityData.OWNER_EID, session.getPlayerEntity().getGeyserId()); - } + } // Can't de-tame an entity so no resetting the owner ID } super.updateBedrockMetadata(entityMetadata, session); } diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/WolfEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/WolfEntity.java index 9796d364f..0ac49d55d 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/WolfEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/WolfEntity.java @@ -44,6 +44,8 @@ public class WolfEntity extends TameableEntity { if (entityMetadata.getId() == 18) { metadata.getFlags().setFlag(EntityFlag.INTERESTED, (boolean) entityMetadata.getValue()); } + // Wolf collar color + // Relies on EntityData.OWNER_EID being set in TameableEntity.java if (entityMetadata.getId() == 19) { metadata.put(EntityData.COLOR, (byte) (int) entityMetadata.getValue()); } From 8f735ae4530df105049c97f882ca054632c5566a Mon Sep 17 00:00:00 2001 From: DoctorMacc Date: Thu, 9 Apr 2020 18:12:53 -0400 Subject: [PATCH 65/79] Remove debug code --- .../connector/entity/living/animal/tameable/CatEntity.java | 1 - 1 file changed, 1 deletion(-) diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java index dcfdf841e..1c160e82e 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java @@ -53,7 +53,6 @@ public class CatEntity extends TameableEntity { } else { metadata.put(EntityData.VARIANT, (int) entityMetadata.getValue()); } - System.out.println("Variant: " + entityMetadata.getValue()); } if (entityMetadata.getId() == 21) { // Needed or else wild cats are a red color From d0a7f6282c7370eec46baec9fa5706c778fd2db0 Mon Sep 17 00:00:00 2001 From: DoctorMacc Date: Thu, 9 Apr 2020 19:33:52 -0400 Subject: [PATCH 66/79] Initial villager types support --- .../AbstractMerchantEntity.java | 3 +- .../living/merchant/VillagerEntity.java | 69 +++++++++++++++++++ .../connector/entity/type/EntityType.java | 3 +- 3 files changed, 73 insertions(+), 2 deletions(-) rename connector/src/main/java/org/geysermc/connector/entity/living/{ => merchant}/AbstractMerchantEntity.java (93%) create mode 100644 connector/src/main/java/org/geysermc/connector/entity/living/merchant/VillagerEntity.java diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/AbstractMerchantEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/merchant/AbstractMerchantEntity.java similarity index 93% rename from connector/src/main/java/org/geysermc/connector/entity/living/AbstractMerchantEntity.java rename to connector/src/main/java/org/geysermc/connector/entity/living/merchant/AbstractMerchantEntity.java index da505fab5..ddeb31bd1 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/AbstractMerchantEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/merchant/AbstractMerchantEntity.java @@ -23,9 +23,10 @@ * @link https://github.com/GeyserMC/Geyser */ -package org.geysermc.connector.entity.living; +package org.geysermc.connector.entity.living.merchant; import com.nukkitx.math.vector.Vector3f; +import org.geysermc.connector.entity.living.AgeableEntity; import org.geysermc.connector.entity.type.EntityType; public class AbstractMerchantEntity extends AgeableEntity { diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/merchant/VillagerEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/merchant/VillagerEntity.java new file mode 100644 index 000000000..04c1a4ea8 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/entity/living/merchant/VillagerEntity.java @@ -0,0 +1,69 @@ +package org.geysermc.connector.entity.living.merchant; + +import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; +import com.github.steveice10.mc.protocol.data.game.entity.metadata.VillagerData; +import com.nukkitx.math.vector.Vector3f; +import com.nukkitx.protocol.bedrock.data.EntityData; +import com.nukkitx.protocol.bedrock.packet.AddEntityPacket; +import it.unimi.dsi.fastutil.ints.Int2IntMap; +import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; +import org.geysermc.connector.entity.type.EntityType; +import org.geysermc.connector.network.session.GeyserSession; + +public class VillagerEntity extends AbstractMerchantEntity { + + public static Int2IntMap VILLAGER_VARIANTS = new Int2IntOpenHashMap(); + + static { + VILLAGER_VARIANTS.put(1, 8); + VILLAGER_VARIANTS.put(2, 11); + VILLAGER_VARIANTS.put(3, 6); + VILLAGER_VARIANTS.put(4, 7); + VILLAGER_VARIANTS.put(5, 1); + VILLAGER_VARIANTS.put(6, 2); + VILLAGER_VARIANTS.put(7, 4); + VILLAGER_VARIANTS.put(8, 12); + VILLAGER_VARIANTS.put(9, 5); + VILLAGER_VARIANTS.put(10, 13); + VILLAGER_VARIANTS.put(11, 14); + VILLAGER_VARIANTS.put(12, 3); + VILLAGER_VARIANTS.put(13, 10); + VILLAGER_VARIANTS.put(14, 9); + } + + public VillagerEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) { + super(entityId, geyserId, entityType, position, motion, rotation); + } + + @Override + public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) { + System.out.println("ID: " + entityMetadata.getId() + ", " + entityMetadata.getValue()); + if (entityMetadata.getId() == 17) { + VillagerData villagerData = (VillagerData) entityMetadata.getValue(); + metadata.put(EntityData.VARIANT, VILLAGER_VARIANTS.get(villagerData.getProfession())); + metadata.put(EntityData.SKIN_ID, villagerData.getType()); + metadata.put(EntityData.TRADE_TIER, villagerData.getLevel() - 1); + } + super.updateBedrockMetadata(entityMetadata, session); + } + + @Override + public void spawnEntity(GeyserSession session) { + AddEntityPacket addEntityPacket = new AddEntityPacket(); + // "v2" or else it's the legacy villager + addEntityPacket.setIdentifier("minecraft:villager_v2"); + addEntityPacket.setRuntimeEntityId(geyserId); + addEntityPacket.setUniqueEntityId(geyserId); + addEntityPacket.setPosition(position); + addEntityPacket.setMotion(motion); + addEntityPacket.setRotation(getBedrockRotation()); + addEntityPacket.setEntityType(entityType.getType()); + addEntityPacket.getMetadata().putAll(metadata); + + valid = true; + session.getUpstream().sendPacket(addEntityPacket); + + session.getConnector().getLogger().debug("Spawned entity " + entityType + " at location " + position + " with id " + geyserId + " (java id " + entityId + ")"); + } + +} diff --git a/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java b/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java index 500aa1a2e..7a82fac72 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java +++ b/connector/src/main/java/org/geysermc/connector/entity/type/EntityType.java @@ -33,6 +33,7 @@ import org.geysermc.connector.entity.living.animal.tameable.CatEntity; import org.geysermc.connector.entity.living.animal.tameable.TameableEntity; import org.geysermc.connector.entity.living.animal.horse.*; import org.geysermc.connector.entity.living.animal.tameable.WolfEntity; +import org.geysermc.connector.entity.living.merchant.*; import org.geysermc.connector.entity.living.monster.*; import org.geysermc.connector.entity.living.monster.raid.AbstractIllagerEntity; import org.geysermc.connector.entity.living.monster.raid.RaidParticipantEntity; @@ -46,7 +47,7 @@ public enum EntityType { PIG(PigEntity.class, 12, 0.9f), SHEEP(SheepEntity.class, 13, 1.3f, 0.9f), WOLF(WolfEntity.class, 14, 0.85f, 0.6f), - VILLAGER(AbstractMerchantEntity.class, 15, 1.8f, 0.6f, 0.6f, 1.62f), + VILLAGER(VillagerEntity.class, 15, 1.8f, 0.6f, 0.6f, 1.62f), MOOSHROOM(AnimalEntity.class, 16, 1.4f, 0.9f), SQUID(WaterEntity.class, 17, 0.8f), RABBIT(RabbitEntity.class, 18, 0.5f, 0.4f), From a580edc78f32a79b6c9a9edb6d170fff4e3cf0c9 Mon Sep 17 00:00:00 2001 From: DoctorMacc Date: Thu, 9 Apr 2020 20:20:41 -0400 Subject: [PATCH 67/79] Little touch --- .../connector/entity/living/merchant/VillagerEntity.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/merchant/VillagerEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/merchant/VillagerEntity.java index 04c1a4ea8..b4cf72cb0 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/merchant/VillagerEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/merchant/VillagerEntity.java @@ -15,6 +15,8 @@ public class VillagerEntity extends AbstractMerchantEntity { public static Int2IntMap VILLAGER_VARIANTS = new Int2IntOpenHashMap(); static { + // Java villager profession IDs -> Bedrock + VILLAGER_VARIANTS.put(0, 0); VILLAGER_VARIANTS.put(1, 8); VILLAGER_VARIANTS.put(2, 11); VILLAGER_VARIANTS.put(3, 6); From 6359fd4e836477103401ccab3abc1c66f844aeab Mon Sep 17 00:00:00 2001 From: DoctorMacc Date: Thu, 9 Apr 2020 20:23:52 -0400 Subject: [PATCH 68/79] Use switch statement for cat variant color --- .../living/animal/tameable/CatEntity.java | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java index 1c160e82e..63a67a0a7 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/animal/tameable/CatEntity.java @@ -42,17 +42,24 @@ public class CatEntity extends TameableEntity { public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) { if (entityMetadata.getId() == 18) { // Different colors in Java and Bedrock for some reason - if ((int) entityMetadata.getValue() == 0) { - metadata.put(EntityData.VARIANT, 8); - } else if ((int) entityMetadata.getValue() == 8) { - metadata.put(EntityData.VARIANT, 0); - } else if ((int) entityMetadata.getValue() == 9) { - metadata.put(EntityData.VARIANT, 10); - } else if ((int) entityMetadata.getValue() == 10) { - metadata.put(EntityData.VARIANT, 9); - } else { - metadata.put(EntityData.VARIANT, (int) entityMetadata.getValue()); + int variantColor; + switch ((int) entityMetadata.getValue()) { + case 0: + variantColor = 8; + break; + case 8: + variantColor = 0; + break; + case 9: + variantColor = 10; + break; + case 10: + variantColor = 9; + break; + default: + variantColor = (int) entityMetadata.getValue(); } + metadata.put(EntityData.VARIANT, variantColor); } if (entityMetadata.getId() == 21) { // Needed or else wild cats are a red color From 23d98bb25f89919ff4f913f9bd7bf411cdec4d3b Mon Sep 17 00:00:00 2001 From: AJ Ferguson Date: Fri, 10 Apr 2020 10:46:29 -0800 Subject: [PATCH 69/79] Fix block placement for stairs, slabs, etc. --- .../bedrock/BedrockActionTranslator.java | 7 +---- ...BedrockInventoryTransactionTranslator.java | 30 +++++++++++++------ 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockActionTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockActionTranslator.java index ebc45ff08..206f42d1f 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockActionTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockActionTranslator.java @@ -33,12 +33,10 @@ import org.geysermc.connector.network.translators.PacketTranslator; import org.geysermc.connector.network.translators.Translator; import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position; -import com.github.steveice10.mc.protocol.data.game.entity.player.Hand; import com.github.steveice10.mc.protocol.data.game.entity.player.PlayerAction; import com.github.steveice10.mc.protocol.data.game.entity.player.PlayerState; 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.ClientPlayerPlaceBlockPacket; import com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerStatePacket; import com.nukkitx.math.vector.Vector3i; import com.nukkitx.protocol.bedrock.packet.PlayStatusPacket; @@ -101,10 +99,7 @@ public class BedrockActionTranslator extends PacketTranslator { @@ -50,14 +50,26 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator Date: Sat, 11 Apr 2020 11:35:14 -0400 Subject: [PATCH 70/79] Final touches --- .../living/merchant/VillagerEntity.java | 41 ++++++++++++++++++- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/merchant/VillagerEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/merchant/VillagerEntity.java index b4cf72cb0..dfc503ac0 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/merchant/VillagerEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/merchant/VillagerEntity.java @@ -1,3 +1,28 @@ +/* + * Copyright (c) 2019-2020 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.entity.living.merchant; import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; @@ -13,6 +38,7 @@ import org.geysermc.connector.network.session.GeyserSession; public class VillagerEntity extends AbstractMerchantEntity { public static Int2IntMap VILLAGER_VARIANTS = new Int2IntOpenHashMap(); + public static Int2IntMap VILLAGER_REGIONS = new Int2IntOpenHashMap(); static { // Java villager profession IDs -> Bedrock @@ -31,6 +57,14 @@ public class VillagerEntity extends AbstractMerchantEntity { VILLAGER_VARIANTS.put(12, 3); VILLAGER_VARIANTS.put(13, 10); VILLAGER_VARIANTS.put(14, 9); + + VILLAGER_REGIONS.put(0, 1); + VILLAGER_REGIONS.put(1, 2); + VILLAGER_REGIONS.put(2, 0); + VILLAGER_REGIONS.put(3, 3); + VILLAGER_REGIONS.put(4, 4); + VILLAGER_REGIONS.put(5, 5); + VILLAGER_REGIONS.put(6, 6); } public VillagerEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) { @@ -39,11 +73,14 @@ public class VillagerEntity extends AbstractMerchantEntity { @Override public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) { - System.out.println("ID: " + entityMetadata.getId() + ", " + entityMetadata.getValue()); if (entityMetadata.getId() == 17) { VillagerData villagerData = (VillagerData) entityMetadata.getValue(); + // Profession metadata.put(EntityData.VARIANT, VILLAGER_VARIANTS.get(villagerData.getProfession())); - metadata.put(EntityData.SKIN_ID, villagerData.getType()); + //metadata.put(EntityData.SKIN_ID, villagerData.getType()); Looks like this is modified but for any reason? + // Region + metadata.put(EntityData.MARK_VARIANT, VILLAGER_REGIONS.get(villagerData.getType())); + // Trade tier - different indexing in Bedrock metadata.put(EntityData.TRADE_TIER, villagerData.getLevel() - 1); } super.updateBedrockMetadata(entityMetadata, session); From 95bcc04177cb3132f67446618581fbc1eba2d9d2 Mon Sep 17 00:00:00 2001 From: AJ Ferguson Date: Sat, 11 Apr 2020 10:33:06 -0800 Subject: [PATCH 71/79] Fix crash on some devices when logging into a different dimension --- .../network/session/GeyserSession.java | 21 +++++++++++-------- ...SetLocalPlayerAsInitializedTranslator.java | 1 + .../java/JavaJoinGameTranslator.java | 2 -- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java index 749dacb2c..9dc03ffb0 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java @@ -149,15 +149,6 @@ public class GeyserSession implements CommandSender { public void connect(RemoteServer remoteServer) { startGame(); this.remoteServer = remoteServer; - if (connector.getAuthType() != AuthType.ONLINE) { - connector.getLogger().info( - "Attempting to login using " + connector.getAuthType().name().toLowerCase() + " mode... " + - (connector.getAuthType() == AuthType.OFFLINE ? - "authentication is disabled." : "authentication will be encrypted" - ) - ); - authenticate(authData.getName()); - } ChunkUtils.sendEmptyChunks(this, playerEntity.getPosition().toInt(), 0, false); @@ -174,6 +165,18 @@ public class GeyserSession implements CommandSender { upstream.sendPacket(playStatusPacket); } + public void login() { + if (connector.getAuthType() != AuthType.ONLINE) { + connector.getLogger().info( + "Attempting to login using " + connector.getAuthType().name().toLowerCase() + " mode... " + + (connector.getAuthType() == AuthType.OFFLINE ? + "authentication is disabled." : "authentication will be encrypted" + ) + ); + authenticate(authData.getName()); + } + } + public void authenticate(String username) { authenticate(username, ""); } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockSetLocalPlayerAsInitializedTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockSetLocalPlayerAsInitializedTranslator.java index 54a5112d4..87da2d00c 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockSetLocalPlayerAsInitializedTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockSetLocalPlayerAsInitializedTranslator.java @@ -40,6 +40,7 @@ public class BedrockSetLocalPlayerAsInitializedTranslator extends PacketTranslat if (session.getPlayerEntity().getGeyserId() == packet.getRuntimeEntityId()) { if (!session.getUpstream().isInitialized()) { session.getUpstream().setInitialized(true); + session.login(); for (PlayerEntity entity : session.getEntityCache().getEntitiesByType(PlayerEntity.class)) { if (!entity.isValid()) { diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaJoinGameTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaJoinGameTranslator.java index 0d6caaed0..34fe2271d 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaJoinGameTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaJoinGameTranslator.java @@ -29,7 +29,6 @@ import org.geysermc.connector.entity.PlayerEntity; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.PacketTranslator; import org.geysermc.connector.network.translators.Translator; -import org.geysermc.connector.utils.ChunkUtils; import org.geysermc.connector.utils.DimensionUtils; import com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket; @@ -69,7 +68,6 @@ public class JavaJoinGameTranslator extends PacketTranslator Date: Sat, 11 Apr 2020 19:43:29 +0100 Subject: [PATCH 72/79] Added translation to bossbar titles --- .../network/translators/java/JavaBossBarTranslator.java | 4 ++-- .../main/java/org/geysermc/connector/utils/MessageUtils.java | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaBossBarTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaBossBarTranslator.java index 3c1452a53..582f0b5aa 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaBossBarTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaBossBarTranslator.java @@ -51,7 +51,7 @@ public class JavaBossBarTranslator extends PacketTranslator bossEventPacket.setAction(BossEventPacket.Action.SHOW); bossEventPacket.setBossUniqueEntityId(entityId); - bossEventPacket.setTitle(MessageUtils.getBedrockMessage(packet.getTitle())); + bossEventPacket.setTitle(MessageUtils.getTranslatedBedrockMessage(packet.getTitle(), session.getClientData().getLanguageCode())); bossEventPacket.setHealthPercentage(packet.getHealth()); bossEventPacket.setColor(0); //ignored by client bossEventPacket.setOverlay(1); @@ -59,7 +59,7 @@ public class JavaBossBarTranslator extends PacketTranslator break; case UPDATE_TITLE: bossEventPacket.setAction(BossEventPacket.Action.TITLE); - bossEventPacket.setTitle(MessageUtils.getBedrockMessage(packet.getTitle())); + bossEventPacket.setTitle(MessageUtils.getTranslatedBedrockMessage(packet.getTitle(), session.getClientData().getLanguageCode())); break; case UPDATE_HEALTH: bossEventPacket.setAction(BossEventPacket.Action.HEALTH_PERCENTAGE); diff --git a/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java b/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java index e58c5d74d..a28d6a7a1 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/MessageUtils.java @@ -108,6 +108,10 @@ public class MessageUtils { return builder.toString(); } + public static String getTranslatedBedrockMessage(Message message, String locale) { + return getTranslatedBedrockMessage(message, locale, true); + } + public static String getBedrockMessage(Message message) { return getTranslatedBedrockMessage(message, null, false); } From f04a267d98c1edc03ab5af0e2d392992f4c78deb Mon Sep 17 00:00:00 2001 From: AJ Ferguson Date: Sat, 11 Apr 2020 10:53:27 -0800 Subject: [PATCH 73/79] Only show login form if AuthType is Online --- .../org/geysermc/connector/network/UpstreamPacketHandler.java | 3 ++- .../org/geysermc/connector/network/session/GeyserSession.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/UpstreamPacketHandler.java b/connector/src/main/java/org/geysermc/connector/network/UpstreamPacketHandler.java index 6fffcda84..cf6c2ee2f 100644 --- a/connector/src/main/java/org/geysermc/connector/network/UpstreamPacketHandler.java +++ b/connector/src/main/java/org/geysermc/connector/network/UpstreamPacketHandler.java @@ -27,6 +27,7 @@ package org.geysermc.connector.network; import com.nukkitx.protocol.bedrock.BedrockPacket; import com.nukkitx.protocol.bedrock.packet.*; +import org.geysermc.common.AuthType; import org.geysermc.common.IGeyserConfiguration; import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.network.session.GeyserSession; @@ -107,7 +108,7 @@ public class UpstreamPacketHandler extends LoggingPacketHandler { @Override public boolean handle(MovePlayerPacket packet) { - if (!session.isLoggedIn() && !session.isLoggingIn()) { + if (!session.isLoggedIn() && !session.isLoggingIn() && session.getConnector().getAuthType() == AuthType.ONLINE) { // TODO it is safer to key authentication on something that won't change (UUID, not username) if (!couldLoginUserByName(session.getAuthData().getName())) { LoginEncryptionUtils.showLoginWindow(session); diff --git a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java index 9dc03ffb0..d5b2e75d5 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java @@ -187,7 +187,7 @@ public class GeyserSession implements CommandSender { return; } - loggedIn = true; + loggingIn = true; // new thread so clients don't timeout new Thread(() -> { try { From 613626915ac2767dc528c0cae0479af0078a44cf Mon Sep 17 00:00:00 2001 From: rtm516 Date: Sat, 11 Apr 2020 20:11:46 +0100 Subject: [PATCH 74/79] Copied fix from inventory a00cf75 --- .../connector/network/translators/block/BlockTranslator.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/block/BlockTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/block/BlockTranslator.java index 906179d1f..58f6ff4e7 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/block/BlockTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/block/BlockTranslator.java @@ -103,7 +103,8 @@ public class BlockTranslator { if ("minecraft:water[level=0]".equals(javaId)) { waterRuntimeId = bedrockRuntimeId; } - boolean waterlogged = entry.getValue().has("waterlogged") && entry.getValue().get("waterlogged").booleanValue(); + boolean waterlogged = entry.getKey().contains("waterlogged=true") + || javaId.contains("minecraft:bubble_column") || javaId.contains("minecraft:kelp") || javaId.contains("seagrass"); if (waterlogged) { BEDROCK_TO_JAVA_BLOCK_MAP.putIfAbsent(bedrockRuntimeId | 1 << 31, new BlockState(javaRuntimeId)); From f3344dbfed65e15becd14ab3f71fa93fade38483 Mon Sep 17 00:00:00 2001 From: DoctorMacc Date: Sat, 11 Apr 2020 15:18:22 -0400 Subject: [PATCH 75/79] Change villager maps to private final --- .../connector/entity/living/merchant/VillagerEntity.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/merchant/VillagerEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/merchant/VillagerEntity.java index dfc503ac0..9ed48b886 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/living/merchant/VillagerEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/living/merchant/VillagerEntity.java @@ -37,8 +37,8 @@ import org.geysermc.connector.network.session.GeyserSession; public class VillagerEntity extends AbstractMerchantEntity { - public static Int2IntMap VILLAGER_VARIANTS = new Int2IntOpenHashMap(); - public static Int2IntMap VILLAGER_REGIONS = new Int2IntOpenHashMap(); + private static final Int2IntMap VILLAGER_VARIANTS = new Int2IntOpenHashMap(); + private static final Int2IntMap VILLAGER_REGIONS = new Int2IntOpenHashMap(); static { // Java villager profession IDs -> Bedrock From 5116f250ad2e7d30ddd26fd4d36bff5a21d90847 Mon Sep 17 00:00:00 2001 From: DoctorMacc Date: Sat, 11 Apr 2020 18:48:04 -0400 Subject: [PATCH 76/79] Add item collection animation --- .../java/world/JavaCollectItemTranslator.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaCollectItemTranslator.java diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaCollectItemTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaCollectItemTranslator.java new file mode 100644 index 000000000..c6af7a138 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaCollectItemTranslator.java @@ -0,0 +1,30 @@ +package org.geysermc.connector.network.translators.java.world; + +import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityCollectItemPacket; +import com.nukkitx.protocol.bedrock.packet.TakeItemEntityPacket; +import org.geysermc.connector.entity.Entity; +import org.geysermc.connector.network.session.GeyserSession; +import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.network.translators.Translator; + +@Translator(packet = ServerEntityCollectItemPacket.class) +public class JavaCollectItemTranslator extends PacketTranslator { + + @Override + public void translate(ServerEntityCollectItemPacket packet, GeyserSession session) { + // This is the definition of translating - both packets take the same values + TakeItemEntityPacket takeItemEntityPacket = new TakeItemEntityPacket(); + // Collected entity is the item + Entity collectedEntity = session.getEntityCache().getEntityByJavaId(packet.getCollectedEntityId()); + // Collector is the entity picking up the item + Entity collectorEntity; + if (packet.getCollectorEntityId() == session.getPlayerEntity().getEntityId()) { + collectorEntity = session.getPlayerEntity(); + } else { + collectorEntity = session.getEntityCache().getEntityByJavaId(packet.getCollectorEntityId()); + } + takeItemEntityPacket.setRuntimeEntityId(collectorEntity.getGeyserId()); + takeItemEntityPacket.setItemRuntimeEntityId(collectedEntity.getGeyserId()); + session.getUpstream().sendPacket(takeItemEntityPacket); + } +} From ce7954d8ab34d388bc0aa5411aa37fba3847a11b Mon Sep 17 00:00:00 2001 From: DoctorMacc Date: Sat, 11 Apr 2020 18:50:01 -0400 Subject: [PATCH 77/79] Add license --- .../java/world/JavaCollectItemTranslator.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaCollectItemTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaCollectItemTranslator.java index c6af7a138..b4287b081 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaCollectItemTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaCollectItemTranslator.java @@ -1,3 +1,28 @@ +/* + * Copyright (c) 2019-2020 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.network.translators.java.world; import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityCollectItemPacket; From 76e29af6b8f91974684cf36ab679bce9f3735b0f Mon Sep 17 00:00:00 2001 From: rtm516 Date: Sun, 12 Apr 2020 01:45:31 +0100 Subject: [PATCH 78/79] Fixed map name --- .../connector/network/translators/item/ItemTranslator.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemTranslator.java index 0da776dcf..68f88bb21 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemTranslator.java @@ -77,8 +77,10 @@ public class ItemTranslator { CompoundTag tag = stack.getNbt(); IntTag mapId = tag.get("map"); - if (mapId != null) + if (mapId != null) { tag.put(new StringTag("map_uuid", mapId.getValue().toString())); + tag.put(new IntTag("map_name_index", mapId.getValue())); + } return ItemData.of(bedrockItem.getBedrockId(), (short) bedrockItem.getBedrockData(), stack.getAmount(), translateToBedrockNBT(tag)); From d613835f9253dbfbcfb924ba882d4e721e41dc1e Mon Sep 17 00:00:00 2001 From: rtm516 Date: Sun, 12 Apr 2020 10:37:31 +0100 Subject: [PATCH 79/79] Added debug packet logging for unhandled packets --- .../org/geysermc/connector/network/translators/Registry.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/Registry.java b/connector/src/main/java/org/geysermc/connector/network/translators/Registry.java index cf80cdbfe..70201ba88 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/Registry.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/Registry.java @@ -55,6 +55,8 @@ public class Registry { if (MAP.containsKey(clazz)) { ((PacketTranslator

) MAP.get(clazz)).translate(packet, session); return true; + } else { + GeyserConnector.getInstance().getLogger().debug("Could not find packet for " + (packet.toString().length() > 25 ? packet.getClass().getSimpleName() : packet)); } } catch (Throwable ex) { GeyserConnector.getInstance().getLogger().error("Could not translate packet " + packet.getClass().getSimpleName(), ex);