Beispiel #1
0
 @Override
 public void toPlayer(Player player, Location value) {
   Block block = value.getBlock();
   Block above = block.getRelative(0, 1, 0);
   while (!block.isEmpty() || !above.isEmpty()) {
     block = above;
     above = block.getRelative(0, 1, 0);
   }
   player.teleport(block.getLocation());
 }
  public void loadBeacon() {
    beaconFlagBlocks = new ArrayList<Block>();
    beaconWireframeBlocks = new ArrayList<Block>();

    if (!TownyWarConfig.isDrawingBeacon()) return;

    int beaconSize = TownyWarConfig.getBeaconSize();
    if (Coord.getCellSize() < beaconSize) return;

    Block minBlock = getBeaconMinBlock(getFlagBaseBlock().getWorld());
    if (flagBaseBlock.getY() + 4 > minBlock.getY()) return;

    int outerEdge = beaconSize - 1;
    for (int y = 0; y < beaconSize; y++) {
      for (int z = 0; z < beaconSize; z++) {
        for (int x = 0; x < beaconSize; x++) {
          Block block =
              flagBaseBlock
                  .getWorld()
                  .getBlockAt(minBlock.getX() + x, minBlock.getY() + y, minBlock.getZ() + z);
          if (block.isEmpty()) {
            int edgeCount = getEdgeCount(x, y, z, outerEdge);
            if (edgeCount == 1) {
              beaconFlagBlocks.add(block);
            } else if (edgeCount > 1) {
              beaconWireframeBlocks.add(block);
            }
          }
        }
      }
    }
  }
    // Hits a netherrack block
    public void onPlayerInteract(PlayerInteractEvent event) {
      // Do not run if cancelled
      if (event.isCancelled()) {
        return;
      }

      // Only run if netherrack ignition is enabled
      if (igniteNetherrack) {
        // Check to see if player clicked a netherrack block
        if (event.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
          if (event.getClickedBlock().getType() == Material.NETHERRACK) {
            // Ignite this block if Firetouch enabled
            Player player = event.getPlayer();
            PotionEntry buff = getPlugin().BuffList.get(player);

            if (buff != null) {
              if (buff.HasBuff.get(Name) != null && buff.HasBuff.get(Name)) {
                // Ignite block
                BlockIgniteEvent ignite =
                    new BlockIgniteEvent(
                        event.getClickedBlock(), IgniteCause.FLINT_AND_STEEL, player);
                getPlugin().getServer().getPluginManager().callEvent(ignite);
                if (!ignite.isCancelled()) {
                  Block above = event.getClickedBlock().getRelative(0, 1, 0);
                  if (above.isEmpty()) {
                    above.setType(Material.FIRE);
                  }
                }
              }
            }
          }
        }
      }
    }
