Skip to content

Commit

Permalink
Fix some protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
s-yh-china committed Feb 7, 2025
1 parent f07c26c commit 74cb952
Show file tree
Hide file tree
Showing 16 changed files with 134 additions and 131 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ index 7763d4c818606ed034f28e050166fe8cae16cfb8..1deedd3fc28792fc368580973038c182
}
// Leaves end - skip
diff --git a/net/minecraft/server/players/PlayerList.java b/net/minecraft/server/players/PlayerList.java
index 8eb35e945a8c376128a4fa3868e32cc90209403a..01bab5294ae27624d8941d55bbe676cb1ea73966 100644
index 93eb9e2d4e44881181a07b12249c3812635fec14..846a96de92c74cfd3091c21d692cb8bdac60c4eb 100644
--- a/net/minecraft/server/players/PlayerList.java
+++ b/net/minecraft/server/players/PlayerList.java
@@ -131,6 +131,7 @@ public abstract class PlayerList {
Expand All @@ -157,7 +157,7 @@ index 8eb35e945a8c376128a4fa3868e32cc90209403a..01bab5294ae27624d8941d55bbe676cb

abstract public void loadAndSaveFiles(); // Paper - fix converting txt to json file; moved from DedicatedPlayerList constructor

+ // Leaves start - replay api
+ // Leaves start - replay mod api
+ public void placeNewPhotographer(Connection connection, org.leavesmc.leaves.replay.ServerPhotographer player, ServerLevel worldserver) {
+ player.isRealPlayer = true; // Paper
+ player.loginTime = System.currentTimeMillis(); // Paper
Expand Down Expand Up @@ -268,7 +268,7 @@ index 8eb35e945a8c376128a4fa3868e32cc90209403a..01bab5294ae27624d8941d55bbe676cb
+ );
+ }
+ }
+ // Leaves end - replay api
+ // Leaves end - replay mod api
+
public void placeNewPlayer(Connection connection, ServerPlayer player, CommonListenerCookie cookie) {
player.isRealPlayer = true; // Paper
Expand Down Expand Up @@ -298,7 +298,7 @@ index 8eb35e945a8c376128a4fa3868e32cc90209403a..01bab5294ae27624d8941d55bbe676cb
}
}

