mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-30 04:19:27 +00:00
@@ -3,6 +3,7 @@ package net.momirealms.craftengine.bukkit.item.listener;
|
||||
import io.papermc.paper.event.block.CompostItemEvent;
|
||||
import net.momirealms.craftengine.bukkit.api.BukkitAdaptors;
|
||||
import net.momirealms.craftengine.bukkit.api.event.CustomBlockInteractEvent;
|
||||
import net.momirealms.craftengine.bukkit.entity.BukkitEntity;
|
||||
import net.momirealms.craftengine.bukkit.item.BukkitCustomItem;
|
||||
import net.momirealms.craftengine.bukkit.item.BukkitItemManager;
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
@@ -96,9 +97,10 @@ public class ItemEventListener implements Listener {
|
||||
Cancellable cancellable = Cancellable.of(event::isCancelled, event::setCancelled);
|
||||
PlayerOptionalContext context = PlayerOptionalContext.of(serverPlayer, ContextHolder.builder()
|
||||
.withOptionalParameter(DirectContextParameters.ITEM_IN_HAND, itemInHand)
|
||||
.withParameter(DirectContextParameters.EVENT, cancellable)
|
||||
.withParameter(DirectContextParameters.POSITION, LocationUtils.toWorldPosition(event.getRightClicked().getLocation()))
|
||||
.withParameter(DirectContextParameters.HAND, hand)
|
||||
.withParameter(DirectContextParameters.EVENT, cancellable)
|
||||
.withParameter(DirectContextParameters.ENTITY, new BukkitEntity(entity))
|
||||
.withParameter(DirectContextParameters.POSITION, LocationUtils.toWorldPosition(event.getRightClicked().getLocation()))
|
||||
);
|
||||
CustomItem<ItemStack> customItem = optionalCustomItem.get();
|
||||
customItem.execute(context, EventTrigger.RIGHT_CLICK);
|
||||
|
||||
@@ -40,6 +40,7 @@ import org.bukkit.*;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.attribute.AttributeInstance;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
@@ -177,6 +178,26 @@ public class BukkitServerPlayer extends Player {
|
||||
return platformPlayer().isSneaking();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSwimming() {
|
||||
return platformPlayer().isSwimming();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isClimbing() {
|
||||
return platformPlayer().isClimbing();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGliding() {
|
||||
return platformPlayer().isGliding();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFlying() {
|
||||
return platformPlayer().isFlying();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameMode gameMode() {
|
||||
return switch (platformPlayer().getGameMode()) {
|
||||
@@ -475,7 +496,7 @@ public class BukkitServerPlayer extends Player {
|
||||
ImmutableBlockState customState = optionalCustomState.get();
|
||||
Item<ItemStack> tool = getItemInHand(InteractionHand.MAIN_HAND);
|
||||
boolean isCorrectTool = FastNMS.INSTANCE.method$ItemStack$isCorrectToolForDrops(tool.getLiteralObject(), blockState);
|
||||
// 如果自定义方块在服务端侧未使用正确地工具,那么需要还原挖掘速度
|
||||
// 如果自定义方块在服务端侧未使用正确的工具,那么需要还原挖掘速度
|
||||
if (!isCorrectTool) {
|
||||
progress *= (10f / 3f);
|
||||
}
|
||||
@@ -939,6 +960,14 @@ public class BukkitServerPlayer extends Player {
|
||||
platformPlayer().performCommand(command);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public void performCommandAsEvent(String command) {
|
||||
String formattedCommand = command.startsWith("/") ? command : "/" + command;
|
||||
PlayerCommandPreprocessEvent event = new PlayerCommandPreprocessEvent(platformPlayer(), formattedCommand);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double luck() {
|
||||
if (VersionHelper.isOrAbove1_21_3()) {
|
||||
@@ -948,11 +977,6 @@ public class BukkitServerPlayer extends Player {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFlying() {
|
||||
return platformPlayer().isFlying();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int foodLevel() {
|
||||
return platformPlayer().getFoodLevel();
|
||||
|
||||
@@ -37,6 +37,7 @@ public final class SoundUtils {
|
||||
case HOSTILE -> SoundCategory.HOSTILE;
|
||||
case NEUTRAL -> SoundCategory.NEUTRAL;
|
||||
case WEATHER -> SoundCategory.WEATHER;
|
||||
case UI -> SoundCategory.UI;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,10 +6,12 @@ import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.CoreReflect
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.MBlocks;
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.MFluids;
|
||||
import net.momirealms.craftengine.bukkit.util.BlockStateUtils;
|
||||
import net.momirealms.craftengine.bukkit.util.KeyUtils;
|
||||
import net.momirealms.craftengine.bukkit.util.LocationUtils;
|
||||
import net.momirealms.craftengine.core.block.CustomBlock;
|
||||
import net.momirealms.craftengine.core.block.ImmutableBlockState;
|
||||
import net.momirealms.craftengine.core.item.context.BlockPlaceContext;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.world.BlockInWorld;
|
||||
import net.momirealms.craftengine.core.world.World;
|
||||
import org.bukkit.Location;
|
||||
@@ -59,6 +61,11 @@ public class BukkitBlockInWorld implements BlockInWorld {
|
||||
return this.block.getZ();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Key type() {
|
||||
return KeyUtils.namespacedKey2Key(this.block.getType().getKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public World world() {
|
||||
return new BukkitWorld(this.block.getWorld());
|
||||
|
||||
Reference in New Issue
Block a user