mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-20 11:45:51 +00:00
Merge pull request #529 from Poslovitch/smelters-fix
Fix NPE on BlockBreakEvent with Smelter's Pickaxe
This commit is contained in:
commit
f9e7c3cae6
@ -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; }
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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<ItemStack>) e.getBlock().getDrops()).get(i) != null) {
|
||||
List<ItemStack> dropsList = (List<ItemStack>) 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<ItemStack>) e.getBlock().getDrops()).get(i), fortune): ((List<ItemStack>) 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()));
|
||||
|
@ -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 {
|
||||
|
||||
|
@ -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 {
|
||||
|
||||
|
@ -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<ItemStack> drops = new ArrayList<ItemStack>();
|
||||
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<ItemStack>) e.getBlock().getDrops();
|
||||
for (ItemStack drop : new ArrayList<ItemStack>(drops)) {
|
||||
if (!drop.getType().isBlock()) drops.add(new CustomItem(drop, fortune * 2));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<ItemStack>) e.getBlock().getDrops();
|
||||
for (ItemStack drop: new ArrayList<ItemStack>(drops)) {
|
||||
if (!drop.getType().isBlock()) drops.add(new CustomItem(drop, fortune * 2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!drops.isEmpty()) {
|
||||
e.getBlock().setType(Material.AIR);
|
||||
for (ItemStack drop: drops) {
|
||||
|
Loading…
Reference in New Issue
Block a user