Advertisement
Guest User

Gravity

a guest
Mar 6th, 2015
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.84 KB | None | 0 0
  1.     @EventHandler
  2.     public void onProjectileHit(ProjectileHitEvent e) {
  3.  
  4.         Projectile p = e.getEntity();
  5.         ProjectileSource ps = p.getShooter();
  6.  
  7.         if (p instanceof Snowball && ps instanceof Player) {
  8.  
  9.             final Player player = (Player) ps;
  10.             if (player.getItemInHand().equals(Items.getGravity())) {
  11.                 final Location loc = p.getLocation();
  12.                 loc.setY(loc.getY() - 1);
  13.  
  14.                 if (Main.getInstance().getWorldGuard() != null) {
  15.  
  16.                     if (!Main.getInstance().getWorldGuard()
  17.                             .canBuild(player, loc.getBlock())) {
  18.  
  19.                         return;
  20.  
  21.                     }
  22.                    
  23.                 }
  24.  
  25.                 int radius = 10;
  26.  
  27.                 final ArrayList<Block> blocks = getBlocksAroundPoint(loc,
  28.                         radius);
  29.  
  30.                 final ArrayList<Entity> entities = new ArrayList<Entity>();
  31.  
  32.                 for (Entity ee : loc.getWorld().getEntities()) {
  33.  
  34.                     if (ee.getLocation().distance(loc) <= radius) {
  35.  
  36.                         entities.add(ee);
  37.  
  38.                     }
  39.  
  40.                 }
  41.  
  42.                 int c = 0;
  43.  
  44.                 for (Block b : blocks) {
  45.  
  46.                     fly.add(b.getState());
  47.  
  48.                 }
  49.  
  50.                 for (final Block b : blocks) {
  51.  
  52.                     c++;
  53.                     new BukkitRunnable() {
  54.                         @Override
  55.                         public void run() {
  56.  
  57.                             final FallingBlock fb = b.getWorld()
  58.                                     .spawnFallingBlock(b.getLocation(),
  59.                                             b.getType(), b.getData());
  60.                             fb.setMetadata("Restore", new FixedMetadataValue(
  61.                                     Main.getInstance(), b.getState()));
  62.  
  63.                             b.setType(Material.AIR);
  64.                             fb.setDropItem(false);
  65.                             double y = 3;
  66.                             fb.setVelocity(new Vector(0, y, 0));
  67.                             falling.add(fb);
  68.  
  69.                             for (Entity ee : entities) {
  70.  
  71.                                 if (ee.getLocation().distance(b.getLocation()) <= 3
  72.                                         && ee instanceof LivingEntity) {
  73.  
  74.                                     LivingEntity le = (LivingEntity) ee;
  75.  
  76.                                     le.setVelocity(new Vector(0, y, 0));
  77.                                     le.addPotionEffect(new PotionEffect(
  78.                                             PotionEffectType.DAMAGE_RESISTANCE,
  79.                                             110, 30));
  80.  
  81.                                 }
  82.  
  83.                             }
  84.  
  85.                         }
  86.  
  87.                     }.runTaskLater(Main.getInstance(), c / 100);
  88.  
  89.                 }
  90.  
  91.  
  92.                 new BukkitRunnable() {
  93.                     @Override
  94.                     public void run() {
  95.  
  96.                         for (Entity ee : entities) {
  97.  
  98.                             if (ee.getLocation().distance(loc) <= 3
  99.                                     && ee instanceof LivingEntity) {
  100.  
  101.                                 LivingEntity le = (LivingEntity) ee;
  102.                                 Material m = le.getLocation().getBlock()
  103.                                         .getType();
  104.                                 if (m == Material.AIR || m == Material.WATER) {
  105.  
  106.                                 } else {
  107.  
  108.                                     le.teleport(le
  109.                                             .getWorld()
  110.                                             .getHighestBlockAt(le.getLocation())
  111.                                             .getLocation());
  112.  
  113.                                 }
  114.  
  115.                             }
  116.  
  117.                         }
  118.  
  119.                     }
  120.  
  121.                 }.runTaskLater(Main.getInstance(), c);
  122.  
  123.             }
  124.  
  125.         }
  126.  
  127.     }
  128.  
  129.     @EventHandler
  130.     public void onEntityChangeBlock(EntityChangeBlockEvent e) {
  131.  
  132.         if (!e.getEntity().hasMetadata("Restore")) {
  133.  
  134.             return;
  135.  
  136.         }
  137.  
  138.         BlockState b = (BlockState) e.getEntity().getMetadata("Restore").get(0)
  139.                 .value();
  140.         e.setCancelled(true);
  141.         b.update(true, false);
  142.  
  143.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement