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 {
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.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import su.nightexpress.excellentenchants.enchantment.util.EnchantDropContainer;
import su.nightexpress.excellentenchants.api.enchantment.IEnchantment;
public interface BlockDropEnchant extends IEnchantment {
boolean onDrop(@NotNull BlockDropItemEvent event, @NotNull EnchantDropContainer dropContainer,
@NotNull Player player, @NotNull ItemStack item, int level);
boolean onDrop(@NotNull BlockDropItemEvent event, @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 {
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 ItemStack weapon, int level);
}

View File

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

View File

@ -8,5 +8,5 @@ import su.nightexpress.excellentenchants.api.enchantment.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 {
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(EnchantPoisonedArrows.ID, () -> new EnchantPoisonedArrows(plugin));
this.register(EnchantWitheredArrows.ID, () -> new EnchantWitheredArrows(plugin));
if (Version.isAbove(Version.V1_18_R2)) {
this.register(DarknessArrowsEnchant.ID, () -> new DarknessArrowsEnchant(plugin));
this.register(DarknessCloakEnchant.ID, () -> new DarknessCloakEnchant(plugin));

View File

@ -62,12 +62,12 @@ public class DarknessCloakEnchant extends ExcellentEnchant implements Chanced, P
}
@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;
}
@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.checkTriggerChance(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
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;
}
@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.checkTriggerChance(level)) return false;

View File

@ -62,12 +62,12 @@ public class EnchantFireShield extends ExcellentEnchant implements Chanced, Comb
}
@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;
}
@Override
public boolean onProtect(@NotNull EntityDamageByEntityEvent e,
public boolean onProtect(@NotNull EntityDamageByEntityEvent event,
@NotNull LivingEntity damager, @NotNull LivingEntity victim,
@NotNull ItemStack weapon, int level) {
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.ItemStack;
import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.Version;
import su.nexmedia.engine.api.particle.SimpleParticle;
import su.nexmedia.engine.api.server.AbstractTask;
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);
long time = pair.getFirst();
if (now >= time) {
block.getWorld().getPlayers().forEach(player -> {
player.sendBlockDamage(block.getLocation(), 0F, pair.getSecond());
});
if (Version.isAtLeast(Version.V1_19_R3)) {
block.getWorld().getPlayers().forEach(player -> {
player.sendBlockDamage(block.getLocation(), 0F, pair.getSecond());
});
}
block.setType(Material.LAVA);
@ -191,7 +194,7 @@ public class EnchantFlameWalker extends ExcellentEnchant implements Cleanable {
return true;
}
else {
else if (Version.isAtLeast(Version.V1_19_R3)) {
long diff = TimeUnit.MILLISECONDS.toSeconds(time - now);
float progress = (float) (1D - Math.min(1D, diff / 5D));

View File

@ -60,12 +60,12 @@ public class EnchantHardened extends ExcellentEnchant implements Chanced, Potion
}
@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;
}
@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.checkTriggerChance(level)) return false;

View File

@ -61,12 +61,12 @@ public class EnchantIceShield extends ExcellentEnchant implements Chanced, Potio
}
@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;
}
@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.checkTriggerChance(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
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;
}
@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.checkTriggerChance(level)) return false;

View File

@ -77,9 +77,9 @@ public class DarknessArrowsEnchant extends ExcellentEnchant implements Chanced,
}
@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 (!(e.getProjectile() instanceof Arrow arrow)) return false;
if (!(event.getProjectile() instanceof Arrow arrow)) return false;
if (!this.checkTriggerChance(level)) return false;
arrow.setPickupStatus(AbstractArrow.PickupStatus.DISALLOWED);
@ -87,12 +87,12 @@ public class DarknessArrowsEnchant extends ExcellentEnchant implements Chanced,
}
@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);
}
@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);
}
}

View File

@ -74,26 +74,26 @@ public class EnchantBomber extends ExcellentEnchant implements Chanced, BowEncha
}
@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.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);
primed.setVelocity(projectile.getVelocity().multiply(e.getForce() * 1.25));
primed.setVelocity(projectile.getVelocity().multiply(event.getForce() * 1.25));
primed.setFuseTicks(this.getFuseTicks(level));
primed.setSource(shooter);
e.setProjectile(primed);
event.setProjectile(primed);
return true;
}
@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;
}
@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;
}
}

View File

@ -77,9 +77,9 @@ public class EnchantConfusingArrows extends ExcellentEnchant implements Chanced,
}
@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 (!(e.getProjectile() instanceof Arrow arrow)) return false;
if (!(event.getProjectile() instanceof Arrow arrow)) return false;
if (!this.checkTriggerChance(level)) return false;
arrow.setPickupStatus(AbstractArrow.PickupStatus.DISALLOWED);
@ -87,12 +87,12 @@ public class EnchantConfusingArrows extends ExcellentEnchant implements Chanced,
}
@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);
}
@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);
}
}

View File

