9
0
mirror of https://github.com/LeavesMC/Leaves.git synced 2025-12-19 14:59:32 +00:00
Files
LeavesMC/patches/server/0047-Xaero-Map-Protocol.patch
2024-07-12 14:34:28 +08:00

67 lines
3.2 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: violetc <58360096+s-yh-china@users.noreply.github.com>
Date: Fri, 27 Jan 2023 09:42:57 +0800
Subject: [PATCH] Xaero Map Protocol
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
index f16d0a072ca78ddf3eeb3a483a73869e47ed8ce1..5c47209505af8e9bea3f20effa4e176c32e5109a 100644
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
@@ -1262,6 +1262,7 @@ public abstract class PlayerList {
player.connection.send(new ClientboundInitializeBorderPacket(worldborder));
player.connection.send(new ClientboundSetTimePacket(world.getGameTime(), world.getDayTime(), world.getGameRules().getBoolean(GameRules.RULE_DAYLIGHT)));
player.connection.send(new ClientboundSetDefaultSpawnPositionPacket(world.getSharedSpawnPos(), world.getSharedSpawnAngle()));
+ org.leavesmc.leaves.protocol.XaeroMapProtocol.onSendWorldInfo(player); // Leaves - xaero map protocol
if (world.isRaining()) {
// CraftBukkit start - handle player weather
// entityplayer.connection.send(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.START_RAINING, 0.0F));
diff --git a/src/main/java/org/leavesmc/leaves/protocol/XaeroMapProtocol.java b/src/main/java/org/leavesmc/leaves/protocol/XaeroMapProtocol.java
new file mode 100644
index 0000000000000000000000000000000000000000..14e66b8eb6f2d768e03439df7f4dedc9ba8624dd
--- /dev/null
+++ b/src/main/java/org/leavesmc/leaves/protocol/XaeroMapProtocol.java
@@ -0,0 +1,42 @@
+package org.leavesmc.leaves.protocol;
+
+import net.minecraft.resources.ResourceLocation;
+import net.minecraft.server.level.ServerPlayer;
+import org.jetbrains.annotations.Contract;
+import org.jetbrains.annotations.NotNull;
+import org.leavesmc.leaves.LeavesConfig;
+import org.leavesmc.leaves.protocol.core.LeavesProtocol;
+import org.leavesmc.leaves.protocol.core.ProtocolUtils;
+
+@LeavesProtocol(namespace = {"xaerominimap", "xaeroworldmap"})
+public class XaeroMapProtocol {
+
+ public static final String PROTOCOL_ID_MINI = "xaerominimap";
+ public static final String PROTOCOL_ID_WORLD = "xaeroworldmap";
+
+ private static final ResourceLocation MINIMAP_KEY = idMini("main");
+ private static final ResourceLocation WORLDMAP_KEY = idWorld("main");
+
+ @Contract("_ -> new")
+ public static @NotNull ResourceLocation idMini(String path) {
+ return new ResourceLocation(PROTOCOL_ID_MINI, path);
+ }
+
+ @Contract("_ -> new")
+ public static @NotNull ResourceLocation idWorld(String path) {
+ return new ResourceLocation(PROTOCOL_ID_WORLD, path);
+ }
+
+ public static void onSendWorldInfo(@NotNull ServerPlayer player) {
+ if (LeavesConfig.xaeroMapProtocol) {
+ ProtocolUtils.sendPayloadPacket(player, MINIMAP_KEY, buf -> {
+ buf.writeByte(0);
+ buf.writeInt(LeavesConfig.xaeroMapServerID);
+ });
+ ProtocolUtils.sendPayloadPacket(player, WORLDMAP_KEY, buf -> {
+ buf.writeByte(0);
+ buf.writeInt(LeavesConfig.xaeroMapServerID);
+ });
+ }
+ }
+}