Advertisement
Guest User

Untitled

a guest
Jan 5th, 2014
654
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.         /*
  2.         You can put this code where ever you want. Most likely you want it in the PlayerInteractEvent
  3.         */
  4.  
  5.     Location location = player.getEyeLocation();
  6.         BlockIterator blocksToAdd = new BlockIterator(location, 0D, 15);
  7.         Location blockToAdd;
  8.         while(blocksToAdd.hasNext()) {
  9.                 if (blockToAdd.getBlock().getType() != Material.AIR ||!shotprojectiledata.containsKey(projectile)) {
  10.                     break;
  11.         }
  12.                 blockToAdd = blocksToAdd.next().getLocation();
  13.             player.getWorld().playEffect(blockToAdd, Effect.STEP_SOUND, Material.FIRE);
  14.         }
  15.         Snowball projectile = player.launchProjectile(Snowball.class);
  16.     EntityData data = new EntityData(projectile.getLocation(), 15, 5D);
  17.         shotprojectiledata.put(projectile, data);
  18.         for (Player p : Bukkit.getOnlinePlayers()) {
  19.             ((CraftPlayer)p).getHandle().playerConnection.sendPacket(new  PacketPlayOutEntityDestroy(((CraftSnowball) projectile).getHandle().getId()));
  20.                     }
  21.  
  22.     //put this in whatever class you want or in it's own class
  23.     public class EntityData {
  24.         private Location firedfrom;
  25.         private Integer range;
  26.         private Double damage;
  27.          public EntityData(Location loc, Integer range, Double damage) {
  28.             this.firedfrom = loc;
  29.             this.range = range;
  30.             this.damage = damage;
  31.         }
  32.         public Location getFiredFrom() {
  33.             return firedfrom;
  34.         }
  35.         public Integer getRange() {
  36.             return range;
  37.         }
  38.         public Double getDamage() {
  39.             return damage;
  40.         }
  41.     }
  42.  
  43.     //put where ever you want again
  44.     public final static HashMap<Entity, EntityData> shotprojectiledata = new HashMap<Entity, EntityData>();
  45.  
  46.  
  47.     @EventHandler
  48.     public void onHit(EntityDamageByEntityEvent event) {
  49.         if (event.getDamager() instanceof Snowball) {
  50.             if (shotprojectiledata.containsKey(event.getDamager())) {
  51.                 EntityData eventdata = shotprojectiledata.get(event.getDamager());
  52.                 if (event.getEntity().getLocation().distance(eventdata.getFiredFrom())<=eventdata.getRange()) {
  53.                     event.setDamage(eventdata.getDamage());
  54.                     shotprojectiledata.remove(event.getDamager());
  55.                 }
  56.             }
  57.         }
  58.     }
Advertisement
RAW Paste Data Copied
Advertisement