@ -98,16 +98,16 @@ public class EnchantDragonfireArrows extends ExcellentEnchant implements Chanced
}
@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;
return this.checkTriggerChance(level);
}
@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 (e.getHitEntity() != null) return false;
if (event.getHitEntity() != null) return false;
if (projectile.getShooter() == null) return false;
this.createCloud(projectile.getShooter(), projectile.getLocation() , level);
@ -115,7 +115,7 @@ public class EnchantDragonfireArrows extends ExcellentEnchant implements Chanced
}
@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;
this.createCloud(shooter, victim.getLocation(), level);

View File

@ -72,18 +72,18 @@ public class EnchantElectrifiedArrows extends ExcellentEnchant implements Chance
}
@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;
return this.checkTriggerChance(level);
}
@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 (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));
if (this.hasVisualEffects()) {
Location center = LocationUtil.getCenter(block.getLocation());
@ -94,7 +94,7 @@ public class EnchantElectrifiedArrows extends ExcellentEnchant implements Chance
}
@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;
plugin.getServer().getScheduler().runTask(plugin, () -> {

View File

@ -60,24 +60,24 @@ public class EnchantEnderBow extends ExcellentEnchant implements BowEnchant, Cha
}
@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.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);
pearl.setVelocity(projectile.getVelocity());
e.setProjectile(pearl);
event.setProjectile(pearl);
return true;
}
@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;
}
@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;
}
}

View File

@ -100,14 +100,14 @@ public class EnchantExplosiveArrows extends ExcellentEnchant implements Chanced,
}
@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;
return this.checkTriggerChance(level);
}
@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;
Entity shooter = null;
@ -126,7 +126,7 @@ public class EnchantExplosiveArrows extends ExcellentEnchant implements Chanced,
}
@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);
}

View File

@ -79,10 +79,10 @@ public class EnchantGhast extends ExcellentEnchant implements BowEnchant, Chance
}
@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.checkTriggerChance(level)) return false;
if (!(e.getProjectile() instanceof Projectile projectile)) return false;
if (!(event.getProjectile() instanceof Projectile projectile)) return false;
Fireball fireball;
@ -99,17 +99,17 @@ public class EnchantGhast extends ExcellentEnchant implements BowEnchant, Chance
fireball.setIsIncendiary(this.isFireSpread());
fireball.setYield(this.getYield(level));
e.setProjectile(fireball);
event.setProjectile(fireball);
return true;
}
@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;
}
@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 ItemStack weapon, int level) {
return false;

View File

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

View File

@ -77,9 +77,9 @@ public class EnchantPoisonedArrows extends ExcellentEnchant implements Chanced,
}
@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 (!(e.getProjectile() instanceof Arrow arrow)) return false;
if (!(event.getProjectile() instanceof Arrow arrow)) return false;
if (!this.checkTriggerChance(level)) return false;
arrow.setPickupStatus(AbstractArrow.PickupStatus.DISALLOWED);
@ -87,12 +87,12 @@ public class EnchantPoisonedArrows extends ExcellentEnchant implements Chanced,
}
@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);
}
@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);
}
}

View File

@ -77,9 +77,9 @@ public class EnchantWitheredArrows extends ExcellentEnchant implements Chanced,
}
@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 (!(e.getProjectile() instanceof Arrow arrow)) return false;
if (!(event.getProjectile() instanceof Arrow arrow)) return false;
if (!this.checkTriggerChance(level)) return false;
arrow.setPickupStatus(AbstractArrow.PickupStatus.DISALLOWED);
@ -87,12 +87,12 @@ public class EnchantWitheredArrows extends ExcellentEnchant implements Chanced,
}
@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);
}
@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);
}
}

View File

@ -69,8 +69,8 @@ public class FlareEnchant extends ExcellentEnchant implements Chanced, Arrowed,
}
@Override
public boolean onShoot(@NotNull EntityShootBowEvent e, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) {
if (!(e.getProjectile() instanceof Arrow arrow)) return false;
public boolean onShoot(@NotNull EntityShootBowEvent event, @NotNull LivingEntity shooter, @NotNull ItemStack bow, int level) {
if (!(event.getProjectile() instanceof Arrow arrow)) return false;
if (!this.isAvailableToUse(shooter)) return false;
if (!this.checkTriggerChance(level)) return false;
@ -110,7 +110,7 @@ public class FlareEnchant extends ExcellentEnchant implements Chanced, Arrowed,
}
@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;
}
}

View File

