From 2502879bde1a50103767d2e28808abf8e6e02800 Mon Sep 17 00:00:00 2001 From: Redned Date: Fri, 20 Sep 2019 23:11:17 -0500 Subject: [PATCH] Add difficulty translator --- .../network/translators/TranslatorsInit.java | 2 + .../java/JavaDifficultyTranslator.java | 41 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 connector/src/main/java/org/geysermc/connector/network/translators/java/JavaDifficultyTranslator.java diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/TranslatorsInit.java b/connector/src/main/java/org/geysermc/connector/network/translators/TranslatorsInit.java index 558c87e45..88e142cd0 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/TranslatorsInit.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/TranslatorsInit.java @@ -51,6 +51,7 @@ import org.geysermc.connector.network.translators.inventory.GenericInventoryTran import org.geysermc.connector.network.translators.inventory.InventoryTranslator; import org.geysermc.connector.network.translators.item.ItemTranslator; import org.geysermc.connector.network.translators.java.JavaChatTranslator; +import org.geysermc.connector.network.translators.java.JavaDifficultyTranslator; import org.geysermc.connector.network.translators.java.JavaJoinGameTranslator; import org.geysermc.connector.network.translators.java.JavaRespawnTranslator; import org.geysermc.connector.network.translators.java.JavaTitleTranslator; @@ -107,6 +108,7 @@ public class TranslatorsInit { Registry.registerJava(ServerUpdateTimePacket.class, new JavaUpdateTimeTranslator()); Registry.registerJava(ServerRespawnPacket.class, new JavaRespawnTranslator()); Registry.registerJava(ServerSpawnPositionPacket.class, new JavaSpawnPositionTranslator()); + Registry.registerJava(ServerDifficultyPacket.class, new JavaDifficultyTranslator()); Registry.registerJava(ServerEntityAnimationPacket.class, new JavaEntityAnimationTranslator()); Registry.registerJava(ServerEntityPositionPacket.class, new JavaEntityPositionTranslator()); diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaDifficultyTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaDifficultyTranslator.java new file mode 100644 index 000000000..7a44054e5 --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/JavaDifficultyTranslator.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2019 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.connector.network.translators.java; + +import com.github.steveice10.mc.protocol.packet.ingame.server.ServerDifficultyPacket; +import com.nukkitx.protocol.bedrock.packet.SetDifficultyPacket; +import org.geysermc.connector.network.session.GeyserSession; +import org.geysermc.connector.network.translators.PacketTranslator; + +public class JavaDifficultyTranslator extends PacketTranslator { + + @Override + public void translate(ServerDifficultyPacket packet, GeyserSession session) { + SetDifficultyPacket setDifficultyPacket = new SetDifficultyPacket(); + setDifficultyPacket.setDifficulty(packet.getDifficulty().ordinal()); + session.getUpstream().sendPacket(setDifficultyPacket); + } +}