Beispiel #4
0
  private static void populateTreeBranch(Block block, int radius) {
    int centerX = block.getX();
    int centerZ = block.getZ();
    int centerY = block.getY();
    World w = block.getWorld();

    int radius_check = radius * radius + 1;

    for (int x = -radius; x <= radius; x++) {
      for (int z = -radius; z <= radius; z++) {
        for (int y = -radius; y <= radius; y++) {
          if (x * x + y * y + z * z <= radius_check) {
            Block b = w.getBlockAt(centerX + x, centerY + y, centerZ + z);
            if (b.isEmpty()) {
              b.setTypeIdAndData(18, (byte) 1, false);
            }
          }
        }
      }
    }
  }
  @EventHandler(priority = EventPriority.HIGH)
  public void onPlayerInteract(PlayerInteractEvent event) {
    final Player player = event.getPlayer();
    final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);

    switch (event.getAction()) {
      case RIGHT_CLICK_AIR:
      case RIGHT_CLICK_BLOCK:
        {
          switch (event.getMaterial()) {
            case WATER_BUCKET:
              {
                if (TFM_AdminList.isSuperAdmin(player)
                    || TFM_ConfigEntry.ALLOW_WATER_PLACE.getBoolean()) {
                  break;
                }

                player
                    .getInventory()
                    .setItem(
                        player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
                player.sendMessage(ChatColor.GRAY + "Water buckets are currently disabled.");
                event.setCancelled(true);
                break;
              }

            case LAVA_BUCKET:
              {
                if (TFM_AdminList.isSuperAdmin(player)
                    || TFM_ConfigEntry.ALLOW_LAVA_PLACE.getBoolean()) {
                  break;
                }

                player
                    .getInventory()
                    .setItem(
                        player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
                player.sendMessage(ChatColor.GRAY + "Lava buckets are currently disabled.");
                event.setCancelled(true);
                break;
              }

            case EXPLOSIVE_MINECART:
              {
                if (TFM_ConfigEntry.ALLOW_TNT_MINECARTS.getBoolean()) {
                  break;
                }

                player.getInventory().clear(player.getInventory().getHeldItemSlot());
                player.sendMessage(ChatColor.GRAY + "TNT minecarts are currently disabled.");
                event.setCancelled(true);
                break;
              }
          }
          break;
        }

      case LEFT_CLICK_AIR:
      case LEFT_CLICK_BLOCK:
        {
          switch (event.getMaterial()) {
            case STICK:
              {
                if (!TFM_AdminList.isSuperAdmin(player)) {
                  break;
                }

                event.setCancelled(true);

                final Location location =
                    TFM_DepreciationAggregator.getTargetBlock(player, null, 5).getLocation();
                final List<RollbackEntry> entries =
                    TFM_RollbackManager.getEntriesAtLocation(location);

                if (entries.isEmpty()) {
                  TFM_Util.playerMsg(player, "No block edits at that location.");
                  break;
                }

                TFM_Util.playerMsg(
                    player,
                    "Block edits at ("
                        + ChatColor.WHITE
                        + "x"
                        + location.getBlockX()
                        + ", y"
                        + location.getBlockY()
                        + ", z"
                        + location.getBlockZ()
                        + ChatColor.BLUE
                        + ")"
                        + ChatColor.WHITE
                        + ":",
                    ChatColor.BLUE);
                for (RollbackEntry entry : entries) {
                  TFM_Util.playerMsg(
                      player,
                      " - "
                          + ChatColor.BLUE
                          + entry.author
                          + " "
                          + entry.getType()
                          + " "
                          + StringUtils.capitalize(entry.getMaterial().toString().toLowerCase())
                          + (entry.data == 0 ? "" : ":" + entry.data));
                }

                break;
              }

            case BONE:
              {
                if (!playerdata.mobThrowerEnabled()) {
                  break;
                }

                Location player_pos = player.getLocation();
                Vector direction = player_pos.getDirection().normalize();

                LivingEntity rezzed_mob =
                    (LivingEntity)
                        player
                            .getWorld()
                            .spawnEntity(
                                player_pos.add(direction.multiply(2.0)),
                                playerdata.mobThrowerCreature());
                rezzed_mob.setVelocity(direction.multiply(playerdata.mobThrowerSpeed()));
                playerdata.enqueueMob(rezzed_mob);

                event.setCancelled(true);
                break;
              }

            case SULPHUR:
              {
                if (!playerdata.isMP44Armed()) {
                  break;
                }

                event.setCancelled(true);

                if (playerdata.toggleMP44Firing()) {
                  playerdata.startArrowShooter(TotalFreedomMod.plugin);
                } else {
                  playerdata.stopArrowShooter();
                }
                break;
              }

            case BLAZE_ROD:
              {
                if (!TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean()) {
                  break;
                }

                if (!TFM_AdminList.isSeniorAdmin(player, true)) {
                  break;
                }

                event.setCancelled(true);
                Block targetBlock;

                if (event.getAction().equals(Action.LEFT_CLICK_AIR)) {
                  targetBlock = TFM_DepreciationAggregator.getTargetBlock(player, null, 120);
                } else {
                  targetBlock = event.getClickedBlock();
                }

                if (targetBlock == null) {
                  player.sendMessage("Can't resolve target block.");
                  break;
                }

                player.getWorld().createExplosion(targetBlock.getLocation(), 4F, true);
                player.getWorld().strikeLightning(targetBlock.getLocation());

                break;
              }

            case CARROT:
              {
                if (!TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean()) {
                  break;
                }

                if (!TFM_AdminList.isSeniorAdmin(player, true)) {
                  break;
                }

                Location location = player.getLocation().clone();

                Vector playerPostion = location.toVector().add(new Vector(0.0, 1.65, 0.0));
                Vector playerDirection = location.getDirection().normalize();

                double distance = 150.0;
                Block targetBlock =
                    TFM_DepreciationAggregator.getTargetBlock(
                        player, null, Math.round((float) distance));
                if (targetBlock != null) {
                  distance = location.distance(targetBlock.getLocation());
                }

                final List<Block> affected = new ArrayList<Block>();

                Block lastBlock = null;
                for (double offset = 0.0; offset <= distance; offset += (distance / 25.0)) {
                  Block block =
                      playerPostion
                          .clone()
                          .add(playerDirection.clone().multiply(offset))
                          .toLocation(player.getWorld())
                          .getBlock();

                  if (!block.equals(lastBlock)) {
                    if (block.isEmpty()) {
                      affected.add(block);
                      block.setType(Material.TNT);
                    } else {
                      break;
                    }
                  }

                  lastBlock = block;
                }

                new BukkitRunnable() {
                  @Override
                  public void run() {
                    for (Block tntBlock : affected) {
                      TNTPrimed tnt =
                          tntBlock.getWorld().spawn(tntBlock.getLocation(), TNTPrimed.class);
                      tnt.setFuseTicks(5);
                      tntBlock.setType(Material.AIR);
                    }
                  }
                }.runTaskLater(TotalFreedomMod.plugin, 30L);

                event.setCancelled(true);
                break;
              }

            case RAW_FISH:
              {
                final int RADIUS_HIT = 5;
                final int STRENGTH = 4;

                // Clownfish
                if (TFM_DepreciationAggregator.getData_MaterialData(event.getItem().getData())
                    == 2) {
                  if (TFM_AdminList.isSeniorAdmin(player, true)
                      || TFM_AdminList.isTelnetAdmin(player, true)) {
                    boolean didHit = false;

                    final Location playerLoc = player.getLocation();
                    final Vector playerLocVec = playerLoc.toVector();

                    final List<Player> players = player.getWorld().getPlayers();
                    for (final Player target : players) {
                      if (target == player) {
                        continue;
                      }

                      final Location targetPos = target.getLocation();
                      final Vector targetPosVec = targetPos.toVector();

                      try {
                        if (targetPosVec.distanceSquared(playerLocVec)
                            < (RADIUS_HIT * RADIUS_HIT)) {
                          TFM_Util.setFlying(player, false);
                          target.setVelocity(
                              targetPosVec.subtract(playerLocVec).normalize().multiply(STRENGTH));
                          didHit = true;
                        }
                      } catch (IllegalArgumentException ex) {
                      }
                    }

                    if (didHit) {
                      final Sound[] sounds = Sound.values();
                      for (Sound sound : sounds) {
                        if (sound.toString().contains("HIT")) {
                          playerLoc
                              .getWorld()
                              .playSound(
                                  randomOffset(playerLoc, 5.0),
                                  sound,
                                  100.0f,
                                  randomDoubleRange(0.5, 2.0).floatValue());
                        }
                      }
                    }
                  } else {
                    final StringBuilder msg = new StringBuilder();
                    final char[] chars = (player.getName() + " is a clown.").toCharArray();
                    for (char c : chars) {
                      msg.append(TFM_Util.randomChatColor()).append(c);
                    }
                    TFM_Util.bcastMsg(msg.toString());

                    player.getInventory().getItemInHand().setType(Material.POTATO_ITEM);
                  }

                  event.setCancelled(true);
                  break;
                }
              }
          }
          break;
        }
    }
  }
  @EventHandler(priority = EventPriority.HIGH)
  public void onPlayerInteract(PlayerInteractEvent event) {
    Player player = event.getPlayer();

    switch (event.getAction()) {
      case RIGHT_CLICK_AIR:
      case RIGHT_CLICK_BLOCK:
        {
          switch (event.getMaterial()) {
            case WATER_BUCKET:
              {
                if (!TotalFreedomMod.allowWaterPlace) {
                  player
                      .getInventory()
                      .setItem(
                          player.getInventory().getHeldItemSlot(),
                          new ItemStack(Material.COOKIE, 1));
                  player.sendMessage(ChatColor.GRAY + "Water buckets are currently disabled.");
                  event.setCancelled(true);
                }
                break;
              }
            case LAVA_BUCKET:
              {
                if (!TotalFreedomMod.allowLavaPlace) {
                  player
                      .getInventory()
                      .setItem(
                          player.getInventory().getHeldItemSlot(),
                          new ItemStack(Material.COOKIE, 1));
                  player.sendMessage(ChatColor.GRAY + "Lava buckets are currently disabled.");
                  event.setCancelled(true);
                }
                break;
              }
            case EXPLOSIVE_MINECART:
              {
                if (!TotalFreedomMod.allowTntMinecarts) {
                  player.getInventory().clear(player.getInventory().getHeldItemSlot());
                  player.sendMessage(ChatColor.GRAY + "TNT minecarts are currently disabled.");
                  event.setCancelled(true);
                }
                break;
              }
          }
          break;
        }
      case LEFT_CLICK_AIR:
      case LEFT_CLICK_BLOCK:
        {
          switch (event.getMaterial()) {
            case STICK:
              {
                TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
                if (playerdata.mobThrowerEnabled()) {
                  Location player_pos = player.getLocation();
                  Vector direction = player_pos.getDirection().normalize();

                  LivingEntity rezzed_mob =
                      (LivingEntity)
                          player
                              .getWorld()
                              .spawnEntity(
                                  player_pos.add(direction.multiply(2.0)),
                                  playerdata.mobThrowerCreature());
                  rezzed_mob.setVelocity(direction.multiply(playerdata.mobThrowerSpeed()));
                  playerdata.enqueueMob(rezzed_mob);

                  event.setCancelled(true);
                }
                break;
              }
            case SULPHUR:
              {
                TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
                if (playerdata.isMP44Armed()) {
                  if (playerdata.toggleMP44Firing()) {
                    playerdata.startArrowShooter(TotalFreedomMod.plugin);
                  } else {
                    playerdata.stopArrowShooter();
                  }

                  event.setCancelled(true);
                }
                break;
              }
            case BLAZE_ROD:
              {
                if (TotalFreedomMod.allowExplosions) {
                  if (TFM_SuperadminList.isSeniorAdmin(player, true)) {
                    Block target_block;

                    if (event.getAction().equals(Action.LEFT_CLICK_AIR)) {
                      target_block = player.getTargetBlock(null, 120);
                    } else {
                      target_block = event.getClickedBlock();
                    }

                    if (target_block != null) {
                      player.getWorld().createExplosion(target_block.getLocation(), 4F, true);
                      player.getWorld().strikeLightning(target_block.getLocation());
                    } else {
                      player.sendMessage("Can't resolve target block.");
                    }

                    event.setCancelled(true);
                  }
                }
                break;
              }
            case CARROT:
              {
                if (TotalFreedomMod.allowExplosions) {
                  if (TFM_SuperadminList.isSeniorAdmin(player, true)) {
                    Location player_location = player.getLocation().clone();

                    Vector player_pos = player_location.toVector().add(new Vector(0.0, 1.65, 0.0));
                    Vector player_dir = player_location.getDirection().normalize();

                    double distance = 150.0;
                    Block target_block = player.getTargetBlock(null, Math.round((float) distance));
                    if (target_block != null) {
                      distance = player_location.distance(target_block.getLocation());
                    }

                    final List<Block> affected = new ArrayList<Block>();

                    Block last_block = null;
                    for (double offset = 0.0; offset <= distance; offset += (distance / 25.0)) {
                      Block test_block =
                          player_pos
                              .clone()
                              .add(player_dir.clone().multiply(offset))
                              .toLocation(player.getWorld())
                              .getBlock();

                      if (!test_block.equals(last_block)) {
                        if (test_block.isEmpty()) {
                          affected.add(test_block);
                          test_block.setType(Material.TNT);
                        } else {
                          break;
                        }
                      }

                      last_block = test_block;
                    }

                    new BukkitRunnable() {
                      @Override
                      public void run() {
                        for (Block tnt_block : affected) {
                          TNTPrimed tnt_primed =
                              tnt_block.getWorld().spawn(tnt_block.getLocation(), TNTPrimed.class);
                          tnt_primed.setFuseTicks(5);
                          tnt_block.setType(Material.AIR);
                        }
                      }
                    }.runTaskLater(TotalFreedomMod.plugin, 30L);

                    event.setCancelled(true);
                  }
                }
                break;
              }
          }
          break;
        }
    }
  }
Beispiel #7
0
  @Override
  protected void onPlayerMove(PlayerMoveEvent evt, Player P) {
    // TODO Auto-generated method stub
    super.onPlayerMove(evt, P);
    Player ply = evt.getPlayer();
    if (isSpectator(ply)) return;
    if (JocIniciat) {
      Player plyr = evt.getPlayer();

      Location to = evt.getTo();
      Location from = evt.getFrom();

      int equip = obtenirEquip(ply).getId() + 1;
      if (ply.getLocation().getY() < 102) {
        ply.setFireTicks(5000);
      }
      if (ply.getLocation().getY() < 60) {
        ply.damage(10000);
      }

      // Torres escuts
      int e = 1;
      while (e <= 2) {
        int i = 0;
        while (i <= 1) {
          Cuboid cub =
              pMapaActual()
                  .ObtenirCuboid("RegT" + Integer.toString(e) + Integer.toString(i), getWorld());
          Location center = cub.getCenter();
          if (cub.contains(to.getBlock())) {
            if (e == equip) {
              Vector vec = Utils.CrearVector(center, from).normalize().add(new Vector(0, 1, 0));
              getWorld().playSound(to, Sound.IRONGOLEM_HIT, 1F, 2.2F);
              getWorld().playEffect(to, Effect.MOBSPAWNER_FLAMES, 3);
              getWorld()
                  .playEffect(to.clone().add(new Vector(0, 1, 0)), Effect.MOBSPAWNER_FLAMES, 3);
              if (cub.contains(from.getBlock()) && plyr.getVelocity().length() >= 1) {
                plyr.teleport(from.add(vec));
                // Bukkit.broadcastMessage("ha entrat");
              } else {
                plyr.setVelocity(vec);
              }
              // evt.setCancelled(true);

            }
          }
          i = i + 1;
        }
        e = e + 1;
      }
      // SECURE NO-FALL
      //
      boolean isNoFallActive = false;

      ItemStack itemInHand = ply.getItemInHand();
      if (itemInHand.hasItemMeta()) {
        ItemMeta itemMeta = itemInHand.getItemMeta();
        if (itemMeta.hasDisplayName()) {
          if (itemMeta.getDisplayName().equals(getBridgeToolName())) {
            isNoFallActive = true;
          }
        }
      }

      if (isNoFallActive) {
        Vector v = Utils.CrearVector(evt.getFrom(), evt.getTo());
        v.multiply(1.45D);
        v.setY(0);
        Block bDown = evt.getTo().add(v).getBlock().getRelative(BlockFace.DOWN);
        if (bDown.isEmpty() && bDown.getRelative(BlockFace.DOWN).isEmpty()) {
          ItemStack placeableItemStack = getPlaceableItemStack(ply);
          if (placeableItemStack != null) {
            bDown.setType(placeableItemStack.getType());
            bDown.setData(placeableItemStack.getData().getData());
            ItemStack sampleIt = new ItemStack(placeableItemStack);
            sampleIt.setAmount(1);
            ply.getInventory().removeItem(sampleIt);
            itemInHand.setDurability((short) (itemInHand.getDurability() + 3));
          }
        }
      }
    }
  }
 @Override
 public boolean canSpawn(World world, int x, int z) {
   Block block = world.getHighestBlockAt(x, z).getRelative(BlockFace.DOWN);
   return !block.isLiquid() && !block.isEmpty() && !noSpawnFloors.contains(block.getType());
 }
  @EventHandler(priority = EventPriority.HIGH)
  public void onPlayerInteract(PlayerInteractEvent event) {
    final Player player = event.getPlayer();
    final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);

    switch (event.getAction()) {
      case RIGHT_CLICK_AIR:
      case RIGHT_CLICK_BLOCK:
        {
          switch (event.getMaterial()) {
            case WATER_BUCKET:
              {
                if (TFM_ConfigEntry.ALLOW_WATER_PLACE.getBoolean()) {
                  break;
                }

                player
                    .getInventory()
                    .setItem(
                        player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
                player.sendMessage(ChatColor.GRAY + "Water buckets are currently disabled.");
                event.setCancelled(true);
                break;
              }

            case LAVA_BUCKET:
              {
                if (TFM_ConfigEntry.ALLOW_LAVA_PLACE.getBoolean()) {
                  break;
                }

                player
                    .getInventory()
                    .setItem(
                        player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1));
                player.sendMessage(ChatColor.GRAY + "Lava buckets are currently disabled.");
                event.setCancelled(true);
                break;
              }

            case EXPLOSIVE_MINECART:
              {
                if (TFM_ConfigEntry.ALLOW_TNT_MINECARTS.getBoolean()) {
                  break;
                }

                player.getInventory().clear(player.getInventory().getHeldItemSlot());
                player.sendMessage(ChatColor.GRAY + "TNT minecarts are currently disabled.");
                event.setCancelled(true);
                break;
              }
          }
          break;
        }

      case LEFT_CLICK_AIR:
      case LEFT_CLICK_BLOCK:
        {
          switch (event.getMaterial()) {
            case STICK:
              {
                if (!TFM_AdminList.isSuperAdmin(player)) {
                  break;
                }

                event.setCancelled(true);

                final Location location = player.getTargetBlock(null, 5).getLocation();
                final List<RollbackEntry> entries =
                    TFM_RollbackManager.getEntriesAtLocation(location);

                if (entries.isEmpty()) {
                  TFM_Util.playerMsg(player, "No block edits at that location.");
                  break;
                }

                TFM_Util.playerMsg(
                    player,
                    "Block edits at ("
                        + ChatColor.WHITE
                        + "x"
                        + location.getBlockX()
                        + ", y"
                        + location.getBlockY()
                        + ", z"
                        + location.getBlockZ()
                        + ChatColor.BLUE
                        + ")"
                        + ChatColor.WHITE
                        + ":",
                    ChatColor.BLUE);
                for (RollbackEntry entry : entries) {
                  TFM_Util.playerMsg(
                      player,
                      " - "
                          + ChatColor.BLUE
                          + entry.author
                          + " "
                          + entry.getType()
                          + " "
                          + StringUtils.capitalize(entry.getMaterial().toString().toLowerCase())
                          + (entry.data == 0 ? "" : ":" + entry.data));
                }

                break;
              }

            case BONE:
              {
                if (!playerdata.mobThrowerEnabled()) {
                  break;
                }

                Location player_pos = player.getLocation();
                Vector direction = player_pos.getDirection().normalize();

                LivingEntity rezzed_mob =
                    (LivingEntity)
                        player
                            .getWorld()
                            .spawnEntity(
                                player_pos.add(direction.multiply(2.0)),
                                playerdata.mobThrowerCreature());
                rezzed_mob.setVelocity(direction.multiply(playerdata.mobThrowerSpeed()));
                playerdata.enqueueMob(rezzed_mob);

                event.setCancelled(true);
                break;
              }

            case SULPHUR:
              {
                if (!playerdata.isMP44Armed()) {
                  break;
                }

                event.setCancelled(true);

                if (playerdata.toggleMP44Firing()) {
                  playerdata.startArrowShooter(TotalFreedomMod.plugin);
                } else {
                  playerdata.stopArrowShooter();
                }
                break;
              }

            case BLAZE_ROD:
              {
                if (!TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean()) {
                  break;
                }

                if (!TFM_AdminList.isSeniorAdmin(player, true)) {
                  break;
                }

                event.setCancelled(true);
                Block targetBlock;

                if (event.getAction().equals(Action.LEFT_CLICK_AIR)) {
                  targetBlock = player.getTargetBlock(null, 120);
                } else {
                  targetBlock = event.getClickedBlock();
                }

                if (targetBlock == null) {
                  player.sendMessage("Can't resolve target block.");
                  break;
                }

                player.getWorld().createExplosion(targetBlock.getLocation(), 4F, true);
                player.getWorld().strikeLightning(targetBlock.getLocation());

                break;
              }

            case CARROT:
              {
                if (!TFM_ConfigEntry.ALLOW_EXPLOSIONS.getBoolean()) {
                  break;
                }

                if (!TFM_AdminList.isSeniorAdmin(player, true)) {
                  break;
                }

                Location location = player.getLocation().clone();

                Vector playerPostion = location.toVector().add(new Vector(0.0, 1.65, 0.0));
                Vector playerDirection = location.getDirection().normalize();

                double distance = 150.0;
                Block targetBlock = player.getTargetBlock(null, Math.round((float) distance));
                if (targetBlock != null) {
                  distance = location.distance(targetBlock.getLocation());
                }

                final List<Block> affected = new ArrayList<Block>();

                Block lastBlock = null;
                for (double offset = 0.0; offset <= distance; offset += (distance / 25.0)) {
                  Block block =
                      playerPostion
                          .clone()
                          .add(playerDirection.clone().multiply(offset))
                          .toLocation(player.getWorld())
                          .getBlock();

                  if (!block.equals(lastBlock)) {
                    if (block.isEmpty()) {
                      affected.add(block);
                      block.setType(Material.TNT);
                    } else {
                      break;
                    }
                  }

                  lastBlock = block;
                }

                new BukkitRunnable() {
                  @Override
                  public void run() {
                    for (Block tntBlock : affected) {
                      TNTPrimed tnt =
                          tntBlock.getWorld().spawn(tntBlock.getLocation(), TNTPrimed.class);
                      tnt.setFuseTicks(5);
                      tntBlock.setType(Material.AIR);
                    }
                  }
                }.runTaskLater(TotalFreedomMod.plugin, 30L);

                event.setCancelled(true);
                break;
              }
          }
          break;
        }
    }
  }
