From 128769dee81356979de08b5a73d5ef2921f8afa6 Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Sat, 3 Aug 2019 22:24:53 -0500 Subject: [PATCH] Minor refactors and tweaks, update README --- README.md | 9 +++- .../network/session/GeyserSession.java | 7 ++- .../session/cache/ScoreboardCache.java | 2 +- .../network/translators/TranslatorsInit.java | 4 +- .../JavaDisplayScoreboardTranslator.java | 46 +++++++++++++++++++ .../JavaScoreboardDisplayTranslator.java | 19 -------- .../JavaScoreboardObjectiveTranslator.java | 30 +++++++++++- .../JavaScoreboardTeamTranslator.java | 17 ------- .../java/scoreboard/JavaTeamTranslator.java | 38 +++++++++++++++ .../scoreboard/JavaUpdateScoreTranslator.java | 30 +++++++++++- .../translators => }/scoreboard/Score.java | 2 +- .../scoreboard/Scoreboard.java | 5 +- .../scoreboard/ScoreboardObjective.java | 3 +- 13 files changed, 161 insertions(+), 51 deletions(-) create mode 100644 connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaDisplayScoreboardTranslator.java delete mode 100644 connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaScoreboardDisplayTranslator.java delete mode 100644 connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaScoreboardTeamTranslator.java create mode 100644 connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaTeamTranslator.java rename connector/src/main/java/org/geysermc/connector/{network/translators => }/scoreboard/Score.java (96%) rename connector/src/main/java/org/geysermc/connector/{network/translators => }/scoreboard/Scoreboard.java (98%) rename connector/src/main/java/org/geysermc/connector/{network/translators => }/scoreboard/ScoreboardObjective.java (97%) diff --git a/README.md b/README.md index 17dabc0a..0f171dca 100644 --- a/README.md +++ b/README.md @@ -24,9 +24,14 @@ Links: - [x] Join detection from remote - [x] Online mode/auth support - [x] Chat/command support +- [ ] Scoreboard + - [x] Objective-based scoreboards + - [ ] Team-based scoreboards - [ ] Inventory support -- [ ] Movement support -- [ ] Entity support + - [x] Inventory viewing + - [ ] Inventory movement (transactions) +- [ ] Player movement support +- [x] Entity support (experimental) - [ ] Chunks - [ ] Block break/place support diff --git a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java index 2d0b03bf..3d514016 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/GeyserSession.java @@ -150,12 +150,13 @@ public class GeyserSession implements PlayerSession, Player { public void disconnected(DisconnectedEvent event) { loggedIn = false; connector.getLogger().info(authenticationData.getName() + " has disconnected from remote java server on address " + remoteServer.getAddress() + " because of " + event.getReason()); - upstream.disconnect(event.getReason()); + disconnect(event.getReason()); } @Override public void packetReceived(PacketReceivedEvent event) { - Registry.JAVA.translate(event.getPacket().getClass(), event.getPacket(), GeyserSession.this); + if (!closed) + Registry.JAVA.translate(event.getPacket().getClass(), event.getPacket(), GeyserSession.this); } }); @@ -175,6 +176,8 @@ public class GeyserSession implements PlayerSession, Player { upstream.disconnect(reason); } } + + closed = true; } @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/session/cache/ScoreboardCache.java b/connector/src/main/java/org/geysermc/connector/network/session/cache/ScoreboardCache.java index 01efa969..147a5355 100644 --- a/connector/src/main/java/org/geysermc/connector/network/session/cache/ScoreboardCache.java +++ b/connector/src/main/java/org/geysermc/connector/network/session/cache/ScoreboardCache.java @@ -29,7 +29,7 @@ import com.nukkitx.protocol.bedrock.packet.RemoveObjectivePacket; import lombok.Getter; import lombok.Setter; import org.geysermc.connector.network.session.GeyserSession; -import org.geysermc.connector.network.translators.scoreboard.Scoreboard; +import org.geysermc.connector.scoreboard.Scoreboard; public class ScoreboardCache { 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 a5dc1ffc..cacdf090 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 @@ -85,7 +85,7 @@ import org.geysermc.connector.network.translators.java.entity.spawn.JavaSpawnMob import org.geysermc.connector.network.translators.java.entity.spawn.JavaSpawnObjectTranslator; import org.geysermc.connector.network.translators.java.entity.spawn.JavaSpawnPaintingTranslator; import org.geysermc.connector.network.translators.java.entity.spawn.JavaSpawnPlayerTranslator; -import org.geysermc.connector.network.translators.java.scoreboard.JavaScoreboardDisplayTranslator; +import org.geysermc.connector.network.translators.java.scoreboard.JavaDisplayScoreboardTranslator; import org.geysermc.connector.network.translators.java.scoreboard.JavaScoreboardObjectiveTranslator; import org.geysermc.connector.network.translators.java.scoreboard.JavaUpdateScoreTranslator; import org.geysermc.connector.network.translators.java.world.JavaNotifyClientTranslator; @@ -155,7 +155,7 @@ public class TranslatorsInit { Registry.registerJava(ServerOpenWindowPacket.class, new JavaOpenWindowTranslator()); Registry.registerJava(ServerSetSlotPacket.class, new JavaSetSlotTranslator()); Registry.registerJava(ServerScoreboardObjectivePacket.class, new JavaScoreboardObjectiveTranslator()); - Registry.registerJava(ServerDisplayScoreboardPacket.class, new JavaScoreboardDisplayTranslator()); + Registry.registerJava(ServerDisplayScoreboardPacket.class, new JavaDisplayScoreboardTranslator()); Registry.registerJava(ServerUpdateScorePacket.class, new JavaUpdateScoreTranslator()); Registry.registerBedrock(AnimatePacket.class, new BedrockAnimateTranslator()); diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaDisplayScoreboardTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaDisplayScoreboardTranslator.java new file mode 100644 index 00000000..429857aa --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaDisplayScoreboardTranslator.java @@ -0,0 +1,46 @@ +/* + * 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.scoreboard; + +import com.github.steveice10.mc.protocol.packet.ingame.server.scoreboard.ServerDisplayScoreboardPacket; +import org.geysermc.connector.network.session.GeyserSession; +import org.geysermc.connector.network.session.cache.ScoreboardCache; +import org.geysermc.connector.network.translators.PacketTranslator; +import org.geysermc.connector.scoreboard.Scoreboard; + +public class JavaDisplayScoreboardTranslator extends PacketTranslator { + + @Override + public void translate(ServerDisplayScoreboardPacket packet, GeyserSession session) { + try { + ScoreboardCache cache = session.getScoreboardCache(); + Scoreboard scoreboard = new Scoreboard(session); + cache.setScoreboard(scoreboard); + } catch (Exception ex) { + ex.printStackTrace(); + } + } +} diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaScoreboardDisplayTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaScoreboardDisplayTranslator.java deleted file mode 100644 index db4eef2f..00000000 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaScoreboardDisplayTranslator.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.geysermc.connector.network.translators.java.scoreboard; - -import com.github.steveice10.mc.protocol.packet.ingame.server.scoreboard.ServerDisplayScoreboardPacket; -import org.geysermc.connector.network.session.GeyserSession; -import org.geysermc.connector.network.session.cache.ScoreboardCache; -import org.geysermc.connector.network.translators.PacketTranslator; -import org.geysermc.connector.network.translators.scoreboard.Scoreboard; - -public class JavaScoreboardDisplayTranslator extends PacketTranslator { - @Override - public void translate(ServerDisplayScoreboardPacket packet, GeyserSession session) { - try { - ScoreboardCache cache = session.getScoreboardCache(); - Scoreboard scoreboard = new Scoreboard(session); - } catch (Exception ex) { - ex.printStackTrace(); - } - } -} diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaScoreboardObjectiveTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaScoreboardObjectiveTranslator.java index 7076d1c6..fb60217c 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaScoreboardObjectiveTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaScoreboardObjectiveTranslator.java @@ -1,14 +1,40 @@ +/* + * 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.scoreboard; import com.github.steveice10.mc.protocol.packet.ingame.server.scoreboard.ServerScoreboardObjectivePacket; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.cache.ScoreboardCache; import org.geysermc.connector.network.translators.PacketTranslator; -import org.geysermc.connector.network.translators.scoreboard.Scoreboard; -import org.geysermc.connector.network.translators.scoreboard.ScoreboardObjective; +import org.geysermc.connector.scoreboard.Scoreboard; +import org.geysermc.connector.scoreboard.ScoreboardObjective; import org.geysermc.connector.utils.MessageUtils; public class JavaScoreboardObjectiveTranslator extends PacketTranslator { + @Override public void translate(ServerScoreboardObjectivePacket packet, GeyserSession session) { try { diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaScoreboardTeamTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaScoreboardTeamTranslator.java deleted file mode 100644 index 85845a4f..00000000 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaScoreboardTeamTranslator.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.geysermc.connector.network.translators.java.scoreboard; - -import com.github.steveice10.mc.protocol.packet.ingame.server.scoreboard.ServerTeamPacket; -import com.nukkitx.protocol.bedrock.packet.SetScorePacket; -import org.geysermc.connector.network.session.GeyserSession; -import org.geysermc.connector.network.session.cache.ScoreboardCache; -import org.geysermc.connector.network.translators.PacketTranslator; -import org.geysermc.connector.network.translators.scoreboard.Scoreboard; -import org.geysermc.connector.network.translators.scoreboard.ScoreboardObjective; -import org.geysermc.connector.utils.MessageUtils; - -public class JavaScoreboardTeamTranslator extends PacketTranslator { - @Override - public void translate(ServerTeamPacket packet, GeyserSession session) { - - } -} diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaTeamTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaTeamTranslator.java new file mode 100644 index 00000000..aa364fef --- /dev/null +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaTeamTranslator.java @@ -0,0 +1,38 @@ +/* + * 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.scoreboard; + +import com.github.steveice10.mc.protocol.packet.ingame.server.scoreboard.ServerTeamPacket; +import org.geysermc.connector.network.session.GeyserSession; +import org.geysermc.connector.network.translators.PacketTranslator; + +public class JavaTeamTranslator extends PacketTranslator { + + @Override + public void translate(ServerTeamPacket packet, GeyserSession session) { + + } +} diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaUpdateScoreTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaUpdateScoreTranslator.java index 3f67ed19..83b01ae0 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaUpdateScoreTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/java/scoreboard/JavaUpdateScoreTranslator.java @@ -1,3 +1,28 @@ +/* + * 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.scoreboard; import com.github.steveice10.mc.protocol.packet.ingame.server.scoreboard.ServerUpdateScorePacket; @@ -5,10 +30,11 @@ import com.nukkitx.protocol.bedrock.packet.SetScorePacket; import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.cache.ScoreboardCache; import org.geysermc.connector.network.translators.PacketTranslator; -import org.geysermc.connector.network.translators.scoreboard.Scoreboard; -import org.geysermc.connector.network.translators.scoreboard.ScoreboardObjective; +import org.geysermc.connector.scoreboard.Scoreboard; +import org.geysermc.connector.scoreboard.ScoreboardObjective; public class JavaUpdateScoreTranslator extends PacketTranslator { + @Override public void translate(ServerUpdateScorePacket packet, GeyserSession session) { try { diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/scoreboard/Score.java b/connector/src/main/java/org/geysermc/connector/scoreboard/Score.java similarity index 96% rename from connector/src/main/java/org/geysermc/connector/network/translators/scoreboard/Score.java rename to connector/src/main/java/org/geysermc/connector/scoreboard/Score.java index 764d9bc7..9535b094 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/scoreboard/Score.java +++ b/connector/src/main/java/org/geysermc/connector/scoreboard/Score.java @@ -23,7 +23,7 @@ * @link https://github.com/GeyserMC/Geyser */ -package org.geysermc.connector.network.translators.scoreboard; +package org.geysermc.connector.scoreboard; import com.nukkitx.protocol.bedrock.packet.SetScorePacket; import lombok.Getter; diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/scoreboard/Scoreboard.java b/connector/src/main/java/org/geysermc/connector/scoreboard/Scoreboard.java similarity index 98% rename from connector/src/main/java/org/geysermc/connector/network/translators/scoreboard/Scoreboard.java rename to connector/src/main/java/org/geysermc/connector/scoreboard/Scoreboard.java index 9fad79bb..6b633799 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/scoreboard/Scoreboard.java +++ b/connector/src/main/java/org/geysermc/connector/scoreboard/Scoreboard.java @@ -23,7 +23,7 @@ * @link https://github.com/GeyserMC/Geyser */ -package org.geysermc.connector.network.translators.scoreboard; +package org.geysermc.connector.scoreboard; import com.nukkitx.protocol.bedrock.data.ScoreInfo; import com.nukkitx.protocol.bedrock.packet.RemoveObjectivePacket; @@ -97,6 +97,9 @@ public class Scoreboard { } public void onUpdate() { + if (objective == null) + return; + RemoveObjectivePacket removeObjectivePacket = new RemoveObjectivePacket(); removeObjectivePacket.setObjectiveId(objective.getObjectiveName()); session.getUpstream().sendPacket(removeObjectivePacket); diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/scoreboard/ScoreboardObjective.java b/connector/src/main/java/org/geysermc/connector/scoreboard/ScoreboardObjective.java similarity index 97% rename from connector/src/main/java/org/geysermc/connector/network/translators/scoreboard/ScoreboardObjective.java rename to connector/src/main/java/org/geysermc/connector/scoreboard/ScoreboardObjective.java index a140ff67..f90c474e 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/scoreboard/ScoreboardObjective.java +++ b/connector/src/main/java/org/geysermc/connector/scoreboard/ScoreboardObjective.java @@ -23,12 +23,11 @@ * @link https://github.com/GeyserMC/Geyser */ -package org.geysermc.connector.network.translators.scoreboard; +package org.geysermc.connector.scoreboard; import com.nukkitx.protocol.bedrock.packet.SetScorePacket; import lombok.Getter; import lombok.Setter; -import org.geysermc.connector.console.GeyserLogger; import java.util.HashMap; import java.util.Map;