+ // Leaevs start - replay mod api
+ // Leaves start - replay mod api
+ public void removePhotographer(org.leavesmc.leaves.replay.ServerPhotographer entityplayer) {
+ ServerLevel worldserver = entityplayer.serverLevel();
+
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: violetc <[email protected]>
Date: Fri, 7 Feb 2025 14:23:43 +0800
Subject: [PATCH] Xaero Map Protocol


diff --git a/net/minecraft/server/players/PlayerList.java b/net/minecraft/server/players/PlayerList.java
index 9187e876a3e226a9f28af32630122f2ead72b6f3..2aafa4a3e5314b69bbb8deedb5df3a8979efc5d9 100644
--- a/net/minecraft/server/players/PlayerList.java
+++ b/net/minecraft/server/players/PlayerList.java
@@ -1323,6 +1323,7 @@ public abstract class PlayerList {
player.connection.send(new ClientboundInitializeBorderPacket(worldBorder));
player.connection.send(new ClientboundSetTimePacket(level.getGameTime(), level.getDayTime(), level.getGameRules().getBoolean(GameRules.RULE_DAYLIGHT)));
player.connection.send(new ClientboundSetDefaultSpawnPositionPacket(level.getSharedSpawnPos(), level.getSharedSpawnAngle()));
+ org.leavesmc.leaves.protocol.XaeroMapProtocol.onSendWorldInfo(player); // Leaves - xaero map protocol
if (level.isRaining()) {
// CraftBukkit start - handle player weather
// player.connection.send(new ClientboundGameEventPacket(ClientboundGameEventPacket.START_RAINING, 0.0F));
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class AlwaysSendDataConfig extends BotConfig<Boolean> {
private boolean value;

public AlwaysSendDataConfig() {
super("always_send_data", CommandArgument.of(CommandArgumentType.BOOLEAN).setTabComplete(0, List.of("ture", "false")), AlwaysSendDataConfig::new);
super("always_send_data", CommandArgument.of(CommandArgumentType.BOOLEAN).setTabComplete(0, List.of("true", "false")), AlwaysSendDataConfig::new);
this.value = LeavesConfig.modify.fakeplayer.canSendDataAlways;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
public class SkipSleepConfig extends BotConfig<Boolean> {

public SkipSleepConfig() {
super("skip_sleep", CommandArgument.of(CommandArgumentType.BOOLEAN).setTabComplete(0, List.of("ture", "false")), SkipSleepConfig::new);
super("skip_sleep", CommandArgument.of(CommandArgumentType.BOOLEAN).setTabComplete(0, List.of("true", "false")), SkipSleepConfig::new);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class SpawnPhantomConfig extends BotConfig<Boolean> {
private boolean value;

public SpawnPhantomConfig() {
super("spawn_phantom", CommandArgument.of(CommandArgumentType.BOOLEAN).setTabComplete(0, List.of("ture", "false")), SpawnPhantomConfig::new);
super("spawn_phantom", CommandArgument.of(CommandArgumentType.BOOLEAN).setTabComplete(0, List.of("true", "false")), SpawnPhantomConfig::new);
this.value = LeavesConfig.modify.fakeplayer.canSpawnPhantom;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public LmsPasterPayload(int id, CompoundTag nbt) {
}

@New
public LmsPasterPayload(FriendlyByteBuf buf) {
public LmsPasterPayload(ResourceLocation location, FriendlyByteBuf buf) {
this(buf.readVarInt(), buf.readNbt());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ public void write(FriendlyByteBuf buf) {
CODEC.encode(ProtocolUtils.decorate(buf), this);
}

@New
public static RequestBlockPayload create(ResourceLocation location, FriendlyByteBuf buf) {
return CODEC.decode(ProtocolUtils.decorate(buf));
}

@Override
@NotNull
public ResourceLocation id() {
return PACKET_REQUEST_BLOCK;
}

@New
public static RequestBlockPayload create(ResourceLocation location, FriendlyByteBuf buf) {
return CODEC.decode(ProtocolUtils.decorate(buf));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ public void write(FriendlyByteBuf buf) {
CODEC.encode(ProtocolUtils.decorate(buf), this);
}

@New
public static RequestEntityPayload create(ResourceLocation location, FriendlyByteBuf buf) {
return CODEC.decode(ProtocolUtils.decorate(buf));
}

@Override
@NotNull
public ResourceLocation id() {
return PACKET_REQUEST_ENTITY;
}

@New
public static RequestEntityPayload create(ResourceLocation location, FriendlyByteBuf buf) {
return CODEC.decode(ProtocolUtils.decorate(buf));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block;
import org.jetbrains.annotations.NotNull;
import org.leavesmc.leaves.protocol.core.LeavesCustomPayload;
import org.leavesmc.leaves.protocol.core.ProtocolUtils;
import org.leavesmc.leaves.protocol.jade.JadeProtocol;
Expand Down Expand Up @@ -42,5 +43,10 @@ public void write(FriendlyByteBuf buf) {
public ResourceLocation id() {
return PACKET_SERVER_HANDSHAKE;
}

@New
public static ServerHandshakePayload create(ResourceLocation location, FriendlyByteBuf buf) {
return CODEC.decode(ProtocolUtils.decorate(buf));
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,39 @@

import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.Mth;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.Contract;
import org.leavesmc.leaves.LeavesConfig;
import org.leavesmc.leaves.protocol.core.LeavesProtocol;
import org.leavesmc.leaves.protocol.core.LeavesProtocolManager.EmptyPayload;
import org.leavesmc.leaves.protocol.core.ProtocolHandler;
import org.leavesmc.leaves.protocol.core.ProtocolUtils;
import org.leavesmc.leaves.protocol.rei.payload.CreateItemGrabPayload;
import org.leavesmc.leaves.protocol.rei.payload.CreateItemHotbarPayload;
import org.leavesmc.leaves.protocol.rei.payload.CreateItemMessagePayload;
import org.leavesmc.leaves.protocol.rei.payload.CreateItemPayload;
import org.leavesmc.leaves.protocol.rei.payload.DeleteItemPayload;

@LeavesProtocol(namespace = "rei")
@LeavesProtocol(namespace = "roughlyenoughitems")
public class REIServerProtocol {

@ProtocolHandler.PayloadReceiver(payload = DeleteItemPayload.class, payloadId = "delete_item")
public static void handleDeleteItem(ServerPlayer player, DeleteItemPayload payload) {
if (!LeavesConfig.protocol.reiServerProtocol) {
return;
}
if (player.getServer().getProfilePermissions(player.getGameProfile()) < player.getServer().getOperatorUserPermissionLevel()) {
player.displayClientMessage(Component.translatable("text.rei.no_permission_cheat").withStyle(ChatFormatting.RED), false);
public static final String PROTOCOL_ID = "roughlyenoughitems";

@Contract("_ -> new")
public static ResourceLocation id(String path) {
return ResourceLocation.tryBuild(PROTOCOL_ID, path);
}

@ProtocolHandler.PayloadReceiver(payload = EmptyPayload.class, payloadId = "delete_item")
public static void handleDeleteItem(ServerPlayer player, EmptyPayload payload) {
if (!check(player, true)) {
return;
}

AbstractContainerMenu menu = player.containerMenu;
if (!menu.getCarried().isEmpty()) {
menu.setCarried(ItemStack.EMPTY);
Expand All @@ -37,14 +44,11 @@ public static void handleDeleteItem(ServerPlayer player, DeleteItemPayload paylo

@ProtocolHandler.PayloadReceiver(payload = CreateItemPayload.class, payloadId = "create_item")
public static void handleCreateItem(ServerPlayer player, CreateItemPayload payload) {
if (!LeavesConfig.protocol.reiServerProtocol) {
return;
}
if (player.getServer().getProfilePermissions(player.getGameProfile()) < player.getServer().getOperatorUserPermissionLevel()) {
player.displayClientMessage(Component.translatable("text.rei.no_permission_cheat").withStyle(ChatFormatting.RED), false);
if (!check(player, true)) {
return;
}
ItemStack stack = payload.getItem();

ItemStack stack = payload.item();
if (player.getInventory().add(stack.copy())) {
ProtocolUtils.sendPayloadPacket(player, new CreateItemMessagePayload(stack.copy(), player.getScoreboardName()));
} else {
Expand All @@ -54,15 +58,12 @@ public static void handleCreateItem(ServerPlayer player, CreateItemPayload paylo

@ProtocolHandler.PayloadReceiver(payload = CreateItemGrabPayload.class, payloadId = "create_item_grab")
public static void handleCreateItemGrab(ServerPlayer player, CreateItemGrabPayload payload) {
if (!LeavesConfig.protocol.reiServerProtocol) {
return;
}
if (player.getServer().getProfilePermissions(player.getGameProfile()) < player.getServer().getOperatorUserPermissionLevel()) {
player.displayClientMessage(Component.translatable("text.rei.no_permission_cheat").withStyle(ChatFormatting.RED), false);
if (!check(player, true)) {
return;
}

AbstractContainerMenu menu = player.containerMenu;
ItemStack itemStack = payload.getItem();
ItemStack itemStack = payload.item();
ItemStack stack = itemStack.copy();
if (!menu.getCarried().isEmpty() && ItemStack.isSameItemSameComponents(menu.getCarried(), stack)) {
stack.setCount(Mth.clamp(stack.getCount() + menu.getCarried().getCount(), 1, stack.getMaxStackSize()));
Expand All @@ -76,15 +77,12 @@ public static void handleCreateItemGrab(ServerPlayer player, CreateItemGrabPaylo

@ProtocolHandler.PayloadReceiver(payload = CreateItemHotbarPayload.class, payloadId = "create_item_hotbar")
public static void handleCreateItemHotbar(ServerPlayer player, CreateItemHotbarPayload payload) {
if (!LeavesConfig.protocol.reiServerProtocol) {
if (!check(player, true)) {
return;
}
if (player.getServer().getProfilePermissions(player.getGameProfile()) < player.getServer().getOperatorUserPermissionLevel()) {
player.displayClientMessage(Component.translatable("text.rei.no_permission_cheat").withStyle(ChatFormatting.RED), false);
return;
}
ItemStack stack = payload.getItem();
int hotbarSlotId = payload.getHotbarSlot();

ItemStack stack = payload.item();
int hotbarSlotId = payload.hotbarSlot();
if (hotbarSlotId >= 0 && hotbarSlotId < 9) {
AbstractContainerMenu menu = player.containerMenu;
player.getInventory().items.set(hotbarSlotId, stack.copy());
Expand All @@ -94,4 +92,16 @@ public static void handleCreateItemHotbar(ServerPlayer player, CreateItemHotbarP
player.displayClientMessage(Component.translatable("text.rei.failed_cheat_items"), false);
}
}

private static boolean check(ServerPlayer player, boolean needOP) {
if (!LeavesConfig.protocol.reiServerProtocol) {
return false;
}

if (needOP && MinecraftServer.getServer().getPlayerList().isOp(player.gameProfile)) { // TODO check permission node
player.displayClientMessage(Component.translatable("text.rei.no_permission_cheat").withStyle(ChatFormatting.RED), false);
return false;
}
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,26 @@
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.leavesmc.leaves.protocol.core.LeavesCustomPayload;
import org.leavesmc.leaves.protocol.rei.REIServerProtocol;

public class CreateItemGrabPayload implements LeavesCustomPayload<CreateItemGrabPayload> {
public record CreateItemGrabPayload(ItemStack item) implements LeavesCustomPayload<CreateItemGrabPayload> {

private static final ResourceLocation ID = ResourceLocation.fromNamespaceAndPath("roughlyenoughitems", "create_item_grab");

private final ItemStack item;

public CreateItemGrabPayload(final ItemStack item) {
this.item = item;
}
private static final ResourceLocation ID = REIServerProtocol.id("create_item_grab");

@New
public CreateItemGrabPayload(FriendlyByteBuf buf) {
public CreateItemGrabPayload(ResourceLocation location, @NotNull FriendlyByteBuf buf) {
this(buf.readJsonWithCodec(ItemStack.OPTIONAL_CODEC));
}

@Override
public void write(FriendlyByteBuf buf) {
public void write(@NotNull FriendlyByteBuf buf) {
buf.writeJsonWithCodec(ItemStack.OPTIONAL_CODEC, item);
}

@Override
public ResourceLocation id() {
return ID;
}

public ItemStack getItem() {
return item;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,14 @@
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import org.leavesmc.leaves.protocol.core.LeavesCustomPayload;
import org.leavesmc.leaves.protocol.rei.REIServerProtocol;

public class CreateItemHotbarPayload implements LeavesCustomPayload<CreateItemHotbarPayload> {
public record CreateItemHotbarPayload(ItemStack item, int hotbarSlot) implements LeavesCustomPayload<CreateItemHotbarPayload> {

private static final ResourceLocation ID = ResourceLocation.fromNamespaceAndPath("roughlyenoughitems", "create_item_hotbar");

private final ItemStack item;
private final int hotbarSlot;

public CreateItemHotbarPayload(final ItemStack item, final int hotbarSlot) {
this.item = item;
this.hotbarSlot = hotbarSlot;
}
private static final ResourceLocation ID = REIServerProtocol.id("create_item_hotbar");

@New
public CreateItemHotbarPayload(FriendlyByteBuf buf) {
public CreateItemHotbarPayload(ResourceLocation location, FriendlyByteBuf buf) {
this(buf.readJsonWithCodec(ItemStack.OPTIONAL_CODEC), buf.readVarInt());
}

Expand All @@ -32,12 +25,4 @@ public void write(FriendlyByteBuf buf) {
public ResourceLocation id() {
return ID;
}

public ItemStack getItem() {
return item;
}

public int getHotbarSlot() {
return hotbarSlot;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,21 @@
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.leavesmc.leaves.protocol.core.LeavesCustomPayload;
import org.leavesmc.leaves.protocol.rei.REIServerProtocol;

public class CreateItemMessagePayload implements LeavesCustomPayload<CreateItemMessagePayload> {
public record CreateItemMessagePayload(ItemStack item, String playerName) implements LeavesCustomPayload<CreateItemMessagePayload> {

private static final ResourceLocation ID = ResourceLocation.fromNamespaceAndPath("roughlyenoughitems", "ci_msg");
private static final ResourceLocation ID = REIServerProtocol.id("ci_msg");

private final ItemStack item;
private final String playerName;

public CreateItemMessagePayload(final ItemStack item, final String playerName) {
this.item = item;
this.playerName = playerName;
@New
public CreateItemMessagePayload(ResourceLocation location, @NotNull FriendlyByteBuf buf) {
this(buf.readJsonWithCodec(ItemStack.OPTIONAL_CODEC), buf.readUtf());
}

@Override
public void write(FriendlyByteBuf buf) {
public void write(@NotNull FriendlyByteBuf buf) {
buf.writeJsonWithCodec(ItemStack.OPTIONAL_CODEC, item);
buf.writeUtf(playerName);
}
Expand All @@ -27,12 +26,4 @@ public void write(FriendlyByteBuf buf) {
public ResourceLocation id() {
return ID;
}

public ItemStack getItem() {
return item;
}

public String getPlayerName() {
return playerName;
}
}
Loading

0 comments on commit 74cb952

Please sign in to comment.