This commit is contained in:
BuildTools 2023-09-04 16:41:08 +05:00
parent 2cec377dfd
commit 7b8d7aad51
66 changed files with 437 additions and 300 deletions

View File

@ -8,5 +8,5 @@ import su.nightexpress.excellentenchants.api.enchantment.IEnchantment;
public interface BlockBreakEnchant extends IEnchantment { public interface BlockBreakEnchant extends IEnchantment {
boolean onBreak(@NotNull BlockBreakEvent e, @NotNull Player player, @NotNull ItemStack item, int level); boolean onBreak(@NotNull BlockBreakEvent event, @NotNull Player player, @NotNull ItemStack item, int level);
} }

View File

@ -4,11 +4,9 @@ import org.bukkit.entity.Player;
import org.bukkit.event.block.BlockDropItemEvent; import org.bukkit.event.block.BlockDropItemEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import su.nightexpress.excellentenchants.enchantment.util.EnchantDropContainer;
import su.nightexpress.excellentenchants.api.enchantment.IEnchantment; import su.nightexpress.excellentenchants.api.enchantment.IEnchantment;
public interface BlockDropEnchant extends IEnchantment { public interface BlockDropEnchant extends IEnchantment {
boolean onDrop(@NotNull BlockDropItemEvent event, @NotNull EnchantDropContainer dropContainer, boolean onDrop(@NotNull BlockDropItemEvent event, @NotNull Player player, @NotNull ItemStack item, int level);
@NotNull Player player, @NotNull ItemStack item, int level);
} }

View File

@ -11,11 +11,11 @@ import su.nightexpress.excellentenchants.api.enchantment.IEnchantment;
public interface BowEnchant extends IEnchantment { public interface BowEnchant extends IEnchantment {
boolean onShoot(@NotNull EntityShootBowEvent e, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level); boolean onShoot(@NotNull EntityShootBowEvent event, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level);
boolean onHit(@NotNull ProjectileHitEvent e, @NotNull Projectile projectile, @NotNull ItemStack bow, int level); boolean onHit(@NotNull ProjectileHitEvent event, @NotNull Projectile projectile, @NotNull ItemStack bow, int level);
boolean onDamage(@NotNull EntityDamageByEntityEvent e, @NotNull Projectile projectile, boolean onDamage(@NotNull EntityDamageByEntityEvent event, @NotNull Projectile projectile,
@NotNull LivingEntity shooter, @NotNull LivingEntity victim, @NotNull LivingEntity shooter, @NotNull LivingEntity victim,
@NotNull ItemStack weapon, int level); @NotNull ItemStack weapon, int level);
} }

View File

@ -8,11 +8,11 @@ import su.nightexpress.excellentenchants.api.enchantment.IEnchantment;
public interface CombatEnchant extends IEnchantment { public interface CombatEnchant extends IEnchantment {
boolean onAttack(@NotNull EntityDamageByEntityEvent e, boolean onAttack(@NotNull EntityDamageByEntityEvent event,
@NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull LivingEntity damager, @NotNull LivingEntity victim,
@NotNull ItemStack weapon, int level); @NotNull ItemStack weapon, int level);
boolean onProtect(@NotNull EntityDamageByEntityEvent e, boolean onProtect(@NotNull EntityDamageByEntityEvent event,
@NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull LivingEntity damager, @NotNull LivingEntity victim,
@NotNull ItemStack weapon, int level); @NotNull ItemStack weapon, int level);
} }

View File

@ -8,5 +8,5 @@ import su.nightexpress.excellentenchants.api.enchantment.IEnchantment;
public interface DamageEnchant extends IEnchantment { public interface DamageEnchant extends IEnchantment {
boolean onDamage(@NotNull EntityDamageEvent e, @NotNull LivingEntity entity, @NotNull ItemStack item, int level); boolean onDamage(@NotNull EntityDamageEvent event, @NotNull LivingEntity entity, @NotNull ItemStack item, int level);
} }

View File

@ -8,5 +8,5 @@ import su.nightexpress.excellentenchants.api.enchantment.IEnchantment;
public interface InteractEnchant extends IEnchantment { public interface InteractEnchant extends IEnchantment {
boolean onInteract(@NotNull PlayerInteractEvent e, @NotNull Player player, @NotNull ItemStack item, int level); boolean onInteract(@NotNull PlayerInteractEvent event, @NotNull Player player, @NotNull ItemStack item, int level);
} }

View File

@ -124,7 +124,6 @@ public class EnchantRegistry {
this.register(SniperEnchant.ID, () -> new SniperEnchant(plugin)); this.register(SniperEnchant.ID, () -> new SniperEnchant(plugin));
this.register(EnchantPoisonedArrows.ID, () -> new EnchantPoisonedArrows(plugin)); this.register(EnchantPoisonedArrows.ID, () -> new EnchantPoisonedArrows(plugin));
this.register(EnchantWitheredArrows.ID, () -> new EnchantWitheredArrows(plugin)); this.register(EnchantWitheredArrows.ID, () -> new EnchantWitheredArrows(plugin));
if (Version.isAbove(Version.V1_18_R2)) { if (Version.isAbove(Version.V1_18_R2)) {
this.register(DarknessArrowsEnchant.ID, () -> new DarknessArrowsEnchant(plugin)); this.register(DarknessArrowsEnchant.ID, () -> new DarknessArrowsEnchant(plugin));
this.register(DarknessCloakEnchant.ID, () -> new DarknessCloakEnchant(plugin)); this.register(DarknessCloakEnchant.ID, () -> new DarknessCloakEnchant(plugin));

View File

@ -62,12 +62,12 @@ public class DarknessCloakEnchant extends ExcellentEnchant implements Chanced, P
} }
@Override @Override
public boolean onAttack(@NotNull EntityDamageByEntityEvent e, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { public boolean onAttack(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
return false; return false;
} }
@Override @Override
public boolean onProtect(@NotNull EntityDamageByEntityEvent e, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { 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.isAvailableToUse(victim)) return false;
if (!this.checkTriggerChance(level)) return false; if (!this.checkTriggerChance(level)) return false;
if (!this.addEffect(damager, level)) return false; if (!this.addEffect(damager, level)) return false;

View File

@ -61,12 +61,12 @@ public class EnchantColdSteel extends ExcellentEnchant implements Chanced, Potio
} }
@Override @Override
public boolean onAttack(@NotNull EntityDamageByEntityEvent e, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { public boolean onAttack(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
return false; return false;
} }
@Override @Override
public boolean onProtect(@NotNull EntityDamageByEntityEvent e, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { 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.isAvailableToUse(damager)) return false;
if (!this.checkTriggerChance(level)) return false; if (!this.checkTriggerChance(level)) return false;

View File

@ -62,12 +62,12 @@ public class EnchantFireShield extends ExcellentEnchant implements Chanced, Comb
} }
@Override @Override
public boolean onAttack(@NotNull EntityDamageByEntityEvent e, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { public boolean onAttack(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
return false; return false;
} }
@Override @Override
public boolean onProtect(@NotNull EntityDamageByEntityEvent e, public boolean onProtect(@NotNull EntityDamageByEntityEvent event,
@NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull LivingEntity damager, @NotNull LivingEntity victim,
@NotNull ItemStack weapon, int level) { @NotNull ItemStack weapon, int level) {
if (!this.isAvailableToUse(victim)) return false; if (!this.isAvailableToUse(victim)) return false;

View File

@ -19,6 +19,7 @@ import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.inventory.EntityEquipment; import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.Version;
import su.nexmedia.engine.api.particle.SimpleParticle; import su.nexmedia.engine.api.particle.SimpleParticle;
import su.nexmedia.engine.api.server.AbstractTask; import su.nexmedia.engine.api.server.AbstractTask;
import su.nexmedia.engine.utils.Pair; import su.nexmedia.engine.utils.Pair;
@ -180,9 +181,11 @@ public class EnchantFlameWalker extends ExcellentEnchant implements Cleanable {
Pair<Long, Integer> pair = BLOCKS_TO_DESTROY.get(block); Pair<Long, Integer> pair = BLOCKS_TO_DESTROY.get(block);
long time = pair.getFirst(); long time = pair.getFirst();
if (now >= time) { if (now >= time) {
block.getWorld().getPlayers().forEach(player -> { if (Version.isAtLeast(Version.V1_19_R3)) {
player.sendBlockDamage(block.getLocation(), 0F, pair.getSecond()); block.getWorld().getPlayers().forEach(player -> {
}); player.sendBlockDamage(block.getLocation(), 0F, pair.getSecond());
});
}
block.setType(Material.LAVA); block.setType(Material.LAVA);
@ -191,7 +194,7 @@ public class EnchantFlameWalker extends ExcellentEnchant implements Cleanable {
return true; return true;
} }
else { else if (Version.isAtLeast(Version.V1_19_R3)) {
long diff = TimeUnit.MILLISECONDS.toSeconds(time - now); long diff = TimeUnit.MILLISECONDS.toSeconds(time - now);
float progress = (float) (1D - Math.min(1D, diff / 5D)); float progress = (float) (1D - Math.min(1D, diff / 5D));

View File

@ -60,12 +60,12 @@ public class EnchantHardened extends ExcellentEnchant implements Chanced, Potion
} }
@Override @Override
public boolean onAttack(@NotNull EntityDamageByEntityEvent e, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { public boolean onAttack(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
return false; return false;
} }
@Override @Override
public boolean onProtect(@NotNull EntityDamageByEntityEvent e, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { 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.isAvailableToUse(damager)) return false;
if (!this.checkTriggerChance(level)) return false; if (!this.checkTriggerChance(level)) return false;

View File

@ -61,12 +61,12 @@ public class EnchantIceShield extends ExcellentEnchant implements Chanced, Potio
} }
@Override @Override
public boolean onAttack(@NotNull EntityDamageByEntityEvent e, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { public boolean onAttack(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
return false; return false;
} }
@Override @Override
public boolean onProtect(@NotNull EntityDamageByEntityEvent e, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { 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.isAvailableToUse(victim)) return false;
if (!this.checkTriggerChance(level)) return false; if (!this.checkTriggerChance(level)) return false;
if (!this.addEffect(damager, level)) return false; if (!this.addEffect(damager, level)) return false;

View File

@ -59,12 +59,12 @@ public class StoppingForceEnchant extends ExcellentEnchant implements Chanced, C
} }
@Override @Override
public boolean onAttack(@NotNull EntityDamageByEntityEvent e, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { public boolean onAttack(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
return false; return false;
} }
@Override @Override
public boolean onProtect(@NotNull EntityDamageByEntityEvent e, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { 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.isAvailableToUse(victim)) return false;
if (!this.checkTriggerChance(level)) return false; if (!this.checkTriggerChance(level)) return false;

View File

@ -77,9 +77,9 @@ public class DarknessArrowsEnchant extends ExcellentEnchant implements Chanced,
} }
@Override @Override
public boolean onShoot(@NotNull EntityShootBowEvent e, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) { public boolean onShoot(@NotNull EntityShootBowEvent event, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) {
if (!this.isAvailableToUse(shooter)) return false; if (!this.isAvailableToUse(shooter)) return false;
if (!(e.getProjectile() instanceof Arrow arrow)) return false; if (!(event.getProjectile() instanceof Arrow arrow)) return false;
if (!this.checkTriggerChance(level)) return false; if (!this.checkTriggerChance(level)) return false;
arrow.setPickupStatus(AbstractArrow.PickupStatus.DISALLOWED); arrow.setPickupStatus(AbstractArrow.PickupStatus.DISALLOWED);
@ -87,12 +87,12 @@ public class DarknessArrowsEnchant extends ExcellentEnchant implements Chanced,
} }
@Override @Override
public boolean onHit(@NotNull ProjectileHitEvent e, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) { public boolean onHit(@NotNull ProjectileHitEvent event, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) {
return this.isOurProjectile(projectile); return this.isOurProjectile(projectile);
} }
@Override @Override
public boolean onDamage(@NotNull EntityDamageByEntityEvent e, @NotNull Projectile projectile, @NotNull LivingEntity shooter, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { 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 this.isOurProjectile(projectile);
} }
} }

View File

@ -74,26 +74,26 @@ public class EnchantBomber extends ExcellentEnchant implements Chanced, BowEncha
} }
@Override @Override
public boolean onShoot(@NotNull EntityShootBowEvent e, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) { public boolean onShoot(@NotNull EntityShootBowEvent event, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) {
if (!this.isAvailableToUse(shooter)) return false; if (!this.isAvailableToUse(shooter)) return false;
if (!this.checkTriggerChance(level)) return false; if (!this.checkTriggerChance(level)) return false;
if (!(e.getProjectile() instanceof Projectile projectile)) return false; if (!(event.getProjectile() instanceof Projectile projectile)) return false;
TNTPrimed primed = projectile.getWorld().spawn(projectile.getLocation(), TNTPrimed.class); TNTPrimed primed = projectile.getWorld().spawn(projectile.getLocation(), TNTPrimed.class);
primed.setVelocity(projectile.getVelocity().multiply(e.getForce() * 1.25)); primed.setVelocity(projectile.getVelocity().multiply(event.getForce() * 1.25));
primed.setFuseTicks(this.getFuseTicks(level)); primed.setFuseTicks(this.getFuseTicks(level));
primed.setSource(shooter); primed.setSource(shooter);
e.setProjectile(primed); event.setProjectile(primed);
return true; return true;
} }
@Override @Override
public boolean onHit(@NotNull ProjectileHitEvent e, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) { public boolean onHit(@NotNull ProjectileHitEvent event, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) {
return false; return false;
} }
@Override @Override
public boolean onDamage(@NotNull EntityDamageByEntityEvent e, @NotNull Projectile projectile, @NotNull LivingEntity shooter, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { public boolean onDamage(@NotNull EntityDamageByEntityEvent event, @NotNull Projectile projectile, @NotNull LivingEntity shooter, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
return false; return false;
} }
} }

View File

@ -77,9 +77,9 @@ public class EnchantConfusingArrows extends ExcellentEnchant implements Chanced,
} }
@Override @Override
public boolean onShoot(@NotNull EntityShootBowEvent e, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) { public boolean onShoot(@NotNull EntityShootBowEvent event, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) {
if (!this.isAvailableToUse(shooter)) return false; if (!this.isAvailableToUse(shooter)) return false;
if (!(e.getProjectile() instanceof Arrow arrow)) return false; if (!(event.getProjectile() instanceof Arrow arrow)) return false;
if (!this.checkTriggerChance(level)) return false; if (!this.checkTriggerChance(level)) return false;
arrow.setPickupStatus(AbstractArrow.PickupStatus.DISALLOWED); arrow.setPickupStatus(AbstractArrow.PickupStatus.DISALLOWED);
@ -87,12 +87,12 @@ public class EnchantConfusingArrows extends ExcellentEnchant implements Chanced,
} }
@Override @Override
public boolean onHit(@NotNull ProjectileHitEvent e, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) { public boolean onHit(@NotNull ProjectileHitEvent event, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) {
return this.isOurProjectile(projectile); return this.isOurProjectile(projectile);
} }
@Override @Override
public boolean onDamage(@NotNull EntityDamageByEntityEvent e, @NotNull Projectile projectile, @NotNull LivingEntity shooter, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { 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 this.isOurProjectile(projectile);
} }
} }

