Skip to content

Commit

Permalink
Improve earthguard, earthshot, earthglove and firewave
Browse files Browse the repository at this point in the history
  • Loading branch information
PrimordialMoros committed Nov 19, 2020
1 parent 8ac52a6 commit e1bcf54
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 40 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group = "me.moros"
version = "1.6.1"
version = "1.6.2"

configure<JavaPluginConvention> {
sourceCompatibility = JavaVersion.VERSION_1_8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public void progress() {
returning = true;
}

Vector vector = lastVelocity.clone(); // Record velocity
if (returning) {
if (!player.isSneaking()) {
shatterGlove();
Expand All @@ -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:
Expand All @@ -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));
}
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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");
Expand Down Expand Up @@ -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())) {
Expand All @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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");
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand Down
36 changes: 26 additions & 10 deletions src/main/java/me/moros/hyperion/listeners/CoreListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -104,37 +105,52 @@ 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);
event.getItem().remove();
}
}

@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;
Expand All @@ -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);
Expand Down

0 comments on commit e1bcf54

Please sign in to comment.