Example #1
0
    protected void checkForGround() {
      checkCounter = 0;

      Location playerLocation = player.getLocation();
      World world = playerLocation.getWorld();
      Block targetBlock = world.getBlockAt(playerLocation);
      targetBlock = targetBlock.getFace(BlockFace.DOWN);

      int newGroundHeight = targetBlock.getY();

      while (targetBlock.getType() == Material.AIR && newGroundHeight > 1) {
        newGroundHeight--;
        targetBlock = targetBlock.getFace(BlockFace.DOWN);
      }

      // if the terrain has changed more than the auto-hover tolerance, re-adjust hover height and
      // keep level.
      if (groundHeight == 0 || targetHeight == 0) {
        hoverHeight = player.getLocation().getBlockY() - newGroundHeight;
        if (hoverHeight < defaultHoverHeight) {
          hoverHeight = defaultHoverHeight;
        }
      } else if (Math.abs(newGroundHeight - groundHeight) > maxTerrainChangeHeight) {
        hoverHeight = targetHeight - newGroundHeight;
      }

      groundHeight = newGroundHeight;

      updateTargetHeight();
    }
  @EventHandler(priority = EventPriority.HIGH)
  public void onBlockPlace(BlockPlaceEvent event) {
    Block block = event.getBlock();

    // Deny GameWorld Blocks
    GameWorld gworld = GameWorld.get(block.getWorld());
    if (gworld != null) {
      if (!GamePlaceableBlock.canBuildHere(
          block, block.getFace(event.getBlockAgainst()), event.getItemInHand().getType(), gworld)) {

        // Workaround for a bug that would allow 3-Block-high jumping
        Location loc = event.getPlayer().getLocation();
        if (loc.getY() > block.getY() + 1.0 && loc.getY() <= block.getY() + 1.5) {
          if (loc.getX() >= block.getX() - 0.3 && loc.getX() <= block.getX() + 1.3) {
            if (loc.getZ() >= block.getZ() - 0.3 && loc.getZ() <= block.getZ() + 1.3) {
              loc.setX(block.getX() + 0.5);
              loc.setY(block.getY());
              loc.setZ(block.getZ() + 0.5);
              event.getPlayer().teleport(loc);
            }
          }
        }
        event.setCancelled(true);
      }
    }
  }
Example #3
0
 @Override
 public boolean runRuneRightClick(BlockRightClickEvent event) {
   Block block = event.getBlock();
   if (canCompass(block)
       && (event.getItemInHand().getType() == Material.AIR
           || !event.getItemInHand().getType().isBlock())) {
     block.setType(Material.AIR);
     block.getFace(BlockFace.NORTH_EAST).setType(Material.AIR);
     block.getFace(BlockFace.NORTH_WEST).setType(Material.AIR);
     block.getFace(BlockFace.NORTH).setType(block.getFace(BlockFace.SOUTH_EAST).getType());
     block.getFace(BlockFace.EAST).setType(block.getFace(BlockFace.SOUTH_EAST).getType());
     block.getFace(BlockFace.WEST).setType(block.getFace(BlockFace.SOUTH_EAST).getType());
     return true;
   }
   return false;
 }
Example #4
0
 /**
  * Detecting factory, based on the position of the base. The rails must be one block above and the
  * sign if it exists must be one or two blocks below. Signs are guaranteed to be signs (unless
  * they're null) and rails are guaranteed to be rails.
  *
  * @param base the block on which the rails sit; the type of this block is what determines the
  *     mechanism type.
  */
 public static CartMechanismBlocks findByBase(Block base) throws InvalidMechanismException {
   if (!BlockType.isRailBlock(base.getFace(BlockFace.UP, 1).getTypeId()))
     throw new InvalidMechanismException("could not find rails.");
   if (SignUtil.isSign(base.getFace(BlockFace.DOWN, 1).getTypeId())) {
     return new CartMechanismBlocks(
         base.getFace(BlockFace.UP, 1), base, base.getFace(BlockFace.DOWN, 1));
   } else if (SignUtil.isSign(base.getFace(BlockFace.DOWN, 2).getTypeId())) {
     return new CartMechanismBlocks(
         base.getFace(BlockFace.UP, 1), base, base.getFace(BlockFace.DOWN, 2));
   }
   return new CartMechanismBlocks(base.getFace(BlockFace.UP, 1), base, null);
 }
