mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-30 12:29:15 +00:00
回退家具注入修改
This commit is contained in:
@@ -28,7 +28,6 @@ import org.joml.Vector3f;
|
||||
import java.io.IOException;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class BukkitFurniture implements Furniture {
|
||||
private final Key id;
|
||||
@@ -131,7 +130,6 @@ public class BukkitFurniture implements Furniture {
|
||||
Object world = FastNMS.INSTANCE.field$CraftWorld$ServerLevel(this.location.getWorld());
|
||||
for (Collider entity : this.colliderEntities) {
|
||||
FastNMS.INSTANCE.method$LevelWriter$addFreshEntity(world, entity.handle());
|
||||
injectFurnitureEntity(entity.handle());
|
||||
Entity bukkitEntity = FastNMS.INSTANCE.method$Entity$getBukkitEntity(entity.handle());
|
||||
bukkitEntity.getPersistentDataContainer().set(BukkitFurnitureManager.FURNITURE_COLLISION, PersistentDataType.BYTE, (byte) 1);
|
||||
}
|
||||
@@ -361,24 +359,4 @@ public class BukkitFurniture implements Furniture {
|
||||
newLocation.add(offset.x, offset.y + 0.6, -offset.z);
|
||||
return newLocation;
|
||||
}
|
||||
|
||||
public static void injectFurnitureEntity(Object nmsEntity) {
|
||||
try {
|
||||
Object trackedEntity = FastNMS.INSTANCE.field$Entity$trackedEntity(nmsEntity);
|
||||
Object serverEntity = FastNMS.INSTANCE.field$ChunkMap$TrackedEntity$serverEntity(trackedEntity);
|
||||
CoreReflections.handle$ServerEntity$broadcastSetter.invokeExact(serverEntity, Handlers.DO_NOTHING);
|
||||
CoreReflections.handle$ServerEntity$updateIntervalSetter.invokeExact(serverEntity, Integer.MAX_VALUE);
|
||||
} catch (Throwable e) {
|
||||
CraftEngine.instance().logger().warn("Failed to inject collider", e);
|
||||
}
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Handlers extends Consumer<Object> {
|
||||
Consumer<Object> DO_NOTHING = doNothing();
|
||||
|
||||
static Handlers doNothing() {
|
||||
return (packet) -> {};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,7 +86,6 @@ public class BukkitFurnitureManager extends AbstractFurnitureManager {
|
||||
SoundData data = furniture.settings().sounds().placeSound();
|
||||
location.getWorld().playSound(location, data.id().toString(), SoundCategory.BLOCKS, data.volume(), data.pitch());
|
||||
}
|
||||
BukkitFurniture.injectFurnitureEntity(FastNMS.INSTANCE.method$CraftEntity$getHandle(furnitureEntity));
|
||||
return loadedFurnitureByRealEntityId(furnitureEntity.getEntityId());
|
||||
}
|
||||
|
||||
@@ -102,7 +101,6 @@ public class BukkitFurnitureManager extends AbstractFurnitureManager {
|
||||
for (Entity entity : entities) {
|
||||
if (entity instanceof ItemDisplay display) {
|
||||
handleBaseEntityLoadEarly(display);
|
||||
BukkitFurniture.injectFurnitureEntity(FastNMS.INSTANCE.method$CraftEntity$getHandle(display));
|
||||
} else if (entity instanceof Interaction interaction) {
|
||||
handleCollisionEntityLoadOnEntitiesLoad(interaction);
|
||||
} else if (entity instanceof Boat boat) {
|
||||
|
||||
@@ -2,7 +2,6 @@ package net.momirealms.craftengine.bukkit.entity.furniture;
|
||||
|
||||
import com.destroystokyo.paper.event.entity.EntityAddToWorldEvent;
|
||||
import com.destroystokyo.paper.event.entity.EntityRemoveFromWorldEvent;
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.ItemDisplay;
|
||||
@@ -37,7 +36,6 @@ public class FurnitureEventListener implements Listener {
|
||||
for (Entity entity : entities) {
|
||||
if (entity instanceof ItemDisplay itemDisplay) {
|
||||
this.manager.handleBaseEntityLoadEarly(itemDisplay);
|
||||
BukkitFurniture.injectFurnitureEntity(FastNMS.INSTANCE.method$CraftEntity$getHandle(itemDisplay));
|
||||
} else if (BukkitFurnitureManager.COLLISION_ENTITY_CLASS.isInstance(entity)) {
|
||||
this.manager.handleCollisionEntityLoadOnEntitiesLoad(entity);
|
||||
}
|
||||
@@ -50,7 +48,6 @@ public class FurnitureEventListener implements Listener {
|
||||
for (Entity entity : entities) {
|
||||
if (entity instanceof ItemDisplay itemDisplay) {
|
||||
this.manager.handleBaseEntityLoadEarly(itemDisplay);
|
||||
BukkitFurniture.injectFurnitureEntity(FastNMS.INSTANCE.method$CraftEntity$getHandle(itemDisplay));
|
||||
} else if (BukkitFurnitureManager.COLLISION_ENTITY_CLASS.isInstance(entity)) {
|
||||
this.manager.handleCollisionEntityLoadOnEntitiesLoad(entity);
|
||||
}
|
||||
@@ -62,7 +59,6 @@ public class FurnitureEventListener implements Listener {
|
||||
Entity entity = event.getEntity();
|
||||
if (entity instanceof ItemDisplay itemDisplay) {
|
||||
this.manager.handleBaseEntityLoadLate(itemDisplay, 0);
|
||||
BukkitFurniture.injectFurnitureEntity(FastNMS.INSTANCE.method$CraftEntity$getHandle(itemDisplay));
|
||||
} else if (BukkitFurnitureManager.COLLISION_ENTITY_CLASS.isInstance(entity)) {
|
||||
this.manager.handleCollisionEntityLoadLate(entity, 0);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.CoreReflections;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.MRegistryOps;
|
||||
import net.momirealms.craftengine.core.item.ItemWrapper;
|
||||
import net.momirealms.craftengine.core.plugin.locale.TranslationManager;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.sparrow.nbt.Tag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@@ -113,7 +112,6 @@ public class ComponentItemWrapper implements ItemWrapper<ItemStack> {
|
||||
if (value == null) return;
|
||||
Object componentType = ensureDataComponentType(type);
|
||||
if (componentType == null) {
|
||||
TranslationManager.instance().log("warning.config.item.component_notfound", type.toString());
|
||||
return;
|
||||
}
|
||||
Codec codec = FastNMS.INSTANCE.method$DataComponentType$codec(componentType);
|
||||
|
||||
@@ -159,6 +159,7 @@ public class BukkitNetworkManager implements NetworkManager, Listener, PluginMes
|
||||
registerNMSPacketConsumer(PacketConsumers.RESOURCE_PACK_RESPONSE, NetworkReflections.clazz$ServerboundResourcePackPacket);
|
||||
registerNMSPacketConsumer(PacketConsumers.ENTITY_EVENT, NetworkReflections.clazz$ClientboundEntityEventPacket);
|
||||
registerNMSPacketConsumer(PacketConsumers.MOVE_POS_AND_ROTATE_ENTITY, NetworkReflections.clazz$ClientboundMoveEntityPacket$PosRot);
|
||||
registerNMSPacketConsumer(PacketConsumers.MOVE_POS_ENTITY, NetworkReflections.clazz$ClientboundMoveEntityPacket$Pos);
|
||||
registerS2CByteBufPacketConsumer(PacketConsumers.LEVEL_CHUNK_WITH_LIGHT, this.packetIds.clientboundLevelChunkWithLightPacket());
|
||||
registerS2CByteBufPacketConsumer(PacketConsumers.SECTION_BLOCK_UPDATE, this.packetIds.clientboundSectionBlocksUpdatePacket());
|
||||
registerS2CByteBufPacketConsumer(PacketConsumers.BLOCK_UPDATE, this.packetIds.clientboundBlockUpdatePacket());
|
||||
|
||||
@@ -162,6 +162,7 @@ public class PacketConsumers {
|
||||
BukkitFurniture furniture = BukkitFurnitureManager.instance().loadedFurnitureByRealEntityId(id);
|
||||
if (furniture != null) {
|
||||
event.setCancelled(true);
|
||||
user.entityPacketHandlers().put(id, FurnitureCollisionPacketHandler.INSTANCE);
|
||||
}
|
||||
};
|
||||
ADD_ENTITY_HANDLERS[MEntityTypes.OAK_BOAT$registryId] = (user, event) -> {
|
||||
@@ -172,6 +173,7 @@ public class PacketConsumers {
|
||||
BukkitFurniture furniture = BukkitFurnitureManager.instance().loadedFurnitureByRealEntityId(id);
|
||||
if (furniture != null) {
|
||||
event.setCancelled(true);
|
||||
user.entityPacketHandlers().put(id, FurnitureCollisionPacketHandler.INSTANCE);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1169,14 +1171,14 @@ public class PacketConsumers {
|
||||
public static final TriConsumer<NetWorkUser, NMSPacketEvent, Object> HELLO_C2S = (user, event, packet) -> {
|
||||
try {
|
||||
BukkitServerPlayer player = (BukkitServerPlayer) user;
|
||||
String name = (String) NetworkReflections.handle$ServerboundHelloPacket$nameGetter.invokeExact(packet);
|
||||
String name = (String) NetworkReflections.methodHandle$ServerboundHelloPacket$nameGetter.invokeExact(packet);
|
||||
player.setName(name);
|
||||
if (VersionHelper.isOrAbove1_20_2()) {
|
||||
UUID uuid = (UUID) NetworkReflections.handle$ServerboundHelloPacket$uuidGetter.invokeExact(packet);
|
||||
UUID uuid = (UUID) NetworkReflections.methodHandle$ServerboundHelloPacket$uuidGetter.invokeExact(packet);
|
||||
player.setUUID(uuid);
|
||||
} else {
|
||||
@SuppressWarnings("unchecked")
|
||||
Optional<UUID> uuid = (Optional<UUID>) NetworkReflections.handle$ServerboundHelloPacket$uuidGetter.invokeExact(packet);
|
||||
Optional<UUID> uuid = (Optional<UUID>) NetworkReflections.methodHandle$ServerboundHelloPacket$uuidGetter.invokeExact(packet);
|
||||
if (uuid.isPresent()) {
|
||||
player.setUUID(uuid.get());
|
||||
} else {
|
||||
@@ -1220,10 +1222,10 @@ public class PacketConsumers {
|
||||
player.clearView();
|
||||
Object dimensionKey;
|
||||
if (!VersionHelper.isOrAbove1_20_2()) {
|
||||
dimensionKey = NetworkReflections.handle$ClientboundRespawnPacket$dimensionGetter.invokeExact(packet);
|
||||
dimensionKey = NetworkReflections.methodHandle$ClientboundRespawnPacket$dimensionGetter.invokeExact(packet);
|
||||
} else {
|
||||
Object commonInfo = NetworkReflections.handle$ClientboundRespawnPacket$commonPlayerSpawnInfoGetter.invokeExact(packet);
|
||||
dimensionKey = NetworkReflections.handle$CommonPlayerSpawnInfo$dimensionGetter.invokeExact(commonInfo);
|
||||
Object commonInfo = NetworkReflections.methodHandle$ClientboundRespawnPacket$commonPlayerSpawnInfoGetter.invokeExact(packet);
|
||||
dimensionKey = NetworkReflections.methodHandle$CommonPlayerSpawnInfo$dimensionGetter.invokeExact(commonInfo);
|
||||
}
|
||||
Object location = FastNMS.INSTANCE.field$ResourceKey$location(dimensionKey);
|
||||
World world = Bukkit.getWorld(Objects.requireNonNull(NamespacedKey.fromString(location.toString())));
|
||||
@@ -1248,10 +1250,10 @@ public class PacketConsumers {
|
||||
if (BukkitNetworkManager.hasViaVersion()) {
|
||||
user.setProtocolVersion(CraftEngine.instance().compatibilityManager().getPlayerProtocolVersion(player.uuid()));
|
||||
}
|
||||
dimensionKey = NetworkReflections.handle$ClientboundLoginPacket$dimensionGetter.invokeExact(packet);
|
||||
dimensionKey = NetworkReflections.methodHandle$ClientboundLoginPacket$dimensionGetter.invokeExact(packet);
|
||||
} else {
|
||||
Object commonInfo = NetworkReflections.handle$ClientboundLoginPacket$commonPlayerSpawnInfoGetter.invokeExact(packet);
|
||||
dimensionKey = NetworkReflections.handle$CommonPlayerSpawnInfo$dimensionGetter.invokeExact(commonInfo);
|
||||
Object commonInfo = NetworkReflections.methodHandle$ClientboundLoginPacket$commonPlayerSpawnInfoGetter.invokeExact(packet);
|
||||
dimensionKey = NetworkReflections.methodHandle$CommonPlayerSpawnInfo$dimensionGetter.invokeExact(commonInfo);
|
||||
}
|
||||
Object location = FastNMS.INSTANCE.field$ResourceKey$location(dimensionKey);
|
||||
World world = Bukkit.getWorld(Objects.requireNonNull(NamespacedKey.fromString(location.toString())));
|
||||
@@ -1295,9 +1297,9 @@ public class PacketConsumers {
|
||||
Player bukkitPlayer = player.platformPlayer();
|
||||
if (bukkitPlayer == null) return;
|
||||
if (bukkitPlayer.getGameMode() != GameMode.CREATIVE) return;
|
||||
int slot = VersionHelper.isOrAbove1_20_5() ? (short) NetworkReflections.handle$ServerboundSetCreativeModeSlotPacket$slotNumGetter.invokeExact(packet) : (int) NetworkReflections.handle$ServerboundSetCreativeModeSlotPacket$slotNumGetter.invokeExact(packet);
|
||||
int slot = VersionHelper.isOrAbove1_20_5() ? (short) NetworkReflections.methodHandle$ServerboundSetCreativeModeSlotPacket$slotNumGetter.invokeExact(packet) : (int) NetworkReflections.methodHandle$ServerboundSetCreativeModeSlotPacket$slotNumGetter.invokeExact(packet);
|
||||
if (slot < 36 || slot > 44) return;
|
||||
ItemStack item = FastNMS.INSTANCE.method$CraftItemStack$asCraftMirror(NetworkReflections.handle$ServerboundSetCreativeModeSlotPacket$itemStackGetter.invokeExact(packet));
|
||||
ItemStack item = FastNMS.INSTANCE.method$CraftItemStack$asCraftMirror(NetworkReflections.methodHandle$ServerboundSetCreativeModeSlotPacket$itemStackGetter.invokeExact(packet));
|
||||
if (ItemUtils.isEmpty(item)) return;
|
||||
if (slot - 36 != bukkitPlayer.getInventory().getHeldItemSlot()) {
|
||||
return;
|
||||
@@ -1370,7 +1372,7 @@ public class PacketConsumers {
|
||||
if (!user.isOnline()) return;
|
||||
Player player = (Player) user.platformPlayer();
|
||||
if (player == null) return;
|
||||
Object pos = NetworkReflections.handle$ServerboundPickItemFromBlockPacket$posGetter.invokeExact(packet);
|
||||
Object pos = NetworkReflections.methodHandle$ServerboundPickItemFromBlockPacket$posGetter.invokeExact(packet);
|
||||
if (VersionHelper.isFolia()) {
|
||||
int x = FastNMS.INSTANCE.field$Vec3i$x(pos);
|
||||
int z = FastNMS.INSTANCE.field$Vec3i$z(pos);
|
||||
@@ -1408,7 +1410,7 @@ public class PacketConsumers {
|
||||
// 1.21.4+
|
||||
public static final TriConsumer<NetWorkUser, NMSPacketEvent, Object> PICK_ITEM_FROM_ENTITY = (user, event, packet) -> {
|
||||
try {
|
||||
int entityId = (int) NetworkReflections.handle$ServerboundPickItemFromEntityPacket$idGetter.invokeExact(packet);
|
||||
int entityId = (int) NetworkReflections.methodHandle$ServerboundPickItemFromEntityPacket$idGetter.invokeExact(packet);
|
||||
BukkitFurniture furniture = BukkitFurnitureManager.instance().loadedFurnitureByEntityId(entityId);
|
||||
if (furniture == null) return;
|
||||
Player player = (Player) user.platformPlayer();
|
||||
@@ -1747,14 +1749,14 @@ public class PacketConsumers {
|
||||
if (((BukkitServerPlayer) user).hasPermission(FontManager.BYPASS_ANVIL)) {
|
||||
return;
|
||||
}
|
||||
String message = (String) NetworkReflections.handle$ServerboundRenameItemPacket$nameGetter.invokeExact(packet);
|
||||
String message = (String) NetworkReflections.methodHandle$ServerboundRenameItemPacket$nameGetter.invokeExact(packet);
|
||||
if (message != null && !message.isEmpty()) {
|
||||
// check bypass
|
||||
FontManager manager = CraftEngine.instance().fontManager();
|
||||
IllegalCharacterProcessResult result = manager.processIllegalCharacters(message);
|
||||
if (result.has()) {
|
||||
try {
|
||||
NetworkReflections.handle$ServerboundRenameItemPacket$nameSetter.invokeExact(packet, result.text());
|
||||
NetworkReflections.methodHandle$ServerboundRenameItemPacket$nameSetter.invokeExact(packet, result.text());
|
||||
} catch (ReflectiveOperationException e) {
|
||||
CraftEngine.instance().logger().warn("Failed to replace chat", e);
|
||||
}
|
||||
@@ -1773,7 +1775,7 @@ public class PacketConsumers {
|
||||
if (((BukkitServerPlayer) user).hasPermission(FontManager.BYPASS_SIGN)) {
|
||||
return;
|
||||
}
|
||||
String[] lines = (String[]) NetworkReflections.handle$ServerboundSignUpdatePacket$linesGetter.invokeExact(packet);
|
||||
String[] lines = (String[]) NetworkReflections.methodHandle$ServerboundSignUpdatePacket$linesGetter.invokeExact(packet);
|
||||
FontManager manager = CraftEngine.instance().fontManager();
|
||||
if (!manager.isDefaultFontInUse()) return;
|
||||
for (int i = 0; i < lines.length; i++) {
|
||||
@@ -1804,9 +1806,9 @@ public class PacketConsumers {
|
||||
|
||||
boolean changed = false;
|
||||
|
||||
List<String> pages = (List<String>) NetworkReflections.handleServerboundEditBookPacket$pagesGetter.invokeExact(packet);
|
||||
List<String> pages = (List<String>) NetworkReflections.methodHandle$ServerboundEditBookPacket$pagesGetter.invokeExact(packet);
|
||||
List<String> newPages = new ArrayList<>(pages.size());
|
||||
Optional<String> title = (Optional<String>) NetworkReflections.handle$ServerboundEditBookPacket$titleGetter.invokeExact(packet);
|
||||
Optional<String> title = (Optional<String>) NetworkReflections.methodHandle$ServerboundEditBookPacket$titleGetter.invokeExact(packet);
|
||||
Optional<String> newTitle;
|
||||
|
||||
if (title.isPresent()) {
|
||||
@@ -1830,7 +1832,7 @@ public class PacketConsumers {
|
||||
|
||||
if (changed) {
|
||||
Object newPacket = NetworkReflections.constructor$ServerboundEditBookPacket.newInstance(
|
||||
(int) NetworkReflections.handle$ServerboundEditBookPacket$slotGetter.invokeExact(packet),
|
||||
(int) NetworkReflections.methodHandle$ServerboundEditBookPacket$slotGetter.invokeExact(packet),
|
||||
newPages,
|
||||
newTitle
|
||||
);
|
||||
@@ -1863,7 +1865,7 @@ public class PacketConsumers {
|
||||
public static final TriConsumer<NetWorkUser, NMSPacketEvent, Object> CUSTOM_PAYLOAD = (user, event, packet) -> {
|
||||
try {
|
||||
if (!VersionHelper.isOrAbove1_20_5()) return;
|
||||
Object payload = NetworkReflections.handle$ServerboundCustomPayloadPacket$payloadGetter.invokeExact(packet);
|
||||
Object payload = NetworkReflections.methodHandle$ServerboundCustomPayloadPacket$payloadGetter.invokeExact(packet);
|
||||
if (NetworkReflections.clazz$DiscardedPayload.isInstance(payload)) {
|
||||
Payload discardedPayload = DiscardedPayload.from(payload);
|
||||
if (discardedPayload == null || !discardedPayload.channel().equals(NetworkManager.MOD_CHANNEL_KEY))
|
||||
@@ -2282,7 +2284,7 @@ public class PacketConsumers {
|
||||
public static final TriConsumer<NetWorkUser, NMSPacketEvent, Object> HANDSHAKE_C2S = (user, event, packet) -> {
|
||||
try {
|
||||
if (BukkitNetworkManager.hasViaVersion()) return;
|
||||
int protocolVersion = (int) NetworkReflections.handle$ClientIntentionPacket$protocolVersionGetter.invokeExact(packet);
|
||||
int protocolVersion = (int) NetworkReflections.methodHandle$ClientIntentionPacket$protocolVersionGetter.invokeExact(packet);
|
||||
user.setProtocolVersion(protocolVersion);
|
||||
} catch (Throwable e) {
|
||||
CraftEngine.instance().logger().warn("Failed to handle ClientIntentionPacket", e);
|
||||
@@ -2302,7 +2304,7 @@ public class PacketConsumers {
|
||||
public static final TriConsumer<NetWorkUser, NMSPacketEvent, Object> RESOURCE_PACK_RESPONSE = (user, event, packet) -> {
|
||||
try {
|
||||
if (user.sentResourcePack() || !Config.sendPackOnJoin() || !Config.kickOnDeclined()) return;
|
||||
Object action = NetworkReflections.handle$ServerboundResourcePackPacket$actionGetter.invokeExact(packet);
|
||||
Object action = NetworkReflections.methodHandle$ServerboundResourcePackPacket$actionGetter.invokeExact(packet);
|
||||
if (action == null) return;
|
||||
if (action == NetworkReflections.instance$ServerboundResourcePackPacket$Action$DECLINED
|
||||
|| action == NetworkReflections.instance$ServerboundResourcePackPacket$Action$FAILED_DOWNLOAD) {
|
||||
@@ -2324,9 +2326,9 @@ public class PacketConsumers {
|
||||
try {
|
||||
Object player = user.serverPlayer();
|
||||
if (player == null) return;
|
||||
int entityId = (int) NetworkReflections.handle$ClientboundEntityEventPacket$entityIdGetter.invokeExact(packet);
|
||||
int entityId = (int) NetworkReflections.methodHandle$ClientboundEntityEventPacket$entityIdGetter.invokeExact(packet);
|
||||
if (entityId != FastNMS.INSTANCE.method$Entity$getId(player)) return;
|
||||
byte eventId = (byte) NetworkReflections.handle$ClientboundEntityEventPacket$eventIdGetter.invokeExact(packet);
|
||||
byte eventId = (byte) NetworkReflections.methodHandle$ClientboundEntityEventPacket$eventIdGetter.invokeExact(packet);
|
||||
if (eventId >= 24 && eventId <= 28) {
|
||||
CraftEngine.instance().fontManager().refreshEmojiSuggestions(user.uuid());
|
||||
}
|
||||
@@ -2346,4 +2348,16 @@ public class PacketConsumers {
|
||||
CraftEngine.instance().logger().warn("Failed to handle ClientboundMoveEntityPacket$PosRot", e);
|
||||
}
|
||||
};
|
||||
|
||||
public static final TriConsumer<NetWorkUser, NMSPacketEvent, Object> MOVE_POS_ENTITY = (user, event, packet) -> {
|
||||
try {
|
||||
int entityId = ProtectedFieldVisitor.get().field$ClientboundMoveEntityPacket$entityId(packet);
|
||||
EntityPacketHandler handler = user.entityPacketHandlers().get(entityId);
|
||||
if (handler != null) {
|
||||
handler.handleMove(user, event, packet);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
CraftEngine.instance().logger().warn("Failed to handle ClientboundMoveEntityPacket", e);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package net.momirealms.craftengine.bukkit.plugin.network.handler;
|
||||
|
||||
import net.momirealms.craftengine.core.plugin.network.EntityPacketHandler;
|
||||
import net.momirealms.craftengine.core.plugin.network.NMSPacketEvent;
|
||||
import net.momirealms.craftengine.core.plugin.network.NetWorkUser;
|
||||
|
||||
public class FurnitureCollisionPacketHandler implements EntityPacketHandler {
|
||||
public static final FurnitureCollisionPacketHandler INSTANCE = new FurnitureCollisionPacketHandler();
|
||||
|
||||
@Override
|
||||
public void handleSyncEntityPosition(NetWorkUser user, NMSPacketEvent event, Object packet) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMove(NetWorkUser user, NMSPacketEvent event, Object packet) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,8 @@ package net.momirealms.craftengine.bukkit.plugin.network.handler;
|
||||
|
||||
import it.unimi.dsi.fastutil.ints.IntList;
|
||||
import net.momirealms.craftengine.core.plugin.network.EntityPacketHandler;
|
||||
import net.momirealms.craftengine.core.plugin.network.NMSPacketEvent;
|
||||
import net.momirealms.craftengine.core.plugin.network.NetWorkUser;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -17,4 +19,14 @@ public class FurniturePacketHandler implements EntityPacketHandler {
|
||||
entityIds.addAll(this.fakeEntities);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleSyncEntityPosition(NetWorkUser user, NMSPacketEvent event, Object packet) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMove(NetWorkUser user, NMSPacketEvent event, Object packet) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1304,165 +1304,165 @@ public final class NetworkReflections {
|
||||
)
|
||||
);
|
||||
|
||||
public static final MethodHandle handle$ServerboundRenameItemPacket$nameGetter;
|
||||
public static final MethodHandle handle$ServerboundRenameItemPacket$nameSetter;
|
||||
public static final MethodHandle handle$ServerboundHelloPacket$nameGetter;
|
||||
public static final MethodHandle handle$ServerboundHelloPacket$uuidGetter;
|
||||
public static final MethodHandle handle$ServerboundSetCreativeModeSlotPacket$itemStackGetter;
|
||||
public static final MethodHandle handle$ServerboundSetCreativeModeSlotPacket$slotNumGetter;
|
||||
public static final MethodHandle handle$ServerboundInteractPacket$actionGetter;
|
||||
public static final MethodHandle handle$ServerboundInteractPacket$InteractionAtLocationAction$handGetter;
|
||||
public static final MethodHandle handle$ServerboundInteractPacket$InteractionAtLocationAction$locationGetter;
|
||||
public static final MethodHandle handle$ServerboundSignUpdatePacket$linesGetter;
|
||||
public static final MethodHandle handleServerboundEditBookPacket$pagesGetter;
|
||||
public static final MethodHandle handle$ServerboundEditBookPacket$titleGetter;
|
||||
public static final MethodHandle handle$ServerboundEditBookPacket$slotGetter;
|
||||
public static final MethodHandle handle$ServerboundResourcePackPacket$actionGetter;
|
||||
public static final MethodHandle handle$ClientboundEntityEventPacket$entityIdGetter;
|
||||
public static final MethodHandle handle$ClientboundEntityEventPacket$eventIdGetter;
|
||||
public static final MethodHandle handle$ClientIntentionPacket$protocolVersionGetter;
|
||||
public static final MethodHandle handle$ClientboundRespawnPacket$dimensionGetter;
|
||||
public static final MethodHandle handle$ClientboundRespawnPacket$commonPlayerSpawnInfoGetter;
|
||||
public static final MethodHandle handle$CommonPlayerSpawnInfo$dimensionGetter;
|
||||
public static final MethodHandle handle$ClientboundLoginPacket$dimensionGetter;
|
||||
public static final MethodHandle handle$ClientboundLoginPacket$commonPlayerSpawnInfoGetter;
|
||||
public static final MethodHandle handle$ServerboundPickItemFromBlockPacket$posGetter;
|
||||
public static final MethodHandle handle$ServerboundPickItemFromEntityPacket$idGetter;
|
||||
public static final MethodHandle handle$ServerboundCustomPayloadPacket$payloadGetter;
|
||||
public static final MethodHandle methodHandle$ServerboundRenameItemPacket$nameGetter;
|
||||
public static final MethodHandle methodHandle$ServerboundRenameItemPacket$nameSetter;
|
||||
public static final MethodHandle methodHandle$ServerboundHelloPacket$nameGetter;
|
||||
public static final MethodHandle methodHandle$ServerboundHelloPacket$uuidGetter;
|
||||
public static final MethodHandle methodHandle$ServerboundSetCreativeModeSlotPacket$itemStackGetter;
|
||||
public static final MethodHandle methodHandle$ServerboundSetCreativeModeSlotPacket$slotNumGetter;
|
||||
public static final MethodHandle methodHandle$ServerboundInteractPacket$actionGetter;
|
||||
public static final MethodHandle methodHandle$ServerboundInteractPacket$InteractionAtLocationAction$handGetter;
|
||||
public static final MethodHandle methodHandle$ServerboundInteractPacket$InteractionAtLocationAction$locationGetter;
|
||||
public static final MethodHandle methodHandle$ServerboundSignUpdatePacket$linesGetter;
|
||||
public static final MethodHandle methodHandle$ServerboundEditBookPacket$pagesGetter;
|
||||
public static final MethodHandle methodHandle$ServerboundEditBookPacket$titleGetter;
|
||||
public static final MethodHandle methodHandle$ServerboundEditBookPacket$slotGetter;
|
||||
public static final MethodHandle methodHandle$ServerboundResourcePackPacket$actionGetter;
|
||||
public static final MethodHandle methodHandle$ClientboundEntityEventPacket$entityIdGetter;
|
||||
public static final MethodHandle methodHandle$ClientboundEntityEventPacket$eventIdGetter;
|
||||
public static final MethodHandle methodHandle$ClientIntentionPacket$protocolVersionGetter;
|
||||
public static final MethodHandle methodHandle$ClientboundRespawnPacket$dimensionGetter;
|
||||
public static final MethodHandle methodHandle$ClientboundRespawnPacket$commonPlayerSpawnInfoGetter;
|
||||
public static final MethodHandle methodHandle$CommonPlayerSpawnInfo$dimensionGetter;
|
||||
public static final MethodHandle methodHandle$ClientboundLoginPacket$dimensionGetter;
|
||||
public static final MethodHandle methodHandle$ClientboundLoginPacket$commonPlayerSpawnInfoGetter;
|
||||
public static final MethodHandle methodHandle$ServerboundPickItemFromBlockPacket$posGetter;
|
||||
public static final MethodHandle methodHandle$ServerboundPickItemFromEntityPacket$idGetter;
|
||||
public static final MethodHandle methodHandle$ServerboundCustomPayloadPacket$payloadGetter;
|
||||
|
||||
static {
|
||||
try {
|
||||
handle$ServerboundRenameItemPacket$nameGetter = requireNonNull(
|
||||
methodHandle$ServerboundRenameItemPacket$nameGetter = requireNonNull(
|
||||
ReflectionUtils.unreflectGetter(field$ServerboundRenameItemPacket$name)
|
||||
.asType(MethodType.methodType(String.class, Object.class))
|
||||
);
|
||||
handle$ServerboundRenameItemPacket$nameSetter = requireNonNull(
|
||||
methodHandle$ServerboundRenameItemPacket$nameSetter = requireNonNull(
|
||||
ReflectionUtils.unreflectSetter(field$ServerboundRenameItemPacket$name)
|
||||
.asType(MethodType.methodType(void.class, Object.class, String.class))
|
||||
);
|
||||
handle$ServerboundHelloPacket$nameGetter = requireNonNull(
|
||||
methodHandle$ServerboundHelloPacket$nameGetter = requireNonNull(
|
||||
ReflectionUtils.unreflectGetter(field$ServerboundHelloPacket$name)
|
||||
.asType(MethodType.methodType(String.class, Object.class))
|
||||
);
|
||||
handle$ServerboundHelloPacket$uuidGetter = requireNonNull(
|
||||
methodHandle$ServerboundHelloPacket$uuidGetter = requireNonNull(
|
||||
ReflectionUtils.unreflectGetter(field$ServerboundHelloPacket$uuid)
|
||||
.asType(MethodType.methodType(VersionHelper.isOrAbove1_20_2() ? UUID.class : Optional.class, Object.class))
|
||||
);
|
||||
handle$ServerboundSetCreativeModeSlotPacket$itemStackGetter = requireNonNull(
|
||||
methodHandle$ServerboundSetCreativeModeSlotPacket$itemStackGetter = requireNonNull(
|
||||
ReflectionUtils.unreflectGetter(field$ServerboundSetCreativeModeSlotPacket$itemStack)
|
||||
.asType(MethodType.methodType(Object.class, Object.class))
|
||||
);
|
||||
handle$ServerboundSetCreativeModeSlotPacket$slotNumGetter = requireNonNull(
|
||||
methodHandle$ServerboundSetCreativeModeSlotPacket$slotNumGetter = requireNonNull(
|
||||
ReflectionUtils.unreflectGetter(field$ServerboundSetCreativeModeSlotPacket$slotNum)
|
||||
.asType(MethodType.methodType(VersionHelper.isOrAbove1_20_5() ? short.class : int.class, Object.class))
|
||||
);
|
||||
handle$ServerboundInteractPacket$actionGetter = requireNonNull(
|
||||
methodHandle$ServerboundInteractPacket$actionGetter = requireNonNull(
|
||||
ReflectionUtils.unreflectGetter(field$ServerboundInteractPacket$action)
|
||||
.asType(MethodType.methodType(Object.class, Object.class))
|
||||
);
|
||||
handle$ServerboundInteractPacket$InteractionAtLocationAction$handGetter = requireNonNull(
|
||||
methodHandle$ServerboundInteractPacket$InteractionAtLocationAction$handGetter = requireNonNull(
|
||||
ReflectionUtils.unreflectGetter(field$ServerboundInteractPacket$InteractionAtLocationAction$hand)
|
||||
.asType(MethodType.methodType(Object.class, Object.class))
|
||||
);
|
||||
handle$ServerboundInteractPacket$InteractionAtLocationAction$locationGetter = requireNonNull(
|
||||
methodHandle$ServerboundInteractPacket$InteractionAtLocationAction$locationGetter = requireNonNull(
|
||||
ReflectionUtils.unreflectGetter(field$ServerboundInteractPacket$InteractionAtLocationAction$location)
|
||||
.asType(MethodType.methodType(Object.class, Object.class))
|
||||
);
|
||||
handle$ServerboundSignUpdatePacket$linesGetter = requireNonNull(
|
||||
methodHandle$ServerboundSignUpdatePacket$linesGetter = requireNonNull(
|
||||
ReflectionUtils.unreflectGetter(field$ServerboundSignUpdatePacket$lines)
|
||||
.asType(MethodType.methodType(String[].class, Object.class))
|
||||
);
|
||||
handleServerboundEditBookPacket$pagesGetter = requireNonNull(
|
||||
methodHandle$ServerboundEditBookPacket$pagesGetter = requireNonNull(
|
||||
ReflectionUtils.unreflectGetter(field$ServerboundEditBookPacket$pages)
|
||||
.asType(MethodType.methodType(List.class, Object.class))
|
||||
);
|
||||
handle$ServerboundEditBookPacket$titleGetter = requireNonNull(
|
||||
methodHandle$ServerboundEditBookPacket$titleGetter = requireNonNull(
|
||||
ReflectionUtils.unreflectGetter(field$ServerboundEditBookPacket$title)
|
||||
.asType(MethodType.methodType(Optional.class, Object.class))
|
||||
);
|
||||
handle$ServerboundEditBookPacket$slotGetter = requireNonNull(
|
||||
methodHandle$ServerboundEditBookPacket$slotGetter = requireNonNull(
|
||||
ReflectionUtils.unreflectGetter(field$ServerboundEditBookPacket$slot)
|
||||
.asType(MethodType.methodType(int.class, Object.class))
|
||||
);
|
||||
handle$ServerboundResourcePackPacket$actionGetter = requireNonNull(
|
||||
methodHandle$ServerboundResourcePackPacket$actionGetter = requireNonNull(
|
||||
ReflectionUtils.unreflectGetter(field$ServerboundResourcePackPacket$action)
|
||||
.asType(MethodType.methodType(Object.class, Object.class))
|
||||
);
|
||||
handle$ClientboundEntityEventPacket$entityIdGetter = requireNonNull(
|
||||
methodHandle$ClientboundEntityEventPacket$entityIdGetter = requireNonNull(
|
||||
ReflectionUtils.unreflectGetter(field$ClientboundEntityEventPacket$entityId)
|
||||
.asType(MethodType.methodType(int.class, Object.class))
|
||||
);
|
||||
handle$ClientboundEntityEventPacket$eventIdGetter = requireNonNull(
|
||||
methodHandle$ClientboundEntityEventPacket$eventIdGetter = requireNonNull(
|
||||
ReflectionUtils.unreflectGetter(field$ClientboundEntityEventPacket$eventId)
|
||||
.asType(MethodType.methodType(byte.class, Object.class))
|
||||
);
|
||||
handle$ClientIntentionPacket$protocolVersionGetter = requireNonNull(
|
||||
methodHandle$ClientIntentionPacket$protocolVersionGetter = requireNonNull(
|
||||
ReflectionUtils.unreflectGetter(field$ClientIntentionPacket$protocolVersion)
|
||||
.asType(MethodType.methodType(int.class, Object.class))
|
||||
);
|
||||
if (field$ServerboundCustomPayloadPacket$payload != null) {
|
||||
handle$ServerboundCustomPayloadPacket$payloadGetter = requireNonNull(
|
||||
methodHandle$ServerboundCustomPayloadPacket$payloadGetter = requireNonNull(
|
||||
ReflectionUtils.unreflectGetter(field$ServerboundCustomPayloadPacket$payload)
|
||||
.asType(MethodType.methodType(Object.class, Object.class))
|
||||
);
|
||||
} else {
|
||||
handle$ServerboundCustomPayloadPacket$payloadGetter = null;
|
||||
methodHandle$ServerboundCustomPayloadPacket$payloadGetter = null;
|
||||
}
|
||||
if (field$ServerboundPickItemFromEntityPacket$id != null) {
|
||||
handle$ServerboundPickItemFromEntityPacket$idGetter = requireNonNull(
|
||||
methodHandle$ServerboundPickItemFromEntityPacket$idGetter = requireNonNull(
|
||||
ReflectionUtils.unreflectGetter(field$ServerboundPickItemFromEntityPacket$id)
|
||||
.asType(MethodType.methodType(int.class, Object.class))
|
||||
);
|
||||
} else {
|
||||
handle$ServerboundPickItemFromEntityPacket$idGetter = null;
|
||||
methodHandle$ServerboundPickItemFromEntityPacket$idGetter = null;
|
||||
}
|
||||
if (field$ServerboundPickItemFromBlockPacket$pos != null) {
|
||||
handle$ServerboundPickItemFromBlockPacket$posGetter = requireNonNull(
|
||||
methodHandle$ServerboundPickItemFromBlockPacket$posGetter = requireNonNull(
|
||||
ReflectionUtils.unreflectGetter(field$ServerboundPickItemFromBlockPacket$pos)
|
||||
.asType(MethodType.methodType(Object.class, Object.class))
|
||||
);
|
||||
} else {
|
||||
handle$ServerboundPickItemFromBlockPacket$posGetter = null;
|
||||
methodHandle$ServerboundPickItemFromBlockPacket$posGetter = null;
|
||||
}
|
||||
if (field$ClientboundLoginPacket$commonPlayerSpawnInfo != null) {
|
||||
handle$ClientboundLoginPacket$commonPlayerSpawnInfoGetter = requireNonNull(
|
||||
methodHandle$ClientboundLoginPacket$commonPlayerSpawnInfoGetter = requireNonNull(
|
||||
ReflectionUtils.unreflectGetter(field$ClientboundLoginPacket$commonPlayerSpawnInfo)
|
||||
.asType(MethodType.methodType(Object.class, Object.class))
|
||||
);
|
||||
} else {
|
||||
handle$ClientboundLoginPacket$commonPlayerSpawnInfoGetter = null;
|
||||
methodHandle$ClientboundLoginPacket$commonPlayerSpawnInfoGetter = null;
|
||||
}
|
||||
if (field$ClientboundLoginPacket$dimension != null) {
|
||||
handle$ClientboundLoginPacket$dimensionGetter = requireNonNull(
|
||||
methodHandle$ClientboundLoginPacket$dimensionGetter = requireNonNull(
|
||||
ReflectionUtils.unreflectGetter(field$ClientboundLoginPacket$dimension)
|
||||
.asType(MethodType.methodType(Object.class, Object.class))
|
||||
);
|
||||
} else {
|
||||
handle$ClientboundLoginPacket$dimensionGetter = null;
|
||||
methodHandle$ClientboundLoginPacket$dimensionGetter = null;
|
||||
}
|
||||
if (field$CommonPlayerSpawnInfo$dimension != null) {
|
||||
handle$CommonPlayerSpawnInfo$dimensionGetter = requireNonNull(
|
||||
methodHandle$CommonPlayerSpawnInfo$dimensionGetter = requireNonNull(
|
||||
ReflectionUtils.unreflectGetter(field$CommonPlayerSpawnInfo$dimension)
|
||||
.asType(MethodType.methodType(Object.class, Object.class))
|
||||
);
|
||||
} else {
|
||||
handle$CommonPlayerSpawnInfo$dimensionGetter = null;
|
||||
methodHandle$CommonPlayerSpawnInfo$dimensionGetter = null;
|
||||
}
|
||||
if (field$ClientboundRespawnPacket$commonPlayerSpawnInfo != null) {
|
||||
handle$ClientboundRespawnPacket$commonPlayerSpawnInfoGetter = requireNonNull(
|
||||
methodHandle$ClientboundRespawnPacket$commonPlayerSpawnInfoGetter = requireNonNull(
|
||||
ReflectionUtils.unreflectGetter(field$ClientboundRespawnPacket$commonPlayerSpawnInfo)
|
||||
.asType(MethodType.methodType(Object.class, Object.class))
|
||||
);
|
||||
} else {
|
||||
handle$ClientboundRespawnPacket$commonPlayerSpawnInfoGetter = null;
|
||||
methodHandle$ClientboundRespawnPacket$commonPlayerSpawnInfoGetter = null;
|
||||
}
|
||||
if (field$ClientboundRespawnPacket$dimension != null) {
|
||||
handle$ClientboundRespawnPacket$dimensionGetter = requireNonNull(
|
||||
methodHandle$ClientboundRespawnPacket$dimensionGetter = requireNonNull(
|
||||
ReflectionUtils.unreflectGetter(field$ClientboundRespawnPacket$dimension)
|
||||
.asType(MethodType.methodType(Object.class, Object.class))
|
||||
);
|
||||
} else {
|
||||
handle$ClientboundRespawnPacket$dimensionGetter = null;
|
||||
methodHandle$ClientboundRespawnPacket$dimensionGetter = null;
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
throw new ReflectionInitException("Failed to initialize reflection", e);
|
||||
|
||||
Reference in New Issue
Block a user