From 3a2cff7864a659a3682eb62323e212b5c2681a66 Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Sun, 20 Jun 2021 21:42:22 -0400 Subject: [PATCH 01/19] Clean up a bunch Mostly checked with IntelliJ, but manually performed. The only issue I possibly anticipate is item name/lore issues, but the new method should be technically better. --- .../bungeecord/GeyserBungeeDumpInfo.java | 15 ++-- .../GeyserBungeePingPassthrough.java | 6 +- .../platform/spigot/GeyserSpigotDumpInfo.java | 14 ++-- .../spigot/GeyserSpigotPingPassthrough.java | 4 +- .../platform/spigot/GeyserSpigotPlugin.java | 2 +- .../command/GeyserSpigotCommandManager.java | 7 +- .../manager/GeyserSpigot1_12WorldManager.java | 1 - .../platform/sponge/GeyserSpongeDumpInfo.java | 13 ++-- .../command/GeyserSpongeCommandExecutor.java | 3 +- .../command/GeyserSpongeCommandManager.java | 7 +- .../standalone/GeyserStandaloneDumpInfo.java | 3 +- .../platform/standalone/LoopbackUtil.java | 3 +- .../platform/standalone/gui/ColorPane.java | 5 +- .../platform/standalone/gui/GraphPanel.java | 3 +- .../velocity/GeyserVelocityDumpInfo.java | 14 ++-- .../command/defaults/HelpCommand.java | 3 +- .../command/defaults/ListCommand.java | 3 +- .../connector/common/main/IGeyserMain.java | 3 +- .../connector/entity/FireworkEntity.java | 35 ++++++---- .../connector/inventory/Inventory.java | 2 +- .../network/LoggingPacketHandler.java | 8 +-- .../connector/network/QueryPacketHandler.java | 2 +- .../network/session/cache/BossBar.java | 11 ++- .../BedrockMapInfoRequestTranslator.java | 13 ++-- .../chat/MinecraftTranslationRegistry.java | 3 +- .../collision/CollisionRemapper.java | 1 - .../network/translators/item/ItemEntry.java | 3 +- .../translators/item/ItemTranslator.java | 2 +- .../item/translators/BannerTranslator.java | 4 +- .../translators/nbt/BasicItemTranslator.java | 69 ++++--------------- .../java/JavaBossBarTranslator.java | 1 - .../world/JavaUpdateTileEntityTranslator.java | 3 +- .../JavaUpdateViewPositionTranslator.java | 1 - .../translators/sound/SoundRegistry.java | 2 +- .../block/BucketSoundInteractionHandler.java | 1 - .../ping/GeyserLegacyPingPassthrough.java | 3 +- .../connector/utils/BedrockMapIcon.java | 21 +++--- .../connector/utils/BlockEntityUtils.java | 6 +- .../geysermc/connector/utils/FileUtils.java | 3 +- .../geysermc/connector/utils/GameRule.java | 6 +- .../geysermc/connector/utils/LocaleUtils.java | 2 +- .../geysermc/connector/utils/MapColor.java | 2 +- .../connector/utils/SettingsUtils.java | 2 - 43 files changed, 125 insertions(+), 190 deletions(-) diff --git a/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeeDumpInfo.java b/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeeDumpInfo.java index 12429d75b..4e87f3a63 100644 --- a/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeeDumpInfo.java +++ b/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeeDumpInfo.java @@ -32,17 +32,16 @@ import org.geysermc.connector.common.serializer.AsteriskSerializer; import org.geysermc.connector.dump.BootstrapDumpInfo; import java.util.ArrayList; -import java.util.Arrays; +import java.util.Collections; import java.util.List; @Getter public class GeyserBungeeDumpInfo extends BootstrapDumpInfo { - - private String platformName; - private String platformVersion; - private boolean onlineMode; - private List listeners; - private List plugins; + private final String platformName; + private final String platformVersion; + private final boolean onlineMode; + private final List listeners; + private final List plugins; GeyserBungeeDumpInfo(ProxyServer proxy) { super(); @@ -63,7 +62,7 @@ public class GeyserBungeeDumpInfo extends BootstrapDumpInfo { } for (Plugin plugin : proxy.getPluginManager().getPlugins()) { - this.plugins.add(new PluginInfo(true, plugin.getDescription().getName(), plugin.getDescription().getVersion(), plugin.getDescription().getMain(), Arrays.asList(plugin.getDescription().getAuthor()))); + this.plugins.add(new PluginInfo(true, plugin.getDescription().getName(), plugin.getDescription().getVersion(), plugin.getDescription().getMain(), Collections.singletonList(plugin.getDescription().getAuthor()))); } } } diff --git a/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeePingPassthrough.java b/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeePingPassthrough.java index 6eea25918..0b8b3901b 100644 --- a/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeePingPassthrough.java +++ b/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeePingPassthrough.java @@ -37,7 +37,6 @@ import net.md_5.bungee.protocol.ProtocolConstants; import org.geysermc.connector.common.ping.GeyserPingInfo; import org.geysermc.connector.ping.IGeyserPingPassthrough; -import java.net.Inet4Address; import java.net.InetSocketAddress; import java.net.SocketAddress; import java.util.Arrays; @@ -64,9 +63,8 @@ public class GeyserBungeePingPassthrough implements IGeyserPingPassthrough, List new GeyserPingInfo.Version(response.getVersion().getName(), response.getVersion().getProtocol()) ); if (event.getResponse().getPlayers().getSample() != null) { - Arrays.stream(event.getResponse().getPlayers().getSample()).forEach(proxiedPlayer -> { - geyserPingInfo.getPlayerList().add(proxiedPlayer.getName()); - }); + Arrays.stream(event.getResponse().getPlayers().getSample()).forEach(proxiedPlayer -> + geyserPingInfo.getPlayerList().add(proxiedPlayer.getName())); } return geyserPingInfo; } diff --git a/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/GeyserSpigotDumpInfo.java b/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/GeyserSpigotDumpInfo.java index 03fa0850a..a929e3237 100644 --- a/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/GeyserSpigotDumpInfo.java +++ b/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/GeyserSpigotDumpInfo.java @@ -37,13 +37,13 @@ import java.util.List; @Getter public class GeyserSpigotDumpInfo extends BootstrapDumpInfo { - private String platformName; - private String platformVersion; - private String platformAPIVersion; - private boolean onlineMode; - private String serverIP; - private int serverPort; - private List plugins; + private final String platformName; + private final String platformVersion; + private final String platformAPIVersion; + private final boolean onlineMode; + private final String serverIP; + private final int serverPort; + private final List plugins; GeyserSpigotDumpInfo() { super(); diff --git a/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/GeyserSpigotPingPassthrough.java b/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/GeyserSpigotPingPassthrough.java index 20bfecb65..c34d96db2 100644 --- a/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/GeyserSpigotPingPassthrough.java +++ b/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/GeyserSpigotPingPassthrough.java @@ -34,6 +34,7 @@ import org.bukkit.util.CachedServerIcon; import org.geysermc.connector.common.ping.GeyserPingInfo; import org.geysermc.connector.ping.IGeyserPingPassthrough; +import javax.annotation.Nonnull; import java.net.InetAddress; import java.net.InetSocketAddress; import java.util.Collections; @@ -72,9 +73,10 @@ public class GeyserSpigotPingPassthrough implements IGeyserPingPassthrough { public void setServerIcon(CachedServerIcon icon) throws IllegalArgumentException, UnsupportedOperationException { } + @Nonnull @Override public Iterator iterator() throws UnsupportedOperationException { - return Collections.EMPTY_LIST.iterator(); + return Collections.emptyIterator(); } } diff --git a/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/GeyserSpigotPlugin.java b/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/GeyserSpigotPlugin.java index 881a9caf9..fc810c418 100644 --- a/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/GeyserSpigotPlugin.java +++ b/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/GeyserSpigotPlugin.java @@ -150,7 +150,7 @@ public class GeyserSpigotPlugin extends JavaPlugin implements GeyserBootstrap { this.geyserSpigotPingPassthrough = new GeyserSpigotPingPassthrough(geyserLogger); } - this.geyserCommandManager = new GeyserSpigotCommandManager(this, connector); + this.geyserCommandManager = new GeyserSpigotCommandManager(connector); boolean isViaVersion = Bukkit.getPluginManager().getPlugin("ViaVersion") != null; if (isViaVersion) { diff --git a/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/command/GeyserSpigotCommandManager.java b/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/command/GeyserSpigotCommandManager.java index c0c239b00..a0e958503 100644 --- a/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/command/GeyserSpigotCommandManager.java +++ b/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/command/GeyserSpigotCommandManager.java @@ -30,7 +30,6 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandMap; import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.command.CommandManager; -import org.geysermc.platform.spigot.GeyserSpigotPlugin; import java.lang.reflect.Field; @@ -48,12 +47,8 @@ public class GeyserSpigotCommandManager extends CommandManager { } } - private GeyserSpigotPlugin plugin; - - public GeyserSpigotCommandManager(GeyserSpigotPlugin plugin, GeyserConnector connector) { + public GeyserSpigotCommandManager(GeyserConnector connector) { super(connector); - - this.plugin = plugin; } @Override diff --git a/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/world/manager/GeyserSpigot1_12WorldManager.java b/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/world/manager/GeyserSpigot1_12WorldManager.java index dadab7c46..b50aefee7 100644 --- a/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/world/manager/GeyserSpigot1_12WorldManager.java +++ b/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/world/manager/GeyserSpigot1_12WorldManager.java @@ -93,7 +93,6 @@ public class GeyserSpigot1_12WorldManager extends GeyserSpigotWorldManager { * @param z Z coordinate of block * @return the block state updated to the latest Minecraft version */ - @SuppressWarnings("deprecation") public int getLegacyBlock(BlockStorage storage, int blockId, int x, int y, int z) { // Convert block state from old version (1.12.2) -> 1.13 -> 1.13.1 -> 1.14 -> 1.15 -> 1.16 -> 1.16.2 blockId = mappingData1_12to1_13.getNewBlockId(blockId); diff --git a/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongeDumpInfo.java b/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongeDumpInfo.java index d36ba3110..2872e5abc 100644 --- a/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongeDumpInfo.java +++ b/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongeDumpInfo.java @@ -36,13 +36,12 @@ import java.util.List; @Getter public class GeyserSpongeDumpInfo extends BootstrapDumpInfo { - - private String platformName; - private String platformVersion; - private boolean onlineMode; - private String serverIP; - private int serverPort; - private List plugins; + private final String platformName; + private final String platformVersion; + private final boolean onlineMode; + private final String serverIP; + private final int serverPort; + private final List plugins; GeyserSpongeDumpInfo() { super(); diff --git a/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/command/GeyserSpongeCommandExecutor.java b/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/command/GeyserSpongeCommandExecutor.java index 8ef23b19e..0e46413cc 100644 --- a/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/command/GeyserSpongeCommandExecutor.java +++ b/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/command/GeyserSpongeCommandExecutor.java @@ -33,7 +33,6 @@ import org.geysermc.connector.common.ChatColor; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.utils.LanguageUtils; import org.spongepowered.api.command.CommandCallable; -import org.spongepowered.api.command.CommandException; import org.spongepowered.api.command.CommandResult; import org.spongepowered.api.command.CommandSource; import org.spongepowered.api.text.Text; @@ -81,7 +80,7 @@ public class GeyserSpongeCommandExecutor extends CommandExecutor implements Comm } @Override - public List getSuggestions(CommandSource source, String arguments, @Nullable Location targetPosition) throws CommandException { + public List getSuggestions(CommandSource source, String arguments, @Nullable Location targetPosition) { if (arguments.split(" ").length == 1) { return connector.getCommandManager().getCommandNames(); } diff --git a/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/command/GeyserSpongeCommandManager.java b/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/command/GeyserSpongeCommandManager.java index 1f6eaa695..38d8ba606 100644 --- a/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/command/GeyserSpongeCommandManager.java +++ b/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/command/GeyserSpongeCommandManager.java @@ -32,8 +32,7 @@ import org.spongepowered.api.command.CommandMapping; import org.spongepowered.api.text.Text; public class GeyserSpongeCommandManager extends CommandManager { - - private org.spongepowered.api.command.CommandManager handle; + private final org.spongepowered.api.command.CommandManager handle; public GeyserSpongeCommandManager(org.spongepowered.api.command.CommandManager handle, GeyserConnector connector) { super(connector); @@ -43,6 +42,8 @@ public class GeyserSpongeCommandManager extends CommandManager { @Override public String getDescription(String command) { - return handle.get(command).map(CommandMapping::getCallable).map(callable -> callable.getShortDescription(Sponge.getServer().getConsole()).orElse(Text.EMPTY)).orElse(Text.EMPTY).toPlain(); + return handle.get(command).map(CommandMapping::getCallable) + .map(callable -> callable.getShortDescription(Sponge.getServer().getConsole()).orElse(Text.EMPTY)) + .orElse(Text.EMPTY).toPlain(); } } diff --git a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserStandaloneDumpInfo.java b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserStandaloneDumpInfo.java index 2577ce033..f7716b5a2 100644 --- a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserStandaloneDumpInfo.java +++ b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/GeyserStandaloneDumpInfo.java @@ -30,8 +30,7 @@ import org.geysermc.connector.dump.BootstrapDumpInfo; @Getter public class GeyserStandaloneDumpInfo extends BootstrapDumpInfo { - - private boolean isGui; + private final boolean isGui; GeyserStandaloneDumpInfo(GeyserStandaloneBootstrap bootstrap) { super(); diff --git a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/LoopbackUtil.java b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/LoopbackUtil.java index 7eeba84bd..5db34dbab 100644 --- a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/LoopbackUtil.java +++ b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/LoopbackUtil.java @@ -30,7 +30,6 @@ import org.geysermc.connector.utils.LanguageUtils; import java.io.InputStream; import java.nio.file.Files; -import java.nio.file.OpenOption; import java.nio.file.Paths; public class LoopbackUtil { @@ -54,7 +53,7 @@ public class LoopbackUtil { String result = sb.toString(); if (!result.contains("minecraftuwp")) { - Files.write(Paths.get(System.getenv("temp") + "/loopback_minecraft.bat"), loopbackCommand.getBytes(), new OpenOption[0]); + Files.write(Paths.get(System.getenv("temp") + "/loopback_minecraft.bat"), loopbackCommand.getBytes()); Runtime.getRuntime().exec(startScript); geyserLogger.info(ChatColor.AQUA + LanguageUtils.getLocaleStringLog("geyser.bootstrap.loopback.added")); diff --git a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/gui/ColorPane.java b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/gui/ColorPane.java index 103093954..db5c4a3e1 100644 --- a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/gui/ColorPane.java +++ b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/gui/ColorPane.java @@ -60,8 +60,8 @@ public class ColorPane extends JTextPane { */ public void appendANSI(String s) { // convert ANSI color codes first int aPos = 0; // current char position in addString - int aIndex = 0; // index of next Escape sequence - int mIndex = 0; // index of "m" terminating Escape sequence + int aIndex; // index of next Escape sequence + int mIndex; // index of "m" terminating Escape sequence String tmpString = ""; boolean stillSearching = true; // true until no more Escape sequences String addString = remaining + s; @@ -83,7 +83,6 @@ public class ColorPane extends JTextPane { // while there's text in the input buffer - stillSearching = true; while (stillSearching) { mIndex = addString.indexOf("m", aPos); // find the end of the escape sequence if (mIndex < 0) { // the buffer ends halfway through the ansi string! diff --git a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/gui/GraphPanel.java b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/gui/GraphPanel.java index ebcc8f82c..68adfde52 100644 --- a/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/gui/GraphPanel.java +++ b/bootstrap/standalone/src/main/java/org/geysermc/platform/standalone/gui/GraphPanel.java @@ -46,7 +46,7 @@ public final class GraphPanel extends JPanel { private final static Color pointColor = new Color(100, 100, 100, 255); private final static Color gridColor = new Color(200, 200, 200, 255); private static final Stroke graphStroke = new BasicStroke(2f); - private List values = new ArrayList<>(10); + private final List values = new ArrayList<>(10); @Setter private String xLabel = ""; @@ -172,6 +172,7 @@ public final class GraphPanel extends JPanel { for (Point graphPoint : graphPoints) { final int x = graphPoint.x - pointWidth / 2; final int y = graphPoint.y - pointWidth / 2; + //noinspection SuspiciousNameCombination g.fillOval(x, y, pointWidth, pointWidth); } } diff --git a/bootstrap/velocity/src/main/java/org/geysermc/platform/velocity/GeyserVelocityDumpInfo.java b/bootstrap/velocity/src/main/java/org/geysermc/platform/velocity/GeyserVelocityDumpInfo.java index b5a8c6c10..93af72d84 100644 --- a/bootstrap/velocity/src/main/java/org/geysermc/platform/velocity/GeyserVelocityDumpInfo.java +++ b/bootstrap/velocity/src/main/java/org/geysermc/platform/velocity/GeyserVelocityDumpInfo.java @@ -37,13 +37,13 @@ import java.util.List; @Getter public class GeyserVelocityDumpInfo extends BootstrapDumpInfo { - private String platformName; - private String platformVersion; - private String platformVendor; - private boolean onlineMode; - private String serverIP; - private int serverPort; - private List plugins; + private final String platformName; + private final String platformVersion; + private final String platformVendor; + private final boolean onlineMode; + private final String serverIP; + private final int serverPort; + private final List plugins; GeyserVelocityDumpInfo(ProxyServer proxy) { super(); diff --git a/connector/src/main/java/org/geysermc/connector/command/defaults/HelpCommand.java b/connector/src/main/java/org/geysermc/connector/command/defaults/HelpCommand.java index c2716f206..53968e40b 100644 --- a/connector/src/main/java/org/geysermc/connector/command/defaults/HelpCommand.java +++ b/connector/src/main/java/org/geysermc/connector/command/defaults/HelpCommand.java @@ -38,8 +38,7 @@ import java.util.Map; import java.util.stream.Collectors; public class HelpCommand extends GeyserCommand { - - public GeyserConnector connector; + private final GeyserConnector connector; public HelpCommand(GeyserConnector connector, String name, String description, String permission) { super(name, description, permission); diff --git a/connector/src/main/java/org/geysermc/connector/command/defaults/ListCommand.java b/connector/src/main/java/org/geysermc/connector/command/defaults/ListCommand.java index 8a000f80c..915a062a7 100644 --- a/connector/src/main/java/org/geysermc/connector/command/defaults/ListCommand.java +++ b/connector/src/main/java/org/geysermc/connector/command/defaults/ListCommand.java @@ -45,8 +45,7 @@ public class ListCommand extends GeyserCommand { @Override public void execute(GeyserSession session, CommandSender sender, String[] args) { - String message = ""; - message = LanguageUtils.getPlayerLocaleString("geyser.commands.list.message", sender.getLocale(), + String message = LanguageUtils.getPlayerLocaleString("geyser.commands.list.message", sender.getLocale(), connector.getPlayers().size(), connector.getPlayers().stream().map(GeyserSession::getName).collect(Collectors.joining(" "))); diff --git a/connector/src/main/java/org/geysermc/connector/common/main/IGeyserMain.java b/connector/src/main/java/org/geysermc/connector/common/main/IGeyserMain.java index f91da11b5..8490dc7f2 100644 --- a/connector/src/main/java/org/geysermc/connector/common/main/IGeyserMain.java +++ b/connector/src/main/java/org/geysermc/connector/common/main/IGeyserMain.java @@ -84,7 +84,8 @@ public class IGeyserMain { Class graphicsEnvironment = Class.forName("java.awt.GraphicsEnvironment"); Method isHeadless = graphicsEnvironment.getDeclaredMethod("isHeadless"); return (Boolean)isHeadless.invoke(null); - } catch (Exception ex) { } + } catch (Exception ignored) { + } return true; } diff --git a/connector/src/main/java/org/geysermc/connector/entity/FireworkEntity.java b/connector/src/main/java/org/geysermc/connector/entity/FireworkEntity.java index ad29c4b3f..4a05dfc03 100644 --- a/connector/src/main/java/org/geysermc/connector/entity/FireworkEntity.java +++ b/connector/src/main/java/org/geysermc/connector/entity/FireworkEntity.java @@ -135,22 +135,27 @@ public class FireworkEntity extends Entity { NbtMapBuilder builder = NbtMap.builder(); builder.put("Fireworks", fireworksBuilder.build()); metadata.put(EntityData.DISPLAY_ITEM, builder.build()); - } else if (entityMetadata.getId() == 9 && !entityMetadata.getValue().equals(OptionalInt.empty()) && ((OptionalInt) entityMetadata.getValue()).getAsInt() == session.getPlayerEntity().getEntityId()) { - //Checks if the firework has an entity ID (used when a player is gliding) and checks to make sure the player that is gliding is the one getting sent the packet or else every player near the gliding player will boost too. - PlayerEntity entity = session.getPlayerEntity(); - float yaw = entity.getRotation().getX(); - float pitch = entity.getRotation().getY(); - //Uses math from NukkitX - entity.setMotion(Vector3f.from( - -Math.sin(Math.toRadians(yaw)) * Math.cos(Math.toRadians(pitch)) * 2, - -Math.sin(Math.toRadians(pitch)) * 2, - Math.cos(Math.toRadians(yaw)) * Math.cos(Math.toRadians(pitch)) * 2)); - //Need to update the EntityMotionPacket or else the player won't boost - SetEntityMotionPacket entityMotionPacket = new SetEntityMotionPacket(); - entityMotionPacket.setRuntimeEntityId(entity.getGeyserId()); - entityMotionPacket.setMotion(entity.getMotion()); + } else if (entityMetadata.getId() == 9) { + OptionalInt optional = (OptionalInt) entityMetadata.getValue(); + // Checks if the firework has an entity ID (used when a player is gliding) + // and checks to make sure the player that is gliding is the one getting sent the packet + // or else every player near the gliding player will boost too. + if (optional.isPresent() && optional.getAsInt() == session.getPlayerEntity().getEntityId()) { + PlayerEntity entity = session.getPlayerEntity(); + float yaw = entity.getRotation().getX(); + float pitch = entity.getRotation().getY(); + // Uses math from NukkitX + entity.setMotion(Vector3f.from( + -Math.sin(Math.toRadians(yaw)) * Math.cos(Math.toRadians(pitch)) * 2, + -Math.sin(Math.toRadians(pitch)) * 2, + Math.cos(Math.toRadians(yaw)) * Math.cos(Math.toRadians(pitch)) * 2)); + // Need to update the EntityMotionPacket or else the player won't boost + SetEntityMotionPacket entityMotionPacket = new SetEntityMotionPacket(); + entityMotionPacket.setRuntimeEntityId(entity.getGeyserId()); + entityMotionPacket.setMotion(entity.getMotion()); - session.sendUpstreamPacket(entityMotionPacket); + session.sendUpstreamPacket(entityMotionPacket); + } } super.updateBedrockMetadata(entityMetadata, session); diff --git a/connector/src/main/java/org/geysermc/connector/inventory/Inventory.java b/connector/src/main/java/org/geysermc/connector/inventory/Inventory.java index 664781763..c2a8ddca1 100644 --- a/connector/src/main/java/org/geysermc/connector/inventory/Inventory.java +++ b/connector/src/main/java/org/geysermc/connector/inventory/Inventory.java @@ -53,7 +53,7 @@ public class Inventory { @Setter protected String title; - protected GeyserItemStack[] items; + protected final GeyserItemStack[] items; /** * The location of the inventory block. Will either be a fake block above the player's head, or the actual block location diff --git a/connector/src/main/java/org/geysermc/connector/network/LoggingPacketHandler.java b/connector/src/main/java/org/geysermc/connector/network/LoggingPacketHandler.java index eef890edf..9be9dc9c8 100644 --- a/connector/src/main/java/org/geysermc/connector/network/LoggingPacketHandler.java +++ b/connector/src/main/java/org/geysermc/connector/network/LoggingPacketHandler.java @@ -38,9 +38,8 @@ import org.geysermc.connector.network.session.GeyserSession; * packets of interest and limit boilerplate code. */ public class LoggingPacketHandler implements BedrockPacketHandler { - - protected GeyserConnector connector; - protected GeyserSession session; + protected final GeyserConnector connector; + protected final GeyserSession session; LoggingPacketHandler(GeyserConnector connector, GeyserSession session) { this.connector = connector; @@ -759,9 +758,6 @@ public class LoggingPacketHandler implements BedrockPacketHandler { return defaultHandler(packet); } - // I question if God exists because of this packet - God does not exist if I find out there's a built-in dab - // TODO for the future: redirect this as a /me command - // TODO for the far future: should we have a client mod that handles skins, handle these too @Override public boolean handle(EmoteListPacket packet) { return defaultHandler(packet); diff --git a/connector/src/main/java/org/geysermc/connector/network/QueryPacketHandler.java b/connector/src/main/java/org/geysermc/connector/network/QueryPacketHandler.java index 87541f704..2d8f7d17c 100644 --- a/connector/src/main/java/org/geysermc/connector/network/QueryPacketHandler.java +++ b/connector/src/main/java/org/geysermc/connector/network/QueryPacketHandler.java @@ -83,7 +83,7 @@ public class QueryPacketHandler { * @return if the packet is a query packet */ private boolean isQueryPacket(ByteBuf buffer) { - return (buffer.readableBytes() >= 2) ? buffer.readUnsignedShort() == 0xFEFD : false; + return buffer.readableBytes() >= 2 && buffer.readUnsignedShort() == 0xFEFD; } /** diff --git a/connector/src/main/java/org/geysermc/connector/network/session/cache/BossBar.java b/connector/src/main/java/org/geysermc/connector/network/session/cache/BossBar.java index c1ba6fff1..28ac9459e 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/cache/BossBar.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/cache/BossBar.java @@ -37,15 +37,14 @@ import org.geysermc.connector.network.translators.chat.MessageTranslator; @AllArgsConstructor public class BossBar { + private final GeyserSession session; - private GeyserSession session; - - private long entityId; + private final long entityId; private Component title; private float health; - private int color; - private int overlay; - private int darkenSky; + private final int color; + private final int overlay; + private final int darkenSky; public void addBossBar() { addBossEntity(); diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockMapInfoRequestTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockMapInfoRequestTranslator.java index 6d6ee5b25..b997644c7 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockMapInfoRequestTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockMapInfoRequestTranslator.java @@ -39,16 +39,13 @@ public class BedrockMapInfoRequestTranslator extends PacketTranslator { - ClientboundMapItemDataPacket mapPacket = session.getStoredMaps().remove(mapID); - if (mapPacket != null) { - session.sendUpstreamPacket(mapPacket); - } - }, 100, TimeUnit.MILLISECONDS); + GeyserConnector.getInstance().getGeneralThreadPool().schedule(() -> session.sendUpstreamPacket(mapPacket), + 100, TimeUnit.MILLISECONDS); } } } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/chat/MinecraftTranslationRegistry.java b/connector/src/main/java/org/geysermc/connector/network/translators/chat/MinecraftTranslationRegistry.java index 95bf7b3de..a003fc912 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/chat/MinecraftTranslationRegistry.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/chat/MinecraftTranslationRegistry.java @@ -31,6 +31,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.connector.utils.LocaleUtils; +import javax.annotation.Nonnull; import java.text.MessageFormat; import java.util.Locale; import java.util.regex.Matcher; @@ -42,7 +43,7 @@ import java.util.regex.Pattern; */ public class MinecraftTranslationRegistry implements Translator { @Override - public @NonNull Key name() { + public @Nonnull Key name() { return Key.key("geyser", "minecraft_translations"); } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/collision/CollisionRemapper.java b/connector/src/main/java/org/geysermc/connector/network/translators/collision/CollisionRemapper.java index aa0180caa..e582d0959 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/collision/CollisionRemapper.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/collision/CollisionRemapper.java @@ -25,7 +25,6 @@ package org.geysermc.connector.network.translators.collision; -import java.lang.annotation.Repeatable; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemEntry.java b/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemEntry.java index 5acaa2e26..74ce0951f 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemEntry.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemEntry.java @@ -34,8 +34,7 @@ import org.geysermc.connector.network.translators.world.block.BlockTranslator1_1 @AllArgsConstructor @ToString public class ItemEntry { - - public static ItemEntry AIR = new ItemEntry("minecraft:air", "minecraft:air", 0, 0, 0, + public static final ItemEntry AIR = new ItemEntry("minecraft:air", "minecraft:air", 0, 0, 0, BlockTranslator1_17_0.INSTANCE.getBedrockAirId(), 64); private final String javaIdentifier; diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemTranslator.java index afb520881..2c6119241 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemTranslator.java @@ -296,7 +296,7 @@ public abstract class ItemTranslator { ListTag listTag = (ListTag) tag; List tagList = new ArrayList<>(); - for (com.github.steveice10.opennbt.tag.builtin.Tag value : listTag) { + for (Tag value : listTag) { tagList.add(translateToBedrockNBT(value)); } NbtType type = NbtType.COMPOUND; diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/BannerTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/BannerTranslator.java index b127e1928..fb1256e40 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/BannerTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/BannerTranslator.java @@ -131,8 +131,8 @@ public class BannerTranslator extends ItemTranslator { */ public static ListTag convertBannerPattern(List patterns) { List tagsList = new ArrayList<>(); - for (Object patternTag : patterns) { - tagsList.add(getJavaBannerPattern((NbtMap) patternTag)); + for (NbtMap patternTag : patterns) { + tagsList.add(getJavaBannerPattern(patternTag)); } return new ListTag("Patterns", tagsList); diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/BasicItemTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/BasicItemTranslator.java index efb50a767..e52bed2c7 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/BasicItemTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/BasicItemTranslator.java @@ -29,12 +29,9 @@ import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.ListTag; import com.github.steveice10.opennbt.tag.builtin.StringTag; import com.github.steveice10.opennbt.tag.builtin.Tag; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.TextComponent; -import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; -import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.ItemRemapper; +import org.geysermc.connector.network.translators.chat.MessageTranslator; import org.geysermc.connector.network.translators.item.ItemEntry; import org.geysermc.connector.network.translators.item.NbtItemStackTranslator; @@ -46,27 +43,17 @@ public class BasicItemTranslator extends NbtItemStackTranslator { @Override public void translateToBedrock(GeyserSession session, CompoundTag itemTag, ItemEntry itemEntry) { - if (!itemTag.contains("display")) { + CompoundTag displayTag = itemTag.get("display"); + if (displayTag == null) { return; } - CompoundTag displayTag = itemTag.get("display"); - if (displayTag.contains("Name")) { - StringTag nameTag = displayTag.get("Name"); - try { - displayTag.put(new StringTag("Name", toBedrockMessage(nameTag))); - } catch (Exception ex) { - } - } - if (displayTag.contains("Lore")) { - ListTag loreTag = displayTag.get("Lore"); + ListTag loreTag = displayTag.get("Lore"); + if (loreTag != null) { List lore = new ArrayList<>(); for (Tag tag : loreTag.getValue()) { - if (!(tag instanceof StringTag)) return; - try { - lore.add(new StringTag("", toBedrockMessage((StringTag) tag))); - } catch (Exception ex) { - } + if (!(tag instanceof StringTag)) continue; + lore.add(new StringTag("", MessageTranslator.convertMessageLenient(((StringTag) tag).getValue(), session.getLocale()))); } displayTag.put(new ListTag("Lore", lore)); } @@ -74,54 +61,24 @@ public class BasicItemTranslator extends NbtItemStackTranslator { @Override public void translateToJava(CompoundTag itemTag, ItemEntry itemEntry) { - if (!itemTag.contains("display")) { + CompoundTag displayTag = itemTag.get("display"); + if (displayTag == null) { return; } - CompoundTag displayTag = itemTag.get("display"); + if (displayTag.contains("Name")) { StringTag nameTag = displayTag.get("Name"); - displayTag.put(new StringTag("Name", toJavaMessage(nameTag))); + displayTag.put(new StringTag("Name", MessageTranslator.convertToJavaMessage(nameTag.getValue()))); } if (displayTag.contains("Lore")) { ListTag loreTag = displayTag.get("Lore"); List lore = new ArrayList<>(); for (Tag tag : loreTag.getValue()) { - if (!(tag instanceof StringTag)) return; - lore.add(new StringTag("", "§r" + toJavaMessage((StringTag) tag))); + if (!(tag instanceof StringTag)) continue; + lore.add(new StringTag("", MessageTranslator.convertToJavaMessage(((StringTag) tag).getValue()))); } displayTag.put(new ListTag("Lore", lore)); } } - - private String toJavaMessage(StringTag tag) { - String message = tag.getValue(); - if (message == null) return null; - if (message.startsWith("§r")) { - message = message.replaceFirst("§r", ""); - } - Component component = Component.text(message); - return GsonComponentSerializer.gson().serialize(component); - } - - private String toBedrockMessage(StringTag tag) { - String message = tag.getValue(); - if (message == null) return null; - TextComponent component = (TextComponent) GsonComponentSerializer.gson().deserialize(message); - String legacy = LegacyComponentSerializer.legacySection().serialize(component); - if (hasFormatting(LegacyComponentSerializer.legacySection().deserialize(legacy))) { - return "§r" + legacy; - } - return legacy; - } - - private boolean hasFormatting(Component component) { - if (component.hasStyling()) return true; - for (Component child : component.children()) { - if (hasFormatting(child)) { - return true; - } - } - return false; - } } 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 45e65f475..0dd7cb950 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 @@ -55,7 +55,6 @@ public class JavaBossBarTranslator extends PacketTranslator case UPDATE_STYLE: case UPDATE_FLAGS: //todo - return; } } } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUpdateTileEntityTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUpdateTileEntityTranslator.java index 00d887895..0f2cb8814 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUpdateTileEntityTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaUpdateTileEntityTranslator.java @@ -29,6 +29,7 @@ import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode; import com.github.steveice10.mc.protocol.data.game.world.block.UpdatedTileType; import com.github.steveice10.mc.protocol.packet.ingame.server.world.ServerUpdateTileEntityPacket; import com.nukkitx.math.vector.Vector3i; +import com.nukkitx.nbt.NbtMap; import com.nukkitx.protocol.bedrock.data.inventory.ContainerType; import com.nukkitx.protocol.bedrock.packet.ContainerOpenPacket; import org.geysermc.connector.network.session.GeyserSession; @@ -47,7 +48,7 @@ public class JavaUpdateTileEntityTranslator extends PacketTranslator { diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/sound/SoundRegistry.java b/connector/src/main/java/org/geysermc/connector/network/translators/sound/SoundRegistry.java index 8ebca00ec..90599eb19 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/sound/SoundRegistry.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/sound/SoundRegistry.java @@ -70,7 +70,7 @@ public class SoundRegistry { brMap.has("playsound_mapping") && brMap.get("playsound_mapping").isTextual() ? brMap.get("playsound_mapping").asText() : null, brMap.has("extra_data") && brMap.get("extra_data").isInt() ? brMap.get("extra_data").asInt() : -1, brMap.has("identifier") && brMap.get("identifier").isTextual() ? brMap.get("identifier").asText() : null, - brMap.has("level_event") && brMap.get("level_event").isBoolean() ? brMap.get("level_event").asBoolean() : false + brMap.has("level_event") && brMap.get("level_event").isBoolean() && brMap.get("level_event").asBoolean() ) ); } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/sound/block/BucketSoundInteractionHandler.java b/connector/src/main/java/org/geysermc/connector/network/translators/sound/block/BucketSoundInteractionHandler.java index afb9ccc6a..227b29521 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/sound/block/BucketSoundInteractionHandler.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/sound/block/BucketSoundInteractionHandler.java @@ -29,7 +29,6 @@ import com.nukkitx.math.vector.Vector3f; import com.nukkitx.protocol.bedrock.data.SoundEvent; import com.nukkitx.protocol.bedrock.packet.LevelSoundEventPacket; import org.geysermc.connector.network.session.GeyserSession; -import org.geysermc.connector.network.translators.item.ItemRegistry; import org.geysermc.connector.network.translators.sound.BlockSoundInteractionHandler; import org.geysermc.connector.network.translators.sound.SoundHandler; diff --git a/connector/src/main/java/org/geysermc/connector/ping/GeyserLegacyPingPassthrough.java b/connector/src/main/java/org/geysermc/connector/ping/GeyserLegacyPingPassthrough.java index a8af51bf5..a1a2d474b 100644 --- a/connector/src/main/java/org/geysermc/connector/ping/GeyserLegacyPingPassthrough.java +++ b/connector/src/main/java/org/geysermc/connector/ping/GeyserLegacyPingPassthrough.java @@ -43,8 +43,7 @@ import java.net.SocketTimeoutException; import java.util.concurrent.TimeUnit; public class GeyserLegacyPingPassthrough implements IGeyserPingPassthrough, Runnable { - - private GeyserConnector connector; + private final GeyserConnector connector; public GeyserLegacyPingPassthrough(GeyserConnector connector) { this.connector = connector; diff --git a/connector/src/main/java/org/geysermc/connector/utils/BedrockMapIcon.java b/connector/src/main/java/org/geysermc/connector/utils/BedrockMapIcon.java index c7727cd62..95e0f809d 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/BedrockMapIcon.java +++ b/connector/src/main/java/org/geysermc/connector/utils/BedrockMapIcon.java @@ -58,22 +58,17 @@ public enum BedrockMapIcon { private static final BedrockMapIcon[] VALUES = values(); - private MapIconType iconType; + private final MapIconType iconType; @Getter - private int iconID; + private final int iconID; - private int red; - private int green; - private int blue; + private final int red; + private final int green; + private final int blue; BedrockMapIcon(MapIconType iconType, int iconID) { - this.iconType = iconType; - this.iconID = iconID; - - this.red = 255; - this.green = 255; - this.blue = 255; + this(iconType, iconID, 255, 255, 255); } BedrockMapIcon(MapIconType iconType, int iconID, int red, int green, int blue) { @@ -107,11 +102,11 @@ public enum BedrockMapIcon { * @return ARGB as an int */ public int toARGB() { - int alpha = 255; + final int alpha = 255; return ((alpha & 0xFF) << 24) | ((red & 0xFF) << 16) | ((green & 0xFF) << 8) | - ((blue & 0xFF) << 0); + (blue & 0xFF); } } diff --git a/connector/src/main/java/org/geysermc/connector/utils/BlockEntityUtils.java b/connector/src/main/java/org/geysermc/connector/utils/BlockEntityUtils.java index 0c570dae6..d932c7d24 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/BlockEntityUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/BlockEntityUtils.java @@ -32,6 +32,8 @@ import com.nukkitx.protocol.bedrock.packet.BlockEntityDataPacket; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.world.block.entity.BlockEntityTranslator; +import javax.annotation.Nonnull; + public class BlockEntityUtils { private static final BlockEntityTranslator EMPTY_TRANSLATOR = BlockEntityTranslator.BLOCK_ENTITY_TRANSLATORS.get("Empty"); @@ -66,11 +68,11 @@ public class BlockEntityUtils { return EMPTY_TRANSLATOR; } - public static void updateBlockEntity(GeyserSession session, NbtMap blockEntity, Position position) { + public static void updateBlockEntity(GeyserSession session, @Nonnull NbtMap blockEntity, Position position) { updateBlockEntity(session, blockEntity, Vector3i.from(position.getX(), position.getY(), position.getZ())); } - public static void updateBlockEntity(GeyserSession session, NbtMap blockEntity, Vector3i position) { + public static void updateBlockEntity(GeyserSession session, @Nonnull NbtMap blockEntity, Vector3i position) { BlockEntityDataPacket blockEntityPacket = new BlockEntityDataPacket(); blockEntityPacket.setBlockPosition(position); blockEntityPacket.setData(blockEntity); 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 eecae8e4f..3fb5c2ebb 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/FileUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/FileUtils.java @@ -205,7 +205,8 @@ public class FileUtils { URL resource = FileUtils.class.getClassLoader().getResource("META-INF/reflections/" + path + "-reflections.xml"); try (InputStream inputStream = resource.openConnection().getInputStream()) { reflections.merge(serializer.read(inputStream)); - } catch (IOException e) { } + } catch (IOException ignored) { + } return reflections; } diff --git a/connector/src/main/java/org/geysermc/connector/utils/GameRule.java b/connector/src/main/java/org/geysermc/connector/utils/GameRule.java index a4e4ef231..ca8ce3d3b 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/GameRule.java +++ b/connector/src/main/java/org/geysermc/connector/utils/GameRule.java @@ -71,13 +71,13 @@ public enum GameRule { private static final GameRule[] VALUES = values(); @Getter - private String javaID; + private final String javaID; @Getter - private Class type; + private final Class type; @Getter - private Object defaultValue; + private final Object defaultValue; GameRule(String javaID, Class type) { this(javaID, type, null); 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 db5457244..7e32553b6 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/LocaleUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/LocaleUtils.java @@ -136,7 +136,7 @@ public class LocaleUtils { // Check if we have already downloaded the locale file if (localeFile.exists()) { String curHash = ""; - String targetHash = ""; + String targetHash; if (locale.equals("en_us")) { try { diff --git a/connector/src/main/java/org/geysermc/connector/utils/MapColor.java b/connector/src/main/java/org/geysermc/connector/utils/MapColor.java index f37527413..893aa0b85 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/MapColor.java +++ b/connector/src/main/java/org/geysermc/connector/utils/MapColor.java @@ -287,6 +287,6 @@ public enum MapColor { return ((alpha & 0xFF) << 24) | ((blue & 0xFF) << 16) | ((green & 0xFF) << 8) | - ((red & 0xFF) << 0); + (red & 0xFF); } } \ No newline at end of file diff --git a/connector/src/main/java/org/geysermc/connector/utils/SettingsUtils.java b/connector/src/main/java/org/geysermc/connector/utils/SettingsUtils.java index 0e2a54a3c..1bd89de60 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/SettingsUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/SettingsUtils.java @@ -34,8 +34,6 @@ import org.geysermc.cumulus.CustomForm; import org.geysermc.cumulus.component.DropdownComponent; import org.geysermc.cumulus.response.CustomFormResponse; -import java.util.ArrayList; - public class SettingsUtils { /** * Build a settings form for the given session and store it for later From 65c52f9ff0447672939233d594024d383e9bda8f Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Mon, 21 Jun 2021 18:51:43 -0400 Subject: [PATCH 02/19] Fix fishing rod durability (fixes #1964) --- .../inventory/InventoryTranslator.java | 3 +- .../translators/item/ItemRegistry.java | 7 ++ .../translators/item/ItemTranslator.java | 6 +- .../translators/nbt/BasicItemTranslator.java | 16 ++- .../geysermc/connector/utils/ItemUtils.java | 108 ++++++++++-------- 5 files changed, 85 insertions(+), 55 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/InventoryTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/InventoryTranslator.java index 4a45b5c9f..c8af7f38f 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/inventory/InventoryTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/inventory/InventoryTranslator.java @@ -56,6 +56,7 @@ import org.geysermc.connector.network.translators.inventory.translators.furnace. import org.geysermc.connector.network.translators.inventory.translators.furnace.FurnaceInventoryTranslator; import org.geysermc.connector.network.translators.inventory.translators.furnace.SmokerInventoryTranslator; import org.geysermc.connector.utils.InventoryUtils; +import org.geysermc.connector.utils.ItemUtils; import java.util.*; @@ -865,7 +866,7 @@ public abstract class InventoryTranslator { if (itemStack.getNbt() != null) { Tag damage = itemStack.getNbt().get("Damage"); if (damage instanceof IntTag) { - durability = ((IntTag) damage).getValue(); + durability = ItemUtils.getCorrectBedrockDurability(itemStack.getJavaId(), ((IntTag) damage).getValue()); } } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemRegistry.java b/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemRegistry.java index 1288930f5..4d8a50e85 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemRegistry.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemRegistry.java @@ -98,6 +98,10 @@ public class ItemRegistry { * Crossbow item entry, used in PillagerEntity.java */ public static ItemEntry CROSSBOW; + /** + * Fishing rod item entry, used in ItemUtils.java + */ + public static ItemEntry FISHING_ROD; /** * Empty item bucket, used in BedrockInventoryTransactionTranslator.java */ @@ -438,6 +442,9 @@ public class ItemRegistry { case "minecraft:egg": EGG = itemEntry; break; + case "minecraft:fishing_rod": + FISHING_ROD = itemEntry; + break; case "minecraft:shield": SHIELD = itemEntry; break; diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemTranslator.java index 2c6119241..c2bef9c6d 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/item/ItemTranslator.java @@ -226,14 +226,14 @@ public abstract class ItemTranslator { public ItemStack translateToJava(ItemData itemData, ItemEntry itemEntry) { if (itemData == null) return null; if (itemData.getTag() == null) { - return new ItemStack(itemEntry.getJavaId(), itemData.getCount(), new com.github.steveice10.opennbt.tag.builtin.CompoundTag("")); + return new ItemStack(itemEntry.getJavaId(), itemData.getCount(), new CompoundTag("")); } return new ItemStack(itemEntry.getJavaId(), itemData.getCount(), this.translateToJavaNBT("", itemData.getTag())); } public abstract List getAppliedItems(); - public NbtMap translateNbtToBedrock(com.github.steveice10.opennbt.tag.builtin.CompoundTag tag) { + public NbtMap translateNbtToBedrock(CompoundTag tag) { NbtMapBuilder builder = NbtMap.builder(); if (tag.getValue() != null && !tag.getValue().isEmpty()) { for (String str : tag.getValue().keySet()) { @@ -248,7 +248,7 @@ public abstract class ItemTranslator { return builder.build(); } - private Object translateToBedrockNBT(com.github.steveice10.opennbt.tag.builtin.Tag tag) { + private Object translateToBedrockNBT(Tag tag) { if (tag instanceof ByteArrayTag) { return ((ByteArrayTag) tag).getValue(); } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/BasicItemTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/BasicItemTranslator.java index e52bed2c7..c097dd544 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/BasicItemTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/BasicItemTranslator.java @@ -25,15 +25,13 @@ package org.geysermc.connector.network.translators.item.translators.nbt; -import com.github.steveice10.opennbt.tag.builtin.CompoundTag; -import com.github.steveice10.opennbt.tag.builtin.ListTag; -import com.github.steveice10.opennbt.tag.builtin.StringTag; -import com.github.steveice10.opennbt.tag.builtin.Tag; +import com.github.steveice10.opennbt.tag.builtin.*; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.ItemRemapper; import org.geysermc.connector.network.translators.chat.MessageTranslator; import org.geysermc.connector.network.translators.item.ItemEntry; import org.geysermc.connector.network.translators.item.NbtItemStackTranslator; +import org.geysermc.connector.utils.ItemUtils; import java.util.ArrayList; import java.util.List; @@ -43,6 +41,16 @@ public class BasicItemTranslator extends NbtItemStackTranslator { @Override public void translateToBedrock(GeyserSession session, CompoundTag itemTag, ItemEntry itemEntry) { + Tag damage = itemTag.get("Damage"); + if (damage instanceof IntTag) { + int originalDurability = ((IntTag) damage).getValue(); + int durability = ItemUtils.getCorrectBedrockDurability(itemEntry.getJavaId(), originalDurability); + if (durability != originalDurability) { + // Fix damage tag inconsistencies + itemTag.put(new IntTag("Damage", durability)); + } + } + CompoundTag displayTag = itemTag.get("display"); if (displayTag == null) { return; diff --git a/connector/src/main/java/org/geysermc/connector/utils/ItemUtils.java b/connector/src/main/java/org/geysermc/connector/utils/ItemUtils.java index 070631645..dd4543f61 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/ItemUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/ItemUtils.java @@ -1,47 +1,61 @@ -/* - * Copyright (c) 2019-2021 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.github.steveice10.opennbt.tag.builtin.*; - -public class ItemUtils { - - public static int getEnchantmentLevel(CompoundTag itemNBTData, String enchantmentId) { - ListTag enchantments = (itemNBTData == null ? null : itemNBTData.get("Enchantments")); - if (enchantments != null) { - int enchantmentLevel = 0; - for (Tag tag : enchantments) { - CompoundTag enchantment = (CompoundTag) tag; - StringTag enchantId = enchantment.get("id"); - if (enchantId.getValue().equals(enchantmentId)) { - enchantmentLevel = (int) ((ShortTag) enchantment.get("lvl")).getValue(); - } - } - return enchantmentLevel; - } - return 0; - } -} +/* + * Copyright (c) 2019-2021 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.github.steveice10.opennbt.tag.builtin.*; +import org.geysermc.connector.network.translators.item.ItemRegistry; + +public class ItemUtils { + + public static int getEnchantmentLevel(CompoundTag itemNBTData, String enchantmentId) { + ListTag enchantments = (itemNBTData == null ? null : itemNBTData.get("Enchantments")); + if (enchantments != null) { + int enchantmentLevel = 0; + for (Tag tag : enchantments) { + CompoundTag enchantment = (CompoundTag) tag; + StringTag enchantId = enchantment.get("id"); + if (enchantId.getValue().equals(enchantmentId)) { + enchantmentLevel = (int) ((ShortTag) enchantment.get("lvl")).getValue(); + } + } + return enchantmentLevel; + } + return 0; + } + + /** + * @return the correct Bedrock durability for this item. + */ + public static int getCorrectBedrockDurability(int javaId, int original) { + if (javaId == ItemRegistry.FISHING_ROD.getJavaId()) { + // Java durability: 64 + // Bedrock durability : 384 + // 384 / 64 = 6 + return original * 6; + } + return original; + } +} From ca558fc727eeacabc67f5cdfb01f29c4c86fed7e Mon Sep 17 00:00:00 2001 From: rtm516 Date: Wed, 23 Jun 2021 13:27:23 +0100 Subject: [PATCH 03/19] Remove GeyserAndroid sub build as its nolonger needed (#2317) --- Jenkinsfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 09e88e86e..a9b4bd354 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -93,7 +93,6 @@ pipeline { script { if (env.BRANCH_NAME == 'master') { build propagate: false, wait: false, job: 'GeyserMC/Geyser-Fabric/java-1.16', parameters: [booleanParam(name: 'SKIP_DISCORD', value: true)] - build propagate: false, wait: false, job: 'GeyserMC/GeyserAndroid/master', parameters: [booleanParam(name: 'SKIP_DISCORD', value: true)] build propagate: false, wait: false, job: 'GeyserMC/GeyserConnect/master', parameters: [booleanParam(name: 'SKIP_DISCORD', value: true)] } } From 0a0d84d7795a1b21a2fbb0eb6dccf232ebc96d22 Mon Sep 17 00:00:00 2001 From: David Choo Date: Wed, 23 Jun 2021 13:39:57 -0400 Subject: [PATCH 04/19] Fix phantom scaling (#2314) --- .../entity/living/monster/PhantomEntity.java | 53 +++++++++++++++++++ .../connector/entity/type/EntityType.java | 2 +- 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 connector/src/main/java/org/geysermc/connector/entity/living/monster/PhantomEntity.java diff --git a/connector/src/main/java/org/geysermc/connector/entity/living/monster/PhantomEntity.java b/connector/src/main/java/org/geysermc/connector/entity/living/monster/PhantomEntity.java new file mode 100644 index 000000000..bfa1ea724 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/entity/living/monster/PhantomEntity.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2019-2021 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.monster; + +import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; +import com.nukkitx.math.vector.Vector3f; +import com.nukkitx.protocol.bedrock.data.entity.EntityData; +import org.geysermc.connector.entity.living.FlyingEntity; +import org.geysermc.connector.entity.type.EntityType; +import org.geysermc.connector.network.session.GeyserSession; + +public class PhantomEntity extends FlyingEntity { + public PhantomEntity(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) { + if (entityMetadata.getId() == 16) { // Size + int size = (int) entityMetadata.getValue(); + float modelScale = 1f + 0.15f * size; + float boundsScale = (1f + (0.2f * size) / EntityType.PHANTOM.getWidth()) / modelScale; + + metadata.put(EntityData.BOUNDING_BOX_WIDTH, boundsScale * EntityType.PHANTOM.getWidth()); + metadata.put(EntityData.BOUNDING_BOX_HEIGHT, boundsScale * EntityType.PHANTOM.getHeight()); + metadata.put(EntityData.SCALE, modelScale); + } + 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 36ee9e1c7..582e2cbfa 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 @@ -97,7 +97,7 @@ public enum EntityType { VINDICATOR(VindicatorEntity.class, 57, 1.8f, 0.6f, 0.6f, 1.62f), PILLAGER(PillagerEntity.class, 114, 1.8f, 0.6f, 0.6f, 1.62f), WANDERING_TRADER(AbstractMerchantEntity.class, 118, 1.8f, 0.6f, 0.6f, 1.62f), - PHANTOM(FlyingEntity.class, 58, 0.5f, 0.9f, 0.9f, 0.6f), + PHANTOM(PhantomEntity.class, 58, 0.5f, 0.9f, 0.9f, 0.6f), RAVAGER(RaidParticipantEntity.class, 59, 1.9f, 1.2f), ARMOR_STAND(ArmorStandEntity.class, 61, 1.975f, 0.5f), From 3220190904ffd4196b48595166a027d6f885c01a Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Wed, 23 Jun 2021 13:57:03 -0400 Subject: [PATCH 05/19] Relocate ASM (fixes #2315) --- bootstrap/spigot/pom.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bootstrap/spigot/pom.xml b/bootstrap/spigot/pom.xml index 4ac236529..9cc4111f2 100644 --- a/bootstrap/spigot/pom.xml +++ b/bootstrap/spigot/pom.xml @@ -103,6 +103,10 @@ net.kyori org.geysermc.platform.spigot.shaded.kyori + + org.objectweb.asm + org.geysermc.platform.spigot.shaded.asm + From 71fe2621fc1056472405299ba349d8075dda909e Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Wed, 23 Jun 2021 16:48:56 -0400 Subject: [PATCH 06/19] Remove obsolete chunk merging --- .../network/session/cache/ChunkCache.java | 21 +++---------------- .../java/world/JavaChunkDataTranslator.java | 15 ++++++------- 2 files changed, 9 insertions(+), 27 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/session/cache/ChunkCache.java b/connector/src/main/java/org/geysermc/connector/network/session/cache/ChunkCache.java index e9d97d66d..9ad0a557b 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/cache/ChunkCache.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/cache/ChunkCache.java @@ -46,27 +46,12 @@ public class ChunkCache { chunks = cache ? new Long2ObjectOpenHashMap<>() : null; } - public Column addToCache(Column chunk) { + public void addToCache(Column chunk) { if (!cache) { - return chunk; + return; } - long chunkPosition = MathUtils.chunkPositionToLong(chunk.getX(), chunk.getZ()); - Column existingChunk; - if (chunk.getBiomeData() == null // Only consider merging columns if the new chunk isn't a full chunk - && (existingChunk = chunks.getOrDefault(chunkPosition, null)) != null) { // Column is already present in cache, we can merge with existing - boolean changed = false; - for (int i = 0; i < chunk.getChunks().length; i++) { // The chunks member is final, so chunk.getChunks() will probably be inlined and then completely optimized away - if (chunk.getChunks()[i] != null) { - existingChunk.getChunks()[i] = chunk.getChunks()[i]; - changed = true; - } - } - return changed ? existingChunk : null; - } else { - chunks.put(chunkPosition, chunk); - return chunk; - } + chunks.put(MathUtils.chunkPositionToLong(chunk.getX(), chunk.getZ()), chunk); } public Column getChunk(int chunkX, int chunkZ) { diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaChunkDataTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaChunkDataTranslator.java index 482acf59d..198a7e3fb 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaChunkDataTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaChunkDataTranslator.java @@ -52,15 +52,12 @@ public class JavaChunkDataTranslator extends PacketTranslator { try { - ChunkUtils.ChunkData chunkData = ChunkUtils.translateToBedrock(session, mergedColumn); + ChunkUtils.ChunkData chunkData = ChunkUtils.translateToBedrock(session, column); ChunkSection[] sections = chunkData.getSections(); // Find highest section @@ -90,7 +87,7 @@ public class JavaChunkDataTranslator extends PacketTranslator Date: Fri, 25 Jun 2021 14:52:17 +0100 Subject: [PATCH 07/19] Fix fabric sub build version (#2325) --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index a9b4bd354..bf14f0d12 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -92,7 +92,7 @@ pipeline { success { script { if (env.BRANCH_NAME == 'master') { - build propagate: false, wait: false, job: 'GeyserMC/Geyser-Fabric/java-1.16', parameters: [booleanParam(name: 'SKIP_DISCORD', value: true)] + build propagate: false, wait: false, job: 'GeyserMC/Geyser-Fabric/java-1.17', parameters: [booleanParam(name: 'SKIP_DISCORD', value: true)] build propagate: false, wait: false, job: 'GeyserMC/GeyserConnect/master', parameters: [booleanParam(name: 'SKIP_DISCORD', value: true)] } } From f9f74a0da877e94b2da5d542475ea0e6f557b170 Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Fri, 25 Jun 2021 13:51:52 -0400 Subject: [PATCH 08/19] Determine chunk Y offset on Java packet processing thread Should stop NullPointerExceptions if the session closes before chunks are processed --- .../translators/java/world/JavaChunkDataTranslator.java | 5 ++++- .../main/java/org/geysermc/connector/utils/ChunkUtils.java | 4 +--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaChunkDataTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaChunkDataTranslator.java index 198a7e3fb..81f5c4db3 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaChunkDataTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/world/JavaChunkDataTranslator.java @@ -55,9 +55,12 @@ public class JavaChunkDataTranslator extends PacketTranslator { try { - ChunkUtils.ChunkData chunkData = ChunkUtils.translateToBedrock(session, column); + ChunkUtils.ChunkData chunkData = ChunkUtils.translateToBedrock(session, column, yOffset); ChunkSection[] sections = chunkData.getSections(); // Find highest section diff --git a/connector/src/main/java/org/geysermc/connector/utils/ChunkUtils.java b/connector/src/main/java/org/geysermc/connector/utils/ChunkUtils.java index 9723cd53c..85b7f8600 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/ChunkUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/ChunkUtils.java @@ -81,10 +81,8 @@ public class ChunkUtils { return (yzx >> 8) | (yzx & 0x0F0) | ((yzx & 0x00F) << 8); } - public static ChunkData translateToBedrock(GeyserSession session, Column column) { + public static ChunkData translateToBedrock(GeyserSession session, Column column, int yOffset) { Chunk[] javaSections = column.getChunks(); - // Ensure that, if the player is using lower world heights, the position is not offset - int yOffset = session.getChunkCache().getChunkMinY(); ChunkSection[] sections = new ChunkSection[javaSections.length - yOffset]; // Temporarily stores compound tags of Bedrock-only block entities From 495eafc6e51bdb87b4dcc00c2d510fd0d7e67513 Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Fri, 25 Jun 2021 14:47:01 -0400 Subject: [PATCH 09/19] Work around axolotl buckets titled 'Bucket of ' Huge thanks to @SupremeMortal for figuring out the magic required NBT. --- .../nbt/AxolotlBucketTranslator.java | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/AxolotlBucketTranslator.java diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/AxolotlBucketTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/AxolotlBucketTranslator.java new file mode 100644 index 000000000..a0fe4910b --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/network/translators/item/translators/nbt/AxolotlBucketTranslator.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2019-2021 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.item.translators.nbt; + +import com.github.steveice10.opennbt.tag.builtin.ByteTag; +import com.github.steveice10.opennbt.tag.builtin.CompoundTag; +import com.github.steveice10.opennbt.tag.builtin.StringTag; +import org.geysermc.connector.network.session.GeyserSession; +import org.geysermc.connector.network.translators.ItemRemapper; +import org.geysermc.connector.network.translators.item.ItemEntry; +import org.geysermc.connector.network.translators.item.NbtItemStackTranslator; +import org.geysermc.connector.utils.LocaleUtils; + +@ItemRemapper +public class AxolotlBucketTranslator extends NbtItemStackTranslator { + + @Override + public void translateToBedrock(GeyserSession session, CompoundTag itemTag, ItemEntry itemEntry) { + // Bedrock Edition displays the properties of the axolotl. Java does not. + // To work around this, set the custom name to the Axolotl translation and it's displayed correctly + itemTag.put(new ByteTag("AppendCustomName", (byte) 1)); + itemTag.put(new StringTag("CustomName", LocaleUtils.getLocaleString("entity.minecraft.axolotl", session.getLocale()))); + // Boilerplate required so the nametag does not appear as "Bucket of " + itemTag.put(new StringTag("ColorID", "")); + itemTag.put(new StringTag("BodyID", "")); + } + + @Override + public boolean acceptItem(ItemEntry itemEntry) { + return itemEntry.getJavaIdentifier().equals("minecraft:axolotl_bucket"); + } +} From 5b1d8159266d1de41b41b4887c6633a1392cbbe6 Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Sat, 26 Jun 2021 14:08:59 -0400 Subject: [PATCH 10/19] Bump NMS adapter version --- bootstrap/spigot/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bootstrap/spigot/pom.xml b/bootstrap/spigot/pom.xml index 9cc4111f2..4d295b66d 100644 --- a/bootstrap/spigot/pom.xml +++ b/bootstrap/spigot/pom.xml @@ -39,7 +39,7 @@ org.geysermc.geyser.adapters spigot-all - 1.1-SNAPSHOT + 1.2-SNAPSHOT From 215ffc618fc04845fff47dd5b2bfd613028f8a34 Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Sun, 27 Jun 2021 19:57:53 -0400 Subject: [PATCH 11/19] Fix some SettingsUtils regressions - Add the new 1.17 gamerules - Don't hide exceptions in form responses - Fix the settings form silently failing - Fix some translation strings in the settings form --- .../network/session/cache/FormCache.java | 11 ++++--- .../geysermc/connector/utils/GameRule.java | 4 ++- .../connector/utils/SettingsUtils.java | 30 +++++++++++-------- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/session/cache/FormCache.java b/connector/src/main/java/org/geysermc/connector/network/session/cache/FormCache.java index 1cdcf228b..954a2b033 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/cache/FormCache.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/cache/FormCache.java @@ -31,6 +31,7 @@ import com.nukkitx.protocol.bedrock.packet.NetworkStackLatencyPacket; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import lombok.RequiredArgsConstructor; +import org.geysermc.connector.GeyserConnector; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.cumulus.Form; import org.geysermc.cumulus.SimpleForm; @@ -73,17 +74,19 @@ public class FormCache { } public void handleResponse(ModalFormResponsePacket response) { - Form form = forms.get(response.getFormId()); + Form form = forms.remove(response.getFormId()); if (form == null) { return; } Consumer responseConsumer = form.getResponseHandler(); if (responseConsumer != null) { - responseConsumer.accept(response.getFormData()); + try { + responseConsumer.accept(response.getFormData()); + } catch (Exception e) { + GeyserConnector.getInstance().getLogger().error("Error while processing form response!", e); + } } - - removeWindow(response.getFormId()); } public boolean removeWindow(int id) { diff --git a/connector/src/main/java/org/geysermc/connector/utils/GameRule.java b/connector/src/main/java/org/geysermc/connector/utils/GameRule.java index ca8ce3d3b..0b3908694 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/GameRule.java +++ b/connector/src/main/java/org/geysermc/connector/utils/GameRule.java @@ -51,6 +51,7 @@ public enum GameRule { DROWNINGDAMAGE("drowningDamage", Boolean.class, true), FALLDAMAGE("fallDamage", Boolean.class, true), FIREDAMAGE("fireDamage", Boolean.class, true), + FREEZEDAMAGE("freezeDamage", Boolean.class, true), FORGIVEDEADPLAYERS("forgiveDeadPlayers", Boolean.class, true), // JE only KEEPINVENTORY("keepInventory", Boolean.class, false), LOGADMINCOMMANDS("logAdminCommands", Boolean.class, true), // JE only @@ -58,6 +59,7 @@ public enum GameRule { MAXENTITYCRAMMING("maxEntityCramming", Integer.class, 24), // JE only MOBGRIEFING("mobGriefing", Boolean.class, true), NATURALREGENERATION("naturalRegeneration", Boolean.class, true), + PLAYERSSLEEPINGPERCENTAGE("playersSleepingPercentage", Integer.class, 100), // JE only RANDOMTICKSPEED("randomTickSpeed", Integer.class, 3), REDUCEDDEBUGINFO("reducedDebugInfo", Boolean.class, false), // JE only SENDCOMMANDFEEDBACK("sendCommandFeedback", Boolean.class, true), @@ -68,7 +70,7 @@ public enum GameRule { UNKNOWN("unknown", Object.class); - private static final GameRule[] VALUES = values(); + public static final GameRule[] VALUES = values(); @Getter private final String javaID; diff --git a/connector/src/main/java/org/geysermc/connector/utils/SettingsUtils.java b/connector/src/main/java/org/geysermc/connector/utils/SettingsUtils.java index 1bd89de60..3937fa9a6 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/SettingsUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/SettingsUtils.java @@ -45,12 +45,13 @@ public class SettingsUtils { String language = session.getLocale(); CustomForm.Builder builder = CustomForm.builder() - .translator(LanguageUtils::getPlayerLocaleString, language) + .translator(SettingsUtils::translateEntry, language) .title("geyser.settings.title.main") .iconPath("textures/ui/settings_glyph_color_2x.png"); // Only show the client title if any of the client settings are available - if (session.getPreferencesCache().isAllowShowCoordinates() || CooldownUtils.getDefaultShowCooldown() != CooldownUtils.CooldownType.DISABLED) { + boolean showClientSettings = session.getPreferencesCache().isAllowShowCoordinates() || CooldownUtils.getDefaultShowCooldown() != CooldownUtils.CooldownType.DISABLED; + if (showClientSettings) { builder.label("geyser.settings.title.client"); // Client can only see its coordinates if reducedDebugInfo is disabled and coordinates are enabled in geyser config. @@ -67,7 +68,8 @@ public class SettingsUtils { } } - if (session.getOpPermissionLevel() >= 2 || session.hasPermission("geyser.settings.server")) { + boolean canModifyServer = session.getOpPermissionLevel() >= 2 || session.hasPermission("geyser.settings.server"); + if (canModifyServer) { builder.label("geyser.settings.title.server"); DropdownComponent.Builder gamemodeDropdown = DropdownComponent.builder("%createWorldScreen.gameMode.personal"); @@ -83,7 +85,8 @@ public class SettingsUtils { builder.dropdown(difficultyDropdown); } - if (session.getOpPermissionLevel() >= 2 || session.hasPermission("geyser.settings.gamerules")) { + boolean showGamerules = session.getOpPermissionLevel() >= 2 || session.hasPermission("geyser.settings.gamerules"); + if (showGamerules) { builder.label("geyser.settings.title.game_rules") .translator(LocaleUtils::getLocaleString); // we need translate gamerules next @@ -108,24 +111,20 @@ public class SettingsUtils { return; } - if (session.getPreferencesCache().isAllowShowCoordinates() || CooldownUtils.getDefaultShowCooldown() != CooldownUtils.CooldownType.DISABLED) { - response.skip(); // Client settings title - + if (showClientSettings) { // Client can only see its coordinates if reducedDebugInfo is disabled and coordinates are enabled in geyser config. if (session.getPreferencesCache().isAllowShowCoordinates()) { session.getPreferencesCache().setPrefersShowCoordinates(response.next()); session.getPreferencesCache().updateShowCoordinates(); - response.skip(); } if (CooldownUtils.getDefaultShowCooldown() != CooldownUtils.CooldownType.DISABLED) { CooldownUtils.CooldownType cooldownType = CooldownUtils.CooldownType.VALUES[(int) response.next()]; session.getPreferencesCache().setCooldownPreference(cooldownType); - response.skip(); } } - if (session.getOpPermissionLevel() >= 2 || session.hasPermission("geyser.settings.server")) { + if (canModifyServer) { GameMode gameMode = GameMode.values()[(int) response.next()]; if (gameMode != null && gameMode != session.getGameMode()) { session.getConnector().getWorldManager().setPlayerGameMode(session, gameMode); @@ -137,8 +136,8 @@ public class SettingsUtils { } } - if (session.getOpPermissionLevel() >= 2 || session.hasPermission("geyser.settings.gamerules")) { - for (GameRule gamerule : GameRule.values()) { + if (showGamerules) { + for (GameRule gamerule : GameRule.VALUES) { if (gamerule.equals(GameRule.UNKNOWN)) { continue; } @@ -160,4 +159,11 @@ public class SettingsUtils { return builder.build(); } + + private static String translateEntry(String key, String locale) { + if (key.startsWith("geyser.")) { + return LanguageUtils.getPlayerLocaleString(key, locale); + } + return LocaleUtils.getLocaleString(key, locale); + } } From ad5356472dd5d1defe6b367b28325c0e6ec76b14 Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Sun, 27 Jun 2021 23:25:51 -0400 Subject: [PATCH 12/19] Create a new cached chunk when a block is created in an empty chunk --- .../connector/network/session/cache/ChunkCache.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/session/cache/ChunkCache.java b/connector/src/main/java/org/geysermc/connector/network/session/cache/ChunkCache.java index 9ad0a557b..3687a2c58 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/cache/ChunkCache.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/cache/ChunkCache.java @@ -75,9 +75,18 @@ public class ChunkCache { } Chunk chunk = column.getChunks()[(y >> 4) - getChunkMinY()]; - if (chunk != null) { - chunk.set(x & 0xF, y & 0xF, z & 0xF, block); + if (chunk == null) { + if (block != BlockTranslator.JAVA_AIR_ID) { + chunk = new Chunk(); + // A previously empty chunk, which is no longer empty as a + column.getChunks()[(y >> 4) - getChunkMinY()] = chunk; + } else { + // Nothing to update + return; + } } + + chunk.set(x & 0xF, y & 0xF, z & 0xF, block); } public int getBlockAt(int x, int y, int z) { From 90fa5610f533e38e598d5aa32a68ada5b3fabf47 Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Sun, 27 Jun 2021 23:26:32 -0400 Subject: [PATCH 13/19] Finish my thought --- .../geysermc/connector/network/session/cache/ChunkCache.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/session/cache/ChunkCache.java b/connector/src/main/java/org/geysermc/connector/network/session/cache/ChunkCache.java index 3687a2c58..393a1f188 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/cache/ChunkCache.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/cache/ChunkCache.java @@ -78,7 +78,7 @@ public class ChunkCache { if (chunk == null) { if (block != BlockTranslator.JAVA_AIR_ID) { chunk = new Chunk(); - // A previously empty chunk, which is no longer empty as a + // A previously empty chunk, which is no longer empty as a block has been added to it column.getChunks()[(y >> 4) - getChunkMinY()] = chunk; } else { // Nothing to update From 1cc9c783052c9a5ed068e28ec7affb46e770d13a Mon Sep 17 00:00:00 2001 From: Hellohi3654 <57390764+Hellohi3654@users.noreply.github.com> Date: Tue, 29 Jun 2021 09:24:06 +1000 Subject: [PATCH 14/19] Add 1.17.2 as supported Bedrock version (#2333) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bf8629ee8..a0bd8c178 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ The ultimate goal of this project is to allow Minecraft: Bedrock Edition users t Special thanks to the DragonProxy project for being a trailblazer in protocol translation and for all the team members who have joined us here! -### Currently supporting Minecraft Bedrock 1.17 and Minecraft Java 1.17. +### Currently supporting Minecraft Bedrock 1.17 - 1.17.2 and Minecraft Java 1.17. ## Setting Up Take a look [here](https://github.com/GeyserMC/Geyser/wiki/Setup) for how to set up Geyser. From 566394f798895576bcd5befe258326263e180ea7 Mon Sep 17 00:00:00 2001 From: David Choo Date: Mon, 28 Jun 2021 19:26:02 -0400 Subject: [PATCH 15/19] Fix breaking animation while jumping (#2335) * Update block break time after a CONTINUE_BREAK action * Fix breaking animation time for some blocks * Reuse Vector3f and add comment Co-authored-by: Camotoy <20743703+Camotoy@users.noreply.github.com> --- .../player/BedrockActionTranslator.java | 30 ++++++++----------- .../geysermc/connector/utils/BlockUtils.java | 17 +++++++++++ 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/entity/player/BedrockActionTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/entity/player/BedrockActionTranslator.java index d094bc353..0bc158502 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/entity/player/BedrockActionTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/entity/player/BedrockActionTranslator.java @@ -29,7 +29,7 @@ import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position; import com.github.steveice10.mc.protocol.data.game.entity.player.*; import com.github.steveice10.mc.protocol.data.game.world.block.BlockFace; import com.github.steveice10.mc.protocol.packet.ingame.client.player.*; -import com.github.steveice10.opennbt.tag.builtin.CompoundTag; +import com.nukkitx.math.vector.Vector3f; import com.nukkitx.math.vector.Vector3i; import com.nukkitx.protocol.bedrock.data.LevelEventType; import com.nukkitx.protocol.bedrock.data.PlayerActionType; @@ -41,12 +41,10 @@ import com.nukkitx.protocol.bedrock.packet.PlayStatusPacket; import com.nukkitx.protocol.bedrock.packet.PlayerActionPacket; import org.geysermc.connector.entity.Entity; import org.geysermc.connector.entity.ItemFrameEntity; -import org.geysermc.connector.inventory.GeyserItemStack; import org.geysermc.connector.inventory.PlayerInventory; 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.network.translators.item.ItemEntry; import org.geysermc.connector.network.translators.item.ItemRegistry; import org.geysermc.connector.network.translators.world.block.BlockTranslator; import org.geysermc.connector.utils.BlockUtils; @@ -166,18 +164,7 @@ public class BedrockActionTranslator extends PacketTranslator Date: Mon, 28 Jun 2021 20:48:44 -0400 Subject: [PATCH 16/19] Spigot plugin fixes - If non-NMS world adapter: don't try to load a chunk if it doesn't exist - Don't error out with older Spigot versions if a gamerule doesn't exist --- .../world/manager/GeyserSpigotWorldManager.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/world/manager/GeyserSpigotWorldManager.java b/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/world/manager/GeyserSpigotWorldManager.java index 41e2fd801..6746a8d1a 100644 --- a/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/world/manager/GeyserSpigotWorldManager.java +++ b/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/world/manager/GeyserSpigotWorldManager.java @@ -71,6 +71,11 @@ public class GeyserSpigotWorldManager extends GeyserWorldManager { return BlockTranslator.JAVA_AIR_ID; } World world = bukkitPlayer.getWorld(); + if (!world.isChunkLoaded(x >> 4, z >> 4)) { + // If the chunk isn't loaded, how could we even be here? + return BlockTranslator.JAVA_AIR_ID; + } + return BlockTranslator.getJavaIdBlockMap().getOrDefault(world.getBlockAt(x, y, z).getBlockData().getAsString(), BlockTranslator.JAVA_AIR_ID); } @@ -151,12 +156,20 @@ public class GeyserSpigotWorldManager extends GeyserWorldManager { } public Boolean getGameRuleBool(GeyserSession session, GameRule gameRule) { - return Boolean.parseBoolean(Bukkit.getPlayer(session.getPlayerEntity().getUsername()).getWorld().getGameRuleValue(gameRule.getJavaID())); + String value = Bukkit.getPlayer(session.getPlayerEntity().getUsername()).getWorld().getGameRuleValue(gameRule.getJavaID()); + if (!value.isEmpty()) { + return Boolean.parseBoolean(value); + } + return (Boolean) gameRule.getDefaultValue(); } @Override public int getGameRuleInt(GeyserSession session, GameRule gameRule) { - return Integer.parseInt(Bukkit.getPlayer(session.getPlayerEntity().getUsername()).getWorld().getGameRuleValue(gameRule.getJavaID())); + String value = Bukkit.getPlayer(session.getPlayerEntity().getUsername()).getWorld().getGameRuleValue(gameRule.getJavaID()); + if (!value.isEmpty()) { + return Integer.parseInt(value); + } + return (int) gameRule.getDefaultValue(); } @Override From afc1f48d5e41f9730348005ae33808f53416b439 Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Tue, 29 Jun 2021 10:09:47 -0400 Subject: [PATCH 17/19] Use custom class for caching chunk data Right now, our chunk cache stores the heightmap and biome data that the server sends, which we never use. This commit saves that data in a custom GeyserColumn class that only stores chunk data. In the future, it may also store NBT data. --- .../network/session/cache/ChunkCache.java | 23 ++++++-- .../translators/world/chunk/GeyserColumn.java | 57 +++++++++++++++++++ .../geysermc/connector/utils/ChunkUtils.java | 1 + 3 files changed, 75 insertions(+), 6 deletions(-) create mode 100644 connector/src/main/java/org/geysermc/connector/network/translators/world/chunk/GeyserColumn.java diff --git a/connector/src/main/java/org/geysermc/connector/network/session/cache/ChunkCache.java b/connector/src/main/java/org/geysermc/connector/network/session/cache/ChunkCache.java index 393a1f188..4f93b0f53 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/cache/ChunkCache.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/cache/ChunkCache.java @@ -32,14 +32,17 @@ import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; import lombok.Setter; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.translators.world.block.BlockTranslator; +import org.geysermc.connector.network.translators.world.chunk.GeyserColumn; import org.geysermc.connector.utils.MathUtils; public class ChunkCache { private final boolean cache; - private final Long2ObjectMap chunks; + private final Long2ObjectMap chunks; @Setter private int minY; + @Setter + private int heightY; public ChunkCache(GeyserSession session) { this.cache = !session.getConnector().getWorldManager().hasOwnChunkCache(); // To prevent Spigot from initializing @@ -51,10 +54,12 @@ public class ChunkCache { return; } - chunks.put(MathUtils.chunkPositionToLong(chunk.getX(), chunk.getZ()), chunk); + long chunkPosition = MathUtils.chunkPositionToLong(chunk.getX(), chunk.getZ()); + GeyserColumn geyserColumn = GeyserColumn.from(this, chunk); + chunks.put(chunkPosition, geyserColumn); } - public Column getChunk(int chunkX, int chunkZ) { + public GeyserColumn getChunk(int chunkX, int chunkZ) { long chunkPosition = MathUtils.chunkPositionToLong(chunkX, chunkZ); return chunks.getOrDefault(chunkPosition, null); } @@ -64,7 +69,7 @@ public class ChunkCache { return; } - Column column = this.getChunk(x >> 4, z >> 4); + GeyserColumn column = this.getChunk(x >> 4, z >> 4); if (column == null) { return; } @@ -77,8 +82,10 @@ public class ChunkCache { Chunk chunk = column.getChunks()[(y >> 4) - getChunkMinY()]; if (chunk == null) { if (block != BlockTranslator.JAVA_AIR_ID) { - chunk = new Chunk(); // A previously empty chunk, which is no longer empty as a block has been added to it + chunk = new Chunk(); + // Fixes the chunk assuming that all blocks is the `block` variable we are updating. /shrug + chunk.getPalette().stateToId(BlockTranslator.JAVA_AIR_ID); column.getChunks()[(y >> 4) - getChunkMinY()] = chunk; } else { // Nothing to update @@ -94,7 +101,7 @@ public class ChunkCache { return BlockTranslator.JAVA_AIR_ID; } - Column column = this.getChunk(x >> 4, z >> 4); + GeyserColumn column = this.getChunk(x >> 4, z >> 4); if (column == null) { return BlockTranslator.JAVA_AIR_ID; } @@ -124,4 +131,8 @@ public class ChunkCache { public int getChunkMinY() { return minY >> 4; } + + public int getChunkHeightY() { + return heightY >> 4; + } } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/world/chunk/GeyserColumn.java b/connector/src/main/java/org/geysermc/connector/network/translators/world/chunk/GeyserColumn.java new file mode 100644 index 000000000..3da5787a5 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/network/translators/world/chunk/GeyserColumn.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2019-2021 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.world.chunk; + +import com.github.steveice10.mc.protocol.data.game.chunk.Chunk; +import com.github.steveice10.mc.protocol.data.game.chunk.Column; +import lombok.Getter; +import org.geysermc.connector.network.session.cache.ChunkCache; + +/** + * Acts as a lightweight version of {@link Column} that doesn't store + * biomes or heightmaps. + */ +public class GeyserColumn { + @Getter + private final Chunk[] chunks; + + private GeyserColumn(Chunk[] chunks) { + this.chunks = chunks; + } + + public static GeyserColumn from(ChunkCache chunkCache, Column column) { + int chunkHeightY = chunkCache.getChunkHeightY(); + Chunk[] chunks; + if (chunkHeightY < column.getChunks().length) { + chunks = new Chunk[chunkHeightY]; + // TODO addresses https://github.com/Steveice10/MCProtocolLib/pull/598#issuecomment-862782392 + System.arraycopy(column.getChunks(), 0, chunks, 0, chunks.length); + } else { + chunks = column.getChunks(); + } + return new GeyserColumn(chunks); + } +} diff --git a/connector/src/main/java/org/geysermc/connector/utils/ChunkUtils.java b/connector/src/main/java/org/geysermc/connector/utils/ChunkUtils.java index 85b7f8600..343f5c53e 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/ChunkUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/ChunkUtils.java @@ -419,6 +419,7 @@ public class ChunkUtils { } session.getChunkCache().setMinY(minY); + session.getChunkCache().setHeightY(maxY); } @Data From b757032457e7d44405e9d546de7074089b96c72d Mon Sep 17 00:00:00 2001 From: Camotoy <20743703+Camotoy@users.noreply.github.com> Date: Tue, 29 Jun 2021 22:36:30 -0400 Subject: [PATCH 18/19] Show iron golem attack animation TODO: Do the same for the hoglin and zoglin - this requires more work with the hitbox. --- .../java/entity/JavaEntityStatusTranslator.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityStatusTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityStatusTranslator.java index f444d3ac1..162028ef8 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityStatusTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/entity/JavaEntityStatusTranslator.java @@ -26,16 +26,12 @@ package org.geysermc.connector.network.translators.java.entity; import com.github.steveice10.mc.protocol.packet.ingame.server.entity.ServerEntityStatusPacket; -import com.nukkitx.protocol.bedrock.data.SoundEvent; import com.nukkitx.protocol.bedrock.data.LevelEventType; +import com.nukkitx.protocol.bedrock.data.SoundEvent; import com.nukkitx.protocol.bedrock.data.entity.EntityData; import com.nukkitx.protocol.bedrock.data.entity.EntityEventType; import com.nukkitx.protocol.bedrock.data.inventory.ItemData; -import com.nukkitx.protocol.bedrock.packet.EntityEventPacket; -import com.nukkitx.protocol.bedrock.packet.LevelEventPacket; -import com.nukkitx.protocol.bedrock.packet.LevelSoundEvent2Packet; -import com.nukkitx.protocol.bedrock.packet.SetEntityDataPacket; -import com.nukkitx.protocol.bedrock.packet.SetEntityMotionPacket; +import com.nukkitx.protocol.bedrock.packet.*; import org.geysermc.connector.entity.Entity; import org.geysermc.connector.entity.LivingEntity; import org.geysermc.connector.entity.type.EntityType; @@ -177,6 +173,11 @@ public class JavaEntityStatusTranslator extends PacketTranslator Date: Thu, 1 Jul 2021 08:48:22 -0400 Subject: [PATCH 19/19] Ensure that the player never dimension switches to the same dimension Fixes #2342 --- .../network/translators/java/JavaRespawnTranslator.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaRespawnTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaRespawnTranslator.java index 908292d36..42f572e14 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaRespawnTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaRespawnTranslator.java @@ -83,8 +83,11 @@ public class JavaRespawnTranslator extends PacketTranslator String newDimension = DimensionUtils.getNewDimension(packet.getDimension()); if (!session.getDimension().equals(newDimension) || !packet.getWorldName().equals(session.getWorldName())) { - if (!packet.getWorldName().equals(session.getWorldName()) && session.getDimension().equals(newDimension)) { - // Switching to a new world (based off the world name change); send a fake dimension change + // Switching to a new world (based off the world name change); send a fake dimension change + if (!packet.getWorldName().equals(session.getWorldName()) && (session.getDimension().equals(newDimension) + // Ensure that the player never ever dimension switches to the same dimension - BAD + // Can likely be removed if the Above Bedrock Nether Building option can be removed + || DimensionUtils.javaToBedrock(session.getDimension()) == DimensionUtils.javaToBedrock(newDimension))) { String fakeDim = DimensionUtils.getTemporaryDimension(session.getDimension(), newDimension); DimensionUtils.switchDimension(session, fakeDim); }