@ -65,13 +65,13 @@ public class SniperEnchant extends ExcellentEnchant implements BowEnchant, Chanc
}
@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.checkTriggerChance(level)) return false;
double modifier = this.getSpeedModifier(level);
Entity entity = e.getProjectile();
Entity entity = event.getProjectile();
Vector vector = entity.getVelocity();
entity.setVelocity(vector.multiply(modifier));
@ -79,12 +79,12 @@ public class SniperEnchant extends ExcellentEnchant implements BowEnchant, Chanc
}
@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;
}
@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;
}
}

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.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.type.FitItemType;
import su.nightexpress.excellentenchants.enchantment.util.EnchantDropContainer;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
public class CurseOfMediocrityEnchant extends ExcellentEnchant implements Chanced, BlockDropEnchant, DeathEnchant {
@ -62,7 +61,7 @@ public class CurseOfMediocrityEnchant extends ExcellentEnchant implements Chance
}
@Override
public boolean onDrop(@NotNull BlockDropItemEvent event, @NotNull EnchantDropContainer dropContainer,
public boolean onDrop(@NotNull BlockDropItemEvent event,
@NotNull Player player, @NotNull ItemStack item, int level) {
if (!this.isAvailableToUse(player)) return false;
if (!this.checkTriggerChance(level)) return false;
@ -75,12 +74,6 @@ public class CurseOfMediocrityEnchant extends ExcellentEnchant implements Chance
drop.setItemStack(stack);
});
dropContainer.getDrop().forEach(stack -> {
ItemUtil.mapMeta(stack, meta -> {
meta.getEnchants().keySet().forEach(meta::removeEnchant);
});
});
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.player.PlayerItemDamageEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.FixedMetadataValue;
import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.utils.NumberUtil;
import su.nightexpress.excellentenchants.ExcellentEnchants;
@ -33,14 +32,12 @@ public class EnchantBlastMining extends ExcellentEnchant implements Chanced, Blo
public static final String ID = "blast_mining";
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 minBlockStrength;
private ChanceImplementation chanceImplementation;
private int explodeLevel;
public EnchantBlastMining(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.MEDIUM);
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
public void loadSettings() {
super.loadSettings();
this.chanceImplementation = ChanceImplementation.create(this,
"20.0 * " + Placeholders.ENCHANTMENT_LEVEL);
this.explosionPower = EnchantScaler.read(this, "Settings.Explosion.Power",
"3.0 + (" + Placeholders.ENCHANTMENT_LEVEL + " - 1.0 * 0.25)",
"Explosion power. The more power = the more blocks (area) to explode.");
this.minBlockStrength = EnchantScaler.read(this, "Settings.Min_Block_Strength",
"1.5 - " + Placeholders.ENCHANTMENT_LEVEL + " / 10",
"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);
}
private boolean isBlockHardEnough(@NotNull Block block, int level) {
float strength = block.getType().getHardness();//plugin.getNMS().getBlockStrength(block);
private boolean isHardEnough(@NotNull Block block, int level) {
float strength = block.getType().getHardness();
return (strength >= this.getMinBlockStrength(level));
}
@ -98,50 +98,37 @@ public class EnchantBlastMining extends ExcellentEnchant implements Chanced, Blo
}
@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 (EnchantUtils.isBusy()) return false;
if (EnchantUtils.contains(item, EnchantVeinminer.ID)) return false;
if (EnchantUtils.contains(item, EnchantTunnel.ID)) return false;
Block block = e.getBlock();
if (block.hasMetadata(META_EXPLOSION_MINED)) return false;
if (!this.isBlockHardEnough(block, level)) return false;
Block block = event.getBlock();
if (!this.isHardEnough(block, level)) return false;
if (!this.checkTriggerChance(level)) return false;
float power = (float) this.getExplosionPower(level);
player.setMetadata(META_EXPLOSION_SOURCE, new FixedMetadataValue(plugin, level));
this.explodeLevel = level;
NoCheatPlusHook.exemptBlocks(player);
boolean exploded = block.getWorld().createExplosion(block.getLocation(), power, false, true, player);
NoCheatPlusHook.unexemptBlocks(player);
player.removeMetadata(META_EXPLOSION_SOURCE, plugin);
this.explodeLevel = -1;
return exploded;
}
// Process explosion event to mine blocks.
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onBlastExplosionEvent(EntityExplodeEvent e) {
if (!(e.getEntity() instanceof Player player)) return;
if (!player.hasMetadata(META_EXPLOSION_SOURCE)) return;
public void onBlastExplosionEvent(EntityExplodeEvent event) {
if (this.explodeLevel <= 0) return;
if (!(event.getEntity() instanceof Player player)) return;
int level = player.getMetadata(META_EXPLOSION_SOURCE).get(0).asInt();
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.
List<Block> blockList = event.blockList();
blockList.forEach(block -> {
block.setMetadata(META_EXPLOSION_MINED, new FixedMetadataValue(plugin, true));
//plugin.getNMS().breakBlock(player, block);
player.breakBlock(block);
block.removeMetadata(META_EXPLOSION_MINED, plugin);
});
if (block.getLocation().equals(event.getLocation()) || !this.isHardEnough(block, this.explodeLevel)) return;
// 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();
}
@ -151,14 +138,12 @@ public class EnchantBlastMining extends ExcellentEnchant implements Chanced, Blo
if (e.getCause() != DamageCause.ENTITY_EXPLOSION) 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.
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onBlastExplosionItemDamage(PlayerItemDamageEvent e) {
if (!e.getPlayer().hasMetadata(META_EXPLOSION_SOURCE)) return;
e.setCancelled(true);
e.setCancelled(this.explodeLevel > 0);
}
}

View File

