mirror of
https://github.com/HibiscusMC/HibiscusCommons.git
synced 2025-12-22 16:39:32 +00:00
feat: latest packet wrappers
This commit is contained in:
@@ -32,12 +32,12 @@ public interface PacketInterface {
|
|||||||
// Override
|
// Override
|
||||||
}
|
}
|
||||||
|
|
||||||
default PacketAction readPlayerArm(@NotNull Player player) {
|
default PacketAction readPlayerArm(@NotNull Player player, @NotNull PlayerSwingWrapper wrapper) {
|
||||||
return PacketAction.NOTHING;
|
return PacketAction.NOTHING;
|
||||||
// Override
|
// Override
|
||||||
}
|
}
|
||||||
|
|
||||||
default PacketAction readEntityHandle(@NotNull Player player) {
|
default PacketAction readEntityHandle(@NotNull Player player, @NotNull PlayerInteractWrapper wrapper) {
|
||||||
return PacketAction.NOTHING;
|
return PacketAction.NOTHING;
|
||||||
// Override
|
// Override
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
package me.lojosho.hibiscuscommons.packets.wrapper;
|
package me.lojosho.hibiscuscommons.packets.wrapper;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@Getter @Setter
|
|
||||||
public class PlayerActionWrapper {
|
public class PlayerActionWrapper {
|
||||||
|
|
||||||
private String actionType;
|
@Getter
|
||||||
|
private final String actionType;
|
||||||
|
|
||||||
public PlayerActionWrapper(String actionType) {
|
public PlayerActionWrapper(@NotNull String actionType) {
|
||||||
this.actionType = actionType;
|
this.actionType = actionType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package me.lojosho.hibiscuscommons.packets.wrapper;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
public class PlayerInteractWrapper {
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private final int entityId;
|
||||||
|
|
||||||
|
public PlayerInteractWrapper(int entityId) {
|
||||||
|
this.entityId = entityId;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package me.lojosho.hibiscuscommons.packets.wrapper;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class PlayerSwingWrapper {
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private final String hand;
|
||||||
|
|
||||||
|
public PlayerSwingWrapper(@NotNull String hand) {
|
||||||
|
this.hand = hand;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -10,7 +10,6 @@ import me.lojosho.hibiscuscommons.packets.PacketAction;
|
|||||||
import me.lojosho.hibiscuscommons.packets.wrapper.*;
|
import me.lojosho.hibiscuscommons.packets.wrapper.*;
|
||||||
import me.lojosho.hibiscuscommons.plugins.SubPlugins;
|
import me.lojosho.hibiscuscommons.plugins.SubPlugins;
|
||||||
import me.lojosho.hibiscuscommons.util.MessagesUtil;
|
import me.lojosho.hibiscuscommons.util.MessagesUtil;
|
||||||
import net.minecraft.core.NonNullList;
|
|
||||||
import net.minecraft.network.protocol.Packet;
|
import net.minecraft.network.protocol.Packet;
|
||||||
import net.minecraft.network.protocol.game.*;
|
import net.minecraft.network.protocol.game.*;
|
||||||
import net.minecraft.world.inventory.ClickType;
|
import net.minecraft.world.inventory.ClickType;
|
||||||
@@ -79,6 +78,7 @@ public class NMSPacketChannel extends ChannelDuplexHandler {
|
|||||||
|
|
||||||
if (action.get() == PacketAction.CANCELLED) return null;
|
if (action.get() == PacketAction.CANCELLED) return null;
|
||||||
if (action.get() == PacketAction.NOTHING) return packet;
|
if (action.get() == PacketAction.NOTHING) return packet;
|
||||||
|
|
||||||
List<ItemStack> nmsItems = new ArrayList<>();
|
List<ItemStack> nmsItems = new ArrayList<>();
|
||||||
for (org.bukkit.inventory.ItemStack bukkitItem : bukkitItems) {
|
for (org.bukkit.inventory.ItemStack bukkitItem : bukkitItems) {
|
||||||
if (bukkitItem == null) {
|
if (bukkitItem == null) {
|
||||||
@@ -88,7 +88,7 @@ public class NMSPacketChannel extends ChannelDuplexHandler {
|
|||||||
nmsItems.add(CraftItemStack.asNMSCopy(bukkitItem));
|
nmsItems.add(CraftItemStack.asNMSCopy(bukkitItem));
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ClientboundContainerSetContentPacket(0, packet.stateId(), nmsItems, packet.carriedItem());
|
return new ClientboundContainerSetContentPacket(wrapper.getWindowId(), packet.stateId(), nmsItems, packet.carriedItem());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Packet<?> handleSlotChange(@NotNull ClientboundContainerSetSlotPacket packet) {
|
private Packet<?> handleSlotChange(@NotNull ClientboundContainerSetSlotPacket packet) {
|
||||||
@@ -218,12 +218,14 @@ public class NMSPacketChannel extends ChannelDuplexHandler {
|
|||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Packet<?> handlePlayerArm(ServerboundSwingPacket packet) {
|
private Packet<?> handlePlayerArm(@NotNull ServerboundSwingPacket packet) {
|
||||||
MessagesUtil.sendDebugMessages("ServerboundSwingPacket");
|
MessagesUtil.sendDebugMessages("ServerboundSwingPacket");
|
||||||
|
PlayerSwingWrapper wrapper = new PlayerSwingWrapper(packet.getHand().name());
|
||||||
|
|
||||||
AtomicReference<PacketAction> action = new AtomicReference<>(PacketAction.NOTHING);
|
AtomicReference<PacketAction> action = new AtomicReference<>(PacketAction.NOTHING);
|
||||||
SubPlugins.getSubPlugins().forEach(plugin -> {
|
SubPlugins.getSubPlugins().forEach(plugin -> {
|
||||||
|
|
||||||
PacketAction pluginAction = plugin.getPacketInterface().readPlayerArm(player);
|
PacketAction pluginAction = plugin.getPacketInterface().readPlayerArm(player, wrapper);
|
||||||
if (pluginAction != PacketAction.NOTHING) action.set(pluginAction);
|
if (pluginAction != PacketAction.NOTHING) action.set(pluginAction);
|
||||||
|
|
||||||
});
|
});
|
||||||
@@ -231,12 +233,15 @@ public class NMSPacketChannel extends ChannelDuplexHandler {
|
|||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Packet<?> handleInteract(ServerboundInteractPacket packet) {
|
private Packet<?> handleInteract(@NotNull ServerboundInteractPacket packet) {
|
||||||
MessagesUtil.sendDebugMessages("ServerboundInteractPacket");
|
MessagesUtil.sendDebugMessages("ServerboundInteractPacket");
|
||||||
|
|
||||||
|
PlayerInteractWrapper wrapper = new PlayerInteractWrapper(packet.getEntityId());
|
||||||
|
|
||||||
AtomicReference<PacketAction> action = new AtomicReference<>(PacketAction.NOTHING);
|
AtomicReference<PacketAction> action = new AtomicReference<>(PacketAction.NOTHING);
|
||||||
SubPlugins.getSubPlugins().forEach(plugin -> {
|
SubPlugins.getSubPlugins().forEach(plugin -> {
|
||||||
|
|
||||||
PacketAction pluginAction = plugin.getPacketInterface().readEntityHandle(player);
|
PacketAction pluginAction = plugin.getPacketInterface().readEntityHandle(player, wrapper);
|
||||||
if (pluginAction != PacketAction.NOTHING) action.set(pluginAction);
|
if (pluginAction != PacketAction.NOTHING) action.set(pluginAction);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user