mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-30 12:29:15 +00:00
perf(entity): 优化反射操作
This commit is contained in:
@@ -366,8 +366,9 @@ public class BukkitFurniture implements Furniture {
|
||||
try {
|
||||
Object trackedEntity = FastNMS.INSTANCE.field$Entity$trackedEntity(nmsEntity);
|
||||
Object serverEntity = FastNMS.INSTANCE.filed$ChunkMap$TrackedEntity$serverEntity(trackedEntity);
|
||||
CoreReflections.field$ServerEntity$broadcast.set(serverEntity, Handlers.DO_NOTHING);
|
||||
} catch (Exception e) {
|
||||
CoreReflections.handle$ServerEntity$broadcastSetter.invoke(serverEntity, Handlers.DO_NOTHING);
|
||||
CoreReflections.handle$ServerEntity$updateIntervalSetter.invoke(serverEntity, Integer.MAX_VALUE);
|
||||
} catch (Throwable e) {
|
||||
CraftEngine.instance().logger().warn("Failed to inject collider", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,7 +70,6 @@ import org.bukkit.util.RayTraceResult;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.util.function.BiConsumer;
|
||||
@@ -1170,21 +1169,21 @@ public class PacketConsumers {
|
||||
public static final TriConsumer<NetWorkUser, NMSPacketEvent, Object> HELLO_C2S = (user, event, packet) -> {
|
||||
try {
|
||||
BukkitServerPlayer player = (BukkitServerPlayer) user;
|
||||
String name = (String) NetworkReflections.field$ServerboundHelloPacket$name.get(packet);
|
||||
String name = (String) NetworkReflections.handle$ServerboundHelloPacket$nameGetter.invoke(packet);
|
||||
player.setName(name);
|
||||
if (VersionHelper.isOrAbove1_20_2()) {
|
||||
UUID uuid = (UUID) NetworkReflections.field$ServerboundHelloPacket$uuid.get(packet);
|
||||
UUID uuid = (UUID) NetworkReflections.handle$ServerboundHelloPacket$uuidGetter.invoke(packet);
|
||||
player.setUUID(uuid);
|
||||
} else {
|
||||
@SuppressWarnings("unchecked")
|
||||
Optional<UUID> uuid = (Optional<UUID>) NetworkReflections.field$ServerboundHelloPacket$uuid.get(packet);
|
||||
Optional<UUID> uuid = (Optional<UUID>) NetworkReflections.handle$ServerboundHelloPacket$uuidGetter.invoke(packet);
|
||||
if (uuid.isPresent()) {
|
||||
player.setUUID(uuid.get());
|
||||
} else {
|
||||
player.setUUID(UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(StandardCharsets.UTF_8)));
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
CraftEngine.instance().logger().warn("Failed to handle ServerboundHelloPacket", e);
|
||||
}
|
||||
};
|
||||
@@ -1221,10 +1220,10 @@ public class PacketConsumers {
|
||||
player.clearView();
|
||||
Object dimensionKey;
|
||||
if (!VersionHelper.isOrAbove1_20_2()) {
|
||||
dimensionKey = NetworkReflections.field$ClientboundRespawnPacket$dimension.get(packet);
|
||||
dimensionKey = NetworkReflections.handle$ClientboundRespawnPacket$dimensionGetter.invoke(packet);
|
||||
} else {
|
||||
Object commonInfo = NetworkReflections.field$ClientboundRespawnPacket$commonPlayerSpawnInfo.get(packet);
|
||||
dimensionKey = NetworkReflections.field$CommonPlayerSpawnInfo$dimension.get(commonInfo);
|
||||
Object commonInfo = NetworkReflections.handle$ClientboundRespawnPacket$commonPlayerSpawnInfoGetter.invoke(packet);
|
||||
dimensionKey = NetworkReflections.handle$CommonPlayerSpawnInfo$dimensionGetter.invoke(commonInfo);
|
||||
}
|
||||
Object location = FastNMS.INSTANCE.field$ResourceKey$location(dimensionKey);
|
||||
World world = Bukkit.getWorld(Objects.requireNonNull(NamespacedKey.fromString(location.toString())));
|
||||
@@ -1235,7 +1234,7 @@ public class PacketConsumers {
|
||||
} else {
|
||||
CraftEngine.instance().logger().warn("Failed to handle ClientboundRespawnPacket: World " + location + " does not exist");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
CraftEngine.instance().logger().warn("Failed to handle ClientboundRespawnPacket", e);
|
||||
}
|
||||
};
|
||||
@@ -1249,10 +1248,10 @@ public class PacketConsumers {
|
||||
if (BukkitNetworkManager.hasViaVersion()) {
|
||||
user.setProtocolVersion(CraftEngine.instance().compatibilityManager().getPlayerProtocolVersion(player.uuid()));
|
||||
}
|
||||
dimensionKey = NetworkReflections.field$ClientboundLoginPacket$dimension.get(packet);
|
||||
dimensionKey = NetworkReflections.handle$ClientboundLoginPacket$dimensionGetter.invoke(packet);
|
||||
} else {
|
||||
Object commonInfo = NetworkReflections.field$ClientboundLoginPacket$commonPlayerSpawnInfo.get(packet);
|
||||
dimensionKey = NetworkReflections.field$CommonPlayerSpawnInfo$dimension.get(commonInfo);
|
||||
Object commonInfo = NetworkReflections.handle$ClientboundLoginPacket$commonPlayerSpawnInfoGetter.invoke(packet);
|
||||
dimensionKey = NetworkReflections.handle$CommonPlayerSpawnInfo$dimensionGetter.invoke(commonInfo);
|
||||
}
|
||||
Object location = FastNMS.INSTANCE.field$ResourceKey$location(dimensionKey);
|
||||
World world = Bukkit.getWorld(Objects.requireNonNull(NamespacedKey.fromString(location.toString())));
|
||||
@@ -1263,7 +1262,7 @@ public class PacketConsumers {
|
||||
} else {
|
||||
CraftEngine.instance().logger().warn("Failed to handle ClientboundLoginPacket: World " + location + " does not exist");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
CraftEngine.instance().logger().warn("Failed to handle ClientboundLoginPacket", e);
|
||||
}
|
||||
};
|
||||
@@ -1280,25 +1279,25 @@ public class PacketConsumers {
|
||||
player.platformPlayer().getScheduler().run(BukkitCraftEngine.instance().javaPlugin(), (t) -> {
|
||||
try {
|
||||
handleSetCreativeSlotPacketOnMainThread(player, packet);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
CraftEngine.instance().logger().warn("Failed to handle ServerboundSetCreativeModeSlotPacket", e);
|
||||
}
|
||||
}, () -> {});
|
||||
} else {
|
||||
handleSetCreativeSlotPacketOnMainThread(player, packet);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
CraftEngine.instance().logger().warn("Failed to handle ServerboundSetCreativeModeSlotPacket", e);
|
||||
}
|
||||
};
|
||||
|
||||
private static void handleSetCreativeSlotPacketOnMainThread(BukkitServerPlayer player, Object packet) throws Exception {
|
||||
private static void handleSetCreativeSlotPacketOnMainThread(BukkitServerPlayer player, Object packet) throws Throwable {
|
||||
Player bukkitPlayer = player.platformPlayer();
|
||||
if (bukkitPlayer == null) return;
|
||||
if (bukkitPlayer.getGameMode() != GameMode.CREATIVE) return;
|
||||
int slot = VersionHelper.isOrAbove1_20_5() ? NetworkReflections.field$ServerboundSetCreativeModeSlotPacket$slotNum.getShort(packet) : NetworkReflections.field$ServerboundSetCreativeModeSlotPacket$slotNum.getInt(packet);
|
||||
int slot = (int) NetworkReflections.handle$ServerboundSetCreativeModeSlotPacket$slotNumGetter.invoke(packet);
|
||||
if (slot < 36 || slot > 44) return;
|
||||
ItemStack item = FastNMS.INSTANCE.method$CraftItemStack$asCraftMirror(NetworkReflections.field$ServerboundSetCreativeModeSlotPacket$itemStack.get(packet));
|
||||
ItemStack item = FastNMS.INSTANCE.method$CraftItemStack$asCraftMirror(NetworkReflections.handle$ServerboundSetCreativeModeSlotPacket$itemStackGetter.invoke(packet));
|
||||
if (ItemUtils.isEmpty(item)) return;
|
||||
if (slot - 36 != bukkitPlayer.getInventory().getHeldItemSlot()) {
|
||||
return;
|
||||
@@ -1371,14 +1370,14 @@ public class PacketConsumers {
|
||||
if (!user.isOnline()) return;
|
||||
Player player = (Player) user.platformPlayer();
|
||||
if (player == null) return;
|
||||
Object pos = NetworkReflections.field$ServerboundPickItemFromBlockPacket$pos.get(packet);
|
||||
Object pos = NetworkReflections.handle$ServerboundPickItemFromBlockPacket$posGetter.invoke(packet);
|
||||
if (VersionHelper.isFolia()) {
|
||||
int x = FastNMS.INSTANCE.field$Vec3i$x(pos);
|
||||
int z = FastNMS.INSTANCE.field$Vec3i$z(pos);
|
||||
BukkitCraftEngine.instance().scheduler().sync().run(() -> {
|
||||
try {
|
||||
handlePickItemFromBlockPacketOnMainThread(player, pos);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
CraftEngine.instance().logger().warn("Failed to handle ServerboundPickItemFromBlockPacket", e);
|
||||
}
|
||||
}, player.getWorld(), x >> 4, z >> 4);
|
||||
@@ -1386,17 +1385,17 @@ public class PacketConsumers {
|
||||
BukkitCraftEngine.instance().scheduler().sync().run(() -> {
|
||||
try {
|
||||
handlePickItemFromBlockPacketOnMainThread(player, pos);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
CraftEngine.instance().logger().warn("Failed to handle ServerboundPickItemFromBlockPacket", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
CraftEngine.instance().logger().warn("Failed to handle ServerboundPickItemFromBlockPacket", e);
|
||||
}
|
||||
};
|
||||
|
||||
private static void handlePickItemFromBlockPacketOnMainThread(Player player, Object pos) throws Exception {
|
||||
private static void handlePickItemFromBlockPacketOnMainThread(Player player, Object pos) throws Throwable {
|
||||
Object serverLevel = FastNMS.INSTANCE.field$CraftWorld$ServerLevel(player.getWorld());
|
||||
Object blockState = FastNMS.INSTANCE.method$BlockGetter$getBlockState(serverLevel, pos);
|
||||
ImmutableBlockState state = BukkitBlockManager.instance().getImmutableBlockState(BlockStateUtils.blockStateToId(blockState));
|
||||
@@ -1409,7 +1408,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.field$ServerboundPickItemFromEntityPacket$id.get(packet);
|
||||
int entityId = (int) NetworkReflections.handle$ServerboundPickItemFromEntityPacket$idGetter.invoke(packet);
|
||||
BukkitFurniture furniture = BukkitFurnitureManager.instance().loadedFurnitureByEntityId(entityId);
|
||||
if (furniture == null) return;
|
||||
Player player = (Player) user.platformPlayer();
|
||||
@@ -1418,7 +1417,7 @@ public class PacketConsumers {
|
||||
player.getScheduler().run(BukkitCraftEngine.instance().javaPlugin(), (t) -> {
|
||||
try {
|
||||
handlePickItemFromEntityOnMainThread(player, furniture);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
CraftEngine.instance().logger().warn("Failed to handle ServerboundPickItemFromEntityPacket", e);
|
||||
}
|
||||
}, () -> {});
|
||||
@@ -1426,23 +1425,23 @@ public class PacketConsumers {
|
||||
BukkitCraftEngine.instance().scheduler().sync().run(() -> {
|
||||
try {
|
||||
handlePickItemFromEntityOnMainThread(player, furniture);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
CraftEngine.instance().logger().warn("Failed to handle ServerboundPickItemFromEntityPacket", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
CraftEngine.instance().logger().warn("Failed to handle ServerboundPickItemFromEntityPacket", e);
|
||||
}
|
||||
};
|
||||
|
||||
private static void handlePickItemFromEntityOnMainThread(Player player, BukkitFurniture furniture) throws Exception {
|
||||
private static void handlePickItemFromEntityOnMainThread(Player player, BukkitFurniture furniture) throws Throwable {
|
||||
Key itemId = furniture.config().settings().itemId();
|
||||
if (itemId == null) return;
|
||||
pickItem(player, itemId, null, FastNMS.INSTANCE.method$CraftEntity$getHandle(furniture.baseEntity()));
|
||||
}
|
||||
|
||||
private static void pickItem(Player player, Key itemId, @Nullable Object blockPos, @Nullable Object entity) throws IllegalAccessException, InvocationTargetException {
|
||||
private static void pickItem(Player player, Key itemId, @Nullable Object blockPos, @Nullable Object entity) throws Throwable {
|
||||
ItemStack itemStack = BukkitCraftEngine.instance().itemManager().buildCustomItemStack(itemId, BukkitCraftEngine.instance().adapt(player));
|
||||
if (itemStack == null) {
|
||||
CraftEngine.instance().logger().warn("Item: " + itemId + " is not a valid item");
|
||||
@@ -1451,11 +1450,11 @@ public class PacketConsumers {
|
||||
assert CoreReflections.method$ServerGamePacketListenerImpl$tryPickItem != null;
|
||||
if (VersionHelper.isOrAbove1_21_5()) {
|
||||
CoreReflections.method$ServerGamePacketListenerImpl$tryPickItem.invoke(
|
||||
CoreReflections.field$ServerPlayer$connection.get(FastNMS.INSTANCE.method$CraftPlayer$getHandle(player)),
|
||||
CoreReflections.handle$ServerPlayer$connectionGetter.invoke(FastNMS.INSTANCE.method$CraftPlayer$getHandle(player)),
|
||||
FastNMS.INSTANCE.method$CraftItemStack$asNMSCopy(itemStack), blockPos, entity, true);
|
||||
} else {
|
||||
CoreReflections.method$ServerGamePacketListenerImpl$tryPickItem.invoke(
|
||||
CoreReflections.field$ServerPlayer$connection.get(FastNMS.INSTANCE.method$CraftPlayer$getHandle(player)), FastNMS.INSTANCE.method$CraftItemStack$asNMSCopy(itemStack));
|
||||
CoreReflections.handle$ServerPlayer$connectionGetter.invoke(FastNMS.INSTANCE.method$CraftPlayer$getHandle(player)), FastNMS.INSTANCE.method$CraftItemStack$asNMSCopy(itemStack));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1520,7 +1519,7 @@ public class PacketConsumers {
|
||||
}
|
||||
BukkitFurniture furniture = BukkitFurnitureManager.instance().loadedFurnitureByEntityId(entityId);
|
||||
if (furniture == null) return;
|
||||
Object action = NetworkReflections.field$ServerboundInteractPacket$action.get(packet);
|
||||
Object action = NetworkReflections.handle$ServerboundInteractPacket$actionGetter.invoke(packet);
|
||||
Object actionType = NetworkReflections.method$ServerboundInteractPacket$Action$getType.invoke(action);
|
||||
if (actionType == null) return;
|
||||
Location location = furniture.baseEntity().getLocation();
|
||||
@@ -1553,15 +1552,15 @@ public class PacketConsumers {
|
||||
InteractionHand hand;
|
||||
Location interactionPoint;
|
||||
try {
|
||||
Object interactionHand = NetworkReflections.field$ServerboundInteractPacket$InteractionAtLocationAction$hand.get(action);
|
||||
Object interactionHand = NetworkReflections.handle$ServerboundInteractPacket$InteractionAtLocationAction$handGetter.invoke(action);
|
||||
hand = interactionHand == CoreReflections.instance$InteractionHand$MAIN_HAND ? InteractionHand.MAIN_HAND : InteractionHand.OFF_HAND;
|
||||
Object vec3 = NetworkReflections.field$ServerboundInteractPacket$InteractionAtLocationAction$location.get(action);
|
||||
Object vec3 = NetworkReflections.handle$ServerboundInteractPacket$InteractionAtLocationAction$locationGetter.invoke(action);
|
||||
|
||||
double x = FastNMS.INSTANCE.field$Vec3$x(vec3);
|
||||
double y = FastNMS.INSTANCE.field$Vec3$y(vec3);
|
||||
double z = FastNMS.INSTANCE.field$Vec3$z(vec3);
|
||||
interactionPoint = new Location(location.getWorld(), x, y, z);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException("Failed to get interaction hand from interact packet", e);
|
||||
}
|
||||
FurnitureInteractEvent interactEvent = new FurnitureInteractEvent(serverPlayer.platformPlayer(), furniture, hand, interactionPoint);
|
||||
@@ -1612,7 +1611,7 @@ public class PacketConsumers {
|
||||
}
|
||||
}
|
||||
}, player.getWorld(), location.getBlockX() >> 4, location.getBlockZ() >> 4);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
CraftEngine.instance().logger().warn("Failed to handle ServerboundInteractPacket", e);
|
||||
}
|
||||
};
|
||||
@@ -1697,20 +1696,20 @@ public class PacketConsumers {
|
||||
if (((BukkitServerPlayer) user).hasPermission(FontManager.BYPASS_ANVIL)) {
|
||||
return;
|
||||
}
|
||||
String message = (String) NetworkReflections.field$ServerboundRenameItemPacket$name.get(packet);
|
||||
String message = (String) NetworkReflections.handle$ServerboundRenameItemPacket$nameGetter.invoke(packet);
|
||||
if (message != null && !message.isEmpty()) {
|
||||
// check bypass
|
||||
FontManager manager = CraftEngine.instance().fontManager();
|
||||
IllegalCharacterProcessResult result = manager.processIllegalCharacters(message);
|
||||
if (result.has()) {
|
||||
try {
|
||||
NetworkReflections.field$ServerboundRenameItemPacket$name.set(packet, result.text());
|
||||
NetworkReflections.handle$ServerboundRenameItemPacket$nameSetter.invoke(packet, result.text());
|
||||
} catch (ReflectiveOperationException e) {
|
||||
CraftEngine.instance().logger().warn("Failed to replace chat", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
CraftEngine.instance().logger().warn("Failed to handle ServerboundRenameItemPacket", e);
|
||||
}
|
||||
};
|
||||
@@ -1723,7 +1722,7 @@ public class PacketConsumers {
|
||||
if (((BukkitServerPlayer) user).hasPermission(FontManager.BYPASS_SIGN)) {
|
||||
return;
|
||||
}
|
||||
String[] lines = (String[]) NetworkReflections.field$ServerboundSignUpdatePacket$lines.get(packet);
|
||||
String[] lines = (String[]) NetworkReflections.handle$ServerboundSignUpdatePacket$linesGetter.invoke(packet);
|
||||
FontManager manager = CraftEngine.instance().fontManager();
|
||||
if (!manager.isDefaultFontInUse()) return;
|
||||
for (int i = 0; i < lines.length; i++) {
|
||||
@@ -1735,7 +1734,7 @@ public class PacketConsumers {
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
CraftEngine.instance().logger().warn("Failed to handle ServerboundSignUpdatePacket", e);
|
||||
}
|
||||
};
|
||||
@@ -1754,9 +1753,9 @@ public class PacketConsumers {
|
||||
|
||||
boolean changed = false;
|
||||
|
||||
List<String> pages = (List<String>) NetworkReflections.field$ServerboundEditBookPacket$pages.get(packet);
|
||||
List<String> pages = (List<String>) NetworkReflections.handleServerboundEditBookPacket$pagesGetter.invoke(packet);
|
||||
List<String> newPages = new ArrayList<>(pages.size());
|
||||
Optional<String> title = (Optional<String>) NetworkReflections.field$ServerboundEditBookPacket$title.get(packet);
|
||||
Optional<String> title = (Optional<String>) NetworkReflections.handle$ServerboundEditBookPacket$titleGetter.invoke(packet);
|
||||
Optional<String> newTitle;
|
||||
|
||||
if (title.isPresent()) {
|
||||
@@ -1780,13 +1779,13 @@ public class PacketConsumers {
|
||||
|
||||
if (changed) {
|
||||
Object newPacket = NetworkReflections.constructor$ServerboundEditBookPacket.newInstance(
|
||||
NetworkReflections.field$ServerboundEditBookPacket$slot.get(packet),
|
||||
NetworkReflections.handle$ServerboundEditBookPacket$slotGetter.invoke(packet),
|
||||
newPages,
|
||||
newTitle
|
||||
);
|
||||
event.replacePacket(newPacket);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
CraftEngine.instance().logger().warn("Failed to handle ServerboundEditBookPacket", e);
|
||||
}
|
||||
};
|
||||
@@ -1813,7 +1812,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.field$ServerboundCustomPayloadPacket$payload.get(packet);
|
||||
Object payload = NetworkReflections.handle$ServerboundCustomPayloadPacket$payloadGetter.invoke(packet);
|
||||
if (NetworkReflections.clazz$DiscardedPayload.isInstance(payload)) {
|
||||
Payload discardedPayload = DiscardedPayload.from(payload);
|
||||
if (discardedPayload == null || !discardedPayload.channel().equals(NetworkManager.MOD_CHANNEL_KEY))
|
||||
@@ -1842,7 +1841,7 @@ public class PacketConsumers {
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
CraftEngine.instance().logger().warn("Failed to handle ServerboundCustomPayloadPacket", e);
|
||||
}
|
||||
};
|
||||
@@ -2232,9 +2231,9 @@ public class PacketConsumers {
|
||||
public static final TriConsumer<NetWorkUser, NMSPacketEvent, Object> HANDSHAKE_C2S = (user, event, packet) -> {
|
||||
try {
|
||||
if (BukkitNetworkManager.hasViaVersion()) return;
|
||||
int protocolVersion = NetworkReflections.field$ClientIntentionPacket$protocolVersion.getInt(packet);
|
||||
int protocolVersion = (int) NetworkReflections.handle$ClientIntentionPacket$protocolVersionGetter.invoke(packet);
|
||||
user.setProtocolVersion(protocolVersion);
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
CraftEngine.instance().logger().warn("Failed to handle ClientIntentionPacket", e);
|
||||
}
|
||||
};
|
||||
@@ -2252,7 +2251,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.field$ServerboundResourcePackPacket$action.get(packet);
|
||||
Object action = NetworkReflections.handle$ServerboundResourcePackPacket$actionGetter.invoke(packet);
|
||||
if (action == null) return;
|
||||
if (action == NetworkReflections.instance$ServerboundResourcePackPacket$Action$DECLINED
|
||||
|| action == NetworkReflections.instance$ServerboundResourcePackPacket$Action$FAILED_DOWNLOAD) {
|
||||
@@ -2265,7 +2264,7 @@ public class PacketConsumers {
|
||||
if (action == NetworkReflections.instance$ServerboundResourcePackPacket$Action$SUCCESSFULLY_LOADED) {
|
||||
user.setSentResourcePack(true);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
CraftEngine.instance().logger().warn("Failed to handle ServerboundResourcePackPacket", e);
|
||||
}
|
||||
};
|
||||
@@ -2274,13 +2273,13 @@ public class PacketConsumers {
|
||||
try {
|
||||
Object player = user.serverPlayer();
|
||||
if (player == null) return;
|
||||
int entityId = NetworkReflections.field$ClientboundEntityEventPacket$entityId.getInt(packet);
|
||||
int entityId = (int) NetworkReflections.handle$ClientboundEntityEventPacket$entityIdGetter.invoke(packet);
|
||||
if (entityId != FastNMS.INSTANCE.method$Entity$getId(player)) return;
|
||||
byte eventId = NetworkReflections.field$ClientboundEntityEventPacket$eventId.getByte(packet);
|
||||
byte eventId = (byte) NetworkReflections.handle$ClientboundEntityEventPacket$eventIdGetter.invoke(packet);
|
||||
if (eventId >= 24 && eventId <= 28) {
|
||||
CraftEngine.instance().fontManager().refreshEmojiSuggestions(user.uuid());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (Throwable e) {
|
||||
CraftEngine.instance().logger().warn("Failed to handle ClientboundEntityEventPacket", e);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -11,6 +11,7 @@ import net.momirealms.craftengine.core.util.ReflectionUtils;
|
||||
import net.momirealms.craftengine.core.util.VersionHelper;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.VarHandle;
|
||||
import java.lang.reflect.*;
|
||||
import java.util.*;
|
||||
@@ -3271,4 +3272,16 @@ public final class CoreReflections {
|
||||
clazz$ServerEntity, Consumer.class, 0
|
||||
)
|
||||
);
|
||||
|
||||
public static final MethodHandle handle$ServerEntity$broadcastSetter = requireNonNull(
|
||||
ReflectionUtils.unreflectSetter(field$ServerEntity$broadcast)
|
||||
);
|
||||
|
||||
public static final MethodHandle handle$ServerEntity$updateIntervalSetter = requireNonNull(
|
||||
ReflectionUtils.unreflectSetter(field$ServerEntity$updateInterval)
|
||||
);
|
||||
|
||||
public static final MethodHandle handle$ServerPlayer$connectionGetter = requireNonNull(
|
||||
ReflectionUtils.unreflectGetter(field$ServerPlayer$connection)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import net.momirealms.craftengine.bukkit.util.BukkitReflectionUtils;
|
||||
import net.momirealms.craftengine.core.util.ReflectionUtils;
|
||||
import net.momirealms.craftengine.core.util.VersionHelper;
|
||||
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
@@ -1293,4 +1294,105 @@ public final class NetworkReflections {
|
||||
public static final Constructor<?> constructor$ClientboundTickingStatePacket = Optional.ofNullable(clazz$ClientboundTickingStatePacket)
|
||||
.map(it -> ReflectionUtils.getConstructor(it, float.class, boolean.class))
|
||||
.orElse(null);
|
||||
|
||||
public static final MethodHandle handle$ServerboundRenameItemPacket$nameGetter = requireNonNull(
|
||||
ReflectionUtils.unreflectGetter(field$ServerboundRenameItemPacket$name)
|
||||
);
|
||||
|
||||
public static final MethodHandle handle$ServerboundRenameItemPacket$nameSetter = requireNonNull(
|
||||
ReflectionUtils.unreflectSetter(field$ServerboundRenameItemPacket$name)
|
||||
);
|
||||
|
||||
public static final MethodHandle handle$ServerboundHelloPacket$nameGetter = requireNonNull(
|
||||
ReflectionUtils.unreflectGetter(field$ServerboundHelloPacket$name)
|
||||
);
|
||||
|
||||
public static final MethodHandle handle$ServerboundHelloPacket$uuidGetter = requireNonNull(
|
||||
ReflectionUtils.unreflectGetter(field$ServerboundHelloPacket$uuid)
|
||||
);
|
||||
|
||||
public static final MethodHandle handle$ClientboundRespawnPacket$dimensionGetter = Optional.ofNullable(field$ClientboundRespawnPacket$dimension)
|
||||
.map(ReflectionUtils::unreflectGetter)
|
||||
.orElse(null);
|
||||
|
||||
public static final MethodHandle handle$ClientboundRespawnPacket$commonPlayerSpawnInfoGetter = Optional.ofNullable(field$ClientboundRespawnPacket$commonPlayerSpawnInfo)
|
||||
.map(ReflectionUtils::unreflectGetter)
|
||||
.orElse(null);
|
||||
|
||||
public static final MethodHandle handle$CommonPlayerSpawnInfo$dimensionGetter = Optional.ofNullable(field$CommonPlayerSpawnInfo$dimension)
|
||||
.map(ReflectionUtils::unreflectGetter)
|
||||
.orElse(null);
|
||||
|
||||
public static final MethodHandle handle$ClientboundLoginPacket$dimensionGetter = Optional.ofNullable(field$ClientboundLoginPacket$dimension)
|
||||
.map(ReflectionUtils::unreflectGetter)
|
||||
.orElse(null);
|
||||
|
||||
public static final MethodHandle handle$ClientboundLoginPacket$commonPlayerSpawnInfoGetter = Optional.ofNullable(field$ClientboundLoginPacket$commonPlayerSpawnInfo)
|
||||
.map(ReflectionUtils::unreflectGetter)
|
||||
.orElse(null);
|
||||
|
||||
public static final MethodHandle handle$ServerboundSetCreativeModeSlotPacket$itemStackGetter = requireNonNull(
|
||||
ReflectionUtils.unreflectGetter(field$ServerboundSetCreativeModeSlotPacket$itemStack)
|
||||
);
|
||||
|
||||
public static final MethodHandle handle$ServerboundSetCreativeModeSlotPacket$slotNumGetter = requireNonNull(
|
||||
ReflectionUtils.unreflectGetter(field$ServerboundSetCreativeModeSlotPacket$slotNum)
|
||||
);
|
||||
|
||||
public static final MethodHandle handle$ServerboundPickItemFromBlockPacket$posGetter = Optional.ofNullable(field$ServerboundPickItemFromBlockPacket$pos)
|
||||
.map(ReflectionUtils::unreflectGetter)
|
||||
.orElse(null);
|
||||
|
||||
public static final MethodHandle handle$ServerboundPickItemFromEntityPacket$idGetter = Optional.ofNullable(field$ServerboundPickItemFromEntityPacket$id)
|
||||
.map(ReflectionUtils::unreflectGetter)
|
||||
.orElse(null);
|
||||
|
||||
public static final MethodHandle handle$ServerboundInteractPacket$actionGetter = requireNonNull(
|
||||
ReflectionUtils.unreflectGetter(field$ServerboundInteractPacket$action)
|
||||
);
|
||||
|
||||
public static final MethodHandle handle$ServerboundInteractPacket$InteractionAtLocationAction$handGetter = requireNonNull(
|
||||
ReflectionUtils.unreflectGetter(field$ServerboundInteractPacket$InteractionAtLocationAction$hand)
|
||||
);
|
||||
|
||||
public static final MethodHandle handle$ServerboundInteractPacket$InteractionAtLocationAction$locationGetter = requireNonNull(
|
||||
ReflectionUtils.unreflectGetter(field$ServerboundInteractPacket$InteractionAtLocationAction$location)
|
||||
);
|
||||
|
||||
public static final MethodHandle handle$ServerboundSignUpdatePacket$linesGetter = requireNonNull(
|
||||
ReflectionUtils.unreflectGetter(field$ServerboundSignUpdatePacket$lines)
|
||||
);
|
||||
|
||||
public static final MethodHandle handleServerboundEditBookPacket$pagesGetter = requireNonNull(
|
||||
ReflectionUtils.unreflectGetter(field$ServerboundEditBookPacket$pages)
|
||||
);
|
||||
|
||||
public static final MethodHandle handle$ServerboundEditBookPacket$titleGetter = requireNonNull(
|
||||
ReflectionUtils.unreflectGetter(field$ServerboundEditBookPacket$title)
|
||||
);
|
||||
|
||||
public static final MethodHandle handle$ServerboundEditBookPacket$slotGetter = requireNonNull(
|
||||
ReflectionUtils.unreflectGetter(field$ServerboundEditBookPacket$slot)
|
||||
);
|
||||
|
||||
public static final MethodHandle handle$ServerboundCustomPayloadPacket$payloadGetter = Optional.ofNullable(field$ServerboundCustomPayloadPacket$payload)
|
||||
.map(ReflectionUtils::unreflectGetter)
|
||||
.orElse(null);
|
||||
|
||||
public static final MethodHandle handle$ServerboundResourcePackPacket$actionGetter = requireNonNull(
|
||||
ReflectionUtils.unreflectGetter(field$ServerboundResourcePackPacket$action)
|
||||
);
|
||||
|
||||
public static final MethodHandle handle$ClientboundEntityEventPacket$entityIdGetter = requireNonNull(
|
||||
ReflectionUtils.unreflectGetter(field$ClientboundEntityEventPacket$entityId)
|
||||
);
|
||||
|
||||
public static final MethodHandle handle$ClientboundEntityEventPacket$eventIdGetter = requireNonNull(
|
||||
ReflectionUtils.unreflectGetter(field$ClientboundEntityEventPacket$eventId)
|
||||
);
|
||||
|
||||
public static final MethodHandle handle$ClientIntentionPacket$protocolVersionGetter = requireNonNull(
|
||||
ReflectionUtils.unreflectGetter(field$ClientIntentionPacket$protocolVersion)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user