From 0137abadf10feeebd80f4db3c3c62b4859c47446 Mon Sep 17 00:00:00 2001 From: Jeffrey Date: Tue, 8 Aug 2023 17:27:30 +0200 Subject: [PATCH 01/18] fix #3836 --- .../slimefun4/implementation/items/tools/ExplosiveTool.java | 4 ++++ 1 file changed, 4 insertions(+) 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 db990c64c9..52c6e44f30 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 @@ -6,6 +6,7 @@ import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; +import dev.lone.itemsadder.api.CustomBlock; import org.bukkit.Bukkit; import org.bukkit.Effect; import org.bukkit.Material; @@ -172,6 +173,9 @@ private void breakBlock(BlockBreakEvent e, Player p, ItemStack item, Block b, Li b.setType(Material.AIR); BlockStorage.clearBlockInfo(b); } + // Fixes #3836 + } else if (CustomBlock.byAlreadyPlaced(b) != null) { + return; } else { b.breakNaturally(item); } From fb9e8c55e842d95906ed59fa628e341f02527a83 Mon Sep 17 00:00:00 2001 From: Jeffrey Date: Mon, 14 Aug 2023 13:00:38 +0200 Subject: [PATCH 02/18] clean up --- .../slimefun4/implementation/items/tools/ExplosiveTool.java | 5 +---- 1 file changed, 1 insertion(+), 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 52c6e44f30..bd85adc0c6 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 @@ -138,7 +138,7 @@ protected boolean canBreak(@Nonnull Player p, @Nonnull Block b) { return false; } else if (!b.getWorld().getWorldBorder().isInside(b.getLocation())) { return false; - } else if (Slimefun.getIntegrations().isCustomBlock(b)) { + } else if (CustomBlock.byAlreadyPlaced(b) != null) { return false; } else { return Slimefun.getProtectionManager().hasPermission(p, b.getLocation(), Interaction.BREAK_BLOCK); @@ -173,9 +173,6 @@ private void breakBlock(BlockBreakEvent e, Player p, ItemStack item, Block b, Li b.setType(Material.AIR); BlockStorage.clearBlockInfo(b); } - // Fixes #3836 - } else if (CustomBlock.byAlreadyPlaced(b) != null) { - return; } else { b.breakNaturally(item); } From 7934a09e1af5685f728469701beff067e35c7953 Mon Sep 17 00:00:00 2001 From: Jeffrey Date: Mon, 14 Aug 2023 13:03:31 +0200 Subject: [PATCH 03/18] changed to == --- .../slimefun4/implementation/items/tools/ExplosiveTool.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 bd85adc0c6..fab595cdcb 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 @@ -138,7 +138,7 @@ protected boolean canBreak(@Nonnull Player p, @Nonnull Block b) { return false; } else if (!b.getWorld().getWorldBorder().isInside(b.getLocation())) { return false; - } else if (CustomBlock.byAlreadyPlaced(b) != null) { + } else if (CustomBlock.byAlreadyPlaced(b) == null) { return false; } else { return Slimefun.getProtectionManager().hasPermission(p, b.getLocation(), Interaction.BREAK_BLOCK); From 27f4ecbacf0eed8ad105f195ea630d05d5f08bce Mon Sep 17 00:00:00 2001 From: iTwins Date: Fri, 18 Aug 2023 23:55:28 +0200 Subject: [PATCH 04/18] fix getting radiated when not supposed to --- .../slimefun4/api/player/PlayerProfile.java | 17 +++----- .../slimefun4/implementation/Slimefun.java | 2 + .../listeners/JoinListener.java | 43 +++++++++++++++++++ .../tasks/armor/RadiationTask.java | 2 + 4 files changed, 52 insertions(+), 12 deletions(-) create mode 100644 src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/JoinListener.java diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/PlayerProfile.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/PlayerProfile.java index 29accb9509..2362a91d4a 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/PlayerProfile.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/player/PlayerProfile.java @@ -493,24 +493,17 @@ public boolean hasFullProtectionAgainst(@Nonnull ProtectionType type) { for (HashedArmorpiece armorpiece : armor) { Optional armorPiece = armorpiece.getItem(); - - if (!armorPiece.isPresent()) { - setId = null; - } else if (armorPiece.get() instanceof ProtectiveArmor protectedArmor) { - if (setId == null && protectedArmor.isFullSetRequired()) { - setId = protectedArmor.getArmorSetId(); - } - - for (ProtectionType protectionType : protectedArmor.getProtectionTypes()) { + if (armorPiece.isPresent() && armorPiece.get() instanceof ProtectiveArmor protectiveArmor) { + for (ProtectionType protectionType : protectiveArmor.getProtectionTypes()) { if (protectionType == type) { - if (setId == null) { + if (!protectiveArmor.isFullSetRequired()) { return true; - } else if (setId.equals(protectedArmor.getArmorSetId())) { + } else if (setId == null || setId.equals(protectiveArmor.getArmorSetId())) { armorCount++; + setId = protectiveArmor.getArmorSetId(); } } } - } } 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 f1fffb2b83..2b8dd78f02 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/Slimefun.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/Slimefun.java @@ -82,6 +82,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.listeners.HopperListener; import io.github.thebusybiscuit.slimefun4.implementation.listeners.ItemDropListener; import io.github.thebusybiscuit.slimefun4.implementation.listeners.ItemPickupListener; +import io.github.thebusybiscuit.slimefun4.implementation.listeners.JoinListener; import io.github.thebusybiscuit.slimefun4.implementation.listeners.MiddleClickListener; import io.github.thebusybiscuit.slimefun4.implementation.listeners.MiningAndroidListener; import io.github.thebusybiscuit.slimefun4.implementation.listeners.MultiBlockListener; @@ -646,6 +647,7 @@ private void registerListeners() { new BeeWingsListener(this, (BeeWings) SlimefunItems.BEE_WINGS.getItem()); new PiglinListener(this); new SmithingTableListener(this); + new JoinListener(this); // Item-specific Listeners new CoolerListener(this, (Cooler) SlimefunItems.COOLER.getItem()); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/JoinListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/JoinListener.java new file mode 100644 index 0000000000..202fe079c0 --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/JoinListener.java @@ -0,0 +1,43 @@ +package io.github.thebusybiscuit.slimefun4.implementation.listeners; + +import javax.annotation.Nonnull; + +import org.bukkit.Material; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.inventory.ItemStack; + +import io.github.thebusybiscuit.slimefun4.api.items.HashedArmorpiece; +import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; +import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile; +import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; +import io.github.thebusybiscuit.slimefun4.implementation.items.armor.SlimefunArmorPiece; +import io.github.thebusybiscuit.slimefun4.implementation.tasks.armor.RadiationTask; + +/** + * This {@link Listener} caches the armor of the player on join. + * This is mainly for the {@link RadiationTask}. + * + * @author iTwins + */ +public class JoinListener implements Listener { + + public JoinListener(@Nonnull Slimefun plugin) { + plugin.getServer().getPluginManager().registerEvents(this, plugin); + } + + @EventHandler + public void onJoin(@Nonnull PlayerJoinEvent e) { + PlayerProfile.get(e.getPlayer(), playerProfile -> { + final ItemStack[] armorContents = e.getPlayer().getInventory().getArmorContents(); + final HashedArmorpiece[] hashedArmorpieces = playerProfile.getArmor(); + for (int i = 0; i < 4; i++) { + if (armorContents[i] != null && armorContents[i].getType() != Material.AIR && SlimefunItem.getByItem(armorContents[i]) instanceof SlimefunArmorPiece sfArmorPiece) { + hashedArmorpieces[i].update(armorContents[i], sfArmorPiece); + } + } + }); + } + +} 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 c2b40ae1ed..29ac850805 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 @@ -85,6 +85,8 @@ protected void onPlayerTick(Player p, PlayerProfile profile) { BaseComponent[] components = new ComponentBuilder().append(ChatColors.color(msg)).create(); p.spigot().sendMessage(ChatMessageType.ACTION_BAR, components); } + } else { + RadiationUtils.removeExposure(p, 1); } } From 1315e5a8c926d2af3e99b5fc67d9608c83091b1c Mon Sep 17 00:00:00 2001 From: iTwins Date: Sun, 20 Aug 2023 03:42:30 +0200 Subject: [PATCH 05/18] refactored ternary operators --- .../slimefun4/api/geo/ResourceManager.java | 7 ++++--- .../slimefun4/utils/ChatUtils.java | 17 +++++++++++++++++ 2 files changed, 21 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 d15024440d..3e93255b72 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 @@ -28,6 +28,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import io.github.thebusybiscuit.slimefun4.implementation.items.geo.GEOMiner; import io.github.thebusybiscuit.slimefun4.implementation.items.geo.GEOScanner; +import io.github.thebusybiscuit.slimefun4.utils.ChatUtils; import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils; import io.github.thebusybiscuit.slimefun4.utils.HeadTexture; @@ -236,13 +237,13 @@ public void scan(@Nonnull Player p, @Nonnull Block block, int page) { for (int i = page * 28; i < resources.size() && i < (page + 1) * 28; i++) { GEOResource resource = resources.get(i); OptionalInt optional = getSupplies(resource, block.getWorld(), x, z); - int supplies = optional.isPresent() ? optional.getAsInt() : generate(resource, block.getWorld(), x, block.getY(), z); - String suffix = Slimefun.getLocalization().getResourceString(p, supplies == 1 ? "tooltips.unit" : "tooltips.units"); + int supplies = optional.orElse(generate(resource, block.getWorld(), x, block.getY(), z)); + String suffix = Slimefun.getLocalization().getResourceString(p, ChatUtils.checkPlurality("tooltips.unit", supplies)); ItemStack item = new CustomItemStack(resource.getItem(), "&f" + resource.getName(p), "&8\u21E8 &e" + supplies + ' ' + suffix); if (supplies > 1) { - item.setAmount(supplies > item.getMaxStackSize() ? item.getMaxStackSize() : supplies); + item.setAmount(Math.min(supplies, item.getMaxStackSize())); } menu.addItem(index, item, ChestMenuUtils.getEmptyClickHandler()); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/ChatUtils.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/ChatUtils.java index e3d7aac4b9..65ed4c8ac5 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/ChatUtils.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/ChatUtils.java @@ -80,4 +80,21 @@ public static void awaitInput(@Nonnull Player p, @Nonnull Consumer callb return builder.toString(); } + /** + * This method adds an s to a string if the supplied integer is not 1. + * + * @param string + * The string to potentially pluralize + * @param count + * The amount of things + * @return + * string if count is 1 else string + "s" + */ + public static @Nonnull String checkPlurality(@Nonnull String string, int count) { + if (count == 1) { + return string; + } + return string + "s"; + } + } From 54f3530658ac834c1f3a341bf71d053093ddd4de Mon Sep 17 00:00:00 2001 From: Jeffrey Date: Sun, 20 Aug 2023 14:16:55 +0200 Subject: [PATCH 06/18] requested changes --- .../slimefun4/implementation/items/tools/ExplosiveTool.java | 2 +- .../slimefun4/integrations/IntegrationsManager.java | 3 ++- 2 files changed, 3 insertions(+), 2 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 fab595cdcb..eb1be0bf45 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 @@ -138,7 +138,7 @@ protected boolean canBreak(@Nonnull Player p, @Nonnull Block b) { return false; } else if (!b.getWorld().getWorldBorder().isInside(b.getLocation())) { return false; - } else if (CustomBlock.byAlreadyPlaced(b) == null) { + } else if (Slimefun.getIntegrations().isCustomBlock(b)) { return false; } else { return Slimefun.getProtectionManager().hasPermission(p, b.getLocation(), Interaction.BREAK_BLOCK); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/integrations/IntegrationsManager.java b/src/main/java/io/github/thebusybiscuit/slimefun4/integrations/IntegrationsManager.java index 579e5bfb69..5063884c56 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/integrations/IntegrationsManager.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/integrations/IntegrationsManager.java @@ -6,6 +6,7 @@ import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; +import dev.lone.itemsadder.api.CustomBlock; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Server; @@ -236,7 +237,7 @@ public boolean isEventFaked(@Nonnull Event event) { public boolean isCustomBlock(@Nonnull Block block) { if (isItemsAdderInstalled) { try { - return ItemsAdder.isCustomBlock(block); + return CustomBlock.byAlreadyPlaced(block) != null; } catch (Exception | LinkageError x) { logError("ItemsAdder", x); } From e4bd5b164028722610e0cf1edba26619ea82c631 Mon Sep 17 00:00:00 2001 From: Jeffrey Date: Sun, 20 Aug 2023 14:18:16 +0200 Subject: [PATCH 07/18] removed unused import --- .../slimefun4/implementation/items/tools/ExplosiveTool.java | 1 - 1 file changed, 1 deletion(-) 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 eb1be0bf45..db990c64c9 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 @@ -6,7 +6,6 @@ import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; -import dev.lone.itemsadder.api.CustomBlock; import org.bukkit.Bukkit; import org.bukkit.Effect; import org.bukkit.Material; From 158167187dc538745eba7405c4b5d18181563e33 Mon Sep 17 00:00:00 2001 From: iTwins Date: Fri, 25 Aug 2023 18:25:12 +0200 Subject: [PATCH 08/18] replaced tags with {@code} tags --- .../io/github/thebusybiscuit/slimefun4/utils/ChatUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/ChatUtils.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/ChatUtils.java index 65ed4c8ac5..c5a175d5a5 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/ChatUtils.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/ChatUtils.java @@ -88,7 +88,7 @@ public static void awaitInput(@Nonnull Player p, @Nonnull Consumer callb * @param count * The amount of things * @return - * string if count is 1 else string + "s" + * {@code string} if {@code count} is 1 else {@code string + "s"} */ public static @Nonnull String checkPlurality(@Nonnull String string, int count) { if (count == 1) { From 98cb08556b0625a45b1d22d5d547b34f53538e00 Mon Sep 17 00:00:00 2001 From: iTwins Date: Fri, 25 Aug 2023 18:39:31 +0200 Subject: [PATCH 09/18] use local variable to avoid accessing array multiple times --- .../slimefun4/implementation/listeners/JoinListener.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/JoinListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/JoinListener.java index 202fe079c0..28d15851bd 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/JoinListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/JoinListener.java @@ -33,8 +33,9 @@ public void onJoin(@Nonnull PlayerJoinEvent e) { final ItemStack[] armorContents = e.getPlayer().getInventory().getArmorContents(); final HashedArmorpiece[] hashedArmorpieces = playerProfile.getArmor(); for (int i = 0; i < 4; i++) { - if (armorContents[i] != null && armorContents[i].getType() != Material.AIR && SlimefunItem.getByItem(armorContents[i]) instanceof SlimefunArmorPiece sfArmorPiece) { - hashedArmorpieces[i].update(armorContents[i], sfArmorPiece); + final ItemStack armorPiece = armorContents[i]; + if (armorPiece != null && armorPiece.getType() != Material.AIR && SlimefunItem.getByItem(armorPiece) instanceof SlimefunArmorPiece sfArmorPiece) { + hashedArmorpieces[i].update(armorPiece, sfArmorPiece); } } }); From 361c83fd73553341c18c9875cb0e204070aee4a7 Mon Sep 17 00:00:00 2001 From: JustAHuman-xD <65748158+JustAHuman-xD@users.noreply.github.com> Date: Tue, 29 Aug 2023 16:47:29 -0500 Subject: [PATCH 10/18] Add the get optional methods --- .../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 0d4b1f12fa..7db2dc5a2d 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 @@ -1161,6 +1161,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}. * @@ -1208,4 +1219,15 @@ 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 @Nonnull Optional getOptionalByItem(@Nullable ItemStack item) { + return Optional.ofNullable(getByItem(item)); + } + } \ No newline at end of file From 25ac1655d6209f2b7390c3c434ac18e10e586072 Mon Sep 17 00:00:00 2001 From: JustAHuman-xD <65748158+JustAHuman-xD@users.noreply.github.com> Date: Tue, 29 Aug 2023 16:56:08 -0500 Subject: [PATCH 11/18] Remove accidental new line --- .../github/thebusybiscuit/slimefun4/api/items/SlimefunItem.java | 1 - 1 file changed, 1 deletion(-) 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 6a54669cf8..d3bc8368fd 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 @@ -1202,5 +1202,4 @@ public final int hashCode() { public @Nonnull Optional getOptionalByItem(@Nullable ItemStack item) { return Optional.ofNullable(getByItem(item)); } - } From 5b2e95933ad9b7fa5e679722c7ce37db9ff2f3cb Mon Sep 17 00:00:00 2001 From: iTwins Date: Wed, 30 Aug 2023 23:52:17 +0200 Subject: [PATCH 12/18] added unit test for checkPlurality and IAE for negative values --- .../thebusybiscuit/slimefun4/utils/ChatUtils.java | 5 +++++ .../thebusybiscuit/slimefun4/utils/TestChatUtils.java | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/ChatUtils.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/ChatUtils.java index c5a175d5a5..829e5891c3 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/ChatUtils.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/ChatUtils.java @@ -89,8 +89,13 @@ public static void awaitInput(@Nonnull Player p, @Nonnull Consumer callb * The amount of things * @return * {@code string} if {@code count} is 1 else {@code string + "s"} + * @throws IllegalArgumentException + * if count is less than 0 */ public static @Nonnull String checkPlurality(@Nonnull String string, int count) { + if (count < 0) { + throw new IllegalArgumentException("Argument count cannot be negative."); + } if (count == 1) { return string; } diff --git a/src/test/java/io/github/thebusybiscuit/slimefun4/utils/TestChatUtils.java b/src/test/java/io/github/thebusybiscuit/slimefun4/utils/TestChatUtils.java index 80fa61aa83..794b02e4b5 100644 --- a/src/test/java/io/github/thebusybiscuit/slimefun4/utils/TestChatUtils.java +++ b/src/test/java/io/github/thebusybiscuit/slimefun4/utils/TestChatUtils.java @@ -33,4 +33,14 @@ void testColorCodeRemoval() { Assertions.assertEquals(expected, ChatUtils.removeColorCodes(ChatColor.GREEN + "Hello " + ChatColor.RED + "world")); } + @Test + @DisplayName("Test ChatUtils.checkPlurality(...)") + void testPluralization() { + String input = "Banana"; + Assertions.assertThrows(IllegalArgumentException.class, () -> ChatUtils.checkPlurality(input, -1)); + Assertions.assertEquals("Bananas", ChatUtils.checkPlurality(input, 0)); + Assertions.assertEquals("Banana", ChatUtils.checkPlurality(input, 1)); + Assertions.assertEquals("Bananas", ChatUtils.checkPlurality(input, 2)); + } + } From 666e9839dcd5a9eed725693f78ad4a9637aafd9f Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 3 Sep 2023 12:39:30 +0200 Subject: [PATCH 13/18] [CI skip] Update dependency net.imprex:orebfuscator-api to v5.4.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index eee000c2b6..d17527aa4a 100644 --- a/pom.xml +++ b/pom.xml @@ -502,7 +502,7 @@ net.imprex orebfuscator-api - 5.3.3 + 5.4.0 provided From d265b7a0208349e5cb369f9653db13d0ab94226f Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 3 Sep 2023 12:40:59 +0200 Subject: [PATCH 14/18] [CI skip] Update dependency org.mockito:mockito-core to v5.5.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index d17527aa4a..8c41fbb567 100644 --- a/pom.xml +++ b/pom.xml @@ -389,7 +389,7 @@ org.mockito mockito-core - 5.4.0 + 5.5.0 test From ef3c960d7fb80e9bc70716a999a69dad177c0de8 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 3 Sep 2023 12:41:56 +0200 Subject: [PATCH 15/18] [CI skip] Update actions/checkout action to v3.6.0 --- .github/workflows/discord-webhook.yml | 2 +- .github/workflows/sonarcloud.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/discord-webhook.yml b/.github/workflows/discord-webhook.yml index f4c018a140..14c37fc1ef 100644 --- a/.github/workflows/discord-webhook.yml +++ b/.github/workflows/discord-webhook.yml @@ -21,7 +21,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3.5.3 + uses: actions/checkout@v3.6.0 - name: Set up Java JDK 17 uses: actions/setup-java@v3.12.0 diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 8454eaac19..8128ed2ef2 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -19,7 +19,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3.5.3 + uses: actions/checkout@v3.6.0 with: fetch-depth: 0 From bcea5077f8236ab0bea6f74ce94287d0b1f900c1 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 3 Sep 2023 12:42:59 +0200 Subject: [PATCH 16/18] [CI skip] Update dependency com.gmail.nossr50.mcMMO:mcMMO to v2.1.223 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 8c41fbb567..2a2d47bf35 100644 --- a/pom.xml +++ b/pom.xml @@ -446,7 +446,7 @@ com.gmail.nossr50.mcMMO mcMMO - 2.1.222 + 2.1.223 provided From 6d70544bb715a1ca9875fec486de9edeabcd077a Mon Sep 17 00:00:00 2001 From: Jeffrey Date: Sun, 3 Sep 2023 17:45:08 +0200 Subject: [PATCH 17/18] we now actually drop --- .../implementation/items/tools/ExplosiveTool.java | 15 +++++++++++---- 1 file changed, 11 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 db990c64c9..9f71e881d9 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 @@ -6,6 +6,7 @@ import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; +import dev.lone.itemsadder.api.CustomBlock; import org.bukkit.Bukkit; import org.bukkit.Effect; import org.bukkit.Material; @@ -35,9 +36,9 @@ /** * This {@link SlimefunItem} is a super class for items like the {@link ExplosivePickaxe} or {@link ExplosiveShovel}. - * + * * @author TheBusyBiscuit - * + * * @see ExplosivePickaxe * @see ExplosiveShovel * @@ -83,6 +84,10 @@ private void breakBlocks(BlockBreakEvent e, Player p, ItemStack item, Block b, L if (!blockExplodeEvent.isCancelled()) { for (Block block : blockExplodeEvent.blockList()) { if (canBreak(p, block)) { + if (CustomBlock.byAlreadyPlaced(block) != null) { + drops.addAll(CustomBlock.byAlreadyPlaced(block).getLoot()); + CustomBlock.remove(block.getLocation()); + } blocksToDestroy.add(block); } } @@ -90,6 +95,10 @@ private void breakBlocks(BlockBreakEvent e, Player p, ItemStack item, Block b, L } else { for (Block block : blocks) { if (canBreak(p, block)) { + if (CustomBlock.byAlreadyPlaced(block) != null) { + drops.addAll(CustomBlock.byAlreadyPlaced(block).getLoot()); + CustomBlock.remove(block.getLocation()); + } blocksToDestroy.add(block); } } @@ -137,8 +146,6 @@ protected boolean canBreak(@Nonnull Player p, @Nonnull Block b) { return false; } else if (!b.getWorld().getWorldBorder().isInside(b.getLocation())) { return false; - } else if (Slimefun.getIntegrations().isCustomBlock(b)) { - return false; } else { return Slimefun.getProtectionManager().hasPermission(p, b.getLocation(), Interaction.BREAK_BLOCK); } From e032437b7154d2c1ed7f2d064dd2f16a9a8d379f Mon Sep 17 00:00:00 2001 From: Jeffrey Date: Mon, 4 Sep 2023 10:28:52 +0200 Subject: [PATCH 18/18] make use of the intergration manager --- .../slimefun4/implementation/items/tools/ExplosiveTool.java | 4 ++-- 1 file changed, 2 insertions(+), 2 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 9f71e881d9..6fe1174e4f 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 @@ -84,7 +84,7 @@ private void breakBlocks(BlockBreakEvent e, Player p, ItemStack item, Block b, L if (!blockExplodeEvent.isCancelled()) { for (Block block : blockExplodeEvent.blockList()) { if (canBreak(p, block)) { - if (CustomBlock.byAlreadyPlaced(block) != null) { + if (Slimefun.getIntegrations().isCustomBlock(block)) { drops.addAll(CustomBlock.byAlreadyPlaced(block).getLoot()); CustomBlock.remove(block.getLocation()); } @@ -95,7 +95,7 @@ private void breakBlocks(BlockBreakEvent e, Player p, ItemStack item, Block b, L } else { for (Block block : blocks) { if (canBreak(p, block)) { - if (CustomBlock.byAlreadyPlaced(block) != null) { + if (Slimefun.getIntegrations().isCustomBlock(block)) { drops.addAll(CustomBlock.byAlreadyPlaced(block).getLoot()); CustomBlock.remove(block.getLocation()); }