View File

@ -98,16 +98,16 @@ public class EnchantDragonfireArrows extends ExcellentEnchant implements Chanced
} }
@Override @Override
public boolean onShoot(@NotNull EntityShootBowEvent e, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) { public boolean onShoot(@NotNull EntityShootBowEvent event, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) {
if (!this.isAvailableToUse(shooter)) return false; if (!this.isAvailableToUse(shooter)) return false;
return this.checkTriggerChance(level); return this.checkTriggerChance(level);
} }
@Override @Override
public boolean onHit(@NotNull ProjectileHitEvent e, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) { public boolean onHit(@NotNull ProjectileHitEvent event, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) {
if (!this.isOurProjectile(projectile)) return false; if (!this.isOurProjectile(projectile)) return false;
if (e.getHitEntity() != null) return false; if (event.getHitEntity() != null) return false;
if (projectile.getShooter() == null) return false; if (projectile.getShooter() == null) return false;
this.createCloud(projectile.getShooter(), projectile.getLocation() , level); this.createCloud(projectile.getShooter(), projectile.getLocation() , level);
@ -115,7 +115,7 @@ public class EnchantDragonfireArrows extends ExcellentEnchant implements Chanced
} }
@Override @Override
public boolean onDamage(@NotNull EntityDamageByEntityEvent e, @NotNull Projectile projectile, @NotNull LivingEntity shooter, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { public boolean onDamage(@NotNull EntityDamageByEntityEvent event, @NotNull Projectile projectile, @NotNull LivingEntity shooter, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
if (!this.isOurProjectile(projectile)) return false; if (!this.isOurProjectile(projectile)) return false;
this.createCloud(shooter, victim.getLocation(), level); this.createCloud(shooter, victim.getLocation(), level);

View File

@ -72,18 +72,18 @@ public class EnchantElectrifiedArrows extends ExcellentEnchant implements Chance
} }
@Override @Override
public boolean onShoot(@NotNull EntityShootBowEvent e, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) { public boolean onShoot(@NotNull EntityShootBowEvent event, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) {
if (!this.isAvailableToUse(shooter)) return false; if (!this.isAvailableToUse(shooter)) return false;
return this.checkTriggerChance(level); return this.checkTriggerChance(level);
} }
@Override @Override
public boolean onHit(@NotNull ProjectileHitEvent e, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) { public boolean onHit(@NotNull ProjectileHitEvent event, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) {
if (!this.isOurProjectile(projectile)) return false; if (!this.isOurProjectile(projectile)) return false;
if (e.getHitEntity() != null || e.getHitBlock() == null) return false; if (event.getHitEntity() != null || event.getHitBlock() == null) return false;
Block block = e.getHitBlock(); Block block = event.getHitBlock();
block.getWorld().strikeLightning(block.getLocation()).setMetadata(META_NO_ITEM_DAMAGE, new FixedMetadataValue(plugin, true)); block.getWorld().strikeLightning(block.getLocation()).setMetadata(META_NO_ITEM_DAMAGE, new FixedMetadataValue(plugin, true));
if (this.hasVisualEffects()) { if (this.hasVisualEffects()) {
Location center = LocationUtil.getCenter(block.getLocation()); Location center = LocationUtil.getCenter(block.getLocation());
@ -94,7 +94,7 @@ public class EnchantElectrifiedArrows extends ExcellentEnchant implements Chance
} }
@Override @Override
public boolean onDamage(@NotNull EntityDamageByEntityEvent e, @NotNull Projectile projectile, @NotNull LivingEntity shooter, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { public boolean onDamage(@NotNull EntityDamageByEntityEvent event, @NotNull Projectile projectile, @NotNull LivingEntity shooter, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
if (!this.isOurProjectile(projectile)) return false; if (!this.isOurProjectile(projectile)) return false;
plugin.getServer().getScheduler().runTask(plugin, () -> { plugin.getServer().getScheduler().runTask(plugin, () -> {

View File

@ -60,24 +60,24 @@ public class EnchantEnderBow extends ExcellentEnchant implements BowEnchant, Cha
} }
@Override @Override
public boolean onShoot(@NotNull EntityShootBowEvent e, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) { public boolean onShoot(@NotNull EntityShootBowEvent event, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) {
if (!this.isAvailableToUse(shooter)) return false; if (!this.isAvailableToUse(shooter)) return false;
if (!this.checkTriggerChance(level)) return false; if (!this.checkTriggerChance(level)) return false;
if (!(e.getProjectile() instanceof Projectile projectile)) return false; if (!(event.getProjectile() instanceof Projectile projectile)) return false;
EnderPearl pearl = shooter.launchProjectile(EnderPearl.class); EnderPearl pearl = shooter.launchProjectile(EnderPearl.class);
pearl.setVelocity(projectile.getVelocity()); pearl.setVelocity(projectile.getVelocity());
e.setProjectile(pearl); event.setProjectile(pearl);
return true; return true;
} }
@Override @Override
public boolean onHit(@NotNull ProjectileHitEvent e, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) { public boolean onHit(@NotNull ProjectileHitEvent event, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) {
return false; return false;
} }
@Override @Override
public boolean onDamage(@NotNull EntityDamageByEntityEvent e, @NotNull Projectile projectile, @NotNull LivingEntity shooter, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { public boolean onDamage(@NotNull EntityDamageByEntityEvent event, @NotNull Projectile projectile, @NotNull LivingEntity shooter, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
return false; return false;
} }
} }

View File

@ -100,14 +100,14 @@ public class EnchantExplosiveArrows extends ExcellentEnchant implements Chanced,
} }
@Override @Override
public boolean onShoot(@NotNull EntityShootBowEvent e, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) { public boolean onShoot(@NotNull EntityShootBowEvent event, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) {
if (!this.isAvailableToUse(shooter)) return false; if (!this.isAvailableToUse(shooter)) return false;
return this.checkTriggerChance(level); return this.checkTriggerChance(level);
} }
@Override @Override
public boolean onHit(@NotNull ProjectileHitEvent e, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) { public boolean onHit(@NotNull ProjectileHitEvent event, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) {
if (!this.isOurProjectile(projectile)) return false; if (!this.isOurProjectile(projectile)) return false;
Entity shooter = null; Entity shooter = null;
@ -126,7 +126,7 @@ public class EnchantExplosiveArrows extends ExcellentEnchant implements Chanced,
} }
@Override @Override
public boolean onDamage(@NotNull EntityDamageByEntityEvent e, @NotNull Projectile projectile, @NotNull LivingEntity shooter, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { 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 this.isOurProjectile(projectile);
} }

View File

@ -79,10 +79,10 @@ public class EnchantGhast extends ExcellentEnchant implements BowEnchant, Chance
} }
@Override @Override
public boolean onShoot(@NotNull EntityShootBowEvent e, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) { public boolean onShoot(@NotNull EntityShootBowEvent event, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) {
if (!this.isAvailableToUse(shooter)) return false; if (!this.isAvailableToUse(shooter)) return false;
if (!this.checkTriggerChance(level)) return false; if (!this.checkTriggerChance(level)) return false;
if (!(e.getProjectile() instanceof Projectile projectile)) return false; if (!(event.getProjectile() instanceof Projectile projectile)) return false;
Fireball fireball; Fireball fireball;
@ -99,17 +99,17 @@ public class EnchantGhast extends ExcellentEnchant implements BowEnchant, Chance
fireball.setIsIncendiary(this.isFireSpread()); fireball.setIsIncendiary(this.isFireSpread());
fireball.setYield(this.getYield(level)); fireball.setYield(this.getYield(level));
e.setProjectile(fireball); event.setProjectile(fireball);
return true; return true;
} }
@Override @Override
public boolean onHit(@NotNull ProjectileHitEvent e, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) { public boolean onHit(@NotNull ProjectileHitEvent event, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) {
return false; return false;
} }
@Override @Override
public boolean onDamage(@NotNull EntityDamageByEntityEvent e, @NotNull Projectile projectile, public boolean onDamage(@NotNull EntityDamageByEntityEvent event, @NotNull Projectile projectile,
@NotNull LivingEntity shooter, @NotNull LivingEntity victim, @NotNull LivingEntity shooter, @NotNull LivingEntity victim,
@NotNull ItemStack weapon, int level) { @NotNull ItemStack weapon, int level) {
return false; return false;

View File

@ -77,9 +77,9 @@ public class EnchantHover extends ExcellentEnchant implements Chanced, Arrowed,
} }
@Override @Override
public boolean onShoot(@NotNull EntityShootBowEvent e, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) { public boolean onShoot(@NotNull EntityShootBowEvent event, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) {
if (!this.isAvailableToUse(shooter)) return false; if (!this.isAvailableToUse(shooter)) return false;
if (!(e.getProjectile() instanceof Arrow arrow)) return false; if (!(event.getProjectile() instanceof Arrow arrow)) return false;
if (!this.checkTriggerChance(level)) return false; if (!this.checkTriggerChance(level)) return false;
arrow.setPickupStatus(AbstractArrow.PickupStatus.DISALLOWED); arrow.setPickupStatus(AbstractArrow.PickupStatus.DISALLOWED);
@ -87,12 +87,12 @@ public class EnchantHover extends ExcellentEnchant implements Chanced, Arrowed,
} }
@Override @Override
public boolean onHit(@NotNull ProjectileHitEvent e, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) { public boolean onHit(@NotNull ProjectileHitEvent event, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) {
return this.isOurProjectile(projectile); return this.isOurProjectile(projectile);
} }
@Override @Override
public boolean onDamage(@NotNull EntityDamageByEntityEvent e, @NotNull Projectile projectile, @NotNull LivingEntity shooter, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { 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 this.isOurProjectile(projectile);
} }
} }

View File

@ -77,9 +77,9 @@ public class EnchantPoisonedArrows extends ExcellentEnchant implements Chanced,
} }
@Override @Override
public boolean onShoot(@NotNull EntityShootBowEvent e, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) { public boolean onShoot(@NotNull EntityShootBowEvent event, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) {
if (!this.isAvailableToUse(shooter)) return false; if (!this.isAvailableToUse(shooter)) return false;
if (!(e.getProjectile() instanceof Arrow arrow)) return false; if (!(event.getProjectile() instanceof Arrow arrow)) return false;
if (!this.checkTriggerChance(level)) return false; if (!this.checkTriggerChance(level)) return false;
arrow.setPickupStatus(AbstractArrow.PickupStatus.DISALLOWED); arrow.setPickupStatus(AbstractArrow.PickupStatus.DISALLOWED);
@ -87,12 +87,12 @@ public class EnchantPoisonedArrows extends ExcellentEnchant implements Chanced,
} }
@Override @Override
public boolean onHit(@NotNull ProjectileHitEvent e, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) { public boolean onHit(@NotNull ProjectileHitEvent event, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) {
return this.isOurProjectile(projectile); return this.isOurProjectile(projectile);
} }
@Override @Override
public boolean onDamage(@NotNull EntityDamageByEntityEvent e, @NotNull Projectile projectile, @NotNull LivingEntity shooter, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { 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 this.isOurProjectile(projectile);
} }
} }

View File

@ -77,9 +77,9 @@ public class EnchantWitheredArrows extends ExcellentEnchant implements Chanced,
} }
@Override @Override
public boolean onShoot(@NotNull EntityShootBowEvent e, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) { public boolean onShoot(@NotNull EntityShootBowEvent event, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) {
if (!this.isAvailableToUse(shooter)) return false; if (!this.isAvailableToUse(shooter)) return false;
if (!(e.getProjectile() instanceof Arrow arrow)) return false; if (!(event.getProjectile() instanceof Arrow arrow)) return false;
if (!this.checkTriggerChance(level)) return false; if (!this.checkTriggerChance(level)) return false;
arrow.setPickupStatus(AbstractArrow.PickupStatus.DISALLOWED); arrow.setPickupStatus(AbstractArrow.PickupStatus.DISALLOWED);
@ -87,12 +87,12 @@ public class EnchantWitheredArrows extends ExcellentEnchant implements Chanced,
} }
@Override @Override
public boolean onHit(@NotNull ProjectileHitEvent e, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) { public boolean onHit(@NotNull ProjectileHitEvent event, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) {
return this.isOurProjectile(projectile); return this.isOurProjectile(projectile);
} }
@Override @Override
public boolean onDamage(@NotNull EntityDamageByEntityEvent e, @NotNull Projectile projectile, @NotNull LivingEntity shooter, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { 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 this.isOurProjectile(projectile);
} }
} }

View File

