Fixed bugs from new listener system

This commit is contained in:
Auxilor 2020-09-25 19:38:02 +01:00
parent 473fb5ad0f
commit 3656d3f684
6 changed files with 41 additions and 13 deletions

View File

@ -41,7 +41,7 @@ public class Buckshot extends EcoEnchant {
Arrow arrow1 = shooter.launchProjectile(Arrow.class, velocity);
if(EnchantChecks.mainhand(shooter, Enchantment.ARROW_FIRE)) arrow1.setFireTicks(Integer.MAX_VALUE);
arrow1.setPickupStatus(AbstractArrow.PickupStatus.DISALLOWED);
if(EnchantChecks.mainhand(shooter, EcoEnchants.MARKSMAN)) arrow1.setGravity(false);
}
}
}

View File

@ -26,7 +26,7 @@ public class Corrosive extends EcoEnchant {
@Override
public void onArrowDamage(LivingEntity attacker, LivingEntity uncastVictim, Arrow arrow, int level, EntityDamageByEntityEvent event) {
if(uncastVictim instanceof Player) return;
if(!(uncastVictim instanceof Player)) return;
Player victim = (Player) uncastVictim;
ArrayList<ItemStack> armor = new ArrayList<ItemStack>(Arrays.asList(victim.getInventory().getArmorContents()));

View File

@ -23,18 +23,31 @@ public class Frozen extends EcoEnchant {
// START OF LISTENERS
@EventHandler
public void onHurt(EntityDamageByEntityEvent event) {
if (!(event.getEntity() instanceof Player))
return;
@Override
public void onDamageWearingArmor(LivingEntity victim, int level, EntityDamageEvent event) {
if (NumberUtils.randFloat(0, 1) > level * 0.01 * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-point"))
if (!(event.getDamager() instanceof LivingEntity))
return;
Player player = (Player) event.getEntity();
LivingEntity victim = (LivingEntity) event.getDamager();
final int points = EnchantChecks.getArmorPoints(player, this, 1);
if (points == 0)
return;
if (NumberUtils.randFloat(0, 1) > points * 0.01 * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-point"))
return;
int divisor = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "points-per-level");
final int amplifier = (int) Math.ceil((double) level / divisor);
final int level = (int) Math.ceil((double) points / divisor);
Bukkit.getScheduler().runTaskLater(EcoEnchantsPlugin.getInstance(), () -> {
victim.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, level * 5, amplifier));
victim.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_DIGGING, level * 5, amplifier));
victim.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, points * 5, level));
victim.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_DIGGING, points * 5, level));
}, 1);
}
}

View File

@ -22,6 +22,9 @@ public class Instantaneous extends EcoEnchant {
@Override
public void onDamageBlock(Player player, Block block, int level, BlockDamageEvent event) {
if (NumberUtils.randFloat(0, 1) > level * 0.01 * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level"))
return;
AnticheatManager.exemptPlayer(player);
event.setInstaBreak(true);

View File

@ -22,18 +22,29 @@ public class Marksman extends EcoEnchant {
// START OF LISTENERS
@EventHandler
public void onMarksmanShoot(ProjectileLaunchEvent event) {
if (event.getEntityType() != EntityType.ARROW)
return;
@Override
public void onBowShoot(LivingEntity shooter, Arrow arrow, int level, EntityShootBowEvent event) {
arrow.setGravity(false);
if (!(event.getEntity().getShooter() instanceof Player))
return;
Player player = (Player) event.getEntity().getShooter();
if (!EnchantChecks.mainhand(player, this)) return;
if (!(event.getEntity() instanceof Arrow)) return;
Arrow a = (Arrow) event.getEntity();
a.setGravity(false);
int ticks = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "remove-arrow-after-ticks");
new BukkitRunnable() {
@Override
public void run() {
if (!arrow.isOnGround()) {
arrow.remove();
if (!a.isOnGround()) {
a.remove();
}
}
}.runTaskLater(EcoEnchantsPlugin.getInstance(), ticks);

View File

@ -21,6 +21,7 @@ public class Tripleshot extends EcoEnchant {
@Override
public void onBowShoot(LivingEntity shooter, Arrow arrow, int level, EntityShootBowEvent event) {
for (int i = -1; i < 2; i += 2) {
Vector velocity = event.getProjectile().getVelocity();