Advertisement
Guest User

Untitled

a guest
Jul 7th, 2014
384
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.03 KB | None | 0 0
  1. package com.herocraftonline.heroes.characters.skill.skills;
  2.  
  3.  
  4. import org.bukkit.Bukkit;
  5. import org.bukkit.ChatColor;
  6. import org.bukkit.Location;
  7. import org.bukkit.Material;
  8. import org.bukkit.block.Block;
  9. import org.bukkit.configuration.ConfigurationSection;
  10. import org.bukkit.entity.Entity;
  11. import org.bukkit.entity.FallingBlock;
  12. import org.bukkit.entity.LivingEntity;
  13. import org.bukkit.entity.Player;
  14. import org.bukkit.event.EventHandler;
  15. import org.bukkit.event.Listener;
  16. import org.bukkit.event.entity.EntityChangeBlockEvent;
  17. import org.bukkit.event.entity.EntityDamageEvent;
  18. import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
  19. import org.bukkit.metadata.FixedMetadataValue;
  20. import org.bukkit.scheduler.BukkitRunnable;
  21. import org.bukkit.scheduler.BukkitTask;
  22. import org.bukkit.util.Vector;
  23.  
  24.  
  25.  
  26.  
  27. import com.herocraftonline.heroes.Heroes;
  28. import com.herocraftonline.heroes.api.SkillResult;
  29. import com.herocraftonline.heroes.characters.Hero;
  30. import com.herocraftonline.heroes.characters.skill.ActiveSkill;
  31. import com.herocraftonline.heroes.characters.skill.SkillConfigManager;
  32. import com.herocraftonline.heroes.characters.skill.SkillSetting;
  33. import com.herocraftonline.heroes.characters.skill.SkillType;
  34.  
  35. public class SkillEarthToss
  36. extends ActiveSkill
  37. implements Listener
  38. {
  39.  
  40.  
  41.         public SkillEarthToss(Heroes plugin)
  42.         {
  43.  
  44.                 super(plugin, "EarthToss");
  45.                 setDescription("Throw the earth under you");
  46.                 setUsage("/skill earthtoss");
  47.                 setArgumentRange(0, 0);
  48.                 setIdentifiers(new String[] { "skill earthtoss" });
  49.                 Bukkit.getPluginManager().registerEvents(this, plugin);
  50.                 setTypes(new SkillType[] { SkillType.PHYSICAL, SkillType.HARMFUL,SkillType.SILENCABLE });
  51.  
  52.         }
  53.  
  54.         public String getDescription(Hero hero)
  55.         {
  56.                 String description = getDescription();
  57.  
  58.                 int cooldown = (SkillConfigManager.getUseSetting(hero, this, SkillSetting.COOLDOWN.node(), 0, false) - SkillConfigManager.getUseSetting(hero, this, SkillSetting.COOLDOWN_REDUCE.node(), 0, false) * hero.getSkillLevel(this)) / 1000;
  59.                 if (cooldown > 0) {
  60.                         description = description + " CD:" + cooldown + "s";
  61.                 }
  62.                 int mana = SkillConfigManager.getUseSetting(hero, this, SkillSetting.MANA.node(), 10, false) - SkillConfigManager.getUseSetting(hero, this, SkillSetting.MANA_REDUCE.node(), 0, false) * hero.getSkillLevel(this);
  63.                 if (mana > 0) {
  64.                         description = description + " M:" + mana;
  65.                 }
  66.                 int healthCost = SkillConfigManager.getUseSetting(hero, this, SkillSetting.HEALTH_COST, 0, false) - SkillConfigManager.getUseSetting(hero, this, SkillSetting.HEALTH_COST_REDUCE, mana, true) * hero.getSkillLevel(this);
  67.                 if (healthCost > 0) {
  68.                         description = description + " HP:" + healthCost;
  69.                 }
  70.                 int staminaCost = SkillConfigManager.getUseSetting(hero, this, SkillSetting.STAMINA.node(), 0, false) - SkillConfigManager.getUseSetting(hero, this, SkillSetting.STAMINA_REDUCE.node(), 0, false) * hero.getSkillLevel(this);
  71.                 if (staminaCost > 0) {
  72.                         description = description + " FP:" + staminaCost;
  73.                 }
  74.                 int delay = SkillConfigManager.getUseSetting(hero, this, SkillSetting.DELAY.node(), 0, false) / 1000;
  75.                 if (delay > 0) {
  76.                         description = description + " W:" + delay + "s";
  77.                 }
  78.                 int exp = SkillConfigManager.getUseSetting(hero, this, SkillSetting.EXP.node(), 0, false);
  79.                 if (exp > 0) {
  80.                         description = description + " XP:" + exp;
  81.                 }
  82.                 return description;
  83.         }
  84.  
  85.         public ConfigurationSection getDefaultConfig()
  86.         {
  87.                 ConfigurationSection node = super.getDefaultConfig();
  88.                 return node;
  89.         }
  90.  
  91.         public void init()
  92.         {
  93.                 super.init();
  94.         }
  95.        
  96.    
  97.         public SkillResult use(Hero hero, String[] args)
  98.     {
  99.             final double damage = 50000.0;
  100.             final DamageCause cause = EntityDamageEvent.DamageCause.MAGIC;
  101.             final Player p = hero.getPlayer();
  102.             Vector animation = new Vector(0,.7,0);
  103.             Location starter = p.getLocation().add(new Vector(p.getEyeLocation().getDirection().getX()*2, -1, p.getEyeLocation().getDirection().getZ()*2));
  104.             Block bottom = (Block) starter.getBlock();
  105.            
  106.            
  107.            
  108.             final Vector direction = p.getEyeLocation().getDirection().multiply(1.5);
  109.              @SuppressWarnings("deprecation")
  110.             final FallingBlock proj =  p.getWorld().spawnFallingBlock(starter,bottom.getType(), (byte) bottom.getData());
  111.              proj.setMetadata("RemoveBlock", new FixedMetadataValue(plugin, true));
  112.              if(proj.getMaterial() == (Material.AIR))
  113.              {
  114.                
  115.                  return SkillResult.FAIL;
  116.          }else{
  117.             proj.setDropItem(false);
  118.             proj.setVelocity(animation);
  119.             Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
  120.                 public void run() {
  121.                    proj.setVelocity(direction);
  122.                 } },5L);
  123.             new Damager(proj, p, damage, cause).runTaskTimer(plugin, 1, 1);
  124.            
  125.                        
  126.            
  127.                        
  128.             broadcastExecuteText(hero);
  129.             return SkillResult.NORMAL;
  130.             }
  131.              
  132.            
  133.     }
  134.  
  135.       @EventHandler
  136.     public void onLand(EntityChangeBlockEvent e)
  137.     {
  138.         if(e.getEntity().hasMetadata("RemoveBlock"))
  139.         {
  140.             e.setCancelled(true);
  141.             e.getEntity().remove();
  142.             e.getBlock().setType(Material.AIR);
  143.        
  144.         }
  145.     }
  146.         public class Damager extends BukkitRunnable{
  147.         private FallingBlock proj;
  148.         private Player p;
  149.         private double damage;
  150.         private DamageCause cause;
  151.         public Damager(FallingBlock projectile, Player player, double damage, DamageCause cause)
  152.         {
  153.                 this.proj = projectile;
  154.                 this.p = player;
  155.                 this.damage = damage;
  156.                 this.cause = cause;
  157.  
  158.         }
  159.         public void run() {
  160.                   for(Entity e : proj.getNearbyEntities(0, 2, 0))
  161.           {
  162.  
  163.                   if(e != p && e instanceof LivingEntity)
  164.                   {
  165.                         if(damageCheck(p, (LivingEntity) e))
  166.                           damageEntity((LivingEntity) e, p, damage, cause);
  167.                           this.cancel();
  168.                          
  169.                  
  170.                   }
  171.                   if(e!=p && e instanceof LivingEntity)
  172.                   proj.remove();
  173.                   this.cancel();
  174.                  
  175.           }
  176.          
  177.           }
  178.        
  179. }
  180.  
  181. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement