From 237729989f35ee400dc582204878e37fa78b82bf Mon Sep 17 00:00:00 2001 From: Xzavier0722 Date: Thu, 18 Jul 2024 13:45:13 +0800 Subject: [PATCH 1/9] fix(profile): request player name --- .../slimefun4/storage/controller/ProfileDataController.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/xzavier0722/mc/plugin/slimefun4/storage/controller/ProfileDataController.java b/src/main/java/com/xzavier0722/mc/plugin/slimefun4/storage/controller/ProfileDataController.java index ac37273a8a..c57294ecd1 100644 --- a/src/main/java/com/xzavier0722/mc/plugin/slimefun4/storage/controller/ProfileDataController.java +++ b/src/main/java/com/xzavier0722/mc/plugin/slimefun4/storage/controller/ProfileDataController.java @@ -46,6 +46,7 @@ public class ProfileDataController extends ADataController { var key = new RecordKey(DataScope.PLAYER_PROFILE); key.addField(FieldKey.PLAYER_BACKPACK_NUM); + key.addField(FieldKey.PLAYER_NAME); key.addCondition(FieldKey.PLAYER_UUID, uuid); var result = getData(key); From e0b036a3329c61d35479c1518fc1ae9755be6cd6 Mon Sep 17 00:00:00 2001 From: StarWishsama Date: Fri, 19 Jul 2024 21:58:36 +0800 Subject: [PATCH 2/9] chore: use github pkg for dough --- .github/workflows/build-ci.yml | 4 ++-- .github/workflows/dev-ci.yml | 4 ++-- .github/workflows/pr-checker.yml | 7 ++----- .gitignore | 1 + .mvn/settings.xml | 12 +++++++++++ pom.xml | 14 +++++++++++-- .../general/Inventory/ChestMenu.java | 20 +++++++++---------- 7 files changed, 41 insertions(+), 21 deletions(-) create mode 100644 .mvn/settings.xml diff --git a/.github/workflows/build-ci.yml b/.github/workflows/build-ci.yml index 4b2c0fabfb..e4e90802f3 100644 --- a/.github/workflows/build-ci.yml +++ b/.github/workflows/build-ci.yml @@ -28,9 +28,9 @@ jobs: architecture: x64 cache: maven - name: Codestyle Check - run: mvn -B spotless:check --errors + run: mvn -s .mvn/settings.xml -B spotless:check --errors - name: Build Slimefun - run: mvn -B package --errors + run: mvn -s .mvn/settings.xml -B package --errors - uses: actions/upload-artifact@v2 name: Upload Beta artifact with: diff --git a/.github/workflows/dev-ci.yml b/.github/workflows/dev-ci.yml index 054556c0c7..bfcc9baa88 100644 --- a/.github/workflows/dev-ci.yml +++ b/.github/workflows/dev-ci.yml @@ -25,9 +25,9 @@ jobs: architecture: x64 cache: maven - name: Codestyle check - run: mvn -B spotless:check --errors + run: mvn -s .mvn/settings.xml -B spotless:check --errors - name: Build Slimefun - run: mvn -B package --errors + run: mvn -s .mvn/settings.xml -B package --errors - name: Mask Output run: | echo "::add-mask::$CF_API_TOKEN" diff --git a/.github/workflows/pr-checker.yml b/.github/workflows/pr-checker.yml index 9b09d247d7..0a91e9c360 100644 --- a/.github/workflows/pr-checker.yml +++ b/.github/workflows/pr-checker.yml @@ -40,10 +40,10 @@ jobs: restore-keys: ${{ runner.os }}-m2 - name: Codestyle Check - run: mvn -B spotless:check compile --errors + run: mvn -s .mvn/settings.xml -B spotless:check compile --errors - name: Build with Maven - run: mvn package + run: mvn -s .mvn/settings.xml package --errors # Setup for the preview build - name: Environment Setup @@ -56,9 +56,6 @@ jobs: echo "JAR_VERSION=$JAR_VERSION" >> "$GITHUB_ENV" sed -i "s/5.0-SNAPSHOT<\/version>/$JAR_VERSION<\/version>/g" pom.xml - - name: Build with Maven - run: mvn clean package - - name: Upload the artifact uses: actions/upload-artifact@v3 with: diff --git a/.gitignore b/.gitignore index 66b05d87e2..5185500aca 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ /.vscode/ /data-storage/ /javadocs/ +/local-deps/ .classpath .factorypath diff --git a/.mvn/settings.xml b/.mvn/settings.xml new file mode 100644 index 0000000000..8679032c89 --- /dev/null +++ b/.mvn/settings.xml @@ -0,0 +1,12 @@ + + + + dough-downstream + StarWishsama + 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 + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 178fc9f707..be19ab4f24 100644 --- a/pom.xml +++ b/pom.xml @@ -25,6 +25,8 @@ 17 17 + ${project.basedir}/.mvn/settings.xml + 1.20.6 https://hub.spigotmc.org/javadocs/spigot/ @@ -48,6 +50,14 @@ + + + dough-downstream + https://maven.pkg.github.com/StarWishsama/dough + + true + + spigot-repo @@ -275,9 +285,9 @@ - com.github.starwishsama.dough + io.github.baked-libs dough-api - d783252831 + 1.3.1-SNAPSHOT compile diff --git a/src/main/java/me/mrCookieSlime/CSCoreLibPlugin/general/Inventory/ChestMenu.java b/src/main/java/me/mrCookieSlime/CSCoreLibPlugin/general/Inventory/ChestMenu.java index c58a643b42..1bb2b07f7b 100644 --- a/src/main/java/me/mrCookieSlime/CSCoreLibPlugin/general/Inventory/ChestMenu.java +++ b/src/main/java/me/mrCookieSlime/CSCoreLibPlugin/general/Inventory/ChestMenu.java @@ -127,17 +127,17 @@ public ChestMenu addPlayerInventoryClickHandler(MenuClickHandler handler) { * @return The ChestMenu Instance */ public ChestMenu addItem(int slot, ItemStack item) { - // do shallow copy due to Paper ItemStack system change - // See also: https://github.com/PaperMC/Paper/pull/10852 - ItemStack clone = item == null ? null : new ItemStack(item.getType(), item.getAmount()); - - if (clone != null && item.hasItemMeta()) { - clone.setItemMeta(item.getItemMeta()); - } - + /** + * // do shallow copy due to Paper ItemStack system change + * // See also: https://github.com/PaperMC/Paper/pull/10852 + * ItemStack clone = item == null ? null : new ItemStack(item.getType(), item.getAmount()); + * + * if (clone != null && item.hasItemMeta()) { + * clone.setItemMeta(item.getItemMeta()); + * }*/ setSize((int) (Math.max(getSize(), Math.ceil((slot + 1) / 9d) * 9))); - this.items.set(slot, clone); - this.inventory.setItem(slot, clone); + this.items.set(slot, item); + this.inventory.setItem(slot, item); return this; } From 2eb1c472bdeed89c53a59f473562bed279f8b6d5 Mon Sep 17 00:00:00 2001 From: StarWishsama Date: Fri, 19 Jul 2024 22:07:58 +0800 Subject: [PATCH 3/9] =?UTF-8?q?chore(doc):=20=E7=BC=96=E8=AF=91=E7=AE=80?= =?UTF-8?q?=E5=8D=95=E6=8C=87=E5=8D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 5e93ede002..d536670ee2 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,12 @@ Slimefun 4 可以在[鬼斩构建站](https://builds.guizhanss.com)页面中** **! 建议你使用最新的测试版,可以获得最新的内容更新和 Bug 修复!** +## :computer: 如何编译 +要编译 Slimefun4,你必须先安装 [Git](https://git-scm.com/) +然后 `git clone https://github.com/SlimefunGuguProject/Slimefun4.git` +最后如果你是 Windows 系统: `.\mvnw.cmd -s .mvn/settings.xml package` +如果你是类 Unix 系统: `.\mvnw -s .mvn/settings.xml package` + ## :framed_picture: 截图 那么,Slimefun 看起来是怎样的呢?
From 28f46d12353e0c7ca474c446b69d8a4694431231 Mon Sep 17 00:00:00 2001 From: StarWishsama Date: Fri, 19 Jul 2024 22:13:20 +0800 Subject: [PATCH 4/9] chore: fix jitpack deploy --- jitpack.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/jitpack.yml b/jitpack.yml index 7af01741c0..c7a5d7f460 100644 --- a/jitpack.yml +++ b/jitpack.yml @@ -1,3 +1,6 @@ before_install: - sdk install java 17.0.5-zulu - sdk use java 17.0.5-zulu + +install: + - ./mvnw -s .mvn/settings.xml install -DskipTests \ No newline at end of file From 73f1dae78304b0861830e459e553b3ca51df5754 Mon Sep 17 00:00:00 2001 From: mcchampions <1309635304@qq.com> Date: Sun, 21 Jul 2024 15:03:42 +0800 Subject: [PATCH 5/9] chore: fix jitpack deploy --- jitpack.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/jitpack.yml b/jitpack.yml index c7a5d7f460..c8ef8c2097 100644 --- a/jitpack.yml +++ b/jitpack.yml @@ -3,4 +3,5 @@ before_install: - sdk use java 17.0.5-zulu install: + - chmod 777 ./mvnw - ./mvnw -s .mvn/settings.xml install -DskipTests \ No newline at end of file From cb6bb12471a13d229c829aae6924aa1198a321ae Mon Sep 17 00:00:00 2001 From: StarWishsama Date: Thu, 1 Aug 2024 07:53:06 +0800 Subject: [PATCH 6/9] fix: add `VersionedEvent` (fix #927) --- pom.xml | 2 +- .../norain/slimefun4/SlimefunExtended.java | 5 ++- .../compatibillty/VersionedEvent.java | 39 +++++++++++++++++++ .../slimefun4/implementation/Slimefun.java | 7 ++-- .../items/tools/ExplosiveTool.java | 3 +- 5 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 src/main/java/city/norain/slimefun4/compatibillty/VersionedEvent.java diff --git a/pom.xml b/pom.xml index be19ab4f24..1aab774c6d 100644 --- a/pom.xml +++ b/pom.xml @@ -28,7 +28,7 @@ ${project.basedir}/.mvn/settings.xml - 1.20.6 + 1.21 https://hub.spigotmc.org/javadocs/spigot/ diff --git a/src/main/java/city/norain/slimefun4/SlimefunExtended.java b/src/main/java/city/norain/slimefun4/SlimefunExtended.java index adacde99bb..330d09fe83 100644 --- a/src/main/java/city/norain/slimefun4/SlimefunExtended.java +++ b/src/main/java/city/norain/slimefun4/SlimefunExtended.java @@ -1,5 +1,6 @@ package city.norain.slimefun4; +import city.norain.slimefun4.compatibillty.VersionedEvent; import city.norain.slimefun4.listener.SlimefunMigrateListener; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import java.util.logging.Level; @@ -47,7 +48,7 @@ public static boolean checkEnvironment(@Nonnull Slimefun sf) { } } - public static void register(@Nonnull Slimefun sf) { + public static void init(@Nonnull Slimefun sf) { EnvironmentChecker.scheduleSlimeGlueCheck(sf); checkDebug(); @@ -55,6 +56,8 @@ public static void register(@Nonnull Slimefun sf) { VaultIntegration.register(sf); migrateListener.register(sf); + + VersionedEvent.init(); } public static void shutdown() { diff --git a/src/main/java/city/norain/slimefun4/compatibillty/VersionedEvent.java b/src/main/java/city/norain/slimefun4/compatibillty/VersionedEvent.java new file mode 100644 index 0000000000..e4b3cf9f2e --- /dev/null +++ b/src/main/java/city/norain/slimefun4/compatibillty/VersionedEvent.java @@ -0,0 +1,39 @@ +package city.norain.slimefun4.compatibillty; + +import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion; +import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; +import java.lang.reflect.Constructor; +import java.util.List; +import java.util.logging.Level; +import lombok.SneakyThrows; +import lombok.experimental.UtilityClass; +import org.bukkit.ExplosionResult; +import org.bukkit.block.Block; +import org.bukkit.event.block.BlockExplodeEvent; + +@UtilityClass +public class VersionedEvent { + private Constructor blockExplodeConstructor; + + public void init() { + if (Slimefun.getMinecraftVersion().isBefore(MinecraftVersion.MINECRAFT_1_21)) { + try { + blockExplodeConstructor = BlockExplodeEvent.class.getConstructor(Block.class, List.class, float.class); + } catch (NoSuchMethodException e) { + Slimefun.logger().log(Level.WARNING, "无法初始化事件版本兼容模块, 部分功能可能无法正常使用", e); + } + } + } + + @SneakyThrows + public BlockExplodeEvent newBlockExplodeEvent(Block block, List affectedBlock, float yield) { + if (Slimefun.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_21)) { + return new BlockExplodeEvent(block, block.getState(), affectedBlock, yield, ExplosionResult.DESTROY); + } else { + if (blockExplodeConstructor == null) { + throw new IllegalStateException("Unable to create BlockExplodeEvent: missing constructor"); + } + return blockExplodeConstructor.newInstance(block, affectedBlock, yield); + } + } +} diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/Slimefun.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/Slimefun.java index 668b828c55..9ae25d5493 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/Slimefun.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/Slimefun.java @@ -372,6 +372,10 @@ private void onPluginStart() { // All Slimefun Listeners logger.log(Level.INFO, "正在注册监听器..."); + + // Inject downstream extra staff + SlimefunExtended.init(this); + registerListeners(); // Initiating various Stuff and all items with a slight delay (0ms after the Server finished @@ -706,9 +710,6 @@ private void registerListeners() { new SmithingTableListener(this); new JoinListener(this); - // Inject downstream extra staff - SlimefunExtended.register(this); - // Item-specific Listeners new CoolerListener(this, (Cooler) SlimefunItems.COOLER.getItem()); new SeismicAxeListener(this, (SeismicAxe) SlimefunItems.SEISMIC_AXE.getItem()); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ExplosiveTool.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ExplosiveTool.java index 05a459a23b..736c041709 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ExplosiveTool.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ExplosiveTool.java @@ -1,5 +1,6 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.tools; +import city.norain.slimefun4.compatibillty.VersionedEvent; import com.xzavier0722.mc.plugin.slimefun4.storage.util.StorageCacheUtils; import dev.lone.itemsadder.api.CustomBlock; import io.github.bakedlibs.dough.protection.Interaction; @@ -79,7 +80,7 @@ private void breakBlocks( List blocksToDestroy = new ArrayList<>(); if (callExplosionEvent.getValue()) { - BlockExplodeEvent blockExplodeEvent = new BlockExplodeEvent(b, blocks, 0); + BlockExplodeEvent blockExplodeEvent = VersionedEvent.newBlockExplodeEvent(b, blocks, 0); Bukkit.getServer().getPluginManager().callEvent(blockExplodeEvent); if (!blockExplodeEvent.isCancelled()) { From f51bf7e58ecc80c9123b47be2c019fbe9e9154c5 Mon Sep 17 00:00:00 2001 From: StarWishsama Date: Thu, 1 Aug 2024 09:06:53 +0800 Subject: [PATCH 7/9] fix: `InventoryView` exception & closes #928 --- .../compatibillty/VersionedEvent.java | 36 ++++- .../items/tools/ExplosiveTool.java | 141 +++++++++--------- .../crafting/BrewingStandListener.java | 3 +- 3 files changed, 107 insertions(+), 73 deletions(-) diff --git a/src/main/java/city/norain/slimefun4/compatibillty/VersionedEvent.java b/src/main/java/city/norain/slimefun4/compatibillty/VersionedEvent.java index e4b3cf9f2e..2344887486 100644 --- a/src/main/java/city/norain/slimefun4/compatibillty/VersionedEvent.java +++ b/src/main/java/city/norain/slimefun4/compatibillty/VersionedEvent.java @@ -3,6 +3,7 @@ import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import java.lang.reflect.Constructor; +import java.lang.reflect.Method; import java.util.List; import java.util.logging.Level; import lombok.SneakyThrows; @@ -10,16 +11,25 @@ import org.bukkit.ExplosionResult; import org.bukkit.block.Block; import org.bukkit.event.block.BlockExplodeEvent; +import org.bukkit.event.inventory.InventoryEvent; +import org.bukkit.inventory.Inventory; @UtilityClass public class VersionedEvent { - private Constructor blockExplodeConstructor; + private Constructor BLOCK_EXPLODE_EVENT_CONSTRUCTOR; + + private Method GET_TOP_INVENTORY; public void init() { if (Slimefun.getMinecraftVersion().isBefore(MinecraftVersion.MINECRAFT_1_21)) { try { - blockExplodeConstructor = BlockExplodeEvent.class.getConstructor(Block.class, List.class, float.class); - } catch (NoSuchMethodException e) { + BLOCK_EXPLODE_EVENT_CONSTRUCTOR = + BlockExplodeEvent.class.getConstructor(Block.class, List.class, float.class); + + GET_TOP_INVENTORY = + Class.forName("org.bukkit.inventory.InventoryView").getMethod("getTopInventory"); + GET_TOP_INVENTORY.setAccessible(true); + } catch (NoSuchMethodException | ClassNotFoundException e) { Slimefun.logger().log(Level.WARNING, "无法初始化事件版本兼容模块, 部分功能可能无法正常使用", e); } } @@ -30,10 +40,26 @@ public BlockExplodeEvent newBlockExplodeEvent(Block block, List affectedB if (Slimefun.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_21)) { return new BlockExplodeEvent(block, block.getState(), affectedBlock, yield, ExplosionResult.DESTROY); } else { - if (blockExplodeConstructor == null) { + if (BLOCK_EXPLODE_EVENT_CONSTRUCTOR == null) { throw new IllegalStateException("Unable to create BlockExplodeEvent: missing constructor"); } - return blockExplodeConstructor.newInstance(block, affectedBlock, yield); + return BLOCK_EXPLODE_EVENT_CONSTRUCTOR.newInstance(block, affectedBlock, yield); + } + } + + /** + * See https://www.spigotmc.org/threads/inventoryview-changed-to-interface-backwards-compatibility.651754/ + */ + @SneakyThrows + public Inventory getTopInventory(InventoryEvent event) { + if (Slimefun.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_21)) { + return event.getView().getTopInventory(); + } else { + if (GET_TOP_INVENTORY == null) { + throw new IllegalStateException("Unable to get top inventory: missing method"); + } + + return (Inventory) GET_TOP_INVENTORY.invoke(event.getView()); } } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ExplosiveTool.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ExplosiveTool.java index 736c041709..e77a0872fc 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ExplosiveTool.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ExplosiveTool.java @@ -69,6 +69,11 @@ public ToolUseHandler getItemHandler() { SoundEffect.EXPLOSIVE_TOOL_EXPLODE_SOUND.playAt(b); List blocks = findBlocks(b); + + if (!StorageCacheUtils.hasBlock(b.getLocation())) { + blocks.add(b); + } + breakBlocks(e, p, tool, b, blocks, drops); } }; @@ -172,79 +177,81 @@ private void breakBlock(BlockBreakEvent event, Player player, ItemStack item, Bl block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, material); Location blockLocation = block.getLocation(); - Optional optionalBlockSfItem = Optional.ofNullable(StorageCacheUtils.getSfItem(blockLocation)); + Optional blockItem = Optional.ofNullable(StorageCacheUtils.getSfItem(blockLocation)); - /* - * 修复: https://github.com/SlimefunGuguProject/Slimefun4/issues/853 - * - * 该问题源于 ExoticGarden MagicalEssence/ExoticGardenFruit useVanillaBlockBreaking 为 true, - * 将调用 breakNaturally 方法而非将其作为 SlimefunItem 进行处理。 - * - * 此前将 blocks 进行排序,以确保头颅为最先处理的对象,检查头颅的 Y - 1 方块是否为叶子, - * 若为叶子则尝试获取该处的 SlimefunItem,若能获取得到则此处应为异域花园植物,将叶子处直接设置为 AIR 并移除该处 Slimefun 方块数据。 - */ AtomicBoolean isUseVanillaBlockBreaking = new AtomicBoolean(true); - if (Bukkit.getPluginManager().isPluginEnabled("ExoticGarden") - && block.getType().equals(Material.PLAYER_HEAD)) { - Location leavesLocation = blockLocation.clone(); - leavesLocation.setY(leavesLocation.getY() - 1); - - Block leaveBlock = leavesLocation.getBlock(); - Material leaveBlockType = leaveBlock.getType(); - - if (Tag.LEAVES.isTagged(leaveBlockType)) { - Optional optionalLeavesBlockSfItem = - Optional.ofNullable(StorageCacheUtils.getSfItem(leavesLocation)); - - optionalBlockSfItem.ifPresent(blockSfItem -> optionalLeavesBlockSfItem.ifPresent(leavesSfItem -> { - Collection sfItemDrops = blockSfItem.getDrops(); - Collection leavesSfItemDrops = leavesSfItem.getDrops(); - - if (Arrays.equals(sfItemDrops.toArray(), leavesSfItemDrops.toArray())) { - leaveBlock.setType(Material.AIR); - Slimefun.getDatabaseManager().getBlockDataController().removeBlock(leavesLocation); - - isUseVanillaBlockBreaking.set(false); + blockItem.ifPresentOrElse( + sfItem -> { + /* + * 修复: https://github.com/SlimefunGuguProject/Slimefun4/issues/853 + * + * 该问题源于 ExoticGarden MagicalEssence/ExoticGardenFruit useVanillaBlockBreaking 为 true, + * 将调用 breakNaturally 方法而非将其作为 SlimefunItem 进行处理。 + * + * 此前将 blocks 进行排序,以确保头颅为最先处理的对象,检查头颅的 Y - 1 方块是否为叶子, + * 若为叶子则尝试获取该处的 SlimefunItem,若能获取得到则此处应为异域花园植物,将叶子处直接设置为 AIR 并移除该处 Slimefun 方块数据。 + */ + if (Bukkit.getPluginManager().isPluginEnabled("ExoticGarden") + && block.getType().equals(Material.PLAYER_HEAD)) { + Location leavesLocation = blockLocation.clone(); + leavesLocation.setY(leavesLocation.getY() - 1); + + Block leaveBlock = leavesLocation.getBlock(); + Material leaveBlockType = leaveBlock.getType(); + + if (Tag.LEAVES.isTagged(leaveBlockType)) { + Optional optionalLeavesBlockSfItem = + Optional.ofNullable(StorageCacheUtils.getSfItem(leavesLocation)); + + optionalLeavesBlockSfItem.ifPresent(leavesSfItem -> { + Collection sfItemDrops = sfItem.getDrops(); + Collection leavesSfItemDrops = leavesSfItem.getDrops(); + + if (Arrays.equals(sfItemDrops.toArray(), leavesSfItemDrops.toArray())) { + leaveBlock.setType(Material.AIR); + Slimefun.getDatabaseManager() + .getBlockDataController() + .removeBlock(leavesLocation); + + isUseVanillaBlockBreaking.set(false); + } + }); + } } - })); - } - } - - optionalBlockSfItem.ifPresent(sfItem -> { - if (isUseVanillaBlockBreaking.get()) { - isUseVanillaBlockBreaking.set(sfItem.useVanillaBlockBreaking()); - } - if (isUseVanillaBlockBreaking.get()) { - block.breakNaturally(item); - } else { - /* - * Fixes #2989 - * We create a dummy here to pass onto the BlockBreakHandler. - * This will set the correct block context. - */ - BlockBreakEvent dummyEvent = new BlockBreakEvent(block, event.getPlayer()); - - /* - * Fixes #3036 and handling in general. - * Call the BlockBreakHandler if the block has one to allow for proper handling. - */ - sfItem.callItemHandler( - BlockBreakHandler.class, handler -> handler.onPlayerBreak(dummyEvent, item, drops)); - - // Make sure the event wasn't cancelled by the BlockBreakHandler. - if (!dummyEvent.isCancelled()) { - drops.addAll(sfItem.getDrops(player)); - block.setType(Material.AIR); - Slimefun.getDatabaseManager().getBlockDataController().removeBlock(blockLocation); - } - } - }); + if (isUseVanillaBlockBreaking.get()) { + isUseVanillaBlockBreaking.set(sfItem.useVanillaBlockBreaking()); + } - if (optionalBlockSfItem.isEmpty()) { - block.breakNaturally(item); - } + if (isUseVanillaBlockBreaking.get()) { + block.breakNaturally(item); + } else { + /* + * Fixes #2989 + * We create a dummy here to pass onto the BlockBreakHandler. + * This will set the correct block context. + */ + BlockBreakEvent dummyEvent = new BlockBreakEvent(block, event.getPlayer()); + + /* + * Fixes #3036 and handling in general. + * Call the BlockBreakHandler if the block has one to allow for proper handling. + */ + sfItem.callItemHandler( + BlockBreakHandler.class, handler -> handler.onPlayerBreak(dummyEvent, item, drops)); + + // Make sure the event wasn't cancelled by the BlockBreakHandler. + if (!dummyEvent.isCancelled()) { + drops.addAll(sfItem.getDrops(player)); + block.setType(Material.AIR); + Slimefun.getDatabaseManager() + .getBlockDataController() + .removeBlock(blockLocation); + } + } + }, + () -> block.breakNaturally(item)); damageItem(player, item); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/crafting/BrewingStandListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/crafting/BrewingStandListener.java index b697bd5764..f0b3dce0e8 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/crafting/BrewingStandListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/crafting/BrewingStandListener.java @@ -1,5 +1,6 @@ package io.github.thebusybiscuit.slimefun4.implementation.listeners.crafting; +import city.norain.slimefun4.compatibillty.VersionedEvent; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import javax.annotation.Nonnull; @@ -32,7 +33,7 @@ public BrewingStandListener(@Nonnull Slimefun plugin) { @EventHandler(ignoreCancelled = true) public void onPreBrew(InventoryClickEvent e) { Inventory clickedInventory = e.getClickedInventory(); - Inventory topInventory = e.getView().getTopInventory(); + Inventory topInventory = VersionedEvent.getTopInventory(e); if (clickedInventory != null && topInventory.getType() == InventoryType.BREWING From cf476adf62ee8c7eb99716c05a52af92e7574d7c Mon Sep 17 00:00:00 2001 From: StarWishsama Date: Thu, 1 Aug 2024 09:13:55 +0800 Subject: [PATCH 8/9] fix: `InventoryView` exception --- .../implementation/listeners/VillagerTradingListener.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/VillagerTradingListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/VillagerTradingListener.java index 7c5d52edc7..70304f309d 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/VillagerTradingListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/VillagerTradingListener.java @@ -1,5 +1,6 @@ package io.github.thebusybiscuit.slimefun4.implementation.listeners; +import city.norain.slimefun4.compatibillty.VersionedEvent; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import io.github.thebusybiscuit.slimefun4.implementation.items.VanillaItem; @@ -31,7 +32,7 @@ public VillagerTradingListener(@Nonnull Slimefun plugin) { @EventHandler(ignoreCancelled = true) public void onPreTrade(InventoryClickEvent e) { Inventory clickedInventory = e.getClickedInventory(); - Inventory topInventory = e.getView().getTopInventory(); + Inventory topInventory = VersionedEvent.getTopInventory(e); if (clickedInventory != null && topInventory.getType() == InventoryType.MERCHANT) { if (e.getAction() == InventoryAction.HOTBAR_SWAP) { From a19da27beeee8cea7bc75c38e180925f8ac17853 Mon Sep 17 00:00:00 2001 From: StarWishsama Date: Thu, 1 Aug 2024 22:59:22 +0800 Subject: [PATCH 9/9] fix(): `InventoryView` ex and revert part of f51bf7e5 --- .../compatibillty/VersionedEvent.java | 20 +++++++++++++++++++ .../items/tools/ExplosiveTool.java | 4 ---- .../listeners/BlockListener.java | 2 +- .../listeners/VillagerTradingListener.java | 2 +- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/main/java/city/norain/slimefun4/compatibillty/VersionedEvent.java b/src/main/java/city/norain/slimefun4/compatibillty/VersionedEvent.java index 2344887486..3e5657129e 100644 --- a/src/main/java/city/norain/slimefun4/compatibillty/VersionedEvent.java +++ b/src/main/java/city/norain/slimefun4/compatibillty/VersionedEvent.java @@ -11,6 +11,7 @@ import org.bukkit.ExplosionResult; import org.bukkit.block.Block; import org.bukkit.event.block.BlockExplodeEvent; +import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryEvent; import org.bukkit.inventory.Inventory; @@ -19,6 +20,7 @@ public class VersionedEvent { private Constructor BLOCK_EXPLODE_EVENT_CONSTRUCTOR; private Method GET_TOP_INVENTORY; + private Method GET_CLICKED_INVENTORY; public void init() { if (Slimefun.getMinecraftVersion().isBefore(MinecraftVersion.MINECRAFT_1_21)) { @@ -29,6 +31,11 @@ public void init() { GET_TOP_INVENTORY = Class.forName("org.bukkit.inventory.InventoryView").getMethod("getTopInventory"); GET_TOP_INVENTORY.setAccessible(true); + + GET_CLICKED_INVENTORY = Class.forName("org.bukkit.event.inventory.InventoryClickEvent") + .getMethod("getClickedInventory"); + GET_CLICKED_INVENTORY.setAccessible(true); + } catch (NoSuchMethodException | ClassNotFoundException e) { Slimefun.logger().log(Level.WARNING, "无法初始化事件版本兼容模块, 部分功能可能无法正常使用", e); } @@ -62,4 +69,17 @@ public Inventory getTopInventory(InventoryEvent event) { return (Inventory) GET_TOP_INVENTORY.invoke(event.getView()); } } + + @SneakyThrows + public Inventory getClickedInventory(InventoryClickEvent event) { + if (Slimefun.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_21)) { + return event.getClickedInventory(); + } else { + if (GET_CLICKED_INVENTORY == null) { + throw new IllegalStateException("Unable to get clicked inventory: missing method"); + } + + return (Inventory) GET_CLICKED_INVENTORY.invoke(event); + } + } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ExplosiveTool.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ExplosiveTool.java index e77a0872fc..e5c2bb5e3b 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ExplosiveTool.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/tools/ExplosiveTool.java @@ -70,10 +70,6 @@ public ToolUseHandler getItemHandler() { List blocks = findBlocks(b); - if (!StorageCacheUtils.hasBlock(b.getLocation())) { - blocks.add(b); - } - breakBlocks(e, p, tool, b, blocks, drops); } }; diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BlockListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BlockListener.java index 1be8b78169..6a2efb809a 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BlockListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BlockListener.java @@ -236,7 +236,7 @@ public void onBlockBreak(BlockBreakEvent e) { dropItems(e, drops); // Checks for vanilla sensitive blocks everywhere - checkForSensitiveBlocks(e.getBlock(), 0, e.isDropItems()); + // checkForSensitiveBlocks(e.getBlock(), 0, e.isDropItems()); } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/VillagerTradingListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/VillagerTradingListener.java index 70304f309d..730790bb8f 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/VillagerTradingListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/VillagerTradingListener.java @@ -31,7 +31,7 @@ public VillagerTradingListener(@Nonnull Slimefun plugin) { @EventHandler(ignoreCancelled = true) public void onPreTrade(InventoryClickEvent e) { - Inventory clickedInventory = e.getClickedInventory(); + Inventory clickedInventory = VersionedEvent.getClickedInventory(e); Inventory topInventory = VersionedEvent.getTopInventory(e); if (clickedInventory != null && topInventory.getType() == InventoryType.MERCHANT) {