@ -74,12 +74,12 @@ public class EnchantCurseOfMisfortune extends ExcellentEnchant implements Chance
}
@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.checkTriggerChance(level)) return false;
e.setDropItems(false);
if (!this.isDropExp()) e.setExpToDrop(0);
event.setDropItems(false);
if (!this.isDropExp()) event.setExpToDrop(0);
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.meta.ChanceImplementation;
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.EnchantUtils;
public class EnchantDivineTouch extends ExcellentEnchant implements Chanced, BlockBreakEnchant, BlockDropEnchant {
@ -102,16 +102,16 @@ public class EnchantDivineTouch extends ExcellentEnchant implements Chanced, Blo
}
@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();
Block block = state.getBlock();
if (!block.hasMetadata(META_HANDLE)) 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()) {
Location location = LocationUtil.getCenter(block.getLocation());
SimpleParticle.of(Particle.VILLAGER_HAPPY).play(location, 0.3, 0.15, 30);
}
block.removeMetadata(META_HANDLE, this.plugin);
@ -119,14 +119,14 @@ public class EnchantDivineTouch extends ExcellentEnchant implements Chanced, Blo
}
@Override
public boolean onBreak(@NotNull BlockBreakEvent e, @NotNull Player player, @NotNull ItemStack item, int level) {
Block block = e.getBlock();
public boolean onBreak(@NotNull BlockBreakEvent event, @NotNull Player player, @NotNull ItemStack item, int level) {
Block block = event.getBlock();
if (!this.isAvailableToUse(player)) return false;
if (!(block.getState() instanceof CreatureSpawner spawnerBlock)) return false;
if (!this.checkTriggerChance(level)) return false;
e.setExpToDrop(0);
e.setDropItems(true);
event.setExpToDrop(0);
event.setDropItems(true);
block.setMetadata(META_HANDLE, new FixedMetadataValue(this.plugin, true));
return false; // Do not consume charges
}

View File

@ -66,12 +66,12 @@ public class EnchantLuckyMiner extends ExcellentEnchant implements Chanced, Bloc
}
@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.checkTriggerChance(level)) return false;
double expMod = this.getExpModifier(level);
e.setExpToDrop((int) ((double) e.getExpToDrop() * expMod));
event.setExpToDrop((int) ((double) event.getExpToDrop() * expMod));
return true;
}
}

View File