@ -69,8 +69,8 @@ public class FlareEnchant extends ExcellentEnchant implements Chanced, Arrowed,
} }
@Override @Override
public boolean onShoot(@NotNull EntityShootBowEvent e, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) { public boolean onShoot(@NotNull EntityShootBowEvent event, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) {
if (!(e.getProjectile() instanceof Arrow arrow)) return false; if (!(event.getProjectile() instanceof Arrow arrow)) return false;
if (!this.isAvailableToUse(shooter)) return false; if (!this.isAvailableToUse(shooter)) return false;
if (!this.checkTriggerChance(level)) return false; if (!this.checkTriggerChance(level)) return false;
@ -110,7 +110,7 @@ public class FlareEnchant extends ExcellentEnchant implements Chanced, Arrowed,
} }
@Override @Override
public boolean onDamage(@NotNull EntityDamageByEntityEvent e, @NotNull Projectile projectile, @NotNull LivingEntity shooter, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { public boolean onDamage(@NotNull EntityDamageByEntityEvent event, @NotNull Projectile projectile, @NotNull LivingEntity shooter, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
return false; return false;
} }
} }

View File

@ -65,13 +65,13 @@ public class SniperEnchant extends ExcellentEnchant implements BowEnchant, Chanc
} }
@Override @Override
public boolean onShoot(@NotNull EntityShootBowEvent e, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) { public boolean onShoot(@NotNull EntityShootBowEvent event, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) {
if (!this.isAvailableToUse(shooter)) return false; if (!this.isAvailableToUse(shooter)) return false;
if (!this.checkTriggerChance(level)) return false; if (!this.checkTriggerChance(level)) return false;
double modifier = this.getSpeedModifier(level); double modifier = this.getSpeedModifier(level);
Entity entity = e.getProjectile(); Entity entity = event.getProjectile();
Vector vector = entity.getVelocity(); Vector vector = entity.getVelocity();
entity.setVelocity(vector.multiply(modifier)); entity.setVelocity(vector.multiply(modifier));
@ -79,12 +79,12 @@ public class SniperEnchant extends ExcellentEnchant implements BowEnchant, Chanc
} }
@Override @Override
public boolean onHit(@NotNull ProjectileHitEvent e, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) { public boolean onHit(@NotNull ProjectileHitEvent event, @NotNull Projectile projectile, @NotNull ItemStack bow, int level) {
return false; return false;
} }
@Override @Override
public boolean onDamage(@NotNull EntityDamageByEntityEvent e, @NotNull Projectile projectile, @NotNull LivingEntity shooter, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { public boolean onDamage(@NotNull EntityDamageByEntityEvent event, @NotNull Projectile projectile, @NotNull LivingEntity shooter, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
return false; return false;
} }
} }

View File

@ -16,7 +16,6 @@ import su.nightexpress.excellentenchants.api.enchantment.type.DeathEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation; import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.type.FitItemType; import su.nightexpress.excellentenchants.enchantment.type.FitItemType;
import su.nightexpress.excellentenchants.enchantment.util.EnchantDropContainer;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
public class CurseOfMediocrityEnchant extends ExcellentEnchant implements Chanced, BlockDropEnchant, DeathEnchant { public class CurseOfMediocrityEnchant extends ExcellentEnchant implements Chanced, BlockDropEnchant, DeathEnchant {
@ -62,7 +61,7 @@ public class CurseOfMediocrityEnchant extends ExcellentEnchant implements Chance
} }
@Override @Override
public boolean onDrop(@NotNull BlockDropItemEvent event, @NotNull EnchantDropContainer dropContainer, public boolean onDrop(@NotNull BlockDropItemEvent event,
@NotNull Player player, @NotNull ItemStack item, int level) { @NotNull Player player, @NotNull ItemStack item, int level) {
if (!this.isAvailableToUse(player)) return false; if (!this.isAvailableToUse(player)) return false;
if (!this.checkTriggerChance(level)) return false; if (!this.checkTriggerChance(level)) return false;
@ -75,12 +74,6 @@ public class CurseOfMediocrityEnchant extends ExcellentEnchant implements Chance
drop.setItemStack(stack); drop.setItemStack(stack);
}); });
dropContainer.getDrop().forEach(stack -> {
ItemUtil.mapMeta(stack, meta -> {
meta.getEnchants().keySet().forEach(meta::removeEnchant);
});
});
return true; return true;
} }

View File

@ -11,7 +11,6 @@ import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.player.PlayerItemDamageEvent; import org.bukkit.event.player.PlayerItemDamageEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.FixedMetadataValue;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.utils.NumberUtil; import su.nexmedia.engine.utils.NumberUtil;
import su.nightexpress.excellentenchants.ExcellentEnchants; import su.nightexpress.excellentenchants.ExcellentEnchants;
@ -33,14 +32,12 @@ public class EnchantBlastMining extends ExcellentEnchant implements Chanced, Blo
public static final String ID = "blast_mining"; public static final String ID = "blast_mining";
public static final String PLACEHOLDER_EXPLOSION_POWER = "%enchantment_explosion_power%"; public static final String PLACEHOLDER_EXPLOSION_POWER = "%enchantment_explosion_power%";
private static final String META_EXPLOSION_SOURCE = ID + "_explosion_source";
private static final String META_EXPLOSION_MINED = ID + "_explosion_mined";
private EnchantScaler explosionPower; private EnchantScaler explosionPower;
private EnchantScaler minBlockStrength; private EnchantScaler minBlockStrength;
private ChanceImplementation chanceImplementation; private ChanceImplementation chanceImplementation;
private int explodeLevel;
public EnchantBlastMining(@NotNull ExcellentEnchants plugin) { public EnchantBlastMining(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM); super(plugin, ID, EnchantPriority.MEDIUM);
this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to mine blocks by explosion."); this.getDefaults().setDescription(Placeholders.ENCHANTMENT_CHANCE + "% chance to mine blocks by explosion.");
@ -52,11 +49,14 @@ public class EnchantBlastMining extends ExcellentEnchant implements Chanced, Blo
@Override @Override
public void loadSettings() { public void loadSettings() {
super.loadSettings(); super.loadSettings();
this.chanceImplementation = ChanceImplementation.create(this, this.chanceImplementation = ChanceImplementation.create(this,
"20.0 * " + Placeholders.ENCHANTMENT_LEVEL); "20.0 * " + Placeholders.ENCHANTMENT_LEVEL);
this.explosionPower = EnchantScaler.read(this, "Settings.Explosion.Power", this.explosionPower = EnchantScaler.read(this, "Settings.Explosion.Power",
"3.0 + (" + Placeholders.ENCHANTMENT_LEVEL + " - 1.0 * 0.25)", "3.0 + (" + Placeholders.ENCHANTMENT_LEVEL + " - 1.0 * 0.25)",
"Explosion power. The more power = the more blocks (area) to explode."); "Explosion power. The more power = the more blocks (area) to explode.");
this.minBlockStrength = EnchantScaler.read(this, "Settings.Min_Block_Strength", this.minBlockStrength = EnchantScaler.read(this, "Settings.Min_Block_Strength",
"1.5 - " + Placeholders.ENCHANTMENT_LEVEL + " / 10", "1.5 - " + Placeholders.ENCHANTMENT_LEVEL + " / 10",
"Minimal block strength value for the enchantment to have effect.", "Minimal block strength value for the enchantment to have effect.",
@ -80,8 +80,8 @@ public class EnchantBlastMining extends ExcellentEnchant implements Chanced, Blo
return (float) minBlockStrength.getValue(level); return (float) minBlockStrength.getValue(level);
} }
private boolean isBlockHardEnough(@NotNull Block block, int level) { private boolean isHardEnough(@NotNull Block block, int level) {
float strength = block.getType().getHardness();//plugin.getNMS().getBlockStrength(block); float strength = block.getType().getHardness();
return (strength >= this.getMinBlockStrength(level)); return (strength >= this.getMinBlockStrength(level));
} }
@ -98,50 +98,37 @@ public class EnchantBlastMining extends ExcellentEnchant implements Chanced, Blo
} }
@Override @Override
public boolean onBreak(@NotNull BlockBreakEvent e, @NotNull Player player, @NotNull ItemStack item, int level) { public boolean onBreak(@NotNull BlockBreakEvent event, @NotNull Player player, @NotNull ItemStack item, int level) {
if (!this.isAvailableToUse(player)) return false; if (!this.isAvailableToUse(player)) return false;
if (EnchantUtils.isBusy()) return false;
if (EnchantUtils.contains(item, EnchantVeinminer.ID)) return false; Block block = event.getBlock();
if (EnchantUtils.contains(item, EnchantTunnel.ID)) return false; if (!this.isHardEnough(block, level)) return false;
Block block = e.getBlock();
if (block.hasMetadata(META_EXPLOSION_MINED)) return false;
if (!this.isBlockHardEnough(block, level)) return false;
if (!this.checkTriggerChance(level)) return false; if (!this.checkTriggerChance(level)) return false;
float power = (float) this.getExplosionPower(level); float power = (float) this.getExplosionPower(level);
player.setMetadata(META_EXPLOSION_SOURCE, new FixedMetadataValue(plugin, level)); this.explodeLevel = level;
NoCheatPlusHook.exemptBlocks(player); NoCheatPlusHook.exemptBlocks(player);
boolean exploded = block.getWorld().createExplosion(block.getLocation(), power, false, true, player); boolean exploded = block.getWorld().createExplosion(block.getLocation(), power, false, true, player);
NoCheatPlusHook.unexemptBlocks(player); NoCheatPlusHook.unexemptBlocks(player);
player.removeMetadata(META_EXPLOSION_SOURCE, plugin); this.explodeLevel = -1;
return exploded; return exploded;
} }
// Process explosion event to mine blocks. // Process explosion event to mine blocks.
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onBlastExplosionEvent(EntityExplodeEvent e) { public void onBlastExplosionEvent(EntityExplodeEvent event) {
if (!(e.getEntity() instanceof Player player)) return; if (this.explodeLevel <= 0) return;
if (!player.hasMetadata(META_EXPLOSION_SOURCE)) return; if (!(event.getEntity() instanceof Player player)) return;
int level = player.getMetadata(META_EXPLOSION_SOURCE).get(0).asInt(); List<Block> blockList = event.blockList();
List<Block> blockList = e.blockList();
// Remove the 'source' block which player mined and caused the explosion to prevent duplicated drops.
// Remove all the 'soft' blocks that should not be exploded.
blockList.removeIf(block -> block.getLocation().equals(e.getLocation()) || !this.isBlockHardEnough(block, level));
// Break all 'exploded' blocks by a player, adding metadata to them to prevent trigger enchantment in a loop.
blockList.forEach(block -> { blockList.forEach(block -> {
block.setMetadata(META_EXPLOSION_MINED, new FixedMetadataValue(plugin, true)); if (block.getLocation().equals(event.getLocation()) || !this.isHardEnough(block, this.explodeLevel)) return;
//plugin.getNMS().breakBlock(player, block);
player.breakBlock(block);
block.removeMetadata(META_EXPLOSION_MINED, plugin);
});
// Clear list of 'exploded' blocks so the event won't affect them, as they are already mined by a player. EnchantUtils.safeBusyBreak(player, block);
});
blockList.clear(); blockList.clear();
} }
@ -151,14 +138,12 @@ public class EnchantBlastMining extends ExcellentEnchant implements Chanced, Blo
if (e.getCause() != DamageCause.ENTITY_EXPLOSION) return; if (e.getCause() != DamageCause.ENTITY_EXPLOSION) return;
if (!(e.getDamager() instanceof Player player)) return; if (!(e.getDamager() instanceof Player player)) return;
e.setCancelled(player.hasMetadata(META_EXPLOSION_SOURCE)); e.setCancelled(this.explodeLevel > 0);
} }
// Do not reduce item durability for 'exploded' blocks. // Do not reduce item durability for 'exploded' blocks.
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onBlastExplosionItemDamage(PlayerItemDamageEvent e) { public void onBlastExplosionItemDamage(PlayerItemDamageEvent e) {
if (!e.getPlayer().hasMetadata(META_EXPLOSION_SOURCE)) return; e.setCancelled(this.explodeLevel > 0);
e.setCancelled(true);
} }
} }

View File

@ -74,12 +74,12 @@ public class EnchantCurseOfMisfortune extends ExcellentEnchant implements Chance
} }
@Override @Override
public boolean onBreak(@NotNull BlockBreakEvent e, @NotNull Player player, @NotNull ItemStack item, int level) { public boolean onBreak(@NotNull BlockBreakEvent event, @NotNull Player player, @NotNull ItemStack item, int level) {
if (!this.isAvailableToUse(player)) return false; if (!this.isAvailableToUse(player)) return false;
if (!this.checkTriggerChance(level)) return false; if (!this.checkTriggerChance(level)) return false;
e.setDropItems(false); event.setDropItems(false);
if (!this.isDropExp()) e.setExpToDrop(0); if (!this.isDropExp()) event.setExpToDrop(0);
return true; return true;
} }

View File