Example #5
0
 /**
  * Detecting factory, based on the position of the rails. The base must be one block below and the
  * sign if it exists must be two or three blocks below. Signs are guaranteed to be signs (unless
  * they're null) and rails are guaranteed to be rails.
  *
  * <p>This is the most important constructor, since it is the one invoked when processing cart
  * move events.
  *
  * @param rail the block containing the rails.
  */
 public static CartMechanismBlocks findByRail(Block rail) throws InvalidMechanismException {
   if (!BlockType.isRailBlock(rail.getTypeId()))
     throw new InvalidMechanismException("rail argument must be a rail!");
   if (SignUtil.isSign(rail.getFace(BlockFace.DOWN, 2).getTypeId())) {
     return new CartMechanismBlocks(
         rail, rail.getFace(BlockFace.DOWN, 1), rail.getFace(BlockFace.DOWN, 2));
   } else if (SignUtil.isSign(rail.getFace(BlockFace.DOWN, 3).getTypeId())) {
     return new CartMechanismBlocks(
         rail, rail.getFace(BlockFace.DOWN, 1), rail.getFace(BlockFace.DOWN, 3));
   }
   return new CartMechanismBlocks(rail, rail.getFace(BlockFace.DOWN, 1), null);
 }
 public HallTunneler tunnel(int min, int max, XorZRetriever currentAxisValue) {
   int cVal = currentAxisValue.get(current);
   if (nextDir != null) {
     Byte dir = getByteDirection(nextDir);
     Byte opDir = getByteDirection(nextDir.getOppositeFace());
     while (!(cVal >= min && cVal <= max)) {
       current = current.getFace(nextDir);
       current.setTypeId(0);
       current.getFace(BlockFace.UP).setTypeId(0);
       if (by < requester.getMinY()) {
         if (dir != null) {
           current.setTypeIdAndData(67, dir, false);
         }
         current = current.getFace(BlockFace.UP);
         current.getFace(BlockFace.UP).setTypeId(0);
       } else if (by > requester.getMinY()) {
         current = current.getFace(BlockFace.DOWN);
         current.setTypeId(0);
         if (by + BlockFace.DOWN.getModY() >= requester.getMinY()) {
           current.getFace(BlockFace.DOWN).setTypeIdAndData(67, opDir, false);
         }
         if (Material.AIR.equals(current.getFace(nextDir).getType())) {
           current = current.getFace(nextDir);
           while (Material.AIR.equals(current.getFace(BlockFace.DOWN).getType())) {
             current = current.getFace(BlockFace.DOWN);
             current.setTypeIdAndData(Material.LADDER.getId(), opDir, false);
           }
           break;
         }
       }
       cVal = currentAxisValue.get(current);
       by = current.getY();
     }
     nextDir = null;
   }
   return this;
 }
Example #7
0
 /**
  * Detecting factory, based on the position of the sign. The base must be one or two blocks above
  * and the rails an additional block above the base. Signs are guaranteed to be signs and rails
  * are guaranteed to be rails.
  *
  * @param sign the block containing the sign that gives additional configuration to the mechanism.
  */
 public static CartMechanismBlocks findBySign(Block sign) throws InvalidMechanismException {
   if (!SignUtil.isSign(sign))
     throw new InvalidMechanismException("sign argument must be a sign!");
   if (BlockType.isRailBlock(sign.getFace(BlockFace.UP, 2).getTypeId())) {
     return new CartMechanismBlocks(
         sign.getFace(BlockFace.UP, 2), sign.getFace(BlockFace.UP, 1), sign);
   } else if (BlockType.isRailBlock(sign.getFace(BlockFace.UP, 3).getTypeId())) {
     return new CartMechanismBlocks(
         sign.getFace(BlockFace.UP, 3), sign.getFace(BlockFace.UP, 2), sign);
   }
   throw new InvalidMechanismException("could not find rails.");
 }
Example #8
0
 private boolean canCompass(Block block) {
   Material mat = block.getType();
   return ((this.plugin.getTier(mat) > 0)
       && block.getFace(BlockFace.NORTH_EAST).getType() == mat
       && block.getFace(BlockFace.SOUTH_EAST).getType() == mat
       && block.getFace(BlockFace.SOUTH_WEST).getType() == mat
       && block.getFace(BlockFace.NORTH_WEST).getType() == mat
       && block.getFace(BlockFace.NORTH).getType() == Material.AIR
       && block.getFace(BlockFace.EAST).getType() == Material.AIR
       && block.getFace(BlockFace.SOUTH).getType() == Material.AIR
       && block.getFace(BlockFace.WEST).getType() == Material.AIR);
 }
  /* (non-Javadoc)
   * @see org.bukkit.event.player.PlayerListener#onPlayerMove(org.bukkit.event.player.PlayerMoveEvent)
   */
  @Override
  public void onPlayerMove(PlayerMoveEvent event) {
    Player p = event.getPlayer();
    Location l = event.getTo();
    Block ch = l.getWorld().getBlockAt(l.getBlockX(), l.getBlockY(), l.getBlockZ());
    Stargate st = StargateManager.getGateFromBlock(ch);

    if (st != null && st.Active && st.Target != null) {
      String gatenetwork;
      if (st.Network != null) {
        gatenetwork = st.Network.netName;
      } else {
        gatenetwork = "Public";
      }
      wxt.prettyLog(
          Level.FINE,
          false,
          "Player in gate:"
              + st.Name
              + " gate Active: "
              + st.Active
              + " Target Gate: "
              + st.Target.Name
              + " Network: "
              + gatenetwork);

      if (ConfigManager.getWormholeUseIsTeleport()
          && ((st.IsSignPowered && !WXPermissions.checkWXPermissions(p, st, PermissionType.SIGN))
              || (!st.IsSignPowered
                  && !WXPermissions.checkWXPermissions(p, st, PermissionType.DIALER)))) {
        p.sendMessage(ConfigManager.output_strings.get(StringTypes.PERMISSION_NO));
        return;
      }
      if (st.Target.IrisActive) {
        p.sendMessage(ConfigManager.errorheader + "Remote Iris is locked!");
        p.setNoDamageTicks(2);
        event.setFrom(st.TeleportLocation);
        event.setTo(st.TeleportLocation);
        p.teleport(st.TeleportLocation);
        if (p.getFireTicks() > 0) {
          p.setFireTicks(0);
        }
        return;
      }

      Location target = st.Target.TeleportLocation;
      if (WormholeXTreme.iconomy != null) {
        double cost = ConfigManager.getIconomyWormholeUseCost();
        if (!ConfigManager.getIconomyOpsExcempt()
            && !p.isOp()
            && cost != 0.0
            && st.Owner != null
            && !st.Owner.equals(p.getName())) {
          Account player_account = iConomy.getBank().getAccount(p.getName());
          double balance = player_account.getBalance();
          String currency = iConomy.getBank().getCurrency();
          if (balance >= cost) {
            player_account.subtract(cost);
            // player_account.save();
            p.sendMessage(
                ConfigManager.normalheader
                    + "Wormhole Use \u00A7F- \u00A72"
                    + cost
                    + " \u00A77"
                    + currency);
            // p.sendMessage("You were charged " + cost + " " + iConomy.getBank().getCurrency() + "
            // to use wormhole." );
            double owner_percent = ConfigManager.getIconomyWormholeOwnerPercent();

            if (owner_percent != 0.0 && st.Owner != null) {
              if (st.Owner != null && iConomy.getBank().hasAccount(st.Owner)) {
                Account own_acc = iConomy.getBank().getAccount(st.Owner);
                own_acc.add(cost * owner_percent);
                // own_acc.save();
              }
            }
          } else {
            p.sendMessage(
                ConfigManager.errorheader
                    + "Not enough "
                    + currency
                    + "! - Requires: \u00A72"
                    + cost
                    + " \u00A77- Available: \u00A74"
                    + player_account.getBalance()
                    + " \u00A77"
                    + currency);
            // p.sendMessage("Not enough " + iConomy.getBank().getCurrency() + " to use - requires:
            // " + cost);
            target = st.TeleportLocation;
          }
        }
      }

      Block target_block =
          target.getWorld().getBlockAt(target.getBlockX(), target.getBlockY(), target.getBlockZ());
      while (target_block.getType() != Material.AIR
          && target_block.getType() != Material.WATER
          && target_block.getType() != Material.LAVA) {
        target_block = target_block.getFace(BlockFace.UP);
        target.setY(target.getY() + 1.0);
      }
      event.setFrom(target);
      event.setTo(target);
      p.setNoDamageTicks(2);
      p.teleport(target);
      event.setCancelled(true);
      if (target == st.Target.TeleportLocation)
        wxt.prettyLog(
            Level.INFO,
            false,
            p.getDisplayName() + " used wormhole: " + st.Name + " to go to: " + st.Target.Name);

      if (ConfigManager.getTimeoutShutdown() == 0) {
        st.ShutdownStargate();
      }
    } else if (st != null) {
      wxt.prettyLog(
          Level.FINE, false, "Player entered gate but wasn't active or didn't have a target.");
    }
  }