@ -120,21 +120,21 @@ public class EnchantReplanter extends ExcellentEnchant implements Chanced, Inter
}
@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.isAvailableToUse(player)) return false;
if (!this.checkTriggerChance(level)) return false;
// Check for a event hand. We dont want to trigger it twice.
if (e.getHand() != EquipmentSlot.HAND) return false;
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return false;
if (event.getHand() != EquipmentSlot.HAND) return false;
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return false;
// Check if player holds seeds to plant them by offhand interaction.
ItemStack off = player.getInventory().getItemInOffHand();
if (!off.getType().isAir() && CROPS.contains(off.getType())) return false;
// Check if clicked block is a farmland.
Block blockGround = e.getClickedBlock();
Block blockGround = event.getClickedBlock();
if (blockGround == null) 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
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.isAvailableToUse(player)) return false;
if (!this.checkTriggerChance(level)) return false;
Block blockPlant = e.getBlock();
Block blockPlant = event.getBlock();
//if (EnchantTelekinesis.isDropHandled(blockPlant)) 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.enchantment.impl.ExcellentEnchant;
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.EnchantUtils;
import java.util.ArrayList;
import java.util.List;
@ -130,7 +130,7 @@ public class EnchantSilkChest extends ExcellentEnchant implements BlockDropEncha
}
@Override
public boolean onDrop(@NotNull BlockDropItemEvent event, @NotNull EnchantDropContainer dropContainer,
public boolean onDrop(@NotNull BlockDropItemEvent event,
@NotNull Player player, @NotNull ItemStack item, int level) {
BlockState state = event.getBlockState();
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]));
if (chest.getBlockInventory().isEmpty()) {
dropContainer.getDrop().add(new ItemStack(chest.getType()));
EnchantUtils.popResource(event, new ItemStack(chest.getType()));
return false;
}
// Добавляем кастомный сундук в кастомный дроп лист.
dropContainer.getDrop().add(this.getSilkChest(chest));
EnchantUtils.popResource(event, this.getSilkChest(chest));
// Очищаем инвентарь сундука и дефолтный дроп лист.
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.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.type.FitItemType;
import su.nightexpress.excellentenchants.enchantment.util.EnchantDropContainer;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import java.util.Map;
@ -89,7 +88,10 @@ public class EnchantSmelter extends ExcellentEnchant implements Chanced, BlockDr
}
@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 (!this.isAvailableToUse(player)) 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 su.nexmedia.engine.utils.PlayerUtil;
import su.nightexpress.excellentenchants.ExcellentEnchants;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.api.enchantment.meta.Chanced;
import su.nightexpress.excellentenchants.api.enchantment.type.BlockDropEnchant;
import su.nightexpress.excellentenchants.enchantment.util.EnchantDropContainer;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import su.nightexpress.excellentenchants.enchantment.impl.ExcellentEnchant;
import su.nightexpress.excellentenchants.enchantment.impl.meta.ChanceImplementation;
import su.nightexpress.excellentenchants.enchantment.type.FitItemType;
import su.nightexpress.excellentenchants.enchantment.util.EnchantPriority;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
public class EnchantTelekinesis extends ExcellentEnchant implements Chanced, BlockDropEnchant {
@ -58,17 +56,15 @@ public class EnchantTelekinesis extends ExcellentEnchant implements Chanced, Blo
}
@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.checkTriggerChance(level)) return false;
List<ItemStack> drops = new ArrayList<>();
drops.addAll(event.getItems().stream().map(Item::getItemStack).toList());
drops.addAll(dropContainer.getDrop());
drops.removeIf(Objects::isNull);
List<ItemStack> drops = new ArrayList<>(event.getItems().stream().map(Item::getItemStack).toList());
//drops.addAll(dropContainer.getDrop());
//drops.removeIf(Objects::isNull);
drops.forEach(drop -> PlayerUtil.addItem(player, drop));
dropContainer.getDrop().clear();
event.getItems().clear();
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.meta.ChanceImplementation;
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.EnchantUtils;
import java.util.*;
import java.util.function.Predicate;
@ -128,15 +128,15 @@ public class EnchantTreasures extends ExcellentEnchant implements Chanced, Block
}
@Override
public boolean onBreak(@NotNull BlockBreakEvent e, @NotNull Player player, @NotNull ItemStack item, int level) {
if (PlayerBlockTracker.isTracked(e.getBlock())) {
e.getBlock().setMetadata(META, new FixedMetadataValue(plugin, true));
public boolean onBreak(@NotNull BlockBreakEvent event, @NotNull Player player, @NotNull ItemStack item, int level) {
if (PlayerBlockTracker.isTracked(event.getBlock())) {
event.getBlock().setMetadata(META, new FixedMetadataValue(plugin, true));
}
return false;
}
@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();
if (block.hasMetadata(META)) {
block.removeMetadata(META, plugin);
@ -145,7 +145,11 @@ public class EnchantTreasures extends ExcellentEnchant implements Chanced, Block
if (!this.isAvailableToUse(player)) 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;
}

View File

@ -20,7 +20,6 @@ import su.nightexpress.excellentenchants.hook.impl.NoCheatPlusHook;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
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);
}
private final Set<UUID> activePlayers;
private boolean disableOnSneak;
public EnchantTunnel(@NotNull ExcellentEnchants plugin) {
super(plugin, ID, EnchantPriority.HIGH);
this.activePlayers = new HashSet<>();
this.getDefaults().setDescription("Mines multiple blocks at once in a certain shape.");
this.getDefaults().setLevelMax(3);
@ -66,19 +63,13 @@ public class EnchantTunnel extends ExcellentEnchant implements BlockBreakEnchant
return EnchantmentTarget.TOOL;
}
public boolean isTunneling(@NotNull Player player) {
return this.activePlayers.contains(player.getUniqueId());
}
@Override
public boolean onBreak(@NotNull BlockBreakEvent e, @NotNull Player player, @NotNull ItemStack item, int level) {
if (this.isTunneling(player)) return false;
public boolean onBreak(@NotNull BlockBreakEvent event, @NotNull Player player, @NotNull ItemStack item, int level) {
if (EnchantUtils.isBusy()) return false;
if (!this.isAvailableToUse(player)) 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.getDrops(item).isEmpty()) return false;
@ -90,9 +81,8 @@ public class EnchantTunnel extends ExcellentEnchant implements BlockBreakEnchant
int blocksBroken = 1;
if (level == 1) blocksBroken = 2;
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);
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.OBSIDIAN && addType != block.getType()) continue;
player.breakBlock(blockAdd);
EnchantUtils.safeBusyBreak(player, blockAdd);
}
NoCheatPlusHook.unexemptBlocks(player);
this.activePlayers.remove(player.getUniqueId());
return true;
}
}

View File

@ -23,7 +23,6 @@ import su.nightexpress.excellentenchants.hook.impl.NoCheatPlusHook;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@ -36,15 +35,13 @@ public class EnchantVeinminer extends ExcellentEnchant implements BlockBreakEnch
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 Set<Material> blocksAffected;
private final Set<UUID> activePlayers;
public EnchantVeinminer(@NotNull ExcellentEnchants plugin) {
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().setLevelMax(3);
@ -110,10 +107,6 @@ public class EnchantVeinminer extends ExcellentEnchant implements BlockBreakEnch
.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) {
Set<Block> ores = new HashSet<>();
Set<Block> prepare = new HashSet<>(this.getNearby(source));
@ -128,26 +121,21 @@ public class EnchantVeinminer extends ExcellentEnchant implements BlockBreakEnch
prepare.addAll(nearby);
}
ores.remove(source);
ores.forEach(player::breakBlock);
ores.forEach(ore -> EnchantUtils.safeBusyBreak(player, ore));
}
@Override
public boolean onBreak(@NotNull BlockBreakEvent e, @NotNull Player player, @NotNull ItemStack tool, int level) {
if (this.isInVein(player)) return false;
public boolean onBreak(@NotNull BlockBreakEvent event, @NotNull Player player, @NotNull ItemStack tool, int level) {
if (!this.isAvailableToUse(player)) return false;
if (EnchantUtils.contains(tool, EnchantBlastMining.ID)) return false;
if (EnchantUtils.contains(tool, EnchantTunnel.ID)) return false;
if (EnchantUtils.isBusy()) return false;
Block block = e.getBlock();
if (block.getDrops(tool).isEmpty()) return false;
Block block = event.getBlock();
if (block.getDrops(tool, player).isEmpty()) return false;
if (!this.getBlocksAffected().contains(block.getType())) return false;
this.activePlayers.add(player.getUniqueId());
NoCheatPlusHook.exemptBlocks(player);
this.vein(player, block, level);
NoCheatPlusHook.unexemptBlocks(player);
this.activePlayers.remove(player.getUniqueId());
return true;
}
}

