mirror of
https://github.com/LeavesMC/Leaves.git
synced 2025-12-22 16:39:30 +00:00
--------- Co-authored-by: MC_XiaoHei <xiaohei.xor7studio@foxmail.com> Co-authored-by: Bluemangoo <chenfy2006@qq.com>
225 lines
8.0 KiB
Diff
225 lines
8.0 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Lumine1909 <3556577839@qq.com>
|
|
Date: Fri, 12 Apr 2024 20:12:33 -0400
|
|
Subject: [PATCH] Bytebuf API
|
|
|
|
|
|
diff --git a/src/main/java/org/bukkit/Bukkit.java b/src/main/java/org/bukkit/Bukkit.java
|
|
index b068de949e21525d79223e607fafd43b030a8294..1853a5c230de0e3bc66e0617efe01e6dd15ef553 100644
|
|
--- a/src/main/java/org/bukkit/Bukkit.java
|
|
+++ b/src/main/java/org/bukkit/Bukkit.java
|
|
@@ -2923,6 +2923,14 @@ public final class Bukkit {
|
|
return server.getPhotographerManager();
|
|
}
|
|
// Leaves end - Photographer API
|
|
+ // Leaves start - Bytebuf API
|
|
+ public static @NotNull org.leavesmc.leaves.packet.bytebuf.Bytebuf newByteBuf() {
|
|
+ return server.newByteBuf();
|
|
+ }
|
|
+ public static @NotNull org.leavesmc.leaves.packet.bytebuf.Bytebuf newByteBuf(int initalCapability) {
|
|
+ return server.newByteBuf(initalCapability);
|
|
+ }
|
|
+ // Leaves end - Bytebuf API
|
|
|
|
@NotNull
|
|
public static Server.Spigot spigot() {
|
|
diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java
|
|
index 23ac9b72d2a59b23223ad9335ebed63c40ac117f..56b7e84f075af5d10cb23635f52fc0fedb1f7c6f 100644
|
|
--- a/src/main/java/org/bukkit/Server.java
|
|
+++ b/src/main/java/org/bukkit/Server.java
|
|
@@ -2564,4 +2564,9 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
|
|
// Leaves start - Photographer API
|
|
@NotNull PhotographerManager getPhotographerManager();
|
|
// Leaves end - Photographer API
|
|
+ // Leaves start - Bytebuf API
|
|
+ @NotNull org.leavesmc.leaves.packet.bytebuf.Bytebuf newByteBuf();
|
|
+ @NotNull org.leavesmc.leaves.packet.bytebuf.Bytebuf newByteBuf(int initalCapability);
|
|
+
|
|
+ // Leaves end - Bytebuf API
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/entity/Player.java b/src/main/java/org/bukkit/entity/Player.java
|
|
index 6c327a07bf8a6aa11a2d7dad12b2830acc539484..cfd3acc5e4adcd30fd70ca2c5601bcca1357c821 100644
|
|
--- a/src/main/java/org/bukkit/entity/Player.java
|
|
+++ b/src/main/java/org/bukkit/entity/Player.java
|
|
@@ -3760,6 +3760,10 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
|
|
*/
|
|
void resetIdleDuration();
|
|
// Paper end
|
|
+ // Leaves start - Bytebuf API
|
|
+ void sendPacket(org.leavesmc.leaves.packet.Packet packet);
|
|
+ void sendPacket(org.leavesmc.leaves.packet.bytebuf.Bytebuf buf, org.leavesmc.leaves.packet.PacketType packetType);
|
|
+ // Leaves end - Bytebuf API
|
|
|
|
// Paper start - Add chunk view API
|
|
/**
|
|
diff --git a/src/main/java/org/leavesmc/leaves/packet/Packet.java b/src/main/java/org/leavesmc/leaves/packet/Packet.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..0ea5069b994eb3da2952f696c1fd1bc0e81e281a
|
|
--- /dev/null
|
|
+++ b/src/main/java/org/leavesmc/leaves/packet/Packet.java
|
|
@@ -0,0 +1,8 @@
|
|
+package org.leavesmc.leaves.packet;
|
|
+
|
|
+import org.leavesmc.leaves.packet.bytebuf.Bytebuf;
|
|
+
|
|
+public interface Packet {
|
|
+ PacketType getType();
|
|
+ Bytebuf getBytebuf();
|
|
+}
|
|
diff --git a/src/main/java/org/leavesmc/leaves/packet/PacketType.java b/src/main/java/org/leavesmc/leaves/packet/PacketType.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..3cf5792ddb7aa52580c4d91c2ddef593a43212af
|
|
--- /dev/null
|
|
+++ b/src/main/java/org/leavesmc/leaves/packet/PacketType.java
|
|
@@ -0,0 +1,115 @@
|
|
+package org.leavesmc.leaves.packet;
|
|
+
|
|
+/***
|
|
+ * TODO: API comment
|
|
+ */
|
|
+public enum PacketType {
|
|
+ ClientboundAddEntity,
|
|
+ ClientboundAddExperienceOrb,
|
|
+ ClientboundAnimate,
|
|
+ ClientboundAwardStats,
|
|
+ ClientboundBlockChangedAck,
|
|
+ ClientboundBlockDestruction,
|
|
+ ClientboundBlockEntityData,
|
|
+ ClientboundBlockEvent,
|
|
+ ClientboundBlockUpdate,
|
|
+ ClientboundBossEvent,
|
|
+ // ClientboundBundle, Not a regular packet, see https://wiki.vg/Protocol#Bundle_Delimiter
|
|
+ ClientboundChangeDifficulty,
|
|
+ ClientboundChunkBatchFinished,
|
|
+ ClientboundChunkBatchStart,
|
|
+ ClientboundChunksBiomes,
|
|
+ ClientboundClearTitles,
|
|
+ ClientboundCommands,
|
|
+ ClientboundCommandSuggestions,
|
|
+ ClientboundContainerClose,
|
|
+ ClientboundContainerSetContent,
|
|
+ ClientboundContainerSetData,
|
|
+ ClientboundContainerSetSlot,
|
|
+ ClientboundCooldown,
|
|
+ ClientboundCustomChatCompletions,
|
|
+ ClientboundDamageEvent,
|
|
+ ClientboundDeleteChat,
|
|
+ ClientboundDisguisedChat,
|
|
+ ClientboundEntityEvent,
|
|
+ ClientboundExplode,
|
|
+ ClientboundForgetLevelChunk,
|
|
+ ClientboundGameEvent,
|
|
+ ClientboundHorseScreenOpen,
|
|
+ ClientboundHurtAnimation,
|
|
+ ClientboundInitializeBorder,
|
|
+ ClientboundLevelChunkWithLight,
|
|
+ ClientboundLevelEvent,
|
|
+ ClientboundLevelParticles,
|
|
+ ClientboundLightUpdate,
|
|
+ ClientboundLightUpdatePack,
|
|
+ ClientboundLogin,
|
|
+ ClientboundMapItemData,
|
|
+ ClientboundMerchantOffers,
|
|
+ // ClientboundMoveEntity, Abstract class
|
|
+ ClientboundMoveVehicle,
|
|
+ ClientboundOpenBook,
|
|
+ ClientboundOpenScreen,
|
|
+ ClientboundOpenSignEditor,
|
|
+ ClientboundPlaceGhostRecipe,
|
|
+ ClientboundPlayerAbilities,
|
|
+ ClientboundPlayerChat,
|
|
+ ClientboundPlayerCombatEnd,
|
|
+ ClientboundPlayerCombatEnter,
|
|
+ ClientboundPlayerCombatKill,
|
|
+ ClientboundPlayerInfoRemove,
|
|
+ ClientboundPlayerInfoUpdate,
|
|
+ ClientboundPlayerLookAt,
|
|
+ ClientboundPlayerPosition,
|
|
+ ClientboundRecipe,
|
|
+ ClientboundRemoveEntities,
|
|
+ ClientboundRemoveMobEffect,
|
|
+ ClientboundResetScore,
|
|
+ ClientboundRespawn,
|
|
+ ClientboundRotateHead,
|
|
+ ClientboundSectionBlocksUpdate,
|
|
+ ClientboundSelectAdvancementsTab,
|
|
+ ClientboundServerData,
|
|
+ ClientboundSetActionBarText,
|
|
+ ClientboundSetBorderCenter,
|
|
+ ClientboundSetBorderLerpSize,
|
|
+ ClientboundSetBorderSize,
|
|
+ ClientboundSetBorderWarningDelay,
|
|
+ ClientboundSetBorderWarningDistance,
|
|
+ ClientboundSetCamera,
|
|
+ ClientboundSetCarriedItem,
|
|
+ ClientboundSetChunkCacheCenter,
|
|
+ ClientboundSetChunkCacheRadius,
|
|
+ ClientboundSetDefaultSpawnPosition,
|
|
+ ClientboundSetDisplayObjective,
|
|
+ ClientboundSetEntityData,
|
|
+ ClientboundSetEntityLink,
|
|
+ ClientboundSetEntityMotion,
|
|
+ ClientboundSetEquipment,
|
|
+ ClientboundSetExperience,
|
|
+ ClientboundSetHealth,
|
|
+ ClientboundSetObjective,
|
|
+ ClientboundSetPassengers,
|
|
+ ClientboundSetPlayerTeam,
|
|
+ ClientboundSetScore,
|
|
+ ClientboundSetSimulationDistance,
|
|
+ ClientboundSetSubtitleText,
|
|
+ ClientboundSetTime,
|
|
+ ClientboundSetTitlesAnimation,
|
|
+ ClientboundSetTitleText,
|
|
+ ClientboundSoundEntity,
|
|
+ ClientboundSound,
|
|
+ ClientboundStartConfiguration,
|
|
+ ClientboundStopSound,
|
|
+ ClientboundSystemChat,
|
|
+ ClientboundTabList,
|
|
+ ClientboundTagQuery,
|
|
+ ClientboundTakeItemEntity,
|
|
+ ClientboundTeleportEntity,
|
|
+ ClientboundTickingState,
|
|
+ ClientboundTickingStep,
|
|
+ ClientboundUpdateAdvancements,
|
|
+ ClientboundUpdateAttributes,
|
|
+ ClientboundUpdateMobEffect,
|
|
+ ClientboundUpdateRecipes
|
|
+}
|
|
diff --git a/src/main/java/org/leavesmc/leaves/packet/bytebuf/Bytebuf.java b/src/main/java/org/leavesmc/leaves/packet/bytebuf/Bytebuf.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..78a49c0d86742bc98f6b1434cba00a735982fd7a
|
|
--- /dev/null
|
|
+++ b/src/main/java/org/leavesmc/leaves/packet/bytebuf/Bytebuf.java
|
|
@@ -0,0 +1,29 @@
|
|
+package org.leavesmc.leaves.packet.bytebuf;
|
|
+
|
|
+import org.bukkit.inventory.ItemStack;
|
|
+import org.leavesmc.leaves.packet.Packet;
|
|
+import org.leavesmc.leaves.packet.PacketType;
|
|
+
|
|
+import java.util.UUID;
|
|
+
|
|
+public interface Bytebuf {
|
|
+ Packet toPacket(PacketType type);
|
|
+ Bytebuf writeByte(int i);
|
|
+ Bytebuf writeBoolean(boolean flag);
|
|
+ Bytebuf writeFloat(float f);
|
|
+ Bytebuf writeInt(int i);
|
|
+ Bytebuf writeShort(int i);
|
|
+ Bytebuf writeLong(long i);
|
|
+ Bytebuf writeVarInt(int value);
|
|
+ Bytebuf writeUUID(UUID uuid);
|
|
+ Bytebuf writeVarLong(long value);
|
|
+
|
|
+ /*
|
|
+ In order to bypass NMS in the API, use deserialization of Object here.
|
|
+ In the future, it may be adjusted to use API encapsulated content (workload++).
|
|
+ */
|
|
+ Bytebuf writeStringNbt(String nbt);
|
|
+ Bytebuf writeStringComponent(String component);
|
|
+ Bytebuf writeItem(ItemStack itemStack);
|
|
+
|
|
+}
|