diff --git a/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/EnderTalisman.java b/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/EnderTalisman.java index 8b48a09e6..5e6add098 100644 --- a/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/EnderTalisman.java +++ b/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/EnderTalisman.java @@ -7,27 +7,30 @@ import me.mrCookieSlime.Slimefun.api.Slimefun; import org.bukkit.inventory.ItemStack; import org.bukkit.potion.PotionEffect; +/** + * @since 4.0 + */ public class EnderTalisman extends SlimefunItem { - - boolean consumed; - boolean cancel; - PotionEffect[] effects; - String suffix; - int chance; + + private String suffix; + private boolean consumable; + private boolean cancel; + private PotionEffect[] effects; + private int chance; public EnderTalisman(Talisman parent) { super(Categories.TALISMANS_2, parent.upgrade(), "ENDER_" + parent.getID(), RecipeType.MAGIC_WORKBENCH, new ItemStack[] {SlimefunItem.getItem("ENDER_LUMP_3"), null, SlimefunItem.getItem("ENDER_LUMP_3"), null, parent.getItem(), null, SlimefunItem.getItem("ENDER_LUMP_3"), null, SlimefunItem.getItem("ENDER_LUMP_3")}, parent.upgrade()); - this.consumed = parent.isConsumable(); + this.consumable = parent.isConsumable(); this.cancel = parent.isEventCancelled(); this.suffix = parent.getSuffix(); this.effects = parent.getEffects(); this.chance = parent.getChance(); Slimefun.addHint("ENDER_" + parent.getID(), "&eEnder Talismans have the advantage", "&eof still working while they", "&eare in your Ender Chest"); } - - public PotionEffect[] getEffects() { return this.effects; } - public boolean isConsumable() { return this.consumed; } - public boolean isEventCancelled() { return this.cancel; } + public String getSuffix() { return this.suffix; } + public boolean isConsumable() { return this.consumable; } + public boolean isEventCancelled() { return this.cancel; } + public PotionEffect[] getEffects() { return this.effects; } public int getChance() { return this.chance; } } diff --git a/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/Talisman.java b/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/Talisman.java index 14d7b9e3c..34bbaba22 100644 --- a/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/Talisman.java +++ b/src/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/Talisman.java @@ -23,26 +23,28 @@ import org.bukkit.event.player.PlayerEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.potion.PotionEffect; +/** + * @since 4.0 + */ public class Talisman extends SlimefunItem { - - boolean consumed; - boolean cancel; - PotionEffect[] effects; - String suffix; - int chance; + + private String suffix; + private boolean consumable = true; + private boolean cancel = true; + private PotionEffect[] effects = new PotionEffect[0]; + private int chance = 100; public Talisman(ItemStack item, String id, ItemStack[] recipe, boolean consumable, boolean cancelEvent, String messageSuffix, PotionEffect... effects) { super(Categories.TALISMANS_1, item, id, RecipeType.MAGIC_WORKBENCH, recipe, new CustomItem(item, consumable ? 4: 1)); - this.consumed = consumable; + this.consumable = consumable; this.cancel = cancelEvent; this.suffix = messageSuffix; this.effects = effects; - this.chance = 100; } public Talisman(ItemStack item, String id, ItemStack[] recipe, boolean consumable, boolean cancelEvent, String messageSuffix, int chance, PotionEffect... effects) { super(Categories.TALISMANS_1, item, id, RecipeType.MAGIC_WORKBENCH, recipe, new CustomItem(item, consumable ? 4: 1)); - this.consumed = consumable; + this.consumable = consumable; this.cancel = cancelEvent; this.suffix = messageSuffix; this.effects = effects; @@ -51,23 +53,21 @@ public class Talisman extends SlimefunItem { public Talisman(ItemStack item, String id, ItemStack[] recipe, String messageSuffix, int chance, PotionEffect... effects) { super(Categories.TALISMANS_1, item, id, RecipeType.MAGIC_WORKBENCH, recipe, item); - this.consumed = true; - this.cancel = true; this.suffix = messageSuffix; this.effects = effects; this.chance = chance; } - - public PotionEffect[] getEffects() { return this.effects; } - public boolean isConsumable() { return this.consumed; } - public boolean isEventCancelled() { return this.cancel; } + public String getSuffix() { return this.suffix; } + public boolean isConsumable() { return this.consumable; } + public boolean isEventCancelled() { return this.cancel; } + public PotionEffect[] getEffects() { return this.effects; } public int getChance() { return this.chance; } public static boolean checkFor(Event e, SlimefunItem talisman) { if (talisman != null) { if (talisman instanceof Talisman) { - boolean message = ((Talisman) talisman).getSuffix().equalsIgnoreCase("") ? false: true; + boolean message = !((Talisman) talisman).getSuffix().equalsIgnoreCase(""); if (SlimefunStartup.chance(100, ((Talisman) talisman).getChance())) { Player p = null; @@ -80,7 +80,7 @@ public class Talisman extends SlimefunItem { boolean pass = true; for (PotionEffect effect: ((Talisman) talisman).getEffects()) { - if (effect != null) if (p.hasPotionEffect(effect.getType())) pass = false; + if (effect != null && p.hasPotionEffect(effect.getType())) pass = false; } if (pass) { diff --git a/src/me/mrCookieSlime/Slimefun/Setup/SlimefunSetup.java b/src/me/mrCookieSlime/Slimefun/Setup/SlimefunSetup.java index 0bfeb8031..1e72ba62a 100644 --- a/src/me/mrCookieSlime/Slimefun/Setup/SlimefunSetup.java +++ b/src/me/mrCookieSlime/Slimefun/Setup/SlimefunSetup.java @@ -1434,7 +1434,6 @@ public class SlimefunSetup { new SlimefunItem(Categories.TECH_MISC, SlimefunItems.SOLAR_PANEL, "SOLAR_PANEL", RecipeType.ENHANCED_CRAFTING_TABLE, new ItemStack[] {new ItemStack(Material.GLASS), new ItemStack(Material.GLASS), new ItemStack(Material.GLASS), SlimefunItems.SILICON, SlimefunItems.SILICON, SlimefunItems.SILICON, SlimefunItems.FERROSILICON, SlimefunItems.FERROSILICON, SlimefunItems.FERROSILICON}) - .register(true); new SolarHelmet(Categories.TECH, SlimefunItems.SOLAR_HELMET, "SOLAR_HELMET", RecipeType.ENHANCED_CRAFTING_TABLE, @@ -1460,10 +1459,11 @@ public class SlimefunSetup { if (e.getBlock().getType().equals(Material.SKULL)) return true; int j = -1; - for (int i = 0; i < e.getBlock().getDrops().size(); i++) { - if (((List) e.getBlock().getDrops()).get(i) != null) { + List dropsList = (List) e.getBlock().getDrops(); + for (int i = 0; i < dropsList.size(); i++) { + if (dropsList.get(i) != null) { j++; - drops.add(e.getBlock().getType().toString().endsWith("_ORE") ? new CustomItem(((List) e.getBlock().getDrops()).get(i), fortune): ((List) e.getBlock().getDrops()).get(i)); + drops.add(e.getBlock().getType().toString().endsWith("_ORE") ? new CustomItem(dropsList.get(i), fortune): dropsList.get(i)); if (RecipeCalculator.getSmeltedOutput(drops.get(i).getType()) != null) { e.getBlock().getWorld().playEffect(e.getBlock().getLocation(), Effect.MOBSPAWNER_FLAMES, 1); drops.set(j, new CustomItem(RecipeCalculator.getSmeltedOutput(drops.get(i).getType()), drops.get(i).getAmount())); diff --git a/src/me/mrCookieSlime/Slimefun/listeners/ItemPickupListener.java b/src/me/mrCookieSlime/Slimefun/listeners/ItemPickupListener.java index 224968e15..dd8336186 100644 --- a/src/me/mrCookieSlime/Slimefun/listeners/ItemPickupListener.java +++ b/src/me/mrCookieSlime/Slimefun/listeners/ItemPickupListener.java @@ -9,7 +9,7 @@ import org.bukkit.event.player.PlayerPickupItemEvent; /** * Listens to the ItemPickup events to prevent it if the item has the "no_pickup" metadata or is an ALTAR_PROBE. * - * @since 4.1.12 + * @since 4.1.11 */ public class ItemPickupListener implements Listener { diff --git a/src/me/mrCookieSlime/Slimefun/listeners/ItemPickupListener_1_12.java b/src/me/mrCookieSlime/Slimefun/listeners/ItemPickupListener_1_12.java index e74c6886d..644b3be05 100644 --- a/src/me/mrCookieSlime/Slimefun/listeners/ItemPickupListener_1_12.java +++ b/src/me/mrCookieSlime/Slimefun/listeners/ItemPickupListener_1_12.java @@ -11,7 +11,7 @@ import org.bukkit.event.inventory.InventoryPickupItemEvent; * * This Listener uses the new {@link EntityPickupItemEvent} due to the deprecation of {@link org.bukkit.event.player.PlayerPickupItemEvent}. * - * @since 4.1.12 + * @since 4.1.11 */ public class ItemPickupListener_1_12 implements Listener { diff --git a/src/me/mrCookieSlime/Slimefun/listeners/TalismanListener.java b/src/me/mrCookieSlime/Slimefun/listeners/TalismanListener.java index 7cc9eaa03..3ebfcfd6d 100644 --- a/src/me/mrCookieSlime/Slimefun/listeners/TalismanListener.java +++ b/src/me/mrCookieSlime/Slimefun/listeners/TalismanListener.java @@ -4,12 +4,14 @@ import java.util.ArrayList; import java.util.List; import java.util.Set; +import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Item.CustomItem; import me.mrCookieSlime.Slimefun.SlimefunStartup; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.Talisman; import me.mrCookieSlime.Slimefun.Setup.SlimefunManager; import me.mrCookieSlime.Slimefun.api.Slimefun; +import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.LivingEntity; @@ -18,12 +20,14 @@ 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.enchantment.EnchantItemEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.player.PlayerItemBreakEvent; import org.bukkit.event.player.PlayerToggleSprintEvent; +import org.bukkit.inventory.ItemStack; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import org.bukkit.util.Vector; @@ -103,4 +107,33 @@ public class TalismanListener implements Listener { } } } + + /** + * + * @param e BlockBreakEvent + * @since 4.2.0 + */ + @EventHandler + public void onBlockBreak(BlockBreakEvent e) { + List drops = new ArrayList(); + ItemStack item = e.getPlayer().getInventory().getItemInMainHand(); + int fortune = 1; + + if (item != null) { + if (item.getEnchantments().containsKey(Enchantment.LOOT_BONUS_BLOCKS) && !item.getEnchantments().containsKey(Enchantment.SILK_TOUCH)) { + fortune = SlimefunStartup.randomize(item.getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS) + 2) - 1; + if (fortune <= 0) fortune = 1; + fortune = (e.getBlock().getType() == Material.LAPIS_ORE ? 4 + SlimefunStartup.randomize(5) : 1) * (fortune + 1); + } + + if (!item.getEnchantments().containsKey(Enchantment.SILK_TOUCH) && e.getBlock().getType().toString().endsWith("_ORE")) { + if (Talisman.checkFor(e, SlimefunItem.getByID("MINER_TALISMAN"))) { + if (drops.isEmpty()) drops = (List) e.getBlock().getDrops(); + for (ItemStack drop : new ArrayList(drops)) { + if (!drop.getType().isBlock()) drops.add(new CustomItem(drop, fortune * 2)); + } + } + } + } + } } diff --git a/src/me/mrCookieSlime/Slimefun/listeners/ToolListener.java b/src/me/mrCookieSlime/Slimefun/listeners/ToolListener.java index 1e5e8b7be..5268aaeb5 100644 --- a/src/me/mrCookieSlime/Slimefun/listeners/ToolListener.java +++ b/src/me/mrCookieSlime/Slimefun/listeners/ToolListener.java @@ -216,15 +216,6 @@ public class ToolListener implements Listener { } } - if (!item.getEnchantments().containsKey(Enchantment.SILK_TOUCH) && e.getBlock().getType().toString().endsWith("_ORE")) { - if (Talisman.checkFor(e, SlimefunItem.getByName("MINER_TALISMAN"))) { - if (drops.isEmpty()) drops = (List) e.getBlock().getDrops(); - for (ItemStack drop: new ArrayList(drops)) { - if (!drop.getType().isBlock()) drops.add(new CustomItem(drop, fortune * 2)); - } - } - } - if (!drops.isEmpty()) { e.getBlock().setType(Material.AIR); for (ItemStack drop: drops) {