mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2025-02-28 06:31:43 +01:00
Expanded javadoc
This commit is contained in:
parent
61106312b6
commit
c4df03884b
@ -20,6 +20,7 @@ import org.bukkit.event.Listener;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.permissions.Permission;
|
import org.bukkit.permissions.Permission;
|
||||||
import org.bukkit.permissions.PermissionDefault;
|
import org.bukkit.permissions.PermissionDefault;
|
||||||
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
@ -53,10 +54,27 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Regist
|
|||||||
|
|
||||||
private boolean enabled;
|
private boolean enabled;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new EcoEnchant that exists within the base plugin
|
||||||
|
*
|
||||||
|
* @param key The key name of the enchantment
|
||||||
|
* @param type The type of the enchantment
|
||||||
|
* @param prerequisites Optional {@link Prerequisite}s that must be met
|
||||||
|
*/
|
||||||
|
@ApiStatus.Internal
|
||||||
protected EcoEnchant(String key, EcoEnchant.EnchantmentType type, Prerequisite... prerequisites) {
|
protected EcoEnchant(String key, EcoEnchant.EnchantmentType type, Prerequisite... prerequisites) {
|
||||||
this(key, type, EcoEnchantsPlugin.class, prerequisites);
|
this(key, type, EcoEnchantsPlugin.class, prerequisites);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new EcoEnchant that exists within an extension or external plugin
|
||||||
|
*
|
||||||
|
* @param key The key name of the enchantment
|
||||||
|
* @param type The type of the enchantment
|
||||||
|
* @param plugin The Main class of the {@link org.bukkit.plugin.Plugin} or {@link com.willfp.ecoenchants.extensions.Extension} that the enchantment was created by
|
||||||
|
* @param prerequisites Optional {@link Prerequisite}s that must be met
|
||||||
|
*/
|
||||||
protected EcoEnchant(String key, EcoEnchant.EnchantmentType type, Class<?> plugin, Prerequisite... prerequisites) {
|
protected EcoEnchant(String key, EcoEnchant.EnchantmentType type, Class<?> plugin, Prerequisite... prerequisites) {
|
||||||
super(NamespacedKey.minecraft(key));
|
super(NamespacedKey.minecraft(key));
|
||||||
|
|
||||||
@ -84,6 +102,7 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Regist
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the enchantment based off config values
|
* Update the enchantment based off config values
|
||||||
|
* This can be overriden but may lead to unexpected behavior
|
||||||
*/
|
*/
|
||||||
public void update() {
|
public void update() {
|
||||||
config.loadFromLang();
|
config.loadFromLang();
|
||||||
|
@ -306,14 +306,14 @@ public class EcoEnchants {
|
|||||||
* @return True if has, false if doesn't have.
|
* @return True if has, false if doesn't have.
|
||||||
*/
|
*/
|
||||||
public static boolean hasAnyOfType(ItemStack item, EcoEnchant.EnchantmentType type) {
|
public static boolean hasAnyOfType(ItemStack item, EcoEnchant.EnchantmentType type) {
|
||||||
if(item == null) return false;
|
if (item == null) return false;
|
||||||
|
|
||||||
AtomicBoolean hasOfType = new AtomicBoolean(false);
|
AtomicBoolean hasOfType = new AtomicBoolean(false);
|
||||||
|
|
||||||
if(item.getItemMeta() instanceof EnchantmentStorageMeta) {
|
if (item.getItemMeta() instanceof EnchantmentStorageMeta) {
|
||||||
((EnchantmentStorageMeta) item.getItemMeta()).getStoredEnchants().forEach(((enchantment, integer) -> {
|
((EnchantmentStorageMeta) item.getItemMeta()).getStoredEnchants().forEach(((enchantment, integer) -> {
|
||||||
if(getFromEnchantment(enchantment) != null) {
|
if (getFromEnchantment(enchantment) != null) {
|
||||||
if(getFromEnchantment(enchantment).getType().equals(type)) hasOfType.set(true);
|
if (getFromEnchantment(enchantment).getType().equals(type)) hasOfType.set(true);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
} else {
|
} else {
|
||||||
|
@ -17,30 +17,53 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility class to simplify enchantment fetching
|
||||||
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public class EnchantChecks {
|
public class EnchantChecks {
|
||||||
|
/**
|
||||||
|
* Does the specified ItemStack have a certain Enchantment present?
|
||||||
|
*
|
||||||
|
* @param item The {@link ItemStack} to check
|
||||||
|
* @param enchantment The enchantment to query
|
||||||
|
* @return If the item has the queried enchantment
|
||||||
|
*/
|
||||||
public static boolean item(ItemStack item, Enchantment enchantment) {
|
public static boolean item(ItemStack item, Enchantment enchantment) {
|
||||||
return getItemLevel(item, enchantment) != 0;
|
return getItemLevel(item, enchantment) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* What level of the specified enchantment does the specified ItemStack have?
|
||||||
|
*
|
||||||
|
* @param item The {@link ItemStack} to check
|
||||||
|
* @param enchantment The enchantment to query
|
||||||
|
* @return The level of the enchantment, or 0 if not found
|
||||||
|
*/
|
||||||
public static int getItemLevel(ItemStack item, Enchantment enchantment) {
|
public static int getItemLevel(ItemStack item, Enchantment enchantment) {
|
||||||
if(item == null) return 0;
|
if (item == null) return 0;
|
||||||
if(item.getType().equals(Material.AIR)) return 0;
|
if (item.getType().equals(Material.AIR)) return 0;
|
||||||
if(!item.hasItemMeta()) return 0;
|
if (!item.hasItemMeta()) return 0;
|
||||||
if(item.getItemMeta() == null) return 0;
|
if (item.getItemMeta() == null) return 0;
|
||||||
|
|
||||||
return item.getItemMeta().getEnchantLevel(enchantment);
|
return item.getItemMeta().getEnchantLevel(enchantment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all {@link EcoEnchant}s on a specified ItemStack
|
||||||
|
*
|
||||||
|
* @param item The ItemStack to query
|
||||||
|
* @return A {@link HashMap<EcoEnchant, Integer>} of all EcoEnchants, where the key represents the level
|
||||||
|
*/
|
||||||
public static Map<EcoEnchant, Integer> getEnchantsOnItem(ItemStack item) {
|
public static Map<EcoEnchant, Integer> getEnchantsOnItem(ItemStack item) {
|
||||||
if(item == null) return new HashMap<>();
|
if (item == null) return new HashMap<>();
|
||||||
if(item.getType().equals(Material.AIR)) return new HashMap<>();
|
if (item.getType().equals(Material.AIR)) return new HashMap<>();
|
||||||
if(!item.hasItemMeta()) return new HashMap<>();
|
if (!item.hasItemMeta()) return new HashMap<>();
|
||||||
if(item.getItemMeta() == null) return new HashMap<>();
|
if (item.getItemMeta() == null) return new HashMap<>();
|
||||||
|
|
||||||
Map<EcoEnchant, Integer> ecoEnchants = new HashMap<>();
|
Map<EcoEnchant, Integer> ecoEnchants = new HashMap<>();
|
||||||
item.getEnchantments().forEach(((enchantment, integer) -> {
|
item.getEnchantments().forEach(((enchantment, integer) -> {
|
||||||
if(EcoEnchants.getFromEnchantment(enchantment) != null) {
|
if (EcoEnchants.getFromEnchantment(enchantment) != null) {
|
||||||
ecoEnchants.put(EcoEnchants.getFromEnchantment(enchantment), integer);
|
ecoEnchants.put(EcoEnchants.getFromEnchantment(enchantment), integer);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
@ -48,10 +71,28 @@ public class EnchantChecks {
|
|||||||
return ecoEnchants;
|
return ecoEnchants;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Does the specified Arrow have a certain Enchantment present?
|
||||||
|
* <p>
|
||||||
|
* EcoEnchants automatically gives an arrow NBT data consisting of the enchantments present to avoid switching errors
|
||||||
|
*
|
||||||
|
* @param arrow The {@link Arrow} to check
|
||||||
|
* @param enchantment The enchantment to query
|
||||||
|
* @return If the arrow has the queried enchantment
|
||||||
|
*/
|
||||||
public static boolean arrow(Arrow arrow, Enchantment enchantment) {
|
public static boolean arrow(Arrow arrow, Enchantment enchantment) {
|
||||||
return getArrowLevel(arrow, enchantment) != 0;
|
return getArrowLevel(arrow, enchantment) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* What level specified Arrow has of a certain Enchantment present?
|
||||||
|
* <p>
|
||||||
|
* EcoEnchants automatically gives an arrow NBT data consisting of the enchantments present to avoid switching errors
|
||||||
|
*
|
||||||
|
* @param arrow The {@link Arrow} to check
|
||||||
|
* @param enchantment The enchantment to query
|
||||||
|
* @return The level found on the arrow, or 0 if not found
|
||||||
|
*/
|
||||||
public static int getArrowLevel(Arrow arrow, Enchantment enchantment) {
|
public static int getArrowLevel(Arrow arrow, Enchantment enchantment) {
|
||||||
if (arrow.getMetadata("enchantments").isEmpty()) return 0;
|
if (arrow.getMetadata("enchantments").isEmpty()) return 0;
|
||||||
|
|
||||||
@ -61,10 +102,16 @@ public class EnchantChecks {
|
|||||||
|
|
||||||
Map<Enchantment, Integer> enchantments = (Map<Enchantment, Integer>) enchantmentsMetaValue.value();
|
Map<Enchantment, Integer> enchantments = (Map<Enchantment, Integer>) enchantmentsMetaValue.value();
|
||||||
if (enchantments == null) return 0;
|
if (enchantments == null) return 0;
|
||||||
if(!enchantments.containsKey(enchantment)) return 0;
|
if (!enchantments.containsKey(enchantment)) return 0;
|
||||||
return enchantments.get(enchantment);
|
return enchantments.get(enchantment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all {@link EcoEnchant}s on a specified Arrow
|
||||||
|
*
|
||||||
|
* @param arrow The Arrow to query
|
||||||
|
* @return A {@link HashMap<EcoEnchant, Integer>} of all EcoEnchants, where the key represents the level
|
||||||
|
*/
|
||||||
public static Map<EcoEnchant, Integer> getEnchantsOnArrow(Arrow arrow) {
|
public static Map<EcoEnchant, Integer> getEnchantsOnArrow(Arrow arrow) {
|
||||||
if (arrow.getMetadata("enchantments").isEmpty()) return new HashMap<>();
|
if (arrow.getMetadata("enchantments").isEmpty()) return new HashMap<>();
|
||||||
|
|
||||||
@ -74,7 +121,7 @@ public class EnchantChecks {
|
|||||||
|
|
||||||
Map<EcoEnchant, Integer> ecoEnchants = new HashMap<>();
|
Map<EcoEnchant, Integer> ecoEnchants = new HashMap<>();
|
||||||
((Map<Enchantment, Integer>) enchantmentsMetaValue.value()).forEach(((enchantment, integer) -> {
|
((Map<Enchantment, Integer>) enchantmentsMetaValue.value()).forEach(((enchantment, integer) -> {
|
||||||
if(EcoEnchants.getFromEnchantment(enchantment) != null) {
|
if (EcoEnchants.getFromEnchantment(enchantment) != null) {
|
||||||
ecoEnchants.put(EcoEnchants.getFromEnchantment(enchantment), integer);
|
ecoEnchants.put(EcoEnchants.getFromEnchantment(enchantment), integer);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
@ -87,7 +134,7 @@ public class EnchantChecks {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static int getMainhandLevel(LivingEntity entity, Enchantment enchantment) {
|
public static int getMainhandLevel(LivingEntity entity, Enchantment enchantment) {
|
||||||
if(entity.getEquipment() == null)
|
if (entity.getEquipment() == null)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
ItemStack item = entity.getEquipment().getItemInMainHand();
|
ItemStack item = entity.getEquipment().getItemInMainHand();
|
||||||
@ -96,17 +143,17 @@ public class EnchantChecks {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Map<EcoEnchant, Integer> getEnchantsOnMainhand(LivingEntity entity) {
|
public static Map<EcoEnchant, Integer> getEnchantsOnMainhand(LivingEntity entity) {
|
||||||
if(entity.getEquipment() == null)
|
if (entity.getEquipment() == null)
|
||||||
return new HashMap<>();
|
return new HashMap<>();
|
||||||
|
|
||||||
ItemStack item = entity.getEquipment().getItemInMainHand();
|
ItemStack item = entity.getEquipment().getItemInMainHand();
|
||||||
|
|
||||||
if(item == null) return new HashMap<>();
|
if (item == null) return new HashMap<>();
|
||||||
|
|
||||||
Map<EcoEnchant, Integer> ecoEnchants = new HashMap<>();
|
Map<EcoEnchant, Integer> ecoEnchants = new HashMap<>();
|
||||||
|
|
||||||
item.getEnchantments().forEach(((enchantment, integer) -> {
|
item.getEnchantments().forEach(((enchantment, integer) -> {
|
||||||
if(EcoEnchants.getFromEnchantment(enchantment) != null) {
|
if (EcoEnchants.getFromEnchantment(enchantment) != null) {
|
||||||
ecoEnchants.put(EcoEnchants.getFromEnchantment(enchantment), integer);
|
ecoEnchants.put(EcoEnchants.getFromEnchantment(enchantment), integer);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
@ -119,7 +166,7 @@ public class EnchantChecks {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static int getOffhandLevel(LivingEntity entity, Enchantment enchantment) {
|
public static int getOffhandLevel(LivingEntity entity, Enchantment enchantment) {
|
||||||
if(entity.getEquipment() == null)
|
if (entity.getEquipment() == null)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
ItemStack item = entity.getEquipment().getItemInOffHand();
|
ItemStack item = entity.getEquipment().getItemInOffHand();
|
||||||
@ -128,17 +175,17 @@ public class EnchantChecks {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Map<EcoEnchant, Integer> getEnchantsOnOffhand(LivingEntity entity) {
|
public static Map<EcoEnchant, Integer> getEnchantsOnOffhand(LivingEntity entity) {
|
||||||
if(entity.getEquipment() == null)
|
if (entity.getEquipment() == null)
|
||||||
return new HashMap<>();
|
return new HashMap<>();
|
||||||
|
|
||||||
ItemStack item = entity.getEquipment().getItemInOffHand();
|
ItemStack item = entity.getEquipment().getItemInOffHand();
|
||||||
|
|
||||||
if(item == null) return new HashMap<>();
|
if (item == null) return new HashMap<>();
|
||||||
|
|
||||||
Map<EcoEnchant, Integer> ecoEnchants = new HashMap<>();
|
Map<EcoEnchant, Integer> ecoEnchants = new HashMap<>();
|
||||||
|
|
||||||
item.getEnchantments().forEach(((enchantment, integer) -> {
|
item.getEnchantments().forEach(((enchantment, integer) -> {
|
||||||
if(EcoEnchants.getFromEnchantment(enchantment) != null) {
|
if (EcoEnchants.getFromEnchantment(enchantment) != null) {
|
||||||
ecoEnchants.put(EcoEnchants.getFromEnchantment(enchantment), integer);
|
ecoEnchants.put(EcoEnchants.getFromEnchantment(enchantment), integer);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
@ -151,7 +198,7 @@ public class EnchantChecks {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static int getArmorPoints(LivingEntity entity, Enchantment enchantment, int damage) {
|
public static int getArmorPoints(LivingEntity entity, Enchantment enchantment, int damage) {
|
||||||
if(entity.getEquipment() == null)
|
if (entity.getEquipment() == null)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
boolean isPlayer = entity instanceof Player;
|
boolean isPlayer = entity instanceof Player;
|
||||||
@ -160,20 +207,20 @@ public class EnchantChecks {
|
|||||||
List<ItemStack> armor = Arrays.asList(entity.getEquipment().getArmorContents());
|
List<ItemStack> armor = Arrays.asList(entity.getEquipment().getArmorContents());
|
||||||
armor.forEach((itemStack -> {
|
armor.forEach((itemStack -> {
|
||||||
int level = getItemLevel(itemStack, enchantment);
|
int level = getItemLevel(itemStack, enchantment);
|
||||||
if(level != 0) {
|
if (level != 0) {
|
||||||
armorPoints.addAndGet(getItemLevel(itemStack, enchantment));
|
armorPoints.addAndGet(getItemLevel(itemStack, enchantment));
|
||||||
if(damage > 0 && isPlayer) {
|
if (damage > 0 && isPlayer) {
|
||||||
Player player = (Player) entity;
|
Player player = (Player) entity;
|
||||||
if(itemStack.equals(entity.getEquipment().getHelmet())) {
|
if (itemStack.equals(entity.getEquipment().getHelmet())) {
|
||||||
DurabilityUtils.damageItem(player, player.getInventory().getHelmet(), level, 39);
|
DurabilityUtils.damageItem(player, player.getInventory().getHelmet(), level, 39);
|
||||||
}
|
}
|
||||||
if(itemStack.equals(entity.getEquipment().getChestplate())) {
|
if (itemStack.equals(entity.getEquipment().getChestplate())) {
|
||||||
DurabilityUtils.damageItem(player, player.getInventory().getChestplate(), level, 38);
|
DurabilityUtils.damageItem(player, player.getInventory().getChestplate(), level, 38);
|
||||||
}
|
}
|
||||||
if(itemStack.equals(entity.getEquipment().getLeggings())) {
|
if (itemStack.equals(entity.getEquipment().getLeggings())) {
|
||||||
DurabilityUtils.damageItem(player, player.getInventory().getLeggings(), level, 37);
|
DurabilityUtils.damageItem(player, player.getInventory().getLeggings(), level, 37);
|
||||||
}
|
}
|
||||||
if(itemStack.equals(entity.getEquipment().getBoots())) {
|
if (itemStack.equals(entity.getEquipment().getBoots())) {
|
||||||
DurabilityUtils.damageItem(player, player.getInventory().getBoots(), level, 36);
|
DurabilityUtils.damageItem(player, player.getInventory().getBoots(), level, 36);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -184,7 +231,7 @@ public class EnchantChecks {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Map<EcoEnchant, Integer> getEnchantsOnArmor(LivingEntity entity) {
|
public static Map<EcoEnchant, Integer> getEnchantsOnArmor(LivingEntity entity) {
|
||||||
if(entity.getEquipment() == null)
|
if (entity.getEquipment() == null)
|
||||||
return new HashMap<>();
|
return new HashMap<>();
|
||||||
|
|
||||||
AtomicInteger armorPoints = new AtomicInteger(0);
|
AtomicInteger armorPoints = new AtomicInteger(0);
|
||||||
@ -204,7 +251,7 @@ public class EnchantChecks {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static int getHelmetLevel(LivingEntity entity, Enchantment enchantment) {
|
public static int getHelmetLevel(LivingEntity entity, Enchantment enchantment) {
|
||||||
if(entity.getEquipment() == null)
|
if (entity.getEquipment() == null)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
ItemStack item = entity.getEquipment().getHelmet();
|
ItemStack item = entity.getEquipment().getHelmet();
|
||||||
@ -217,7 +264,7 @@ public class EnchantChecks {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static int getChestplateLevel(LivingEntity entity, Enchantment enchantment) {
|
public static int getChestplateLevel(LivingEntity entity, Enchantment enchantment) {
|
||||||
if(entity.getEquipment() == null)
|
if (entity.getEquipment() == null)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
ItemStack item = entity.getEquipment().getChestplate();
|
ItemStack item = entity.getEquipment().getChestplate();
|
||||||
@ -230,7 +277,7 @@ public class EnchantChecks {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static int getLeggingsLevel(LivingEntity entity, Enchantment enchantment) {
|
public static int getLeggingsLevel(LivingEntity entity, Enchantment enchantment) {
|
||||||
if(entity.getEquipment() == null)
|
if (entity.getEquipment() == null)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
ItemStack item = entity.getEquipment().getLeggings();
|
ItemStack item = entity.getEquipment().getLeggings();
|
||||||
@ -243,7 +290,7 @@ public class EnchantChecks {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static int getBootsLevel(LivingEntity entity, Enchantment enchantment) {
|
public static int getBootsLevel(LivingEntity entity, Enchantment enchantment) {
|
||||||
if(entity.getEquipment() == null)
|
if (entity.getEquipment() == null)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
ItemStack item = entity.getEquipment().getBoots();
|
ItemStack item = entity.getEquipment().getBoots();
|
||||||
|
@ -43,10 +43,11 @@ public class EntityDeathByEntityEvent extends Event {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Create event based off parameters
|
* Create event based off parameters
|
||||||
* @param victim The killed entity
|
*
|
||||||
* @param damager The killer
|
* @param victim The killed entity
|
||||||
* @param drops The item drops
|
* @param damager The killer
|
||||||
* @param xp The amount of xp to drop
|
* @param drops The item drops
|
||||||
|
* @param xp The amount of xp to drop
|
||||||
* @param deathEvent The associated {@link EntityDeathEvent}
|
* @param deathEvent The associated {@link EntityDeathEvent}
|
||||||
*/
|
*/
|
||||||
public EntityDeathByEntityEvent(@NotNull LivingEntity victim, @NotNull Entity damager, @NotNull List<ItemStack> drops, int xp, @NotNull EntityDeathEvent deathEvent) {
|
public EntityDeathByEntityEvent(@NotNull LivingEntity victim, @NotNull Entity damager, @NotNull List<ItemStack> drops, int xp, @NotNull EntityDeathEvent deathEvent) {
|
||||||
@ -59,6 +60,7 @@ public class EntityDeathByEntityEvent extends Event {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get victim
|
* Get victim
|
||||||
|
*
|
||||||
* @return The victim
|
* @return The victim
|
||||||
*/
|
*/
|
||||||
public LivingEntity getVictim() {
|
public LivingEntity getVictim() {
|
||||||
@ -67,6 +69,7 @@ public class EntityDeathByEntityEvent extends Event {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get killer
|
* Get killer
|
||||||
|
*
|
||||||
* @return The killer
|
* @return The killer
|
||||||
*/
|
*/
|
||||||
public Entity getKiller() {
|
public Entity getKiller() {
|
||||||
@ -75,6 +78,7 @@ public class EntityDeathByEntityEvent extends Event {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get xp amount
|
* Get xp amount
|
||||||
|
*
|
||||||
* @return The xp
|
* @return The xp
|
||||||
*/
|
*/
|
||||||
public int getDroppedExp() {
|
public int getDroppedExp() {
|
||||||
@ -83,6 +87,7 @@ public class EntityDeathByEntityEvent extends Event {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get drops
|
* Get drops
|
||||||
|
*
|
||||||
* @return {@link List} of drops
|
* @return {@link List} of drops
|
||||||
*/
|
*/
|
||||||
public List<ItemStack> getDrops() {
|
public List<ItemStack> getDrops() {
|
||||||
@ -92,6 +97,7 @@ public class EntityDeathByEntityEvent extends Event {
|
|||||||
/**
|
/**
|
||||||
* Get associated {@link EntityDeathEvent}
|
* Get associated {@link EntityDeathEvent}
|
||||||
* Use this to modify event parameters.
|
* Use this to modify event parameters.
|
||||||
|
*
|
||||||
* @return The associated {@link EntityDeathEvent}
|
* @return The associated {@link EntityDeathEvent}
|
||||||
*/
|
*/
|
||||||
public EntityDeathEvent getDeathEvent() {
|
public EntityDeathEvent getDeathEvent() {
|
||||||
|
@ -18,6 +18,7 @@ public class NaturalExpGainEvent extends Event {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Create event based off parameters
|
* Create event based off parameters
|
||||||
|
*
|
||||||
* @param event The associate PlayerExpChangeEvent
|
* @param event The associate PlayerExpChangeEvent
|
||||||
*/
|
*/
|
||||||
public NaturalExpGainEvent(@NotNull PlayerExpChangeEvent event) {
|
public NaturalExpGainEvent(@NotNull PlayerExpChangeEvent event) {
|
||||||
@ -27,6 +28,7 @@ public class NaturalExpGainEvent extends Event {
|
|||||||
/**
|
/**
|
||||||
* Get associated {@link PlayerExpChangeEvent}
|
* Get associated {@link PlayerExpChangeEvent}
|
||||||
* Use this to modify event parameters.
|
* Use this to modify event parameters.
|
||||||
|
*
|
||||||
* @return The associated {@link PlayerExpChangeEvent}
|
* @return The associated {@link PlayerExpChangeEvent}
|
||||||
*/
|
*/
|
||||||
public PlayerExpChangeEvent getExpChangeEvent() {
|
public PlayerExpChangeEvent getExpChangeEvent() {
|
||||||
|
@ -41,8 +41,9 @@ public abstract class Extension {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the metadata of the extension
|
* Set the metadata of the extension
|
||||||
*
|
* <p>
|
||||||
* Must be called before enabling
|
* Must be called before enabling
|
||||||
|
*
|
||||||
* @param metadata The metadata to set
|
* @param metadata The metadata to set
|
||||||
*/
|
*/
|
||||||
public final void setMetadata(ExtensionMetadata metadata) {
|
public final void setMetadata(ExtensionMetadata metadata) {
|
||||||
@ -51,6 +52,7 @@ public abstract class Extension {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the name of the extension
|
* Get the name of the extension
|
||||||
|
*
|
||||||
* @return The name of the metadata attached to the extension
|
* @return The name of the metadata attached to the extension
|
||||||
*/
|
*/
|
||||||
public final String getName() {
|
public final String getName() {
|
||||||
@ -60,6 +62,7 @@ public abstract class Extension {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the version of the extension
|
* Get the version of the extension
|
||||||
|
*
|
||||||
* @return The version of the metadata attached to the extension
|
* @return The version of the metadata attached to the extension
|
||||||
*/
|
*/
|
||||||
public final String getVersion() {
|
public final String getVersion() {
|
||||||
|
@ -4,6 +4,12 @@ package com.willfp.ecoenchants.extensions;
|
|||||||
* Called when the extension is made incorrectly
|
* Called when the extension is made incorrectly
|
||||||
*/
|
*/
|
||||||
public class MalformedExtensionException extends RuntimeException {
|
public class MalformedExtensionException extends RuntimeException {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new MalformedExtensionException
|
||||||
|
*
|
||||||
|
* @param errorMessage The error message to show
|
||||||
|
*/
|
||||||
public MalformedExtensionException(String errorMessage) {
|
public MalformedExtensionException(String errorMessage) {
|
||||||
super(errorMessage);
|
super(errorMessage);
|
||||||
}
|
}
|
||||||
|
@ -18,14 +18,11 @@ import java.util.HashSet;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class containing method to load extensions
|
* Concrete implementation of {@link ExtensionLoader}
|
||||||
*/
|
*/
|
||||||
public class EcoExtensionLoader implements ExtensionLoader {
|
public class EcoExtensionLoader implements ExtensionLoader {
|
||||||
private final Set<Extension> extensions = new HashSet<>();
|
private final Set<Extension> extensions = new HashSet<>();
|
||||||
|
|
||||||
/**
|
|
||||||
* Load all extensions
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void loadExtensions() {
|
public void loadExtensions() {
|
||||||
File dir = new File(EcoEnchantsPlugin.getInstance().getDataFolder(), "/extensions");
|
File dir = new File(EcoEnchantsPlugin.getInstance().getDataFolder(), "/extensions");
|
||||||
@ -35,11 +32,11 @@ public class EcoExtensionLoader implements ExtensionLoader {
|
|||||||
|
|
||||||
File[] extensionJars = dir.listFiles();
|
File[] extensionJars = dir.listFiles();
|
||||||
|
|
||||||
if(extensionJars == null)
|
if (extensionJars == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (File extensionJar : extensionJars) {
|
for (File extensionJar : extensionJars) {
|
||||||
if(!extensionJar.isFile()) continue;
|
if (!extensionJar.isFile()) continue;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
loadExtension(extensionJar);
|
loadExtension(extensionJar);
|
||||||
@ -70,7 +67,7 @@ public class EcoExtensionLoader implements ExtensionLoader {
|
|||||||
Set<String> keys = extensionYml.getKeys(false);
|
Set<String> keys = extensionYml.getKeys(false);
|
||||||
ArrayList<String> required = new ArrayList<>(Arrays.asList("main", "name", "version"));
|
ArrayList<String> required = new ArrayList<>(Arrays.asList("main", "name", "version"));
|
||||||
required.removeAll(keys);
|
required.removeAll(keys);
|
||||||
if(!required.isEmpty()) {
|
if (!required.isEmpty()) {
|
||||||
throw new MalformedExtensionException("Invalid extension.yml found in " + extensionJar.getName() + " - Missing: " + String.join(", ", required));
|
throw new MalformedExtensionException("Invalid extension.yml found in " + extensionJar.getName() + " - Missing: " + String.join(", ", required));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,7 +85,7 @@ public class EcoExtensionLoader implements ExtensionLoader {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!(object instanceof Extension))
|
if (!(object instanceof Extension))
|
||||||
throw new MalformedExtensionException(extensionJar.getName() + " is invalid");
|
throw new MalformedExtensionException(extensionJar.getName() + " is invalid");
|
||||||
|
|
||||||
Extension extension = (Extension) object;
|
Extension extension = (Extension) object;
|
||||||
@ -97,28 +94,18 @@ public class EcoExtensionLoader implements ExtensionLoader {
|
|||||||
extensions.add(extension);
|
extensions.add(extension);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Unload all extensions
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void unloadExtensions() {
|
public void unloadExtensions() {
|
||||||
extensions.forEach(Extension::disable);
|
extensions.forEach(Extension::disable);
|
||||||
extensions.clear();
|
extensions.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Reload all extensions
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void reloadExtensions() {
|
public void reloadExtensions() {
|
||||||
unloadExtensions();
|
unloadExtensions();
|
||||||
loadExtensions();
|
loadExtensions();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get set of all loaded extensions
|
|
||||||
* @return {@link Set} of {@link Extension}s
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public Set<Extension> getLoadedExtensions() {
|
public Set<Extension> getLoadedExtensions() {
|
||||||
return extensions;
|
return extensions;
|
||||||
|
@ -4,12 +4,31 @@ import com.willfp.ecoenchants.extensions.Extension;
|
|||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface for extension loader
|
||||||
|
* Some external plugins may modify extension loading for internal server purposes
|
||||||
|
*/
|
||||||
public interface ExtensionLoader {
|
public interface ExtensionLoader {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load all extensions
|
||||||
|
*/
|
||||||
void loadExtensions();
|
void loadExtensions();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unload all loaded extensions
|
||||||
|
*/
|
||||||
void unloadExtensions();
|
void unloadExtensions();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reload all extensions
|
||||||
|
*/
|
||||||
void reloadExtensions();
|
void reloadExtensions();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve a set of all loaded extensions
|
||||||
|
*
|
||||||
|
* @return An {@link Set<Extension>} of all loaded extensions
|
||||||
|
*/
|
||||||
Set<Extension> getLoadedExtensions();
|
Set<Extension> getLoadedExtensions();
|
||||||
}
|
}
|
||||||
|
@ -8,20 +8,39 @@ import org.bukkit.event.Listener;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility class for Anticheat Integrations
|
||||||
|
*/
|
||||||
public class AnticheatManager {
|
public class AnticheatManager {
|
||||||
private static final Set<AnticheatWrapper> anticheats = new HashSet<>();
|
private static final Set<AnticheatWrapper> anticheats = new HashSet<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a new anticheat
|
||||||
|
*
|
||||||
|
* @param anticheat The anticheat to register
|
||||||
|
*/
|
||||||
public static void register(AnticheatWrapper anticheat) {
|
public static void register(AnticheatWrapper anticheat) {
|
||||||
if(anticheat instanceof Listener) {
|
if (anticheat instanceof Listener) {
|
||||||
Bukkit.getPluginManager().registerEvents((Listener) anticheat, EcoEnchantsPlugin.getInstance());
|
Bukkit.getPluginManager().registerEvents((Listener) anticheat, EcoEnchantsPlugin.getInstance());
|
||||||
}
|
}
|
||||||
anticheats.add(anticheat);
|
anticheats.add(anticheat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exempt a player from triggering anticheats
|
||||||
|
*
|
||||||
|
* @param player The player to exempt
|
||||||
|
*/
|
||||||
public static void exemptPlayer(Player player) {
|
public static void exemptPlayer(Player player) {
|
||||||
anticheats.forEach(anticheat -> anticheat.exempt(player));
|
anticheats.forEach(anticheat -> anticheat.exempt(player));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unexempt a player from triggering anticheats
|
||||||
|
* This is ran a tick after it is called to ensure that there are no event timing conflicts
|
||||||
|
*
|
||||||
|
* @param player The player to remove the exemption
|
||||||
|
*/
|
||||||
public static void unexemptPlayer(Player player) {
|
public static void unexemptPlayer(Player player) {
|
||||||
Bukkit.getScheduler().runTaskLater(EcoEnchantsPlugin.getInstance(), () -> {
|
Bukkit.getScheduler().runTaskLater(EcoEnchantsPlugin.getInstance(), () -> {
|
||||||
anticheats.forEach(anticheat -> anticheat.unexempt(player));
|
anticheats.forEach(anticheat -> anticheat.unexempt(player));
|
||||||
|
@ -3,15 +3,20 @@ package com.willfp.ecoenchants.integrations.anticheat;
|
|||||||
import com.willfp.ecoenchants.integrations.Integration;
|
import com.willfp.ecoenchants.integrations.Integration;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface for anticheat integrations
|
||||||
|
*/
|
||||||
public interface AnticheatWrapper extends Integration {
|
public interface AnticheatWrapper extends Integration {
|
||||||
/**
|
/**
|
||||||
* Exempt a player from checks
|
* Exempt a player from checks
|
||||||
|
*
|
||||||
* @param player The player to exempt
|
* @param player The player to exempt
|
||||||
*/
|
*/
|
||||||
void exempt(Player player);
|
void exempt(Player player);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unexempt a player from checks
|
* Unexempt a player from checks
|
||||||
|
*
|
||||||
* @param player The player to unexempt
|
* @param player The player to unexempt
|
||||||
*/
|
*/
|
||||||
void unexempt(Player player);
|
void unexempt(Player player);
|
||||||
|
@ -11,14 +11,20 @@ import java.util.Set;
|
|||||||
public class AntigriefManager {
|
public class AntigriefManager {
|
||||||
private static final Set<AntigriefWrapper> antigriefs = new HashSet<>();
|
private static final Set<AntigriefWrapper> antigriefs = new HashSet<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a new AntiGrief/Land Management integration
|
||||||
|
*
|
||||||
|
* @param antigrief The integration to register
|
||||||
|
*/
|
||||||
public static void register(AntigriefWrapper antigrief) {
|
public static void register(AntigriefWrapper antigrief) {
|
||||||
antigriefs.add(antigrief);
|
antigriefs.add(antigrief);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Can player break block
|
* Can player break block
|
||||||
|
*
|
||||||
* @param player The player
|
* @param player The player
|
||||||
* @param block The block
|
* @param block The block
|
||||||
* @return If player can break block
|
* @return If player can break block
|
||||||
*/
|
*/
|
||||||
public static boolean canBreakBlock(Player player, Block block) {
|
public static boolean canBreakBlock(Player player, Block block) {
|
||||||
@ -27,7 +33,8 @@ public class AntigriefManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Can player create explosion at location
|
* Can player create explosion at location
|
||||||
* @param player The player
|
*
|
||||||
|
* @param player The player
|
||||||
* @param location The location
|
* @param location The location
|
||||||
* @return If player can create explosion
|
* @return If player can create explosion
|
||||||
*/
|
*/
|
||||||
@ -37,8 +44,9 @@ public class AntigriefManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Can player place block
|
* Can player place block
|
||||||
|
*
|
||||||
* @param player The player
|
* @param player The player
|
||||||
* @param block The block
|
* @param block The block
|
||||||
* @return If player can place block
|
* @return If player can place block
|
||||||
*/
|
*/
|
||||||
public static boolean canPlaceBlock(Player player, Block block) {
|
public static boolean canPlaceBlock(Player player, Block block) {
|
||||||
@ -47,6 +55,7 @@ public class AntigriefManager {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Can player injure living entity
|
* Can player injure living entity
|
||||||
|
*
|
||||||
* @param player The player
|
* @param player The player
|
||||||
* @param victim The victim
|
* @param victim The victim
|
||||||
* @return If player can injure
|
* @return If player can injure
|
||||||
|
@ -6,12 +6,23 @@ import org.bukkit.block.Block;
|
|||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface for Antigrief integrations
|
||||||
|
*/
|
||||||
public interface AntigriefWrapper extends Integration {
|
public interface AntigriefWrapper extends Integration {
|
||||||
|
/**
|
||||||
|
* Can player break block
|
||||||
|
*
|
||||||
|
* @param player The player
|
||||||
|
* @param block The block
|
||||||
|
* @return If player cna break block
|
||||||
|
*/
|
||||||
boolean canBreakBlock(Player player, Block block);
|
boolean canBreakBlock(Player player, Block block);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Can player create explosion at location
|
* Can player create explosion at location
|
||||||
* @param player The player
|
*
|
||||||
|
* @param player The player
|
||||||
* @param location The location
|
* @param location The location
|
||||||
* @return If player can create explosion
|
* @return If player can create explosion
|
||||||
*/
|
*/
|
||||||
@ -19,14 +30,16 @@ public interface AntigriefWrapper extends Integration {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Can player place block
|
* Can player place block
|
||||||
|
*
|
||||||
* @param player The player
|
* @param player The player
|
||||||
* @param block The block
|
* @param block The block
|
||||||
* @return If player can place block
|
* @return If player can place block
|
||||||
*/
|
*/
|
||||||
boolean canPlaceBlock(Player player, Block block);
|
boolean canPlaceBlock(Player player, Block block);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Can player injure living entity
|
* Can player injure living entity
|
||||||
|
*
|
||||||
* @param player The player
|
* @param player The player
|
||||||
* @param victim The victim
|
* @param victim The victim
|
||||||
* @return If player can injure
|
* @return If player can injure
|
||||||
|
Loading…
Reference in New Issue
Block a user