From 841fbfafe87f22cd5418ce5ba1759dc5dabc3317 Mon Sep 17 00:00:00 2001 From: Ddggdd135 <1306334428@qq.com> Date: Sat, 27 Apr 2024 07:17:36 +0800 Subject: [PATCH 01/14] fix #858 --- .../slimefun4/api/geo/ResourceManager.java | 22 +++++++++++-------- .../implementation/items/geo/GEOMiner.java | 13 +++++++---- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/geo/ResourceManager.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/geo/ResourceManager.java index 8d8701a429..57c2bd13d5 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/geo/ResourceManager.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/geo/ResourceManager.java @@ -13,11 +13,7 @@ import io.github.thebusybiscuit.slimefun4.utils.ChatUtils; import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils; import io.github.thebusybiscuit.slimefun4.utils.HeadTexture; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; -import java.util.Locale; -import java.util.OptionalInt; +import java.util.*; import java.util.concurrent.ThreadLocalRandom; import javax.annotation.Nonnull; import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu; @@ -246,7 +242,7 @@ private int generate(@Nonnull GEOResource resource, @Nonnull World world, int x, * @param block * The {@link Block} which the scan starts at * @param page - * The page to display + * The zero-based page to display */ public void scan(@Nonnull Player p, @Nonnull Block block, int page) { if (Slimefun.getGPSNetwork().getNetworkComplexity(p.getUniqueId()) < 600) { @@ -282,12 +278,20 @@ public void scan(@Nonnull Player p, @Nonnull Block block, int page) { resources.sort(Comparator.comparing(a -> a.getName(p).toLowerCase(Locale.ROOT))); int index = 10; - int pages = (resources.size() - 1) / 36 + 1; + int pages = (int) (Math.ceil((double) resources.size() / 36) + 1); - for (int i = page * 28; i < resources.size() && i < (page + 1) * 28; i++) { - GEOResource resource = resources.get(i); + Map suppliemap = new HashMap<>(); + + // if resource is not generated, generate the first + resources.forEach(resource -> { OptionalInt optional = getSupplies(resource, block.getWorld(), x, z); int supplies = optional.orElseGet(() -> generate(resource, block.getWorld(), x, block.getY(), z)); + suppliemap.put(resource, supplies); + }); + + for (int i = page * 28; i < resources.size() && i < (page + 1) * 28; i++) { + GEOResource resource = resources.get(i); + int supplies = suppliemap.get(resource); String suffix = Slimefun.getLocalization() .getResourceString(p, ChatUtils.checkPlurality("tooltips.unit", supplies)); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/geo/GEOMiner.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/geo/GEOMiner.java index c100c8aca7..8459799334 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/geo/GEOMiner.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/geo/GEOMiner.java @@ -343,16 +343,16 @@ public void onResult(SlimefunChunkData result) { } private void start(@Nonnull Block b, @Nonnull BlockMenu inv) { + boolean succeed = Slimefun.getRegistry().getGEOResources().values().isEmpty(); for (GEOResource resource : Slimefun.getRegistry().getGEOResources().values()) { if (resource.isObtainableFromGEOMiner()) { OptionalInt optional = Slimefun.getGPSNetwork() .getResourceManager() .getSupplies(resource, b.getWorld(), b.getX() >> 4, b.getZ() >> 4); - if (!optional.isPresent()) { - updateHologram(b, "&4需要先进行地形扫描!"); - return; - } + if (optional.isEmpty()) continue; + + succeed = true; int supplies = optional.getAsInt(); if (supplies > 0) { @@ -370,6 +370,11 @@ private void start(@Nonnull Block b, @Nonnull BlockMenu inv) { } } + if (!succeed) { + updateHologram(b, "&4需要先进行地形扫描!"); + return; + } + updateHologram(b, "&7开采完成"); } } From 79e4cc93b3822f29af7080e68f9dc0267b0acb82 Mon Sep 17 00:00:00 2001 From: Ddggdd135 <1306334428@qq.com> Date: Sat, 27 Apr 2024 07:23:40 +0800 Subject: [PATCH 02/14] =?UTF-8?q?=E9=9D=9E=E5=B8=B8=E5=9D=8Fidea=20?= =?UTF-8?q?=E4=BD=BF=E6=88=91=E4=BD=BF=E7=94=A8=E6=98=9F=E5=9E=8Bimport?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../thebusybiscuit/slimefun4/api/geo/ResourceManager.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/geo/ResourceManager.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/geo/ResourceManager.java index 57c2bd13d5..664cafe258 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/geo/ResourceManager.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/geo/ResourceManager.java @@ -13,7 +13,13 @@ import io.github.thebusybiscuit.slimefun4.utils.ChatUtils; import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils; import io.github.thebusybiscuit.slimefun4.utils.HeadTexture; -import java.util.*; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.OptionalInt; import java.util.concurrent.ThreadLocalRandom; import javax.annotation.Nonnull; import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu; From 31e66d23c0b964139fe06d12d628a58c22f0c227 Mon Sep 17 00:00:00 2001 From: Ddggdd135 <1306334428@qq.com> Date: Sat, 27 Apr 2024 12:01:31 +0800 Subject: [PATCH 03/14] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=8F=98=E9=87=8F?= =?UTF-8?q?=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../thebusybiscuit/slimefun4/api/geo/ResourceManager.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/geo/ResourceManager.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/geo/ResourceManager.java index 664cafe258..e4b9e25b12 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/geo/ResourceManager.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/geo/ResourceManager.java @@ -286,18 +286,18 @@ public void scan(@Nonnull Player p, @Nonnull Block block, int page) { int index = 10; int pages = (int) (Math.ceil((double) resources.size() / 36) + 1); - Map suppliemap = new HashMap<>(); + Map supplyMap = new HashMap<>(); // if resource is not generated, generate the first resources.forEach(resource -> { OptionalInt optional = getSupplies(resource, block.getWorld(), x, z); int supplies = optional.orElseGet(() -> generate(resource, block.getWorld(), x, block.getY(), z)); - suppliemap.put(resource, supplies); + supplyMap.put(resource, supplies); }); for (int i = page * 28; i < resources.size() && i < (page + 1) * 28; i++) { GEOResource resource = resources.get(i); - int supplies = suppliemap.get(resource); + int supplies = supplyMap.get(resource); String suffix = Slimefun.getLocalization() .getResourceString(p, ChatUtils.checkPlurality("tooltips.unit", supplies)); From 0e8202ac4a12f9cf80dab8f39e28f305f8d8ab40 Mon Sep 17 00:00:00 2001 From: Ddggdd135 <1306334428@qq.com> Date: Sat, 18 May 2024 22:10:30 +0800 Subject: [PATCH 04/14] =?UTF-8?q?=E5=B0=86succeed=E9=87=8D=E5=91=BD?= =?UTF-8?q?=E5=90=8D=E4=B8=BAsuccess?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: StarWishsama --- .../slimefun4/implementation/items/geo/GEOMiner.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/geo/GEOMiner.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/geo/GEOMiner.java index 8459799334..38e3f193c6 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/geo/GEOMiner.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/geo/GEOMiner.java @@ -343,7 +343,7 @@ public void onResult(SlimefunChunkData result) { } private void start(@Nonnull Block b, @Nonnull BlockMenu inv) { - boolean succeed = Slimefun.getRegistry().getGEOResources().values().isEmpty(); + boolean success = Slimefun.getRegistry().getGEOResources().values().isEmpty(); for (GEOResource resource : Slimefun.getRegistry().getGEOResources().values()) { if (resource.isObtainableFromGEOMiner()) { OptionalInt optional = Slimefun.getGPSNetwork() @@ -352,7 +352,7 @@ private void start(@Nonnull Block b, @Nonnull BlockMenu inv) { if (optional.isEmpty()) continue; - succeed = true; + success = true; int supplies = optional.getAsInt(); if (supplies > 0) { @@ -370,7 +370,7 @@ private void start(@Nonnull Block b, @Nonnull BlockMenu inv) { } } - if (!succeed) { + if (!success) { updateHologram(b, "&4需要先进行地形扫描!"); return; } From eb5391a496b27ffefd93720fccf9cd87c13907f8 Mon Sep 17 00:00:00 2001 From: QwQ-dev Date: Sun, 26 May 2024 18:38:53 +0800 Subject: [PATCH 05/14] Add SlimefunItem#getOptionalById(String) and SlimefunItem#getOptionalByItem(ItemStack). --- .../slimefun4/api/items/SlimefunItem.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/SlimefunItem.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/SlimefunItem.java index 3593dfa8d5..f9e23e222a 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/SlimefunItem.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/SlimefunItem.java @@ -1233,6 +1233,17 @@ public final int hashCode() { return Slimefun.getRegistry().getSlimefunItemIds().get(id); } + /** + * Retrieve a {@link Optional} {@link SlimefunItem} by its id. + * + * @param id + * The id of the {@link SlimefunItem} + * @return The {@link Optional} {@link SlimefunItem} associated with that id. Empty if non-existent + */ + public static @Nonnull Optional getOptionalById(@Nonnull String id) { + return Optional.ofNullable(getById(id)); + } + /** * Retrieve a {@link SlimefunItem} from an {@link ItemStack}. * @@ -1258,6 +1269,17 @@ public final int hashCode() { return null; } + /** + * Retrieve a {@link Optional} {@link SlimefunItem} from an {@link ItemStack}. + * + * @param item + * The {@link ItemStack} to check + * @return The {@link Optional} {@link SlimefunItem} associated with this {@link ItemStack} if present, otherwise empty + */ + public static @Nonnull Optional getOptionalByItem(@Nullable ItemStack item) { + return Optional.ofNullable(getByItem(item)); + } + /** * Should load the {@link SlimefunBlockData} by default. * If return false, only the item with {@link BlockTicker} will be loaded with {@link ChunkLoadEvent}. From 2b353e5d11ca62704e722cb5930cc40146215ba1 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 26 May 2024 14:44:19 +0000 Subject: [PATCH 06/14] fix(deps): update dependency org.postgresql:postgresql to v42.7.3 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 9261301f1a..8ab2940fce 100644 --- a/pom.xml +++ b/pom.xml @@ -309,7 +309,7 @@ org.postgresql postgresql - 42.7.2 + 42.7.3 compile From b0a00ce3ea84511638dbe22faf86dcc63256344a Mon Sep 17 00:00:00 2001 From: QwQ-dev Date: Mon, 27 May 2024 12:00:14 +0800 Subject: [PATCH 07/14] Fix #853. --- .../items/tools/ExplosiveTool.java | 136 +++++++++++++----- 1 file changed, 99 insertions(+), 37 deletions(-) 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 8894b6b924..0bcbdd3428 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 @@ -17,27 +17,32 @@ import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem; import io.github.thebusybiscuit.slimefun4.utils.tags.SlimefunTag; -import java.util.ArrayList; -import java.util.List; -import javax.annotation.Nonnull; -import javax.annotation.ParametersAreNonnullByDefault; import org.bukkit.Bukkit; import org.bukkit.Effect; +import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.Tag; import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockExplodeEvent; import org.bukkit.inventory.ItemStack; +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import java.util.Optional; +import java.util.concurrent.atomic.AtomicBoolean; + /** * This {@link SlimefunItem} is a super class for items like the {@link ExplosivePickaxe} or {@link ExplosiveShovel}. * * @author TheBusyBiscuit - * * @see ExplosivePickaxe * @see ExplosiveShovel - * */ public class ExplosiveTool extends SimpleSlimefunItem implements NotPlaceable, DamageableItem { @@ -71,7 +76,7 @@ public ToolUseHandler getItemHandler() { @ParametersAreNonnullByDefault private void breakBlocks( - BlockBreakEvent e, Player p, ItemStack item, Block b, List blocks, List drops) { + BlockBreakEvent e, Player p, ItemStack item, Block b, List blocks, List drops) { List blocksToDestroy = new ArrayList<>(); if (callExplosionEvent.getValue()) { @@ -104,6 +109,15 @@ private void breakBlocks( ExplosiveToolBreakBlocksEvent event = new ExplosiveToolBreakBlocksEvent(p, b, blocksToDestroy, item, this); Bukkit.getServer().getPluginManager().callEvent(event); + /* + * 修复: https://github.com/SlimefunGuguProject/Slimefun4/issues/853 + * + * 为了修复该问题应该对该列表进行排序,确保头颅先被处理,具体为什么可以看下方 breakBlock 方法。 + */ + if (Bukkit.getPluginManager().isPluginEnabled("ExoticGarden")) { + blocksToDestroy.sort((block1, block2) -> Boolean.compare(block2.getType().equals(Material.PLAYER_HEAD), block1.getType().equals(Material.PLAYER_HEAD))); + } + if (!event.isCancelled()) { for (Block block : blocksToDestroy) { breakBlock(e, p, item, block, drops); @@ -149,38 +163,86 @@ protected boolean canBreak(@Nonnull Player p, @Nonnull Block b) { } @ParametersAreNonnullByDefault - private void breakBlock(BlockBreakEvent e, Player p, ItemStack item, Block b, List drops) { - Slimefun.getProtectionManager().logAction(p, b, Interaction.BREAK_BLOCK); - Material material = b.getType(); - - b.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, material); - var loc = b.getLocation(); - SlimefunItem sfItem = StorageCacheUtils.getSfItem(loc); - - if (sfItem != null && !sfItem.useVanillaBlockBreaking()) { - /* - * Fixes #2989 - * We create a dummy here to pass onto the BlockBreakHandler. - * This will set the correct block context. - */ - BlockBreakEvent dummyEvent = new BlockBreakEvent(b, e.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(p)); - b.setType(Material.AIR); - Slimefun.getDatabaseManager().getBlockDataController().removeBlock(loc); + private void breakBlock(BlockBreakEvent event, Player player, ItemStack item, Block block, List drops) { + Slimefun.getProtectionManager().logAction(player, block, Interaction.BREAK_BLOCK); + Material material = block.getType(); + + block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, material); + Location bloclLocation = block.getLocation(); + + Optional optionalBlockSfItem = + Optional.ofNullable(StorageCacheUtils.getSfItem(bloclLocation)); + + /* + * 修复: 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 = bloclLocation.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); + } + })); } - } else { - b.breakNaturally(item); } - damageItem(p, item); + 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(bloclLocation); + } + } + }); + + if (optionalBlockSfItem.isEmpty()) { + block.breakNaturally(item); + } + + damageItem(player, item); } } From e4bb93b965d296c5c06fa688d8e37550152d171d Mon Sep 17 00:00:00 2001 From: QwQ-dev Date: Mon, 27 May 2024 12:16:37 +0800 Subject: [PATCH 08/14] Format code. --- .../items/tools/ExplosiveTool.java | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) 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 0bcbdd3428..6f2d6256d0 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 @@ -17,6 +17,14 @@ import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem; import io.github.thebusybiscuit.slimefun4.utils.tags.SlimefunTag; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import java.util.Optional; +import java.util.concurrent.atomic.AtomicBoolean; +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; import org.bukkit.Bukkit; import org.bukkit.Effect; import org.bukkit.Location; @@ -28,15 +36,6 @@ import org.bukkit.event.block.BlockExplodeEvent; import org.bukkit.inventory.ItemStack; -import javax.annotation.Nonnull; -import javax.annotation.ParametersAreNonnullByDefault; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; -import java.util.Optional; -import java.util.concurrent.atomic.AtomicBoolean; - /** * This {@link SlimefunItem} is a super class for items like the {@link ExplosivePickaxe} or {@link ExplosiveShovel}. * @@ -76,7 +75,7 @@ public ToolUseHandler getItemHandler() { @ParametersAreNonnullByDefault private void breakBlocks( - BlockBreakEvent e, Player p, ItemStack item, Block b, List blocks, List drops) { + BlockBreakEvent e, Player p, ItemStack item, Block b, List blocks, List drops) { List blocksToDestroy = new ArrayList<>(); if (callExplosionEvent.getValue()) { @@ -115,7 +114,9 @@ private void breakBlocks( * 为了修复该问题应该对该列表进行排序,确保头颅先被处理,具体为什么可以看下方 breakBlock 方法。 */ if (Bukkit.getPluginManager().isPluginEnabled("ExoticGarden")) { - blocksToDestroy.sort((block1, block2) -> Boolean.compare(block2.getType().equals(Material.PLAYER_HEAD), block1.getType().equals(Material.PLAYER_HEAD))); + blocksToDestroy.sort((block1, block2) -> Boolean.compare( + block2.getType().equals(Material.PLAYER_HEAD), + block1.getType().equals(Material.PLAYER_HEAD))); } if (!event.isCancelled()) { @@ -170,8 +171,7 @@ private void breakBlock(BlockBreakEvent event, Player player, ItemStack item, Bl block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, material); Location bloclLocation = block.getLocation(); - Optional optionalBlockSfItem = - Optional.ofNullable(StorageCacheUtils.getSfItem(bloclLocation)); + Optional optionalBlockSfItem = Optional.ofNullable(StorageCacheUtils.getSfItem(bloclLocation)); /* * 修复: https://github.com/SlimefunGuguProject/Slimefun4/issues/853 @@ -184,7 +184,8 @@ private void breakBlock(BlockBreakEvent event, Player player, ItemStack item, Bl */ AtomicBoolean isUseVanillaBlockBreaking = new AtomicBoolean(true); - if (Bukkit.getPluginManager().isPluginEnabled("ExoticGarden") && block.getType().equals(Material.PLAYER_HEAD)) { + if (Bukkit.getPluginManager().isPluginEnabled("ExoticGarden") + && block.getType().equals(Material.PLAYER_HEAD)) { Location leavesLocation = bloclLocation.clone(); leavesLocation.setY(leavesLocation.getY() - 1); @@ -193,7 +194,7 @@ private void breakBlock(BlockBreakEvent event, Player player, ItemStack item, Bl if (Tag.LEAVES.isTagged(leaveBlockType)) { Optional optionalLeavesBlockSfItem = - Optional.ofNullable(StorageCacheUtils.getSfItem(leavesLocation)); + Optional.ofNullable(StorageCacheUtils.getSfItem(leavesLocation)); optionalBlockSfItem.ifPresent(blockSfItem -> optionalLeavesBlockSfItem.ifPresent(leavesSfItem -> { Collection sfItemDrops = blockSfItem.getDrops(); @@ -228,7 +229,8 @@ private void breakBlock(BlockBreakEvent event, Player player, ItemStack item, Bl * 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)); + sfItem.callItemHandler( + BlockBreakHandler.class, handler -> handler.onPlayerBreak(dummyEvent, item, drops)); // Make sure the event wasn't cancelled by the BlockBreakHandler. if (!dummyEvent.isCancelled()) { From 1b08db00c0bc71f40897039a9ffa3259ff08fc65 Mon Sep 17 00:00:00 2001 From: QwQ-dev Date: Mon, 27 May 2024 12:19:22 +0800 Subject: [PATCH 09/14] Spelling correction. --- .../implementation/items/tools/ExplosiveTool.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 6f2d6256d0..05a459a23b 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 @@ -169,9 +169,9 @@ private void breakBlock(BlockBreakEvent event, Player player, ItemStack item, Bl Material material = block.getType(); block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, material); - Location bloclLocation = block.getLocation(); + Location blockLocation = block.getLocation(); - Optional optionalBlockSfItem = Optional.ofNullable(StorageCacheUtils.getSfItem(bloclLocation)); + Optional optionalBlockSfItem = Optional.ofNullable(StorageCacheUtils.getSfItem(blockLocation)); /* * 修复: https://github.com/SlimefunGuguProject/Slimefun4/issues/853 @@ -186,7 +186,7 @@ private void breakBlock(BlockBreakEvent event, Player player, ItemStack item, Bl if (Bukkit.getPluginManager().isPluginEnabled("ExoticGarden") && block.getType().equals(Material.PLAYER_HEAD)) { - Location leavesLocation = bloclLocation.clone(); + Location leavesLocation = blockLocation.clone(); leavesLocation.setY(leavesLocation.getY() - 1); Block leaveBlock = leavesLocation.getBlock(); @@ -236,7 +236,7 @@ private void breakBlock(BlockBreakEvent event, Player player, ItemStack item, Bl if (!dummyEvent.isCancelled()) { drops.addAll(sfItem.getDrops(player)); block.setType(Material.AIR); - Slimefun.getDatabaseManager().getBlockDataController().removeBlock(bloclLocation); + Slimefun.getDatabaseManager().getBlockDataController().removeBlock(blockLocation); } } }); From 749ba3046e401b3f2d7dc5ef5af67862c96a1f28 Mon Sep 17 00:00:00 2001 From: StarWishsama Date: Mon, 27 May 2024 12:40:30 +0800 Subject: [PATCH 10/14] chore(doc): update contributing guide --- .git-hooks/commit-msg | 20 ++++++++++++++++++++ .git-hooks/pre-commit | 2 +- CONTRIBUTING.md | 20 +++++++++++++------- pom.xml | 27 ++------------------------- 4 files changed, 36 insertions(+), 33 deletions(-) create mode 100644 .git-hooks/commit-msg diff --git a/.git-hooks/commit-msg b/.git-hooks/commit-msg new file mode 100644 index 0000000000..9aa35923b3 --- /dev/null +++ b/.git-hooks/commit-msg @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +INPUT_FILE=$1 + +START_LINE=$(head -n1 "$INPUT_FILE") + +PATTERN='^(feat(ure)?|fix|docs|style|refactor|ci|chore|perf|build|test|revert|trans)(\(.+\))?(!)?: .+$' + +if [ "${#START_LINE}" -gt "72" ]; then + echo -e "Message too long! Assert length <= 72." + exit +fi + +if ! [[ "$START_LINE" =~ $PATTERN ]]; then + echo -e "$START_LINE" + echo + echo -e "↑ Bad commit message, it does not meet the Conventional Commit standard." + echo -e "See more: https://www.conventionalcommits.org/en/v1.0.0/" + exit 1 +fi \ No newline at end of file diff --git a/.git-hooks/pre-commit b/.git-hooks/pre-commit index 3c0c23770a..d1853bd821 100644 --- a/.git-hooks/pre-commit +++ b/.git-hooks/pre-commit @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash echo "[pre-commit check]" diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 08f8025bfd..87a1b8ff9a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,10 +1,16 @@ -# 贡献代码指南 +# 贡献指南 -在向 Slimefun 汉化版提交代码前,你必须先阅读这个指南。 +在对 Slimefun 汉化版进行代码前,必须先阅读此贡献指南。 + +# 设置环境 + +我们提供了一个自动化格式检查系统,请使用 `mvn configure` 进行初始化。 + +本项目已经提供 `.editorconfig` 用于控制代码样式。如果你有自己的代码样式风格,请在对本仓库进行贡献前切换为当前仓库的风格配置。 # 提交信息规范 -本项目强制使用 [约定式提交](https://www.conventionalcommits.org/zh-hans/v1.0.0/) 的提交信息规范。 +本项目**强制使用** [约定式提交](https://www.conventionalcommits.org/zh-hans/v1.0.0/) 的提交信息规范。 > 简单来说, 你的提交信息需要包含以下内容: > @@ -18,6 +24,8 @@ 如果是修复请在主提交消息上声明,不必重复声明。 +我们支持的类型前缀正则如下:`(feat(ure)?|fix|docs|style|refactor|ci|chore|perf|build|test|revert|trans)` + 另外的, 如果是与翻译相关的提交,类型应为 trans。 # 代码规范 @@ -26,12 +34,10 @@ 请不要过度缩减代码长度, 空格少了 Slimefun 也不会因此跑得更快. -我们使用了 Spotless 作为代码格式化工具,你可以直接使用 `mvn spotless:check spotless:apply` 来自动格式化你的代码。 - -如果你希望你的代码被合并至官方, 请遵守 Slimefun 主仓库的 [提交规范](https://github.com/Slimefun/Slimefun4/blob/master/CONTRIBUTING.md) +我们使用了 Spotless 作为代码格式化工具,在提交前你**必须**使用 `mvn spotless:check spotless:apply` 来自动格式化你的代码,否则将会被格式检查器拦截 PR。 # 提交代码类型 你提交的代码可以是修复、新增内容和 API。 -下游代码现在支持提交 API 相关代码,开发者们可以通过 jitpack/GitHub Package 依赖汉化版的 Slimefun。 \ No newline at end of file +下游代码现在支持提交 API 相关代码,开发者们可以通过 jitpack 依赖汉化版的 Slimefun。 \ No newline at end of file diff --git a/pom.xml b/pom.xml index 8ab2940fce..8fd9dad7a2 100644 --- a/pom.xml +++ b/pom.xml @@ -201,12 +201,13 @@ .git-hooks/pre-commit + .git-hooks/commit-msg - install + configure @@ -312,30 +313,6 @@ 42.7.3 compile - - org.apache.logging.log4j - log4j-api - 2.19.0 - provided - - - org.apache.logging.log4j - log4j-core - 2.19.0 - provided - - - org.apache.logging.log4j - log4j-slf4j-impl - 2.19.0 - provided - - - org.slf4j - slf4j-api - 2.0.7 - provided - From 88ab0b4097348e0d1c310e1412d28b1023d5465a Mon Sep 17 00:00:00 2001 From: StarWishsama Date: Mon, 27 May 2024 12:53:13 +0800 Subject: [PATCH 11/14] chore: remove unused hikari filter --- CONTRIBUTING.md | 2 +- pom.xml | 2 +- .../norain/slimefun4/SlimefunExtended.java | 2 - .../slimefun4/utils/HikariLogFilter.java | 50 ------------------- 4 files changed, 2 insertions(+), 54 deletions(-) delete mode 100644 src/main/java/city/norain/slimefun4/utils/HikariLogFilter.java diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 87a1b8ff9a..1c27c23107 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -4,7 +4,7 @@ # 设置环境 -我们提供了一个自动化格式检查系统,请使用 `mvn configure` 进行初始化。 +我们提供了一个自动化格式检查系统,请使用 `mvn install` 进行初始化。 本项目已经提供 `.editorconfig` 用于控制代码样式。如果你有自己的代码样式风格,请在对本仓库进行贡献前切换为当前仓库的风格配置。 diff --git a/pom.xml b/pom.xml index 8fd9dad7a2..bff339ba85 100644 --- a/pom.xml +++ b/pom.xml @@ -207,7 +207,7 @@ - configure + install diff --git a/src/main/java/city/norain/slimefun4/SlimefunExtended.java b/src/main/java/city/norain/slimefun4/SlimefunExtended.java index a614f4f9a8..adacde99bb 100644 --- a/src/main/java/city/norain/slimefun4/SlimefunExtended.java +++ b/src/main/java/city/norain/slimefun4/SlimefunExtended.java @@ -1,7 +1,6 @@ package city.norain.slimefun4; import city.norain.slimefun4.listener.SlimefunMigrateListener; -import city.norain.slimefun4.utils.HikariLogFilter; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import java.util.logging.Level; import javax.annotation.Nonnull; @@ -16,7 +15,6 @@ public final class SlimefunExtended { private static void checkDebug() { if ("true".equals(System.getProperty("slimefun.database.debug"))) { databaseDebugMode = true; - HikariLogFilter.registerFilter(org.apache.logging.log4j.Level.DEBUG); } } diff --git a/src/main/java/city/norain/slimefun4/utils/HikariLogFilter.java b/src/main/java/city/norain/slimefun4/utils/HikariLogFilter.java deleted file mode 100644 index 582b1eba7a..0000000000 --- a/src/main/java/city/norain/slimefun4/utils/HikariLogFilter.java +++ /dev/null @@ -1,50 +0,0 @@ -package city.norain.slimefun4.utils; - -import org.apache.logging.log4j.Level; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Marker; -import org.apache.logging.log4j.core.LogEvent; -import org.apache.logging.log4j.core.Logger; -import org.apache.logging.log4j.core.filter.AbstractFilter; -import org.apache.logging.log4j.message.Message; - -public class HikariLogFilter extends AbstractFilter { - private final Level level; - - public HikariLogFilter(Level level) { - this.level = level; - } - - public static void registerFilter(Level level) { - Logger logger = (Logger) LogManager.getRootLogger(); - logger.addFilter(new HikariLogFilter(level)); - } - - @Override - public Result filter(LogEvent event) { - if (event == null) { - return Result.NEUTRAL; - } - - if (event.getLoggerName().contains("Hikari") && event.getLevel().isInRange(level, Level.FATAL)) { - return Result.ACCEPT; - } - - return Result.NEUTRAL; - } - - @Override - public Result filter(Logger logger, Level level, Marker marker, Message msg, Throwable t) { - return Result.NEUTRAL; - } - - @Override - public Result filter(Logger logger, Level level, Marker marker, String msg, Object... params) { - return Result.NEUTRAL; - } - - @Override - public Result filter(Logger logger, Level level, Marker marker, Object msg, Throwable t) { - return Result.NEUTRAL; - } -} From 4bd30b50816ecaccad5042568a594ee2327f0526 Mon Sep 17 00:00:00 2001 From: StarWishsama Date: Mon, 27 May 2024 12:59:56 +0800 Subject: [PATCH 12/14] build: introduce commit msg checker --- .github/workflows/dev-ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/dev-ci.yml b/.github/workflows/dev-ci.yml index b902674614..23b35451f3 100644 --- a/.github/workflows/dev-ci.yml +++ b/.github/workflows/dev-ci.yml @@ -24,6 +24,10 @@ jobs: java-package: jdk architecture: x64 cache: maven + - name: Commit message style check + run: | + chmod +x .git-hooks/commit-msg + ./commit-msg - name: Codestyle check run: mvn -B spotless:check --errors - name: Build Slimefun From 872eae8dc7c03953ca650746e5e6eaabbec112b7 Mon Sep 17 00:00:00 2001 From: StarWishsama Date: Mon, 27 May 2024 20:55:26 +0800 Subject: [PATCH 13/14] chore: thanks but no --- .git-hooks/commit-msg | 20 -------------------- .github/workflows/dev-ci.yml | 4 ---- pom.xml | 1 - 3 files changed, 25 deletions(-) delete mode 100644 .git-hooks/commit-msg diff --git a/.git-hooks/commit-msg b/.git-hooks/commit-msg deleted file mode 100644 index 9aa35923b3..0000000000 --- a/.git-hooks/commit-msg +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env bash - -INPUT_FILE=$1 - -START_LINE=$(head -n1 "$INPUT_FILE") - -PATTERN='^(feat(ure)?|fix|docs|style|refactor|ci|chore|perf|build|test|revert|trans)(\(.+\))?(!)?: .+$' - -if [ "${#START_LINE}" -gt "72" ]; then - echo -e "Message too long! Assert length <= 72." - exit -fi - -if ! [[ "$START_LINE" =~ $PATTERN ]]; then - echo -e "$START_LINE" - echo - echo -e "↑ Bad commit message, it does not meet the Conventional Commit standard." - echo -e "See more: https://www.conventionalcommits.org/en/v1.0.0/" - exit 1 -fi \ No newline at end of file diff --git a/.github/workflows/dev-ci.yml b/.github/workflows/dev-ci.yml index 23b35451f3..b902674614 100644 --- a/.github/workflows/dev-ci.yml +++ b/.github/workflows/dev-ci.yml @@ -24,10 +24,6 @@ jobs: java-package: jdk architecture: x64 cache: maven - - name: Commit message style check - run: | - chmod +x .git-hooks/commit-msg - ./commit-msg - name: Codestyle check run: mvn -B spotless:check --errors - name: Build Slimefun diff --git a/pom.xml b/pom.xml index bff339ba85..5ce886f565 100644 --- a/pom.xml +++ b/pom.xml @@ -201,7 +201,6 @@ .git-hooks/pre-commit - .git-hooks/commit-msg From b86c0474ede00ce25d45285d7ae23bd6dc7fa5aa Mon Sep 17 00:00:00 2001 From: Ddggdd135 <66861021+JWJUN233233@users.noreply.github.com> Date: Thu, 30 May 2024 09:51:12 +0800 Subject: [PATCH 14/14] =?UTF-8?q?fix:=20=E8=BE=90=E5=B0=84=E7=89=A9?= =?UTF-8?q?=E5=93=81=E7=89=B9=E6=80=A7=E5=88=A4=E6=96=AD=E9=94=99=E8=AF=AF?= =?UTF-8?q?=20(#894)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../slimefun4/implementation/tasks/armor/RadiationTask.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/armor/RadiationTask.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/armor/RadiationTask.java index eda9bd5e1c..63ac21bf24 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/armor/RadiationTask.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/armor/RadiationTask.java @@ -7,7 +7,6 @@ import io.github.thebusybiscuit.slimefun4.core.attributes.RadiationSymptom; import io.github.thebusybiscuit.slimefun4.core.attributes.Radioactive; import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; -import io.github.thebusybiscuit.slimefun4.implementation.items.RadioactiveItem; import io.github.thebusybiscuit.slimefun4.implementation.listeners.RadioactivityListener; import io.github.thebusybiscuit.slimefun4.utils.RadiationUtils; import java.util.HashMap; @@ -52,7 +51,7 @@ protected void onPlayerTick(Player p, PlayerProfile profile) { continue; } SlimefunItem sfItem = SlimefunItem.getByItem(item); - if (sfItem instanceof RadioactiveItem radioactiveItem) { + if (sfItem instanceof Radioactive radioactiveItem) { exposureTotal += item.getAmount() * radioactiveItem.getRadioactivity().getExposureModifier(); }