View File

@ -65,13 +65,13 @@ public class EnchantBaneOfNetherspawn extends ExcellentEnchant implements Combat
}
@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 (!this.isAvailableToUse(damager)) return false;
double damageEvent = e.getDamage();
double damageEvent = event.getDamage();
double damageAdd = this.getDamageModifier(level);
e.setDamage(this.damageModifier ? damageEvent * damageAdd : damageEvent + damageAdd);
event.setDamage(this.damageModifier ? damageEvent * damageAdd : damageEvent + damageAdd);
if (this.hasVisualEffects()) {
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
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;
}
}

View File

@ -61,7 +61,7 @@ public class EnchantBlindness extends ExcellentEnchant implements Chanced, Potio
}
@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.checkTriggerChance(level)) return false;
if (!this.addEffect(victim, level)) return false;
@ -73,7 +73,7 @@ public class EnchantBlindness extends ExcellentEnchant implements Chanced, Potio
}
@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;
}
}

View File

@ -62,7 +62,7 @@ public class EnchantConfusion extends ExcellentEnchant implements Chanced, Potio
}
@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.checkTriggerChance(level)) return false;
if (!this.addEffect(victim, level)) return false;
@ -75,7 +75,7 @@ public class EnchantConfusion extends ExcellentEnchant implements Chanced, Potio
}
@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;
}
}

View File

@ -53,13 +53,13 @@ public class EnchantCure extends ExcellentEnchant implements Chanced, CombatEnch
}
@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 (!CUREABLE.contains(victim.getType())) return false;
if (!this.checkTriggerChance(level)) return false;
if (!(damager instanceof Player player)) return false;
e.setCancelled(true);
event.setCancelled(true);
if (this.hasVisualEffects()) {
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
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;
}
}

View File

@ -78,7 +78,7 @@ public class EnchantCutter extends ExcellentEnchant implements Chanced, CombatEn
}
@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;
EntityEquipment equipment = victim.getEquipment();
@ -117,7 +117,7 @@ public class EnchantCutter extends ExcellentEnchant implements Chanced, CombatEn
}
@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;
}
}

View File

@ -50,11 +50,11 @@ public class EnchantDoubleStrike extends ExcellentEnchant implements Chanced, Co
}
@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.checkTriggerChance(level)) return false;
e.setDamage(e.getDamage() * 2D);
event.setDamage(event.getDamage() * 2D);
if (this.hasVisualEffects()) {
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
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;
}
}

View File

@ -62,7 +62,7 @@ public class EnchantExhaust extends ExcellentEnchant implements Chanced, Potione
}
@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.checkTriggerChance(level)) return false;
if (!this.addEffect(victim, level)) return false;
@ -74,7 +74,7 @@ public class EnchantExhaust extends ExcellentEnchant implements Chanced, Potione
}
@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;
}
}

View File

@ -61,7 +61,7 @@ public class EnchantIceAspect extends ExcellentEnchant implements Chanced, Potio
}
@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.checkTriggerChance(level)) return false;
if (!this.addEffect(victim, level)) return false;
@ -75,7 +75,7 @@ public class EnchantIceAspect extends ExcellentEnchant implements Chanced, Potio
}
@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;
}
}

View File

@ -61,7 +61,7 @@ public class EnchantParalyze extends ExcellentEnchant implements Chanced, Potion
}
@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.checkTriggerChance(level)) return false;
if (!this.addEffect(victim, level)) return false;
@ -73,7 +73,7 @@ public class EnchantParalyze extends ExcellentEnchant implements Chanced, Potion
}
@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;
}
}

View File

@ -61,7 +61,7 @@ public class EnchantRage extends ExcellentEnchant implements Chanced, Potioned,
}
@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.checkTriggerChance(level)) return false;
if (!this.addEffect(damager, level)) return false;
@ -73,7 +73,7 @@ public class EnchantRage extends ExcellentEnchant implements Chanced, Potioned,
}
@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;
}
}

View File

@ -61,7 +61,7 @@ public class EnchantRocket extends ExcellentEnchant implements Chanced, CombatEn
}
@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.checkTriggerChance(level)) return false;
@ -96,7 +96,7 @@ public class EnchantRocket extends ExcellentEnchant implements Chanced, CombatEn
}
@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;
}
}

