From e1bcf54fae9a89976b46858f8c47b01c9bfe73cc Mon Sep 17 00:00:00 2001 From: PrimordialMoros Date: Tue, 17 Nov 2020 23:49:19 +0200 Subject: [PATCH] Improve earthguard, earthshot, earthglove and firewave --- build.gradle.kts | 2 +- .../abilities/earthbending/EarthGlove.java | 25 +++++++---- .../abilities/earthbending/EarthGuard.java | 12 +++++- .../abilities/earthbending/EarthShot.java | 41 +++++++++++++------ .../abilities/firebending/combo/FireWave.java | 9 +++- .../hyperion/configuration/ConfigManager.java | 4 +- .../hyperion/listeners/AbilityListener.java | 4 +- .../hyperion/listeners/CoreListener.java | 36 +++++++++++----- 8 files changed, 93 insertions(+), 40 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 5cb8c4b..4e58e13 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,7 +4,7 @@ plugins { } group = "me.moros" -version = "1.6.1" +version = "1.6.2" configure { sourceCompatibility = JavaVersion.VERSION_1_8 diff --git a/src/main/java/me/moros/hyperion/abilities/earthbending/EarthGlove.java b/src/main/java/me/moros/hyperion/abilities/earthbending/EarthGlove.java index 565e16e..aaf833c 100755 --- a/src/main/java/me/moros/hyperion/abilities/earthbending/EarthGlove.java +++ b/src/main/java/me/moros/hyperion/abilities/earthbending/EarthGlove.java @@ -98,6 +98,7 @@ public void progress() { returning = true; } + Vector vector = lastVelocity.clone(); // Record velocity if (returning) { if (!player.isSneaking()) { shatterGlove(); @@ -109,31 +110,36 @@ public void progress() { remove(); return; } - final Vector returnVector = GeneralMethods.getDirection(glove.getLocation(), returnLocation).normalize(); if (grabbed) { if (grabbedTarget == null || !grabbedTarget.isValid() || (grabbedTarget instanceof Player && !((Player) grabbedTarget).isOnline())) { shatterGlove(); return; } - grabbedTarget.setVelocity(returnVector.clone().multiply(GLOVE_GRABBED_SPEED)); - setGloveVelocity(returnVector.clone().multiply(GLOVE_GRABBED_SPEED)); + grabbedTarget.setVelocity(GeneralMethods.getDirection(grabbedTarget.getLocation(), returnLocation).normalize().multiply(GLOVE_GRABBED_SPEED)); + glove.teleport(grabbedTarget.getEyeLocation().subtract(0, grabbedTarget.getHeight() / 2, 0)); + return; } else { - setGloveVelocity(returnVector.clone().multiply(GLOVE_SPEED)); + setGloveVelocity(GeneralMethods.getDirection(glove.getLocation(), returnLocation).normalize().multiply(GLOVE_SPEED)); } } else { setGloveVelocity(lastVelocity.clone().normalize().multiply(GLOVE_SPEED)); checkDamage(); + if (grabbed) { + Location returnLocation = player.getEyeLocation().add(player.getEyeLocation().getDirection().multiply(1.5)); + final Vector returnVector = GeneralMethods.getDirection(glove.getLocation(), returnLocation).normalize(); + grabbedTarget.setVelocity(returnVector.clone().multiply(GLOVE_GRABBED_SPEED)); + setGloveVelocity(returnVector.clone().multiply(GLOVE_GRABBED_SPEED)); + return; + } } double velocityLimit = (grabbed ? GLOVE_GRABBED_SPEED : GLOVE_SPEED) - 0.2; - if (glove.isOnGround() || lastVelocity.angle(glove.getVelocity()) > Math.PI / 4 || glove.getVelocity().length() < velocityLimit) { + if (glove.isOnGround() || vector.angle(glove.getVelocity()) > Math.PI / 4 || glove.getVelocity().length() < velocityLimit) { shatterGlove(); } } private boolean launchEarthGlove() { - if (!player.isSneaking()) return false; - final Location gloveSpawnLocation; switch (lastUsedSide.getOrDefault(player.getUniqueId(), Side.RIGHT)) { case LEFT: @@ -156,7 +162,8 @@ private boolean launchEarthGlove() { final Entity targetedEntity = GeneralMethods.getTargetedEntity(player, range, Collections.singletonList(player)); final Vector velocityVector; if (targetedEntity instanceof LivingEntity) { - velocityVector = GeneralMethods.getDirection(gloveSpawnLocation, ((LivingEntity) targetedEntity).getEyeLocation()); + Location targetLoc = ((LivingEntity) targetedEntity).getEyeLocation().subtract(0, targetedEntity.getHeight() / 2, 0); + velocityVector = GeneralMethods.getDirection(gloveSpawnLocation, targetLoc); } else { velocityVector = GeneralMethods.getDirection(gloveSpawnLocation, GeneralMethods.getTargetedLocation(player, range)); } @@ -181,7 +188,7 @@ public void grabTarget(final LivingEntity entity) { returning = true; grabbed = true; grabbedTarget = entity; - glove.teleport(grabbedTarget.getEyeLocation()); + glove.teleport(grabbedTarget.getEyeLocation().subtract(0, grabbedTarget.getHeight() / 2, 0)); } public void checkDamage() { diff --git a/src/main/java/me/moros/hyperion/abilities/earthbending/EarthGuard.java b/src/main/java/me/moros/hyperion/abilities/earthbending/EarthGuard.java index daf6183..0fbdba6 100755 --- a/src/main/java/me/moros/hyperion/abilities/earthbending/EarthGuard.java +++ b/src/main/java/me/moros/hyperion/abilities/earthbending/EarthGuard.java @@ -23,12 +23,14 @@ import com.projectkorra.projectkorra.ability.AddonAbility; import com.projectkorra.projectkorra.ability.EarthAbility; import com.projectkorra.projectkorra.attribute.Attribute; +import com.projectkorra.projectkorra.earthbending.EarthArmor; import com.projectkorra.projectkorra.util.ParticleEffect; import com.projectkorra.projectkorra.util.TempBlock; import com.projectkorra.projectkorra.util.TempPotionEffect; import me.moros.hyperion.Hyperion; import me.moros.hyperion.util.BendingFallingBlock; import org.bukkit.ChatColor; +import org.bukkit.Color; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.Material; @@ -38,6 +40,7 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.inventory.meta.LeatherArmorMeta; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import org.bukkit.util.NumberConversions; @@ -126,10 +129,11 @@ public void progress() { } } - private void formArmor() { + private void formArmor(Material material) { if (formed) return; final ItemStack head, chest, leggings, boots; + Color color = Color.fromRGB(EarthArmor.getColor(material)); if (metal) { if (gold) { head = new ItemStack(Material.GOLDEN_HELMET, 1); @@ -156,6 +160,9 @@ private void formArmor() { for (ItemStack item : newArmor) { ItemMeta generalMeta = item.getItemMeta(); + if (generalMeta instanceof LeatherArmorMeta) { + ((LeatherArmorMeta) generalMeta).setColor(color); + } generalMeta.setDisplayName(ChatColor.GREEN + "Earth Guard Armor"); generalMeta.setLore(Collections.singletonList(ChatColor.DARK_GREEN + "Temporary")); item.setItemMeta(generalMeta); @@ -189,8 +196,9 @@ private void moveBlock() { final double distanceSquared = player.getEyeLocation().distanceSquared(loc); final double speedFactor = (distanceSquared > selectRange * selectRange) ? 1.5 : 0.8; if (distanceSquared <= 0.5 * 0.5) { + Material mat = armorFallingBlock.getFallingBlock().getBlockData().getMaterial(); armorFallingBlock.remove(); - formArmor(); + formArmor(mat); return; } diff --git a/src/main/java/me/moros/hyperion/abilities/earthbending/EarthShot.java b/src/main/java/me/moros/hyperion/abilities/earthbending/EarthShot.java index 8e1b635..5f06ea7 100755 --- a/src/main/java/me/moros/hyperion/abilities/earthbending/EarthShot.java +++ b/src/main/java/me/moros/hyperion/abilities/earthbending/EarthShot.java @@ -70,6 +70,7 @@ public class EarthShot extends EarthAbility implements AddonAbility { private boolean ready; private boolean launched; private boolean convertedMagma; + private boolean allowQuickLaunch; private long magmaStartTime; public EarthShot(Player player) { @@ -83,6 +84,7 @@ public EarthShot(Player player) { cooldown = Hyperion.getPlugin().getConfig().getLong("Abilities.Earth.EarthShot.Cooldown"); range = Hyperion.getPlugin().getConfig().getInt("Abilities.Earth.EarthShot.Range"); selectRange = Hyperion.getPlugin().getConfig().getInt("Abilities.Earth.EarthShot.SelectRange"); + allowQuickLaunch = Hyperion.getPlugin().getConfig().getBoolean("Abilities.Earth.EarthShot.AllowQuickLaunch"); magmaShot = Hyperion.getPlugin().getConfig().getBoolean("Abilities.Earth.EarthShot.MagmaShot.AllowConvert"); magmaModifier = Hyperion.getPlugin().getConfig().getDouble("Abilities.Earth.EarthShot.MagmaShot.DamageModifier"); chargeTime = Hyperion.getPlugin().getConfig().getLong("Abilities.Earth.EarthShot.MagmaShot.ChargeTime"); @@ -312,11 +314,11 @@ public void remove() { if (projectile.getFallingBlock() != null) { if (launched) { final Location tempLocation = projectile.getFallingBlock().getLocation().clone(); - ParticleEffect.BLOCK_CRACK.display(tempLocation, 6, ThreadLocalRandom.current().nextDouble(), ThreadLocalRandom.current().nextDouble(), ThreadLocalRandom.current().nextDouble(), 0, projectile.getFallingBlock().getBlockData()); - ParticleEffect.BLOCK_DUST.display(tempLocation, 4, ThreadLocalRandom.current().nextDouble(), ThreadLocalRandom.current().nextDouble(), ThreadLocalRandom.current().nextDouble(), 0, projectile.getFallingBlock().getBlockData()); + ParticleEffect.BLOCK_CRACK.display(tempLocation, 6, 1, 1, 1, 0, projectile.getFallingBlock().getBlockData()); + ParticleEffect.BLOCK_DUST.display(tempLocation, 4, 1, 1, 1, 0, projectile.getFallingBlock().getBlockData()); if (convertedMagma) { - ParticleEffect.SMOKE_LARGE.display(tempLocation, 16, ThreadLocalRandom.current().nextDouble(), ThreadLocalRandom.current().nextDouble(), ThreadLocalRandom.current().nextDouble(), 0.05); - ParticleEffect.FIREWORKS_SPARK.display(tempLocation, 8, ThreadLocalRandom.current().nextDouble(), ThreadLocalRandom.current().nextDouble(), ThreadLocalRandom.current().nextDouble(), 0.05); + ParticleEffect.SMOKE_LARGE.display(tempLocation, 16, 1, 1, 1, 0.05); + ParticleEffect.FIREWORKS_SPARK.display(tempLocation, 8,1, 1, 1, 0.05); tempLocation.getWorld().playSound(tempLocation, Sound.ENTITY_GENERIC_EXPLODE, 1.5f, 0); } else { if (isMetal(projectile.getFallingBlock().getBlockData().getMaterial())) { @@ -343,24 +345,37 @@ public static void throwProjectile(Player player) { } public void throwProjectile() { - if (launched || !ready) { + if (launched) { return; } - - Vector direction = GeneralMethods.getDirection(readySource.getLocation(), GeneralMethods.getTargetedLocation(player, range, readySource.getBlock().getType())).normalize(); - projectile = new BendingFallingBlock(readySource.getLocation().add(0.5, 0, 0.5), readySource.getBlock().getBlockData(), direction.multiply(1.8), this, true); - location = projectile.getFallingBlock().getLocation(); + boolean prematureLaunch = false; + if (!ready) { + if (!allowQuickLaunch) { + return; + } + prematureLaunch = true; + } + if (prematureLaunch) { + location = projectile.getFallingBlock().getLocation(); + Vector direction = GeneralMethods.getDirection(location, GeneralMethods.getTargetedLocation(player, range)).normalize(); + projectile.getFallingBlock().setGravity(true); + projectile.getFallingBlock().setVelocity(direction.multiply(1.8)); + } else { + Vector direction = GeneralMethods.getDirection(readySource.getLocation(), GeneralMethods.getTargetedLocation(player, range, readySource.getBlock().getType())).normalize(); + projectile = new BendingFallingBlock(readySource.getLocation().add(0.5, 0, 0.5), readySource.getBlock().getBlockData(), direction.multiply(1.8), this, true); + location = projectile.getFallingBlock().getLocation(); + readySource.revertBlock(); + getPreventEarthbendingBlocks().remove(readySource.getBlock()); + } lastVelocity = projectile.getFallingBlock().getVelocity().clone(); if (source != null) source.revertBlock(); - readySource.revertBlock(); - getPreventEarthbendingBlocks().remove(readySource.getBlock()); bPlayer.addCooldown(this, cooldown); launched = true; } public void playParticles(Location loc) { - ParticleEffect.LAVA.display(loc, 2, ThreadLocalRandom.current().nextDouble() / 2, ThreadLocalRandom.current().nextDouble() / 2, ThreadLocalRandom.current().nextDouble() / 2); - ParticleEffect.SMOKE_NORMAL.display(loc, 2, ThreadLocalRandom.current().nextDouble() / 2, ThreadLocalRandom.current().nextDouble() / 2, ThreadLocalRandom.current().nextDouble() / 2); + ParticleEffect.LAVA.display(loc, 2, 0.5, 0.5, 0.5); + ParticleEffect.SMOKE_NORMAL.display(loc, 2, 0.5, 0.5, 0.5); for (int i = 0; i < 8; i++) { GeneralMethods.displayColoredParticle("#FFA400", CoreMethods.getRandomOffsetLocation(loc, 1)); GeneralMethods.displayColoredParticle("#FF8C00", CoreMethods.getRandomOffsetLocation(loc, 1)); diff --git a/src/main/java/me/moros/hyperion/abilities/firebending/combo/FireWave.java b/src/main/java/me/moros/hyperion/abilities/firebending/combo/FireWave.java index dfeb997..d5bd758 100755 --- a/src/main/java/me/moros/hyperion/abilities/firebending/combo/FireWave.java +++ b/src/main/java/me/moros/hyperion/abilities/firebending/combo/FireWave.java @@ -76,6 +76,7 @@ public class FireWave extends FireAbility implements AddonAbility, ComboAbility @Attribute(Attribute.WIDTH) private int width; private int height; + private boolean requireSneaking; private int ticks = 0; @@ -86,6 +87,7 @@ public FireWave(Player player) { return; } + requireSneaking = Hyperion.getPlugin().getConfig().getBoolean("Abilities.Fire.FireCombo.FireWave.RequireSneaking"); damage = Hyperion.getPlugin().getConfig().getDouble("Abilities.Fire.FireCombo.FireWave.Damage"); cooldown = Hyperion.getPlugin().getConfig().getLong("Abilities.Fire.FireCombo.FireWave.Cooldown"); int range = Hyperion.getPlugin().getConfig().getInt("Abilities.Fire.FireCombo.FireWave.Range"); @@ -128,7 +130,12 @@ public FireWave(Player player) { @Override public void progress() { - if (!bPlayer.canBendIgnoreBindsCooldowns(this) || bPlayer.getBoundAbilityName() == null || !bPlayer.getBoundAbilityName().equalsIgnoreCase("WallOfFire") || blocks.isEmpty() || !player.isSneaking()) { + if (!bPlayer.canBendIgnoreBindsCooldowns(this) || bPlayer.getBoundAbilityName() == null || !bPlayer.getBoundAbilityName().equalsIgnoreCase("WallOfFire") || blocks.isEmpty()) { + remove(); + return; + } + + if (requireSneaking && !player.isSneaking()) { remove(); return; } diff --git a/src/main/java/me/moros/hyperion/configuration/ConfigManager.java b/src/main/java/me/moros/hyperion/configuration/ConfigManager.java index cf57ebb..ca0b2f6 100755 --- a/src/main/java/me/moros/hyperion/configuration/ConfigManager.java +++ b/src/main/java/me/moros/hyperion/configuration/ConfigManager.java @@ -91,12 +91,13 @@ public void setupMainConfig() { config.addDefault("Abilities.Earth.EarthShot.Cooldown", 1500); config.addDefault("Abilities.Earth.EarthShot.Range", 60); config.addDefault("Abilities.Earth.EarthShot.SelectRange", 6); + config.addDefault("Abilities.Earth.EarthShot.AllowQuickLaunch", false); config.addDefault("Abilities.Earth.EarthShot.MagmaShot.AllowConvert", true); config.addDefault("Abilities.Earth.EarthShot.MagmaShot.DamageModifier", 2.0); config.addDefault("Abilities.Earth.EarthShot.MagmaShot.ChargeTime", 1500); config.addDefault("Abilities.Earth.EarthGlove.Enabled", true); - config.addDefault("Abilities.Earth.EarthGlove.Description", "Dai Li agents use this technique for various purposes. Hold sneak and click to launch your glove and attempt to grab your target. If you continue holding sneak, the gloves will attempt to return to you. You can also destroy other players' gloves by tapping sneak while looking at them."); + config.addDefault("Abilities.Earth.EarthGlove.Description", "Dai Li agents use this technique for various purposes. Left click to launch your glove and attempt to grab your target. If you are holding sneak, the gloves will attempt to return to you. You can also destroy other players' gloves by tapping sneak while looking at them."); config.addDefault("Abilities.Earth.EarthGlove.Damage", 1.0); config.addDefault("Abilities.Earth.EarthGlove.Cooldown", 5000); config.addDefault("Abilities.Earth.EarthGlove.Range", 24); @@ -178,6 +179,7 @@ public void setupMainConfig() { config.addDefault("Abilities.Fire.FireCombo.FireWave.Enabled", true); config.addDefault("Abilities.Fire.FireCombo.FireWave.Description", "Master Jeong Jeong used this advanced technique to cast a great fire wave that grows in size while it advances forward."); + config.addDefault("Abilities.Fire.FireCombo.FireWave.RequireSneaking", true); config.addDefault("Abilities.Fire.FireCombo.FireWave.Damage", 3.0); config.addDefault("Abilities.Fire.FireCombo.FireWave.Cooldown", 20000); config.addDefault("Abilities.Fire.FireCombo.FireWave.Range", 16); diff --git a/src/main/java/me/moros/hyperion/listeners/AbilityListener.java b/src/main/java/me/moros/hyperion/listeners/AbilityListener.java index 2d403ca..7b493b6 100755 --- a/src/main/java/me/moros/hyperion/listeners/AbilityListener.java +++ b/src/main/java/me/moros/hyperion/listeners/AbilityListener.java @@ -141,9 +141,7 @@ public void onPlayerSwing(final PlayerInteractEvent event) { } else if (abilityName.equalsIgnoreCase("earthguard")) { new EarthGuard(player); } else if (abilityName.equalsIgnoreCase("earthglove")) { - if (player.isSneaking()) { - new EarthGlove(player); - } + new EarthGlove(player); } } else if (coreAbility instanceof FireAbility && bPlayer.isElementToggled(Element.FIRE)) { if (abilityName.equalsIgnoreCase("combustion")) { diff --git a/src/main/java/me/moros/hyperion/listeners/CoreListener.java b/src/main/java/me/moros/hyperion/listeners/CoreListener.java index 4d44314..e77f6b6 100755 --- a/src/main/java/me/moros/hyperion/listeners/CoreListener.java +++ b/src/main/java/me/moros/hyperion/listeners/CoreListener.java @@ -45,6 +45,8 @@ import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityChangeBlockEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.entity.EntityPickupItemEvent; import org.bukkit.event.entity.EntitySpawnEvent; import org.bukkit.event.entity.ItemMergeEvent; @@ -58,8 +60,7 @@ import org.bukkit.inventory.PlayerInventory; public class CoreListener implements Listener { - - @EventHandler(priority = EventPriority.HIGHEST) + @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void EntityChangeBlockEvent(final EntityChangeBlockEvent event) { if (event.getEntityType().equals(EntityType.FALLING_BLOCK)) { final FallingBlock fb = (FallingBlock) event.getEntity(); @@ -77,7 +78,7 @@ public void EntityChangeBlockEvent(final EntityChangeBlockEvent event) { } } - @EventHandler(priority = EventPriority.HIGHEST) + @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onArrowHit(final ProjectileHitEvent event) { if (event.getEntity() instanceof Arrow && event.getEntity().hasMetadata(CoreMethods.CABLE_KEY)) { final MetalCable cable = (MetalCable) event.getEntity().getMetadata(CoreMethods.CABLE_KEY).get(0).value(); @@ -104,29 +105,44 @@ public void onLightningStrike(final EntitySpawnEvent event) { } } - @EventHandler(priority = EventPriority.HIGHEST) + @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onEntityDamageByEntity(final EntityDamageByEntityEvent event) { if (event.getDamager() instanceof Arrow && event.getDamager().hasMetadata(CoreMethods.CABLE_KEY)) { event.setCancelled(true); } } - @EventHandler(priority = EventPriority.HIGHEST) + @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) + public void onEntityDamageEvent(final EntityDamageEvent event) { + if (event.getCause() != DamageCause.FIRE && event.getCause() != DamageCause.FIRE_TICK) { + return; + } + if (event.getEntity() instanceof Player) { + final Player player = (Player) event.getEntity(); + if (CoreAbility.hasAbility(player, EarthGuard.class)) { + if (CoreAbility.getAbility(player, EarthGuard.class).hasActiveArmor()) { + player.setFireTicks(0); + event.setCancelled(true); + } + } + } + } + + @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onInteractAtEntity(final PlayerInteractAtEntityEvent event) { if (event.getRightClicked().hasMetadata(CoreMethods.NO_INTERACTION_KEY)) { event.setCancelled(true); } } - @EventHandler(priority = EventPriority.HIGHEST) + @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onItemPickup(final EntityPickupItemEvent event) { if (event.getItem().hasMetadata(CoreMethods.NO_PICKUP_KEY)) { event.setCancelled(true); - event.getItem().remove(); } } - @EventHandler(priority = EventPriority.HIGHEST) + @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onHopperItemPickup(final InventoryPickupItemEvent event) { if (event.getItem().hasMetadata(CoreMethods.NO_PICKUP_KEY)) { event.setCancelled(true); @@ -134,7 +150,7 @@ public void onHopperItemPickup(final InventoryPickupItemEvent event) { } } - @EventHandler(priority = EventPriority.HIGHEST) + @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onInventoryClick(final InventoryClickEvent event) { if (event.isCancelled() || !(event.getClickedInventory() instanceof PlayerInventory) || event.getSlotType() != InventoryType.SlotType.ARMOR) { return; @@ -149,7 +165,7 @@ public void onInventoryClick(final InventoryClickEvent event) { } } - @EventHandler + @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onItemMerge(final ItemMergeEvent event) { if (event.getEntity().hasMetadata(CoreMethods.GLOVE_KEY) || event.getTarget().hasMetadata(CoreMethods.GLOVE_KEY)) { event.setCancelled(true);