This commit is contained in:
BuildTools 2023-10-03 18:07:42 +05:00
parent 354a396dc6
commit eeef240e49
112 changed files with 1550 additions and 823 deletions

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>ExcellentEnchants</artifactId>
<groupId>su.nightexpress.excellentenchants</groupId>
<version>3.5.8</version>
<version>3.5.9</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@ -76,32 +76,32 @@
<dependency>
<groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>NMS</artifactId>
<version>3.5.8</version>
<version>3.5.9</version>
</dependency>
<dependency>
<groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>V1_17_R1</artifactId>
<version>3.5.8</version>
<version>3.5.9</version>
</dependency>
<dependency>
<groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>V1_18_R2</artifactId>
<version>3.5.8</version>
<version>3.5.9</version>
</dependency>
<dependency>
<groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>V1_19_R3</artifactId>
<version>3.5.8</version>
<version>3.5.9</version>
</dependency>
<dependency>
<groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>V1_20_R1</artifactId>
<version>3.5.8</version>
<version>3.5.9</version>
</dependency>
<dependency>
<groupId>su.nightexpress.excellentenchants</groupId>
<artifactId>V1_20_R2</artifactId>
<version>3.5.8</version>
<version>3.5.9</version>
</dependency>
</dependencies>

View File