Example #10
0
  public void move(double d0, double d1, double d2) {
    if (this.bt) {
      this.boundingBox.d(d0, d1, d2);
      this.locX = (this.boundingBox.a + this.boundingBox.d) / 2.0D;
      this.locY = this.boundingBox.b + (double) this.height - (double) this.br;
      this.locZ = (this.boundingBox.c + this.boundingBox.f) / 2.0D;
    } else {
      this.br *= 0.4F;
      double d3 = this.locX;
      double d4 = this.locZ;

      if (this.bf) {
        this.bf = false;
        d0 *= 0.25D;
        d1 *= 0.05000000074505806D;
        d2 *= 0.25D;
        this.motX = 0.0D;
        this.motY = 0.0D;
        this.motZ = 0.0D;
      }

      double d5 = d0;
      double d6 = d1;
      double d7 = d2;
      AxisAlignedBB axisalignedbb = this.boundingBox.clone();
      boolean flag = this.onGround && this.isSneaking();

      if (flag) {
        double d8;

        for (d8 = 0.05D;
            d0 != 0.0D
                && this.world.getEntities(this, this.boundingBox.c(d0, -1.0D, 0.0D)).size() == 0;
            d5 = d0) {
          if (d0 < d8 && d0 >= -d8) {
            d0 = 0.0D;
          } else if (d0 > 0.0D) {
            d0 -= d8;
          } else {
            d0 += d8;
          }
        }

        for (;
            d2 != 0.0D
                && this.world.getEntities(this, this.boundingBox.c(0.0D, -1.0D, d2)).size() == 0;
            d7 = d2) {
          if (d2 < d8 && d2 >= -d8) {
            d2 = 0.0D;
          } else if (d2 > 0.0D) {
            d2 -= d8;
          } else {
            d2 += d8;
          }
        }
      }

      List list = this.world.getEntities(this, this.boundingBox.a(d0, d1, d2));

      for (int i = 0; i < list.size(); ++i) {
        d1 = ((AxisAlignedBB) list.get(i)).b(this.boundingBox, d1);
      }

      this.boundingBox.d(0.0D, d1, 0.0D);
      if (!this.bg && d6 != d1) {
        d2 = 0.0D;
        d1 = 0.0D;
        d0 = 0.0D;
      }

      boolean flag1 = this.onGround || d6 != d1 && d6 < 0.0D;

      int j;

      for (j = 0; j < list.size(); ++j) {
        d0 = ((AxisAlignedBB) list.get(j)).a(this.boundingBox, d0);
      }

      this.boundingBox.d(d0, 0.0D, 0.0D);
      if (!this.bg && d5 != d0) {
        d2 = 0.0D;
        d1 = 0.0D;
        d0 = 0.0D;
      }

      for (j = 0; j < list.size(); ++j) {
        d2 = ((AxisAlignedBB) list.get(j)).c(this.boundingBox, d2);
      }

      this.boundingBox.d(0.0D, 0.0D, d2);
      if (!this.bg && d7 != d2) {
        d2 = 0.0D;
        d1 = 0.0D;
        d0 = 0.0D;
      }

      double d9;
      double d10;
      int k;

      if (this.bs > 0.0F && flag1 && (flag || this.br < 0.05F) && (d5 != d0 || d7 != d2)) {
        d9 = d0;
        d10 = d1;
        double d11 = d2;

        d0 = d5;
        d1 = (double) this.bs;
        d2 = d7;
        AxisAlignedBB axisalignedbb1 = this.boundingBox.clone();

        this.boundingBox.b(axisalignedbb);
        list = this.world.getEntities(this, this.boundingBox.a(d5, d1, d7));

        for (k = 0; k < list.size(); ++k) {
          d1 = ((AxisAlignedBB) list.get(k)).b(this.boundingBox, d1);
        }

        this.boundingBox.d(0.0D, d1, 0.0D);
        if (!this.bg && d6 != d1) {
          d2 = 0.0D;
          d1 = 0.0D;
          d0 = 0.0D;
        }

        for (k = 0; k < list.size(); ++k) {
          d0 = ((AxisAlignedBB) list.get(k)).a(this.boundingBox, d0);
        }

        this.boundingBox.d(d0, 0.0D, 0.0D);
        if (!this.bg && d5 != d0) {
          d2 = 0.0D;
          d1 = 0.0D;
          d0 = 0.0D;
        }

        for (k = 0; k < list.size(); ++k) {
          d2 = ((AxisAlignedBB) list.get(k)).c(this.boundingBox, d2);
        }

        this.boundingBox.d(0.0D, 0.0D, d2);
        if (!this.bg && d7 != d2) {
          d2 = 0.0D;
          d1 = 0.0D;
          d0 = 0.0D;
        }

        if (!this.bg && d6 != d1) {
          d2 = 0.0D;
          d1 = 0.0D;
          d0 = 0.0D;
        } else {
          d1 = (double) (-this.bs);

          for (k = 0; k < list.size(); ++k) {
            d1 = ((AxisAlignedBB) list.get(k)).b(this.boundingBox, d1);
          }

          this.boundingBox.d(0.0D, d1, 0.0D);
        }

        if (d9 * d9 + d11 * d11 >= d0 * d0 + d2 * d2) {
          d0 = d9;
          d1 = d10;
          d2 = d11;
          this.boundingBox.b(axisalignedbb1);
        } else {
          double d12 = this.boundingBox.b - (double) ((int) this.boundingBox.b);

          if (d12 > 0.0D) {
            this.br = (float) ((double) this.br + d12 + 0.01D);
          }
        }
      }

      this.locX = (this.boundingBox.a + this.boundingBox.d) / 2.0D;
      this.locY = this.boundingBox.b + (double) this.height - (double) this.br;
      this.locZ = (this.boundingBox.c + this.boundingBox.f) / 2.0D;
      this.positionChanged = d5 != d0 || d7 != d2;
      this.bc = d6 != d1;
      this.onGround = d6 != d1 && d6 < 0.0D;
      this.bd = this.positionChanged || this.bc;
      this.a(d1, this.onGround);
      if (d5 != d0) {
        this.motX = 0.0D;
      }

      if (d6 != d1) {
        this.motY = 0.0D;
      }

      if (d7 != d2) {
        this.motZ = 0.0D;
      }

      d9 = this.locX - d3;
      d10 = this.locZ - d4;
      int l;
      int i1;
      int j1;

      // CraftBukkit start
      if ((this.positionChanged) && (getBukkitEntity() instanceof Vehicle)) {
        Vehicle vehicle = (Vehicle) getBukkitEntity();
        org.bukkit.World wrld = ((WorldServer) world).getWorld();
        org.bukkit.block.Block block =
            wrld.getBlockAt(
                MathHelper.floor(locX),
                MathHelper.floor(locY - 0.20000000298023224D - (double) this.height),
                MathHelper.floor(locZ));

        if (d5 > d0) {
          block = block.getFace(BlockFace.SOUTH);
        } else if (d5 < d0) {
          block = block.getFace(BlockFace.NORTH);
        } else if (d7 > d2) {
          block = block.getFace(BlockFace.WEST);
        } else if (d7 < d2) {
          block = block.getFace(BlockFace.EAST);
        }

        VehicleBlockCollisionEvent event = new VehicleBlockCollisionEvent(vehicle, block);
        ((WorldServer) world).getServer().getPluginManager().callEvent(event);
      }
      // CraftBukkit end

      if (this.n() && !flag && this.vehicle == null) {
        this.bm = (float) ((double) this.bm + (double) MathHelper.a(d9 * d9 + d10 * d10) * 0.6D);
        l = MathHelper.floor(this.locX);
        i1 = MathHelper.floor(this.locY - 0.20000000298023224D - (double) this.height);
        j1 = MathHelper.floor(this.locZ);
        k = this.world.getTypeId(l, i1, j1);
        if (this.world.getTypeId(l, i1 - 1, j1) == Block.FENCE.id) {
          k = this.world.getTypeId(l, i1 - 1, j1);
        }

        if (this.bm > (float) this.b && k > 0) {
          ++this.b;
          StepSound stepsound = Block.byId[k].stepSound;

          if (this.world.getTypeId(l, i1 + 1, j1) == Block.SNOW.id) {
            stepsound = Block.SNOW.stepSound;
            this.world.makeSound(
                this, stepsound.getName(), stepsound.getVolume1() * 0.15F, stepsound.getVolume2());
          } else if (!Block.byId[k].material.isLiquid()) {
            this.world.makeSound(
                this, stepsound.getName(), stepsound.getVolume1() * 0.15F, stepsound.getVolume2());
          }

          Block.byId[k].b(this.world, l, i1, j1, this);
        }
      }

      l = MathHelper.floor(this.boundingBox.a + 0.0010D);
      i1 = MathHelper.floor(this.boundingBox.b + 0.0010D);
      j1 = MathHelper.floor(this.boundingBox.c + 0.0010D);
      k = MathHelper.floor(this.boundingBox.d - 0.0010D);
      int k1 = MathHelper.floor(this.boundingBox.e - 0.0010D);
      int l1 = MathHelper.floor(this.boundingBox.f - 0.0010D);

      if (this.world.a(l, i1, j1, k, k1, l1)) {
        for (int i2 = l; i2 <= k; ++i2) {
          for (int j2 = i1; j2 <= k1; ++j2) {
            for (int k2 = j1; k2 <= l1; ++k2) {
              int l2 = this.world.getTypeId(i2, j2, k2);

              if (l2 > 0) {
                Block.byId[l2].a(this.world, i2, j2, k2, this);
              }
            }
          }
        }
      }

      boolean flag2 = this.ab();

      if (this.world.d(this.boundingBox.shrink(0.0010D, 0.0010D, 0.0010D))) {
        this.a(1);
        if (!flag2) {
          ++this.fireTicks;
          // CraftBukkit start
          if (this.fireTicks <= 0) {
            // not on fire yet
            CraftServer server = ((WorldServer) this.world).getServer();
            org.bukkit.entity.Entity damagee = this.getBukkitEntity();

            EntityCombustEvent event = new EntityCombustEvent(damagee);
            server.getPluginManager().callEvent(event);

            if (!event.isCancelled()) {
              this.fireTicks = 300;
            }
          } else {
            // CraftBukkit end - reset fire level back to max
            this.fireTicks = 300;
          }
        }
      } else if (this.fireTicks <= 0) {
        this.fireTicks = -this.maxFireTicks;
      }

      if (flag2 && this.fireTicks > 0) {
        this.world.makeSound(
            this,
            "random.fizz",
            0.7F,
            1.6F + (this.random.nextFloat() - this.random.nextFloat()) * 0.4F);
        this.fireTicks = -this.maxFireTicks;
      }
    }
  }