View File

@ -64,7 +64,7 @@ public class EnchantSurprise extends ExcellentEnchant implements Chanced, Potion
}
@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.checkTriggerChance(level)) return false;
@ -80,7 +80,7 @@ public class EnchantSurprise extends ExcellentEnchant implements Chanced, Potion
}
@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;
}
}

View File

@ -68,7 +68,7 @@ public class EnchantTemper extends ExcellentEnchant implements CombatEnchant {
}
@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;
double healthPoint = this.getHealthPoint(level);
@ -84,12 +84,12 @@ public class EnchantTemper extends ExcellentEnchant implements CombatEnchant {
double damageCap = this.getDamageCapacity(level);
double damageFinal = Math.min(damageCap, 1D + damageAmount * pointAmount);
e.setDamage(e.getDamage() * damageFinal);
event.setDamage(event.getDamage() * damageFinal);
return true;
}
@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;
}
}

View File

@ -60,7 +60,7 @@ public class EnchantThunder extends ExcellentEnchant implements Chanced, CombatE
}
@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.isInThunderstormOnly() && !victim.getWorld().isThundering()) return false;
if (victim.getLocation().getBlock().getLightFromSky() != 15) return false;
@ -76,7 +76,7 @@ public class EnchantThunder extends ExcellentEnchant implements Chanced, CombatE
}
@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;
}

View File

@ -73,7 +73,7 @@ public class EnchantVampire extends ExcellentEnchant implements Chanced, CombatE
}
@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;
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;
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);
plugin.getPluginManager().callEvent(healthEvent);
@ -98,7 +98,7 @@ public class EnchantVampire extends ExcellentEnchant implements Chanced, CombatE
}
@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;
}
}

View File

@ -61,7 +61,7 @@ public class EnchantVenom extends ExcellentEnchant implements Chanced, Potioned,
}
@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.checkTriggerChance(level)) return false;
if (!this.addEffect(victim, level)) return false;
@ -73,7 +73,7 @@ public class EnchantVenom extends ExcellentEnchant implements Chanced, Potioned,
}
@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;
}
}

View File

@ -61,15 +61,15 @@ public class EnchantVillageDefender extends ExcellentEnchant implements CombatEn
}
@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 (!(victim instanceof Illager)) return false;
double damageAdd = this.getDamageAddict(level);
double damageHas = e.getDamage();
double damageHas = event.getDamage();
double damageFinal = this.isDamageMultiplier() ? (damageHas * damageAdd) : (damageHas + damageAdd);
e.setDamage(damageFinal);
event.setDamage(damageFinal);
if (this.hasVisualEffects()) {
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
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;
}
}

View File

@ -61,7 +61,7 @@ public class EnchantWither extends ExcellentEnchant implements Chanced, Potioned
}
@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.checkTriggerChance(level)) return false;
if (!this.addEffect(victim, level)) return false;
@ -73,7 +73,7 @@ public class EnchantWither extends ExcellentEnchant implements Chanced, Potioned
}
@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;
}
}

View File

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

View File

