9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-23 08:59:27 +00:00
This commit is contained in:
XiaoMoMi
2025-05-30 18:51:29 +08:00
parent bac73e5553
commit 70a89c0de3
3 changed files with 42 additions and 9 deletions

View File

@@ -4,6 +4,7 @@ import com.mojang.datafixers.util.Pair;
import net.momirealms.craftengine.bukkit.nms.FastNMS; import net.momirealms.craftengine.bukkit.nms.FastNMS;
import net.momirealms.craftengine.bukkit.plugin.BukkitCraftEngine; import net.momirealms.craftengine.bukkit.plugin.BukkitCraftEngine;
import net.momirealms.craftengine.bukkit.plugin.network.BukkitNetworkManager; import net.momirealms.craftengine.bukkit.plugin.network.BukkitNetworkManager;
import net.momirealms.craftengine.core.plugin.CraftEngine;
import net.momirealms.craftengine.core.util.RandomUtils; import net.momirealms.craftengine.core.util.RandomUtils;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Item; import org.bukkit.entity.Item;
@@ -20,9 +21,24 @@ import java.util.List;
import static java.util.Objects.requireNonNull; import static java.util.Objects.requireNonNull;
public class PlayerUtils { public final class PlayerUtils {
private PlayerUtils() {
}
private PlayerUtils() {} public static void resendItemInHand(@NotNull final Player player) {
ItemStack itemInHand = player.getInventory().getItemInMainHand();
if (ItemUtils.isEmpty(itemInHand)) return;
Object serverPlayer = FastNMS.INSTANCE.method$CraftPlayer$getHandle(player);
try {
Object inventoryMenu = Reflections.field$Player$inventoryMenu.get(serverPlayer);
int containerId = Reflections.field$AbstractContainerMenu$containerId.getInt(inventoryMenu);
int heldItemSlot = player.getInventory().getHeldItemSlot();
int stateId = (int) Reflections.method$AbstractContainerMenu$incrementStateId.invoke(inventoryMenu);
} catch (ReflectiveOperationException e) {
CraftEngine.instance().logger().warn("Failed to resend item in hand", e);
}
}
public static void dropItem(@NotNull Player player, @NotNull ItemStack itemStack, boolean retainOwnership, boolean noPickUpDelay, boolean throwRandomly) { public static void dropItem(@NotNull Player player, @NotNull ItemStack itemStack, boolean retainOwnership, boolean noPickUpDelay, boolean throwRandomly) {
requireNonNull(player, "player"); requireNonNull(player, "player");

View File

@@ -6982,4 +6982,21 @@ public class Reflections {
"nbt.Tag" "nbt.Tag"
) )
); );
public static final Class<?> clazz$InventoryMenu = requireNonNull(
BukkitReflectionUtils.findReobfOrMojmapClass(
"world.inventory.ContainerPlayer",
"world.inventory.InventoryMenu"
)
);
public static final Field field$Player$inventoryMenu = requireNonNull(
ReflectionUtils.getDeclaredField(clazz$Player, clazz$InventoryMenu, 0)
);
public static final Method method$AbstractContainerMenu$incrementStateId = requireNonNull(
ReflectionUtils.getMethod(
clazz$AbstractContainerMenu, int.class, new String[]{"incrementStateId", "k"}
)
);
} }

View File

@@ -2,7 +2,7 @@ org.gradle.jvmargs=-Xmx1G
# Project settings # Project settings
# Rule: [major update].[feature update].[bug fix] # Rule: [major update].[feature update].[bug fix]
project_version=0.0.55 project_version=0.0.55.1
config_version=34 config_version=34
lang_version=14 lang_version=14
project_group=net.momirealms project_group=net.momirealms