@ -31,8 +31,8 @@ import su.nightexpress.excellentenchants.api.enchantment.type.BlockDropEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation; import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.type.FitItemType; import su.nightexpress.excellentenchants.enchantment.type.FitItemType;
import su.nightexpress.excellentenchants.enchantment.util.EnchantDropContainer;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; 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 EnchantDivineTouch extends ExcellentEnchant implements Chanced, BlockBreakEnchant, BlockDropEnchant {
@ -102,16 +102,16 @@ public class EnchantDivineTouch extends ExcellentEnchant implements Chanced, Blo
} }
@Override @Override
public boolean onDrop(@NotNull BlockDropItemEvent event, @NotNull EnchantDropContainer dropContainer, @NotNull Player player, @NotNull ItemStack item, int level) { public boolean onDrop(@NotNull BlockDropItemEvent event, @NotNull Player player, @NotNull ItemStack item, int level) {
BlockState state = event.getBlockState(); BlockState state = event.getBlockState();
Block block = state.getBlock(); Block block = state.getBlock();
if (!block.hasMetadata(META_HANDLE)) return false; if (!block.hasMetadata(META_HANDLE)) return false;
if (!(state instanceof CreatureSpawner spawnerBlock)) return false; if (!(state instanceof CreatureSpawner spawnerBlock)) return false;
dropContainer.getDrop().add(this.getSpawner(spawnerBlock)); EnchantUtils.popResource(event, this.getSpawner(spawnerBlock));
Location location = LocationUtil.getCenter(block.getLocation());
if (this.hasVisualEffects()) { if (this.hasVisualEffects()) {
Location location = LocationUtil.getCenter(block.getLocation());
SimpleParticle.of(Particle.VILLAGER_HAPPY).play(location, 0.3, 0.15, 30); SimpleParticle.of(Particle.VILLAGER_HAPPY).play(location, 0.3, 0.15, 30);
} }
block.removeMetadata(META_HANDLE, this.plugin); block.removeMetadata(META_HANDLE, this.plugin);
@ -119,14 +119,14 @@ public class EnchantDivineTouch extends ExcellentEnchant implements Chanced, Blo
} }
@Override @Override
public boolean onBreak(@NotNull BlockBreakEvent e, @NotNull Player player, @NotNull ItemStack item, int level) { public boolean onBreak(@NotNull BlockBreakEvent event, @NotNull Player player, @NotNull ItemStack item, int level) {
Block block = e.getBlock(); Block block = event.getBlock();
if (!this.isAvailableToUse(player)) return false; if (!this.isAvailableToUse(player)) return false;
if (!(block.getState() instanceof CreatureSpawner spawnerBlock)) return false; if (!(block.getState() instanceof CreatureSpawner spawnerBlock)) return false;
if (!this.checkTriggerChance(level)) return false; if (!this.checkTriggerChance(level)) return false;
e.setExpToDrop(0); event.setExpToDrop(0);
e.setDropItems(true); event.setDropItems(true);
block.setMetadata(META_HANDLE, new FixedMetadataValue(this.plugin, true)); block.setMetadata(META_HANDLE, new FixedMetadataValue(this.plugin, true));
return false; // Do not consume charges return false; // Do not consume charges
} }

View File

@ -66,12 +66,12 @@ public class EnchantLuckyMiner extends ExcellentEnchant implements Chanced, Bloc
} }
@Override @Override
public boolean onBreak(@NotNull BlockBreakEvent e, @NotNull Player player, @NotNull ItemStack item, int level) { public boolean onBreak(@NotNull BlockBreakEvent event, @NotNull Player player, @NotNull ItemStack item, int level) {
if (!this.isAvailableToUse(player)) return false; if (!this.isAvailableToUse(player)) return false;
if (!this.checkTriggerChance(level)) return false; if (!this.checkTriggerChance(level)) return false;
double expMod = this.getExpModifier(level); double expMod = this.getExpModifier(level);
e.setExpToDrop((int) ((double) e.getExpToDrop() * expMod)); event.setExpToDrop((int) ((double) event.getExpToDrop() * expMod));
return true; return true;
} }
} }

View File

@ -120,21 +120,21 @@ public class EnchantReplanter extends ExcellentEnchant implements Chanced, Inter
} }
@Override @Override
public boolean onInteract(@NotNull PlayerInteractEvent e, @NotNull Player player, @NotNull ItemStack item, int level) { public boolean onInteract(@NotNull PlayerInteractEvent event, @NotNull Player player, @NotNull ItemStack item, int level) {
if (!this.isReplantOnRightClick()) return false; if (!this.isReplantOnRightClick()) return false;
if (!this.isAvailableToUse(player)) return false; if (!this.isAvailableToUse(player)) return false;
if (!this.checkTriggerChance(level)) return false; if (!this.checkTriggerChance(level)) return false;
// Check for a event hand. We dont want to trigger it twice. // Check for a event hand. We dont want to trigger it twice.
if (e.getHand() != EquipmentSlot.HAND) return false; if (event.getHand() != EquipmentSlot.HAND) return false;
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return false; if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return false;
// Check if player holds seeds to plant them by offhand interaction. // Check if player holds seeds to plant them by offhand interaction.
ItemStack off = player.getInventory().getItemInOffHand(); ItemStack off = player.getInventory().getItemInOffHand();
if (!off.getType().isAir() && CROPS.contains(off.getType())) return false; if (!off.getType().isAir() && CROPS.contains(off.getType())) return false;
// Check if clicked block is a farmland. // Check if clicked block is a farmland.
Block blockGround = e.getClickedBlock(); Block blockGround = event.getClickedBlock();
if (blockGround == null) return false; if (blockGround == null) return false;
if (blockGround.getType() != Material.FARMLAND && blockGround.getType() != Material.SOUL_SAND) return false; if (blockGround.getType() != Material.FARMLAND && blockGround.getType() != Material.SOUL_SAND) return false;
@ -158,12 +158,12 @@ public class EnchantReplanter extends ExcellentEnchant implements Chanced, Inter
} }
@Override @Override
public boolean onBreak(@NotNull BlockBreakEvent e, @NotNull Player player, @NotNull ItemStack item, int level) { public boolean onBreak(@NotNull BlockBreakEvent event, @NotNull Player player, @NotNull ItemStack item, int level) {
if (!this.isReplantOnPlantBreak()) return false; if (!this.isReplantOnPlantBreak()) return false;
if (!this.isAvailableToUse(player)) return false; if (!this.isAvailableToUse(player)) return false;
if (!this.checkTriggerChance(level)) return false; if (!this.checkTriggerChance(level)) return false;
Block blockPlant = e.getBlock(); Block blockPlant = event.getBlock();
//if (EnchantTelekinesis.isDropHandled(blockPlant)) return false; //if (EnchantTelekinesis.isDropHandled(blockPlant)) return false;
//if (EnchantRegister.TELEKINESIS != null && item.containsEnchantment(EnchantRegister.TELEKINESIS)) return false; //if (EnchantRegister.TELEKINESIS != null && item.containsEnchantment(EnchantRegister.TELEKINESIS)) return false;

View File

@ -28,8 +28,8 @@ import su.nightexpress.excellentenchants.Placeholders;
import su.nightexpress.excellentenchants.api.enchantment.type.BlockDropEnchant; import su.nightexpress.excellentenchants.api.enchantment.type.BlockDropEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.type.FitItemType; import su.nightexpress.excellentenchants.enchantment.type.FitItemType;
import su.nightexpress.excellentenchants.enchantment.util.EnchantDropContainer;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -130,7 +130,7 @@ public class EnchantSilkChest extends ExcellentEnchant implements BlockDropEncha
} }
@Override @Override
public boolean onDrop(@NotNull BlockDropItemEvent event, @NotNull EnchantDropContainer dropContainer, public boolean onDrop(@NotNull BlockDropItemEvent event,
@NotNull Player player, @NotNull ItemStack item, int level) { @NotNull Player player, @NotNull ItemStack item, int level) {
BlockState state = event.getBlockState(); BlockState state = event.getBlockState();
Block block = state.getBlock(); Block block = state.getBlock();
@ -143,12 +143,12 @@ public class EnchantSilkChest extends ExcellentEnchant implements BlockDropEncha
chest.getBlockInventory().addItem(event.getItems().stream().map(Item::getItemStack).toList().toArray(new ItemStack[0])); chest.getBlockInventory().addItem(event.getItems().stream().map(Item::getItemStack).toList().toArray(new ItemStack[0]));
if (chest.getBlockInventory().isEmpty()) { if (chest.getBlockInventory().isEmpty()) {
dropContainer.getDrop().add(new ItemStack(chest.getType())); EnchantUtils.popResource(event, new ItemStack(chest.getType()));
return false; return false;
} }
// Добавляем кастомный сундук в кастомный дроп лист. // Добавляем кастомный сундук в кастомный дроп лист.
dropContainer.getDrop().add(this.getSilkChest(chest)); EnchantUtils.popResource(event, this.getSilkChest(chest));
// Очищаем инвентарь сундука и дефолтный дроп лист. // Очищаем инвентарь сундука и дефолтный дроп лист.
chest.getBlockInventory().clear(); chest.getBlockInventory().clear();

View File

@ -22,7 +22,6 @@ import su.nightexpress.excellentenchants.api.enchantment.type.BlockDropEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation; import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.type.FitItemType; import su.nightexpress.excellentenchants.enchantment.type.FitItemType;
import su.nightexpress.excellentenchants.enchantment.util.EnchantDropContainer;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import java.util.Map; import java.util.Map;
@ -89,7 +88,10 @@ public class EnchantSmelter extends ExcellentEnchant implements Chanced, BlockDr
} }
@Override @Override
public boolean onDrop(@NotNull BlockDropItemEvent event, @NotNull EnchantDropContainer dropContainer, @NotNull Player player, @NotNull ItemStack item, int level) { public boolean onDrop(@NotNull BlockDropItemEvent event, @NotNull Player player, @NotNull ItemStack item, int level) {
// TODO Use furnace recipes
// TODO Re-add smelted items instead of setType
if (event.getBlockState() instanceof Container) return false; if (event.getBlockState() instanceof Container) return false;
if (!this.isAvailableToUse(player)) return false; if (!this.isAvailableToUse(player)) return false;
if (!this.checkTriggerChance(level)) return false; if (!this.checkTriggerChance(level)) return false;

View File

@ -8,17 +8,15 @@ import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.utils.PlayerUtil; import su.nexmedia.engine.utils.PlayerUtil;
import su.nightexpress.excellentenchants.ExcellentEnchants; 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.meta.Chanced;
import su.nightexpress.excellentenchants.api.enchantment.type.BlockDropEnchant; import su.nightexpress.excellentenchants.api.enchantment.type.BlockDropEnchant;
import su.nightexpress.excellentenchants.enchantment.util.EnchantDropContainer; import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation; import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.type.FitItemType; import su.nightexpress.excellentenchants.enchantment.type.FitItemType;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects;
public class EnchantTelekinesis extends ExcellentEnchant implements Chanced, BlockDropEnchant { public class EnchantTelekinesis extends ExcellentEnchant implements Chanced, BlockDropEnchant {
@ -58,17 +56,15 @@ public class EnchantTelekinesis extends ExcellentEnchant implements Chanced, Blo
} }
@Override @Override
public boolean onDrop(@NotNull BlockDropItemEvent event, @NotNull EnchantDropContainer dropContainer, @NotNull Player player, @NotNull ItemStack item, int level) { public boolean onDrop(@NotNull BlockDropItemEvent event, @NotNull Player player, @NotNull ItemStack item, int level) {
if (!this.isAvailableToUse(player)) return false; if (!this.isAvailableToUse(player)) return false;
if (!this.checkTriggerChance(level)) return false; if (!this.checkTriggerChance(level)) return false;
List<ItemStack> drops = new ArrayList<>(); List<ItemStack> drops = new ArrayList<>(event.getItems().stream().map(Item::getItemStack).toList());
drops.addAll(event.getItems().stream().map(Item::getItemStack).toList()); //drops.addAll(dropContainer.getDrop());
drops.addAll(dropContainer.getDrop()); //drops.removeIf(Objects::isNull);
drops.removeIf(Objects::isNull);
drops.forEach(drop -> PlayerUtil.addItem(player, drop)); drops.forEach(drop -> PlayerUtil.addItem(player, drop));
dropContainer.getDrop().clear();
event.getItems().clear(); event.getItems().clear();
return true; return true;

View File

@ -21,8 +21,8 @@ import su.nightexpress.excellentenchants.api.enchantment.type.BlockDropEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant; import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation; import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.type.FitItemType; import su.nightexpress.excellentenchants.enchantment.type.FitItemType;
import su.nightexpress.excellentenchants.enchantment.util.EnchantDropContainer;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority; import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils;
import java.util.*; import java.util.*;
import java.util.function.Predicate; import java.util.function.Predicate;
@ -128,15 +128,15 @@ public class EnchantTreasures extends ExcellentEnchant implements Chanced, Block
} }
@Override @Override
public boolean onBreak(@NotNull BlockBreakEvent e, @NotNull Player player, @NotNull ItemStack item, int level) { public boolean onBreak(@NotNull BlockBreakEvent event, @NotNull Player player, @NotNull ItemStack item, int level) {
if (PlayerBlockTracker.isTracked(e.getBlock())) { if (PlayerBlockTracker.isTracked(event.getBlock())) {
e.getBlock().setMetadata(META, new FixedMetadataValue(plugin, true)); event.getBlock().setMetadata(META, new FixedMetadataValue(plugin, true));
} }
return false; return false;
} }
@Override @Override
public boolean onDrop(@NotNull BlockDropItemEvent event, @NotNull EnchantDropContainer dropContainer, @NotNull Player player, @NotNull ItemStack item, int level) { public boolean onDrop(@NotNull BlockDropItemEvent event, @NotNull Player player, @NotNull ItemStack item, int level) {
Block block = event.getBlockState().getBlock(); Block block = event.getBlockState().getBlock();
if (block.hasMetadata(META)) { if (block.hasMetadata(META)) {
block.removeMetadata(META, plugin); block.removeMetadata(META, plugin);
@ -145,7 +145,11 @@ public class EnchantTreasures extends ExcellentEnchant implements Chanced, Block
if (!this.isAvailableToUse(player)) return false; if (!this.isAvailableToUse(player)) return false;
if (!this.checkTriggerChance(level)) return false; if (!this.checkTriggerChance(level)) return false;
dropContainer.getDrop().addAll(this.getTreasures(event.getBlockState().getType())); this.getTreasures(event.getBlockState().getType()).forEach(treasure -> {
EnchantUtils.popResource(event, treasure);
});
//dropContainer.getDrop().addAll(this.getTreasures(event.getBlockState().getType()));
return true; return true;
} }

View File

@ -20,7 +20,6 @@ import su.nightexpress.excellentenchants.hook.impl.NoCheatPlusHook;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.UUID;
public class EnchantTunnel extends ExcellentEnchant implements BlockBreakEnchant { public class EnchantTunnel extends ExcellentEnchant implements BlockBreakEnchant {
@ -34,12 +33,10 @@ public class EnchantTunnel extends ExcellentEnchant implements BlockBreakEnchant
INTERACTABLE_BLOCKS.add(Material.DEEPSLATE_REDSTONE_ORE); INTERACTABLE_BLOCKS.add(Material.DEEPSLATE_REDSTONE_ORE);
} }
private final Set<UUID> activePlayers;
private boolean disableOnSneak; private boolean disableOnSneak;
public EnchantTunnel(@NotNull ExcellentEnchants plugin) { public EnchantTunnel(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.HIGH); super(plugin, ID, EnchantPriority.HIGH);
this.activePlayers = new HashSet<>();
this.getDefaults().setDescription("Mines multiple blocks at once in a certain shape."); this.getDefaults().setDescription("Mines multiple blocks at once in a certain shape.");
this.getDefaults().setLevelMax(3); this.getDefaults().setLevelMax(3);
@ -66,19 +63,13 @@ public class EnchantTunnel extends ExcellentEnchant implements BlockBreakEnchant
return EnchantmentTarget.TOOL; return EnchantmentTarget.TOOL;
} }
public boolean isTunneling(@NotNull Player player) {
return this.activePlayers.contains(player.getUniqueId());
}
@Override @Override
public boolean onBreak(@NotNull BlockBreakEvent e, @NotNull Player player, @NotNull ItemStack item, int level) { public boolean onBreak(@NotNull BlockBreakEvent event, @NotNull Player player, @NotNull ItemStack item, int level) {
if (this.isTunneling(player)) return false; if (EnchantUtils.isBusy()) return false;
if (!this.isAvailableToUse(player)) return false; if (!this.isAvailableToUse(player)) return false;
if (this.disableOnSneak && player.isSneaking()) return false; if (this.disableOnSneak && player.isSneaking()) return false;
if (EnchantUtils.contains(item, EnchantVeinminer.ID)) return false;
if (EnchantUtils.contains(item, EnchantBlastMining.ID)) return false;
Block block = e.getBlock(); Block block = event.getBlock();
if (block.getType().isInteractable() && !INTERACTABLE_BLOCKS.contains(block.getType())) return false; if (block.getType().isInteractable() && !INTERACTABLE_BLOCKS.contains(block.getType())) return false;
if (block.getDrops(item).isEmpty()) return false; if (block.getDrops(item).isEmpty()) return false;
@ -90,9 +81,8 @@ public class EnchantTunnel extends ExcellentEnchant implements BlockBreakEnchant
int blocksBroken = 1; int blocksBroken = 1;
if (level == 1) blocksBroken = 2; if (level == 1) blocksBroken = 2;
else if (level == 2) blocksBroken = 5; else if (level == 2) blocksBroken = 5;
else if (level == 3) blocksBroken = 9; else if (level >= 3) blocksBroken = 9;
this.activePlayers.add(player.getUniqueId());
NoCheatPlusHook.exemptBlocks(player); NoCheatPlusHook.exemptBlocks(player);
for (int i = 0; i < blocksBroken; i++) { for (int i = 0; i < blocksBroken; i++) {
@ -121,11 +111,10 @@ public class EnchantTunnel extends ExcellentEnchant implements BlockBreakEnchant
if (addType == Material.BEDROCK || addType == Material.END_PORTAL || addType == Material.END_PORTAL_FRAME) continue; if (addType == Material.BEDROCK || addType == Material.END_PORTAL || addType == Material.END_PORTAL_FRAME) continue;
if (addType == Material.OBSIDIAN && addType != block.getType()) continue; if (addType == Material.OBSIDIAN && addType != block.getType()) continue;
player.breakBlock(blockAdd); EnchantUtils.safeBusyBreak(player, blockAdd);
} }
NoCheatPlusHook.unexemptBlocks(player); NoCheatPlusHook.unexemptBlocks(player);
this.activePlayers.remove(player.getUniqueId());
return true; return true;
} }
} }

View File

@ -23,7 +23,6 @@ import su.nightexpress.excellentenchants.hook.impl.NoCheatPlusHook;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
@ -36,15 +35,13 @@ public class EnchantVeinminer extends ExcellentEnchant implements BlockBreakEnch
BlockFace.WEST, BlockFace.SOUTH, BlockFace.NORTH BlockFace.WEST, BlockFace.SOUTH, BlockFace.NORTH
}; };
private static final String PLACEHOLDER_BLOCK_LIMIT = "%enchantment_block_limit%"; private static final String PLACEHOLDER_BLOCK_LIMIT = "%enchantment_block_limit%";
private Scaler blocksLimit; private Scaler blocksLimit;
private Set<Material> blocksAffected; private Set<Material> blocksAffected;
private final Set<UUID> activePlayers;
public EnchantVeinminer(@NotNull ExcellentEnchants plugin) { public EnchantVeinminer(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.HIGH); super(plugin, ID, EnchantPriority.HIGH);
this.activePlayers = new HashSet<>();
this.getDefaults().setDescription("Mines up to " + PLACEHOLDER_BLOCK_LIMIT + " blocks of the ore vein at once."); this.getDefaults().setDescription("Mines up to " + PLACEHOLDER_BLOCK_LIMIT + " blocks of the ore vein at once.");
this.getDefaults().setLevelMax(3); this.getDefaults().setLevelMax(3);
@ -110,10 +107,6 @@ public class EnchantVeinminer extends ExcellentEnchant implements BlockBreakEnch
.filter(blockAdded -> blockAdded.getType() == block.getType()).collect(Collectors.toSet()); .filter(blockAdded -> blockAdded.getType() == block.getType()).collect(Collectors.toSet());
} }
public boolean isInVein(@NotNull Player player) {
return this.activePlayers.contains(player.getUniqueId());
}
private void vein(@NotNull Player player, @NotNull Block source, int level) { private void vein(@NotNull Player player, @NotNull Block source, int level) {
Set<Block> ores = new HashSet<>(); Set<Block> ores = new HashSet<>();
Set<Block> prepare = new HashSet<>(this.getNearby(source)); Set<Block> prepare = new HashSet<>(this.getNearby(source));
@ -128,26 +121,21 @@ public class EnchantVeinminer extends ExcellentEnchant implements BlockBreakEnch
prepare.addAll(nearby); prepare.addAll(nearby);
} }
ores.remove(source); ores.remove(source);
ores.forEach(player::breakBlock); ores.forEach(ore -> EnchantUtils.safeBusyBreak(player, ore));
} }
@Override @Override
public boolean onBreak(@NotNull BlockBreakEvent e, @NotNull Player player, @NotNull ItemStack tool, int level) { public boolean onBreak(@NotNull BlockBreakEvent event, @NotNull Player player, @NotNull ItemStack tool, int level) {
if (this.isInVein(player)) return false;
if (!this.isAvailableToUse(player)) return false; if (!this.isAvailableToUse(player)) return false;
if (EnchantUtils.contains(tool, EnchantBlastMining.ID)) return false; if (EnchantUtils.isBusy()) return false;
if (EnchantUtils.contains(tool, EnchantTunnel.ID)) return false;
Block block = e.getBlock(); Block block = event.getBlock();
if (block.getDrops(tool).isEmpty()) return false; if (block.getDrops(tool, player).isEmpty()) return false;
if (!this.getBlocksAffected().contains(block.getType())) return false; if (!this.getBlocksAffected().contains(block.getType())) return false;
this.activePlayers.add(player.getUniqueId());
NoCheatPlusHook.exemptBlocks(player); NoCheatPlusHook.exemptBlocks(player);
this.vein(player, block, level); this.vein(player, block, level);
NoCheatPlusHook.unexemptBlocks(player); NoCheatPlusHook.unexemptBlocks(player);
this.activePlayers.remove(player.getUniqueId());
return true; return true;
} }
} }

