示例#1
0
 private void stop() {
   plugin.getServer().getScheduler().cancelTask(id);
   fb.remove();
   fb.getLocation().getBlock().setTypeId(0);
   fb.setDropItem(false);
   plugin.fakeExplosion(loc, plugin.getRadius(34));
 }
  @Override
  public void cast(Entity entity) {
    // entity.getWorld().playSound(entity.getLocation(), Sound.GHAST_FIREBALL, 1F, 1F);
    entity.getWorld().playSound(entity.getLocation(), Sound.NOTE_STICKS, 1F, 0.4F);

    // TODO - find a better way to launch block without needing Player
    if (entity instanceof Player) {
      Player player = (Player) entity;

      Vector velocity = player.getEyeLocation().getDirection();
      velocity.normalize().multiply(power);

      FallingBlock fb =
          DeprecatedMethods.spawnFallingBlock(
              entity.getLocation().clone().add(0, 1, 0),
              DeprecatedMethods.getMaterialByID(blockID),
              (byte) 0);
      fb.setDropItem(false);
      fb.setVelocity(velocity);

      // make it do damage
      if (damage) {
        DynamicClassFunctions.setFallingBlockHurtEntities(fb, hurt, hurt);
      }
    }
  }
 @Override
 public void setDropItem(boolean drop) {
   f.setDropItem(drop);
 }
  @SuppressWarnings("deprecation")
  @Override
  public void rightClick(final Player player) {
    long cooldown;
    if (item.getHasPermission() == true && player.hasPermission(item.getPermission()) == false) {
    } else {
      RPGValue value = RPGValue.get(player, item, "ice.cooldown");
      if (value == null) {
        cooldown = System.currentTimeMillis() / 50;
        value = new RPGValue(player, item, "ice.cooldown", cooldown);
      } else {
        cooldown = value.asLong();
      }
      if (cooldown <= System.currentTimeMillis() / 50) {
        value.set(System.currentTimeMillis() / 50 + cooldownTime);
        player.playSound(player.getLocation(), Sound.FIZZ, 1.0f, 0.1f);
        final FallingBlock block =
            player
                .getWorld()
                .spawnFallingBlock(player.getLocation().add(0, 1.8, 0), Material.ICE, (byte) 0);
        block.setVelocity(player.getLocation().getDirection().multiply(2d));
        block.setDropItem(false);
        BukkitRunnable run =
            new BukkitRunnable() {

              public void run() {
                boolean hit = false;
                World world = block.getWorld();
                Location bLoc = block.getLocation();
                loop:
                for (int x = -1; x < 2; x++) {
                  for (int y = -1; y < 2; y++) {
                    for (int z = -1; z < 2; z++) {
                      Location loc = block.getLocation().add(x, y, z);
                      if (world.getBlockAt(loc).getType() != Material.AIR) {
                        Block b = world.getBlockAt(loc);
                        if (b.getType().isSolid()) {
                          if (checkBlock(
                              loc.getBlockX(),
                              loc.getBlockY(),
                              loc.getBlockZ(),
                              1,
                              1,
                              1,
                              bLoc.getX() - 0.5d,
                              bLoc.getY() - 0.5d,
                              bLoc.getZ() - 0.5d,
                              1,
                              1,
                              1)) {
                            hit = true;
                            break loop;
                          }
                        }
                      }
                    }
                  }
                }
                if (!hit) {
                  List<Entity> entities = block.getNearbyEntities(1, 1, 1);
                  for (Entity e : entities) {
                    if (e != player) {
                      hit = true;
                      break;
                    }
                  }
                }
                if (block.isDead() || hit) {
                  block.remove();
                  if (!block.getLocation().getBlock().getType().isSolid()
                      && !block.getLocation().getBlock().getType().toString().contains("SIGN"))
                    block.getLocation().getBlock().setType(Material.AIR);
                  cancel();
                  final TObjectLongHashMap<Location> changedBlocks =
                      new gnu.trove.map.hash.TObjectLongHashMap<Location>();
                  for (int x = -1; x < 2; x++) {
                    for (int y = -1; y < 3; y++) {
                      for (int z = -1; z < 2; z++) {
                        Location loc = block.getLocation().add(x, y, z);
                        Block b = world.getBlockAt(loc);
                        if (!b.getType().isSolid() && !b.getType().toString().contains("SIGN")) {
                          changedBlocks.put(b.getLocation(), b.getTypeId() | (b.getData() << 16));
                          b.setType(Material.ICE);
                        }
                      }
                    }
                  }
                  (new BukkitRunnable() {
                        Random random = new Random();

                        @Override
                        public void run() {
                          for (int i = 0; i < 4; i++) {
                            if (changedBlocks.isEmpty()) {
                              cancel();
                              return;
                            }
                            int index = random.nextInt(changedBlocks.size());
                            long data = changedBlocks.values()[index];
                            Location position = (Location) changedBlocks.keys()[index];
                            changedBlocks.remove(position);
                            Block c = position.getBlock();
                            position
                                .getWorld()
                                .playEffect(position, Effect.STEP_SOUND, c.getTypeId());
                            c.setTypeId((int) (data & 0xFFFF));
                            c.setData((byte) (data >> 16));
                          }
                        }
                      })
                      .runTaskTimer(Plugin.plugin, 4 * 20 + new Random().nextInt(40), 3);
                }
              }
            };
        run.runTaskTimer(Plugin.plugin, 0, 1);

      } else {
        player.sendMessage(
            ChatColor.AQUA
                + String.format(
                    Locale.get("message.cooldown"),
                    ((double) (cooldown - System.currentTimeMillis() / 50)) / 20d));
      }
    }
  }