Beispiel #10
0
  private static void buildTree(World world, XYZ[] snakeBlocks) {
    // cut the snake into slices, this is my lab report
    HashMap<Integer, ArrayList<Block>> slices = new HashMap<Integer, ArrayList<Block>>();
    // System.out.println(snakeBlocks.length);
    for (XYZ loc : snakeBlocks) {
      Block block = world.getBlockAt(loc.x, loc.y, loc.z);
      if (block.isEmpty() && !block.isLiquid() && block.getType() != Material.BEDROCK) {
        if (slices.containsKey(Integer.valueOf(loc.y))) {
          slices.get(Integer.valueOf(loc.y)).add(block);
        } else {
          slices.put(Integer.valueOf(loc.y), new ArrayList<Block>());
          slices.get(Integer.valueOf(loc.y)).add(block);
        }
      }
    }

    ArrayList<Integer> sortedKeys = new ArrayList<Integer>(slices.keySet());
    Collections.sort(sortedKeys);
    int low = sortedKeys.get(0);
    int high = sortedKeys.get(sortedKeys.size() - 1);
    // boolean buildLayer1 = false;
    boolean buildLayer2 = false;
    boolean buildLayer3 = false;
    boolean buildLayer4 = false;
    for (Integer key : sortedKeys) {
      ArrayList<Block> slice = slices.get(key);
      for (Block b : slice) {
        b.setTypeIdAndData(17, (byte) 1, false);
      }
      //			if (!buildLayer1) {
      //				ArrayList<Block> toBranches = new ArrayList<Block>();
      //				for (Block b : slice) {
      //					if (b.getY()-low >= (high-low)-12 && checkBlockIsOnBorderOfSlice(b, slice)) {
      //						toBranches.add(b);
      //						buildLayer1 = true;
      //					}
      //				}
      //				buildTreeLayer1(toBranches);
      //			}
      if (!buildLayer2) {
        ArrayList<Block> toBranches = new ArrayList<Block>();
        for (Block b : slice) {
          if (b.getY() - low >= (high - low) - 8 && checkBlockIsOnBorderOfSlice(b, slice)) {
            toBranches.add(b);
            buildLayer2 = true;
          }
        }
        buildTreeLayer2(toBranches);
      }
      if (!buildLayer3) {
        ArrayList<Block> toBranches = new ArrayList<Block>();
        for (Block b : slice) {
          if (b.getY() - low >= (high - low) - 4 && checkBlockIsOnBorderOfSlice(b, slice)) {
            toBranches.add(b);
            buildLayer3 = true;
          }
        }
        buildTreeLayer3(toBranches);
      }
      if (!buildLayer4) {
        ArrayList<Block> toBranches = new ArrayList<Block>();
        for (Block b : slice) {
          if (b.getY() - low >= (high - low) && checkBlockIsOnBorderOfSlice(b, slice)) {
            toBranches.add(b);
            buildLayer4 = true;
          }
        }
        buildTreeLayer4(toBranches);
      }
    }
  }
Beispiel #11
0
 /**
  * Determine whether a given block is a either empty or liquid (but not lava)
  *
  * @param b the block to check
  * @return whether the block is suitable
  */
 public static boolean isSpaceForPlayer(Block b) {
   return (b.isEmpty() || b.isLiquid())
       && b.getType() != Material.LAVA
       && b.getType() != Material.STATIONARY_LAVA;
 }