Example #11
0
  @Override
  public boolean onCast(String[] parameters) {
    PlayerPermissions permissions = spells.getPermissions(player.getName());

    if (parameters.length > 0) {
      if (parameters[0].equalsIgnoreCase("ascend")) {
        if (!ascend()) {
          castMessage(player, "Nowhere to go up");
          return false;
        }
        return true;
      }

      if (parameters[0].equalsIgnoreCase("descend")) {
        if (!descend()) {
          castMessage(player, "Nowhere to go down");
          return false;
        }
        return true;
      }

      return false;
    }

    // No parameters

    // Auto ascend + descend

    if (getYRotation() < -80 && permissions.hasPermission("descend") && autoDescend) {
      if (descend()) {
        return true;
      }
    }

    if (getYRotation() > 80 && permissions.hasPermission("ascend") && autoAscend) {
      if (ascend()) {
        return true;
      }
    }

    if (autoPassthrough) {
      Block firstBlock = getNextBlock();
      if (firstBlock.getType() != Material.AIR) {
        setReverseTargeting(true);
        setTargetHeightRequired(2);
        targetThrough(Material.AIR);
      } else {
        targetThrough(Material.GLASS);
      }
    }

    Block target = getTargetBlock();
    Block face = getLastBlock();

    if (target == null) {
      castMessage(player, "Nowhere to blink to");
      return false;
    }
    if (maxRange > 0 && getDistance(player, target) > maxRange) {
      castMessage(player, "Can't blink that far");
      return false;
    }

    World world = player.getWorld();

    // Don't drop the player too far, and make sure there is somewhere to stand
    Block destination = face;
    int distanceUp = 0;
    int distanceDown = 0;
    if (isReverseTargeting()) {
      destination = target;
    }
    Block groundBlock = destination.getFace(BlockFace.DOWN);
    while (distanceDown < verticalSearchDistance && !isOkToStandOn(groundBlock.getType())) {
      destination = groundBlock;
      groundBlock = destination.getFace(BlockFace.DOWN);
      distanceDown++;
    }

    Block ledge = null;
    // Also check for a ledge above the target
    if (!isReverseTargeting()) {
      ledge = target;
      Block inFront = face;
      Block oneUp = null;
      Block twoUp = null;

      do {
        oneUp = ledge.getFace(BlockFace.UP);
        twoUp = oneUp.getFace(BlockFace.UP);
        inFront = inFront.getFace(BlockFace.UP);
        ledge = ledge.getFace(BlockFace.UP);
        distanceUp++;
      } while (distanceUp < verticalSearchDistance
          && isOkToStandIn(inFront.getType())
          && (!isOkToStandOn(groundBlock.getType())
              || !isOkToStandIn(oneUp.getType())
              || !isOkToStandIn(twoUp.getType())));
    }

    if (ledge != null && distanceUp < distanceDown) {
      destination = ledge;
    }

    Block oneUp = destination.getFace(BlockFace.UP);
    Block twoUp = oneUp.getFace(BlockFace.UP);
    if (!isOkToStandIn(oneUp.getType()) || !isOkToStandIn(twoUp.getType())) {
      castMessage(player, "You can't fit in there!");
      return false;
    }
    castMessage(player, "Blink!");
    player.teleportTo(
        new org.bukkit.Location(
            world,
            destination.getX() + 0.5,
            destination.getY(),
            destination.getZ() + 0.5,
            player.getLocation().getYaw(),
            player.getLocation().getPitch()));
    return true;
  }
Example #12
0
  @Override
  public Result onProtectionInteract(
      LWC lwc,
      Player player,
      Protection protection,
      List<String> actions,
      boolean canAccess,
      boolean canAdmin) {
    if (!enabled || action == Action.NULL) {
      return DEFAULT;
    }

    if (!canAccess) {
      return DEFAULT;
    }

    // get the blocks for the door
    List<Block> blocks =
        lwc.getProtectionSet(
            protection.getBukkitWorld(), protection.getX(), protection.getY(), protection.getZ());

    // only send them one message :-)
    boolean sentMessage = false;

    // search around for iron doors if enabled
    if (configuration.getBoolean("doors.doubleDoors", true)) {
      Block protectionBlock = protection.getBlock();
      Block temp = null;

      BlockFace[] faces =
          new BlockFace[] {BlockFace.NORTH, BlockFace.WEST, BlockFace.EAST, BlockFace.SOUTH};

      for (BlockFace face : faces) {
        if (isValid((temp = protectionBlock.getFace(face)).getType())) {
          Protection found = lwc.findProtection(temp);

          if (found != null) {
            if (lwc.canAccessProtection(player, found)) {
              // we can access it, add it to the blocks
              blocks.addAll(
                  lwc.getProtectionSet(
                      found.getBukkitWorld(), found.getX(), found.getY(), found.getZ()));
            }
          }
        }
      }
    }

    for (Block block : blocks) {
      if (!isValid(block.getType())) {
        continue;
      }

      // create the door instance
      Door door = new Door(block.getType(), block.getData());

      // process the current door's data
      byte data = initializeDoorData(door);

      switch (this.action) {
        case TOGGLE:
          if ((block.getData() & 0x4) != 0x4) {
            data |= 0x4;
          }

          if (!sentMessage) {
            sentMessage = true;

            if (isDoorOpen(door)) {
              // lwc.sendLocale(player, "protection.doors.open");
            } else {
              // lwc.sendLocale(player, "protection.doors.close");
            }
          }

          break;

        case OPEN_AND_CLOSE:
          if ((block.getData() & 0x4) != 0x4) {
            data |= 0x4;
          }

          if (!sentMessage) {
            sentMessage = true;

            if (isDoorOpen(door)) {
              // lwc.sendLocale(player, "protection.doors.open");
            } else {
              // lwc.sendLocale(player, "protection.doors.close");
            }
          }

          if (!isDoorOpen(door)) {
            Location location =
                new Location(block.getWorld(), block.getX(), block.getY(), block.getZ());

            DoorAction doorAction = new DoorAction();
            doorAction.location = location;
            doorAction.triggerTime = System.currentTimeMillis() + (interval * 1000L);

            doors.push(doorAction);
          }

          break;
      }

      // update the door
      block.setData(data);
    }

    return DEFAULT;
  }
