Improving Codestyle (3/?)

This commit is contained in:
Auxilor 2020-12-26 14:28:50 +00:00
parent 25d6231e44
commit 55fa3a21e2
11 changed files with 195 additions and 100 deletions

View File

@ -9,6 +9,7 @@ import com.willfp.ecoenchants.display.options.DisplayOptions;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget;
import lombok.experimental.UtilityClass;
import org.bukkit.NamespacedKey;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemFlag;
@ -16,6 +17,7 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.HashMap;
@ -26,8 +28,9 @@ import java.util.List;
* All methods and fields pertaining to showing players the enchantments on their items.
*/
@SuppressWarnings("DeprecatedIsStillUsed")
@UtilityClass
public class EnchantDisplay implements Updatable {
private static final AbstractEcoPlugin plugin = AbstractEcoPlugin.getInstance();
private static final AbstractEcoPlugin PLUGIN = AbstractEcoPlugin.getInstance();
/**
* The meta key to hide enchantments in lore
@ -38,14 +41,14 @@ public class EnchantDisplay implements Updatable {
* @deprecated Temporary fix
*/
@Deprecated
public static final NamespacedKey KEY_SKIP = plugin.getNamespacedKeyFactory().create("ecoenchantlore-skip");
public static final NamespacedKey KEY_SKIP = PLUGIN.getNamespacedKeyFactory().create("ecoenchantlore-skip");
/**
* The meta key to notify the server that an item is from a villager trade
* <p>
* Bit of a bodge - plan on making it better.
*/
public static final NamespacedKey KEY_V = plugin.getNamespacedKeyFactory().create("ecoenchantlore-v");
public static final NamespacedKey KEY_V = PLUGIN.getNamespacedKeyFactory().create("ecoenchantlore-v");
/**
* The prefix for all enchantment lines to have in lore
@ -75,8 +78,10 @@ public class EnchantDisplay implements Updatable {
*
* @return The item, with KEY_V
*/
public static ItemStack addV(ItemStack item) {
if (item == null || item.getItemMeta() == null) return item;
public static ItemStack addV(@Nullable final ItemStack item) {
if (item == null || item.getItemMeta() == null) {
return item;
}
ItemMeta meta = item.getItemMeta();
meta.getPersistentDataContainer().set(KEY_V, PersistentDataType.INTEGER, 1);
@ -91,28 +96,33 @@ public class EnchantDisplay implements Updatable {
*
* @return The item, updated
*/
public static ItemStack revertDisplay(final ItemStack item) {
if (item == null || !EnchantmentTarget.ALL.getMaterials().contains(item.getType()) || item.getItemMeta() == null)
public static ItemStack revertDisplay(@Nullable final ItemStack item) {
if (item == null || !EnchantmentTarget.ALL.getMaterials().contains(item.getType()) || item.getItemMeta() == null) {
return item;
}
ItemMeta meta = item.getItemMeta();
List<String> itemLore;
if (meta.hasLore())
if (meta.hasLore()) {
itemLore = meta.getLore();
else
} else {
itemLore = new ArrayList<>();
}
if (itemLore == null) itemLore = new ArrayList<>();
if (itemLore == null) {
itemLore = new ArrayList<>();
}
if (meta.getPersistentDataContainer().has(KEY_V, PersistentDataType.INTEGER)) {
meta.getPersistentDataContainer().remove(KEY_V);
}
itemLore.removeIf((s) -> s.startsWith(PREFIX));
itemLore.removeIf(s -> s.startsWith(PREFIX));
if (!meta.getPersistentDataContainer().has(KEY_SKIP, PersistentDataType.INTEGER)) {
if (meta instanceof EnchantmentStorageMeta)
if (meta instanceof EnchantmentStorageMeta) {
meta.removeItemFlags(ItemFlag.HIDE_POTION_EFFECTS); // Thanks ShaneBee!
}
meta.removeItemFlags(ItemFlag.HIDE_ENCHANTS);
}
meta.getPersistentDataContainer().remove(KEY_SKIP);
@ -122,7 +132,7 @@ public class EnchantDisplay implements Updatable {
return item;
}
public static ItemStack displayEnchantments(final ItemStack item) {
public static ItemStack displayEnchantments(@Nullable final ItemStack item) {
return displayEnchantments(item, false);
}
@ -133,21 +143,27 @@ public class EnchantDisplay implements Updatable {
*
* @return The item, updated
*/
public static ItemStack displayEnchantments(final ItemStack item, boolean hideEnchants) {
if (item == null || item.getItemMeta() == null || !EnchantmentTarget.ALL.getMaterials().contains(item.getType()))
public static ItemStack displayEnchantments(@Nullable final ItemStack item,
final boolean hideEnchants) {
boolean hide = hideEnchants;
if (item == null || item.getItemMeta() == null || !EnchantmentTarget.ALL.getMaterials().contains(item.getType())) {
return item;
}
if (item.getItemMeta().getPersistentDataContainer().has(KEY_V, PersistentDataType.INTEGER) && hideEnchants) {
hideEnchants = false;
hide = false;
}
revertDisplay(item);
ItemMeta meta = item.getItemMeta();
if (meta == null) return item;
if (meta == null) {
return item;
}
List<String> itemLore = new ArrayList<>();
if (hideEnchants || meta.getPersistentDataContainer().has(KEY_SKIP, PersistentDataType.INTEGER)) {
if (hide || meta.getPersistentDataContainer().has(KEY_SKIP, PersistentDataType.INTEGER)) {
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
meta.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS);
meta.getPersistentDataContainer().set(KEY_SKIP, PersistentDataType.INTEGER, 1);
@ -155,10 +171,13 @@ public class EnchantDisplay implements Updatable {
return item;
}
if (meta.hasLore())
if (meta.hasLore()) {
itemLore = meta.getLore();
}
if (itemLore == null) itemLore = new ArrayList<>();
if (itemLore == null) {
itemLore = new ArrayList<>();
}
List<String> lore = new ArrayList<>();
@ -174,9 +193,7 @@ public class EnchantDisplay implements Updatable {
enchantments.entrySet().removeIf(enchantmentIntegerEntry -> enchantmentIntegerEntry.getValue().equals(0));
List<Enchantment> unsorted = new ArrayList<>();
enchantments.forEach((enchantment, integer) -> {
unsorted.add(enchantment);
});
enchantments.forEach((enchantment, integer) -> unsorted.add(enchantment));
HashMap<Enchantment, Integer> tempEnchantments = new HashMap<>(enchantments);
@ -188,12 +205,15 @@ public class EnchantDisplay implements Updatable {
});
enchantments.forEach((enchantment, level) -> {
if (EcoEnchants.getFromEnchantment(enchantment) == null) return;
if (EcoEnchants.getFromEnchantment(enchantment) == null) {
return;
}
EcoEnchant ecoEnchant = EcoEnchants.getFromEnchantment(enchantment);
if (!ecoEnchant.isEnabled())
if (!ecoEnchant.isEnabled()) {
forRemoval.add(enchantment);
}
});
forRemoval.forEach(enchantment -> {
@ -217,8 +237,9 @@ public class EnchantDisplay implements Updatable {
}
lore.add(PREFIX + name);
if (enchantments.size() <= OPTIONS.getDescribeThreshold() && OPTIONS.isUseDescribe())
if (enchantments.size() <= OPTIONS.getDescribeThreshold() && OPTIONS.isUseDescribe()) {
lore.addAll(EnchantmentCache.getEntry(enchantment).getDescription());
}
});
if (OPTIONS.isUseShrink() && (enchantments.size() > OPTIONS.getShrinkThreshold())) {

View File

@ -227,6 +227,7 @@ import com.willfp.ecoenchants.enchantments.ecoenchants.spell.Missile;
import com.willfp.ecoenchants.enchantments.ecoenchants.spell.Quake;
import com.willfp.ecoenchants.enchantments.ecoenchants.spell.Vitalize;
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
import lombok.experimental.UtilityClass;
import org.bukkit.NamespacedKey;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
@ -242,7 +243,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
* Contains general methods for EcoEnchants
*/
@SuppressWarnings("unused")
public class EcoEnchants implements Updatable {
public final class EcoEnchants implements Updatable {
public static final String CONFIG_LOCATION = "config.";
public static final String OBTAINING_LOCATION = "obtaining.";
public static final String GENERAL_LOCATION = "general-config.";

View File

@ -13,4 +13,4 @@ public class EmeraldArtifact extends Artifact {
public Particle getParticle() {
return Particle.COMPOSTER;
}
}
}

View File

@ -6,6 +6,7 @@ import org.bukkit.entity.Arrow;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Tameable;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.jetbrains.annotations.NotNull;
public class Defender extends EcoEnchant {
public Defender() {
@ -18,13 +19,23 @@ public class Defender extends EcoEnchant {
@Override
public void onArrowDamage(LivingEntity attacker, LivingEntity victim, Arrow arrow, int level, EntityDamageByEntityEvent event) {
if(!(victim instanceof Tameable)) return;
public void onArrowDamage(@NotNull final LivingEntity attacker,
@NotNull final LivingEntity victim,
@NotNull final Arrow arrow,
final int level,
@NotNull final EntityDamageByEntityEvent event) {
if (!(victim instanceof Tameable)) {
return;
}
Tameable pet = (Tameable) victim;
if(pet.getOwner() == null) return;
if(!pet.getOwner().equals(attacker)) return;
if (pet.getOwner() == null) {
return;
}
if (!pet.getOwner().equals(attacker)) {
return;
}
event.setCancelled(true);
}

View File

@ -64,4 +64,4 @@ public class Drill extends EcoEnchant {
AnticheatManager.unexemptPlayer(player);
}
}
}

View File

@ -19,11 +19,15 @@ public class Economical extends EcoEnchant {
@EventHandler
public void onElytraBoost(@NotNull final PlayerElytraBoostEvent event) {
if(!EnchantChecks.chestplate(event.getPlayer(), this))
if (!EnchantChecks.chestplate(event.getPlayer(), this)) {
return;
if(!EnchantmentUtils.passedChance(this, EnchantChecks.getArmorPoints(event.getPlayer(), this)))
}
if (!EnchantmentUtils.passedChance(this, EnchantChecks.getArmorPoints(event.getPlayer(), this))) {
return;
if(this.getDisabledWorlds().contains(event.getPlayer().getWorld())) return;
}
if (this.getDisabledWorlds().contains(event.getPlayer().getWorld())) {
return;
}
event.setShouldConsume(false);
}
}

View File

@ -28,26 +28,26 @@ import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
public class EnchantingListeners extends PluginDependent implements Listener {
private static final Set<Material> secondary = new ImmutableSet.Builder<Material>()
private static final Set<Material> SECONDARY_ENCHANTABLE = new ImmutableSet.Builder<Material>()
.add(Material.ELYTRA)
.add(Material.SHIELD)
.add(Material.FLINT_AND_STEEL)
.add(Material.SHEARS)
.add(Material.CARROT_ON_A_STICK).build();
public static final Map<Player, int[]> currentlyEnchantingSecondary = new HashMap<>();
public static final Map<Player, int[]> CURRENTLY_ENCHANTING_SECONDARY = new HashMap<>();
public EnchantingListeners(AbstractEcoPlugin plugin) {
public EnchantingListeners(@NotNull final AbstractEcoPlugin plugin) {
super(plugin);
}
@EventHandler
public void onPlayerLeave(PlayerQuitEvent event) {
currentlyEnchantingSecondary.remove(event.getPlayer());
public void onPlayerLeave(@NotNull final PlayerQuitEvent event) {
CURRENTLY_ENCHANTING_SECONDARY.remove(event.getPlayer());
}
@EventHandler
public void enchantItem(EnchantItemEvent event) {
public void enchantItem(@NotNull final EnchantItemEvent event) {
Player player = event.getEnchanter();
ItemStack item = event.getItem();
int cost = event.getExpLevelCost();
@ -62,7 +62,7 @@ public class EnchantingListeners extends PluginDependent implements Listener {
return;
}
if ((secondary.contains(event.getItem().getType()))) {
if (SECONDARY_ENCHANTABLE.contains(event.getItem().getType())) {
try {
ItemStack lapis = event.getInventory().getItem(1);
lapis.setAmount(event.getInventory().getItem(1).getAmount() - (event.whichButton() + 1));
@ -144,9 +144,9 @@ public class EnchantingListeners extends PluginDependent implements Listener {
}
toAdd.forEach(event.getEnchantsToAdd()::putIfAbsent);
if (secondary.contains(event.getItem().getType()) && !toAdd.containsKey(EcoEnchants.INDESTRUCTIBILITY)) {
event.getEnchantsToAdd().put(Enchantment.DURABILITY, currentlyEnchantingSecondary.get(player)[event.whichButton()]);
currentlyEnchantingSecondary.remove(player);
if (SECONDARY_ENCHANTABLE.contains(event.getItem().getType()) && !toAdd.containsKey(EcoEnchants.INDESTRUCTIBILITY)) {
event.getEnchantsToAdd().put(Enchantment.DURABILITY, CURRENTLY_ENCHANTING_SECONDARY.get(player)[event.whichButton()]);
CURRENTLY_ENCHANTING_SECONDARY.remove(player);
}
if (gotSpecial && Configs.CONFIG.getBool("enchanting-table.notify-on-special")) {
@ -180,7 +180,7 @@ public class EnchantingListeners extends PluginDependent implements Listener {
} catch (ArrayIndexOutOfBoundsException | NullPointerException ignored) {
}
if (!secondary.contains(event.getItem().getType()))
if (!SECONDARY_ENCHANTABLE.contains(event.getItem().getType()))
return;
int bonus = event.getEnchantmentBonus();
@ -221,7 +221,7 @@ public class EnchantingListeners extends PluginDependent implements Listener {
event.getOffers()[i] = offers[i];
}
currentlyEnchantingSecondary.remove(event.getEnchanter());
CURRENTLY_ENCHANTING_SECONDARY.remove(event.getEnchanter());
int[] unbLevels = {
event.getOffers()[0].getEnchantmentLevel(),
@ -229,6 +229,6 @@ public class EnchantingListeners extends PluginDependent implements Listener {
event.getOffers()[2].getEnchantmentLevel()
};
currentlyEnchantingSecondary.put(event.getEnchanter(), unbLevels);
CURRENTLY_ENCHANTING_SECONDARY.put(event.getEnchanter(), unbLevels);
}
}

View File

@ -6,6 +6,7 @@ import com.willfp.eco.util.DurabilityUtils;
import com.willfp.eco.util.ProxyUtils;
import com.willfp.ecoenchants.enchantments.EcoEnchant;
import com.willfp.ecoenchants.enchantments.EcoEnchants;
import lombok.experimental.UtilityClass;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Arrow;
@ -13,6 +14,8 @@ import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.MetadataValue;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
import java.util.HashMap;
@ -24,6 +27,7 @@ import java.util.concurrent.atomic.AtomicInteger;
* Utility class to simplify enchantment fetching
*/
@SuppressWarnings("unchecked")
@UtilityClass
public class EnchantChecks {
private static final FastGetEnchantsProxy PROXY = ProxyUtils.getProxy(FastGetEnchantsProxy.class);
@ -35,7 +39,8 @@ public class EnchantChecks {
*
* @return If the item has the queried enchantment
*/
public static boolean item(ItemStack item, Enchantment enchantment) {
public static boolean item(@Nullable final ItemStack item,
@NotNull final Enchantment enchantment) {
return getItemLevel(item, enchantment) != 0;
}
@ -47,9 +52,14 @@ public class EnchantChecks {
*
* @return The level of the enchantment, or 0 if not found
*/
public static int getItemLevel(ItemStack item, Enchantment enchantment) {
if (item == null) return 0;
if (item.getType().equals(Material.AIR)) return 0;
public static int getItemLevel(@Nullable final ItemStack item,
@NotNull final Enchantment enchantment) {
if (item == null) {
return 0;
}
if (item.getType().equals(Material.AIR)) {
return 0;
}
return PROXY.getLevelOnItem(item, enchantment);
}
@ -61,14 +71,20 @@ public class EnchantChecks {
*
* @return A {@link HashMap} of all EcoEnchants, where the key represents the level
*/
public static Map<EcoEnchant, Integer> getEnchantsOnItem(ItemStack item) {
if (item == null) return new HashMap<>();
if (item.getType().equals(Material.AIR)) return new HashMap<>();
public static Map<EcoEnchant, Integer> getEnchantsOnItem(@Nullable final ItemStack item) {
if (item == null) {
return new HashMap<>();
}
if (item.getType().equals(Material.AIR)) {
return new HashMap<>();
}
Map<EcoEnchant, Integer> ecoEnchants = new HashMap<>();
for (Map.Entry<Enchantment, Integer> enchantmentIntegerEntry : PROXY.getEnchantmentsOnItem(item).entrySet()) {
EcoEnchant enchant = EcoEnchants.getFromEnchantment(enchantmentIntegerEntry.getKey());
if(enchant != null) ecoEnchants.put(enchant, enchantmentIntegerEntry.getValue());
if (enchant != null) {
ecoEnchants.put(enchant, enchantmentIntegerEntry.getValue());
}
}
return ecoEnchants;
@ -84,7 +100,8 @@ public class EnchantChecks {
*
* @return If the arrow has the queried enchantment
*/
public static boolean arrow(Arrow arrow, Enchantment enchantment) {
public static boolean arrow(@NotNull final Arrow arrow,
@NotNull final Enchantment enchantment) {
return getArrowLevel(arrow, enchantment) != 0;
}
@ -98,16 +115,24 @@ public class EnchantChecks {
*
* @return The level found on the arrow, or 0 if not found
*/
public static int getArrowLevel(Arrow arrow, Enchantment enchantment) {
if (arrow.getMetadata("enchantments").isEmpty()) return 0;
public static int getArrowLevel(@NotNull final Arrow arrow,
@NotNull final Enchantment enchantment) {
if (arrow.getMetadata("enchantments").isEmpty()) {
return 0;
}
MetadataValue enchantmentsMetaValue = arrow.getMetadata("enchantments").get(0);
if (!(enchantmentsMetaValue.value() instanceof Map))
if (!(enchantmentsMetaValue.value() instanceof Map)) {
return 0;
}
Map<Enchantment, Integer> enchantments = (Map<Enchantment, Integer>) enchantmentsMetaValue.value();
if (enchantments == null) return 0;
if (!enchantments.containsKey(enchantment)) return 0;
if (enchantments == null) {
return 0;
}
if (!enchantments.containsKey(enchantment)) {
return 0;
}
return enchantments.get(enchantment);
}
@ -118,12 +143,15 @@ public class EnchantChecks {
*
* @return A {@link HashMap} of all EcoEnchants, where the key represents the level
*/
public static Map<EcoEnchant, Integer> getEnchantsOnArrow(Arrow arrow) {
if (arrow.getMetadata("enchantments").isEmpty()) return new HashMap<>();
public static Map<EcoEnchant, Integer> getEnchantsOnArrow(@NotNull final Arrow arrow) {
if (arrow.getMetadata("enchantments").isEmpty()) {
return new HashMap<>();
}
MetadataValue enchantmentsMetaValue = arrow.getMetadata("enchantments").get(0);
if (!(enchantmentsMetaValue.value() instanceof Map))
if (!(enchantmentsMetaValue.value() instanceof Map)) {
return new HashMap<>();
}
Map<EcoEnchant, Integer> ecoEnchants = new HashMap<>();
((Map<Enchantment, Integer>) enchantmentsMetaValue.value()).forEach(((enchantment, integer) -> {
@ -143,7 +171,8 @@ public class EnchantChecks {
*
* @return If the LivingEntity has the enchantment
*/
public static boolean mainhand(LivingEntity entity, Enchantment enchantment) {
public static boolean mainhand(@NotNull final LivingEntity entity,
@NotNull final Enchantment enchantment) {
return getMainhandLevel(entity, enchantment) != 0;
}
@ -155,9 +184,11 @@ public class EnchantChecks {
*
* @return The level found on the mainhand item, or 0 if not found
*/
public static int getMainhandLevel(LivingEntity entity, Enchantment enchantment) {
if (entity.getEquipment() == null)
public static int getMainhandLevel(@NotNull final LivingEntity entity,
@NotNull final Enchantment enchantment) {
if (entity.getEquipment() == null) {
return 0;
}
ItemStack item = entity.getEquipment().getItemInMainHand();
@ -171,9 +202,10 @@ public class EnchantChecks {
*
* @return A {@link HashMap} of all EcoEnchants, where the key represents the level
*/
public static Map<EcoEnchant, Integer> getEnchantsOnMainhand(LivingEntity entity) {
if (entity.getEquipment() == null)
public static Map<EcoEnchant, Integer> getEnchantsOnMainhand(@NotNull final LivingEntity entity) {
if (entity.getEquipment() == null) {
return new HashMap<>();
}
ItemStack item = entity.getEquipment().getItemInMainHand();
@ -188,7 +220,8 @@ public class EnchantChecks {
*
* @return If the LivingEntity has the enchantment
*/
public static boolean offhand(LivingEntity entity, Enchantment enchantment) {
public static boolean offhand(@NotNull final LivingEntity entity,
@NotNull final Enchantment enchantment) {
return getOffhandLevel(entity, enchantment) != 0;
}
@ -200,9 +233,11 @@ public class EnchantChecks {
*
* @return The level found on the offhand item, or 0 if not found
*/
public static int getOffhandLevel(LivingEntity entity, Enchantment enchantment) {
if (entity.getEquipment() == null)
public static int getOffhandLevel(@NotNull final LivingEntity entity,
@NotNull final Enchantment enchantment) {
if (entity.getEquipment() == null) {
return 0;
}
ItemStack item = entity.getEquipment().getItemInOffHand();
@ -216,9 +251,10 @@ public class EnchantChecks {
*
* @return A {@link HashMap} of all EcoEnchants, where the key represents the level
*/
public static Map<EcoEnchant, Integer> getEnchantsOnOffhand(LivingEntity entity) {
if (entity.getEquipment() == null)
public static Map<EcoEnchant, Integer> getEnchantsOnOffhand(@NotNull final LivingEntity entity) {
if (entity.getEquipment() == null) {
return new HashMap<>();
}
ItemStack item = entity.getEquipment().getItemInOffHand();
@ -233,7 +269,8 @@ public class EnchantChecks {
*
* @return The cumulative total of all levels, ie 4 pieces all with level 3 returns 12
*/
public static int getArmorPoints(LivingEntity entity, Enchantment enchantment) {
public static int getArmorPoints(@NotNull final LivingEntity entity,
@NotNull final Enchantment enchantment) {
return getArmorPoints(entity, enchantment, 0);
}
@ -248,9 +285,12 @@ public class EnchantChecks {
*
* @return The cumulative total of all levels, ie 4 pieces all with level 3 returns 12
*/
public static int getArmorPoints(LivingEntity entity, Enchantment enchantment, int damage) {
if (entity.getEquipment() == null)
public static int getArmorPoints(@NotNull final LivingEntity entity,
@NotNull final Enchantment enchantment,
final int damage) {
if (entity.getEquipment() == null) {
return 0;
}
boolean isPlayer = entity instanceof Player;
@ -288,9 +328,10 @@ public class EnchantChecks {
*
* @return A {@link HashMap} of all EcoEnchants, where the key represents the cumulative total levels
*/
public static Map<EcoEnchant, Integer> getEnchantsOnArmor(LivingEntity entity) {
if (entity.getEquipment() == null)
public static Map<EcoEnchant, Integer> getEnchantsOnArmor(@NotNull final LivingEntity entity) {
if (entity.getEquipment() == null) {
return new HashMap<>();
}
List<ItemStack> armor = Arrays.asList(entity.getEquipment().getArmorContents());
@ -311,7 +352,8 @@ public class EnchantChecks {
*
* @return If the LivingEntity has the enchantment
*/
public static boolean helmet(LivingEntity entity, Enchantment enchantment) {
public static boolean helmet(@NotNull final LivingEntity entity,
@NotNull final Enchantment enchantment) {
return getHelmetLevel(entity, enchantment) != 0;
}
@ -323,9 +365,11 @@ public class EnchantChecks {
*
* @return The level found, or 0 if not found
*/
public static int getHelmetLevel(LivingEntity entity, Enchantment enchantment) {
if (entity.getEquipment() == null)
public static int getHelmetLevel(@NotNull final LivingEntity entity,
@NotNull final Enchantment enchantment) {
if (entity.getEquipment() == null) {
return 0;
}
ItemStack item = entity.getEquipment().getHelmet();
@ -340,7 +384,8 @@ public class EnchantChecks {
*
* @return If the LivingEntity has the enchantment
*/
public static boolean chestplate(LivingEntity entity, Enchantment enchantment) {
public static boolean chestplate(@NotNull final LivingEntity entity,
@NotNull final Enchantment enchantment) {
return getChestplateLevel(entity, enchantment) != 0;
}
@ -352,9 +397,11 @@ public class EnchantChecks {
*
* @return The level found, or 0 if not found
*/
public static int getChestplateLevel(LivingEntity entity, Enchantment enchantment) {
if (entity.getEquipment() == null)
public static int getChestplateLevel(@NotNull final LivingEntity entity,
@NotNull final Enchantment enchantment) {
if (entity.getEquipment() == null) {
return 0;
}
ItemStack item = entity.getEquipment().getChestplate();
@ -369,7 +416,8 @@ public class EnchantChecks {
*
* @return If the LivingEntity has the enchantment
*/
public static boolean leggings(LivingEntity entity, Enchantment enchantment) {
public static boolean leggings(@NotNull final LivingEntity entity,
@NotNull final Enchantment enchantment) {
return getLeggingsLevel(entity, enchantment) != 0;
}
@ -381,9 +429,11 @@ public class EnchantChecks {
*
* @return The level found, or 0 if not found
*/
public static int getLeggingsLevel(LivingEntity entity, Enchantment enchantment) {
if (entity.getEquipment() == null)
public static int getLeggingsLevel(@NotNull final LivingEntity entity,
@NotNull final Enchantment enchantment) {
if (entity.getEquipment() == null) {
return 0;
}
ItemStack item = entity.getEquipment().getLeggings();
@ -398,7 +448,8 @@ public class EnchantChecks {
*
* @return If the LivingEntity has the enchantment
*/
public static boolean boots(LivingEntity entity, Enchantment enchantment) {
public static boolean boots(@NotNull final LivingEntity entity,
@NotNull final Enchantment enchantment) {
return getBootsLevel(entity, enchantment) != 0;
}
@ -410,12 +461,14 @@ public class EnchantChecks {
*
* @return The level found, or 0 if not found
*/
public static int getBootsLevel(LivingEntity entity, Enchantment enchantment) {
if (entity.getEquipment() == null)
public static int getBootsLevel(@NotNull final LivingEntity entity,
@NotNull final Enchantment enchantment) {
if (entity.getEquipment() == null) {
return 0;
}
ItemStack item = entity.getEquipment().getBoots();
return getItemLevel(item, enchantment);
}
}
}

View File

@ -14,7 +14,7 @@ public class Elevation extends BiomesEnchantment {
}
@Override
public boolean isValid(@NotNull Biome biome) {
public boolean isValid(@NotNull final Biome biome) {
return Arrays.stream(new String[]{"mountain", "hill"}).anyMatch(biome.name().toLowerCase()::contains);
}
}

View File

@ -10,16 +10,19 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.jetbrains.annotations.NotNull;
public abstract class EffectsEnchantment extends EcoEnchant {
protected EffectsEnchantment(String key, EnchantmentType type, Prerequisite... prerequisites) {
protected EffectsEnchantment(@NotNull final String key,
@NotNull final EnchantmentType type,
@NotNull final Prerequisite... prerequisites) {
super(key, type, prerequisites);
}
public abstract PotionEffectType getPotionEffect();
@EventHandler
public void onEquip(ArmorEquipEvent event) {
public void onEquip(@NotNull final ArmorEquipEvent event) {
final Player player = event.getPlayer();
this.getPlugin().getScheduler().runLater(() -> {
@ -28,8 +31,10 @@ public abstract class EffectsEnchantment extends EcoEnchant {
}
int level = EnchantChecks.getArmorPoints(player, this);
if(this.getDisabledWorlds().contains(player.getWorld())) return;
if(level > 0) {
if (this.getDisabledWorlds().contains(player.getWorld())) {
return;
}
if (level > 0) {
player.addPotionEffect(new PotionEffect(this.getPotionEffect(), 0x6fffffff, level - 1, false, false, true));
}
}, 1);

View File

@ -238,4 +238,4 @@ public class ArmorListener implements Listener {
public static boolean isAirOrNull(@Nullable final ItemStack item) {
return item == null || item.getType().equals(Material.AIR);
}
}
}