From e80a14b7dcfdbb06ebabe13cec05b736cccf7e80 Mon Sep 17 00:00:00 2001 From: memetrollsXD Date: Wed, 20 Apr 2022 17:55:33 +0200 Subject: [PATCH] Custom Y position on MarkMapReq --- .../server/packet/recv/HandlerMarkMapReq.java | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/main/java/emu/grasscutter/server/packet/recv/HandlerMarkMapReq.java b/src/main/java/emu/grasscutter/server/packet/recv/HandlerMarkMapReq.java index 024728789..60d58e75e 100644 --- a/src/main/java/emu/grasscutter/server/packet/recv/HandlerMarkMapReq.java +++ b/src/main/java/emu/grasscutter/server/packet/recv/HandlerMarkMapReq.java @@ -15,26 +15,41 @@ import emu.grasscutter.server.packet.send.PacketSceneEntityAppearNotify; @Opcodes(PacketOpcodes.MarkMapReq) public class HandlerMarkMapReq extends PacketHandler { - + + private static boolean isInt(String str) { + + try { + @SuppressWarnings("unused") + int x = Integer.parseInt(str); + return true; // String is an Integer + } catch (NumberFormatException e) { + return false; // String is not an Integer + } + + } + @Override public void handle(GameSession session, byte[] header, byte[] payload) throws Exception { MarkMapReq req = MarkMapReq.parseFrom(payload); - + if (req.getOp() != Operation.Add) { return; } session.getPlayer().getPos().setX(req.getMark().getPos().getX()); session.getPlayer().getPos().setZ(req.getMark().getPos().getZ()); - session.getPlayer().getPos().setY(300); - - Grasscutter.getLogger().info("Player [" + session.getPlayer().getUid() + ":" + session.getPlayer().getNickname() + "] tp to " + session.getPlayer().getPos() + " Scene id: " + req.getMark().getSceneId()); - + + session.getPlayer().getPos() + .setY(isInt(req.getMark().getName()) ? Integer.parseInt(req.getMark().getName()) : 300); + + Grasscutter.getLogger().info("Player [" + session.getPlayer().getUid() + ":" + session.getPlayer().getNickname() + + "] tp to " + session.getPlayer().getPos() + " Scene id: " + req.getMark().getSceneId()); + if (req.getMark().getSceneId() != session.getPlayer().getSceneId()) { - session.getPlayer().getWorld().transferPlayerToScene(session.getPlayer(), req.getMark().getSceneId(), session.getPlayer().getPos()); + session.getPlayer().getWorld().transferPlayerToScene(session.getPlayer(), req.getMark().getSceneId(), + session.getPlayer().getPos()); } else { session.getPlayer().getScene().broadcastPacket(new PacketSceneEntityAppearNotify(session.getPlayer())); } } - }