diff --git a/bukkit/compatibility/build.gradle.kts b/bukkit/compatibility/build.gradle.kts index 949b79fe4..13d93e5cd 100644 --- a/bukkit/compatibility/build.gradle.kts +++ b/bukkit/compatibility/build.gradle.kts @@ -41,8 +41,8 @@ dependencies { compileOnly("io.github.toxicity188:bettermodel:1.14.0") compileOnly("com.mojang:authlib:${rootProject.properties["authlib_version"]}") // MMOItems - compileOnly("net.Indyuce:MMOItems-API:6.10-SNAPSHOT") - compileOnly("io.lumine:MythicLib-dist:1.6.2-SNAPSHOT") + compileOnly("net.Indyuce:MMOItems-API:6.10.1-SNAPSHOT") + compileOnly("io.lumine:MythicLib-dist:1.7.1-SNAPSHOT") // Nexo compileOnly("com.nexomc:nexo:1.13.0") // LuckPerms @@ -62,7 +62,7 @@ dependencies { // McMMO compileOnly("com.gmail.nossr50.mcMMO:mcMMO:2.2.038") // MMOCore - compileOnly("net.Indyuce:MMOCore-API:1.12.1-SNAPSHOT") + compileOnly("net.Indyuce:MMOCore-API:1.13.1-SNAPSHOT") // JobsReborn compileOnly("com.github.Zrips:Jobs:v5.2.2.3") // CustomFishing diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/BlockEventListener.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/BlockEventListener.java index 8da86d668..49ffc0057 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/BlockEventListener.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/BlockEventListener.java @@ -21,6 +21,7 @@ import net.momirealms.craftengine.core.plugin.context.ContextHolder; import net.momirealms.craftengine.core.plugin.context.PlayerOptionalContext; import net.momirealms.craftengine.core.plugin.context.event.EventTrigger; import net.momirealms.craftengine.core.plugin.context.parameter.DirectContextParameters; +import net.momirealms.craftengine.core.sound.SoundData; import net.momirealms.craftengine.core.sound.SoundSource; import net.momirealms.craftengine.core.util.Cancellable; import net.momirealms.craftengine.core.util.ItemUtils; @@ -38,6 +39,7 @@ import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockPhysicsEvent; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.world.GenericGameEvent; import org.bukkit.inventory.ItemStack; @@ -233,12 +235,14 @@ public final class BlockEventListener implements Listener { @EventHandler(priority = EventPriority.LOW) public void onStep(GenericGameEvent event) { - if (event.getEvent() != GameEvent.STEP) return; + GameEvent gameEvent = event.getEvent(); + // 只处理落地和走路 + if (gameEvent != GameEvent.STEP) return; Entity entity = event.getEntity(); if (!(entity instanceof Player player)) return; BlockPos pos = EntityUtils.getOnPos(player); Block block = player.getWorld().getBlockAt(pos.x(), pos.y(), pos.z()); - Object blockState = FastNMS.INSTANCE.method$BlockGetter$getBlockState(FastNMS.INSTANCE.field$CraftWorld$ServerLevel(block.getWorld()), LocationUtils.toBlockPos(block.getX(), block.getY(), block.getZ())); + Object blockState = FastNMS.INSTANCE.method$BlockGetter$getBlockState(FastNMS.INSTANCE.field$CraftWorld$ServerLevel(player.getWorld()), LocationUtils.toBlockPos(pos)); Optional optionalCustomState = BlockStateUtils.getOptionalCustomBlockState(blockState); if (optionalCustomState.isPresent()) { Location location = player.getLocation(); @@ -253,7 +257,8 @@ public final class BlockEventListener implements Listener { if (cancellable.isCancelled() && !Config.processCancelledStep()) { return; } - player.playSound(location, state.settings().sounds().stepSound().id().toString(), SoundCategory.BLOCKS, state.settings().sounds().stepSound().volume().get(), state.settings().sounds().stepSound().pitch().get()); + SoundData soundData = state.settings().sounds().stepSound(); + player.playSound(location, soundData.id().toString(), SoundCategory.BLOCKS, soundData.volume().get(), soundData.pitch().get()); } else if (Config.enableSoundSystem()) { if (event.isCancelled() && !Config.processCancelledStep()) { return; @@ -267,6 +272,32 @@ public final class BlockEventListener implements Listener { } } + @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH) + public void onFall(EntityDamageEvent event) { + if (event.getCause() != EntityDamageEvent.DamageCause.FALL) + return; + if (!(event.getEntity() instanceof Player player)) return; + BlockPos pos = EntityUtils.getOnPos(player); + Object blockState = FastNMS.INSTANCE.method$BlockGetter$getBlockState(FastNMS.INSTANCE.field$CraftWorld$ServerLevel(player.getWorld()), LocationUtils.toBlockPos(pos)); + Optional optionalCustomState = BlockStateUtils.getOptionalCustomBlockState(blockState); + if (optionalCustomState.isPresent()) { + Location location = player.getLocation(); + ImmutableBlockState state = optionalCustomState.get(); + SoundData soundData = state.settings().sounds().fallSound(); + player.playSound(location, soundData.id().toString(), SoundCategory.BLOCKS, soundData.volume().get(), soundData.pitch().get()); + } else if (Config.enableSoundSystem()) { + if (event.isCancelled() && !Config.processCancelledStep()) { + return; + } + Object soundType = FastNMS.INSTANCE.method$BlockBehaviour$BlockStateBase$getSoundType(blockState); + Object soundEvent = FastNMS.INSTANCE.field$SoundType$fallSound(soundType); + Object soundId = FastNMS.INSTANCE.field$SoundEvent$location(soundEvent); + if (this.manager.isStepSoundMissing(soundId)) { + player.playSound(player.getLocation(), soundId.toString(), SoundCategory.BLOCKS, 0.15f, 1f); + } + } + } + @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) public void onBlockPhysics(BlockPhysicsEvent event) { // for vanilla blocks diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/util/EntityUtils.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/util/EntityUtils.java index f9cc52975..81396c16e 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/util/EntityUtils.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/util/EntityUtils.java @@ -26,13 +26,9 @@ public final class EntityUtils { } public static BlockPos getOnPos(Player player) { - try { - Object serverPlayer = FastNMS.INSTANCE.method$CraftPlayer$getHandle(player); - Object blockPos = CoreReflections.method$Entity$getOnPos.invoke(serverPlayer, 1.0E-5F); - return LocationUtils.fromBlockPos(blockPos); - } catch (ReflectiveOperationException e) { - throw new RuntimeException(e); - } + Object serverPlayer = FastNMS.INSTANCE.method$CraftPlayer$getHandle(player); + Object blockPos = FastNMS.INSTANCE.method$Entity$getOnPos(serverPlayer); + return LocationUtils.fromBlockPos(blockPos); } public static Entity spawnEntity(World world, Location loc, EntityType type, Consumer function) { diff --git a/core/src/main/java/net/momirealms/craftengine/core/plugin/context/event/EventTrigger.java b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/event/EventTrigger.java index 2a29e7fd9..0faee9842 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/plugin/context/event/EventTrigger.java +++ b/core/src/main/java/net/momirealms/craftengine/core/plugin/context/event/EventTrigger.java @@ -11,7 +11,8 @@ public enum EventTrigger { BREAK("break", "dig"), PLACE("place", "build"), PICK_UP("pick_up", "pick"), - STEP("step"),; + STEP("step"), + FALL("fall"),; public static final Map BY_NAME = new HashMap<>(); private final String[] names; diff --git a/gradle.properties b/gradle.properties index c1b0ab52a..5e2c657b8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -48,7 +48,7 @@ byte_buddy_version=1.18.1 ahocorasick_version=0.6.3 snake_yaml_version=2.5 anti_grief_version=1.0.5 -nms_helper_version=1.0.140 +nms_helper_version=1.0.141 evalex_version=3.5.0 reactive_streams_version=1.0.4 amazon_awssdk_version=2.38.7