mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-25 06:36:45 +01:00
Implemented slow/speed effects for Stick alt-fire.
This commit is contained in:
parent
4965cb2b68
commit
2bf1563b20
@ -5,6 +5,7 @@ import org.bukkit.entity.Entity;
|
|||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.entity.Projectile;
|
||||||
import org.bukkit.entity.TNTPrimed;
|
import org.bukkit.entity.TNTPrimed;
|
||||||
import org.bukkit.entity.Wolf;
|
import org.bukkit.entity.Wolf;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
@ -39,6 +40,7 @@ import com.gmail.nossr50.skills.Acrobatics;
|
|||||||
import com.gmail.nossr50.skills.Archery;
|
import com.gmail.nossr50.skills.Archery;
|
||||||
import com.gmail.nossr50.skills.BlastMining;
|
import com.gmail.nossr50.skills.BlastMining;
|
||||||
import com.gmail.nossr50.skills.Skills;
|
import com.gmail.nossr50.skills.Skills;
|
||||||
|
import com.gmail.nossr50.skills.Staves;
|
||||||
import com.gmail.nossr50.skills.Taming;
|
import com.gmail.nossr50.skills.Taming;
|
||||||
|
|
||||||
public class mcEntityListener implements Listener {
|
public class mcEntityListener implements Listener {
|
||||||
@ -80,6 +82,28 @@ public class mcEntityListener implements Listener {
|
|||||||
if (!m.isInvincible(livingDefender, event)) {
|
if (!m.isInvincible(livingDefender, event)) {
|
||||||
Combat.combatChecks(event, plugin);
|
Combat.combatChecks(event, plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (attacker.hasMetadata("mcmmoFiredFromStaff")) {
|
||||||
|
event.setDamage(0);
|
||||||
|
|
||||||
|
Projectile projectile = (Projectile) attacker;
|
||||||
|
Player shooter = (Player) projectile.getShooter();
|
||||||
|
|
||||||
|
switch (attacker.getType()) {
|
||||||
|
case EGG:
|
||||||
|
Staves.eggEffect(livingDefender, shooter);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FIREBALL:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SNOWBALL:
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,17 +1,24 @@
|
|||||||
package com.gmail.nossr50.skills;
|
package com.gmail.nossr50.skills;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Egg;
|
import org.bukkit.entity.Egg;
|
||||||
import org.bukkit.entity.Fireball;
|
import org.bukkit.entity.Fireball;
|
||||||
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.Projectile;
|
import org.bukkit.entity.Projectile;
|
||||||
import org.bukkit.entity.Snowball;
|
import org.bukkit.entity.Snowball;
|
||||||
import org.bukkit.metadata.FixedMetadataValue;
|
import org.bukkit.metadata.FixedMetadataValue;
|
||||||
|
import org.bukkit.potion.PotionEffect;
|
||||||
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
|
||||||
import com.gmail.nossr50.mcMMO;
|
import com.gmail.nossr50.mcMMO;
|
||||||
|
import com.gmail.nossr50.party.Party;
|
||||||
|
|
||||||
public class Staves {
|
public class Staves {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fire a projectile on alt-fire from a staff.
|
* Fire a projectile on alt-fire from a staff.
|
||||||
*
|
*
|
||||||
@ -41,4 +48,62 @@ public class Staves {
|
|||||||
|
|
||||||
projectile.setMetadata("mcmmoFiredFromStaff", new FixedMetadataValue(plugin, true));
|
projectile.setMetadata("mcmmoFiredFromStaff", new FixedMetadataValue(plugin, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle the effects of the Stick's projectile.
|
||||||
|
*
|
||||||
|
* @param target Entity hit by the projectile
|
||||||
|
* @param shooter Player who fired the projectile
|
||||||
|
*/
|
||||||
|
public static void eggEffect(LivingEntity target, Player shooter) {
|
||||||
|
final int TICKS_PER_SECOND = 20;
|
||||||
|
final int MAX_SLOW_DURATION_SECONDS = 240;
|
||||||
|
final int MAX_SPEED_DURATION_SECONDS = 800;
|
||||||
|
|
||||||
|
Collection<PotionEffect> potionEffects = target.getActivePotionEffects();
|
||||||
|
|
||||||
|
int duration = durationCalulate();
|
||||||
|
int amplifier = amplifierCalulate();
|
||||||
|
PotionEffectType type;
|
||||||
|
|
||||||
|
if (target instanceof Player && Party.getInstance().inSameParty((Player) target, shooter)) {
|
||||||
|
type = PotionEffectType.SPEED;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
type = PotionEffectType.SLOW;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (PotionEffect effect : potionEffects) {
|
||||||
|
if (effect.getType().equals(type)) {
|
||||||
|
duration = duration + effect.getDuration();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type.equals(PotionEffectType.SLOW) && duration > (TICKS_PER_SECOND * MAX_SLOW_DURATION_SECONDS)) {
|
||||||
|
duration = (TICKS_PER_SECOND * MAX_SLOW_DURATION_SECONDS);
|
||||||
|
}
|
||||||
|
else if (type.equals(PotionEffectType.SPEED) && duration > (TICKS_PER_SECOND * MAX_SPEED_DURATION_SECONDS)) {
|
||||||
|
duration = (TICKS_PER_SECOND * MAX_SPEED_DURATION_SECONDS);
|
||||||
|
}
|
||||||
|
|
||||||
|
target.addPotionEffect(new PotionEffect(type, duration, amplifier));
|
||||||
|
|
||||||
|
if (type.equals(PotionEffectType.SLOW)) {
|
||||||
|
shooter.sendMessage("Your enemy was slowed!"); //TODO: Use mcLocale
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
shooter.sendMessage("Your ally's speed was boosted!"); //TODO: Use mcLocale
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int durationCalulate() {
|
||||||
|
//TODO: Calculate duration based off time held
|
||||||
|
return 80;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int amplifierCalulate() {
|
||||||
|
//TODO: Calculate amplifier based off skill level
|
||||||
|
return 10;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user