Advertisement
Guest User

Untitled

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