mirror of
https://github.com/LeavesMC/Leaves.git
synced 2025-12-19 14:59:32 +00:00
399 lines
12 KiB
Diff
399 lines
12 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Lumine1909 <133463833+Lumine1909@users.noreply.github.com>
|
|
Date: Wed, 22 May 2024 10:12:04 +0800
|
|
Subject: [PATCH] Bytebuf API
|
|
|
|
|
|
diff --git a/src/main/java/org/bukkit/Bukkit.java b/src/main/java/org/bukkit/Bukkit.java
|
|
index f633ddbc5041d93333f3db0cb675deb47d423224..992db8d11b6cb230488c0e77ce8f4834932bbded 100644
|
|
--- a/src/main/java/org/bukkit/Bukkit.java
|
|
+++ b/src/main/java/org/bukkit/Bukkit.java
|
|
@@ -2925,6 +2925,12 @@ public final class Bukkit {
|
|
}
|
|
// Leaves end - Photographer API
|
|
|
|
+ // Leaves start - Bytebuf API
|
|
+ public static org.leavesmc.leaves.bytebuf.BytebufManager getBytebufManager() {
|
|
+ return server.getBytebufManager();
|
|
+ }
|
|
+ // Leaves end - Bytebuf API
|
|
+
|
|
@NotNull
|
|
public static Server.Spigot spigot() {
|
|
return server.spigot();
|
|
diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java
|
|
index 98ca0f656ea3a5be30ad49bc7fb22c886adbef03..79ad3c362e5437b28e44270a9c7b8947ce8b00d5 100644
|
|
--- a/src/main/java/org/bukkit/Server.java
|
|
+++ b/src/main/java/org/bukkit/Server.java
|
|
@@ -2568,4 +2568,8 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
|
|
// Leaves start - Photographer API
|
|
@NotNull PhotographerManager getPhotographerManager();
|
|
// Leaves end - Photographer API
|
|
+
|
|
+ // Leaves start - Bytebuf API
|
|
+ org.leavesmc.leaves.bytebuf.BytebufManager getBytebufManager();
|
|
+ // 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 f2e1b98880503a9933a20ebcf0ba91413c859a08..ee8bcc5b50bff84b18abed6f5e82c55899367827 100644
|
|
--- a/src/main/java/org/bukkit/entity/Player.java
|
|
+++ b/src/main/java/org/bukkit/entity/Player.java
|
|
@@ -3802,6 +3802,12 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
|
|
boolean isChunkSent(long chunkKey);
|
|
// Paper end
|
|
|
|
+ // Leaves start - Bytebuf API
|
|
+ void sendPacket(org.leavesmc.leaves.bytebuf.packet.Packet packet);
|
|
+
|
|
+ void sendPacket(org.leavesmc.leaves.bytebuf.Bytebuf buf, org.leavesmc.leaves.bytebuf.packet.PacketType type);
|
|
+ // Leaves end - Bytebuf API
|
|
+
|
|
@NotNull
|
|
@Override
|
|
Spigot spigot();
|
|
diff --git a/src/main/java/org/leavesmc/leaves/bytebuf/Bytebuf.java b/src/main/java/org/leavesmc/leaves/bytebuf/Bytebuf.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..657eee1d4a18f765480135ef50f5ef65fdc3ed28
|
|
--- /dev/null
|
|
+++ b/src/main/java/org/leavesmc/leaves/bytebuf/Bytebuf.java
|
|
@@ -0,0 +1,102 @@
|
|
+package org.leavesmc.leaves.bytebuf;
|
|
+
|
|
+import com.google.gson.JsonElement;
|
|
+import org.bukkit.Bukkit;
|
|
+import org.bukkit.inventory.ItemStack;
|
|
+
|
|
+import java.util.UUID;
|
|
+
|
|
+public interface Bytebuf {
|
|
+
|
|
+ static Bytebuf buf(int size) {
|
|
+ return Bukkit.getBytebufManager().newBytebuf(size);
|
|
+ }
|
|
+
|
|
+ static Bytebuf buf() {
|
|
+ return buf(128);
|
|
+ }
|
|
+
|
|
+ static Bytebuf of(byte[] bytes) {
|
|
+ return Bukkit.getBytebufManager().toBytebuf(bytes);
|
|
+ }
|
|
+
|
|
+ byte[] toArray();
|
|
+
|
|
+ Bytebuf skipBytes(int i);
|
|
+
|
|
+ int readerIndex();
|
|
+
|
|
+ Bytebuf readerIndex(int i);
|
|
+
|
|
+ int writerIndex();
|
|
+
|
|
+ Bytebuf writerIndex(int i);
|
|
+
|
|
+ Bytebuf resetReaderIndex();
|
|
+
|
|
+ Bytebuf resetWriterIndex();
|
|
+
|
|
+ Bytebuf writeByte(int i);
|
|
+
|
|
+ byte readByte();
|
|
+
|
|
+ Bytebuf writeBoolean(boolean b);
|
|
+
|
|
+ boolean readBoolean();
|
|
+
|
|
+ Bytebuf writeFloat(float f);
|
|
+
|
|
+ float readFloat();
|
|
+
|
|
+ Bytebuf writeDouble(double d);
|
|
+
|
|
+ double readDouble();
|
|
+
|
|
+ Bytebuf writeShort(int i);
|
|
+
|
|
+ short readShort();
|
|
+
|
|
+ Bytebuf writeInt(int i);
|
|
+
|
|
+ int readInt();
|
|
+
|
|
+ Bytebuf writeLong(long i);
|
|
+
|
|
+ long readLong();
|
|
+
|
|
+ Bytebuf writeVarInt(int i);
|
|
+
|
|
+ int readVarInt();
|
|
+
|
|
+ Bytebuf writeVarLong(long i);
|
|
+
|
|
+ long readVarLong();
|
|
+
|
|
+ Bytebuf writeUUID(UUID uuid);
|
|
+
|
|
+ UUID readUUID();
|
|
+
|
|
+ Bytebuf writeEnum(Enum<?> instance);
|
|
+
|
|
+ <T extends Enum<T>> T readEnum(Class<T> enumClass);
|
|
+
|
|
+ Bytebuf writeUTFString(String utf);
|
|
+
|
|
+ String readUTFString();
|
|
+
|
|
+ Bytebuf writeComponentPlain(String str);
|
|
+
|
|
+ String readComponentPlain();
|
|
+
|
|
+ Bytebuf writeComponentJson(JsonElement json);
|
|
+
|
|
+ JsonElement readComponentJson();
|
|
+
|
|
+ Bytebuf writeItemStack(ItemStack itemStack);
|
|
+
|
|
+ ItemStack readItemStack();
|
|
+
|
|
+ Bytebuf copy();
|
|
+
|
|
+ boolean release();
|
|
+}
|
|
diff --git a/src/main/java/org/leavesmc/leaves/bytebuf/BytebufManager.java b/src/main/java/org/leavesmc/leaves/bytebuf/BytebufManager.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..8668e47dee7a23d7843efc4a9752919f7a1dce88
|
|
--- /dev/null
|
|
+++ b/src/main/java/org/leavesmc/leaves/bytebuf/BytebufManager.java
|
|
@@ -0,0 +1,15 @@
|
|
+package org.leavesmc.leaves.bytebuf;
|
|
+
|
|
+import org.bukkit.plugin.Plugin;
|
|
+import org.leavesmc.leaves.bytebuf.packet.PacketListener;
|
|
+
|
|
+public interface BytebufManager {
|
|
+
|
|
+ void registerListener(Plugin plugin, PacketListener listener);
|
|
+
|
|
+ void unregisterListener(Plugin plugin, PacketListener listener);
|
|
+
|
|
+ Bytebuf newBytebuf(int size);
|
|
+
|
|
+ Bytebuf toBytebuf(byte[] bytes);
|
|
+}
|
|
diff --git a/src/main/java/org/leavesmc/leaves/bytebuf/packet/Packet.java b/src/main/java/org/leavesmc/leaves/bytebuf/packet/Packet.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..8bb00c16fe3e6089397cc0fcaaec4715960dd724
|
|
--- /dev/null
|
|
+++ b/src/main/java/org/leavesmc/leaves/bytebuf/packet/Packet.java
|
|
@@ -0,0 +1,6 @@
|
|
+package org.leavesmc.leaves.bytebuf.packet;
|
|
+
|
|
+import org.leavesmc.leaves.bytebuf.Bytebuf;
|
|
+
|
|
+public record Packet(PacketType type, Bytebuf bytebuf) {
|
|
+}
|
|
diff --git a/src/main/java/org/leavesmc/leaves/bytebuf/packet/PacketListener.java b/src/main/java/org/leavesmc/leaves/bytebuf/packet/PacketListener.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..e246c0a8725fa3b2be065433652a19a565c7205c
|
|
--- /dev/null
|
|
+++ b/src/main/java/org/leavesmc/leaves/bytebuf/packet/PacketListener.java
|
|
@@ -0,0 +1,10 @@
|
|
+package org.leavesmc.leaves.bytebuf.packet;
|
|
+
|
|
+import org.bukkit.entity.Player;
|
|
+
|
|
+public interface PacketListener {
|
|
+
|
|
+ Packet onPacketIn(Player player, Packet packet);
|
|
+
|
|
+ Packet onPacketOut(Player player, Packet packet);
|
|
+}
|
|
diff --git a/src/main/java/org/leavesmc/leaves/bytebuf/packet/PacketType.java b/src/main/java/org/leavesmc/leaves/bytebuf/packet/PacketType.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..89c45a056716d0644fe1b41d49a4bdcede53c795
|
|
--- /dev/null
|
|
+++ b/src/main/java/org/leavesmc/leaves/bytebuf/packet/PacketType.java
|
|
@@ -0,0 +1,182 @@
|
|
+package org.leavesmc.leaves.bytebuf.packet;
|
|
+
|
|
+public enum PacketType {
|
|
+ // ClientboundBundle,
|
|
+ // ClientboundBundleDelimiter,
|
|
+ ClientboundAddEntity,
|
|
+ ClientboundAddExperienceOrb,
|
|
+ ClientboundAnimate,
|
|
+ ClientboundAwardStats,
|
|
+ ClientboundBlockChangedAck,
|
|
+ ClientboundBlockDestruction,
|
|
+ ClientboundBlockEntityData,
|
|
+ ClientboundBlockEvent,
|
|
+ ClientboundBlockUpdate,
|
|
+ ClientboundBossEvent,
|
|
+ ClientboundChangeDifficulty,
|
|
+ ClientboundChunkBatchFinished,
|
|
+ ClientboundChunkBatchStart,
|
|
+ ClientboundChunksBiomes,
|
|
+ ClientboundClearTitles,
|
|
+ ClientboundCommandSuggestions,
|
|
+ ClientboundCommands,
|
|
+ ClientboundContainerClose,
|
|
+ ClientboundContainerSetContent,
|
|
+ ClientboundContainerSetData,
|
|
+ ClientboundContainerSetSlot,
|
|
+ ClientboundCooldown,
|
|
+ ClientboundCustomChatCompletions,
|
|
+ ClientboundDamageEvent,
|
|
+ ClientboundDebugSample,
|
|
+ ClientboundDeleteChat,
|
|
+ ClientboundDisguisedChat,
|
|
+ ClientboundEntityEvent,
|
|
+ ClientboundExplode,
|
|
+ ClientboundForgetLevelChunk,
|
|
+ ClientboundGameEvent,
|
|
+ ClientboundHorseScreenOpen,
|
|
+ ClientboundHurtAnimation,
|
|
+ ClientboundInitializeBorder,
|
|
+ ClientboundLevelChunkWithLight,
|
|
+ ClientboundLevelEvent,
|
|
+ ClientboundLevelParticles,
|
|
+ ClientboundLightUpdate,
|
|
+ ClientboundLogin,
|
|
+ ClientboundMapItemData,
|
|
+ ClientboundMerchantOffers,
|
|
+ ClientboundMoveEntityPos,
|
|
+ ClientboundMoveEntityPosRot,
|
|
+ ClientboundMoveEntityRot,
|
|
+ ClientboundMoveVehicle,
|
|
+ ClientboundOpenBook,
|
|
+ ClientboundOpenScreen,
|
|
+ ClientboundOpenSignEditor,
|
|
+ ClientboundPlaceGhostRecipe,
|
|
+ ClientboundPlayerAbilities,
|
|
+ ClientboundPlayerChat,
|
|
+ ClientboundPlayerCombatEnd,
|
|
+ ClientboundPlayerCombatEnter,
|
|
+ ClientboundPlayerCombatKill,
|
|
+ ClientboundPlayerInfoRemove,
|
|
+ ClientboundPlayerInfoUpdate,
|
|
+ ClientboundPlayerLookAt,
|
|
+ ClientboundPlayerPosition,
|
|
+ ClientboundRecipe,
|
|
+ ClientboundRemoveEntities,
|
|
+ ClientboundRemoveMobEffect,
|
|
+ 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,
|
|
+ ClientboundSetTitleText,
|
|
+ ClientboundSetTitlesAnimation,
|
|
+ ClientboundSoundEntity,
|
|
+ ClientboundSound,
|
|
+ ClientboundStartConfiguration,
|
|
+ ClientboundStopSound,
|
|
+ ClientboundSystemChat,
|
|
+ ClientboundTabList,
|
|
+ ClientboundTagQuery,
|
|
+ ClientboundTakeItemEntity,
|
|
+ ClientboundTeleportEntity,
|
|
+ ClientboundUpdateAdvancements,
|
|
+ ClientboundUpdateAttributes,
|
|
+ ClientboundUpdateMobEffect,
|
|
+ ClientboundUpdateRecipes,
|
|
+ ClientboundProjectilePower,
|
|
+ ServerboundAcceptTeleportation,
|
|
+ ServerboundBlockEntityTagQuery,
|
|
+ ServerboundChangeDifficulty,
|
|
+ ServerboundChatAck,
|
|
+ ServerboundChatCommand,
|
|
+ ServerboundChatCommandSigned,
|
|
+ ServerboundChat,
|
|
+ ServerboundChatSessionUpdate,
|
|
+ ServerboundChunkBatchReceived,
|
|
+ ServerboundClientCommand,
|
|
+ ServerboundCommandSuggestion,
|
|
+ ServerboundConfigurationAcknowledged,
|
|
+ ServerboundContainerButtonClick,
|
|
+ ServerboundContainerClick,
|
|
+ ServerboundContainerClose,
|
|
+ ServerboundContainerSlotStateChanged,
|
|
+ ServerboundDebugSampleSubscription,
|
|
+ ServerboundEditBook,
|
|
+ ServerboundEntityTagQuery,
|
|
+ ServerboundInteract,
|
|
+ ServerboundJigsawGenerate,
|
|
+ ServerboundLockDifficulty,
|
|
+ ServerboundMovePlayerPos,
|
|
+ ServerboundMovePlayerPosRot,
|
|
+ ServerboundMovePlayerRot,
|
|
+ ServerboundMovePlayerStatusOnly,
|
|
+ ServerboundMoveVehicle,
|
|
+ ServerboundPaddleBoat,
|
|
+ ServerboundPickItem,
|
|
+ ServerboundPlaceRecipe,
|
|
+ ServerboundPlayerAbilities,
|
|
+ ServerboundPlayerAction,
|
|
+ ServerboundPlayerCommand,
|
|
+ ServerboundPlayerInput,
|
|
+ ServerboundRecipeBookChangeSettings,
|
|
+ ServerboundRecipeBookSeenRecipe,
|
|
+ ServerboundRenameItem,
|
|
+ ServerboundSeenAdvancements,
|
|
+ ServerboundSelectTrade,
|
|
+ ServerboundSetBeacon,
|
|
+ ServerboundSetCarriedItem,
|
|
+ ServerboundSetCommandBlock,
|
|
+ ServerboundSetCommandMinecart,
|
|
+ ServerboundSetCreativeModeSlot,
|
|
+ ServerboundSetJigsawBlock,
|
|
+ ServerboundSetStructureBlock,
|
|
+ ServerboundSignUpdate,
|
|
+ ServerboundSwing,
|
|
+ ServerboundTeleportToEntity,
|
|
+ ServerboundUseItemOn,
|
|
+ ServerboundUseItem,
|
|
+ ClientboundResetScore,
|
|
+ ClientboundTickingState,
|
|
+ ClientboundTickingStep,
|
|
+ ClientboundCustomPayload,
|
|
+ ClientboundDisconnect,
|
|
+ ClientboundKeepAlive,
|
|
+ ClientboundResourcePackPop,
|
|
+ ClientboundResourcePackPush,
|
|
+ ClientboundStoreCookie,
|
|
+ ClientboundTransfer,
|
|
+ ClientboundUpdateTags,
|
|
+ ServerboundClientInformation,
|
|
+ ServerboundCustomPayload,
|
|
+ ServerboundKeepAlive,
|
|
+ ServerboundPong,
|
|
+ ServerboundResourcePack,
|
|
+ ServerboundPingRequest,
|
|
+ ClientboundPongResponse
|
|
+}
|