View File

@ -65,13 +65,13 @@ public class EnchantBaneOfNetherspawn extends ExcellentEnchant implements Combat
} }
@Override @Override
public boolean onAttack(@NotNull EntityDamageByEntityEvent e, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { 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 (!ENTITY_TYPES.contains(victim.getType())) return false;
if (!this.isAvailableToUse(damager)) return false; if (!this.isAvailableToUse(damager)) return false;
double damageEvent = e.getDamage(); double damageEvent = event.getDamage();
double damageAdd = this.getDamageModifier(level); double damageAdd = this.getDamageModifier(level);
e.setDamage(this.damageModifier ? damageEvent * damageAdd : damageEvent + damageAdd); event.setDamage(this.damageModifier ? damageEvent * damageAdd : damageEvent + damageAdd);
if (this.hasVisualEffects()) { if (this.hasVisualEffects()) {
SimpleParticle.of(Particle.SMOKE_NORMAL).play(victim.getEyeLocation(), 0.25, 0.1, 30); SimpleParticle.of(Particle.SMOKE_NORMAL).play(victim.getEyeLocation(), 0.25, 0.1, 30);
} }
@ -79,7 +79,7 @@ public class EnchantBaneOfNetherspawn extends ExcellentEnchant implements Combat
} }
@Override @Override
public boolean onProtect(@NotNull EntityDamageByEntityEvent e, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { public boolean onProtect(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
return false; return false;
} }
} }

View File

@ -61,7 +61,7 @@ public class EnchantBlindness extends ExcellentEnchant implements Chanced, Potio
} }
@Override @Override
public boolean onAttack(@NotNull EntityDamageByEntityEvent e, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { 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.isAvailableToUse(damager)) return false;
if (!this.checkTriggerChance(level)) return false; if (!this.checkTriggerChance(level)) return false;
if (!this.addEffect(victim, level)) return false; if (!this.addEffect(victim, level)) return false;
@ -73,7 +73,7 @@ public class EnchantBlindness extends ExcellentEnchant implements Chanced, Potio
} }
@Override @Override
public boolean onProtect(@NotNull EntityDamageByEntityEvent e, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { public boolean onProtect(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
return false; return false;
} }
} }

View File

@ -62,7 +62,7 @@ public class EnchantConfusion extends ExcellentEnchant implements Chanced, Potio
} }
@Override @Override
public boolean onAttack(@NotNull EntityDamageByEntityEvent e, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { 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.isAvailableToUse(damager)) return false;
if (!this.checkTriggerChance(level)) return false; if (!this.checkTriggerChance(level)) return false;
if (!this.addEffect(victim, level)) return false; if (!this.addEffect(victim, level)) return false;
@ -75,7 +75,7 @@ public class EnchantConfusion extends ExcellentEnchant implements Chanced, Potio
} }
@Override @Override
public boolean onProtect(@NotNull EntityDamageByEntityEvent e, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { public boolean onProtect(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
return false; return false;
} }
} }

View File

@ -53,13 +53,13 @@ public class EnchantCure extends ExcellentEnchant implements Chanced, CombatEnch
} }
@Override @Override
public boolean onAttack(@NotNull EntityDamageByEntityEvent e, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { 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.isAvailableToUse(damager)) return false;
if (!CUREABLE.contains(victim.getType())) return false; if (!CUREABLE.contains(victim.getType())) return false;
if (!this.checkTriggerChance(level)) return false; if (!this.checkTriggerChance(level)) return false;
if (!(damager instanceof Player player)) return false; if (!(damager instanceof Player player)) return false;
e.setCancelled(true); event.setCancelled(true);
if (this.hasVisualEffects()) { if (this.hasVisualEffects()) {
SimpleParticle.of(Particle.CLOUD).play(victim.getEyeLocation(), 0.25, 0.1, 30); SimpleParticle.of(Particle.CLOUD).play(victim.getEyeLocation(), 0.25, 0.1, 30);
@ -77,7 +77,7 @@ public class EnchantCure extends ExcellentEnchant implements Chanced, CombatEnch
} }
@Override @Override
public boolean onProtect(@NotNull EntityDamageByEntityEvent e, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { public boolean onProtect(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
return false; return false;
} }
} }

View File

@ -78,7 +78,7 @@ public class EnchantCutter extends ExcellentEnchant implements Chanced, CombatEn
} }
@Override @Override
public boolean onAttack(@NotNull EntityDamageByEntityEvent e, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { 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.isAvailableToUse(damager)) return false;
EntityEquipment equipment = victim.getEquipment(); EntityEquipment equipment = victim.getEquipment();
@ -117,7 +117,7 @@ public class EnchantCutter extends ExcellentEnchant implements Chanced, CombatEn
} }
@Override @Override
public boolean onProtect(@NotNull EntityDamageByEntityEvent e, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { public boolean onProtect(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
return false; return false;
} }
} }

View File

@ -50,11 +50,11 @@ public class EnchantDoubleStrike extends ExcellentEnchant implements Chanced, Co
} }
@Override @Override
public boolean onAttack(@NotNull EntityDamageByEntityEvent e, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { 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.isAvailableToUse(damager)) return false;
if (!this.checkTriggerChance(level)) return false; if (!this.checkTriggerChance(level)) return false;
e.setDamage(e.getDamage() * 2D); event.setDamage(event.getDamage() * 2D);
if (this.hasVisualEffects()) { if (this.hasVisualEffects()) {
SimpleParticle.of(Particle.EXPLOSION_NORMAL).play(victim.getEyeLocation(), 0.25, 0.15, 15); SimpleParticle.of(Particle.EXPLOSION_NORMAL).play(victim.getEyeLocation(), 0.25, 0.15, 15);
@ -64,7 +64,7 @@ public class EnchantDoubleStrike extends ExcellentEnchant implements Chanced, Co
} }
@Override @Override
public boolean onProtect(@NotNull EntityDamageByEntityEvent e, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { public boolean onProtect(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
return false; return false;
} }
} }

View File

@ -62,7 +62,7 @@ public class EnchantExhaust extends ExcellentEnchant implements Chanced, Potione
} }
@Override @Override
public boolean onAttack(@NotNull EntityDamageByEntityEvent e, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { 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.isAvailableToUse(damager)) return false;
if (!this.checkTriggerChance(level)) return false; if (!this.checkTriggerChance(level)) return false;
if (!this.addEffect(victim, level)) return false; if (!this.addEffect(victim, level)) return false;
@ -74,7 +74,7 @@ public class EnchantExhaust extends ExcellentEnchant implements Chanced, Potione
} }
@Override @Override
public boolean onProtect(@NotNull EntityDamageByEntityEvent e, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { public boolean onProtect(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
return false; return false;
} }
} }

View File

