Add missing null check, cache Random

This commit is contained in:
Pim van der Loos 2021-05-20 16:56:40 +02:00
parent 8f1a8baf76
commit 7ed7236450
No known key found for this signature in database
GPG Key ID: C16F020ADAE6D5A8
2 changed files with 3 additions and 3 deletions

View File

@ -25,6 +25,7 @@ import java.util.Random;
public class EventHandlers implements Listener
{
private final ArmoredElytra plugin;
private final Random random = new Random();
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
// enchantment will take effect.
Random r = new Random();
int randomInt = r.nextInt(101);
int randomInt = random.nextInt(101);
int enchantLevel = p.getInventory().getChestplate().getEnchantmentLevel(Enchantment.DURABILITY);
int durabilityDelta = (100 / (enchantLevel + 1)) < randomInt ? 0 : 1;
// If the durability equals/exceeds maxDurability, it's broken (0 = full item

View File

@ -109,7 +109,7 @@ abstract class SmithingTableListener extends ArmoredElytraHandler implements Lis
return false;
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)
return false;