9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-30 20:39:10 +00:00

skript兼容

This commit is contained in:
XiaoMoMi
2025-04-27 02:49:30 +08:00
parent a18ab82753
commit b0514d475f
21 changed files with 671 additions and 54 deletions

View File

@@ -10,6 +10,8 @@ import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -24,6 +26,7 @@ public class CustomBlockInteractEvent extends PlayerEvent implements Cancellable
private final InteractionHand hand;
private final Action action;
private final BlockFace clickedFace;
private final ItemStack item;
public CustomBlockInteractEvent(@NotNull Player player,
@NotNull Location location,
@@ -32,7 +35,8 @@ public class CustomBlockInteractEvent extends PlayerEvent implements Cancellable
@NotNull Block bukkitBlock,
@NotNull BlockFace clickedFace,
@NotNull InteractionHand hand,
@NotNull Action action) {
@NotNull Action action,
@Nullable ItemStack item) {
super(player);
this.customBlock = state.owner().value();
this.bukkitBlock = bukkitBlock;
@@ -42,6 +46,7 @@ public class CustomBlockInteractEvent extends PlayerEvent implements Cancellable
this.hand = hand;
this.action = action;
this.clickedFace = clickedFace;
this.item = item;
}
@NotNull
@@ -89,6 +94,12 @@ public class CustomBlockInteractEvent extends PlayerEvent implements Cancellable
return this.state;
}
@ApiStatus.Experimental
@NotNull
public ItemStack item() {
return this.item;
}
@NotNull
public static HandlerList getHandlerList() {
return HANDLER_LIST;

View File

@@ -70,7 +70,8 @@ public class ItemEventListener implements Listener {
block,
event.getBlockFace(),
event.getHand() == EquipmentSlot.HAND ? InteractionHand.MAIN_HAND : InteractionHand.OFF_HAND,
action.isRightClick() ? CustomBlockInteractEvent.Action.RIGHT_CLICK : CustomBlockInteractEvent.Action.LEFT_CLICK
action.isRightClick() ? CustomBlockInteractEvent.Action.RIGHT_CLICK : CustomBlockInteractEvent.Action.LEFT_CLICK,
event.getItem()
);
if (EventUtils.fireAndCheckCancel(interactEvent)) {
event.setCancelled(true);

View File

@@ -368,11 +368,28 @@ public class BukkitInjector {
}
}
public synchronized static void injectLevelChunkSection(Object targetSection, CESection ceSection, CEWorld ceWorld, SectionPos pos) {
// public synchronized static void injectLevelChunkSection(Object targetSection, CESection ceSection, CEWorld ceWorld, SectionPos pos) {
// try {
// Object container = FastNMS.INSTANCE.field$LevelChunkSection$states(targetSection);
// if (!(container instanceof InjectedPalettedContainerHolder)) {
// InjectedPalettedContainerHolder injectedObject = FastNMS.INSTANCE.createInjectedPalettedContainerHolder(container);
// injectedObject.ceSection(ceSection);
// injectedObject.ceWorld(ceWorld);
// injectedObject.cePos(pos);
// Reflections.varHandle$PalettedContainer$data.setVolatile(injectedObject, Reflections.varHandle$PalettedContainer$data.get(container));
// Reflections.field$LevelChunkSection$states.set(targetSection, injectedObject);
// }
// } catch (Exception e) {
// CraftEngine.instance().logger().severe("Failed to inject chunk section", e);
// }
// }
public static void injectLevelChunkSection(Object targetSection, CESection ceSection, CEWorld ceWorld, SectionPos pos) {
try {
Object container = FastNMS.INSTANCE.field$LevelChunkSection$states(targetSection);
if (!(container instanceof InjectedPalettedContainerHolder)) {
InjectedPalettedContainerHolder injectedObject = FastNMS.INSTANCE.createInjectedPalettedContainerHolder(container);
if (!clazz$InjectedPalettedContainer.isInstance(container)) {
InjectedPalettedContainerHolder injectedObject = (InjectedPalettedContainerHolder) Reflections.UNSAFE.allocateInstance(clazz$InjectedPalettedContainer);
varHandle$InjectedPalettedContainer$target.set(injectedObject, container);
injectedObject.ceSection(ceSection);
injectedObject.ceWorld(ceWorld);
injectedObject.cePos(pos);