@ -61,7 +61,7 @@ public class EnchantIceAspect extends ExcellentEnchant implements Chanced, Potio
} }
@Override @Override
public boolean onAttack(@NotNull EntityDamageByEntityEvent e, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { 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.isAvailableToUse(damager)) return false;
if (!this.checkTriggerChance(level)) return false; if (!this.checkTriggerChance(level)) return false;
if (!this.addEffect(victim, level)) return false; if (!this.addEffect(victim, level)) return false;
@ -75,7 +75,7 @@ public class EnchantIceAspect extends ExcellentEnchant implements Chanced, Potio
} }
@Override @Override
public boolean onProtect(@NotNull EntityDamageByEntityEvent e, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { public boolean onProtect(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
return false; return false;
} }
} }

View File

@ -61,7 +61,7 @@ public class EnchantParalyze extends ExcellentEnchant implements Chanced, Potion
} }
@Override @Override
public boolean onAttack(@NotNull EntityDamageByEntityEvent e, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { 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.isAvailableToUse(damager)) return false;
if (!this.checkTriggerChance(level)) return false; if (!this.checkTriggerChance(level)) return false;
if (!this.addEffect(victim, level)) return false; if (!this.addEffect(victim, level)) return false;
@ -73,7 +73,7 @@ public class EnchantParalyze extends ExcellentEnchant implements Chanced, Potion
} }
@Override @Override
public boolean onProtect(@NotNull EntityDamageByEntityEvent e, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { public boolean onProtect(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
return false; return false;
} }
} }

View File

@ -61,7 +61,7 @@ public class EnchantRage extends ExcellentEnchant implements Chanced, Potioned,
} }
@Override @Override
public boolean onAttack(@NotNull EntityDamageByEntityEvent e, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { 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.isAvailableToUse(damager)) return false;
if (!this.checkTriggerChance(level)) return false; if (!this.checkTriggerChance(level)) return false;
if (!this.addEffect(damager, level)) return false; if (!this.addEffect(damager, level)) return false;
@ -73,7 +73,7 @@ public class EnchantRage extends ExcellentEnchant implements Chanced, Potioned,
} }
@Override @Override
public boolean onProtect(@NotNull EntityDamageByEntityEvent e, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { public boolean onProtect(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
return false; return false;
} }
} }

View File

@ -61,7 +61,7 @@ public class EnchantRocket extends ExcellentEnchant implements Chanced, CombatEn
} }
@Override @Override
public boolean onAttack(@NotNull EntityDamageByEntityEvent e, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { 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.isAvailableToUse(damager)) return false;
if (!this.checkTriggerChance(level)) return false; if (!this.checkTriggerChance(level)) return false;
@ -96,7 +96,7 @@ public class EnchantRocket extends ExcellentEnchant implements Chanced, CombatEn
} }
@Override @Override
public boolean onProtect(@NotNull EntityDamageByEntityEvent e, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { public boolean onProtect(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
return false; return false;
} }
} }

View File

@ -64,7 +64,7 @@ public class EnchantSurprise extends ExcellentEnchant implements Chanced, Potion
} }
@Override @Override
public boolean onAttack(@NotNull EntityDamageByEntityEvent e, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { 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.isAvailableToUse(damager)) return false;
if (!this.checkTriggerChance(level)) return false; if (!this.checkTriggerChance(level)) return false;
@ -80,7 +80,7 @@ public class EnchantSurprise extends ExcellentEnchant implements Chanced, Potion
} }
@Override @Override
public boolean onProtect(@NotNull EntityDamageByEntityEvent e, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { public boolean onProtect(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
return false; return false;
} }
} }

View File

@ -68,7 +68,7 @@ public class EnchantTemper extends ExcellentEnchant implements CombatEnchant {
} }
@Override @Override
public boolean onAttack(@NotNull EntityDamageByEntityEvent e, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { 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.isAvailableToUse(damager)) return false;
double healthPoint = this.getHealthPoint(level); double healthPoint = this.getHealthPoint(level);
@ -84,12 +84,12 @@ public class EnchantTemper extends ExcellentEnchant implements CombatEnchant {
double damageCap = this.getDamageCapacity(level); double damageCap = this.getDamageCapacity(level);
double damageFinal = Math.min(damageCap, 1D + damageAmount * pointAmount); double damageFinal = Math.min(damageCap, 1D + damageAmount * pointAmount);
e.setDamage(e.getDamage() * damageFinal); event.setDamage(event.getDamage() * damageFinal);
return true; return true;
} }
@Override @Override
public boolean onProtect(@NotNull EntityDamageByEntityEvent e, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { public boolean onProtect(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
return false; return false;
} }
} }

View File

@ -60,7 +60,7 @@ public class EnchantThunder extends ExcellentEnchant implements Chanced, CombatE
} }
@Override @Override
public boolean onAttack(@NotNull EntityDamageByEntityEvent e, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { 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.isAvailableToUse(damager)) return false;
if (this.isInThunderstormOnly() && !victim.getWorld().isThundering()) return false; if (this.isInThunderstormOnly() && !victim.getWorld().isThundering()) return false;
if (victim.getLocation().getBlock().getLightFromSky() != 15) return false; if (victim.getLocation().getBlock().getLightFromSky() != 15) return false;
@ -76,7 +76,7 @@ public class EnchantThunder extends ExcellentEnchant implements Chanced, CombatE
} }
@Override @Override
public boolean onProtect(@NotNull EntityDamageByEntityEvent e, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { public boolean onProtect(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
return false; return false;
} }

View File

@ -73,7 +73,7 @@ public class EnchantVampire extends ExcellentEnchant implements Chanced, CombatE
} }
@Override @Override
public boolean onAttack(@NotNull EntityDamageByEntityEvent e, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { 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.isAvailableToUse(damager)) return false;
double healthMax = EntityUtil.getAttribute(damager, Attribute.GENERIC_MAX_HEALTH); double healthMax = EntityUtil.getAttribute(damager, Attribute.GENERIC_MAX_HEALTH);
@ -83,7 +83,7 @@ public class EnchantVampire extends ExcellentEnchant implements Chanced, CombatE
if (!this.checkTriggerChance(level)) return false; if (!this.checkTriggerChance(level)) return false;
double healAmount = this.getHealAmount(level); double healAmount = this.getHealAmount(level);
double healFinal = this.isHealMultiplier() ? e.getDamage() * healAmount : healAmount; double healFinal = this.isHealMultiplier() ? event.getDamage() * healAmount : healAmount;
EntityRegainHealthEvent healthEvent = new EntityRegainHealthEvent(damager, healFinal, EntityRegainHealthEvent.RegainReason.CUSTOM); EntityRegainHealthEvent healthEvent = new EntityRegainHealthEvent(damager, healFinal, EntityRegainHealthEvent.RegainReason.CUSTOM);
plugin.getPluginManager().callEvent(healthEvent); plugin.getPluginManager().callEvent(healthEvent);
@ -98,7 +98,7 @@ public class EnchantVampire extends ExcellentEnchant implements Chanced, CombatE
} }
@Override @Override
public boolean onProtect(@NotNull EntityDamageByEntityEvent e, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { public boolean onProtect(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
return false; return false;
} }
} }

View File

@ -61,7 +61,7 @@ public class EnchantVenom extends ExcellentEnchant implements Chanced, Potioned,
} }
@Override @Override
public boolean onAttack(@NotNull EntityDamageByEntityEvent e, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { 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.isAvailableToUse(damager)) return false;
if (!this.checkTriggerChance(level)) return false; if (!this.checkTriggerChance(level)) return false;
if (!this.addEffect(victim, level)) return false; if (!this.addEffect(victim, level)) return false;
@ -73,7 +73,7 @@ public class EnchantVenom extends ExcellentEnchant implements Chanced, Potioned,
} }
@Override @Override
public boolean onProtect(@NotNull EntityDamageByEntityEvent e, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { public boolean onProtect(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
return false; return false;
} }
} }

View File

@ -61,15 +61,15 @@ public class EnchantVillageDefender extends ExcellentEnchant implements CombatEn
} }
@Override @Override
public boolean onAttack(@NotNull EntityDamageByEntityEvent e, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { 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.isAvailableToUse(damager)) return false;
if (!(victim instanceof Illager)) return false; if (!(victim instanceof Illager)) return false;
double damageAdd = this.getDamageAddict(level); double damageAdd = this.getDamageAddict(level);
double damageHas = e.getDamage(); double damageHas = event.getDamage();
double damageFinal = this.isDamageMultiplier() ? (damageHas * damageAdd) : (damageHas + damageAdd); double damageFinal = this.isDamageMultiplier() ? (damageHas * damageAdd) : (damageHas + damageAdd);
e.setDamage(damageFinal); event.setDamage(damageFinal);
if (this.hasVisualEffects()) { if (this.hasVisualEffects()) {
SimpleParticle.of(Particle.VILLAGER_ANGRY).play(victim.getEyeLocation(), 0.25, 0.1, 30); SimpleParticle.of(Particle.VILLAGER_ANGRY).play(victim.getEyeLocation(), 0.25, 0.1, 30);
@ -78,7 +78,7 @@ public class EnchantVillageDefender extends ExcellentEnchant implements CombatEn
} }
@Override @Override
public boolean onProtect(@NotNull EntityDamageByEntityEvent e, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { public boolean onProtect(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
return false; return false;
} }
} }

View File

@ -61,7 +61,7 @@ public class EnchantWither extends ExcellentEnchant implements Chanced, Potioned
} }
@Override @Override
public boolean onAttack(@NotNull EntityDamageByEntityEvent e, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { 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.isAvailableToUse(damager)) return false;
if (!this.checkTriggerChance(level)) return false; if (!this.checkTriggerChance(level)) return false;
if (!this.addEffect(victim, level)) return false; if (!this.addEffect(victim, level)) return false;
@ -73,7 +73,7 @@ public class EnchantWither extends ExcellentEnchant implements Chanced, Potioned
} }
@Override @Override
public boolean onProtect(@NotNull EntityDamageByEntityEvent e, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) { public boolean onProtect(@NotNull EntityDamageByEntityEvent event, @NotNull LivingEntity damager, @NotNull LivingEntity victim, @NotNull ItemStack weapon, int level) {
return false; return false;
} }
} }

View File