Example #13
0
  protected void createStairs(Block targetBlock) {
    BlockFace vertDirection = BlockFace.UP;
    BlockFace horzDirection = getPlayerFacing();

    int depth = defaultDepth;
    int height = defaultHeight;
    int width = defaultWidth;

    BlockList tunneledBlocks = new BlockList();
    BlockList stairBlocks = new BlockList();
    Material fillMaterial = targetBlock.getType();

    BlockFace toTheLeft = goLeft(horzDirection);
    BlockFace toTheRight = goRight(horzDirection);
    Block bottomBlock = targetBlock;
    Block bottomLeftBlock = bottomBlock;
    for (int i = 0; i < width / 2; i++) {
      bottomLeftBlock = bottomLeftBlock.getFace(toTheLeft);
    }

    targetBlock = bottomLeftBlock;
    Material stairsMaterial = Material.COBBLESTONE_STAIRS;

    for (int d = 0; d < depth; d++) {
      bottomBlock = bottomLeftBlock;
      for (int w = 0; w < width; w++) {
        targetBlock = bottomBlock;
        for (int h = 0; h < height; h++) {
          if (isDestructible(targetBlock)) {
            // Check to see if the torch will stick to the wall
            // TODO: Check for glass, other non-sticky types.
            Block checkBlock = null;
            if (w == 0) {
              checkBlock = targetBlock.getFace(toTheLeft);
            } else {
              checkBlock = targetBlock.getFace(toTheRight);
            }
            // Put torches on the left and right wall
            boolean useTorch =
                (torchFrequency > 0
                    && (w == 0 || w == width - 1)
                    && (h == 1)
                    && (d % torchFrequency == 0)
                    && checkBlock.getType() != Material.AIR);
            boolean useStairs = (h == 0);
            if (useStairs) {
              stairBlocks.add(targetBlock);
              targetBlock.setType(stairsMaterial);
            } else if (useTorch) {
              tunneledBlocks.add(targetBlock);
              targetBlock.setType(Material.TORCH);
            } else {
              tunneledBlocks.add(targetBlock);
              targetBlock.setType(Material.AIR);
            }
            Block standingBlock = targetBlock.getFace(BlockFace.DOWN);
            if (standingBlock.getType() == Material.AIR) {
              stairBlocks.add(standingBlock);
              standingBlock.setType(fillMaterial);
            }
          }
          targetBlock = targetBlock.getFace(BlockFace.UP);
        }
        bottomBlock = bottomBlock.getFace(toTheRight);
      }
      bottomLeftBlock = bottomLeftBlock.getFace(horzDirection);
      bottomLeftBlock = bottomLeftBlock.getFace(vertDirection);
    }

    spells.addToUndoQueue(player, tunneledBlocks);
    spells.addToUndoQueue(player, stairBlocks);
    castMessage(
        player,
        "Tunneled through "
            + tunneledBlocks.size()
            + "blocks and created "
            + stairBlocks.size()
            + " stairs");
  }