Add missing null check, cache Random
This commit is contained in:
		@@ -25,6 +25,7 @@ import java.util.Random;
 | 
				
			|||||||
public class EventHandlers implements Listener
 | 
					public class EventHandlers implements Listener
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    private final ArmoredElytra plugin;
 | 
					    private final ArmoredElytra plugin;
 | 
				
			||||||
 | 
					    private final Random random = new Random();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public EventHandlers(ArmoredElytra plugin)
 | 
					    public EventHandlers(ArmoredElytra plugin)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
@@ -96,8 +97,7 @@ public class EventHandlers implements Listener
 | 
				
			|||||||
                {
 | 
					                {
 | 
				
			||||||
                    // Get a random int between 0 and 100 to use in deciding if the durability
 | 
					                    // Get a random int between 0 and 100 to use in deciding if the durability
 | 
				
			||||||
                    // enchantment will take effect.
 | 
					                    // enchantment will take effect.
 | 
				
			||||||
                    Random r = new Random();
 | 
					                    int randomInt = random.nextInt(101);
 | 
				
			||||||
                    int randomInt = r.nextInt(101);
 | 
					 | 
				
			||||||
                    int enchantLevel = p.getInventory().getChestplate().getEnchantmentLevel(Enchantment.DURABILITY);
 | 
					                    int enchantLevel = p.getInventory().getChestplate().getEnchantmentLevel(Enchantment.DURABILITY);
 | 
				
			||||||
                    int durabilityDelta = (100 / (enchantLevel + 1)) < randomInt ? 0 : 1;
 | 
					                    int durabilityDelta = (100 / (enchantLevel + 1)) < randomInt ? 0 : 1;
 | 
				
			||||||
                    // If the durability equals/exceeds maxDurability, it's broken (0 = full item
 | 
					                    // If the durability equals/exceeds maxDurability, it's broken (0 = full item
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -109,7 +109,7 @@ abstract class SmithingTableListener extends ArmoredElytraHandler implements Lis
 | 
				
			|||||||
            return false;
 | 
					            return false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        final ItemStack result = smithingInventory.getItem(2);
 | 
					        final ItemStack result = smithingInventory.getItem(2);
 | 
				
			||||||
        if (result.getType() != Material.ELYTRA ||
 | 
					        if (result == null || result.getType() != Material.ELYTRA ||
 | 
				
			||||||
            ArmoredElytra.getInstance().getNbtEditor().getArmorTier(result) == ArmorTier.NONE)
 | 
					            ArmoredElytra.getInstance().getNbtEditor().getArmorTier(result) == ArmorTier.NONE)
 | 
				
			||||||
            return false;
 | 
					            return false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user