@ -1,5 +1,6 @@
package su.nightexpress.excellentenchants;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.NexPlugin;
import su.nexmedia.engine.Version;
@ -13,8 +14,10 @@ import su.nightexpress.excellentenchants.command.TierbookCommand;
import su.nightexpress.excellentenchants.config.Config;
import su.nightexpress.excellentenchants.config.Lang;
import su.nightexpress.excellentenchants.enchantment.EnchantManager;
import su.nightexpress.excellentenchants.enchantment.EnchantRegistry;
import su.nightexpress.excellentenchants.enchantment.EnchantPopulator;
import su.nightexpress.excellentenchants.enchantment.registry.EnchantRegistry;
import su.nightexpress.excellentenchants.enchantment.type.FitItemType;
import su.nightexpress.excellentenchants.enchantment.type.ObtainType;
import su.nightexpress.excellentenchants.hook.HookId;
import su.nightexpress.excellentenchants.hook.impl.PlaceholderHook;
import su.nightexpress.excellentenchants.hook.impl.ProtocolHook;
@ -28,7 +31,7 @@ import su.nightexpress.excellentenchants.tier.TierManager;
public class ExcellentEnchants extends NexPlugin<ExcellentEnchants> {
private EnchantRegistry enchantRegistry;
private EnchantRegistry registry;
private EnchantManager enchantManager;
private EnchantNMS enchantNMS;
private TierManager tierManager;
@ -42,7 +45,7 @@ public class ExcellentEnchants extends NexPlugin<ExcellentEnchants> {
@Override
public void onLoad() {
super.onLoad();
this.enchantRegistry = new EnchantRegistry(this);
this.registry = new EnchantRegistry(this);
}
@Override
@ -52,7 +55,7 @@ public class ExcellentEnchants extends NexPlugin<ExcellentEnchants> {
this.tierManager = new TierManager(this);
this.tierManager.setup();
this.enchantRegistry.setup();
this.registry.setup();
this.enchantManager = new EnchantManager(this);
this.enchantManager.setup();
@ -79,7 +82,7 @@ public class ExcellentEnchants extends NexPlugin<ExcellentEnchants> {
this.tierManager = null;
}
PlaceholderHook.shutdown();
//this.enchantRegistry.shutdown(); Do we ever need this at all?
this.registry.shutdown();
}
private void setNMS() {
@ -126,14 +129,19 @@ public class ExcellentEnchants extends NexPlugin<ExcellentEnchants> {
this.registerPermissions(Perms.class);
}
@NotNull
public EnchantPopulator createPopulator(@NotNull ItemStack item, @NotNull ObtainType obtainType) {
return new EnchantPopulator(this, item, obtainType);
}
@NotNull
public TierManager getTierManager() {
return tierManager;
}
@NotNull
public EnchantRegistry getEnchantRegistry() {
return this.enchantRegistry;
public EnchantRegistry getRegistry() {
return registry;
}
@NotNull

View File

@ -1,25 +1,27 @@
package su.nightexpress.excellentenchants.api.enchantment;
import org.bukkit.Keyed;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventPriority;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import su.nexmedia.engine.api.config.JYML;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import su.nightexpress.excellentenchants.tier.Tier;
import su.nightexpress.excellentenchants.enchantment.type.ObtainType;
import su.nightexpress.excellentenchants.tier.Tier;
import java.util.List;
import java.util.Set;
public interface IEnchantment {
public interface IEnchantment extends Keyed {
boolean isAvailableToUse(@NotNull LivingEntity entity);
@NotNull JYML getConfig();
@NotNull String getId();
@NotNull EnchantPriority getPriority();
@NotNull String getDisplayName();
@NotNull String getNameFormatted(int level);

View File

@ -1,6 +1,7 @@
package su.nightexpress.excellentenchants.api.enchantment.type;
import org.bukkit.entity.Player;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
@ -8,5 +9,10 @@ import su.nightexpress.excellentenchants.api.enchantment.IEnchantment;
public interface BlockBreakEnchant extends IEnchantment {
boolean onBreak(@NotNull BlockBreakEvent event, @NotNull Player player, @NotNull ItemStack item, int level);
boolean onBreak(@NotNull BlockBreakEvent event, @NotNull LivingEntity player, @NotNull ItemStack item, int level);
@NotNull
default EventPriority getBreakPriority() {
return EventPriority.HIGH;
}
}

View File

@ -1,6 +1,7 @@
package su.nightexpress.excellentenchants.api.enchantment.type;
import org.bukkit.entity.Player;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockDropItemEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
@ -8,5 +9,10 @@ import su.nightexpress.excellentenchants.api.enchantment.IEnchantment;
public interface BlockDropEnchant extends IEnchantment {
boolean onDrop(@NotNull BlockDropItemEvent event, @NotNull Player player, @NotNull ItemStack item, int level);
boolean onDrop(@NotNull BlockDropItemEvent event, @NotNull LivingEntity player, @NotNull ItemStack item, int level);
@NotNull
default EventPriority getDropPriority() {
return EventPriority.NORMAL;
}
}

View File

@ -2,6 +2,7 @@ package su.nightexpress.excellentenchants.api.enchantment.type;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Projectile;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityShootBowEvent;
import org.bukkit.event.entity.ProjectileHitEvent;
@ -13,9 +14,24 @@ public interface BowEnchant extends IEnchantment {
boolean onShoot(@NotNull EntityShootBowEvent event, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level);
boolean onHit(@NotNull ProjectileHitEvent event, @NotNull Projectile projectile, @NotNull ItemStack bow, int level);
boolean onHit(@NotNull ProjectileHitEvent event, LivingEntity user, @NotNull Projectile projectile, @NotNull ItemStack bow, int level);
boolean onDamage(@NotNull EntityDamageByEntityEvent event, @NotNull Projectile projectile,
@NotNull LivingEntity shooter, @NotNull LivingEntity victim,
@NotNull ItemStack weapon, int level);
@NotNull
default EventPriority getShootPriority() {
return EventPriority.NORMAL;
}
@NotNull
default EventPriority getHitPriority() {
return EventPriority.NORMAL;
}
@NotNull
default EventPriority getDamagePriority() {
return EventPriority.NORMAL;
}
}

View File

@ -1,6 +1,7 @@
package su.nightexpress.excellentenchants.api.enchantment.type;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
@ -15,4 +16,14 @@ public interface CombatEnchant extends IEnchantment {
boolean onProtect(@NotNull EntityDamageByEntityEvent event,
@NotNull LivingEntity damager, @NotNull LivingEntity victim,
@NotNull ItemStack weapon, int level);
@NotNull
default EventPriority getAttackPriority() {
return EventPriority.NORMAL;
}
@NotNull
default EventPriority getProtectPriority() {
return EventPriority.NORMAL;
}
}

View File

@ -1,6 +1,7 @@
package su.nightexpress.excellentenchants.api.enchantment.type;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
@ -9,4 +10,9 @@ import su.nightexpress.excellentenchants.api.enchantment.IEnchantment;
public interface DamageEnchant extends IEnchantment {
boolean onDamage(@NotNull EntityDamageEvent event, @NotNull LivingEntity entity, @NotNull ItemStack item, int level);
@NotNull
default EventPriority getDamagePriority() {
return EventPriority.NORMAL;
}
}

View File

@ -2,6 +2,7 @@ package su.nightexpress.excellentenchants.api.enchantment.type;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
@ -12,4 +13,14 @@ public interface DeathEnchant extends IEnchantment {
boolean onDeath(@NotNull EntityDeathEvent event, @NotNull LivingEntity entity, ItemStack item, int level);
boolean onKill(@NotNull EntityDeathEvent event, @NotNull LivingEntity entity, @NotNull Player killer, int level);
@NotNull
default EventPriority getDeathPriority() {
return EventPriority.NORMAL;
}
@NotNull
default EventPriority getKillPriority() {
return EventPriority.NORMAL;
}
}

View File

@ -1,5 +1,6 @@
package su.nightexpress.excellentenchants.api.enchantment.type;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerFishEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
@ -8,4 +9,9 @@ import su.nightexpress.excellentenchants.api.enchantment.IEnchantment;
public interface FishingEnchant extends IEnchantment {
boolean onFishing(@NotNull PlayerFishEvent event, @NotNull ItemStack item, int level);
@NotNull
default EventPriority getFishingPriority() {
return EventPriority.NORMAL;
}
}

View File

@ -0,0 +1,7 @@
package su.nightexpress.excellentenchants.api.enchantment.type;
import su.nightexpress.excellentenchants.api.enchantment.IEnchantment;
public interface GenericEnchant extends IEnchantment {
}

View File

@ -1,6 +1,7 @@
package su.nightexpress.excellentenchants.api.enchantment.type;
import org.bukkit.entity.Player;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
@ -8,5 +9,10 @@ import su.nightexpress.excellentenchants.api.enchantment.IEnchantment;
public interface InteractEnchant extends IEnchantment {
boolean onInteract(@NotNull PlayerInteractEvent event, @NotNull Player player, @NotNull ItemStack item, int level);
boolean onInteract(@NotNull PlayerInteractEvent event, @NotNull LivingEntity entity, @NotNull ItemStack item, int level);
@NotNull
default EventPriority getInteractPriority() {
return EventPriority.NORMAL;
}
}

View File

@ -14,8 +14,8 @@ import su.nexmedia.engine.utils.random.Rnd;
import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.Perms;
import su.nightexpress.excellentenchants.config.Lang;
import su.nightexpress.excellentenchants.enchantment.EnchantRegistry;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.registry.EnchantRegistry;
import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils;
import su.nightexpress.excellentenchants.tier.Tier;

View File

@ -4,7 +4,7 @@ import su.nexmedia.engine.api.lang.LangKey;
import su.nexmedia.engine.lang.EngineLang;
import su.nightexpress.excellentenchants.Placeholders;
import static su.nexmedia.engine.utils.Colors.*;
import static su.nexmedia.engine.utils.Colors.RED;
public class Lang extends EngineLang {

View File

@ -5,7 +5,6 @@ import su.nexmedia.engine.api.manager.AbstractManager;
import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.enchantment.listener.EnchantAnvilListener;
import su.nightexpress.excellentenchants.enchantment.listener.EnchantGenericListener;
import su.nightexpress.excellentenchants.enchantment.listener.EnchantHandlerListener;
import su.nightexpress.excellentenchants.enchantment.menu.EnchantmentsListMenu;
import su.nightexpress.excellentenchants.enchantment.task.ArrowTrailsTask;
import su.nightexpress.excellentenchants.enchantment.task.PotionEffectsTask;
@ -26,7 +25,7 @@ public class EnchantManager extends AbstractManager<ExcellentEnchants> {
@Override
protected void onLoad() {
this.enchantmentsListMenu = new EnchantmentsListMenu(this.plugin);
this.addListener(new EnchantHandlerListener(this));
//this.addListener(new EnchantHandlerListener(this));
this.addListener(new EnchantGenericListener(this));
this.addListener(new EnchantAnvilListener(this.plugin));

View File

@ -1,11 +1,17 @@
package su.nightexpress.excellentenchants.enchantment;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import su.nexmedia.engine.utils.random.Rnd;
import su.nightexpress.excellentenchants.ExcellentEnchantsAPI;
import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.config.Config;
import su.nightexpress.excellentenchants.config.ObtainSettings;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.registry.EnchantRegistry;
import su.nightexpress.excellentenchants.enchantment.type.ObtainType;
import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils;
import su.nightexpress.excellentenchants.tier.Tier;
@ -14,45 +20,80 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Function;
import java.util.stream.Collectors;
public class EnchantPopulator {
private final ExcellentEnchants plugin;
private final ObtainType obtainType;
private final ItemStack item;
private final Map<Tier, Set<ExcellentEnchant>> enchants;
private final Map<Tier, Set<ExcellentEnchant>> candidates;
private final Map<Enchantment, Integer> population;
public EnchantPopulator(@NotNull ObtainType obtainType, @NotNull ItemStack item) {
this.obtainType = obtainType;
private World world;
private Function<ExcellentEnchant, Integer> levelGenerator;
public EnchantPopulator(@NotNull ExcellentEnchants plugin, @NotNull ItemStack item, @NotNull ObtainType obtainType) {
this.plugin = plugin;
this.item = item;
this.enchants = new HashMap<>();
this.obtainType = obtainType;
this.candidates = new HashMap<>();
this.population = new HashMap<>();
this.withLevelGenerator(enchant -> enchant.generateLevel(this.getObtainType()));
ExcellentEnchantsAPI.getTierManager().getTiers().forEach(tier -> {
this.fillDefaultCandidates();
}
@NotNull
public EnchantPopulator withWorld(@NotNull World world) {
this.world = world;
return this;
}
@NotNull
public EnchantPopulator withLevelGenerator(@NotNull Function<ExcellentEnchant, Integer> levelGenerator) {
this.levelGenerator = levelGenerator;
return this;
}
@NotNull
public EnchantPopulator withDefaultPopulation(@NotNull Map<Enchantment, Integer> population) {
this.getPopulation().putAll(population);
return this;
}
private void fillDefaultCandidates() {
this.plugin.getTierManager().getTiers().forEach(tier -> {
Set<ExcellentEnchant> enchants = EnchantRegistry.getOfTier(tier);
this.enchants.put(tier, EnchantUtils.populateFilter(enchants, obtainType, item));
enchants.removeIf(enchant -> {
if (enchant.getObtainChance(this.getObtainType()) <= 0D) return true;
if (!enchant.canEnchantItem(this.getItem())) return true;
return this.getObtainType() == ObtainType.ENCHANTING && (enchant.isTreasure() || enchant.isCursed());
});
this.candidates.put(tier, enchants);
});
}
public boolean isEmpty() {
return this.getEnchants().isEmpty() || this.getEnchants().values().stream().allMatch(Set::isEmpty);
return this.getCandidates().isEmpty() || this.getCandidates().values().stream().allMatch(Set::isEmpty);
}
public boolean isEmpty(@NotNull Tier tier) {
return this.getEnchants(tier).isEmpty();
return this.getCandidates(tier).isEmpty();
}
public void purge(@NotNull Tier tier) {
this.getEnchants().remove(tier);
this.getCandidates().remove(tier);
}
public void purge(@NotNull Tier tier, @NotNull ExcellentEnchant enchant) {
this.getEnchants(tier).remove(enchant);
this.getEnchants().keySet().removeIf(this::isEmpty);
}
@NotNull
public ObtainType getObtainType() {
return obtainType;
this.getCandidates(tier).remove(enchant);
this.getCandidates().keySet().removeIf(this::isEmpty);
}
@NotNull
@ -61,18 +102,38 @@ public class EnchantPopulator {
}
@NotNull
public Map<Tier, Set<ExcellentEnchant>> getEnchants() {
return this.enchants;
public ObtainType getObtainType() {
return obtainType;
}
@Nullable
public World getWorld() {
return world;
}
@NotNull
public Set<ExcellentEnchant> getEnchants(@NotNull Tier tier) {
return this.getEnchants().getOrDefault(tier, new HashSet<>());
public Function<ExcellentEnchant, Integer> getLevelGenerator() {
return levelGenerator;
}
@NotNull
public Map<Tier, Set<ExcellentEnchant>> getCandidates() {
return this.candidates;
}
@NotNull
public Set<ExcellentEnchant> getCandidates(@NotNull Tier tier) {
return this.getCandidates().getOrDefault(tier, new HashSet<>());
}
@NotNull
public Map<Enchantment, Integer> getPopulation() {
return this.population;
}
@Nullable
public Tier getTierByChance() {
Map<Tier, Double> map = this.getEnchants().keySet().stream()
Map<Tier, Double> map = this.getCandidates().keySet().stream()
.filter(tier -> tier.getChance(this.getObtainType()) > 0D)
.collect(Collectors.toMap(k -> k, v -> v.getChance(this.getObtainType()), (o, n) -> n, HashMap::new));
if (map.isEmpty()) return null;
@ -82,8 +143,86 @@ public class EnchantPopulator {
@Nullable
public ExcellentEnchant getEnchantByChance(@NotNull Tier tier) {
Map<ExcellentEnchant, Double> map = this.getEnchants(tier).stream()
Map<ExcellentEnchant, Double> map = this.getCandidates(tier).stream()
.collect(Collectors.toMap(k -> k, v -> v.getObtainChance(this.getObtainType())));
return map.isEmpty() ? null : Rnd.getByWeight(map);
}
@NotNull
public Map<Enchantment, Integer> createPopulation() {
Map<Enchantment, Integer> population = this.getPopulation();
ObtainSettings settings = Config.getObtainSettings(this.getObtainType()).orElse(null);
if (settings == null || !Rnd.chance(settings.getEnchantsCustomGenerationChance())) return population;
int enchantsLimit = settings.getEnchantsTotalMax();
int enchantsRolled = Rnd.get(settings.getEnchantsCustomMin(), settings.getEnchantsCustomMax());
// Try to populate as many as possible.
while (!this.isEmpty() && enchantsRolled > 0) {
// Limit reached.
if (population.size() >= enchantsLimit) break;
Tier tier = this.getTierByChance();
if (tier == null) break; // no tiers left.
ExcellentEnchant enchant = this.getEnchantByChance(tier);
// Remove entire tier if no enchants can be selected.
if (enchant == null) {
this.purge(tier);
continue;
}
// Remove disabled world enchants.
if (world != null && enchant.isDisabledInWorld(world)) {
this.purge(tier, enchant);
continue;
}
// Remove conflicting enchants.
if (population.keySet().stream().anyMatch(has -> has.conflictsWith(enchant) || enchant.conflictsWith(has))) {
this.purge(tier, enchant);
continue;
}
// Level generation failed.
int level = this.getLevelGenerator().apply(enchant);
if (level < enchant.getStartLevel()) {
this.purge(tier, enchant);
continue;
}
// All good!
this.purge(tier, enchant);
population.put(enchant, level);
enchantsRolled--;
}
return population;
}
public boolean populate() {
ItemStack item = this.getItem();
AtomicBoolean status = new AtomicBoolean(false);
var population = this.getPopulation().isEmpty() ? this.createPopulation() : this.getPopulation();
if (this.getObtainType() == ObtainType.VILLAGER && item.getType() == Material.ENCHANTED_BOOK) {
if (Config.ENCHANTMENTS_SINGLE_ENCHANT_IN_VILLAGER_BOOKS.get() && !population.isEmpty()) {
EnchantUtils.getAll(item).keySet().forEach(enchantment -> EnchantUtils.remove(item, enchantment));
}
}
population.forEach((enchantment, level) -> {
if (EnchantUtils.add(item, enchantment, level, false)) {
status.set(true);
}
});
if (status.get()) {
EnchantUtils.updateDisplay(item);
}
return status.get();
}
}

View File

@ -25,7 +25,6 @@ import su.nightexpress.excellentenchants.enchantment.EnchantManager;
import su.nightexpress.excellentenchants.enchantment.config.EnchantDefaults;
import su.nightexpress.excellentenchants.enchantment.type.FitItemType;
import su.nightexpress.excellentenchants.enchantment.type.ObtainType;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils;
import su.nightexpress.excellentenchants.tier.Tier;
@ -33,22 +32,20 @@ import java.util.*;
import java.util.function.Function;
import java.util.stream.Stream;
public abstract class ExcellentEnchant extends Enchantment implements IEnchantment, EventListener {
public abstract class ExcellentEnchant extends Enchantment implements IEnchantment {
protected final ExcellentEnchants plugin;
protected final JYML cfg;
protected final String id;
protected final EnchantPriority priority;
protected final EnchantDefaults defaults;
protected final NamespacedKey chargesKey;
protected final ExcellentEnchants plugin;
protected final JYML cfg;
protected final String id;
protected final EnchantDefaults defaults;
protected final NamespacedKey chargesKey;
protected final Map<Integer, PlaceholderMap> placeholdersMap;
public ExcellentEnchant(@NotNull ExcellentEnchants plugin, @NotNull String id, @NotNull EnchantPriority priority) {
public ExcellentEnchant(@NotNull ExcellentEnchants plugin, @NotNull String id) {
super(NamespacedKey.minecraft(id.toLowerCase()));
this.plugin = plugin;
this.id = this.getKey().getKey();
this.cfg = new JYML(plugin.getDataFolder() + EnchantManager.DIR_ENCHANTS, id + ".yml");
this.priority = priority;
this.chargesKey = new NamespacedKey(plugin, this.getId() + ".charges");
this.defaults = new EnchantDefaults(this);
this.placeholdersMap = new HashMap<>();
@ -111,9 +108,10 @@ public abstract class ExcellentEnchant extends Enchantment implements IEnchantme
}
}
@Override
public void registerListeners() {
this.plugin.getPluginManager().registerEvents(this, plugin);
if (this instanceof EventListener listener) {
this.plugin.getPluginManager().registerEvents(listener, plugin);
}
}
@NotNull
@ -127,6 +125,7 @@ public abstract class ExcellentEnchant extends Enchantment implements IEnchantme
return disabled.contains(this.getKey().getKey()) || disabled.contains(Placeholders.WILDCARD);
}
@Override
public boolean isAvailableToUse(@NotNull LivingEntity entity) {
return !this.isDisabledInWorld(entity.getWorld());
}
@ -141,11 +140,6 @@ public abstract class ExcellentEnchant extends Enchantment implements IEnchantme
return this.id;
}
@NotNull
public EnchantPriority getPriority() {
return priority;
}
@NotNull
public EnchantDefaults getDefaults() {
return defaults;

View File

@ -7,20 +7,19 @@ import org.bukkit.potion.PotionEffectType;
import org.jetbrains.annotations.NotNull;
import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.Placeholders;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.api.enchantment.meta.Potioned;
import su.nightexpress.excellentenchants.api.enchantment.type.PassiveEnchant;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.PotionImplementation;
public class EnchantAquaman extends ExcellentEnchant implements Potioned, PassiveEnchant {
public class AquamanEnchant extends ExcellentEnchant implements Potioned, PassiveEnchant {
public static final String ID = "aquaman";
private PotionImplementation potionImplementation;
public EnchantAquaman(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM);
public AquamanEnchant(@NotNull ExcellentEnchants plugin) {
super(plugin, ID);
this.getDefaults().setLevelMax(1);
this.getDefaults().setTier(0.4);
this.getDefaults().setDescription("Grants permanent " + Placeholders.ENCHANTMENT_POTION_TYPE + " " + Placeholders.ENCHANTMENT_POTION_LEVEL + " effect.");
@ -46,8 +45,6 @@ public class EnchantAquaman extends ExcellentEnchant implements Potioned, Passiv
@Override
public boolean onTrigger(@NotNull LivingEntity entity, @NotNull ItemStack item, int level) {
if (!this.isAvailableToUse(entity)) return false;
return this.addEffect(entity, level);
}
}

View File

@ -2,29 +2,29 @@ package su.nightexpress.excellentenchants.enchantment.impl.armor;
import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffectType;
import org.jetbrains.annotations.NotNull;
import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.Placeholders;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.api.enchantment.meta.Chanced;
import su.nightexpress.excellentenchants.api.enchantment.meta.Potioned;
import su.nightexpress.excellentenchants.api.enchantment.type.CombatEnchant;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.impl.meta.PotionImplementation;
public class EnchantColdSteel extends ExcellentEnchant implements Chanced, Potioned, CombatEnchant {
public class ColdSteelEnchant extends ExcellentEnchant implements Chanced, Potioned, CombatEnchant {
public static final String ID = "cold_steel";
private ChanceImplementation chanceImplementation;
private PotionImplementation potionImplementation;
public EnchantColdSteel(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM);
public ColdSteelEnchant(@NotNull ExcellentEnchants plugin) {
super(plugin, ID);
this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to apply " + Placeholders.ENCHANTMENT_POTION_TYPE + " " + Placeholders.ENCHANTMENT_POTION_LEVEL + " (" + Placeholders.ENCHANTMENT_POTION_DURATION + "s.) on attacker.");
this.getDefaults().setTier(0.3);
this.getDefaults().setLevelMax(3);
@ -60,6 +60,12 @@ public class EnchantColdSteel extends ExcellentEnchant implements Chanced, Potio
return EnchantmentTarget.ARMOR_TORSO;
}
@NotNull
@Override
public EventPriority getProtectPriority() {
return EventPriority.HIGHEST;
}
@Override
public boolean onAttack(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
return false;
@ -67,7 +73,6 @@ public class EnchantColdSteel extends ExcellentEnchant implements Chanced, Potio
@Override
public boolean onProtect(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
if (!this.isAvailableToUse(damager)) return false;
if (!this.checkTriggerChance(level)) return false;
return this.addEffect(damager, level);

View File

@ -3,6 +3,7 @@ package su.nightexpress.excellentenchants.enchantment.impl.armor;
import org.bukkit.Particle;
import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffectType;
@ -16,7 +17,6 @@ import su.nightexpress.excellentenchants.api.enchantment.type.CombatEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.impl.meta.PotionImplementation;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
public class DarknessCloakEnchant extends ExcellentEnchant implements Chanced, Potioned, CombatEnchant {
@ -26,7 +26,7 @@ public class DarknessCloakEnchant extends ExcellentEnchant implements Chanced, P
private PotionImplementation potionImplementation;
public DarknessCloakEnchant(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM);
super(plugin, ID);
this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to apply " + Placeholders.ENCHANTMENT_POTION_TYPE + " " + Placeholders.ENCHANTMENT_POTION_LEVEL + " (" + Placeholders.ENCHANTMENT_POTION_DURATION + "s.) on attacker.");
this.getDefaults().setLevelMax(3);
this.getDefaults().setTier(0.2);
@ -61,6 +61,12 @@ public class DarknessCloakEnchant extends ExcellentEnchant implements Chanced, P
return EnchantmentTarget.ARMOR_TORSO;
}
@NotNull
@Override
public EventPriority getProtectPriority() {
return EventPriority.HIGHEST;
}
@Override
public boolean onAttack(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
return false;
@ -68,7 +74,6 @@ public class DarknessCloakEnchant extends ExcellentEnchant implements Chanced, P
@Override
public boolean onProtect(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
if (!this.isAvailableToUse(victim)) return false;
if (!this.checkTriggerChance(level)) return false;
if (!this.addEffect(damager, level)) return false;

View File

@ -8,17 +8,18 @@ import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.api.config.JOption;
import su.nexmedia.engine.api.manager.EventListener;
import su.nexmedia.engine.utils.NumberUtil;
import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.Placeholders;
import su.nightexpress.excellentenchants.api.enchantment.type.GenericEnchant;
import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils;
import java.util.Set;
public class EnchantElementalProtection extends ExcellentEnchant {
public class ElementalProtectionEnchant extends ExcellentEnchant implements GenericEnchant, EventListener {
public static final String ID = "elemental_protection";
public static final String PLACEHOLDER_PROTECTION_AMOUNT = "%enchantment_protection_amount%";
@ -33,8 +34,8 @@ public class EnchantElementalProtection extends ExcellentEnchant {
private double protectionCapacity;
private boolean protectionAsModifier;
public EnchantElementalProtection(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM);
public ElementalProtectionEnchant(@NotNull ExcellentEnchants plugin) {
super(plugin, ID);
this.getDefaults().setDescription("Reduces Poison, Magic, Wither, Lightning, Freeze damage by " + PLACEHOLDER_PROTECTION_AMOUNT + ".");
this.getDefaults().setLevelMax(5);
this.getDefaults().setTier(0.2);
@ -76,9 +77,9 @@ public class EnchantElementalProtection extends ExcellentEnchant {
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onDamage(EntityDamageEvent e) {
if (!DAMAGE_CAUSES.contains(e.getCause())) return;
if (!(e.getEntity() instanceof LivingEntity entity)) return;
public void onDamage(EntityDamageEvent event) {
if (!DAMAGE_CAUSES.contains(event.getCause())) return;
if (!(event.getEntity() instanceof LivingEntity entity)) return;
if (!this.isAvailableToUse(entity)) return;
double protectionAmount = 0D;
@ -96,10 +97,10 @@ public class EnchantElementalProtection extends ExcellentEnchant {
}
if (this.isProtectionAsModifier()) {
e.setDamage(Math.max(0, e.getDamage() * (1D - protectionAmount)));
event.setDamage(Math.max(0, event.getDamage() * (1D - protectionAmount)));
}
else {
e.setDamage(Math.max(0, e.getDamage() - protectionAmount));
event.setDamage(Math.max(0, event.getDamage() - protectionAmount));
}
}
}

View File

@ -2,6 +2,7 @@ package su.nightexpress.excellentenchants.enchantment.impl.armor;
import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
@ -13,9 +14,8 @@ import su.nightexpress.excellentenchants.api.enchantment.type.CombatEnchant;
import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
public class EnchantFireShield extends ExcellentEnchant implements Chanced, CombatEnchant {
public class FireShieldEnchant extends ExcellentEnchant implements Chanced, CombatEnchant {
public static final String ID = "fire_shield";
public static final String PLACEHOLDER_FIRE_DURATION = "%enchantment_fire_duration%";
@ -23,8 +23,8 @@ public class EnchantFireShield extends ExcellentEnchant implements Chanced, Comb
private EnchantScaler fireDuration;
private ChanceImplementation chanceImplementation;
public EnchantFireShield(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM);
public FireShieldEnchant(@NotNull ExcellentEnchants plugin) {
super(plugin, ID);
this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to ignite the attacker for " + PLACEHOLDER_FIRE_DURATION + "s.");
this.getDefaults().setLevelMax(3);
this.getDefaults().setTier(0.4);
@ -57,6 +57,12 @@ public class EnchantFireShield extends ExcellentEnchant implements Chanced, Comb
return EnchantmentTarget.ARMOR;
}
@NotNull
@Override
public EventPriority getProtectPriority() {
return EventPriority.HIGHEST;
}
public double getFireDuration(int level) {
return this.fireDuration.getValue(level);
}
@ -70,7 +76,6 @@ public class EnchantFireShield extends ExcellentEnchant implements Chanced, Comb
public boolean onProtect(@NotNull EntityDamageByEntityEvent event,
@NotNull LivingEntity damager, @NotNull LivingEntity victim,
@NotNull ItemStack weapon, int level) {
if (!this.isAvailableToUse(victim)) return false;
if (!this.checkTriggerChance(level)) return false;
int ticksToSet = (int) (this.getFireDuration(level) * 20);

View File

@ -19,15 +19,16 @@ import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.Version;
import su.nexmedia.engine.api.manager.EventListener;
import su.nexmedia.engine.api.server.AbstractTask;
import su.nexmedia.engine.utils.Pair;
import su.nexmedia.engine.utils.random.Rnd;
import su.nexmedia.engine.utils.values.UniParticle;
import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.api.enchantment.Cleanable;
import su.nightexpress.excellentenchants.api.enchantment.type.GenericEnchant;
import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils;
import java.util.List;
@ -36,7 +37,7 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;
public class EnchantFlameWalker extends ExcellentEnchant implements Cleanable {
public class FlameWalkerEnchant extends ExcellentEnchant implements GenericEnchant, EventListener, Cleanable {
public static final String ID = "flame_walker";
@ -46,8 +47,8 @@ public class EnchantFlameWalker extends ExcellentEnchant implements Cleanable {
private EnchantScaler blockDecayTime;
private BlockTickTask blockTickTask;
public EnchantFlameWalker(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM);
public FlameWalkerEnchant(@NotNull ExcellentEnchants plugin) {
super(plugin, ID);
this.getDefaults().setDescription("Ability to walk on lava and magma blocks without getting damage.");
this.getDefaults().setLevelMax(3);
this.getDefaults().setTier(0.7);
@ -93,12 +94,12 @@ public class EnchantFlameWalker extends ExcellentEnchant implements Cleanable {
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPlayerMove(PlayerMoveEvent e) {
Player player = e.getPlayer();
public void onPlayerMove(PlayerMoveEvent event) {
Player player = event.getPlayer();
if (player.isFlying() || !this.isAvailableToUse(player)) return;
Location from = e.getFrom();
Location to = e.getTo();
Location from = event.getFrom();
Location to = event.getTo();
if (to == null) return;
if (from.getX() == to.getX() && from.getY() == to.getY() && from.getZ() == to.getZ()) return;
@ -147,9 +148,9 @@ public class EnchantFlameWalker extends ExcellentEnchant implements Cleanable {
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onMagmaDamage(EntityDamageEvent e) {
if (e.getCause() != EntityDamageEvent.DamageCause.HOT_FLOOR) return;
if (!(e.getEntity() instanceof LivingEntity livingEntity)) return;
public void onMagmaDamage(EntityDamageEvent event) {
if (event.getCause() != EntityDamageEvent.DamageCause.HOT_FLOOR) return;
if (!(event.getEntity() instanceof LivingEntity livingEntity)) return;
if (!this.isAvailableToUse(livingEntity)) return;
EntityEquipment equipment = livingEntity.getEquipment();
@ -161,7 +162,7 @@ public class EnchantFlameWalker extends ExcellentEnchant implements Cleanable {
int level = EnchantUtils.getLevel(boots, this);
if (level <= 0) return;
e.setCancelled(true);
event.setCancelled(true);
}
static class BlockTickTask extends AbstractTask<ExcellentEnchants> {

View File

@ -2,6 +2,7 @@ package su.nightexpress.excellentenchants.enchantment.impl.armor;
import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffectType;
@ -14,17 +15,16 @@ import su.nightexpress.excellentenchants.api.enchantment.type.CombatEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.impl.meta.PotionImplementation;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
public class EnchantHardened extends ExcellentEnchant implements Chanced, Potioned, CombatEnchant {
public class HardenedEnchant extends ExcellentEnchant implements Chanced, Potioned, CombatEnchant {
public static final String ID = "hardened";
private ChanceImplementation chanceImplementation;
private PotionImplementation potionImplementation;
public EnchantHardened(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM);
public HardenedEnchant(@NotNull ExcellentEnchants plugin) {
super(plugin, ID);
this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to obtain " + Placeholders.ENCHANTMENT_POTION_TYPE + " " + Placeholders.ENCHANTMENT_POTION_LEVEL + " (" + Placeholders.ENCHANTMENT_POTION_DURATION + "s.) when damaged.");
this.getDefaults().setLevelMax(3);
this.getDefaults().setTier(0.4);
@ -59,6 +59,12 @@ public class EnchantHardened extends ExcellentEnchant implements Chanced, Potion
return EnchantmentTarget.ARMOR_TORSO;
}
@NotNull
@Override
public EventPriority getProtectPriority() {
return EventPriority.HIGHEST;
}
@Override
public boolean onAttack(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
return false;
@ -66,7 +72,6 @@ public class EnchantHardened extends ExcellentEnchant implements Chanced, Potion
@Override
public boolean onProtect(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
if (!this.isAvailableToUse(damager)) return false;
if (!this.checkTriggerChance(level)) return false;
return this.addEffect(victim, level);

View File

@ -3,6 +3,7 @@ package su.nightexpress.excellentenchants.enchantment.impl.armor;
import org.bukkit.Material;
import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffectType;
@ -16,17 +17,16 @@ import su.nightexpress.excellentenchants.api.enchantment.type.CombatEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.impl.meta.PotionImplementation;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
public class EnchantIceShield extends ExcellentEnchant implements Chanced, Potioned, CombatEnchant {
public class IceShieldEnchant extends ExcellentEnchant implements Chanced, Potioned, CombatEnchant {
public static final String ID = "ice_shield";
private ChanceImplementation chanceImplementation;
private PotionImplementation potionImplementation;
public EnchantIceShield(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM);
public IceShieldEnchant(@NotNull ExcellentEnchants plugin) {
super(plugin, ID);
this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to freeze and apply " + Placeholders.ENCHANTMENT_POTION_TYPE + " " + Placeholders.ENCHANTMENT_POTION_LEVEL + " (" + Placeholders.ENCHANTMENT_POTION_DURATION + "s.) on attacker.");
this.getDefaults().setLevelMax(3);
this.getDefaults().setTier(0.1);
@ -47,6 +47,12 @@ public class EnchantIceShield extends ExcellentEnchant implements Chanced, Potio
return EnchantmentTarget.ARMOR_TORSO;
}
@NotNull
@Override
public EventPriority getProtectPriority() {
return EventPriority.HIGHEST;
}
@Override
@NotNull
public Chanced getChanceImplementation() {
@ -66,7 +72,6 @@ public class EnchantIceShield extends ExcellentEnchant implements Chanced, Potio
@Override
public boolean onProtect(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
if (!this.isAvailableToUse(victim)) return false;
if (!this.checkTriggerChance(level)) return false;
if (!this.addEffect(damager, level)) return false;

View File

@ -7,20 +7,19 @@ import org.bukkit.potion.PotionEffectType;
import org.jetbrains.annotations.NotNull;
import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.Placeholders;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.api.enchantment.meta.Potioned;
import su.nightexpress.excellentenchants.api.enchantment.type.PassiveEnchant;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.PotionImplementation;
public class EnchantBunnyHop extends ExcellentEnchant implements Potioned, PassiveEnchant {
public class JumpingEnchant extends ExcellentEnchant implements Potioned, PassiveEnchant {
public static final String ID = "bunny_hop";
private PotionImplementation potionImplementation;
public EnchantBunnyHop(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM);
public JumpingEnchant(@NotNull ExcellentEnchants plugin) {
super(plugin, ID);
this.getDefaults().setLevelMax(3);
this.getDefaults().setTier(0.1);
this.getDefaults().setDescription("Grants permanent " + Placeholders.ENCHANTMENT_POTION_TYPE + " " + Placeholders.ENCHANTMENT_POTION_LEVEL + " effect.");
@ -46,8 +45,6 @@ public class EnchantBunnyHop extends ExcellentEnchant implements Potioned, Passi
@Override
public boolean onTrigger(@NotNull LivingEntity entity, @NotNull ItemStack item, int level) {
if (!this.isAvailableToUse(entity)) return false;
return this.addEffect(entity, level);
}
}

View File

@ -1,6 +1,7 @@
package su.nightexpress.excellentenchants.enchantment.impl.armor;
import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Item;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
@ -9,7 +10,6 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.FixedMetadataValue;
import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.utils.NumberUtil;
import su.nightexpress.excellentenchants.ExcellentEnchants;
@ -19,20 +19,19 @@ import su.nightexpress.excellentenchants.api.enchantment.type.DeathEnchant;
import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
public class EnchantSelfDestruction extends ExcellentEnchant implements Chanced, DeathEnchant {
public class KamikadzeEnchant extends ExcellentEnchant implements Chanced, DeathEnchant {
public static final String ID = "self_destruction";
private static final String META_EXPLOSION_SOURCE = ID + "_explosion_source";
private static final String PLACEHOLDER_EXPLOSION_POWER = "%enchantment_explosion_power%";
private EnchantScaler explosionSize;
private ChanceImplementation chanceImplementation;
public EnchantSelfDestruction(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM);
private Entity exploder;
public KamikadzeEnchant(@NotNull ExcellentEnchants plugin) {
super(plugin, ID);
this.getDefaults().setDescription("%enchantment_trigger_chance%% chance to create an explosion on death.");
this.getDefaults().setLevelMax(3);
this.getDefaults().setTier(0.3);
@ -68,13 +67,12 @@ public class EnchantSelfDestruction extends ExcellentEnchant implements Chanced,
@Override
public boolean onDeath(@NotNull EntityDeathEvent event, @NotNull LivingEntity entity, ItemStack item, int level) {
if (!this.isAvailableToUse(entity)) return false;
if (!this.checkTriggerChance(level)) return false;
float size = (float) this.getExplosionSize(level);
entity.setMetadata(META_EXPLOSION_SOURCE, new FixedMetadataValue(plugin, true));
this.exploder = entity;
boolean exploded = entity.getWorld().createExplosion(entity.getLocation(), size, false, false, entity);
entity.removeMetadata(META_EXPLOSION_SOURCE, plugin);
this.exploder = null;
return exploded;
}
@ -84,10 +82,10 @@ public class EnchantSelfDestruction extends ExcellentEnchant implements Chanced,
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onItemDamage(EntityDamageByEntityEvent e) {
if (!e.getDamager().hasMetadata(META_EXPLOSION_SOURCE)) return;
if (!(e.getEntity() instanceof Item item)) return;
public void onItemDamage(EntityDamageByEntityEvent event) {
if (this.exploder == null || event.getDamager() != this.exploder) return;
if (!(event.getEntity() instanceof Item item)) return;
e.setCancelled(true);
event.setCancelled(true);
}
}

View File

@ -7,20 +7,19 @@ import org.bukkit.potion.PotionEffectType;
import org.jetbrains.annotations.NotNull;
import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.Placeholders;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.api.enchantment.meta.Potioned;
import su.nightexpress.excellentenchants.api.enchantment.type.PassiveEnchant;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.PotionImplementation;
public class EnchantNightVision extends ExcellentEnchant implements Potioned, PassiveEnchant {
public class NightVisionEnchant extends ExcellentEnchant implements Potioned, PassiveEnchant {
public static final String ID = "night_vision";
private PotionImplementation potionImplementation;
public EnchantNightVision(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM);
public NightVisionEnchant(@NotNull ExcellentEnchants plugin) {
super(plugin, ID);
this.getDefaults().setDescription("Grants permanent " + Placeholders.ENCHANTMENT_POTION_TYPE + " " + Placeholders.ENCHANTMENT_POTION_LEVEL + " effect.");
this.getDefaults().setLevelMax(1);
this.getDefaults().setTier(0.7);
@ -46,8 +45,6 @@ public class EnchantNightVision extends ExcellentEnchant implements Potioned, Pa
@Override
public boolean onTrigger(@NotNull LivingEntity entity, @NotNull ItemStack item, int level) {
if (!this.isAvailableToUse(entity)) return false;
return this.addEffect(entity, level);
}
}

View File

@ -19,10 +19,9 @@ import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.task.AbstractEnchantmentTask;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils;
public class EnchantRegrowth extends ExcellentEnchant implements Chanced, PassiveEnchant, Cleanable {
public class RegrowthEnchant extends ExcellentEnchant implements Chanced, PassiveEnchant, Cleanable {
public static final String ID = "regrowth";
@ -39,8 +38,8 @@ public class EnchantRegrowth extends ExcellentEnchant implements Chanced, Passiv
private ChanceImplementation chanceImplementation;
private Task task;
public EnchantRegrowth(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM);
public RegrowthEnchant(@NotNull ExcellentEnchants plugin) {
super(plugin, ID);
this.getDefaults().setDescription("Restores " + PLACEHOLDER_HEAL_AMOUNT + " hearts every " + PLACEHOLDER_HEAL_INTERVAL + "s.");
this.getDefaults().setLevelMax(5);
this.getDefaults().setTier(0.7);
@ -111,7 +110,6 @@ public class EnchantRegrowth extends ExcellentEnchant implements Chanced, Passiv
@Override
public boolean onTrigger(@NotNull LivingEntity entity, @NotNull ItemStack item, int level) {
if (!this.isAvailableToUse(entity)) return false;
if (!this.checkTriggerChance(level)) return false;
double healthMax = EntityUtil.getAttribute(entity, Attribute.GENERIC_MAX_HEALTH);
@ -137,7 +135,7 @@ public class EnchantRegrowth extends ExcellentEnchant implements Chanced, Passiv
@Override
public void action() {
for (LivingEntity entity : this.getEntities()) {
EnchantUtils.getEquipped(entity, EnchantRegrowth.class).forEach((item, enchants) -> {
EnchantUtils.getEquipped(entity, RegrowthEnchant.class).forEach((item, enchants) -> {
enchants.forEach((enchant, level) -> {
if (enchant.isOutOfCharges(item)) return;
if (enchant.onTrigger(entity, item, level)) {

View File

@ -14,10 +14,9 @@ import su.nightexpress.excellentenchants.api.enchantment.type.PassiveEnchant;
import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.task.AbstractEnchantmentTask;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils;
public class EnchantSaturation extends ExcellentEnchant implements PassiveEnchant, Cleanable {
public class SaturationEnchant extends ExcellentEnchant implements PassiveEnchant, Cleanable {
public static final String ID = "saturation";
@ -31,8 +30,8 @@ public class EnchantSaturation extends ExcellentEnchant implements PassiveEnchan
private Task task;
public EnchantSaturation(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM);
public SaturationEnchant(@NotNull ExcellentEnchants plugin) {
super(plugin, ID);
this.getDefaults().setDescription("Restores " + PLACEHOLDER_SATURATION_AMOUNT + " food points every " + PLACEHOLDER_SATURATION_INTERVAL + "s.");
this.getDefaults().setLevelMax(3);
this.getDefaults().setTier(0.5);
@ -88,13 +87,11 @@ public class EnchantSaturation extends ExcellentEnchant implements PassiveEnchan
@Override
public boolean onTrigger(@NotNull LivingEntity entity, @NotNull ItemStack item, int level) {
if (!this.isAvailableToUse(entity)) return false;
if (!(entity instanceof Player player)) return false;
if (player.getFoodLevel() >= this.getMaxFoodLevel(level)) return false;
int amount = this.getSaturationAmount(level);
player.setFoodLevel(Math.min(20, player.getFoodLevel() + amount));
player.setSaturation(Math.min(20, player.getSaturation() + amount));
return true;
}
@ -107,7 +104,7 @@ public class EnchantSaturation extends ExcellentEnchant implements PassiveEnchan
@Override
public void action() {
for (LivingEntity entity : this.getEntities()) {
EnchantUtils.getEquipped(entity, EnchantSaturation.class).forEach((item, enchants) -> {
EnchantUtils.getEquipped(entity, SaturationEnchant.class).forEach((item, enchants) -> {
enchants.forEach((enchant, level) -> {
if (enchant.isOutOfCharges(item)) return;
if (enchant.onTrigger(entity, item, level)) {

View File

@ -7,20 +7,19 @@ import org.bukkit.potion.PotionEffectType;
import org.jetbrains.annotations.NotNull;
import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.Placeholders;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.api.enchantment.meta.Potioned;
import su.nightexpress.excellentenchants.api.enchantment.type.PassiveEnchant;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.PotionImplementation;
public class EnchantSonic extends ExcellentEnchant implements Potioned, PassiveEnchant {
public class SpeedyEnchant extends ExcellentEnchant implements Potioned, PassiveEnchant {
public static final String ID = "sonic";
private PotionImplementation potionImplementation;
public EnchantSonic(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM);
public SpeedyEnchant(@NotNull ExcellentEnchants plugin) {
super(plugin, ID);
this.getDefaults().setDescription("Grants permanent " + Placeholders.ENCHANTMENT_POTION_TYPE + " " + Placeholders.ENCHANTMENT_POTION_LEVEL + " effect.");
this.getDefaults().setLevelMax(3);
this.getDefaults().setTier(0.3);
@ -46,8 +45,6 @@ public class EnchantSonic extends ExcellentEnchant implements Potioned, PassiveE
@Override
public boolean onTrigger(@NotNull LivingEntity entity, @NotNull ItemStack item, int level) {
if (!this.isAvailableToUse(entity)) return false;
return this.addEffect(entity, level);
}
}

View File

@ -2,6 +2,7 @@ package su.nightexpress.excellentenchants.enchantment.impl.armor;
import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
@ -13,7 +14,6 @@ import su.nightexpress.excellentenchants.api.enchantment.type.CombatEnchant;
import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
public class StoppingForceEnchant extends ExcellentEnchant implements Chanced, CombatEnchant {
@ -25,7 +25,7 @@ public class StoppingForceEnchant extends ExcellentEnchant implements Chanced, C
private EnchantScaler knockbackModifier;
public StoppingForceEnchant(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM);
super(plugin, ID);
this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to resist knockback in combat by " + PLACEHOLDER_KNOCKBACK_RESISTANCE + "%.");
this.getDefaults().setLevelMax(3);
this.getDefaults().setTier(0.5);
@ -52,6 +52,12 @@ public class StoppingForceEnchant extends ExcellentEnchant implements Chanced, C
return EnchantmentTarget.ARMOR_LEGS;
}
@NotNull
@Override
public EventPriority getProtectPriority() {
return EventPriority.HIGHEST;
}
@NotNull
@Override
public Chanced getChanceImplementation() {
@ -65,7 +71,6 @@ public class StoppingForceEnchant extends ExcellentEnchant implements Chanced, C
@Override
public boolean onProtect(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
if (!this.isAvailableToUse(victim)) return false;
if (!this.checkTriggerChance(level)) return false;
this.plugin.runTask(task -> {

View File

@ -23,7 +23,6 @@ import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ArrowImplementation;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.impl.meta.PotionImplementation;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
public class DarknessArrowsEnchant extends ExcellentEnchant implements Chanced, Arrowed, Potioned, BowEnchant {
@ -34,7 +33,7 @@ public class DarknessArrowsEnchant extends ExcellentEnchant implements Chanced,
private PotionImplementation potionImplementation;
public DarknessArrowsEnchant(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM);
super(plugin, ID);
this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to launch an arrow with " + Placeholders.ENCHANTMENT_POTION_TYPE + " " + Placeholders.ENCHANTMENT_POTION_LEVEL + " (" + Placeholders.ENCHANTMENT_POTION_DURATION + "s.)");
this.getDefaults().setLevelMax(3);
this.getDefaults().setTier(0.1);
@ -78,7 +77,6 @@ public class DarknessArrowsEnchant extends ExcellentEnchant implements Chanced,
@Override
public boolean onShoot(@NotNull EntityShootBowEvent event, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) {
if (!this.isAvailableToUse(shooter)) return false;
if (!(event.getProjectile() instanceof Arrow arrow)) return false;
if (!this.checkTriggerChance(level)) return false;
@ -87,12 +85,12 @@ public class DarknessArrowsEnchant extends ExcellentEnchant implements Chanced,
}
@Override
public boolean onHit(@NotNull ProjectileHitEvent event, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) {
return this.isOurProjectile(projectile);
public boolean onHit(@NotNull ProjectileHitEvent event, LivingEntity user, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) {
return false;
}
@Override
public boolean onDamage(@NotNull EntityDamageByEntityEvent event, @NotNull Projectile projectile, @NotNull LivingEntity shooter, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
return this.isOurProjectile(projectile);
return false;
}
}

View File

@ -5,6 +5,7 @@ import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityShootBowEvent;
import org.bukkit.event.entity.ProjectileHitEvent;
@ -18,7 +19,6 @@ import su.nightexpress.excellentenchants.api.enchantment.type.BowEnchant;
import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
public class EnchantBomber extends ExcellentEnchant implements Chanced, BowEnchant {
@ -29,7 +29,7 @@ public class EnchantBomber extends ExcellentEnchant implements Chanced, BowEncha
private ChanceImplementation chanceImplementation;
public EnchantBomber(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.HIGHEST);
super(plugin, ID);
this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to launch TNT that explodes in " + PLACEHOLDER_FUSE_TICKS + "s.");
this.getDefaults().setLevelMax(3);
this.getDefaults().setTier(0.7);
@ -73,9 +73,14 @@ public class EnchantBomber extends ExcellentEnchant implements Chanced, BowEncha
return EnchantmentTarget.BOW;
}
@NotNull
@Override
public EventPriority getShootPriority() {
return EventPriority.LOWEST;
}
@Override
public boolean onShoot(@NotNull EntityShootBowEvent event, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) {
if (!this.isAvailableToUse(shooter)) return false;
if (!this.checkTriggerChance(level)) return false;
if (!(event.getProjectile() instanceof Projectile projectile)) return false;
@ -88,7 +93,7 @@ public class EnchantBomber extends ExcellentEnchant implements Chanced, BowEncha
}
@Override
public boolean onHit(@NotNull ProjectileHitEvent event, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) {
public boolean onHit(@NotNull ProjectileHitEvent event, LivingEntity user, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) {
return false;
}

View File

@ -23,7 +23,6 @@ import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ArrowImplementation;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.impl.meta.PotionImplementation;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
public class EnchantConfusingArrows extends ExcellentEnchant implements Chanced, Arrowed, Potioned, BowEnchant {
@ -34,7 +33,7 @@ public class EnchantConfusingArrows extends ExcellentEnchant implements Chanced,
private PotionImplementation potionImplementation;
public EnchantConfusingArrows(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM);
super(plugin, ID);
this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to launch an arrow with " + Placeholders.ENCHANTMENT_POTION_TYPE + " " + Placeholders.ENCHANTMENT_POTION_LEVEL + " (" + Placeholders.ENCHANTMENT_POTION_DURATION + "s.)");
this.getDefaults().setLevelMax(3);
this.getDefaults().setTier(0.1);
@ -78,7 +77,6 @@ public class EnchantConfusingArrows extends ExcellentEnchant implements Chanced,
@Override
public boolean onShoot(@NotNull EntityShootBowEvent event, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) {
if (!this.isAvailableToUse(shooter)) return false;
if (!(event.getProjectile() instanceof Arrow arrow)) return false;
if (!this.checkTriggerChance(level)) return false;
@ -87,12 +85,12 @@ public class EnchantConfusingArrows extends ExcellentEnchant implements Chanced,
}
@Override
public boolean onHit(@NotNull ProjectileHitEvent event, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) {
return this.isOurProjectile(projectile);
public boolean onHit(@NotNull ProjectileHitEvent event, LivingEntity user, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) {
return false;
}
@Override
public boolean onDamage(@NotNull EntityDamageByEntityEvent event, @NotNull Projectile projectile, @NotNull LivingEntity shooter, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
return this.isOurProjectile(projectile);
return false;
}
}

View File

@ -31,7 +31,6 @@ import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ArrowImplementation;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
public class EnchantDragonfireArrows extends ExcellentEnchant implements Chanced, Arrowed, BowEnchant {
@ -47,7 +46,7 @@ public class EnchantDragonfireArrows extends ExcellentEnchant implements Chanced
private ChanceImplementation chanceImplementation;
public EnchantDragonfireArrows(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM);
super(plugin, ID);
this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to launch an dragonfire arrow (R=" + PLACEHOLDER_FIRE_RADIUS + ", " + PLACEHOLDER_FIRE_DURATION + "s).");
this.getDefaults().setLevelMax(3);
this.getDefaults().setTier(0.7);
@ -99,19 +98,17 @@ public class EnchantDragonfireArrows extends ExcellentEnchant implements Chanced
@Override
public boolean onShoot(@NotNull EntityShootBowEvent event, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) {
if (!this.isAvailableToUse(shooter)) return false;
return this.checkTriggerChance(level);
}
@Override
public boolean onHit(@NotNull ProjectileHitEvent event, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) {
public boolean onHit(@NotNull ProjectileHitEvent event, LivingEntity user, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) {
if (!this.isOurProjectile(projectile)) return false;
if (event.getHitEntity() != null) return false;
if (projectile.getShooter() == null) return false;
this.createCloud(projectile.getShooter(), projectile.getLocation() , level);
return true;
return false;
}
@Override
@ -119,7 +116,7 @@ public class EnchantDragonfireArrows extends ExcellentEnchant implements Chanced
if (!this.isOurProjectile(projectile)) return false;
this.createCloud(shooter, victim.getLocation(), level);
return true;
return false;
}
private void createCloud(@NotNull ProjectileSource shooter, @NotNull Location location, int level) {

View File

@ -26,7 +26,6 @@ import su.nightexpress.excellentenchants.api.enchantment.type.BowEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ArrowImplementation;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
public class EnchantElectrifiedArrows extends ExcellentEnchant implements Chanced, Arrowed, BowEnchant {
@ -38,7 +37,7 @@ public class EnchantElectrifiedArrows extends ExcellentEnchant implements Chance
private ChanceImplementation chanceImplementation;
public EnchantElectrifiedArrows(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM);
super(plugin, ID);
this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to launch an electrified arrow.");
this.getDefaults().setLevelMax(3);
this.getDefaults().setTier(0.3);
@ -73,13 +72,11 @@ public class EnchantElectrifiedArrows extends ExcellentEnchant implements Chance
@Override
public boolean onShoot(@NotNull EntityShootBowEvent event, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) {
if (!this.isAvailableToUse(shooter)) return false;
return this.checkTriggerChance(level);
}
@Override
public boolean onHit(@NotNull ProjectileHitEvent event, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) {
public boolean onHit(@NotNull ProjectileHitEvent event, LivingEntity user, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) {
if (!this.isOurProjectile(projectile)) return false;
if (event.getHitEntity() != null || event.getHitBlock() == null) return false;
@ -90,7 +87,7 @@ public class EnchantElectrifiedArrows extends ExcellentEnchant implements Chance
UniParticle.blockCrack(block.getType()).play(center, 1, 0.05, 120);
UniParticle.of(Particle.FIREWORKS_SPARK).play(center, 1, 0.05, 120);
}
return true;
return false;
}
@Override
@ -103,7 +100,7 @@ public class EnchantElectrifiedArrows extends ExcellentEnchant implements Chance
victim.getWorld().strikeLightning(victim.getLocation()).setMetadata(META_NO_ITEM_DAMAGE, new FixedMetadataValue(plugin, true));
});
return true;
return false;
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)

View File

@ -5,16 +5,16 @@ import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.EnderPearl;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Projectile;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityShootBowEvent;
import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.api.enchantment.meta.Chanced;
import su.nightexpress.excellentenchants.api.enchantment.type.BowEnchant;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
public class EnchantEnderBow extends ExcellentEnchant implements BowEnchant, Chanced {
@ -24,7 +24,7 @@ public class EnchantEnderBow extends ExcellentEnchant implements BowEnchant, Cha
private ChanceImplementation chanceImplementation;
public EnchantEnderBow(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.HIGHEST);
super(plugin, ID);
this.getDefaults().setDescription("Shoots ender pearls instead of arrows.");
this.getDefaults().setLevelMax(1);
this.getDefaults().setTier(1.0);
@ -59,9 +59,14 @@ public class EnchantEnderBow extends ExcellentEnchant implements BowEnchant, Cha
return EnchantmentTarget.BOW;
}
@NotNull
@Override
public EventPriority getShootPriority() {
return EventPriority.LOWEST;
}
@Override
public boolean onShoot(@NotNull EntityShootBowEvent event, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) {
if (!this.isAvailableToUse(shooter)) return false;
if (!this.checkTriggerChance(level)) return false;
if (!(event.getProjectile() instanceof Projectile projectile)) return false;
@ -72,7 +77,7 @@ public class EnchantEnderBow extends ExcellentEnchant implements BowEnchant, Cha
}
@Override
public boolean onHit(@NotNull ProjectileHitEvent event, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) {
public boolean onHit(@NotNull ProjectileHitEvent event, LivingEntity user, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) {
return false;
}

View File

@ -11,7 +11,6 @@ import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityShootBowEvent;
import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.FixedMetadataValue;
import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.api.config.JOption;
import su.nexmedia.engine.utils.NumberUtil;
@ -25,15 +24,12 @@ import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ArrowImplementation;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
public class EnchantExplosiveArrows extends ExcellentEnchant implements Chanced, Arrowed, BowEnchant {
public static final String ID = "explosive_arrows";
public static final String PLACEHOLDER_EXPLOSION_POWER = "%enchantment_explosion_power%";
private static final String META_EXPLOSION_SOURCE = ID + "_source";
private boolean explosionFireSpread;
private boolean explosionDamageItems;
private boolean explosionDamageBlocks;
@ -42,8 +38,10 @@ public class EnchantExplosiveArrows extends ExcellentEnchant implements Chanced,
private ArrowImplementation arrowImplementation;
private ChanceImplementation chanceImplementation;
private Entity lastExploder;
public EnchantExplosiveArrows(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM);
super(plugin, ID);
this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to launch an explosive arrow.");
this.getDefaults().setLevelMax(3);
this.getDefaults().setTier(0.7);
@ -101,43 +99,39 @@ public class EnchantExplosiveArrows extends ExcellentEnchant implements Chanced,
@Override
public boolean onShoot(@NotNull EntityShootBowEvent event, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) {
if (!this.isAvailableToUse(shooter)) return false;
return this.checkTriggerChance(level);
}
@Override
public boolean onHit(@NotNull ProjectileHitEvent event, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) {
public boolean onHit(@NotNull ProjectileHitEvent event, LivingEntity user, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) {
if (!this.isOurProjectile(projectile)) return false;
Entity shooter = null;
if (projectile.getShooter() instanceof Entity entity) {
shooter = entity;
shooter.setMetadata(META_EXPLOSION_SOURCE, new FixedMetadataValue(this.plugin, true));
this.lastExploder = entity;
}
World world = projectile.getWorld();
float explSize = (float) this.getExplosionSize(level);
boolean explFire = this.isExplosionFireSpread();
boolean explBlocks = this.isExplosionDamageBlocks();
boolean exploded = world.createExplosion(projectile.getLocation(), explSize, explFire, explBlocks, shooter);
if (shooter != null) shooter.removeMetadata(META_EXPLOSION_SOURCE, this.plugin);
return exploded;
boolean exploded = world.createExplosion(projectile.getLocation(), explSize, explFire, explBlocks, this.lastExploder);
this.lastExploder = null;
return false;
}
@Override
public boolean onDamage(@NotNull EntityDamageByEntityEvent event, @NotNull Projectile projectile, @NotNull LivingEntity shooter, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
return this.isOurProjectile(projectile);
return false;
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onItemDamage(EntityDamageByEntityEvent e) {
if (e.getCause() != EntityDamageEvent.DamageCause.ENTITY_EXPLOSION) return;
public void onItemDamage(EntityDamageByEntityEvent event) {
if (event.getCause() != EntityDamageEvent.DamageCause.ENTITY_EXPLOSION) return;
if (this.explosionDamageItems) return;
if (!e.getDamager().hasMetadata(META_EXPLOSION_SOURCE)) return;
if (this.lastExploder == null || this.lastExploder != event.getDamager()) return;
if (e.getEntity() instanceof Item || e.getEntity() instanceof ItemFrame) {
e.setCancelled(true);
if (event.getEntity() instanceof Item || event.getEntity() instanceof ItemFrame) {
event.setCancelled(true);
}
}
}

View File

@ -6,6 +6,7 @@ import org.bukkit.entity.Fireball;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.SmallFireball;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityShootBowEvent;
import org.bukkit.event.entity.ProjectileHitEvent;
@ -14,11 +15,10 @@ import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.api.config.JOption;
import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.Placeholders;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.api.enchantment.meta.Chanced;
import su.nightexpress.excellentenchants.api.enchantment.type.BowEnchant;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils;
@ -31,7 +31,7 @@ public class EnchantGhast extends ExcellentEnchant implements BowEnchant, Chance
private ChanceImplementation chanceImplementation;
public EnchantGhast(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.HIGHEST);
super(plugin, ID);
this.getDefaults().setDescription("Shoots fireballs instead of arrows.");
this.getDefaults().setLevelMax(1);
this.getDefaults().setTier(0.3);
@ -78,9 +78,14 @@ public class EnchantGhast extends ExcellentEnchant implements BowEnchant, Chance
return EnchantmentTarget.BOW;
}
@NotNull
@Override
public EventPriority getShootPriority() {
return EventPriority.LOWEST;
}
@Override
public boolean onShoot(@NotNull EntityShootBowEvent event, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) {
if (!this.isAvailableToUse(shooter)) return false;
if (!this.checkTriggerChance(level)) return false;
if (!(event.getProjectile() instanceof Projectile projectile)) return false;
@ -104,7 +109,7 @@ public class EnchantGhast extends ExcellentEnchant implements BowEnchant, Chance
}
@Override
public boolean onHit(@NotNull ProjectileHitEvent event, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) {
public boolean onHit(@NotNull ProjectileHitEvent event, LivingEntity user, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) {
return false;
}

View File

@ -23,7 +23,6 @@ import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ArrowImplementation;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.impl.meta.PotionImplementation;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
public class EnchantHover extends ExcellentEnchant implements Chanced, Arrowed, Potioned, BowEnchant {
@ -34,7 +33,7 @@ public class EnchantHover extends ExcellentEnchant implements Chanced, Arrowed,
private PotionImplementation potionImplementation;
public EnchantHover(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM);
super(plugin, ID);
this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to launch an arrow with " + Placeholders.ENCHANTMENT_POTION_TYPE + " " + Placeholders.ENCHANTMENT_POTION_LEVEL + " (" + Placeholders.ENCHANTMENT_POTION_DURATION + "s.)");
this.getDefaults().setLevelMax(3);
this.getDefaults().setTier(0.1);
@ -78,7 +77,6 @@ public class EnchantHover extends ExcellentEnchant implements Chanced, Arrowed,
@Override
public boolean onShoot(@NotNull EntityShootBowEvent event, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) {
if (!this.isAvailableToUse(shooter)) return false;
if (!(event.getProjectile() instanceof Arrow arrow)) return false;
if (!this.checkTriggerChance(level)) return false;
@ -87,12 +85,12 @@ public class EnchantHover extends ExcellentEnchant implements Chanced, Arrowed,
}
@Override
public boolean onHit(@NotNull ProjectileHitEvent event, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) {
return this.isOurProjectile(projectile);
public boolean onHit(@NotNull ProjectileHitEvent event, LivingEntity user, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) {
return false;
}
@Override
public boolean onDamage(@NotNull EntityDamageByEntityEvent event, @NotNull Projectile projectile, @NotNull LivingEntity shooter, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
return this.isOurProjectile(projectile);
return false;
}
}

View File

@ -23,7 +23,6 @@ import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ArrowImplementation;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.impl.meta.PotionImplementation;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
public class EnchantPoisonedArrows extends ExcellentEnchant implements Chanced, Arrowed, Potioned, BowEnchant {
@ -34,7 +33,7 @@ public class EnchantPoisonedArrows extends ExcellentEnchant implements Chanced,
private PotionImplementation potionImplementation;
public EnchantPoisonedArrows(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM);
super(plugin, ID);
this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to launch an arrow with " + Placeholders.ENCHANTMENT_POTION_TYPE + " " + Placeholders.ENCHANTMENT_POTION_LEVEL + " (" + Placeholders.ENCHANTMENT_POTION_DURATION + "s.)");
this.getDefaults().setLevelMax(3);
this.getDefaults().setTier(0.1);
@ -78,7 +77,6 @@ public class EnchantPoisonedArrows extends ExcellentEnchant implements Chanced,
@Override
public boolean onShoot(@NotNull EntityShootBowEvent event, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) {
if (!this.isAvailableToUse(shooter)) return false;
if (!(event.getProjectile() instanceof Arrow arrow)) return false;
if (!this.checkTriggerChance(level)) return false;
@ -87,12 +85,12 @@ public class EnchantPoisonedArrows extends ExcellentEnchant implements Chanced,
}
@Override
public boolean onHit(@NotNull ProjectileHitEvent event, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) {
return this.isOurProjectile(projectile);
public boolean onHit(@NotNull ProjectileHitEvent event, LivingEntity user, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) {
return false;
}
@Override
public boolean onDamage(@NotNull EntityDamageByEntityEvent event, @NotNull Projectile projectile, @NotNull LivingEntity shooter, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
return this.isOurProjectile(projectile);
return false;
}
}

View File

@ -23,7 +23,6 @@ import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ArrowImplementation;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.impl.meta.PotionImplementation;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
public class EnchantWitheredArrows extends ExcellentEnchant implements Chanced, Arrowed, Potioned, BowEnchant {
@ -34,7 +33,7 @@ public class EnchantWitheredArrows extends ExcellentEnchant implements Chanced,
private PotionImplementation potionImplementation;
public EnchantWitheredArrows(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM);
super(plugin, ID);
this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to launch an arrow with " + Placeholders.ENCHANTMENT_POTION_TYPE + " " + Placeholders.ENCHANTMENT_POTION_LEVEL + " (" + Placeholders.ENCHANTMENT_POTION_DURATION + "s.)");
this.getDefaults().setLevelMax(3);
this.getDefaults().setTier(0.5);
@ -78,7 +77,6 @@ public class EnchantWitheredArrows extends ExcellentEnchant implements Chanced,
@Override
public boolean onShoot(@NotNull EntityShootBowEvent event, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) {
if (!this.isAvailableToUse(shooter)) return false;
if (!(event.getProjectile() instanceof Arrow arrow)) return false;
if (!this.checkTriggerChance(level)) return false;
@ -87,12 +85,12 @@ public class EnchantWitheredArrows extends ExcellentEnchant implements Chanced,
}
@Override
public boolean onHit(@NotNull ProjectileHitEvent event, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) {
return this.isOurProjectile(projectile);
public boolean onHit(@NotNull ProjectileHitEvent event, LivingEntity user, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) {
return false;
}
@Override
public boolean onDamage(@NotNull EntityDamageByEntityEvent event, @NotNull Projectile projectile, @NotNull LivingEntity shooter, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
return this.isOurProjectile(projectile);
return false;
}
}

View File

@ -10,6 +10,7 @@ import org.bukkit.entity.Arrow;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityShootBowEvent;
@ -26,7 +27,6 @@ import su.nightexpress.excellentenchants.api.enchantment.type.BowEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ArrowImplementation;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
public class FlareEnchant extends ExcellentEnchant implements Chanced, Arrowed, BowEnchant {
@ -36,7 +36,7 @@ public class FlareEnchant extends ExcellentEnchant implements Chanced, Arrowed,
private ArrowImplementation arrowImplementation;
public FlareEnchant(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.LOWEST);
super(plugin, ID);
this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to create a torch where arrow lands.");
this.getDefaults().setLevelMax(1);
@ -56,6 +56,12 @@ public class FlareEnchant extends ExcellentEnchant implements Chanced, Arrowed,
return EnchantmentTarget.BOW;
}
@NotNull
@Override
public EventPriority getHitPriority() {
return EventPriority.HIGHEST;
}
@NotNull
@Override
public Chanced getChanceImplementation() {
@ -71,7 +77,6 @@ public class FlareEnchant extends ExcellentEnchant implements Chanced, Arrowed,
@Override
public boolean onShoot(@NotNull EntityShootBowEvent event, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) {
if (!(event.getProjectile() instanceof Arrow arrow)) return false;
if (!this.isAvailableToUse(shooter)) return false;
if (!this.checkTriggerChance(level)) return false;
this.addData(arrow);
@ -79,7 +84,7 @@ public class FlareEnchant extends ExcellentEnchant implements Chanced, Arrowed,
}
@Override
public boolean onHit(@NotNull ProjectileHitEvent e, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) {
public boolean onHit(@NotNull ProjectileHitEvent e, LivingEntity user, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) {
Block block = e.getHitBlock();
if (block == null) return false;
@ -106,7 +111,7 @@ public class FlareEnchant extends ExcellentEnchant implements Chanced, Arrowed,
relative.setBlockData(directional, true);
}
return true;
return false;
}
@Override

View File

@ -4,6 +4,7 @@ import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Projectile;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityShootBowEvent;
import org.bukkit.event.entity.ProjectileHitEvent;
@ -18,7 +19,6 @@ import su.nightexpress.excellentenchants.api.enchantment.type.BowEnchant;
import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
public class SniperEnchant extends ExcellentEnchant implements BowEnchant, Chanced {
@ -30,7 +30,7 @@ public class SniperEnchant extends ExcellentEnchant implements BowEnchant, Chanc
private EnchantScaler speedModifier;
public SniperEnchant(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.LOWEST);
super(plugin, ID);
this.getDefaults().setDescription("Increases projectile speed by " + PLACEHOLDER_PROJECTILE_SPEED + "%");
this.getDefaults().setLevelMax(5);
@ -48,6 +48,12 @@ public class SniperEnchant extends ExcellentEnchant implements BowEnchant, Chanc
this.addPlaceholder(PLACEHOLDER_PROJECTILE_SPEED, level -> NumberUtil.format(this.getSpeedModifier(level) * 100D));
}
@NotNull
@Override
public Chanced getChanceImplementation() {
return this.chanceImplementation;
}
public double getSpeedModifier(int level) {
return this.speedModifier.getValue(level);
}
@ -60,13 +66,12 @@ public class SniperEnchant extends ExcellentEnchant implements BowEnchant, Chanc
@NotNull
@Override
public Chanced getChanceImplementation() {
return this.chanceImplementation;
public EventPriority getShootPriority() {
return EventPriority.LOWEST;
}
@Override
public boolean onShoot(@NotNull EntityShootBowEvent event, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) {
if (!this.isAvailableToUse(shooter)) return false;
if (!this.checkTriggerChance(level)) return false;
double modifier = this.getSpeedModifier(level);
@ -79,7 +84,7 @@ public class SniperEnchant extends ExcellentEnchant implements BowEnchant, Chanc
}
@Override
public boolean onHit(@NotNull ProjectileHitEvent event, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) {
public boolean onHit(@NotNull ProjectileHitEvent event, LivingEntity user, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) {
return false;
}

View File

@ -7,14 +7,13 @@ import org.jetbrains.annotations.NotNull;
import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.api.enchantment.type.FishingEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
public class AutoReelEnchant extends ExcellentEnchant implements FishingEnchant {
public static final String ID = "auto_reel";
public AutoReelEnchant(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM);
super(plugin, ID);
this.getDefaults().setDescription("Automatically reels in a hook on bite.");
this.getDefaults().setLevelMax(1);
this.getDefaults().setTier(1.0);
@ -29,7 +28,6 @@ public class AutoReelEnchant extends ExcellentEnchant implements FishingEnchant
@Override
public boolean onFishing(@NotNull PlayerFishEvent event, @NotNull ItemStack item, int level) {
if (event.getState() != PlayerFishEvent.State.BITE) return false;
if (!this.isAvailableToUse(event.getPlayer())) return false;
this.plugin.runTask(task -> {
if (event.isCancelled()) return;

View File

@ -16,7 +16,6 @@ import su.nightexpress.excellentenchants.api.enchantment.meta.Chanced;
import su.nightexpress.excellentenchants.api.enchantment.type.FishingEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
public class CurseOfDrownedEnchant extends ExcellentEnchant implements FishingEnchant, Chanced {
@ -25,7 +24,7 @@ public class CurseOfDrownedEnchant extends ExcellentEnchant implements FishingEn
private ChanceImplementation chanceImplementation;
public CurseOfDrownedEnchant(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.HIGHEST);
super(plugin, ID);
this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to fish up a Drowned Zombie.");
this.getDefaults().setLevelMax(5);
this.getDefaults().setTier(0D);
@ -53,7 +52,6 @@ public class CurseOfDrownedEnchant extends ExcellentEnchant implements FishingEn
@Override
public boolean onFishing(@NotNull PlayerFishEvent event, @NotNull ItemStack item, int level) {
if (event.getState() != PlayerFishEvent.State.CAUGHT_FISH) return false;
if (!this.isAvailableToUse(event.getPlayer())) return false;
if (!this.checkTriggerChance(level)) return false;
FishHook hook = event.getHook();

View File

@ -2,6 +2,7 @@ package su.nightexpress.excellentenchants.enchantment.impl.fishing;
import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.Item;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerFishEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
@ -11,7 +12,6 @@ import su.nightexpress.excellentenchants.api.enchantment.meta.Chanced;
import su.nightexpress.excellentenchants.api.enchantment.type.FishingEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
public class DoubleCatchEnchant extends ExcellentEnchant implements FishingEnchant, Chanced {
@ -20,7 +20,7 @@ public class DoubleCatchEnchant extends ExcellentEnchant implements FishingEncha
private ChanceImplementation chanceImplementation;
public DoubleCatchEnchant(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.LOWEST);
super(plugin, ID);
this.getDefaults().setDescription("Increases amount of caught item by x2 with " + Placeholders.ENCHANTMENT_CHANCE + "% chance.");
this.getDefaults().setLevelMax(3);
this.getDefaults().setTier(0.5);
@ -39,6 +39,12 @@ public class DoubleCatchEnchant extends ExcellentEnchant implements FishingEncha
return EnchantmentTarget.FISHING_ROD;
}
@NotNull
@Override
public EventPriority getFishingPriority() {
return EventPriority.HIGHEST;
}
@Override
@NotNull
public ChanceImplementation getChanceImplementation() {
@ -49,7 +55,6 @@ public class DoubleCatchEnchant extends ExcellentEnchant implements FishingEncha
public boolean onFishing(@NotNull PlayerFishEvent event, @NotNull ItemStack item, int level) {
if (event.getState() != PlayerFishEvent.State.CAUGHT_FISH) return false;
if (!(event.getCaught() instanceof Item drop)) return false;
if (!this.isAvailableToUse(event.getPlayer())) return false;
if (!this.checkTriggerChance(level)) return false;
ItemStack stack = drop.getItemStack();

View File

@ -8,21 +8,22 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.api.manager.EventListener;
import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.Placeholders;
import su.nightexpress.excellentenchants.api.enchantment.type.GenericEnchant;
import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils;
public class RiverMasterEnchant extends ExcellentEnchant {
public class RiverMasterEnchant extends ExcellentEnchant implements GenericEnchant, EventListener {
public static final String ID = "river_master";
private EnchantScaler distanceMod;
public RiverMasterEnchant(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM);
super(plugin, ID);
this.getDefaults().setDescription("Increases casting distance.");
this.getDefaults().setLevelMax(5);
this.getDefaults().setTier(0.1);
@ -51,7 +52,6 @@ public class RiverMasterEnchant extends ExcellentEnchant {
public void onHookLaunch(ProjectileLaunchEvent event) {
if (!(event.getEntity() instanceof FishHook hook)) return;
if (!(hook.getShooter() instanceof Player player)) return;
if (!this.isAvailableToUse(player)) return;
ItemStack rod = EnchantUtils.getFishingRod(player);
if (rod == null) return;

View File

@ -10,7 +10,6 @@ import su.nightexpress.excellentenchants.Placeholders;
import su.nightexpress.excellentenchants.api.enchantment.type.FishingEnchant;
import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
public class SeasonedAnglerEnchant extends ExcellentEnchant implements FishingEnchant {
@ -19,7 +18,7 @@ public class SeasonedAnglerEnchant extends ExcellentEnchant implements FishingEn
private EnchantScaler expMod;
public SeasonedAnglerEnchant(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM);
super(plugin, ID);
this.getDefaults().setDescription("Increases amount of XP gained from fishing by " + Placeholders.GENERIC_AMOUNT + "%.");
this.getDefaults().setLevelMax(4);
this.getDefaults().setTier(0.1);
@ -48,7 +47,6 @@ public class SeasonedAnglerEnchant extends ExcellentEnchant implements FishingEn
@Override
public boolean onFishing(@NotNull PlayerFishEvent event, @NotNull ItemStack item, int level) {
if (event.getState() != PlayerFishEvent.State.CAUGHT_FISH) return false;
if (!this.isAvailableToUse(event.getPlayer())) return false;
if (event.getExpToDrop() == 0) return false;
int expDrop = event.getExpToDrop();

View File

@ -2,6 +2,7 @@ package su.nightexpress.excellentenchants.enchantment.impl.fishing;
import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.Item;
import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerFishEvent;
import org.bukkit.inventory.CookingRecipe;
import org.bukkit.inventory.ItemStack;
@ -11,7 +12,6 @@ import su.nightexpress.excellentenchants.api.enchantment.meta.Chanced;
import su.nightexpress.excellentenchants.api.enchantment.type.FishingEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import java.util.HashSet;
import java.util.Set;
@ -25,7 +25,7 @@ public class SurvivalistEnchant extends ExcellentEnchant implements FishingEncha
private ChanceImplementation chanceImplementation;
public SurvivalistEnchant(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.HIGH);
super(plugin, ID);
this.getDefaults().setDescription("Automatically cooks fish if what is caught is raw.");
this.getDefaults().setLevelMax(1);
this.getDefaults().setTier(0.4);
@ -58,10 +58,15 @@ public class SurvivalistEnchant extends ExcellentEnchant implements FishingEncha
return EnchantmentTarget.FISHING_ROD;
}
@NotNull
@Override
public EventPriority getFishingPriority() {
return EventPriority.HIGH;
}
@Override
public boolean onFishing(@NotNull PlayerFishEvent event, @NotNull ItemStack item, int level) {
if (event.getState() != PlayerFishEvent.State.CAUGHT_FISH) return false;
if (!this.isAvailableToUse(event.getPlayer())) return false;
if (!this.checkTriggerChance(level)) return false;
if (!(event.getCaught() instanceof Item drop)) return false;

View File

@ -2,9 +2,9 @@ package su.nightexpress.excellentenchants.enchantment.impl.meta;
import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.utils.random.Rnd;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.api.enchantment.meta.Chanced;
import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
public final class ChanceImplementation implements Chanced {

View File

@ -6,10 +6,10 @@ import org.bukkit.potion.PotionEffectType;
import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.utils.Scaler;
import su.nightexpress.excellentenchants.Placeholders;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.api.enchantment.meta.Potioned;
import su.nightexpress.excellentenchants.config.Config;
import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
public final class PotionImplementation implements Potioned {

View File

@ -2,6 +2,7 @@ package su.nightexpress.excellentenchants.enchantment.impl.tool;
import org.bukkit.block.Block;
import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -12,6 +13,7 @@ import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.player.PlayerItemDamageEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.api.manager.EventListener;
import su.nexmedia.engine.utils.NumberUtil;
import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.Placeholders;
@ -21,13 +23,12 @@ import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.type.FitItemType;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils;
import su.nightexpress.excellentenchants.hook.impl.NoCheatPlusHook;
import java.util.List;
public class EnchantBlastMining extends ExcellentEnchant implements Chanced, BlockBreakEnchant {
public class BlastMiningEnchant extends ExcellentEnchant implements Chanced, BlockBreakEnchant, EventListener {
public static final String ID = "blast_mining";
public static final String PLACEHOLDER_EXPLOSION_POWER = "%enchantment_explosion_power%";
@ -38,12 +39,12 @@ public class EnchantBlastMining extends ExcellentEnchant implements Chanced, Blo
private int explodeLevel;
public EnchantBlastMining(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM);
public BlastMiningEnchant(@NotNull ExcellentEnchants plugin) {
super(plugin, ID);
this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to mine blocks by explosion.");
this.getDefaults().setLevelMax(5);
this.getDefaults().setTier(1.0);
this.getDefaults().setConflicts(EnchantVeinminer.ID, EnchantTunnel.ID);
this.getDefaults().setConflicts(VeinminerEnchant.ID, TunnelEnchant.ID);
}
@Override
@ -98,8 +99,8 @@ public class EnchantBlastMining extends ExcellentEnchant implements Chanced, Blo
}
@Override
public boolean onBreak(@NotNull BlockBreakEvent event, @NotNull Player player, @NotNull ItemStack item, int level) {
if (!this.isAvailableToUse(player)) return false;
public boolean onBreak(@NotNull BlockBreakEvent event, @NotNull LivingEntity entity, @NotNull ItemStack item, int level) {
if (!(entity instanceof Player player)) return false;
if (EnchantUtils.isBusy()) return false;
Block block = event.getBlock();

View File

@ -7,17 +7,18 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerItemDamageEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.api.manager.EventListener;
import su.nexmedia.engine.utils.NumberUtil;
import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.Placeholders;
import su.nightexpress.excellentenchants.api.enchantment.meta.Chanced;
import su.nightexpress.excellentenchants.api.enchantment.type.GenericEnchant;
import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils;
public class EnchantCurseOfBreaking extends ExcellentEnchant implements Chanced {
public class CurseOfBreakingEnchant extends ExcellentEnchant implements GenericEnchant, EventListener, Chanced {
public static final String ID = "curse_of_breaking";
public static final String PLACEHOLDER_DURABILITY_AMOUNT = "%enchantment_durability_amount%";
@ -25,8 +26,8 @@ public class EnchantCurseOfBreaking extends ExcellentEnchant implements Chanced
private EnchantScaler durabilityAmount;
private ChanceImplementation chanceImplementation;
public EnchantCurseOfBreaking(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM);
public CurseOfBreakingEnchant(@NotNull ExcellentEnchants plugin) {
super(plugin, ID);
this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to consume extra " + PLACEHOLDER_DURABILITY_AMOUNT + " durability points.");
this.getDefaults().setLevelMax(3);
this.getDefaults().setTier(0D);
@ -66,11 +67,11 @@ public class EnchantCurseOfBreaking extends ExcellentEnchant implements Chanced
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onItemDurability(PlayerItemDamageEvent e) {
Player player = e.getPlayer();
public void onItemDurability(PlayerItemDamageEvent event) {
Player player = event.getPlayer();
if (!this.isAvailableToUse(player)) return;
ItemStack item = e.getItem();
ItemStack item = event.getItem();
int level = EnchantUtils.getLevel(item, this);
if (level < 1) return;
@ -79,6 +80,6 @@ public class EnchantCurseOfBreaking extends ExcellentEnchant implements Chanced
int durabilityAmount = this.getDurabilityAmount(level);
if (durabilityAmount <= 0) return;
e.setDamage(e.getDamage() + durabilityAmount);
event.setDamage(event.getDamage() + durabilityAmount);
}
}

View File

@ -3,6 +3,7 @@ package su.nightexpress.excellentenchants.enchantment.impl.tool;
import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockDropItemEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.inventory.ItemStack;
@ -16,7 +17,6 @@ import su.nightexpress.excellentenchants.api.enchantment.type.DeathEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.type.FitItemType;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
public class CurseOfMediocrityEnchant extends ExcellentEnchant implements Chanced, BlockDropEnchant, DeathEnchant {
@ -25,7 +25,7 @@ public class CurseOfMediocrityEnchant extends ExcellentEnchant implements Chance
private ChanceImplementation chanceImplementation;
public CurseOfMediocrityEnchant(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.LOWEST);
super(plugin, ID);
this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to disenchant item drops.");
this.getDefaults().setLevelMax(3);
this.getDefaults().setTier(0D);
@ -49,6 +49,12 @@ public class CurseOfMediocrityEnchant extends ExcellentEnchant implements Chance
return new FitItemType[] {FitItemType.WEAPON, FitItemType.TOOL};
}
@NotNull
@Override
public EventPriority getDropPriority() {
return EventPriority.HIGHEST;
}
@NotNull
@Override
public Chanced getChanceImplementation() {
@ -62,8 +68,7 @@ public class CurseOfMediocrityEnchant extends ExcellentEnchant implements Chance
@Override
public boolean onDrop(@NotNull BlockDropItemEvent event,
@NotNull Player player, @NotNull ItemStack item, int level) {
if (!this.isAvailableToUse(player)) return false;
@NotNull LivingEntity player, @NotNull ItemStack item, int level) {
if (!this.checkTriggerChance(level)) return false;
event.getItems().forEach(drop -> {
@ -84,7 +89,6 @@ public class CurseOfMediocrityEnchant extends ExcellentEnchant implements Chance
@Override
public boolean onKill(@NotNull EntityDeathEvent event, @NotNull LivingEntity entity, @NotNull Player killer, int level) {
if (!this.isAvailableToUse(killer)) return false;
if (!this.checkTriggerChance(level)) return false;
event.getDrops().forEach(stack -> {

View File

@ -4,6 +4,7 @@ import org.bukkit.enchantments.Enchantment;
import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.inventory.ItemStack;
@ -11,23 +12,22 @@ import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.api.config.JOption;
import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.Placeholders;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.api.enchantment.meta.Chanced;
import su.nightexpress.excellentenchants.api.enchantment.type.BlockBreakEnchant;
import su.nightexpress.excellentenchants.api.enchantment.type.DeathEnchant;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.type.FitItemType;
public class EnchantCurseOfMisfortune extends ExcellentEnchant implements Chanced, BlockBreakEnchant, DeathEnchant {
public class CurseOfMisfortuneEnchant extends ExcellentEnchant implements Chanced, BlockBreakEnchant, DeathEnchant {
public static final String ID = "curse_of_misfortune";
private boolean dropExp;
private ChanceImplementation chanceImplementation;
public EnchantCurseOfMisfortune(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.LOWEST);
public CurseOfMisfortuneEnchant(@NotNull ExcellentEnchants plugin) {
super(plugin, ID);
this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to have no drops from blocks or mobs.");
this.getDefaults().setLevelMax(3);
this.getDefaults().setTier(0D);
@ -68,14 +68,25 @@ public class EnchantCurseOfMisfortune extends ExcellentEnchant implements Chance
return EnchantmentTarget.BREAKABLE;
}
@NotNull
@Override
public EventPriority getBreakPriority() {
return EventPriority.HIGHEST;
}
@NotNull
@Override
public EventPriority getKillPriority() {
return EventPriority.HIGH;
}
@Override
public boolean isCursed() {
return true;
}
@Override
public boolean onBreak(@NotNull BlockBreakEvent event, @NotNull Player player, @NotNull ItemStack item, int level) {
if (!this.isAvailableToUse(player)) return false;
public boolean onBreak(@NotNull BlockBreakEvent event, @NotNull LivingEntity player, @NotNull ItemStack item, int level) {
if (!this.checkTriggerChance(level)) return false;
event.setDropItems(false);
@ -85,7 +96,6 @@ public class EnchantCurseOfMisfortune extends ExcellentEnchant implements Chance
@Override
public boolean onKill(@NotNull EntityDeathEvent event, @NotNull LivingEntity entity, @NotNull Player killer, int level) {
if (!this.isAvailableToUse(killer)) return false;
if (!this.checkTriggerChance(level)) return false;
event.getDrops().clear();

View File

@ -8,6 +8,7 @@ import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.CreatureSpawner;
import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -16,10 +17,12 @@ import org.bukkit.event.block.BlockDropItemEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BlockStateMeta;
import org.bukkit.metadata.FixedMetadataValue;
import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.api.config.JOption;
import su.nexmedia.engine.api.manager.EventListener;
import su.nexmedia.engine.lang.LangManager;
import su.nexmedia.engine.utils.Colorizer;
import su.nexmedia.engine.utils.Colors;
import su.nexmedia.engine.utils.LocationUtil;
import su.nexmedia.engine.utils.PDCUtil;
import su.nexmedia.engine.utils.values.UniParticle;
@ -31,39 +34,41 @@ import su.nightexpress.excellentenchants.api.enchantment.type.BlockDropEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.type.FitItemType;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils;
public class EnchantDivineTouch extends ExcellentEnchant implements Chanced, BlockBreakEnchant, BlockDropEnchant {
public class DivineTouchEnchant extends ExcellentEnchant implements Chanced, BlockBreakEnchant, BlockDropEnchant, EventListener {
public static final String ID = "divine_touch";
private static final String META_HANDLE = ID + "_handle";
private final NamespacedKey key;
private String spawnerName;
private ChanceImplementation chanceImplementation;
private final NamespacedKey key;
private Location handleSpawner;
public EnchantDivineTouch(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM);
public DivineTouchEnchant(@NotNull ExcellentEnchants plugin) {
super(plugin, ID);
this.key = new NamespacedKey(plugin, "divine_spawner");
this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to mine spawner.");
this.getDefaults().setLevelMax(5);
this.getDefaults().setTier(1.0);
this.getDefaults().setConflicts(EnchantSmelter.ID);
this.getDefaults().setConflicts(SmelterEnchant.ID);
}
@Override
public void loadSettings() {
super.loadSettings();
this.chanceImplementation = ChanceImplementation.create(this,
"15.0 * " + Placeholders.ENCHANTMENT_LEVEL);
this.spawnerName = JOption.create("Settings.Spawner_Item.Name",
"&aMob Spawner &7(" + Placeholders.GENERIC_TYPE + ")",
Colors.GREEN + "Mob Spawner " + Colors.GRAY + "(" + Placeholders.GENERIC_TYPE + ")",
"Spawner item display name.",
"Placeholder '" + Placeholders.GENERIC_TYPE + "' for the mob type.")
.mapReader(Colorizer::apply).read(cfg);
"Placeholder '" + Placeholders.GENERIC_TYPE + "' for the mob type."
).mapReader(Colorizer::apply).read(cfg);
}
@NotNull
@ -84,6 +89,18 @@ public class EnchantDivineTouch extends ExcellentEnchant implements Chanced, Blo
return EnchantmentTarget.TOOL;
}
@NotNull
@Override
public EventPriority getDropPriority() {
return EventPriority.NORMAL;
}
@NotNull
@Override
public EventPriority getBreakPriority() {
return EventPriority.HIGH;
}
@NotNull
public ItemStack getSpawner(@NotNull CreatureSpawner spawnerBlock) {
ItemStack itemSpawner = new ItemStack(Material.SPAWNER);
@ -94,7 +111,7 @@ public class EnchantDivineTouch extends ExcellentEnchant implements Chanced, Blo
spawnerItem.setSpawnedType(spawnerBlock.getSpawnedType());
spawnerItem.update(true);
stateItem.setBlockState(spawnerItem);
stateItem.setDisplayName(this.spawnerName.replace(Placeholders.GENERIC_TYPE, plugin.getLangManager().getEnum(spawnerBlock.getSpawnedType())));
stateItem.setDisplayName(this.spawnerName.replace(Placeholders.GENERIC_TYPE, LangManager.getEntityType(spawnerBlock.getSpawnedType())));
itemSpawner.setItemMeta(stateItem);
PDCUtil.set(itemSpawner, this.key, true);
@ -102,10 +119,12 @@ public class EnchantDivineTouch extends ExcellentEnchant implements Chanced, Blo
}
@Override
public boolean onDrop(@NotNull BlockDropItemEvent event, @NotNull Player player, @NotNull ItemStack item, int level) {
public boolean onDrop(@NotNull BlockDropItemEvent event, @NotNull LivingEntity player, @NotNull ItemStack item, int level) {
BlockState state = event.getBlockState();
Block block = state.getBlock();
if (!block.hasMetadata(META_HANDLE)) return false;
if (this.handleSpawner == null || !this.handleSpawner.equals(block.getLocation())) return false;
this.handleSpawner = null;
if (!(state instanceof CreatureSpawner spawnerBlock)) return false;
EnchantUtils.popResource(event, this.getSpawner(spawnerBlock));
@ -114,20 +133,18 @@ public class EnchantDivineTouch extends ExcellentEnchant implements Chanced, Blo
Location location = LocationUtil.getCenter(block.getLocation());
UniParticle.of(Particle.VILLAGER_HAPPY).play(location, 0.3, 0.15, 30);
}
block.removeMetadata(META_HANDLE, this.plugin);
return true;
}
@Override
public boolean onBreak(@NotNull BlockBreakEvent event, @NotNull Player player, @NotNull ItemStack item, int level) {
public boolean onBreak(@NotNull BlockBreakEvent event, @NotNull LivingEntity player, @NotNull ItemStack item, int level) {
Block block = event.getBlock();
if (!this.isAvailableToUse(player)) return false;
if (!(block.getState() instanceof CreatureSpawner spawnerBlock)) return false;
if (!this.checkTriggerChance(level)) return false;
event.setExpToDrop(0);
event.setDropItems(true);
block.setMetadata(META_HANDLE, new FixedMetadataValue(this.plugin, true));
this.handleSpawner = block.getLocation();
return false; // Do not consume charges
}

View File

@ -7,20 +7,19 @@ import org.bukkit.potion.PotionEffectType;
import org.jetbrains.annotations.NotNull;
import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.Placeholders;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.api.enchantment.meta.Potioned;
import su.nightexpress.excellentenchants.api.enchantment.type.PassiveEnchant;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.PotionImplementation;
public class EnchantHaste extends ExcellentEnchant implements Potioned, PassiveEnchant {
public class HasteEnchant extends ExcellentEnchant implements Potioned, PassiveEnchant {
public static final String ID = "haste";
private PotionImplementation potionImplementation;
public EnchantHaste(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM);
public HasteEnchant(@NotNull ExcellentEnchants plugin) {
super(plugin, ID);
this.getDefaults().setDescription("Grants permanent " + Placeholders.ENCHANTMENT_POTION_TYPE + " " + Placeholders.ENCHANTMENT_POTION_LEVEL + " effect.");
this.getDefaults().setLevelMax(3);
this.getDefaults().setTier(0.3);
@ -46,8 +45,6 @@ public class EnchantHaste extends ExcellentEnchant implements Potioned, PassiveE
@Override
public boolean onTrigger(@NotNull LivingEntity entity, @NotNull ItemStack item, int level) {
if (!this.isAvailableToUse(entity)) return false;
return this.addEffect(entity, level);
}
}

View File

@ -1,7 +1,7 @@
package su.nightexpress.excellentenchants.enchantment.impl.tool;
import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.Player;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
@ -14,9 +14,8 @@ import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.type.FitItemType;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
public class EnchantLuckyMiner extends ExcellentEnchant implements Chanced, BlockBreakEnchant {
public class LuckyMinerEnchant extends ExcellentEnchant implements Chanced, BlockBreakEnchant {
public static final String ID = "lucky_miner";
private static final String PLACEHOLDER_EXP_MODIFIER = "%enchantment_exp_modifier%";
@ -24,8 +23,8 @@ public class EnchantLuckyMiner extends ExcellentEnchant implements Chanced, Bloc
private EnchantScaler expModifier;
private ChanceImplementation chanceImplementation;
public EnchantLuckyMiner(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM);
public LuckyMinerEnchant(@NotNull ExcellentEnchants plugin) {
super(plugin, ID);
this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to gain " + PLACEHOLDER_EXP_MODIFIER + "% more exp from ores.");
this.getDefaults().setLevelMax(5);
this.getDefaults().setTier(0.1);
@ -66,8 +65,7 @@ public class EnchantLuckyMiner extends ExcellentEnchant implements Chanced, Bloc
}
@Override
public boolean onBreak(@NotNull BlockBreakEvent event, @NotNull Player player, @NotNull ItemStack item, int level) {
if (!this.isAvailableToUse(player)) return false;
public boolean onBreak(@NotNull BlockBreakEvent event, @NotNull LivingEntity player, @NotNull ItemStack item, int level) {
if (!this.checkTriggerChance(level)) return false;
double expMod = this.getExpModifier(level);

View File

@ -7,7 +7,9 @@ import org.bukkit.block.BlockFace;
import org.bukkit.block.data.Ageable;
import org.bukkit.block.data.BlockData;
import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.player.PlayerInteractEvent;
@ -23,11 +25,10 @@ import su.nightexpress.excellentenchants.api.enchantment.type.InteractEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.type.FitItemType;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import java.util.Set;
public class EnchantReplanter extends ExcellentEnchant implements Chanced, InteractEnchant, BlockBreakEnchant {
public class ReplanterEnchant extends ExcellentEnchant implements Chanced, InteractEnchant, BlockBreakEnchant {
public static final String ID = "replanter";
@ -41,8 +42,8 @@ public class EnchantReplanter extends ExcellentEnchant implements Chanced, Inter
Material.MELON_SEEDS, Material.PUMPKIN_SEEDS,
Material.POTATO, Material.CARROT, Material.NETHER_WART);
public EnchantReplanter(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.HIGH);
public ReplanterEnchant(@NotNull ExcellentEnchants plugin) {
super(plugin, ID);
this.getDefaults().setDescription("Automatically replant crops on right click and when harvest.");
this.getDefaults().setLevelMax(1);
this.getDefaults().setTier(0.3);
@ -119,10 +120,16 @@ public class EnchantReplanter extends ExcellentEnchant implements Chanced, Inter
return EnchantmentTarget.TOOL;
}
@NotNull
@Override
public boolean onInteract(@NotNull PlayerInteractEvent event, @NotNull Player player, @NotNull ItemStack item, int level) {
public EventPriority getInteractPriority() {
return EventPriority.HIGHEST;
}
@Override
public boolean onInteract(@NotNull PlayerInteractEvent event, @NotNull LivingEntity entity, @NotNull ItemStack item, int level) {
if (!(entity instanceof Player player)) return false;
if (!this.isReplantOnRightClick()) return false;
if (!this.isAvailableToUse(player)) return false;
if (!this.checkTriggerChance(level)) return false;
// Check for a event hand. We dont want to trigger it twice.
@ -158,9 +165,9 @@ public class EnchantReplanter extends ExcellentEnchant implements Chanced, Inter
}
@Override
public boolean onBreak(@NotNull BlockBreakEvent event, @NotNull Player player, @NotNull ItemStack item, int level) {
public boolean onBreak(@NotNull BlockBreakEvent event, @NotNull LivingEntity entity, @NotNull ItemStack item, int level) {
if (!(entity instanceof Player player)) return false;
if (!this.isReplantOnPlantBreak()) return false;
if (!this.isAvailableToUse(player)) return false;
if (!this.checkTriggerChance(level)) return false;
Block blockPlant = event.getBlock();

View File

@ -6,6 +6,7 @@ import org.bukkit.block.BlockState;
import org.bukkit.block.Chest;
import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.Item;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -20,6 +21,7 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BlockStateMeta;
import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.api.config.JOption;
import su.nexmedia.engine.api.manager.EventListener;
import su.nexmedia.engine.utils.Colorizer;
import su.nexmedia.engine.utils.ItemUtil;
import su.nexmedia.engine.utils.PDCUtil;
@ -28,14 +30,13 @@ import su.nightexpress.excellentenchants.Placeholders;
import su.nightexpress.excellentenchants.api.enchantment.type.BlockDropEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.type.FitItemType;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;
public class EnchantSilkChest extends ExcellentEnchant implements BlockDropEnchant {
public class SilkChestEnchant extends ExcellentEnchant implements BlockDropEnchant, EventListener {
public static final String ID = "silk_chest";
@ -43,8 +44,8 @@ public class EnchantSilkChest extends ExcellentEnchant implements BlockDropEncha
private List<String> chestLore;
private final NamespacedKey keyChest;
public EnchantSilkChest(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.HIGH);
public SilkChestEnchant(@NotNull ExcellentEnchants plugin) {
super(plugin, ID);
this.getDefaults().setDescription("Drop chests and saves all its content.");
this.getDefaults().setLevelMax(1);
this.getDefaults().setTier(0.5);
@ -75,6 +76,12 @@ public class EnchantSilkChest extends ExcellentEnchant implements BlockDropEncha
return EnchantmentTarget.TOOL;
}
@NotNull
@Override
public EventPriority getDropPriority() {
return EventPriority.NORMAL;
}
public boolean isSilkChest(@NotNull ItemStack item) {
return PDCUtil.getBoolean(item, this.keyChest).isPresent();
}
@ -131,11 +138,10 @@ public class EnchantSilkChest extends ExcellentEnchant implements BlockDropEncha
@Override
public boolean onDrop(@NotNull BlockDropItemEvent event,
@NotNull Player player, @NotNull ItemStack item, int level) {
@NotNull LivingEntity player, @NotNull ItemStack item, int level) {
BlockState state = event.getBlockState();
Block block = state.getBlock();
if (!this.isAvailableToUse(player)) return false;
if (!(state instanceof Chest chest)) return false;
// Добавляем в сундук обратно предметы из дроп листа, кроме самого сундука.

View File

@ -8,7 +8,8 @@ import org.bukkit.block.Block;
import org.bukkit.block.Container;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.Player;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockDropItemEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
@ -23,11 +24,10 @@ import su.nightexpress.excellentenchants.api.enchantment.type.BlockDropEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.type.FitItemType;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import java.util.Map;
public class EnchantSmelter extends ExcellentEnchant implements Chanced, BlockDropEnchant {
public class SmelterEnchant extends ExcellentEnchant implements Chanced, BlockDropEnchant {
public static final String ID = "smelter";
@ -35,13 +35,13 @@ public class EnchantSmelter extends ExcellentEnchant implements Chanced, BlockDr
private Map<Material, Material> smeltingTable;
private ChanceImplementation chanceImplementation;
public EnchantSmelter(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM);
public SmelterEnchant(@NotNull ExcellentEnchants plugin) {
super(plugin, ID);
this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to smelt a block/ore.");
this.getDefaults().setLevelMax(5);
this.getDefaults().setTier(0.3);
this.getDefaults().setConflicts(
EnchantDivineTouch.ID,
DivineTouchEnchant.ID,
Enchantment.SILK_TOUCH.getKey().getKey()
);
}
@ -88,12 +88,17 @@ public class EnchantSmelter extends ExcellentEnchant implements Chanced, BlockDr
return EnchantmentTarget.TOOL;
}
@NotNull
@Override
public boolean onDrop(@NotNull BlockDropItemEvent event, @NotNull Player player, @NotNull ItemStack item, int level) {
public EventPriority getDropPriority() {
return EventPriority.NORMAL;
}
@Override
public boolean onDrop(@NotNull BlockDropItemEvent event, @NotNull LivingEntity player, @NotNull ItemStack item, int level) {
// TODO Use furnace recipes & Re-add smelted items instead of setType
if (event.getBlockState() instanceof Container) return false;
if (!this.isAvailableToUse(player)) return false;
if (!this.checkTriggerChance(level)) return false;
if (event.getItems().stream().noneMatch(drop -> this.isSmeltable(drop.getItemStack().getType()))) return false;

View File

@ -1,8 +1,9 @@
package su.nightexpress.excellentenchants.enchantment.impl.tool;
import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.Item;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockDropItemEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
@ -13,19 +14,15 @@ import su.nightexpress.excellentenchants.api.enchantment.type.BlockDropEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.type.FitItemType;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import java.util.ArrayList;
import java.util.List;
public class EnchantTelekinesis extends ExcellentEnchant implements Chanced, BlockDropEnchant {
public class TelekinesisEnchant extends ExcellentEnchant implements Chanced, BlockDropEnchant {
public static final String ID = "telekinesis";
private ChanceImplementation chanceImplementation;
public EnchantTelekinesis(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.LOWEST);
public TelekinesisEnchant(@NotNull ExcellentEnchants plugin) {
super(plugin, ID);
this.getDefaults().setDescription("Moves all blocks loot directly to your inventory.");
this.getDefaults().setLevelMax(1);
this.getDefaults().setTier(0.75);
@ -55,18 +52,21 @@ public class EnchantTelekinesis extends ExcellentEnchant implements Chanced, Blo
return EnchantmentTarget.TOOL;
}
@NotNull
@Override
public boolean onDrop(@NotNull BlockDropItemEvent event, @NotNull Player player, @NotNull ItemStack item, int level) {
if (!this.isAvailableToUse(player)) return false;
public EventPriority getDropPriority() {
return EventPriority.HIGHEST;
}
@Override
public boolean onDrop(@NotNull BlockDropItemEvent event, @NotNull LivingEntity entity, @NotNull ItemStack item, int level) {
if (!(entity instanceof Player player)) return false;
if (!this.checkTriggerChance(level)) return false;
List<ItemStack> drops = new ArrayList<>(event.getItems().stream().map(Item::getItemStack).toList());
//drops.addAll(dropContainer.getDrop());
//drops.removeIf(Objects::isNull);
drops.forEach(drop -> PlayerUtil.addItem(player, drop));
event.getItems().forEach(drop -> {
PlayerUtil.addItem(player, drop.getItemStack());
});
event.getItems().clear();
return true;
}
}

View File

@ -4,11 +4,11 @@ import org.bukkit.Material;
import org.bukkit.Tag;
import org.bukkit.block.Block;
import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.Player;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockDropItemEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.FixedMetadataValue;
import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.utils.blocktracker.PlayerBlockTracker;
import su.nexmedia.engine.utils.random.Rnd;
@ -21,24 +21,24 @@ import su.nightexpress.excellentenchants.api.enchantment.type.BlockDropEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.type.FitItemType;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils;
import java.util.*;
import java.util.function.Predicate;
public class EnchantTreasures extends ExcellentEnchant implements Chanced, BlockBreakEnchant, BlockDropEnchant, Cleanable {
public class TreasuresEnchant extends ExcellentEnchant implements Chanced, BlockBreakEnchant, BlockDropEnchant, Cleanable {
public static final String ID = "treasures";
@Deprecated private static final String META = "wasted";
private final Predicate<Block> blockTracker;
private Map<Material, Map<Material, Double>> treasures;
private ChanceImplementation chanceImplementation;
private final Predicate<Block> blockTracker;
private Block handleDrop;
public EnchantTreasures(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM);
public TreasuresEnchant(@NotNull ExcellentEnchants plugin) {
super(plugin, ID);
this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to attempt to find a treasure in mined block.");
this.getDefaults().setLevelMax(5);
this.getDefaults().setTier(0.1);
@ -126,29 +126,31 @@ public class EnchantTreasures extends ExcellentEnchant implements Chanced, Block
return EnchantmentTarget.TOOL;
}
@NotNull
@Override
public boolean onBreak(@NotNull BlockBreakEvent event, @NotNull Player player, @NotNull ItemStack item, int level) {
if (PlayerBlockTracker.isTracked(event.getBlock())) {
event.getBlock().setMetadata(META, new FixedMetadataValue(plugin, true));
}
public EventPriority getDropPriority() {
return EventPriority.NORMAL;
}
@Override
public boolean onBreak(@NotNull BlockBreakEvent event, @NotNull LivingEntity player, @NotNull ItemStack item, int level) {
if (!event.isDropItems()) return false;
if (PlayerBlockTracker.isTracked(event.getBlock())) return false;
this.handleDrop = event.getBlock();
return false;
}
@Override
public boolean onDrop(@NotNull BlockDropItemEvent event, @NotNull Player player, @NotNull ItemStack item, int level) {
Block block = event.getBlockState().getBlock();
if (block.hasMetadata(META)) {
block.removeMetadata(META, plugin);
return false;
}
if (!this.isAvailableToUse(player)) return false;
public boolean onDrop(@NotNull BlockDropItemEvent event, @NotNull LivingEntity player, @NotNull ItemStack item, int level) {
if (this.handleDrop != event.getBlock()) return false;
this.handleDrop = null;
if (!this.checkTriggerChance(level)) return false;
this.getTreasures(event.getBlockState().getType()).forEach(treasure -> {
EnchantUtils.popResource(event, treasure);
});
//dropContainer.getDrop().addAll(this.getTreasures(event.getBlockState().getType()));
return true;
}

View File

@ -4,17 +4,16 @@ import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.api.config.JOption;
import su.nexmedia.engine.utils.EntityUtil;
import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.api.enchantment.type.BlockBreakEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.type.FitItemType;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils;
import su.nightexpress.excellentenchants.hook.impl.NoCheatPlusHook;
@ -22,7 +21,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class EnchantTunnel extends ExcellentEnchant implements BlockBreakEnchant {
public class TunnelEnchant extends ExcellentEnchant implements BlockBreakEnchant {
public static final String ID = "tunnel";
// X and Z offsets for each block AoE mined
@ -36,13 +35,13 @@ public class EnchantTunnel extends ExcellentEnchant implements BlockBreakEnchant
private boolean disableOnSneak;
public EnchantTunnel(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.HIGH);
public TunnelEnchant(@NotNull ExcellentEnchants plugin) {
super(plugin, ID);
this.getDefaults().setDescription("Mines multiple blocks at once in a certain shape.");
this.getDefaults().setLevelMax(3);
this.getDefaults().setTier(1.0);
this.getDefaults().setConflicts(EnchantVeinminer.ID, EnchantBlastMining.ID);
this.getDefaults().setConflicts(VeinminerEnchant.ID, BlastMiningEnchant.ID);
}
@Override
@ -65,9 +64,9 @@ public class EnchantTunnel extends ExcellentEnchant implements BlockBreakEnchant
}
@Override
public boolean onBreak(@NotNull BlockBreakEvent event, @NotNull Player player, @NotNull ItemStack item, int level) {
public boolean onBreak(@NotNull BlockBreakEvent event, @NotNull LivingEntity entity, @NotNull ItemStack item, int level) {
if (!(entity instanceof Player player)) return false;
if (EnchantUtils.isBusy()) return false;
if (!this.isAvailableToUse(player)) return false;
if (this.disableOnSneak && player.isSneaking()) return false;
Block block = event.getBlock();

View File

@ -5,6 +5,7 @@ import org.bukkit.Tag;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.inventory.ItemStack;
@ -17,7 +18,6 @@ import su.nightexpress.excellentenchants.api.enchantment.type.BlockBreakEnchant;
import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.type.FitItemType;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils;
import su.nightexpress.excellentenchants.hook.impl.NoCheatPlusHook;
@ -26,7 +26,7 @@ import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class EnchantVeinminer extends ExcellentEnchant implements BlockBreakEnchant {
public class VeinminerEnchant extends ExcellentEnchant implements BlockBreakEnchant {
public static final String ID = "veinminer";
@ -40,13 +40,13 @@ public class EnchantVeinminer extends ExcellentEnchant implements BlockBreakEnch
private Scaler blocksLimit;
private Set<Material> blocksAffected;
public EnchantVeinminer(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.HIGH);
public VeinminerEnchant(@NotNull ExcellentEnchants plugin) {
super(plugin, ID);
this.getDefaults().setDescription("Mines up to " + PLACEHOLDER_BLOCK_LIMIT + " blocks of the ore vein at once.");
this.getDefaults().setLevelMax(3);
this.getDefaults().setTier(0.3);
this.getDefaults().setConflicts(EnchantBlastMining.ID, EnchantTunnel.ID);
this.getDefaults().setConflicts(BlastMiningEnchant.ID, TunnelEnchant.ID);
}
@Override
@ -125,8 +125,8 @@ public class EnchantVeinminer extends ExcellentEnchant implements BlockBreakEnch
}
@Override
public boolean onBreak(@NotNull BlockBreakEvent event, @NotNull Player player, @NotNull ItemStack tool, int level) {
if (!this.isAvailableToUse(player)) return false;
public boolean onBreak(@NotNull BlockBreakEvent event, @NotNull LivingEntity entity, @NotNull ItemStack tool, int level) {
if (!(entity instanceof Player player)) return false;
if (EnchantUtils.isBusy()) return false;
Block block = event.getBlock();

View File

@ -11,17 +11,18 @@ import org.bukkit.inventory.AnvilInventory;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.api.manager.EventListener;
import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.api.enchantment.type.GenericEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils;
public class EnchantCurseOfFragility extends ExcellentEnchant {
public class CurseOfFragilityEnchant extends ExcellentEnchant implements GenericEnchant, EventListener {
public static final String ID = "curse_of_fragility";
public EnchantCurseOfFragility(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM);
public CurseOfFragilityEnchant(@NotNull ExcellentEnchants plugin) {
super(plugin, ID);
this.getDefaults().setDescription("Prevents an item from being grindstoned or anviled.");
this.getDefaults().setLevelMax(1);
this.getDefaults().setTier(0D);

View File

@ -9,20 +9,21 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.api.manager.EventListener;
import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.api.enchantment.type.GenericEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils;
import java.util.ArrayList;
import java.util.List;
public class SoulboundEnchant extends ExcellentEnchant {
public class SoulboundEnchant extends ExcellentEnchant implements GenericEnchant, EventListener {
public static final String ID = "soulbound";
public SoulboundEnchant(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.LOWEST);
super(plugin, ID);
this.getDefaults().setDescription("Protects from being dropped on death.");
this.getDefaults().setLevelMax(1);
this.getDefaults().setTier(0.8);

View File

@ -15,7 +15,6 @@ import su.nightexpress.excellentenchants.Placeholders;
import su.nightexpress.excellentenchants.api.enchantment.type.CombatEnchant;
import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import java.util.Set;
@ -36,7 +35,7 @@ public class EnchantBaneOfNetherspawn extends ExcellentEnchant implements Combat
private EnchantScaler damageFormula;
public EnchantBaneOfNetherspawn(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM);
super(plugin, ID);
this.getDefaults().setDescription("Inflicts " + PLACEHOLDER_DAMAGE + " more damage to nether mobs.");
this.getDefaults().setLevelMax(5);
this.getDefaults().setTier(0.1);
@ -67,7 +66,6 @@ public class EnchantBaneOfNetherspawn extends ExcellentEnchant implements Combat
@Override
public boolean onAttack(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
if (!ENTITY_TYPES.contains(victim.getType())) return false;
if (!this.isAvailableToUse(damager)) return false;
double damageEvent = event.getDamage();
double damageAdd = this.getDamageModifier(level);

View File

@ -3,6 +3,7 @@ package su.nightexpress.excellentenchants.enchantment.impl.weapon;
import org.bukkit.Particle;
import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffectType;
@ -16,7 +17,6 @@ import su.nightexpress.excellentenchants.api.enchantment.type.CombatEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.impl.meta.PotionImplementation;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
public class EnchantBlindness extends ExcellentEnchant implements Chanced, Potioned, CombatEnchant {
@ -26,7 +26,7 @@ public class EnchantBlindness extends ExcellentEnchant implements Chanced, Potio
private PotionImplementation potionImplementation;
public EnchantBlindness(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM);
super(plugin, ID);
this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to apply " + Placeholders.ENCHANTMENT_POTION_TYPE + " " + Placeholders.ENCHANTMENT_POTION_LEVEL + " (" + Placeholders.ENCHANTMENT_POTION_DURATION + "s.) on hit.");
this.getDefaults().setLevelMax(3);
this.getDefaults().setTier(0.1);
@ -60,9 +60,14 @@ public class EnchantBlindness extends ExcellentEnchant implements Chanced, Potio
return EnchantmentTarget.WEAPON;
}
@NotNull
@Override
public EventPriority getAttackPriority() {
return EventPriority.HIGHEST;
}
@Override
public boolean onAttack(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
if (!this.isAvailableToUse(damager)) return false;
if (!this.checkTriggerChance(level)) return false;
if (!this.addEffect(victim, level)) return false;

View File

@ -3,6 +3,7 @@ package su.nightexpress.excellentenchants.enchantment.impl.weapon;
import org.bukkit.Material;
import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffectType;
@ -16,7 +17,6 @@ import su.nightexpress.excellentenchants.api.enchantment.type.CombatEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.impl.meta.PotionImplementation;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
public class EnchantConfusion extends ExcellentEnchant implements Chanced, Potioned, CombatEnchant {
@ -26,7 +26,7 @@ public class EnchantConfusion extends ExcellentEnchant implements Chanced, Potio
private PotionImplementation potionImplementation;
public EnchantConfusion(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM);
super(plugin, ID);
this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to apply " + Placeholders.ENCHANTMENT_POTION_TYPE + " " + Placeholders.ENCHANTMENT_POTION_LEVEL + " (" + Placeholders.ENCHANTMENT_POTION_DURATION + "s.) on hit.");
this.getDefaults().setLevelMax(3);
this.getDefaults().setTier(0.1);
@ -60,9 +60,14 @@ public class EnchantConfusion extends ExcellentEnchant implements Chanced, Potio
return EnchantmentTarget.WEAPON;
}
@NotNull
@Override
public EventPriority getAttackPriority() {
return EventPriority.HIGHEST;
}
@Override
public boolean onAttack(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
if (!this.isAvailableToUse(damager)) return false;
if (!this.checkTriggerChance(level)) return false;
if (!this.addEffect(victim, level)) return false;

View File

@ -4,6 +4,7 @@ import com.google.common.collect.Sets;
import org.bukkit.Particle;
import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.*;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
@ -14,7 +15,6 @@ import su.nightexpress.excellentenchants.api.enchantment.meta.Chanced;
import su.nightexpress.excellentenchants.api.enchantment.type.CombatEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import java.util.Set;
@ -27,7 +27,7 @@ public class EnchantCure extends ExcellentEnchant implements Chanced, CombatEnch
private static final Set<EntityType> CUREABLE = Sets.newHashSet(EntityType.ZOMBIFIED_PIGLIN, EntityType.ZOMBIE_VILLAGER);
public EnchantCure(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM);
super(plugin, ID);
this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to cure Zombified Piglins and Zombie Villagers on hit.");
this.getDefaults().setLevelMax(5);
this.getDefaults().setTier(0.5);
@ -52,9 +52,14 @@ public class EnchantCure extends ExcellentEnchant implements Chanced, CombatEnch
return EnchantmentTarget.WEAPON;
}
@NotNull
@Override
public EventPriority getAttackPriority() {
return EventPriority.HIGHEST;
}
@Override
public boolean onAttack(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
if (!this.isAvailableToUse(damager)) return false;
if (!CUREABLE.contains(victim.getType())) return false;
if (!this.checkTriggerChance(level)) return false;
if (!(damager instanceof Player player)) return false;

View File

@ -5,6 +5,7 @@ import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.Item;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.ItemStack;
@ -23,7 +24,6 @@ import su.nightexpress.excellentenchants.api.enchantment.type.CombatEnchant;
import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
public class EnchantCutter extends ExcellentEnchant implements Chanced, CombatEnchant {
@ -36,7 +36,7 @@ public class EnchantCutter extends ExcellentEnchant implements Chanced, CombatEn
private boolean allowMobs;
public EnchantCutter(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.LOWEST);
super(plugin, ID);
this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to throw away enemy''s armor and damage it for " + PLACEHOLDER_DURABILITY_DAMAGE + "%.");
this.getDefaults().setLevelMax(5);
this.getDefaults().setTier(0.75);
@ -76,10 +76,14 @@ public class EnchantCutter extends ExcellentEnchant implements Chanced, CombatEn
return EnchantmentTarget.WEAPON;
}
@NotNull
@Override
public EventPriority getAttackPriority() {
return EventPriority.HIGHEST;
}
@Override
public boolean onAttack(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
if (!this.isAvailableToUse(damager)) return false;
EntityEquipment equipment = victim.getEquipment();
if (equipment == null) return false;

View File

@ -29,7 +29,6 @@ import su.nightexpress.excellentenchants.api.enchantment.meta.Chanced;
import su.nightexpress.excellentenchants.api.enchantment.type.DeathEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import java.util.HashMap;
import java.util.Map;
@ -48,7 +47,7 @@ public class EnchantDecapitator extends ExcellentEnchant implements Chanced, Dea
private final NamespacedKey skullKey;
public EnchantDecapitator(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM);
super(plugin, ID);
this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to obtain player''s or mob''s head.");
this.getDefaults().setLevelMax(4);
this.getDefaults().setTier(0.75);
@ -185,8 +184,6 @@ public class EnchantDecapitator extends ExcellentEnchant implements Chanced, Dea
@Override
public boolean onKill(@NotNull EntityDeathEvent event, @NotNull LivingEntity entity, @NotNull Player killer, int level) {
if (!this.isAvailableToUse(entity)) return false;
EntityType entityType = entity.getType();
if (this.ignoredEntityTypes.contains(entityType)) return false;
if (!this.checkTriggerChance(level)) return false;

View File

@ -4,6 +4,7 @@ import org.bukkit.Particle;
import org.bukkit.Sound;
import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
@ -15,7 +16,6 @@ import su.nightexpress.excellentenchants.api.enchantment.meta.Chanced;
import su.nightexpress.excellentenchants.api.enchantment.type.CombatEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
public class EnchantDoubleStrike extends ExcellentEnchant implements Chanced, CombatEnchant {
@ -24,7 +24,7 @@ public class EnchantDoubleStrike extends ExcellentEnchant implements Chanced, Co
private ChanceImplementation chanceImplementation;
public EnchantDoubleStrike(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.LOW);
super(plugin, ID);
this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to inflict double damage.");
this.getDefaults().setLevelMax(4);
this.getDefaults().setTier(1.0);
@ -49,9 +49,14 @@ public class EnchantDoubleStrike extends ExcellentEnchant implements Chanced, Co
return EnchantmentTarget.WEAPON;
}
@NotNull
@Override
public EventPriority getAttackPriority() {
return EventPriority.HIGHEST;
}
@Override
public boolean onAttack(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
if (!this.isAvailableToUse(damager)) return false;
if (!this.checkTriggerChance(level)) return false;
event.setDamage(event.getDamage() * 2D);

View File

@ -3,6 +3,7 @@ package su.nightexpress.excellentenchants.enchantment.impl.weapon;
import org.bukkit.Material;
import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffectType;
@ -16,7 +17,6 @@ import su.nightexpress.excellentenchants.api.enchantment.type.CombatEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.impl.meta.PotionImplementation;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
public class EnchantExhaust extends ExcellentEnchant implements Chanced, Potioned, CombatEnchant {
@ -26,7 +26,7 @@ public class EnchantExhaust extends ExcellentEnchant implements Chanced, Potione
private PotionImplementation potionImplementation;
public EnchantExhaust(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM);
super(plugin, ID);
this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to apply " + Placeholders.ENCHANTMENT_POTION_TYPE + " " + Placeholders.ENCHANTMENT_POTION_LEVEL + " (" + Placeholders.ENCHANTMENT_POTION_DURATION + "s.) on hit.");
this.getDefaults().setLevelMax(3);
this.getDefaults().setTier(0.1);
@ -60,9 +60,14 @@ public class EnchantExhaust extends ExcellentEnchant implements Chanced, Potione
return EnchantmentTarget.WEAPON;
}
@NotNull
@Override
public EventPriority getAttackPriority() {
return EventPriority.HIGHEST;
}
@Override
public boolean onAttack(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
if (!this.isAvailableToUse(damager)) return false;
if (!this.checkTriggerChance(level)) return false;
if (!this.addEffect(victim, level)) return false;

View File

@ -12,7 +12,6 @@ import su.nightexpress.excellentenchants.Placeholders;
import su.nightexpress.excellentenchants.api.enchantment.type.DeathEnchant;
import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
public class EnchantExpHunter extends ExcellentEnchant implements DeathEnchant {
@ -22,7 +21,7 @@ public class EnchantExpHunter extends ExcellentEnchant implements DeathEnchant {
private EnchantScaler expModifier;
public EnchantExpHunter(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM);
super(plugin, ID);
this.getDefaults().setDescription("Increases exp drop from mobs by " + PLACEHOLDER_EXP_MODIFIER + "%.");
this.getDefaults().setLevelMax(5);
this.getDefaults().setTier(0.3);
@ -50,8 +49,6 @@ public class EnchantExpHunter extends ExcellentEnchant implements DeathEnchant {
@Override
public boolean onKill(@NotNull EntityDeathEvent event, @NotNull LivingEntity entity, @NotNull Player killer, int level) {
if (!this.isAvailableToUse(entity)) return false;
double expModifier = this.getExpModifier(level);
double expFinal = Math.ceil((double) event.getDroppedExp() * expModifier);

View File

@ -3,6 +3,7 @@ package su.nightexpress.excellentenchants.enchantment.impl.weapon;
import org.bukkit.Material;
import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffectType;
@ -16,7 +17,6 @@ import su.nightexpress.excellentenchants.api.enchantment.type.CombatEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.impl.meta.PotionImplementation;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
public class EnchantIceAspect extends ExcellentEnchant implements Chanced, Potioned, CombatEnchant {
@ -26,7 +26,7 @@ public class EnchantIceAspect extends ExcellentEnchant implements Chanced, Potio
private PotionImplementation potionImplementation;
public EnchantIceAspect(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM);
super(plugin, ID);
this.getDefaults().setDescription("Freezes and applies " + Placeholders.ENCHANTMENT_POTION_TYPE + " " + Placeholders.ENCHANTMENT_POTION_LEVEL + " (" + Placeholders.ENCHANTMENT_POTION_DURATION + "s.) on hit.");
this.getDefaults().setLevelMax(3);
this.getDefaults().setTier(0.1);
@ -59,9 +59,14 @@ public class EnchantIceAspect extends ExcellentEnchant implements Chanced, Potio
return EnchantmentTarget.WEAPON;
}
@NotNull
@Override
public EventPriority getAttackPriority() {
return EventPriority.HIGHEST;
}
@Override
public boolean onAttack(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
if (!this.isAvailableToUse(damager)) return false;
if (!this.checkTriggerChance(level)) return false;
if (!this.addEffect(victim, level)) return false;

View File

@ -10,15 +10,16 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.api.manager.EventListener;
import su.nexmedia.engine.utils.NumberUtil;
import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.Placeholders;
import su.nightexpress.excellentenchants.api.enchantment.type.GenericEnchant;
import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils;
public class EnchantInfernus extends ExcellentEnchant {
public class EnchantInfernus extends ExcellentEnchant implements GenericEnchant, EventListener {
public static final String ID = "infernus";
public static final String PLACEHOLDER_FIRE_DURATION = "%enchantment_fire_duration%";
@ -26,7 +27,7 @@ public class EnchantInfernus extends ExcellentEnchant {
private EnchantScaler fireTicks;
public EnchantInfernus(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM);
super(plugin, ID);
this.getDefaults().setDescription("Launched trident will ignite the enemy for " + PLACEHOLDER_FIRE_DURATION + "s. on hit.");
this.getDefaults().setLevelMax(3);
this.getDefaults().setTier(0.1);

View File

@ -3,15 +3,15 @@ package su.nightexpress.excellentenchants.enchantment.impl.weapon;
import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.utils.PlayerUtil;
import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.api.enchantment.meta.Chanced;
import su.nightexpress.excellentenchants.api.enchantment.type.DeathEnchant;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
public class EnchantNimble extends ExcellentEnchant implements Chanced, DeathEnchant {
@ -21,7 +21,7 @@ public class EnchantNimble extends ExcellentEnchant implements Chanced, DeathEnc
private ChanceImplementation chanceImplementation;
public EnchantNimble(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.LOWEST);
super(plugin, ID);
this.getDefaults().setDescription("Moves all mob's loot directly to your inventory.");
this.getDefaults().setLevelMax(1);
this.getDefaults().setTier(0.4);
@ -45,9 +45,14 @@ public class EnchantNimble extends ExcellentEnchant implements Chanced, DeathEnc
return EnchantmentTarget.WEAPON;
}
@NotNull
@Override
public EventPriority getKillPriority() {
return EventPriority.HIGHEST;
}
@Override
public boolean onKill(@NotNull EntityDeathEvent event, @NotNull LivingEntity entity, @NotNull Player killer, int level) {
if (!this.isAvailableToUse(entity)) return false;
if (!this.checkTriggerChance(level)) return false;
event.getDrops().forEach(item -> PlayerUtil.addItem(killer, item));

View File

@ -3,6 +3,7 @@ package su.nightexpress.excellentenchants.enchantment.impl.weapon;
import org.bukkit.Particle;
import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffectType;
@ -16,7 +17,6 @@ import su.nightexpress.excellentenchants.api.enchantment.type.CombatEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.impl.meta.PotionImplementation;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
public class EnchantParalyze extends ExcellentEnchant implements Chanced, Potioned, CombatEnchant {
@ -26,7 +26,7 @@ public class EnchantParalyze extends ExcellentEnchant implements Chanced, Potion
private PotionImplementation potionImplementation;
public EnchantParalyze(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM);
super(plugin, ID);
this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to apply " + Placeholders.ENCHANTMENT_POTION_TYPE + " " + Placeholders.ENCHANTMENT_POTION_LEVEL + " (" + Placeholders.ENCHANTMENT_POTION_DURATION + "s.) on hit.");
this.getDefaults().setLevelMax(3);
this.getDefaults().setTier(0.3);
@ -60,9 +60,14 @@ public class EnchantParalyze extends ExcellentEnchant implements Chanced, Potion
return EnchantmentTarget.WEAPON;
}
@NotNull
@Override
public EventPriority getAttackPriority() {
return EventPriority.HIGHEST;
}
@Override
public boolean onAttack(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
if (!this.isAvailableToUse(damager)) return false;
if (!this.checkTriggerChance(level)) return false;
if (!this.addEffect(victim, level)) return false;

View File

@ -3,6 +3,7 @@ package su.nightexpress.excellentenchants.enchantment.impl.weapon;
import org.bukkit.Particle;
import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffectType;
@ -16,7 +17,6 @@ import su.nightexpress.excellentenchants.api.enchantment.type.CombatEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.impl.meta.PotionImplementation;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
public class EnchantRage extends ExcellentEnchant implements Chanced, Potioned, CombatEnchant {
@ -26,7 +26,7 @@ public class EnchantRage extends ExcellentEnchant implements Chanced, Potioned,
private PotionImplementation potionImplementation;
public EnchantRage(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM);
super(plugin, ID);
this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to get " + Placeholders.ENCHANTMENT_POTION_TYPE + " " + Placeholders.ENCHANTMENT_POTION_LEVEL + " (" + Placeholders.ENCHANTMENT_POTION_DURATION + "s.) on hit.");
this.getDefaults().setLevelMax(3);
this.getDefaults().setTier(0.5);
@ -60,9 +60,14 @@ public class EnchantRage extends ExcellentEnchant implements Chanced, Potioned,
return EnchantmentTarget.WEAPON;
}
@NotNull
@Override
public EventPriority getAttackPriority() {
return EventPriority.HIGHEST;
}
@Override
public boolean onAttack(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
if (!this.isAvailableToUse(damager)) return false;
if (!this.checkTriggerChance(level)) return false;
if (!this.addEffect(damager, level)) return false;

View File

@ -5,6 +5,7 @@ import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Firework;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.FireworkMeta;
@ -18,7 +19,6 @@ import su.nightexpress.excellentenchants.api.enchantment.type.CombatEnchant;
import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
public class EnchantRocket extends ExcellentEnchant implements Chanced, CombatEnchant {
@ -28,7 +28,7 @@ public class EnchantRocket extends ExcellentEnchant implements Chanced, CombatEn
private ChanceImplementation chanceImplementation;
public EnchantRocket(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM);
super(plugin, ID);
this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to launch your enemy into the space.");
this.getDefaults().setLevelMax(3);
this.getDefaults().setTier(0.5);
@ -60,9 +60,14 @@ public class EnchantRocket extends ExcellentEnchant implements Chanced, CombatEn
return EnchantmentTarget.WEAPON;
}
@NotNull
@Override
public EventPriority getAttackPriority() {
return EventPriority.HIGHEST;
}
@Override
public boolean onAttack(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
if (!this.isAvailableToUse(damager)) return false;
if (!this.checkTriggerChance(level)) return false;
if (victim.isInsideVehicle()) {

View File

@ -17,7 +17,6 @@ import su.nightexpress.excellentenchants.api.enchantment.meta.Chanced;
import su.nightexpress.excellentenchants.api.enchantment.type.DeathEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import java.util.HashMap;
import java.util.Map;
@ -31,7 +30,7 @@ public class EnchantScavenger extends ExcellentEnchant implements Chanced, Death
private ChanceImplementation chanceImplementation;
public EnchantScavenger(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM);
super(plugin, ID);
this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to obtain additional loot from mobs.");
this.getDefaults().setLevelMax(3);
this.getDefaults().setTier(0.3);
@ -100,8 +99,6 @@ public class EnchantScavenger extends ExcellentEnchant implements Chanced, Death
@Override
public boolean onKill(@NotNull EntityDeathEvent event, @NotNull LivingEntity entity, @NotNull Player killer, int level) {
if (!this.isAvailableToUse(entity)) return false;
Map<Material, Pair<int[], Double>> items = this.loot.get(entity.getType());
if (items == null) return false;

View File

@ -4,6 +4,7 @@ import org.bukkit.Color;
import org.bukkit.Particle;
import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
@ -19,7 +20,6 @@ import su.nightexpress.excellentenchants.api.enchantment.type.CombatEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.impl.meta.PotionImplementation;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
public class EnchantSurprise extends ExcellentEnchant implements Chanced, Potioned, CombatEnchant {
@ -29,7 +29,7 @@ public class EnchantSurprise extends ExcellentEnchant implements Chanced, Potion
private PotionImplementation potionImplementation;
public EnchantSurprise(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM);
super(plugin, ID);
this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to apply random potion effect to enemy on hit.");
this.getDefaults().setLevelMax(3);
this.getDefaults().setTier(0.75);
@ -63,9 +63,14 @@ public class EnchantSurprise extends ExcellentEnchant implements Chanced, Potion
return EnchantmentTarget.WEAPON;
}
@NotNull
@Override
public EventPriority getAttackPriority() {
return EventPriority.HIGHEST;
}
@Override
public boolean onAttack(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
if (!this.isAvailableToUse(damager)) return false;
if (!this.checkTriggerChance(level)) return false;
PotionEffect effect = new PotionEffect(Rnd.get(PotionEffectType.values()), this.getEffectDuration(level), Math.max(0, this.getEffectAmplifier(level) - 1), false, false);

View File

@ -3,6 +3,7 @@ package su.nightexpress.excellentenchants.enchantment.impl.weapon;
import org.bukkit.attribute.Attribute;
import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
@ -13,7 +14,6 @@ import su.nightexpress.excellentenchants.Placeholders;
import su.nightexpress.excellentenchants.api.enchantment.type.CombatEnchant;
import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
public class EnchantTemper extends ExcellentEnchant implements CombatEnchant {
@ -27,7 +27,7 @@ public class EnchantTemper extends ExcellentEnchant implements CombatEnchant {
private EnchantScaler healthPoint;
public EnchantTemper(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM);
super(plugin, ID);
this.getDefaults().setDescription("Inflicts " + PLACEHOLDER_DAMAGE_AMOUNT + "% (max. " + PLACEHOLDER_DAMAGE_CAPACITY + "%) more damage for each " + PLACEHOLDER_HEALTH_POINT + " hearts missing.");
this.getDefaults().setLevelMax(5);
this.getDefaults().setTier(0.3);
@ -67,10 +67,14 @@ public class EnchantTemper extends ExcellentEnchant implements CombatEnchant {
return EnchantmentTarget.WEAPON;
}
@NotNull
@Override
public EventPriority getAttackPriority() {
return EventPriority.NORMAL;
}
@Override
public boolean onAttack(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
if (!this.isAvailableToUse(damager)) return false;
double healthPoint = this.getHealthPoint(level);
double healthHas = damager.getHealth();
double healthMax = EntityUtil.getAttribute(damager, Attribute.GENERIC_MAX_HEALTH);

View File

@ -20,7 +20,6 @@ import su.nightexpress.excellentenchants.api.enchantment.meta.Chanced;
import su.nightexpress.excellentenchants.api.enchantment.type.DeathEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import java.util.Objects;
import java.util.Set;
@ -37,7 +36,7 @@ public class EnchantThrifty extends ExcellentEnchant implements Chanced, DeathEn
private ChanceImplementation chanceImplementation;
public EnchantThrifty(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM);
super(plugin, ID);
this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to obtain mob spawn egg on kill.");
this.getDefaults().setLevelMax(3);
this.getDefaults().setTier(0.75);
@ -82,8 +81,6 @@ public class EnchantThrifty extends ExcellentEnchant implements Chanced, DeathEn
@Override
public boolean onKill(@NotNull EntityDeathEvent event, @NotNull LivingEntity entity, @NotNull Player killer, int level) {
if (!this.isAvailableToUse(entity)) return false;
if (this.ignoredEntityTypes.contains(entity.getType())) return false;
if (PDCUtil.getBoolean(entity, this.keyEntityIgnored).orElse(false)) return false;
if (!this.checkTriggerChance(level)) return false;

View File

@ -12,10 +12,9 @@ import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.api.config.JOption;
import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.Placeholders;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.api.enchantment.meta.Chanced;
import su.nightexpress.excellentenchants.api.enchantment.type.CombatEnchant;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
public class EnchantThunder extends ExcellentEnchant implements Chanced, CombatEnchant {
@ -28,7 +27,7 @@ public class EnchantThunder extends ExcellentEnchant implements Chanced, CombatE
private ChanceImplementation chanceImplementation;
public EnchantThunder(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM);
super(plugin, ID);
this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to summon lightning to enemy on hit.");
this.getDefaults().setLevelMax(3);
this.getDefaults().setTier(0.3);
@ -59,9 +58,14 @@ public class EnchantThunder extends ExcellentEnchant implements Chanced, CombatE
return EnchantmentTarget.WEAPON;
}
@NotNull
@Override
public EventPriority getAttackPriority() {
return EventPriority.HIGHEST;
}
@Override
public boolean onAttack(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
if (!this.isAvailableToUse(damager)) return false;
if (this.isInThunderstormOnly() && !victim.getWorld().isThundering()) return false;
if (victim.getLocation().getBlock().getLightFromSky() != 15) return false;
if (!this.checkTriggerChance(level)) return false;

View File

@ -4,6 +4,7 @@ import org.bukkit.Particle;
import org.bukkit.attribute.Attribute;
import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityRegainHealthEvent;
import org.bukkit.inventory.ItemStack;
@ -19,7 +20,6 @@ import su.nightexpress.excellentenchants.api.enchantment.type.CombatEnchant;
import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
public class EnchantVampire extends ExcellentEnchant implements Chanced, CombatEnchant {
@ -31,7 +31,7 @@ public class EnchantVampire extends ExcellentEnchant implements Chanced, CombatE
private ChanceImplementation chanceImplementation;
public EnchantVampire(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.LOWEST);
super(plugin, ID);
this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to heal for " + PLACEHOLDER_HEAL_AMOUNT + " heart(s) on hit.");
this.getDefaults().setLevelMax(4);
this.getDefaults().setTier(0.75);
@ -72,10 +72,14 @@ public class EnchantVampire extends ExcellentEnchant implements Chanced, CombatE
return EnchantmentTarget.WEAPON;
}
@NotNull
@Override
public EventPriority getAttackPriority() {
return EventPriority.MONITOR;
}
@Override
public boolean onAttack(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
if (!this.isAvailableToUse(damager)) return false;
double healthMax = EntityUtil.getAttribute(damager, Attribute.GENERIC_MAX_HEALTH);
double healthHas = damager.getHealth();
if (healthHas == healthMax) return false;
@ -83,7 +87,7 @@ public class EnchantVampire extends ExcellentEnchant implements Chanced, CombatE
if (!this.checkTriggerChance(level)) return false;
double healAmount = this.getHealAmount(level);
double healFinal = this.isHealMultiplier() ? event.getDamage() * healAmount : healAmount;
double healFinal = this.isHealMultiplier() ? event.getFinalDamage() * healAmount : healAmount;
EntityRegainHealthEvent healthEvent = new EntityRegainHealthEvent(damager, healFinal, EntityRegainHealthEvent.RegainReason.CUSTOM);
plugin.getPluginManager().callEvent(healthEvent);

View File

@ -3,6 +3,7 @@ package su.nightexpress.excellentenchants.enchantment.impl.weapon;
import org.bukkit.Particle;
import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffectType;
@ -16,7 +17,6 @@ import su.nightexpress.excellentenchants.api.enchantment.type.CombatEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.impl.meta.PotionImplementation;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
public class EnchantVenom extends ExcellentEnchant implements Chanced, Potioned, CombatEnchant {
@ -26,7 +26,7 @@ public class EnchantVenom extends ExcellentEnchant implements Chanced, Potioned,
private PotionImplementation potionImplementation;
public EnchantVenom(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM);
super(plugin, ID);
this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to apply " + Placeholders.ENCHANTMENT_POTION_TYPE + " " + Placeholders.ENCHANTMENT_POTION_LEVEL + " (" + Placeholders.ENCHANTMENT_POTION_DURATION + "s.) on hit.");
this.getDefaults().setLevelMax(3);
this.getDefaults().setTier(0.3);
@ -60,9 +60,14 @@ public class EnchantVenom extends ExcellentEnchant implements Chanced, Potioned,
return EnchantmentTarget.WEAPON;
}
@NotNull
@Override
public EventPriority getAttackPriority() {
return EventPriority.HIGHEST;
}
@Override
public boolean onAttack(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
if (!this.isAvailableToUse(damager)) return false;
if (!this.checkTriggerChance(level)) return false;
if (!this.addEffect(victim, level)) return false;

View File

@ -15,7 +15,6 @@ import su.nightexpress.excellentenchants.Placeholders;
import su.nightexpress.excellentenchants.api.enchantment.type.CombatEnchant;
import su.nightexpress.excellentenchants.enchantment.config.EnchantScaler;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
public class EnchantVillageDefender extends ExcellentEnchant implements CombatEnchant {
@ -26,7 +25,7 @@ public class EnchantVillageDefender extends ExcellentEnchant implements CombatEn
private EnchantScaler damageAmount;
public EnchantVillageDefender(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM);
super(plugin, ID);
this.getDefaults().setDescription("Inflicts " + PLACEHOLDER_DAMAGE_AMOUNT + " more damage to all pillagers.");
this.getDefaults().setLevelMax(5);
this.getDefaults().setTier(0.1);
@ -62,7 +61,6 @@ public class EnchantVillageDefender extends ExcellentEnchant implements CombatEn
@Override
public boolean onAttack(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
if (!this.isAvailableToUse(damager)) return false;
if (!(victim instanceof Illager)) return false;
double damageAdd = this.getDamageAddict(level);

View File

@ -3,6 +3,7 @@ package su.nightexpress.excellentenchants.enchantment.impl.weapon;
import org.bukkit.Particle;
import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffectType;
@ -16,7 +17,6 @@ import su.nightexpress.excellentenchants.api.enchantment.type.CombatEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.impl.meta.PotionImplementation;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
public class EnchantWither extends ExcellentEnchant implements Chanced, Potioned, CombatEnchant {
@ -26,7 +26,7 @@ public class EnchantWither extends ExcellentEnchant implements Chanced, Potioned
private PotionImplementation potionImplementation;
public EnchantWither(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM);
super(plugin, ID);
this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to apply " + Placeholders.ENCHANTMENT_POTION_TYPE + " " + Placeholders.ENCHANTMENT_POTION_LEVEL + " (" + Placeholders.ENCHANTMENT_POTION_DURATION + "s.) on hit.");
this.getDefaults().setLevelMax(3);
this.getDefaults().setTier(0.5);
@ -60,9 +60,14 @@ public class EnchantWither extends ExcellentEnchant implements Chanced, Potioned
return EnchantmentTarget.WEAPON;
}
@NotNull
@Override
public EventPriority getAttackPriority() {
return EventPriority.HIGHEST;
}
@Override
public boolean onAttack(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
if (!this.isAvailableToUse(damager)) return false;
if (!this.checkTriggerChance(level)) return false;
if (!this.addEffect(victim, level)) return false;

View File

@ -53,7 +53,7 @@ public class EnchantAnvilListener extends AbstractListener<ExcellentEnchants> {
this.handleEnchantMerging(e, first, second, result);
}
private boolean handleRename(@NotNull PrepareAnvilEvent e,
private boolean handleRename(@NotNull PrepareAnvilEvent event,
@NotNull ItemStack first, @NotNull ItemStack second, @NotNull ItemStack result) {
if (!second.getType().isAir() && (second.getType() == first.getType() || second.getType() == Material.ENCHANTED_BOOK)) return false;
@ -64,11 +64,11 @@ public class EnchantAnvilListener extends AbstractListener<ExcellentEnchants> {
EnchantUtils.add(result2, hasEnch, hasLevel, true);
});
EnchantUtils.updateDisplay(result2);
e.setResult(result2);
event.setResult(result2);
return true;
}
private boolean handleRecharge(@NotNull PrepareAnvilEvent e,
private boolean handleRecharge(@NotNull PrepareAnvilEvent event,
@NotNull ItemStack first, @NotNull ItemStack second, @NotNull ItemStack result) {
if (second.getType().isAir()) return false;
@ -90,12 +90,12 @@ public class EnchantAnvilListener extends AbstractListener<ExcellentEnchants> {
PDCUtil.set(result2, RECHARGED, count);
EnchantUtils.updateDisplay(result2);
e.setResult(result2);
this.plugin.runTask(task -> e.getInventory().setRepairCost(chargable.size()));
event.setResult(result2);
this.plugin.runTask(task -> event.getInventory().setRepairCost(chargable.size()));
return true;
}
private boolean handleEnchantMerging(@NotNull PrepareAnvilEvent e,
private boolean handleEnchantMerging(@NotNull PrepareAnvilEvent event,
@NotNull ItemStack first, @NotNull ItemStack second, @NotNull ItemStack result) {
// Validate items in the first two slots.
if (second.getType().isAir() || second.getAmount() > 1 || !EnchantUtils.isEnchantable(second)) return false;
@ -104,7 +104,7 @@ public class EnchantAnvilListener extends AbstractListener<ExcellentEnchants> {
ItemStack result2 = new ItemStack(result.getType().isAir() ? first : result);
Map<ExcellentEnchant, Integer> enchantments = EnchantUtils.getExcellents(first);
Map<ExcellentEnchant, Integer> charges = new HashMap<>(enchantments.keySet().stream().collect(Collectors.toMap(k -> k, v -> v.getCharges(first))));
AtomicInteger repairCost = new AtomicInteger(e.getInventory().getRepairCost());
AtomicInteger repairCost = new AtomicInteger(event.getInventory().getRepairCost());
// Merge only if it's Item + Item, Item + Enchanted book or Enchanted Book + Enchanted Book
if (second.getType() == Material.ENCHANTED_BOOK || second.getType() == first.getType()) {
@ -125,31 +125,31 @@ public class EnchantAnvilListener extends AbstractListener<ExcellentEnchants> {
if (first.equals(result2)) return false;
EnchantUtils.updateDisplay(result2);
e.setResult(result2);
event.setResult(result2);
// NMS ContainerAnvil will set level cost to 0 right after calling the event, need 1 tick delay.
this.plugin.runTask(task -> e.getInventory().setRepairCost(repairCost.get()));
this.plugin.runTask(task -> event.getInventory().setRepairCost(repairCost.get()));
return true;
}
@EventHandler(priority = EventPriority.NORMAL)
public void onClickAnvil(InventoryClickEvent e) {
if (!(e.getInventory() instanceof AnvilInventory inventory)) return;
if (e.getRawSlot() != 2) return;
public void onClickAnvil(InventoryClickEvent event) {
if (!(event.getInventory() instanceof AnvilInventory inventory)) return;
if (event.getRawSlot() != 2) return;
ItemStack item = e.getCurrentItem();
ItemStack item = event.getCurrentItem();
if (item == null) return;
int count = PDCUtil.getInt(item, RECHARGED).orElse(0);
if (count == 0) return;
Player player = (Player) e.getWhoClicked();
Player player = (Player) event.getWhoClicked();
if (player.getLevel() < inventory.getRepairCost()) return;
player.setLevel(player.getLevel() - inventory.getRepairCost());
PDCUtil.remove(item, RECHARGED);
e.getView().setCursor(item);
e.setCancelled(false);
event.getView().setCursor(item);
event.setCancelled(false);
UniSound.of(Sound.BLOCK_ENCHANTMENT_TABLE_USE).play(player);

View File

@ -2,14 +2,11 @@ package su.nightexpress.excellentenchants.enchantment.listener;
import org.bukkit.World;
import org.bukkit.block.Chest;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.*;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.enchantment.EnchantItemEvent;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.EntityPickupItemEvent;
import org.bukkit.event.entity.VillagerAcquireTradeEvent;
import org.bukkit.event.entity.*;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.event.inventory.InventoryType;
@ -24,6 +21,7 @@ import su.nexmedia.engine.utils.EngineUtils;
import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.config.Config;
import su.nightexpress.excellentenchants.enchantment.EnchantManager;
import su.nightexpress.excellentenchants.enchantment.EnchantPopulator;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.type.ObtainType;
import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils;
@ -39,21 +37,33 @@ public class EnchantGenericListener extends AbstractListener<ExcellentEnchants>
super(enchantManager.plugin());
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onEnchantProjectileShoot(EntityShootBowEvent event) {
if (event.getProjectile() instanceof Projectile projectile) {
EnchantUtils.setSourceWeapon(projectile, event.getBow());
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onEnchantProjectileLand(ProjectileHitEvent event) {
EnchantUtils.removeSourceWeapon(event.getEntity());
}
// ---------------------------------------------------------------
// Update enchantment lore after grindstone
// ---------------------------------------------------------------
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onEnchantUpdateGrindstoneClick(InventoryClickEvent e) {
Inventory inventory = e.getInventory();
public void onEnchantUpdateGrindstoneClick(InventoryClickEvent event) {
Inventory inventory = event.getInventory();
if (inventory.getType() != InventoryType.GRINDSTONE) return;
if (e.getRawSlot() == 2) return;
if (event.getRawSlot() == 2) return;
this.updateGrindstone(inventory);
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onEnchantUpdateGrindstoneDrag(InventoryDragEvent e) {
Inventory inventory = e.getInventory();
public void onEnchantUpdateGrindstoneDrag(InventoryDragEvent event) {
Inventory inventory = event.getInventory();
if (inventory.getType() != InventoryType.GRINDSTONE) return;
this.updateGrindstone(inventory);
@ -80,10 +90,10 @@ public class EnchantGenericListener extends AbstractListener<ExcellentEnchants>
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onEnchantUpdatePickup(EntityPickupItemEvent e) {
if (!(e.getEntity() instanceof Player player)) return;
public void onEnchantUpdatePickup(EntityPickupItemEvent event) {
if (!(event.getEntity() instanceof Player player)) return;
Item item = e.getItem();
Item item = event.getItem();
ItemStack itemStack = item.getItemStack();
if (EnchantUtils.updateDisplay(itemStack)) {
item.setItemStack(itemStack);
@ -98,13 +108,12 @@ public class EnchantGenericListener extends AbstractListener<ExcellentEnchants>
ItemStack target = event.getItem();
World world = event.getEnchanter().getWorld();
Map<Enchantment, Integer> enchantsPrepared = event.getEnchantsToAdd();
Map<Enchantment, Integer> enchantsToPopulate = EnchantUtils.getPopulationCandidates(
target, ObtainType.ENCHANTING, enchantsPrepared,
enchant -> enchant.getLevelByEnchantCost(event.getExpLevelCost()),
world);
EnchantPopulator populator = this.plugin.createPopulator(target, ObtainType.ENCHANTING)
.withWorld(world)
.withLevelGenerator(enchant -> enchant.getLevelByEnchantCost(event.getExpLevelCost()))
.withDefaultPopulation(event.getEnchantsToAdd());
enchantsPrepared.putAll(enchantsToPopulate);
event.getEnchantsToAdd().putAll(populator.createPopulation());
plugin.getServer().getScheduler().runTask(plugin, () -> {
ItemStack result = event.getInventory().getItem(0);
@ -141,10 +150,11 @@ public class EnchantGenericListener extends AbstractListener<ExcellentEnchants>
public void onEnchantPopulateVillagerAcquire(VillagerAcquireTradeEvent event) {
MerchantRecipe recipe = event.getRecipe();
ItemStack result = recipe.getResult();
World world = event.getEntity().getWorld();
if (!EnchantUtils.isEnchantable(result)) return;
if (!EnchantUtils.populate(result, ObtainType.VILLAGER, world)) return;
EnchantPopulator populator = this.plugin.createPopulator(result, ObtainType.VILLAGER)
.withWorld(event.getEntity().getWorld());
if (!populator.populate()) return;
int uses = recipe.getUses();
int maxUses = recipe.getMaxUses();
@ -171,7 +181,9 @@ public class EnchantGenericListener extends AbstractListener<ExcellentEnchants>
if (entity instanceof Minecart || holder instanceof Chest) {
event.getLoot().forEach(item -> {
if (item != null && EnchantUtils.isEnchantable(item)) {
EnchantUtils.populate(item, ObtainType.LOOT_GENERATION, world);
this.plugin.createPopulator(item, ObtainType.LOOT_GENERATION)
.withWorld(world)
.populate();
}
});
}
@ -186,15 +198,18 @@ public class EnchantGenericListener extends AbstractListener<ExcellentEnchants>
ItemStack itemStack = item.getItemStack();
World world = item.getWorld();
if (EnchantUtils.isEnchantable(itemStack)) {
EnchantUtils.populate(itemStack, ObtainType.FISHING, world);
this.plugin.createPopulator(itemStack, ObtainType.FISHING).withWorld(world).populate();
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onEnchantPopulateSpawn(CreatureSpawnEvent e) {
public void onEnchantPopulateSpawn(CreatureSpawnEvent event) {
//if (Config.getObtainSettings(ObtainType.MOB_SPAWNING).isEmpty()) return;
LivingEntity entity = e.getEntity();
LivingEntity entity = event.getEntity();
if (entity.getType() == EntityType.ARMOR_STAND) return;
if (event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.DISPENSE_EGG) return;
if (event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.SPAWNER_EGG) return;
if (event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.SPAWNER) return;
this.plugin.runTaskLater(task -> {
EntityEquipment equipment = entity.getEquipment();
@ -207,7 +222,9 @@ public class EnchantGenericListener extends AbstractListener<ExcellentEnchants>
for (EquipmentSlot slot : EquipmentSlot.values()) {
ItemStack item = equipment.getItem(slot);
if (EnchantUtils.isEnchantable(item)) {
if (doPopulation) EnchantUtils.populate(item, ObtainType.MOB_SPAWNING, world);
if (doPopulation) {
this.plugin.createPopulator(item, ObtainType.MOB_SPAWNING).withWorld(world).populate();
}
EnchantUtils.getExcellents(item).forEach((enchant, level) -> EnchantUtils.restoreCharges(item, enchant, level));
equipment.setItem(slot, item);
}

View File

@ -1,82 +1,37 @@
package su.nightexpress.excellentenchants.enchantment.listener;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.Event.Result;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockDropItemEvent;
import org.bukkit.event.entity.*;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.player.PlayerFishEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.FixedMetadataValue;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import su.nexmedia.engine.api.manager.AbstractListener;
import su.nexmedia.engine.utils.EntityUtil;
import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.api.enchantment.meta.Arrowed;
import su.nightexpress.excellentenchants.api.enchantment.type.*;
import su.nightexpress.excellentenchants.config.Config;
import su.nightexpress.excellentenchants.enchantment.EnchantManager;
import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils;
public class EnchantHandlerListener extends AbstractListener<ExcellentEnchants> {
private static final String META_PROJECTILE_WEAPON = "sourceWeapon";
public EnchantHandlerListener(@NotNull EnchantManager enchantManager) {
super(enchantManager.plugin());
}
private void setSourceWeapon(@NotNull Projectile projectile, @NotNull ItemStack item) {
projectile.setMetadata(META_PROJECTILE_WEAPON, new FixedMetadataValue(plugin, item));
}
@Nullable
private ItemStack getSourceWeapon(@NotNull Projectile projectile) {
return projectile.hasMetadata(META_PROJECTILE_WEAPON) ? (ItemStack) projectile.getMetadata(META_PROJECTILE_WEAPON).get(0).value() : null;
}
private void removeSourceWeapon(@NotNull Projectile projectile) {
projectile.removeMetadata(META_PROJECTILE_WEAPON, plugin);
}
// ---------------------------------------------------------------
// Combat Attacking Enchants
// ---------------------------------------------------------------
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onEnchantCombatMelee(EntityDamageEvent e) {
if (e.getCause() == DamageCause.THORNS) return;
if (!(e.getEntity() instanceof LivingEntity victim)) return;
/*@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onEnchantCombatMelee(EntityDamageEvent event) {
if (event.getCause() == DamageCause.THORNS) return;
if (!(event.getEntity() instanceof LivingEntity victim)) return;
if (e instanceof EntityDamageByEntityEvent ede) {
LivingEntity damager = null;
if (ede.getDamager() instanceof LivingEntity living) {
damager = living;
}
else if (ede.getDamager() instanceof Projectile pj && pj.getShooter() instanceof LivingEntity living) {
damager = living;
}
if (damager == null || damager.equals(victim)) return;
if (ede.getDamager() instanceof Projectile projectile) {
if (event instanceof EntityDamageByEntityEvent ede) {
if (ede.getDamager() instanceof Projectile projectile && this.getSourceWeapon(projectile) != null) {
this.handleCombatBowEnchants(ede, projectile, victim);
return;
}
else {
this.handleCombatWeaponEnchants(ede, damager, victim);
}
if (!(ede.getDamager() instanceof LivingEntity damager) || damager == victim) return;
this.handleCombatWeaponEnchants(ede, damager, victim);
this.handleCombatArmorEnchants(ede, damager, victim);
}
else {
this.handleArmorEnchants(e, victim);
this.handleArmorEnchants(event, victim);
}
}
@ -145,17 +100,17 @@ public class EnchantHandlerListener extends AbstractListener<ExcellentEnchants>
// Bow Shooting Enchants
// ---------------------------------------------------------------
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onEnchantBowShoot(EntityShootBowEvent e) {
LivingEntity shooter = e.getEntity();
public void onEnchantBowShoot(EntityShootBowEvent event) {
LivingEntity shooter = event.getEntity();
if (shooter.getEquipment() == null) return;
ItemStack bow = e.getBow();
ItemStack bow = event.getBow();
if (bow == null || bow.getType().isAir() || bow.getType() == Material.ENCHANTED_BOOK) return;
EnchantUtils.getExcellents(bow, BowEnchant.class).forEach((bowEnchant, level) -> {
if (bowEnchant.isOutOfCharges(bow)) return;
if (bowEnchant.onShoot(e, shooter, bow, level)) {
if (bowEnchant instanceof Arrowed arrowed && e.getProjectile() instanceof Projectile projectile) {
if (bowEnchant.onShoot(event, shooter, bow, level)) {
if (bowEnchant instanceof Arrowed arrowed && event.getProjectile() instanceof Projectile projectile) {
arrowed.addData(projectile);
arrowed.addTrail(projectile);
}
@ -164,7 +119,7 @@ public class EnchantHandlerListener extends AbstractListener<ExcellentEnchants>
});
EnchantUtils.updateChargesDisplay(bow);
if (e.getProjectile() instanceof Projectile projectile) {
if (event.getProjectile() instanceof Projectile projectile) {
this.setSourceWeapon(projectile, bow);
}
}
@ -173,35 +128,35 @@ public class EnchantHandlerListener extends AbstractListener<ExcellentEnchants>
// Bow Hit Land Enchants
// ---------------------------------------------------------------
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onEnchantBowHit(ProjectileHitEvent e) {
Projectile projectile = e.getEntity();
public void onEnchantBowHit(ProjectileHitEvent event) {
Projectile projectile = event.getEntity();
ItemStack bow = this.getSourceWeapon(projectile);
if (bow == null || bow.getType().isAir() || bow.getType() == Material.ENCHANTED_BOOK) return;
EnchantUtils.getExcellents(bow, BowEnchant.class).forEach((bowEnchant, level) -> {
bowEnchant.onHit(e, projectile, bow, level);
bowEnchant.onHit(event, null, projectile, bow, level);
});
// Prevent to apply enchants multiple times on hits.
this.plugin.getScheduler().runTask(this.plugin, c -> this.removeSourceWeapon(projectile));
this.plugin.runTask(task -> this.removeSourceWeapon(projectile));
}
// ---------------------------------------------------------------
// Interaction Related Enchants
// ---------------------------------------------------------------
@EventHandler(priority = EventPriority.HIGHEST)
public void onEnchantInteract(PlayerInteractEvent e) {
if (e.useInteractedBlock() == Result.DENY) return;
if (e.useItemInHand() == Result.DENY) return;
public void onEnchantInteract(PlayerInteractEvent event) {
if (event.useInteractedBlock() == Result.DENY) return;
if (event.useItemInHand() == Result.DENY) return;
ItemStack item = e.getItem();
ItemStack item = event.getItem();
if (item == null || item.getType().isAir() || item.getType() == Material.ENCHANTED_BOOK) return;
Player player = e.getPlayer();
Player player = event.getPlayer();
EnchantUtils.getExcellents(item, InteractEnchant.class).forEach((interEnchant, level) -> {
if (interEnchant.isOutOfCharges(item)) return;
if (interEnchant.onInteract(e, player, item, level)) {
if (interEnchant.onInteract(event, player, item, level)) {
interEnchant.consumeChargesNoUpdate(item, level);
}
});
@ -261,8 +216,8 @@ public class EnchantHandlerListener extends AbstractListener<ExcellentEnchants>
// Handle BlockBreak enchantments.
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onEnchantBlockBreak(BlockBreakEvent e) {
Player player = e.getPlayer();
public void onEnchantBlockBreak(BlockBreakEvent event) {
Player player = event.getPlayer();
if (player.getGameMode() == GameMode.CREATIVE) return;
ItemStack tool = player.getInventory().getItemInMainHand();
@ -270,7 +225,7 @@ public class EnchantHandlerListener extends AbstractListener<ExcellentEnchants>
EnchantUtils.getExcellents(tool, BlockBreakEnchant.class).forEach((blockEnchant, level) -> {
if (blockEnchant.isOutOfCharges(tool)) return;
if (blockEnchant.onBreak(e, player, tool, level)) {
if (blockEnchant.onBreak(event, player, tool, level)) {
blockEnchant.consumeChargesNoUpdate(tool, level);
}
});
@ -285,7 +240,6 @@ public class EnchantHandlerListener extends AbstractListener<ExcellentEnchants>
ItemStack tool = player.getInventory().getItemInMainHand();
if (tool.getType().isAir() || tool.getType() == Material.ENCHANTED_BOOK) return;
//EnchantDropContainer dropContainer = new EnchantDropContainer(e);
EnchantUtils.getExcellents(tool, BlockDropEnchant.class).forEach((enchant, level) -> {
if (enchant.isOutOfCharges(tool)) return;
if (enchant.onDrop(event, player, tool, level)) {
@ -293,11 +247,5 @@ public class EnchantHandlerListener extends AbstractListener<ExcellentEnchants>
}
});
EnchantUtils.updateChargesDisplay(tool);
//BlockState state = e.getBlockState();
//World world = state.getWorld();
//Location location = state.getLocation();
//dropContainer.getDrop().forEach(item -> world.dropItem(location, item));
}
}*/
}

View File

@ -18,8 +18,8 @@ import su.nexmedia.engine.utils.PDCUtil;
import su.nexmedia.engine.utils.StringUtil;
import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.Placeholders;
import su.nightexpress.excellentenchants.enchantment.EnchantRegistry;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.registry.EnchantRegistry;
import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils;
import java.util.*;

View File

@ -1,21 +1,37 @@
package su.nightexpress.excellentenchants.enchantment;
package su.nightexpress.excellentenchants.enchantment.registry;
import org.bukkit.NamespacedKey;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.event.Event;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockDropItemEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityShootBowEvent;
import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.event.player.PlayerFishEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import su.nexmedia.engine.Version;
import su.nexmedia.engine.api.manager.AbstractManager;
import su.nexmedia.engine.utils.Reflex;
import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.api.enchantment.IEnchantment;
import su.nightexpress.excellentenchants.api.enchantment.type.*;
import su.nightexpress.excellentenchants.config.Config;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.armor.*;
import su.nightexpress.excellentenchants.enchantment.impl.bow.*;
import su.nightexpress.excellentenchants.enchantment.impl.fishing.*;
import su.nightexpress.excellentenchants.enchantment.impl.tool.*;
import su.nightexpress.excellentenchants.enchantment.impl.universal.EnchantCurseOfFragility;
import su.nightexpress.excellentenchants.enchantment.impl.universal.CurseOfFragilityEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.universal.SoulboundEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.weapon.*;
import su.nightexpress.excellentenchants.enchantment.registry.wrapper.DataGather;
import su.nightexpress.excellentenchants.enchantment.registry.wrapper.DataGathers;
import su.nightexpress.excellentenchants.enchantment.registry.wrapper.WrappedEvent;
import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils;
import su.nightexpress.excellentenchants.tier.Tier;
@ -23,18 +39,34 @@ import java.util.*;
import java.util.function.Supplier;
import java.util.stream.Collectors;
public class EnchantRegistry {
public class EnchantRegistry extends AbstractManager<ExcellentEnchants> {
public static final Map<NamespacedKey, ExcellentEnchant> REGISTRY_MAP = new HashMap<>();
private static final Map<Class<? extends IEnchantment>, Set<? super IEnchantment>> ENCHANTS_MAP = new HashMap<>();
private final ExcellentEnchants plugin;
private boolean isLocked;
public EnchantRegistry(@NotNull ExcellentEnchants plugin) {
this.plugin = plugin;
super(plugin);
}
public void setup() {
@Override
protected void onLoad() {
this.registerType(GenericEnchant.class);
this.registerType(PassiveEnchant.class);
this.registerWrapper(BlockBreakEvent.class, BlockBreakEnchant.class, DataGathers.BLOCK_BREAK);
this.registerWrapper(BlockDropItemEvent.class, BlockDropEnchant.class, DataGathers.BLOCK_DROP);
this.registerWrapper(EntityShootBowEvent.class, BowEnchant.class, DataGathers.BOW_SHOOT);
this.registerWrapper(ProjectileHitEvent.class, BowEnchant.class, DataGathers.PROJECTILE_HIT);
this.registerWrapper(EntityDamageByEntityEvent.class, BowEnchant.class, DataGathers.ENTITY_DAMAGE_SHOOT);
this.registerWrapper(EntityDamageByEntityEvent.class, CombatEnchant.class, DataGathers.ENTITY_DAMAGE_ATTACK);
this.registerWrapper(EntityDamageByEntityEvent.class, CombatEnchant.class, DataGathers.ENTITY_DAMAGE_DEFENSE);
this.registerWrapper(EntityDeathEvent.class, DeathEnchant.class, DataGathers.ENTITY_KILL);
this.registerWrapper(EntityDeathEvent.class, DeathEnchant.class, DataGathers.ENTITY_DEATH);
this.registerWrapper(PlayerFishEvent.class, FishingEnchant.class, DataGathers.FISHING);
this.registerWrapper(PlayerInteractEvent.class, InteractEnchant.class, DataGathers.INTERACT);
// Prevent to register enchantments during the runtime.
if (this.isLocked) {
REGISTRY_MAP.values().forEach(enchant -> {
@ -46,7 +78,7 @@ public class EnchantRegistry {
Reflex.setFieldValue(Enchantment.class, "acceptingNew", true);
// Fising Enchants
// Fishing Enchants
this.register(AutoReelEnchant.ID,() -> new AutoReelEnchant(plugin));
this.register(DoubleCatchEnchant.ID, () -> new DoubleCatchEnchant(plugin));
this.register(SeasonedAnglerEnchant.ID, () -> new SeasonedAnglerEnchant(plugin));
@ -55,19 +87,19 @@ public class EnchantRegistry {
this.register(RiverMasterEnchant.ID, () -> new RiverMasterEnchant(plugin));
// Tool enchants
this.register(EnchantBlastMining.ID, () -> new EnchantBlastMining(plugin));
this.register(EnchantCurseOfBreaking.ID, () -> new EnchantCurseOfBreaking(plugin));
this.register(EnchantCurseOfMisfortune.ID, () -> new EnchantCurseOfMisfortune(plugin));
this.register(EnchantDivineTouch.ID, () -> new EnchantDivineTouch(plugin));
this.register(EnchantHaste.ID, () -> new EnchantHaste(plugin));
this.register(EnchantLuckyMiner.ID, () -> new EnchantLuckyMiner(plugin));
this.register(EnchantReplanter.ID, () -> new EnchantReplanter(plugin));
this.register(EnchantSilkChest.ID, () -> new EnchantSilkChest(plugin));
this.register(EnchantSmelter.ID, () -> new EnchantSmelter(plugin));
this.register(EnchantTelekinesis.ID, () -> new EnchantTelekinesis(plugin));
this.register(EnchantTreasures.ID, () -> new EnchantTreasures(plugin));
this.register(EnchantTunnel.ID, () -> new EnchantTunnel(plugin));
this.register(EnchantVeinminer.ID, () -> new EnchantVeinminer(plugin));
this.register(BlastMiningEnchant.ID, () -> new BlastMiningEnchant(plugin));
this.register(CurseOfBreakingEnchant.ID, () -> new CurseOfBreakingEnchant(plugin));
this.register(CurseOfMisfortuneEnchant.ID, () -> new CurseOfMisfortuneEnchant(plugin));
this.register(DivineTouchEnchant.ID, () -> new DivineTouchEnchant(plugin));
this.register(HasteEnchant.ID, () -> new HasteEnchant(plugin));
this.register(LuckyMinerEnchant.ID, () -> new LuckyMinerEnchant(plugin));
this.register(ReplanterEnchant.ID, () -> new ReplanterEnchant(plugin));
this.register(SilkChestEnchant.ID, () -> new SilkChestEnchant(plugin));
this.register(SmelterEnchant.ID, () -> new SmelterEnchant(plugin));
this.register(TelekinesisEnchant.ID, () -> new TelekinesisEnchant(plugin));
this.register(TreasuresEnchant.ID, () -> new TreasuresEnchant(plugin));
this.register(TunnelEnchant.ID, () -> new TunnelEnchant(plugin));
this.register(VeinminerEnchant.ID, () -> new VeinminerEnchant(plugin));
// Weapon enchants
this.register(EnchantBaneOfNetherspawn.ID, () -> new EnchantBaneOfNetherspawn(plugin));
@ -96,20 +128,20 @@ public class EnchantRegistry {
this.register(EnchantWither.ID, () -> new EnchantWither(plugin));
// Armor enchants
this.register(EnchantAquaman.ID, () -> new EnchantAquaman(plugin));
this.register(EnchantBunnyHop.ID, () -> new EnchantBunnyHop(plugin));
this.register(EnchantColdSteel.ID, () -> new EnchantColdSteel(plugin));
this.register(EnchantIceShield.ID, () -> new EnchantIceShield(plugin));
this.register(EnchantElementalProtection.ID, () -> new EnchantElementalProtection(plugin));
this.register(EnchantFireShield.ID, () -> new EnchantFireShield(plugin));
this.register(EnchantFlameWalker.ID, () -> new EnchantFlameWalker(plugin));
this.register(EnchantHardened.ID, () -> new EnchantHardened(plugin));
this.register(EnchantNightVision.ID, () -> new EnchantNightVision(plugin));
this.register(EnchantRegrowth.ID, () -> new EnchantRegrowth(plugin));
this.register(EnchantSaturation.ID, () -> new EnchantSaturation(plugin));
this.register(EnchantSelfDestruction.ID, () -> new EnchantSelfDestruction(plugin));
this.register(AquamanEnchant.ID, () -> new AquamanEnchant(plugin));
this.register(JumpingEnchant.ID, () -> new JumpingEnchant(plugin));
this.register(ColdSteelEnchant.ID, () -> new ColdSteelEnchant(plugin));
this.register(IceShieldEnchant.ID, () -> new IceShieldEnchant(plugin));
this.register(ElementalProtectionEnchant.ID, () -> new ElementalProtectionEnchant(plugin));
this.register(FireShieldEnchant.ID, () -> new FireShieldEnchant(plugin));
this.register(FlameWalkerEnchant.ID, () -> new FlameWalkerEnchant(plugin));
this.register(HardenedEnchant.ID, () -> new HardenedEnchant(plugin));
this.register(NightVisionEnchant.ID, () -> new NightVisionEnchant(plugin));
this.register(RegrowthEnchant.ID, () -> new RegrowthEnchant(plugin));
this.register(SaturationEnchant.ID, () -> new SaturationEnchant(plugin));
this.register(KamikadzeEnchant.ID, () -> new KamikadzeEnchant(plugin));
this.register(StoppingForceEnchant.ID, () -> new StoppingForceEnchant(plugin));
this.register(EnchantSonic.ID, () -> new EnchantSonic(plugin));
this.register(SpeedyEnchant.ID, () -> new SpeedyEnchant(plugin));
// Bow enchants
this.register(EnchantBomber.ID, () -> new EnchantBomber(plugin));
@ -130,36 +162,48 @@ public class EnchantRegistry {
}
// Universal
this.register(EnchantCurseOfFragility.ID, () -> new EnchantCurseOfFragility(plugin));
this.register(CurseOfFragilityEnchant.ID, () -> new CurseOfFragilityEnchant(plugin));
this.register(CurseOfMediocrityEnchant.ID, () -> new CurseOfMediocrityEnchant(plugin));
this.register(SoulboundEnchant.ID, () -> new SoulboundEnchant(plugin));
Enchantment.stopAcceptingRegistrations();
this.plugin.info("Enchantments Registered: " + getRegistered().size());
this.plugin.info("Enchantments Registered: " + EnchantRegistry.getRegistered().size());
this.isLocked = true;
}
/*@SuppressWarnings("unchecked")
public void shutdown() {
if (this.plugin.isEnabled()) return; // Prevent to unregister enchantments during the runtime.
@Override
protected void onShutdown() {
ENCHANTS_MAP.clear();
}
Map<NamespacedKey, Enchantment> byKey = (Map<NamespacedKey, Enchantment>) Reflex.getFieldValue(Enchantment.class, "byKey");
Map<String, Enchantment> byName = (Map<String, Enchantment>) Reflex.getFieldValue(Enchantment.class, "byName");
public <T extends IEnchantment> void registerType(@NotNull Class<T> enchantClass) {
ENCHANTS_MAP.computeIfAbsent(enchantClass, k -> new HashSet<>());
}
if (byKey == null || byName == null) return;
public <E extends Event, T extends IEnchantment> void registerWrapper(@NotNull Class<E> eventClass,
@NotNull Class<T> enchantClass,
@NotNull DataGather<E, T> dataGather) {
for (ExcellentEnchant enchant : REGISTRY_MAP.values()) {
if (enchant instanceof ICleanable cleanable) {
cleanable.clear();
}
byKey.remove(enchant.getKey());
byName.remove(enchant.getName());
enchant.unregisterListeners();
for (EventPriority priority : EventPriority.values()) {
WrappedEvent<E, T> event = new WrappedEvent<>(plugin, priority, eventClass, enchantClass, dataGather);
plugin.getPluginManager().registerEvent(eventClass, event, priority, event, plugin, true);
}
REGISTRY_MAP.clear();
this.plugin.info("All enchants are unregistered.");
}*/
this.registerType(enchantClass);
}
private <T extends IEnchantment> boolean registerEnchantType(@NotNull T enchant) {
Class<? extends IEnchantment> enchantClass = enchant.getClass();
Set<Class<?>> assignables = ENCHANTS_MAP.keySet().stream().filter(clazz -> clazz.isAssignableFrom(enchantClass)).collect(Collectors.toSet());
if (assignables.isEmpty()) {
this.plugin.warn("Could not register enchantment '" + enchant.getId() + "': Enchantment type is not registered.");
return false;
}
assignables.forEach(clazz -> ENCHANTS_MAP.get(clazz).add(enchant));
return true;
}
private void register(@NotNull String id, @NotNull Supplier<ExcellentEnchant> supplier) {
if (Config.ENCHANTMENTS_DISABLED.get().contains(id)) return;
@ -171,6 +215,10 @@ public class EnchantRegistry {
return;
}
if (!this.registerEnchantType(enchant)) {
return;
}
Enchantment.registerEnchantment(enchant);
REGISTRY_MAP.put(enchant.getKey(), enchant);
enchant.loadSettings();
@ -179,6 +227,18 @@ public class EnchantRegistry {
this.plugin.info("Registered enchantment: " + enchant.getId());
}
@NotNull
public static Set<PassiveEnchant> getPeriodicTalents() {
return getEnchantments(PassiveEnchant.class);
}
@NotNull
@SuppressWarnings("unchecked")
public static <T extends IEnchantment> Set<T> getEnchantments(@NotNull Class<T> clazz) {
Set<? super T> set = new HashSet<>(ENCHANTS_MAP.getOrDefault(clazz, Collections.emptySet()));
return (Set<T>) set;
}
@Nullable
public static ExcellentEnchant getById(@NotNull String id) {
return getByKey(EnchantUtils.createKey(id));
@ -196,8 +256,6 @@ public class EnchantRegistry {
@NotNull
public static Set<ExcellentEnchant> getOfTier(@NotNull Tier tier) {
return getRegistered().stream().filter(enchant -> enchant.getTier() == tier)
.collect(Collectors.toCollection(HashSet::new));
return getRegistered().stream().filter(enchant -> enchant.getTier() == tier).collect(Collectors.toCollection(HashSet::new));
}
}

View File

@ -0,0 +1,31 @@
package su.nightexpress.excellentenchants.enchantment.registry.wrapper;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.Event;
import org.bukkit.event.EventPriority;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import su.nightexpress.excellentenchants.api.enchantment.IEnchantment;
import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils;
import java.util.Map;
public abstract class DataGather<E extends Event, T extends IEnchantment> {
@Nullable
public abstract LivingEntity getEntity(@NotNull E event);
@NotNull
public abstract EquipmentSlot[] getEnchantSlots(@NotNull E event);
public abstract boolean checkPriority(@NotNull T enchant, @NotNull EventPriority priority);
@NotNull
public Map<ItemStack, Map<T, Integer>> getEnchants(@NotNull E event, @NotNull Class<T> enchantClass, @NotNull LivingEntity entity) {
return EnchantUtils.getEquipped(entity, enchantClass, this.getEnchantSlots(event));
}
public abstract boolean useEnchant(@NotNull E event, @NotNull LivingEntity entity, @NotNull ItemStack item, @NotNull T enchant, int level);
}

View File

@ -0,0 +1,351 @@
package su.nightexpress.excellentenchants.enchantment.registry.wrapper;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockDropItemEvent;
import org.bukkit.event.entity.*;
import org.bukkit.event.player.PlayerFishEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import su.nightexpress.excellentenchants.api.enchantment.meta.Arrowed;
import su.nightexpress.excellentenchants.api.enchantment.type.*;
import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
public class DataGathers {
public static final DataGather<BlockBreakEvent, BlockBreakEnchant> BLOCK_BREAK = new DataGather<>() {
@Override
@NotNull
public LivingEntity getEntity(@NotNull BlockBreakEvent event) {
return event.getPlayer();
}
@Override
public boolean checkPriority(@NotNull BlockBreakEnchant enchant, @NotNull EventPriority priority) {
return enchant.getBreakPriority() == priority;
}
@NotNull
@Override
public EquipmentSlot[] getEnchantSlots(@NotNull BlockBreakEvent event) {
return new EquipmentSlot[]{EquipmentSlot.HAND};
}
@Override
public boolean useEnchant(@NotNull BlockBreakEvent event, @NotNull LivingEntity entity, @NotNull ItemStack item, @NotNull BlockBreakEnchant enchant, int level) {
return enchant.onBreak(event, entity, item, level);
}
};
public static final DataGather<BlockDropItemEvent, BlockDropEnchant> BLOCK_DROP = new DataGather<>() {
@Override
@NotNull
public LivingEntity getEntity(@NotNull BlockDropItemEvent event) {
return event.getPlayer();
}
@Override
public boolean checkPriority(@NotNull BlockDropEnchant enchant, @NotNull EventPriority priority) {
return enchant.getDropPriority() == priority;
}
@NotNull
@Override
public EquipmentSlot[] getEnchantSlots(@NotNull BlockDropItemEvent event) {
return new EquipmentSlot[]{EquipmentSlot.HAND};
}
@Override
public boolean useEnchant(@NotNull BlockDropItemEvent event, @NotNull LivingEntity entity, @NotNull ItemStack item, @NotNull BlockDropEnchant enchant, int level) {
return enchant.onDrop(event, entity, item, level);
}
};
public static final DataGather<EntityShootBowEvent, BowEnchant> BOW_SHOOT = new DataGather<>() {
@Override
@NotNull
public LivingEntity getEntity(@NotNull EntityShootBowEvent event) {
return event.getEntity();
}
@Override
public boolean checkPriority(@NotNull BowEnchant enchant, @NotNull EventPriority priority) {
return enchant.getShootPriority() == priority;
}
@NotNull
@Override
public EquipmentSlot[] getEnchantSlots(@NotNull EntityShootBowEvent event) {
return new EquipmentSlot[]{event.getHand()};
}
@Override
public boolean useEnchant(@NotNull EntityShootBowEvent event, @NotNull LivingEntity entity, @NotNull ItemStack item, @NotNull BowEnchant enchant, int level) {
if (enchant.onShoot(event, entity, item, level)) {
if (enchant instanceof Arrowed arrowed && event.getProjectile() instanceof Projectile projectile) {
arrowed.addData(projectile);
arrowed.addTrail(projectile);
}
return true;
}
return false;
}
};
public static final DataGather<ProjectileHitEvent, BowEnchant> PROJECTILE_HIT = new DataGather<>() {
@Override
@Nullable
public LivingEntity getEntity(@NotNull ProjectileHitEvent event) {
return event.getEntity().getShooter() instanceof LivingEntity entity ? entity : null;
}
@Override
public boolean checkPriority(@NotNull BowEnchant enchant, @NotNull EventPriority priority) {
return enchant.getHitPriority() == priority;
}
@NotNull
@Override
public EquipmentSlot[] getEnchantSlots(@NotNull ProjectileHitEvent event) {
return new EquipmentSlot[0];
}
@NotNull
@Override
public Map<ItemStack, Map<BowEnchant, Integer>> getEnchants(@NotNull ProjectileHitEvent event, @NotNull Class<BowEnchant> enchantClass, @NotNull LivingEntity entity) {
Map<ItemStack, Map<BowEnchant, Integer>> map = new HashMap<>();
ItemStack bow = EnchantUtils.getSourceWeapon(event.getEntity());
if (bow != null) {
map.put(bow, EnchantUtils.getExcellents(bow, enchantClass));
}
return map;
}
@Override
public boolean useEnchant(@NotNull ProjectileHitEvent event, @NotNull LivingEntity entity, @NotNull ItemStack item, @NotNull BowEnchant enchant, int level) {
return enchant.onHit(event, entity, event.getEntity(), item, level);
}
};
public static final DataGather<EntityDamageByEntityEvent, BowEnchant> ENTITY_DAMAGE_SHOOT = new DataGather<>() {
@Override
@Nullable
public LivingEntity getEntity(@NotNull EntityDamageByEntityEvent event) {
if (event.getDamager() instanceof Projectile projectile && projectile.getShooter() instanceof LivingEntity shooter) {
return shooter;
}
return null;
}
@Override
public boolean checkPriority(@NotNull BowEnchant enchant, @NotNull EventPriority priority) {
return enchant.getDamagePriority() == priority;
}
@NotNull
@Override
public EquipmentSlot[] getEnchantSlots(@NotNull EntityDamageByEntityEvent event) {
return new EquipmentSlot[0];
}
@NotNull
@Override
public Map<ItemStack, Map<BowEnchant, Integer>> getEnchants(@NotNull EntityDamageByEntityEvent event, @NotNull Class<BowEnchant> enchantClass, @NotNull LivingEntity entity) {
if (!(event.getDamager() instanceof Projectile projectile)) return Collections.emptyMap();
Map<ItemStack, Map<BowEnchant, Integer>> map = new HashMap<>();
ItemStack bow = EnchantUtils.getSourceWeapon(projectile);
if (bow != null) {
map.put(bow, EnchantUtils.getExcellents(bow, enchantClass));
}
return map;
}
@Override
public boolean useEnchant(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull ItemStack item, @NotNull BowEnchant enchant, int level) {
if (!(event.getDamager() instanceof Projectile projectile)) return false;
if (!(event.getEntity() instanceof LivingEntity victim)) return false;
return enchant.onDamage(event, projectile, damager, victim, item, level);
}
};
public static final DataGather<EntityDamageByEntityEvent, CombatEnchant> ENTITY_DAMAGE_ATTACK = new DataGather<>() {
@Override
@Nullable
public LivingEntity getEntity(@NotNull EntityDamageByEntityEvent event) {
if (event.getDamager() instanceof LivingEntity entity) {
return entity;
}
return null;
}
@Override
public boolean checkPriority(@NotNull CombatEnchant enchant, @NotNull EventPriority priority) {
return enchant.getAttackPriority() == priority;
}
@NotNull
@Override
public EquipmentSlot[] getEnchantSlots(@NotNull EntityDamageByEntityEvent event) {
return new EquipmentSlot[]{EquipmentSlot.HAND};
}
@Override
public boolean useEnchant(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull ItemStack item, @NotNull CombatEnchant enchant, int level) {
if (event.getCause() == EntityDamageEvent.DamageCause.THORNS) return false;
if (!(event.getEntity() instanceof LivingEntity victim)) return false;
return enchant.onAttack(event, damager, victim, item, level);
}
};
public static final DataGather<EntityDamageByEntityEvent, CombatEnchant> ENTITY_DAMAGE_DEFENSE = new DataGather<>() {
@Override
@Nullable
public LivingEntity getEntity(@NotNull EntityDamageByEntityEvent event) {
Entity entity = event.getEntity();
return entity instanceof Player player ? player : null;
}
@Override
public boolean checkPriority(@NotNull CombatEnchant enchant, @NotNull EventPriority priority) {
return enchant.getProtectPriority() == priority;
}
@NotNull
@Override
public EquipmentSlot[] getEnchantSlots(@NotNull EntityDamageByEntityEvent event) {
return EquipmentSlot.values();
}
@Override
public boolean useEnchant(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity victim, @NotNull ItemStack item, @NotNull CombatEnchant enchant, int level) {
if (event.getCause() == EntityDamageEvent.DamageCause.THORNS) return false;
if (!(event.getDamager() instanceof LivingEntity damager)) return false;
return enchant.onProtect(event, damager, victim, item, level);
}
};
public static final DataGather<EntityDeathEvent, DeathEnchant> ENTITY_KILL = new DataGather<>() {
@Override
@Nullable
public LivingEntity getEntity(@NotNull EntityDeathEvent event) {
return event.getEntity().getKiller();
}
@Override
public boolean checkPriority(@NotNull DeathEnchant enchant, @NotNull EventPriority priority) {
return enchant.getKillPriority() == priority;
}
@NotNull
@Override
public EquipmentSlot[] getEnchantSlots(@NotNull EntityDeathEvent event) {
return new EquipmentSlot[] {EquipmentSlot.HAND};
}
@Override
public boolean useEnchant(@NotNull EntityDeathEvent event, @NotNull LivingEntity entity, @NotNull ItemStack item, @NotNull DeathEnchant enchant, int level) {
Player killer = entity.getKiller();
if (killer == null) return false;
return enchant.onKill(event, entity, killer, level); // TODO item?
}
};
public static final DataGather<EntityDeathEvent, DeathEnchant> ENTITY_DEATH = new DataGather<>() {
@Override
@NotNull
public LivingEntity getEntity(@NotNull EntityDeathEvent event) {
return event.getEntity();
}
@Override
public boolean checkPriority(@NotNull DeathEnchant enchant, @NotNull EventPriority priority) {
return enchant.getDeathPriority() == priority;
}
@NotNull
@Override
public EquipmentSlot[] getEnchantSlots(@NotNull EntityDeathEvent event) {
return EquipmentSlot.values();
}
@Override
public boolean useEnchant(@NotNull EntityDeathEvent event, @NotNull LivingEntity entity, @NotNull ItemStack item, @NotNull DeathEnchant enchant, int level) {
return enchant.onDeath(event, entity, item, level);
}
};
public static final DataGather<PlayerFishEvent, FishingEnchant> FISHING = new DataGather<>() {
@Override
@NotNull
public LivingEntity getEntity(@NotNull PlayerFishEvent event) {
return event.getPlayer();
}
@Override
public boolean checkPriority(@NotNull FishingEnchant enchant, @NotNull EventPriority priority) {
return enchant.getFishingPriority() == priority;
}
@NotNull
@Override
public EquipmentSlot[] getEnchantSlots(@NotNull PlayerFishEvent event) {
return new EquipmentSlot[] {event.getHand()};
}
@Override
public boolean useEnchant(@NotNull PlayerFishEvent event, @NotNull LivingEntity entity, @NotNull ItemStack item, @NotNull FishingEnchant enchant, int level) {
return enchant.onFishing(event, item, level);
}
};
public static final DataGather<PlayerInteractEvent, InteractEnchant> INTERACT = new DataGather<>() {
@NotNull
@Override
public LivingEntity getEntity(@NotNull PlayerInteractEvent event) {
return event.getPlayer();
}
@Override
public boolean checkPriority(@NotNull InteractEnchant enchant, @NotNull EventPriority priority) {
return enchant.getInteractPriority() == priority;
}
@NotNull
@Override
public EquipmentSlot[] getEnchantSlots(@NotNull PlayerInteractEvent event) {
return new EquipmentSlot[]{event.getHand()};
}
@Override
public boolean useEnchant(@NotNull PlayerInteractEvent event, @NotNull LivingEntity entity, @NotNull ItemStack item, @NotNull InteractEnchant enchant, int level) {
return enchant.onInteract(event, entity, item, level);
}
};
}

Some files were not shown because too many files have changed in this diff Show More