diff --git a/CHANGELOG.md b/CHANGELOG.md index ec080f206..5bf2b5b5b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -60,6 +60,8 @@ * Fixed #2205 * Fixed #2209 * Fixed #2217 +* Fixed Miner Talisman sending messages when drops were not even doubled +* Fixed #2077 ## Release Candidate 15 (01 Aug 2020) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/options/SlimefunGuideSettings.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/options/SlimefunGuideSettings.java index 07c3b6153..6f7840e5b 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/options/SlimefunGuideSettings.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/guide/options/SlimefunGuideSettings.java @@ -5,6 +5,7 @@ import java.util.List; import java.util.Optional; import org.bukkit.Bukkit; +import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.entity.Player; @@ -21,7 +22,6 @@ import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils; import io.github.thebusybiscuit.slimefun4.utils.NumberUtils; import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu; -import net.md_5.bungee.api.ChatColor; /** * This static utility class offers various methods that provide access to the diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java index 378efa246..8ec502809 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java @@ -11,6 +11,7 @@ import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; import org.bukkit.event.Event; import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockDropItemEvent; import org.bukkit.event.enchantment.EnchantItemEvent; import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.entity.EntityEvent; @@ -127,7 +128,7 @@ public class Talisman extends SlimefunItem { } private static boolean hasMessage(Talisman talisman) { - return !("").equalsIgnoreCase(talisman.getMessageSuffix()); + return talisman.getMessageSuffix() != null; } public static boolean checkFor(Event e, SlimefunItemStack stack) { @@ -224,6 +225,9 @@ public class Talisman extends SlimefunItem { else if (e instanceof BlockBreakEvent) { return ((BlockBreakEvent) e).getPlayer(); } + else if (e instanceof BlockDropItemEvent) { + return ((BlockDropItemEvent) e).getPlayer(); + } else if (e instanceof PlayerEvent) { return ((PlayerEvent) e).getPlayer(); } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/TalismanListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/TalismanListener.java index df00ffc64..8a41ff747 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/TalismanListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/TalismanListener.java @@ -13,13 +13,14 @@ import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.AbstractArrow; import org.bukkit.entity.ArmorStand; import org.bukkit.entity.ChestedHorse; +import org.bukkit.entity.Item; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.entity.Projectile; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; -import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockDropItemEvent; import org.bukkit.event.enchantment.EnchantItemEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; @@ -35,7 +36,6 @@ import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.util.Vector; import io.github.thebusybiscuit.cscorelib2.item.CustomItem; -import io.github.thebusybiscuit.cscorelib2.materials.MaterialCollections; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.implementation.items.magical.talismans.MagicianTalisman; @@ -229,32 +229,48 @@ public class TalismanListener implements Listener { } } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onBlockBreak(BlockBreakEvent e) { + @EventHandler(ignoreCancelled = true) + public void onBlockDropItems(BlockDropItemEvent e) { // We only want to double ores - if (MaterialCollections.getAllOres().contains(e.getBlock().getType())) { + Material type = e.getBlockState().getType(); + if (type.name().endsWith("_ORE")) { ItemStack item = e.getPlayer().getInventory().getItemInMainHand(); if (item.getType() != Material.AIR && item.getAmount() > 0 && !item.containsEnchantment(Enchantment.SILK_TOUCH)) { - Collection drops = e.getBlock().getDrops(item); - int dropAmount = 1; - - if (item.containsEnchantment(Enchantment.LOOT_BONUS_BLOCKS)) { - Random random = ThreadLocalRandom.current(); - dropAmount = random.nextInt(item.getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) + 2) - 1; - dropAmount = Math.max(dropAmount, 1); - dropAmount = (e.getBlock().getType() == Material.LAPIS_ORE ? 4 + random.nextInt(5) : 1) * (dropAmount + 1); - } + Collection drops = e.getItems(); if (Talisman.checkFor(e, SlimefunItems.TALISMAN_MINER)) { - for (ItemStack drop : drops) { - if (drop != null && !drop.getType().isBlock()) { - int amount = Math.max(1, (dropAmount * 2) - drop.getAmount()); - e.getBlock().getWorld().dropItemNaturally(e.getBlock().getLocation(), new CustomItem(drop, amount)); + int dropAmount = getAmountWithFortune(type, item.getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS)); + boolean doubledDrops = false; + + for (Item drop : drops) { + ItemStack droppedItem = drop.getItemStack(); + + if (!droppedItem.getType().isBlock()) { + int amount = Math.max(1, (dropAmount * 2) - droppedItem.getAmount()); + e.getBlock().getWorld().dropItemNaturally(e.getBlock().getLocation(), new CustomItem(droppedItem, amount)); + doubledDrops = true; } } + + if (doubledDrops) { + SlimefunPlugin.getLocalization().sendMessage(e.getPlayer(), "messages.talisman.miner", true); + } } } } } + + private int getAmountWithFortune(Material type, int fortuneLevel) { + if (fortuneLevel > 0) { + Random random = ThreadLocalRandom.current(); + int amount = random.nextInt(fortuneLevel + 2) - 1; + amount = Math.max(amount, 1); + amount = (type == Material.LAPIS_ORE ? 4 + random.nextInt(5) : 1) * (amount + 1); + return amount; + } + else { + return 1; + } + } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java index 60781232d..ccbaf67d6 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java @@ -818,7 +818,7 @@ public final class SlimefunItemSetup { new Talisman(SlimefunItems.TALISMAN_MINER, new ItemStack[] {SlimefunItems.MAGIC_LUMP_3, null, SlimefunItems.MAGIC_LUMP_3, SlimefunItems.SYNTHETIC_SAPPHIRE, SlimefunItems.COMMON_TALISMAN, SlimefunItems.SIFTED_ORE, SlimefunItems.MAGIC_LUMP_3, null, SlimefunItems.MAGIC_LUMP_3}, - false, false, "miner", 20) + false, false, null, 20) .register(plugin); new Talisman(SlimefunItems.TALISMAN_HUNTER,