@ -1,5 +1,6 @@
package su.nightexpress.excellentenchants.enchantment.listener; package su.nightexpress.excellentenchants.enchantment.listener;
import org.bukkit.World;
import org.bukkit.block.Chest; import org.bukkit.block.Chest;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.*; import org.bukkit.entity.*;
@ -93,15 +94,20 @@ public class EnchantGenericListener extends AbstractListener<ExcellentEnchants>
// Handle Enchanting Table // Handle Enchanting Table
// --------------------------------------------------------------- // ---------------------------------------------------------------
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onEnchantPopulateEnchantingTable(final EnchantItemEvent e) { public void onEnchantPopulateEnchantingTable(final EnchantItemEvent event) {
ItemStack target = e.getItem(); ItemStack target = event.getItem();
Map<Enchantment, Integer> enchantsPrepared = e.getEnchantsToAdd(); World world = event.getEnchanter().getWorld();
Map<Enchantment, Integer> enchantsToPopulate = EnchantUtils.getPopulationCandidates(target, ObtainType.ENCHANTING, enchantsPrepared, enchant -> enchant.getLevelByEnchantCost(e.getExpLevelCost()));
Map<Enchantment, Integer> enchantsPrepared = event.getEnchantsToAdd();
Map<Enchantment, Integer> enchantsToPopulate = EnchantUtils.getPopulationCandidates(
target, ObtainType.ENCHANTING, enchantsPrepared,
enchant -> enchant.getLevelByEnchantCost(event.getExpLevelCost()),
world);
enchantsPrepared.putAll(enchantsToPopulate); enchantsPrepared.putAll(enchantsToPopulate);
plugin.getServer().getScheduler().runTask(plugin, () -> { plugin.getServer().getScheduler().runTask(plugin, () -> {
ItemStack result = e.getInventory().getItem(0); ItemStack result = event.getInventory().getItem(0);
if (result == null) return; if (result == null) return;
// Fix enchantments for Enchant Books. // Fix enchantments for Enchant Books.
@ -109,7 +115,7 @@ public class EnchantGenericListener extends AbstractListener<ExcellentEnchants>
// Server gets enchants from NMS to apply it on Book NBT tags. // Server gets enchants from NMS to apply it on Book NBT tags.
ItemMeta meta = result.getItemMeta(); ItemMeta meta = result.getItemMeta();
if (meta instanceof EnchantmentStorageMeta storageMeta) { if (meta instanceof EnchantmentStorageMeta storageMeta) {
e.getEnchantsToAdd().forEach((enchantment, level) -> { event.getEnchantsToAdd().forEach((enchantment, level) -> {
if (!storageMeta.hasStoredEnchant(enchantment)) { if (!storageMeta.hasStoredEnchant(enchantment)) {
storageMeta.addStoredEnchant(enchantment, level, true); storageMeta.addStoredEnchant(enchantment, level, true);
} }
@ -117,14 +123,14 @@ public class EnchantGenericListener extends AbstractListener<ExcellentEnchants>
result.setItemMeta(storageMeta); result.setItemMeta(storageMeta);
} }
e.getEnchantsToAdd().forEach((enchantment, level) -> { event.getEnchantsToAdd().forEach((enchantment, level) -> {
if (enchantment instanceof ExcellentEnchant enchant && enchant.isChargesEnabled()) { if (enchantment instanceof ExcellentEnchant enchant && enchant.isChargesEnabled()) {
EnchantUtils.restoreCharges(result, enchant, level); EnchantUtils.restoreCharges(result, enchant, level);
} }
}); });
EnchantUtils.updateDisplay(result); EnchantUtils.updateDisplay(result);
e.getInventory().setItem(0, result); event.getInventory().setItem(0, result);
}); });
} }
@ -132,12 +138,13 @@ public class EnchantGenericListener extends AbstractListener<ExcellentEnchants>
// Adding Enchants to Villagers // Adding Enchants to Villagers
// --------------------------------------------------------------- // ---------------------------------------------------------------
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onEnchantPopulateVillagerAcquire(VillagerAcquireTradeEvent e) { public void onEnchantPopulateVillagerAcquire(VillagerAcquireTradeEvent event) {
MerchantRecipe recipe = e.getRecipe(); MerchantRecipe recipe = event.getRecipe();
ItemStack result = recipe.getResult(); ItemStack result = recipe.getResult();
World world = event.getEntity().getWorld();
if (!EnchantUtils.isEnchantable(result)) return; if (!EnchantUtils.isEnchantable(result)) return;
if (!EnchantUtils.populate(result, ObtainType.VILLAGER)) return; if (!EnchantUtils.populate(result, ObtainType.VILLAGER, world)) return;
int uses = recipe.getUses(); int uses = recipe.getUses();
int maxUses = recipe.getMaxUses(); int maxUses = recipe.getMaxUses();
@ -150,34 +157,36 @@ public class EnchantGenericListener extends AbstractListener<ExcellentEnchants>
MerchantRecipe recipe2 = new MerchantRecipe(result, uses, maxUses, expReward, villagerExperience, MerchantRecipe recipe2 = new MerchantRecipe(result, uses, maxUses, expReward, villagerExperience,
priceMultiplier, demand, specialPrice); priceMultiplier, demand, specialPrice);
recipe2.setIngredients(recipe.getIngredients()); recipe2.setIngredients(recipe.getIngredients());
e.setRecipe(recipe2); event.setRecipe(recipe2);
} }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onEnchantPopulateLoot(LootGenerateEvent e) { public void onEnchantPopulateLoot(LootGenerateEvent event) {
if (Config.getObtainSettings(ObtainType.LOOT_GENERATION).isEmpty()) return; if (Config.getObtainSettings(ObtainType.LOOT_GENERATION).isEmpty()) return;
Entity entity = e.getEntity(); Entity entity = event.getEntity();
InventoryHolder holder = e.getInventoryHolder(); InventoryHolder holder = event.getInventoryHolder();
World world = event.getWorld();
if (entity instanceof Minecart || holder instanceof Chest) { if (entity instanceof Minecart || holder instanceof Chest) {
e.getLoot().forEach(item -> { event.getLoot().forEach(item -> {
if (item != null && EnchantUtils.isEnchantable(item)) { if (item != null && EnchantUtils.isEnchantable(item)) {
EnchantUtils.populate(item, ObtainType.LOOT_GENERATION); EnchantUtils.populate(item, ObtainType.LOOT_GENERATION, world);
} }
}); });
} }
} }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onEnchantPopulateFishing(PlayerFishEvent e) { public void onEnchantPopulateFishing(PlayerFishEvent event) {
if (Config.getObtainSettings(ObtainType.FISHING).isEmpty()) return; if (Config.getObtainSettings(ObtainType.FISHING).isEmpty()) return;
if (e.getState() != PlayerFishEvent.State.CAUGHT_FISH) return; if (event.getState() != PlayerFishEvent.State.CAUGHT_FISH) return;
if (!(e.getCaught() instanceof Item item)) return; if (!(event.getCaught() instanceof Item item)) return;
ItemStack itemStack = item.getItemStack(); ItemStack itemStack = item.getItemStack();
World world = item.getWorld();
if (EnchantUtils.isEnchantable(itemStack)) { if (EnchantUtils.isEnchantable(itemStack)) {
EnchantUtils.populate(itemStack, ObtainType.FISHING); EnchantUtils.populate(itemStack, ObtainType.FISHING, world);
} }
} }
@ -191,13 +200,14 @@ public class EnchantGenericListener extends AbstractListener<ExcellentEnchants>
EntityEquipment equipment = entity.getEquipment(); EntityEquipment equipment = entity.getEquipment();
if (equipment == null) return; if (equipment == null) return;
World world = entity.getWorld();
boolean isMythic = EngineUtils.hasPlugin(HookId.MYTHIC_MOBS) && MythicMobsHook.isMythicMob(entity); boolean isMythic = EngineUtils.hasPlugin(HookId.MYTHIC_MOBS) && MythicMobsHook.isMythicMob(entity);
boolean doPopulation = Config.getObtainSettings(ObtainType.MOB_SPAWNING).isPresent() && !isMythic; boolean doPopulation = Config.getObtainSettings(ObtainType.MOB_SPAWNING).isPresent() && !isMythic;
for (EquipmentSlot slot : EquipmentSlot.values()) { for (EquipmentSlot slot : EquipmentSlot.values()) {
ItemStack item = equipment.getItem(slot); ItemStack item = equipment.getItem(slot);
if (EnchantUtils.isEnchantable(item)) { if (EnchantUtils.isEnchantable(item)) {
if (doPopulation) EnchantUtils.populate(item, ObtainType.MOB_SPAWNING); if (doPopulation) EnchantUtils.populate(item, ObtainType.MOB_SPAWNING, world);
EnchantUtils.getExcellents(item).forEach((enchant, level) -> EnchantUtils.restoreCharges(item, enchant, level)); EnchantUtils.getExcellents(item).forEach((enchant, level) -> EnchantUtils.restoreCharges(item, enchant, level));
equipment.setItem(slot, item); equipment.setItem(slot, item);
} }

View File

@ -1,10 +1,7 @@
package su.nightexpress.excellentenchants.enchantment.listener; package su.nightexpress.excellentenchants.enchantment.listener;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.BlockState;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile; import org.bukkit.entity.Projectile;
@ -29,7 +26,6 @@ import su.nightexpress.excellentenchants.api.enchantment.meta.Arrowed;
import su.nightexpress.excellentenchants.api.enchantment.type.*; import su.nightexpress.excellentenchants.api.enchantment.type.*;
import su.nightexpress.excellentenchants.config.Config; import su.nightexpress.excellentenchants.config.Config;
import su.nightexpress.excellentenchants.enchantment.EnchantManager; import su.nightexpress.excellentenchants.enchantment.EnchantManager;
import su.nightexpress.excellentenchants.enchantment.util.EnchantDropContainer;
import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils; import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils;
public class EnchantHandlerListener extends AbstractListener<ExcellentEnchants> { public class EnchantHandlerListener extends AbstractListener<ExcellentEnchants> {
@ -282,26 +278,26 @@ public class EnchantHandlerListener extends AbstractListener<ExcellentEnchants>
} }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onEnchantBlockDropItem(BlockDropItemEvent e) { public void onEnchantBlockDropItem(BlockDropItemEvent event) {
Player player = e.getPlayer(); Player player = event.getPlayer();
if (player.getGameMode() == GameMode.CREATIVE) return; if (player.getGameMode() == GameMode.CREATIVE) return;
ItemStack tool = player.getInventory().getItemInMainHand(); ItemStack tool = player.getInventory().getItemInMainHand();
if (tool.getType().isAir() || tool.getType() == Material.ENCHANTED_BOOK) return; if (tool.getType().isAir() || tool.getType() == Material.ENCHANTED_BOOK) return;
EnchantDropContainer dropContainer = new EnchantDropContainer(e); //EnchantDropContainer dropContainer = new EnchantDropContainer(e);
EnchantUtils.getExcellents(tool, BlockDropEnchant.class).forEach((enchant, level) -> { EnchantUtils.getExcellents(tool, BlockDropEnchant.class).forEach((enchant, level) -> {
if (enchant.isOutOfCharges(tool)) return; if (enchant.isOutOfCharges(tool)) return;
if (enchant.onDrop(e, dropContainer, player, tool, level)) { if (enchant.onDrop(event, player, tool, level)) {
enchant.consumeChargesNoUpdate(tool, level); enchant.consumeChargesNoUpdate(tool, level);
} }
}); });
EnchantUtils.updateChargesDisplay(tool); EnchantUtils.updateChargesDisplay(tool);
BlockState state = e.getBlockState(); //BlockState state = e.getBlockState();
World world = state.getWorld(); //World world = state.getWorld();
Location location = state.getLocation(); //Location location = state.getLocation();
dropContainer.getDrop().forEach(item -> world.dropItem(location, item)); //dropContainer.getDrop().forEach(item -> world.dropItem(location, item));
} }
} }

View File

@ -7,6 +7,7 @@ import org.jetbrains.annotations.NotNull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@Deprecated
public class EnchantDropContainer { public class EnchantDropContainer {
private final BlockDropItemEvent parent; private final BlockDropItemEvent parent;

View File

@ -2,10 +2,14 @@ package su.nightexpress.excellentenchants.enchantment.util;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.enchantments.EnchantmentTarget; import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.Item;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.block.BlockDropItemEvent;
import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -32,6 +36,7 @@ import su.nightexpress.excellentenchants.enchantment.type.ObtainType;
import su.nightexpress.excellentenchants.tier.Tier; import su.nightexpress.excellentenchants.tier.Tier;
import java.util.*; import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
@ -40,6 +45,37 @@ public class EnchantUtils {
public static final NamespacedKey KEY_LORE_SIZE = new NamespacedKey(ExcellentEnchantsAPI.PLUGIN, "lore_size"); public static final NamespacedKey KEY_LORE_SIZE = new NamespacedKey(ExcellentEnchantsAPI.PLUGIN, "lore_size");
private static boolean busyBreak = false;
public static void popResource(@NotNull BlockDropItemEvent event, @NotNull ItemStack itemStack) {
Item item = ExcellentEnchantsAPI.PLUGIN.getEnchantNMS().popResource(event.getBlock(), itemStack);
event.getItems().add(item);
}
public static boolean isBusyByOthers() {
return false;
}
public static boolean isBusyByEnchant() {
return busyBreak;
}
public static boolean isBusy() {
return isBusyByEnchant() || isBusyByOthers();
}
public static void busyBreak(@NotNull Player player, @NotNull Block block) {
busyBreak = true;
player.breakBlock(block);
busyBreak = false;
}
public static void safeBusyBreak(@NotNull Player player, @NotNull Block block) {
if (!isBusy()) {
busyBreak(player, block);
}
}
@NotNull @NotNull
public static NamespacedKey createKey(@NotNull String id) { public static NamespacedKey createKey(@NotNull String id) {
return NamespacedKey.minecraft(id.toLowerCase()); return NamespacedKey.minecraft(id.toLowerCase());
@ -65,15 +101,19 @@ public class EnchantUtils {
return item.getType() == Material.ENCHANTED_BOOK || Stream.of(EnchantmentTarget.values()).anyMatch(target -> target.includes(item)); return item.getType() == Material.ENCHANTED_BOOK || Stream.of(EnchantmentTarget.values()).anyMatch(target -> target.includes(item));
} }
public static boolean populate(@NotNull ItemStack item, @NotNull ObtainType obtainType) { // TODO Move in populator class
int enchantsHad = getAmount(item);
getPopulationCandidates(item, obtainType).forEach((enchantment, level) -> { public static boolean populate(@NotNull ItemStack item, @NotNull ObtainType obtainType, @Nullable World world) {
add(item, enchantment, level, false); AtomicBoolean status = new AtomicBoolean(false);
getPopulationCandidates(item, obtainType, world).forEach((enchantment, level) -> {
if (add(item, enchantment, level, false)) {
status.set(true);
}
}); });
updateDisplay(item); updateDisplay(item);
return getAmount(item) != enchantsHad; return status.get();
} }
@NotNull @NotNull
@ -88,14 +128,16 @@ public class EnchantUtils {
} }
@NotNull @NotNull
public static Map<Enchantment, Integer> getPopulationCandidates(@NotNull ItemStack item, @NotNull ObtainType obtainType) { public static Map<Enchantment, Integer> getPopulationCandidates(@NotNull ItemStack item, @NotNull ObtainType obtainType,
return getPopulationCandidates(item, obtainType, new HashMap<>(), (enchant) -> enchant.generateLevel(obtainType)); @Nullable World world) {
return getPopulationCandidates(item, obtainType, new HashMap<>(), (enchant) -> enchant.generateLevel(obtainType), world);
} }
@NotNull @NotNull
public static Map<Enchantment, Integer> getPopulationCandidates(@NotNull ItemStack item, @NotNull ObtainType obtainType, public static Map<Enchantment, Integer> getPopulationCandidates(@NotNull ItemStack item, @NotNull ObtainType obtainType,
@NotNull Map<Enchantment, Integer> enchantsPrepared, @NotNull Map<Enchantment, Integer> enchantsPrepared,
@NotNull Function<ExcellentEnchant, Integer> levelFunc) { @NotNull Function<ExcellentEnchant, Integer> levelFunc,
@Nullable World world) {
Map<Enchantment, Integer> enchantsToAdd = new HashMap<>(enchantsPrepared); Map<Enchantment, Integer> enchantsToAdd = new HashMap<>(enchantsPrepared);
ObtainSettings settings = Config.getObtainSettings(obtainType).orElse(null); ObtainSettings settings = Config.getObtainSettings(obtainType).orElse(null);
@ -104,44 +146,54 @@ public class EnchantUtils {
int enchMax = settings.getEnchantsTotalMax(); int enchMax = settings.getEnchantsTotalMax();
int enchRoll = Rnd.get(settings.getEnchantsCustomMin(), settings.getEnchantsCustomMax()); int enchRoll = Rnd.get(settings.getEnchantsCustomMin(), settings.getEnchantsCustomMax());
// Класс для исключения неудачных попыток.
EnchantPopulator populator = new EnchantPopulator(obtainType, item); EnchantPopulator populator = new EnchantPopulator(obtainType, item);
// Добавляем сколько можем, пока нужное количество не будет добавлено или не закончатся чары и/или тиры. // Try to populate as many as possible.
while (!populator.isEmpty() && enchRoll > 0) { while (!populator.isEmpty() && enchRoll > 0) {
// Достигнут максимум чар (любых) для итема, заканчиваем. // Limit reached.
if (enchantsToAdd.size() >= enchMax) break; if (enchantsToAdd.size() >= enchMax) break;
Tier tier = populator.getTierByChance(); Tier tier = populator.getTierByChance();
if (tier == null) break; // Нет тира? if (tier == null) break; // no tiers left.
ExcellentEnchant enchant = populator.getEnchantByChance(tier); ExcellentEnchant enchant = populator.getEnchantByChance(tier);
// В тире нет подходящих чар (вообще) для итема, исключаем и идем дальше. // Remove entire tier if no enchants can be selected.
if (enchant == null) { if (enchant == null) {
populator.purge(tier); populator.purge(tier);
continue; continue;
} }
// Среди уже добавленных чар есть конфликты с тем, что нашли. // Remove disabled world enchants.
// Исключаем, идем дальше. if (world != null && enchant.isDisabledInWorld(world)) {
populator.purge(tier, enchant);
continue;
}
// Remove conflicting enchants.
if (enchantsToAdd.keySet().stream().anyMatch(has -> has.conflictsWith(enchant) || enchant.conflictsWith(has))) { if (enchantsToAdd.keySet().stream().anyMatch(has -> has.conflictsWith(enchant) || enchant.conflictsWith(has))) {
populator.purge(tier, enchant); populator.purge(tier, enchant);
continue; continue;
} }
// Не получилось сгенерировать подходящий уровень. // Level generation failed.
// Исключаем, идем дальше.
int level = levelFunc.apply(enchant); int level = levelFunc.apply(enchant);
if (level < enchant.getStartLevel()) { if (level < enchant.getStartLevel()) {
populator.purge(tier, enchant); populator.purge(tier, enchant);
continue; continue;
} }
// Добавляем чар, засчитываем попытку. // All good!
populator.purge(tier, enchant); populator.purge(tier, enchant);
enchantsToAdd.put(enchant, level); enchantsToAdd.put(enchant, level);
enchRoll--; enchRoll--;
} }
if (!enchantsToAdd.isEmpty()) {
if (obtainType == ObtainType.VILLAGER && item.getType() == Material.ENCHANTED_BOOK && enchRoll == 1) {
getAll(item).keySet().forEach(enchantment -> remove(item, enchantment));
}
}
return enchantsToAdd; return enchantsToAdd;
} }

View File

@ -3,6 +3,7 @@ package su.nightexpress.excellentenchants.nms;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.FishHook; import org.bukkit.entity.FishHook;
import org.bukkit.entity.Item;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -20,4 +21,6 @@ public interface EnchantNMS {
@Nullable ItemStack getSpawnEgg(@NotNull LivingEntity entity); @Nullable ItemStack getSpawnEgg(@NotNull LivingEntity entity);
@NotNull Set<Block> handleFlameWalker(@NotNull LivingEntity entity, @NotNull Location location, int level); @NotNull Set<Block> handleFlameWalker(@NotNull LivingEntity entity, @NotNull Location location, int level);
@NotNull Item popResource(@NotNull Block block, @NotNull ItemStack item);
} }

View File

@ -3,9 +3,13 @@ package su.nightexpress.excellentenchants.nms.v1_17_R1;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.network.protocol.game.ClientboundAnimatePacket; import net.minecraft.network.protocol.game.ClientboundAnimatePacket;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.projectile.FishingHook; import net.minecraft.world.entity.projectile.FishingHook;
import net.minecraft.world.item.SpawnEggItem; import net.minecraft.world.item.SpawnEggItem;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.LiquidBlock; import net.minecraft.world.level.block.LiquidBlock;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
@ -13,12 +17,14 @@ import net.minecraft.world.phys.shapes.CollisionContext;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_17_R1.CraftWorld; import org.bukkit.craftbukkit.v1_17_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_17_R1.block.CraftBlock;
import org.bukkit.craftbukkit.v1_17_R1.entity.CraftFishHook; import org.bukkit.craftbukkit.v1_17_R1.entity.CraftFishHook;
import org.bukkit.craftbukkit.v1_17_R1.entity.CraftLivingEntity; import org.bukkit.craftbukkit.v1_17_R1.entity.CraftLivingEntity;
import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_17_R1.event.CraftEventFactory; import org.bukkit.craftbukkit.v1_17_R1.event.CraftEventFactory;
import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack;
import org.bukkit.entity.FishHook; import org.bukkit.entity.FishHook;
import org.bukkit.entity.Item;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -91,4 +97,20 @@ public class V1_17_R1 implements EnchantNMS {
} }
return blocks; return blocks;
} }
@NotNull
public Item popResource(@NotNull Block block, @NotNull ItemStack item) {
Level world = ((CraftWorld)block.getWorld()).getHandle();
BlockPos pos = ((CraftBlock)block).getPosition();
net.minecraft.world.item.ItemStack itemstack = CraftItemStack.asNMSCopy(item);
float yMod = EntityType.ITEM.getHeight() / 2.0F;
double x = (pos.getX() + 0.5F) + Mth.nextDouble(world.random, -0.25D, 0.25D);
double y = (pos.getY() + 0.5F) + Mth.nextDouble(world.random, -0.25D, 0.25D) - yMod;
double z = (pos.getZ() + 0.5F) + Mth.nextDouble(world.random, -0.25D, 0.25D);
ItemEntity itemEntity = new ItemEntity(world, x, y, z, itemstack);
itemEntity.setDefaultPickUpDelay();
return (Item) itemEntity.getBukkitEntity();
}
} }

View File

@ -3,9 +3,13 @@ package su.nightexpress.excellentenchants.nms.v1_18_R2;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.network.protocol.game.ClientboundAnimatePacket; import net.minecraft.network.protocol.game.ClientboundAnimatePacket;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.projectile.FishingHook; import net.minecraft.world.entity.projectile.FishingHook;
import net.minecraft.world.item.SpawnEggItem; import net.minecraft.world.item.SpawnEggItem;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.LiquidBlock; import net.minecraft.world.level.block.LiquidBlock;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
@ -13,12 +17,14 @@ import net.minecraft.world.phys.shapes.CollisionContext;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_18_R2.CraftWorld; import org.bukkit.craftbukkit.v1_18_R2.CraftWorld;
import org.bukkit.craftbukkit.v1_18_R2.block.CraftBlock;
import org.bukkit.craftbukkit.v1_18_R2.entity.CraftFishHook; import org.bukkit.craftbukkit.v1_18_R2.entity.CraftFishHook;
import org.bukkit.craftbukkit.v1_18_R2.entity.CraftLivingEntity; import org.bukkit.craftbukkit.v1_18_R2.entity.CraftLivingEntity;
import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_18_R2.event.CraftEventFactory; import org.bukkit.craftbukkit.v1_18_R2.event.CraftEventFactory;
import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack;
import org.bukkit.entity.FishHook; import org.bukkit.entity.FishHook;
import org.bukkit.entity.Item;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -91,4 +97,20 @@ public class V1_18_R2 implements EnchantNMS {
} }
return blocks; return blocks;
} }
@NotNull
public Item popResource(@NotNull Block block, @NotNull ItemStack item) {
Level world = ((CraftWorld)block.getWorld()).getHandle();
BlockPos pos = ((CraftBlock)block).getPosition();
net.minecraft.world.item.ItemStack itemstack = CraftItemStack.asNMSCopy(item);
float yMod = EntityType.ITEM.getHeight() / 2.0F;
double x = (pos.getX() + 0.5F) + Mth.nextDouble(world.random, -0.25D, 0.25D);
double y = (pos.getY() + 0.5F) + Mth.nextDouble(world.random, -0.25D, 0.25D) - yMod;
double z = (pos.getZ() + 0.5F) + Mth.nextDouble(world.random, -0.25D, 0.25D);
ItemEntity itemEntity = new ItemEntity(world, x, y, z, itemstack);
itemEntity.setDefaultPickUpDelay();
return (Item) itemEntity.getBukkitEntity();
}
} }

