9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-31 04:46:37 +00:00

更新依赖

This commit is contained in:
XiaoMoMi
2025-05-12 22:57:29 +08:00
parent ed965137cc
commit 2731ce4d71
15 changed files with 103 additions and 58 deletions

View File

@@ -122,6 +122,7 @@ public class ItemEventListener implements Listener {
Block clickedBlock = Objects.requireNonNull(event.getClickedBlock());
BukkitServerPlayer player = this.plugin.adapt(bukkitPlayer);
InteractionHand hand = event.getHand() == EquipmentSlot.HAND ? InteractionHand.MAIN_HAND : InteractionHand.OFF_HAND;
// 如果同一tick已经处理过交互则忽略
if (cancelEventIfHasInteraction(event, player, hand)) {
return;
}
@@ -132,6 +133,7 @@ public class ItemEventListener implements Listener {
Optional<List<ItemBehavior>> optionalItemBehaviors = itemInHand.getItemBehavior();
// has custom item behavior
// 物品类型是否包含自定义物品行为,行为不一定来自于自定义物品,部分原版物品也包含了新的行为
if (optionalItemBehaviors.isPresent()) {
BlockPos pos = LocationUtils.toBlockPos(clickedBlock.getLocation());
Vec3d vec3d = new Vec3d(interactionPoint.getX(), interactionPoint.getY(), interactionPoint.getZ());
@@ -140,12 +142,17 @@ public class ItemEventListener implements Listener {
boolean interactable = InteractUtils.isInteractable(BlockStateUtils.getBlockOwnerId(clickedBlock), bukkitPlayer, clickedBlock.getBlockData(), hitResult, itemInHand);
// do not allow to place block if it's a vanilla block
// 如果这个是自定义物品,那么会阻止玩家放置其对应的原版方块
Optional<CustomItem<ItemStack>> optionalCustomItem = itemInHand.getCustomItem();
if (itemInHand.isBlockItem() && optionalCustomItem.isPresent()) {
// it's a custom item, but now it's ignored
// 如果用户设置了允许放置对应的原版方块,那么直接返回。
// todo 实际上这里的处理并不正确,因为判断玩家是否能够放置那个方块需要更加细节的判断。比如玩家无法对着树叶放置火把,但是交互事件依然触发,此情况下不可丢弃自定义行为。
if (optionalCustomItem.get().settings().canPlaceRelatedVanillaBlock()) {
return;
}
// 如果玩家潜行放置或者交互对象不可交互,那么取消掉事件以防止玩家放置。
// todo 这些处理应该要搬到BlockPlaceEvent?
if (!interactable || player.isSecondaryUseActive()) {
event.setCancelled(true);
}
@@ -180,10 +187,10 @@ public class ItemEventListener implements Listener {
return;
}
}
return;
}
// it's a vanilla block
// 这部分代码是处理放置原版方块“缺失的”声音和挥手动画
if (itemInHand.isBlockItem() && !itemInHand.isCustomItem()) {
// client won't have sounds if the fake block is interactable
// so we should check and resend sounds on interact

View File

@@ -0,0 +1,38 @@
package net.momirealms.craftengine.bukkit.plugin.classpath;
import net.momirealms.craftengine.bukkit.util.Reflections;
import net.momirealms.craftengine.core.plugin.Plugin;
import net.momirealms.craftengine.core.plugin.classpath.ClassPathAppender;
import net.momirealms.craftengine.core.plugin.classpath.URLClassLoaderAccess;
import java.net.MalformedURLException;
import java.net.URLClassLoader;
import java.nio.file.Path;
public class BukkitClassPathAppender implements ClassPathAppender {
private final URLClassLoaderAccess classLoaderAccess;
public BukkitClassPathAppender(ClassLoader classLoader) throws IllegalAccessException {
if (Reflections.clazz$PaperPluginClassLoader != null && Reflections.clazz$PaperPluginClassLoader.isInstance(classLoader)) {
URLClassLoader libraryClassLoader = (URLClassLoader) Reflections.field$PaperPluginClassLoader$libraryLoader.get(classLoader);
this.classLoaderAccess = URLClassLoaderAccess.create(libraryClassLoader);
} else if (classLoader instanceof URLClassLoader) {
this.classLoaderAccess = URLClassLoaderAccess.create((URLClassLoader) classLoader);
} else {
throw new IllegalStateException("ClassLoader is not instance of URLClassLoader");
}
}
public BukkitClassPathAppender(Plugin plugin) throws IllegalAccessException {
this(plugin.getClass().getClassLoader());
}
@Override
public void addJarToClasspath(Path file) {
try {
this.classLoaderAccess.addURL(file.toUri().toURL());
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}
}

View File

@@ -317,7 +317,6 @@ public class BukkitServerPlayer extends Player {
public void tick() {
// not fully online
if (serverPlayer() == null) return;
if (VersionHelper.isFolia()) {
try {
Object serverPlayer = serverPlayer();
@@ -329,7 +328,7 @@ public class BukkitServerPlayer extends Player {
} else {
this.gameTicks = FastNMS.INSTANCE.field$MinecraftServer$currentTick();
}
if (this.gameTicks % 15 == 0) {
if (this.gameTicks % 30 == 0) {
this.updateGUI();
}
if (this.isDestroyingBlock) {

View File

@@ -27,6 +27,7 @@ import sun.misc.Unsafe;
import java.io.BufferedReader;
import java.lang.invoke.VarHandle;
import java.lang.reflect.*;
import java.net.URLClassLoader;
import java.time.Instant;
import java.util.*;
import java.util.concurrent.CompletableFuture;
@@ -6675,4 +6676,12 @@ public class Reflections {
public static final Constructor<?> constructor$DiscardedPayload = Optional.ofNullable(clazz$DiscardedPayload)
.map(clazz -> ReflectionUtils.getTheOnlyConstructor(clazz))
.orElse(null);
public static final Class<?> clazz$PaperPluginClassLoader = ReflectionUtils.getClazz(
"io.papermc.paper.plugin.entrypoint.classloader.PaperPluginClassLoader"
);
public static final Field field$PaperPluginClassLoader$libraryLoader = Optional.ofNullable(clazz$PaperPluginClassLoader)
.map(it -> ReflectionUtils.getDeclaredField(it, URLClassLoader.class, 0))
.orElse(null);
}