@ -1,10 +1,7 @@
package su.nightexpress.excellentenchants.enchantment.listener;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.BlockState;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
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.config.Config;
import su.nightexpress.excellentenchants.enchantment.EnchantManager;
import su.nightexpress.excellentenchants.enchantment.util.EnchantDropContainer;
import su.nightexpress.excellentenchants.enchantment.util.EnchantUtils;
public class EnchantHandlerListener extends AbstractListener<ExcellentEnchants> {
@ -282,26 +278,26 @@ public class EnchantHandlerListener extends AbstractListener<ExcellentEnchants>
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onEnchantBlockDropItem(BlockDropItemEvent e) {
Player player = e.getPlayer();
public void onEnchantBlockDropItem(BlockDropItemEvent event) {
Player player = event.getPlayer();
if (player.getGameMode() == GameMode.CREATIVE) return;
ItemStack tool = player.getInventory().getItemInMainHand();
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) -> {
if (enchant.isOutOfCharges(tool)) return;
if (enchant.onDrop(e, dropContainer, player, tool, level)) {
if (enchant.onDrop(event, player, tool, level)) {
enchant.consumeChargesNoUpdate(tool, level);
}
});
EnchantUtils.updateChargesDisplay(tool);
BlockState state = e.getBlockState();
World world = state.getWorld();
Location location = state.getLocation();
//BlockState state = e.getBlockState();
//World world = state.getWorld();
//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.List;
@Deprecated
public class EnchantDropContainer {
private final BlockDropItemEvent parent;

View File

@ -2,10 +2,14 @@ package su.nightexpress.excellentenchants.enchantment.util;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.enchantments.EnchantmentTarget;
import org.bukkit.entity.Item;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.block.BlockDropItemEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
@ -32,6 +36,7 @@ import su.nightexpress.excellentenchants.enchantment.type.ObtainType;
import su.nightexpress.excellentenchants.tier.Tier;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Function;
import java.util.stream.Collectors;
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");
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
public static NamespacedKey createKey(@NotNull String id) {
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));
}
public static boolean populate(@NotNull ItemStack item, @NotNull ObtainType obtainType) {
int enchantsHad = getAmount(item);
// TODO Move in populator class
getPopulationCandidates(item, obtainType).forEach((enchantment, level) -> {
add(item, enchantment, level, false);
public static boolean populate(@NotNull ItemStack item, @NotNull ObtainType obtainType, @Nullable World world) {
AtomicBoolean status = new AtomicBoolean(false);
getPopulationCandidates(item, obtainType, world).forEach((enchantment, level) -> {
if (add(item, enchantment, level, false)) {
status.set(true);
}
});
updateDisplay(item);
return getAmount(item) != enchantsHad;
return status.get();
}
@NotNull
@ -88,14 +128,16 @@ public class EnchantUtils {
}
@NotNull
public static Map<Enchantment, Integer> getPopulationCandidates(@NotNull ItemStack item, @NotNull ObtainType obtainType) {
return getPopulationCandidates(item, obtainType, new HashMap<>(), (enchant) -> enchant.generateLevel(obtainType));
public static Map<Enchantment, Integer> getPopulationCandidates(@NotNull ItemStack item, @NotNull ObtainType obtainType,
@Nullable World world) {
return getPopulationCandidates(item, obtainType, new HashMap<>(), (enchant) -> enchant.generateLevel(obtainType), world);
}
@NotNull
public static Map<Enchantment, Integer> getPopulationCandidates(@NotNull ItemStack item, @NotNull ObtainType obtainType,
@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);
ObtainSettings settings = Config.getObtainSettings(obtainType).orElse(null);
@ -104,44 +146,54 @@ public class EnchantUtils {
int enchMax = settings.getEnchantsTotalMax();
int enchRoll = Rnd.get(settings.getEnchantsCustomMin(), settings.getEnchantsCustomMax());
// Класс для исключения неудачных попыток.
EnchantPopulator populator = new EnchantPopulator(obtainType, item);
// Добавляем сколько можем, пока нужное количество не будет добавлено или не закончатся чары и/или тиры.
// Try to populate as many as possible.
while (!populator.isEmpty() && enchRoll > 0) {
// Достигнут максимум чар (любых) для итема, заканчиваем.
// Limit reached.
if (enchantsToAdd.size() >= enchMax) break;
Tier tier = populator.getTierByChance();
if (tier == null) break; // Нет тира?
if (tier == null) break; // no tiers left.
ExcellentEnchant enchant = populator.getEnchantByChance(tier);
// В тире нет подходящих чар (вообще) для итема, исключаем и идем дальше.
// Remove entire tier if no enchants can be selected.
if (enchant == null) {
populator.purge(tier);
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))) {
populator.purge(tier, enchant);
continue;
}
// Не получилось сгенерировать подходящий уровень.
// Исключаем, идем дальше.
// Level generation failed.
int level = levelFunc.apply(enchant);
if (level < enchant.getStartLevel()) {
populator.purge(tier, enchant);
continue;
}
// Добавляем чар, засчитываем попытку.
// All good!
populator.purge(tier, enchant);
enchantsToAdd.put(enchant, level);
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;
}

View File

@ -3,6 +3,7 @@ package su.nightexpress.excellentenchants.nms;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.FishHook;
import org.bukkit.entity.Item;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@ -20,4 +21,6 @@ public interface EnchantNMS {
@Nullable ItemStack getSpawnEgg(@NotNull LivingEntity entity);
@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.network.protocol.game.ClientboundAnimatePacket;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.Mth;
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.item.SpawnEggItem;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.LiquidBlock;
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.block.Block;
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.CraftLivingEntity;
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.inventory.CraftItemStack;
import org.bukkit.entity.FishHook;
import org.bukkit.entity.Item;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@ -91,4 +97,20 @@ public class V1_17_R1 implements EnchantNMS {
}
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.network.protocol.game.ClientboundAnimatePacket;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.Mth;
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.item.SpawnEggItem;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.LiquidBlock;
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.block.Block;
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.CraftLivingEntity;
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.inventory.CraftItemStack;
import org.bukkit.entity.FishHook;
import org.bukkit.entity.Item;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@ -91,4 +97,20 @@ public class V1_18_R2 implements EnchantNMS {
}
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.network.protocol.game.ClientboundAnimatePacket;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.Mth;
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.item.SpawnEggItem;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.LiquidBlock;
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.block.Block;
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.CraftLivingEntity;
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.inventory.CraftItemStack;
import org.bukkit.entity.FishHook;
import org.bukkit.entity.Item;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@ -91,4 +97,20 @@ public class V1_19_R3 implements EnchantNMS {
}
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.network.protocol.game.ClientboundAnimatePacket;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.Mth;
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.item.SpawnEggItem;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.LiquidBlock;
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.block.Block;
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.CraftLivingEntity;
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.inventory.CraftItemStack;
import org.bukkit.entity.FishHook;
import org.bukkit.entity.Item;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@ -91,4 +97,50 @@ public class V1_20_R1 implements EnchantNMS {
}
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);
}
}
}*/
}