This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Sep 27th, 2011  |  syntax: Java  |  size: 5.63 KB  |  views: 216  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. package com.herocraftonline.dev.heroes.skill.skills;
  2.  
  3. import net.minecraft.server.EntityPlayer;
  4. import net.minecraft.server.MobEffect;
  5. import net.minecraft.server.Packet41MobEffect;
  6. import net.minecraft.server.Packet42RemoveMobEffect;
  7.  
  8. import org.bukkit.craftbukkit.entity.CraftPlayer;
  9. import org.bukkit.entity.Player;
  10. import org.bukkit.entity.Projectile;
  11. import org.bukkit.event.Event.Priority;
  12. import org.bukkit.event.Event.Type;
  13. import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
  14. import org.bukkit.util.config.ConfigurationNode;
  15.  
  16. import com.herocraftonline.dev.heroes.Heroes;
  17. import com.herocraftonline.dev.heroes.api.HeroesEventListener;
  18. import com.herocraftonline.dev.heroes.api.WeaponDamageEvent;
  19. import com.herocraftonline.dev.heroes.effects.EffectType;
  20. import com.herocraftonline.dev.heroes.effects.PeriodicEffect;
  21. import com.herocraftonline.dev.heroes.hero.Hero;
  22. import com.herocraftonline.dev.heroes.skill.PassiveSkill;
  23. import com.herocraftonline.dev.heroes.skill.Skill;
  24. import com.herocraftonline.dev.heroes.skill.SkillType;
  25. import com.herocraftonline.dev.heroes.util.Setting;
  26.  
  27. public class SkillFrenzy extends PassiveSkill {
  28.        
  29.     private String applyText = null;
  30.     private String unapplyText = null;
  31.    
  32.         public SkillFrenzy(Heroes plugin) {
  33.         super(plugin, "Frenzy");
  34.         setDescription("Makes you move faster, deal more damage at lower health");
  35.         setTypes(SkillType.COUNTER, SkillType.MOVEMENT, SkillType.BUFF, SkillType.HARMFUL);
  36.        
  37.        
  38.         registerEvent(Type.CUSTOM_EVENT, new SkillHeroListener(), Priority.Normal);
  39.     }
  40.  
  41.     @Override
  42.     public ConfigurationNode getDefaultConfig() {
  43.         ConfigurationNode node = super.getDefaultConfig();
  44.         node.setProperty("max-damage-modifier", 2);
  45.         node.setProperty("use-speed-modifier", "true");
  46.         node.setProperty(Setting.APPLY_TEXT.node(), "%hero% went into a %skill%!");
  47.         node.setProperty(Setting.UNAPPLY_TEXT.node(), "%hero% came out of a %skill%!");
  48.         return node;
  49.     }
  50.     @Override
  51.     public void init() {
  52.         applyText = getSetting(null, Setting.APPLY_TEXT.node(), "%hero% gained %skill%!");
  53.         applyText = applyText.replace("%hero%", "$1").replace("%skill%", "$2");
  54.         unapplyText = getSetting(null, Setting.UNAPPLY_TEXT.node(), "%hero% lost %skill%!");
  55.         unapplyText = unapplyText.replace("%hero%", "$1").replace("%skill%", "$2");
  56.     }
  57.     @Override
  58.     protected void apply(Hero hero){
  59.         FrenzyEffect effect = new FrenzyEffect(this,getName());
  60.         effect.setPersistent(true);
  61.         hero.addEffect(effect);
  62.         Player player = hero.getPlayer();
  63.         broadcast(player.getLocation(), applyText, player.getDisplayName(), getName());
  64.     }
  65.    
  66.     @Override
  67.     protected void unapply(Hero hero) {
  68.         if (hero.hasEffect(getName())) {
  69.             hero.removeEffect(hero.getEffect(getName()));
  70.             Player player = hero.getPlayer();
  71.             broadcast(player.getLocation(), unapplyText, player.getDisplayName(), getName());
  72.         }
  73.     }
  74.     public class FrenzyEffect extends PeriodicEffect {
  75.  
  76.         private MobEffect mobEffect = new MobEffect(1, 0, 0);
  77.  
  78.         public FrenzyEffect(Skill skill, String name) {
  79.             super(skill, name, 2000);
  80.             this.types.add(EffectType.BENEFICIAL);
  81.         }
  82.  
  83.         @Override
  84.         public void tick(Hero hero) {
  85.             super.tick(hero);
  86.  
  87.             if (hero.getHealth()/hero.getMaxHealth() <= .5) {
  88.                 this.mobEffect = new MobEffect(1, 40, 2);
  89.                 Player player = hero.getPlayer();
  90.                 EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle();
  91.                 entityPlayer.netServerHandler.sendPacket(new Packet42RemoveMobEffect(entityPlayer.id, this.mobEffect));
  92.                 entityPlayer.netServerHandler.sendPacket(new Packet41MobEffect(entityPlayer.id, this.mobEffect));
  93.             }
  94.         }
  95.  
  96.         @Override
  97.         public void remove(Hero hero) {
  98.             Player player = hero.getPlayer();
  99.             EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle();
  100.             entityPlayer.netServerHandler.sendPacket(new Packet42RemoveMobEffect(entityPlayer.id, this.mobEffect));
  101.         }
  102.  
  103.     }
  104.    
  105.     public class SkillHeroListener extends HeroesEventListener {
  106.  
  107.         @Override
  108.         public void onWeaponDamage(WeaponDamageEvent event) {
  109.             if (event.getCause() != DamageCause.ENTITY_ATTACK)
  110.                 return;
  111.  
  112.             if (event.getDamager() instanceof Player) {
  113.                 Player player = (Player) event.getDamager();
  114.                 Hero hero = plugin.getHeroManager().getHero(player);
  115.  
  116.                 if (hero.hasSkill("Frenzy")) {
  117.                     double damageBonus = (double) getSetting(hero.getHeroClass(), "max-damage-modifier", 2) * hero.getMaxHealth() / hero.getHealth();
  118.                     event.setDamage((int) (event.getDamage() * damageBonus));
  119.                 }
  120.             } else if (event.getDamager() instanceof Projectile) {
  121.                 if (((Projectile) event.getDamager()).getShooter() instanceof Player) {
  122.                     Player player = (Player) ((Projectile) event.getDamager()).getShooter();
  123.                     Hero hero = plugin.getHeroManager().getHero(player);
  124.  
  125.                     if (hero.hasSkill("Frenzy")) {
  126.                         double damageBonus = (double) getSetting(hero.getHeroClass(), "max-damage-modifier", 2) * hero.getMaxHealth() / hero.getHealth();
  127.                         event.setDamage((int) (event.getDamage() * damageBonus));
  128.                     }
  129.                 }
  130.             }
  131.         }
  132.     }
  133.  
  134. }
  135.  
  136.  
clone this paste RAW Paste Data