View File

@ -3,9 +3,13 @@ package su.nightexpress.excellentenchants.nms.v1_19_R3;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.network.protocol.game.ClientboundAnimatePacket; import net.minecraft.network.protocol.game.ClientboundAnimatePacket;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.projectile.FishingHook; import net.minecraft.world.entity.projectile.FishingHook;
import net.minecraft.world.item.SpawnEggItem; import net.minecraft.world.item.SpawnEggItem;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.LiquidBlock; import net.minecraft.world.level.block.LiquidBlock;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
@ -13,12 +17,14 @@ import net.minecraft.world.phys.shapes.CollisionContext;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_19_R3.CraftWorld; import org.bukkit.craftbukkit.v1_19_R3.CraftWorld;
import org.bukkit.craftbukkit.v1_19_R3.block.CraftBlock;
import org.bukkit.craftbukkit.v1_19_R3.entity.CraftFishHook; import org.bukkit.craftbukkit.v1_19_R3.entity.CraftFishHook;
import org.bukkit.craftbukkit.v1_19_R3.entity.CraftLivingEntity; import org.bukkit.craftbukkit.v1_19_R3.entity.CraftLivingEntity;
import org.bukkit.craftbukkit.v1_19_R3.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_19_R3.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_19_R3.event.CraftEventFactory; import org.bukkit.craftbukkit.v1_19_R3.event.CraftEventFactory;
import org.bukkit.craftbukkit.v1_19_R3.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_19_R3.inventory.CraftItemStack;
import org.bukkit.entity.FishHook; import org.bukkit.entity.FishHook;
import org.bukkit.entity.Item;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -91,4 +97,20 @@ public class V1_19_R3 implements EnchantNMS {
} }
return blocks; return blocks;
} }
@NotNull
public Item popResource(@NotNull Block block, @NotNull ItemStack item) {
Level world = ((CraftWorld)block.getWorld()).getHandle();
BlockPos pos = ((CraftBlock)block).getPosition();
net.minecraft.world.item.ItemStack itemstack = CraftItemStack.asNMSCopy(item);
float yMod = EntityType.ITEM.getHeight() / 2.0F;
double x = (pos.getX() + 0.5F) + Mth.nextDouble(world.random, -0.25D, 0.25D);
double y = (pos.getY() + 0.5F) + Mth.nextDouble(world.random, -0.25D, 0.25D) - yMod;
double z = (pos.getZ() + 0.5F) + Mth.nextDouble(world.random, -0.25D, 0.25D);
ItemEntity itemEntity = new ItemEntity(world, x, y, z, itemstack);
itemEntity.setDefaultPickUpDelay();
return (Item) itemEntity.getBukkitEntity();
}
} }

View File

@ -3,9 +3,13 @@ package su.nightexpress.excellentenchants.nms.v1_20_R1;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.network.protocol.game.ClientboundAnimatePacket; import net.minecraft.network.protocol.game.ClientboundAnimatePacket;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.projectile.FishingHook; import net.minecraft.world.entity.projectile.FishingHook;
import net.minecraft.world.item.SpawnEggItem; import net.minecraft.world.item.SpawnEggItem;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.LiquidBlock; import net.minecraft.world.level.block.LiquidBlock;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
@ -13,12 +17,14 @@ import net.minecraft.world.phys.shapes.CollisionContext;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_20_R1.CraftWorld; import org.bukkit.craftbukkit.v1_20_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_20_R1.block.CraftBlock;
import org.bukkit.craftbukkit.v1_20_R1.entity.CraftFishHook; import org.bukkit.craftbukkit.v1_20_R1.entity.CraftFishHook;
import org.bukkit.craftbukkit.v1_20_R1.entity.CraftLivingEntity; import org.bukkit.craftbukkit.v1_20_R1.entity.CraftLivingEntity;
import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_20_R1.event.CraftEventFactory; import org.bukkit.craftbukkit.v1_20_R1.event.CraftEventFactory;
import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftItemStack;
import org.bukkit.entity.FishHook; import org.bukkit.entity.FishHook;
import org.bukkit.entity.Item;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -91,4 +97,50 @@ public class V1_20_R1 implements EnchantNMS {
} }
return blocks; return blocks;
} }
@NotNull
public Item popResource(@NotNull Block block, @NotNull ItemStack item) {
Level world = ((CraftWorld)block.getWorld()).getHandle();
BlockPos pos = ((CraftBlock)block).getPosition();
net.minecraft.world.item.ItemStack itemstack = CraftItemStack.asNMSCopy(item);
float yMod = EntityType.ITEM.getHeight() / 2.0F;
double x = (pos.getX() + 0.5F) + Mth.nextDouble(world.random, -0.25D, 0.25D);
double y = (pos.getY() + 0.5F) + Mth.nextDouble(world.random, -0.25D, 0.25D) - yMod;
double z = (pos.getZ() + 0.5F) + Mth.nextDouble(world.random, -0.25D, 0.25D);
ItemEntity itemEntity = new ItemEntity(world, x, y, z, itemstack);
itemEntity.setDefaultPickUpDelay();
return (Item) itemEntity.getBukkitEntity();
}
/*public static void popResourceFromFace(Level world, BlockPos blockposition, Direction enumdirection, ItemStack itemstack) {
int i = enumdirection.getStepX();
int j = enumdirection.getStepY();
int k = enumdirection.getStepZ();
float f = EntityType.ITEM.getWidth() / 2.0F;
float f1 = EntityType.ITEM.getHeight() / 2.0F;
double d0 = (double)((float)blockposition.getX() + 0.5F) + (i == 0 ? Mth.nextDouble(world.random, -0.25D, 0.25D) : (double)((float)i * (0.5F + f)));
double d1 = (double)((float)blockposition.getY() + 0.5F) + (j == 0 ? Mth.nextDouble(world.random, -0.25D, 0.25D) : (double)((float)j * (0.5F + f1))) - (double)f1;
double d2 = (double)((float)blockposition.getZ() + 0.5F) + (k == 0 ? Mth.nextDouble(world.random, -0.25D, 0.25D) : (double)((float)k * (0.5F + f)));
double d3 = i == 0 ? Mth.nextDouble(world.random, -0.1D, 0.1D) : (double)i * 0.1D;
double d4 = j == 0 ? Mth.nextDouble(world.random, 0.0D, 0.1D) : (double)j * 0.1D + 0.1D;
double d5 = k == 0 ? Mth.nextDouble(world.random, -0.1D, 0.1D) : (double)k * 0.1D;
popResource(world, () -> {
return new ItemEntity(world, d0, d1, d2, itemstack, d3, d4, d5);
}, itemstack);
}
private static void popResource(Level world, Supplier<ItemEntity> supplier, ItemStack itemstack) {
if (!world.isClientSide && !itemstack.isEmpty() && world.getGameRules().getBoolean(GameRules.RULE_DOBLOCKDROPS)) {
ItemEntity entityitem = (ItemEntity)supplier.get();
entityitem.setDefaultPickUpDelay();
if (world.captureDrops != null) {
world.captureDrops.add(entityitem);
} else {
world.addFreshEntity(entityitem);
}
}
}*/
} }