mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2026-01-04 15:41:38 +00:00
改善低版本兼容性
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package net.momirealms.craftengine.bukkit.util;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryAction;
|
||||
import org.bukkit.event.inventory.InventoryEvent;
|
||||
import org.bukkit.event.inventory.PrepareAnvilEvent;
|
||||
import org.bukkit.inventory.AnvilInventory;
|
||||
@@ -70,4 +71,8 @@ public class LegacyInventoryUtils {
|
||||
public static Player getPlayerFromInventoryEvent(InventoryEvent event) {
|
||||
return (Player) event.getView().getPlayer();
|
||||
}
|
||||
|
||||
public static boolean isHotBarSwapAndReadd(InventoryAction action) {
|
||||
return action == InventoryAction.HOTBAR_MOVE_AND_READD;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import net.momirealms.craftengine.core.item.ItemBuildContext;
|
||||
import net.momirealms.craftengine.core.item.ItemManager;
|
||||
import net.momirealms.craftengine.core.item.recipe.CustomCraftingTableRecipe;
|
||||
import net.momirealms.craftengine.core.item.recipe.Recipe;
|
||||
import net.momirealms.craftengine.core.plugin.context.ContextHolder;
|
||||
import net.momirealms.craftengine.core.plugin.context.PlayerOptionalContext;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
||||
@@ -11,6 +11,7 @@ import net.momirealms.craftengine.bukkit.plugin.reflection.bukkit.CraftBukkitRef
|
||||
import net.momirealms.craftengine.bukkit.plugin.reflection.minecraft.CoreReflections;
|
||||
import net.momirealms.craftengine.bukkit.plugin.user.BukkitServerPlayer;
|
||||
import net.momirealms.craftengine.bukkit.util.*;
|
||||
import net.momirealms.craftengine.core.entity.player.InteractionHand;
|
||||
import net.momirealms.craftengine.core.item.*;
|
||||
import net.momirealms.craftengine.core.item.equipment.TrimBasedEquipment;
|
||||
import net.momirealms.craftengine.core.item.recipe.*;
|
||||
@@ -647,12 +648,30 @@ public class RecipeEventListener implements Listener {
|
||||
if (!ceRecipe.hasVisualResult() && !ceRecipe.hasFunctions()) {
|
||||
return;
|
||||
}
|
||||
InventoryAction action = event.getAction();
|
||||
// 无事发生,不要更新
|
||||
if (event.getAction() == InventoryAction.NOTHING) {
|
||||
if (action == InventoryAction.NOTHING) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = InventoryUtils.getPlayerFromInventoryEvent(event);
|
||||
BukkitServerPlayer serverPlayer = BukkitAdaptors.adapt(player);
|
||||
|
||||
// 对低版本nothing不全的兼容
|
||||
if (!VersionHelper.isOrAbove1_20_5() && LegacyInventoryUtils.isHotBarSwapAndReadd(action)) {
|
||||
int slot = event.getHotbarButton();
|
||||
if (slot == -1) {
|
||||
if (!serverPlayer.getItemInHand(InteractionHand.OFF_HAND).isEmpty()) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
ItemStack item = player.getInventory().getItem(slot);
|
||||
if (!ItemStackUtils.isEmpty(item)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 多次合成
|
||||
if (event.isShiftClick()) {
|
||||
// 由插件自己处理多次合成
|
||||
|
||||
@@ -2,13 +2,10 @@ package net.momirealms.craftengine.core.plugin.context.condition;
|
||||
|
||||
import net.momirealms.craftengine.core.plugin.context.Condition;
|
||||
import net.momirealms.craftengine.core.plugin.context.Context;
|
||||
import net.momirealms.craftengine.core.plugin.context.ContextKey;
|
||||
import net.momirealms.craftengine.core.plugin.context.PlayerOptionalContext;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
import net.momirealms.craftengine.core.util.ResourceConfigUtils;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class HasPlayerCondition<CTX extends Context> implements Condition<CTX> {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user