From 65277dc82aea3e53a5f24789efb51af62b8cf277 Mon Sep 17 00:00:00 2001 From: rtm516 Date: Sat, 4 Apr 2020 17:25:38 +0100 Subject: [PATCH 01/63] 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 02/63] 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 03/63] 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 7f1fb3d43caf3456988b86caef70aebc55e5ec84 Mon Sep 17 00:00:00 2001 From: rtm516 Date: Sun, 5 Apr 2020 02:36:25 +0100 Subject: [PATCH 04/63] 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 05/63] 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 06/63] 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 de22248fe0a0a9e7dcfaeb7694145d0988f8bac9 Mon Sep 17 00:00:00 2001 From: Redned Date: Sun, 5 Apr 2020 01:19:57 -0500 Subject: [PATCH 07/63] 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 08/63] 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 09/63] 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 10/63] 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 11/63] 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 12/63] 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 13/63] 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 14/63] 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 15/63] 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 16/63] 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 17/63] 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 18/63] 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 19/63] 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 20/63] 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 21/63] 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 22/63] 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 23/63] 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 24/63] 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 25/63] 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 26/63] 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 27/63] 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 28/63] 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 29/63] 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 30/63] 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 31/63] 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 32/63] 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 33/63] 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 34/63] 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 35/63] 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 36/63] 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 37/63] 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 38/63] 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 39/63] 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 40/63] 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 41/63] 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 42/63] 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 43/63] 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 44/63] 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 45/63] 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 46/63] 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 47/63] 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 48/63] 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 49/63] 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 50/63] 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 51/63] 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 52/63] 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 53/63] 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 54/63] 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 55/63] 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 56/63] 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 57/63] 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 58/63] 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 59/63] 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 60/63] 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 61/63] 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 62/63] 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 63/63] 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;