示例#1
0
  public void teleport(final Vehicle vehicle) {
    Location traveller =
        new Location(
            this.world,
            vehicle.getLocation().getX(),
            vehicle.getLocation().getY(),
            vehicle.getLocation().getZ());
    Location exit = getExit(traveller);

    double velocity = vehicle.getVelocity().length();

    // Stop and teleport
    vehicle.setVelocity(new Vector());

    // Get new velocity
    final Vector newVelocity = new Vector();
    switch ((int) id.getBlock().getData()) {
      case 2:
        newVelocity.setZ(-1);
        break;
      case 3:
        newVelocity.setZ(1);
        break;
      case 4:
        newVelocity.setX(-1);
        break;
      case 5:
        newVelocity.setX(1);
        break;
    }
    newVelocity.multiply(velocity);

    final Entity passenger = vehicle.getPassenger();
    if (passenger != null) {
      final Vehicle v = exit.getWorld().spawn(exit, vehicle.getClass());
      vehicle.eject();
      vehicle.remove();
      passenger.teleport(exit);
      Stargate.server
          .getScheduler()
          .scheduleSyncDelayedTask(
              Stargate.stargate,
              new Runnable() {
                public void run() {
                  v.setPassenger(passenger);
                  v.setVelocity(newVelocity);
                }
              },
              1);
    } else {
      Vehicle mc = exit.getWorld().spawn(exit, vehicle.getClass());
      if (mc instanceof StorageMinecart) {
        StorageMinecart smc = (StorageMinecart) mc;
        smc.getInventory().setContents(((StorageMinecart) vehicle).getInventory().getContents());
      }
      mc.setVelocity(newVelocity);
      vehicle.remove();
    }
  }
示例#2
0
  public static Vector calculateVector(Location loc) {

    Vector vec = loc.getDirection();
    int mult = 3;
    vec.setX(vec.getX() * mult);
    vec.setY(vec.getY() * mult);
    vec.setZ(vec.getZ() * mult);
    return vec;
  }
示例#3
0
  @EventHandler
  public void LocationUpdater(UpdateEvent event) {
    if (event.getType() == UpdateType.TICK) {
      for (Player p : EffectManager.effect3.keySet()) {
        if (EffectManager.getEffect(p) == EffectManager.EffectType.HourGlass) {
          if (p.isValid()) {
            if (ExtraManager.isMoving(p)) {
              Location location = p.getLocation();

              Vector vector = new Vector();

              for (int i = 0; i < this.particlesPerIteration; i++) {
                this.step += 1;

                float t = 3.141593F / this.particles * this.step;
                float r =
                    MathUtils.sin(t * 2.718282F * this.particlesPerIteration / this.particles)
                        * this.size;
                float s = r * 3.141593F * t;

                vector.setX(this.xFactor * r * -MathUtils.cos(s));
                vector.setZ(this.zFactor * r * -MathUtils.sin(s));
                vector.setY(this.yFactor * r + this.yOffset + 2.0F);

                UtilVector.rotateVector(vector, this.xRotation, this.yRotation, this.zRotation);
                ParticleLib18 ench =
                    new ParticleLib18(
                        com.lightcraftmc.particles18.ParticleLib18.ParticleType.ENCHANTMENT_TABLE,
                        0.0D,
                        1,
                        0.0D);
                ench.sendToLocation(location.add(vector));

                location.subtract(vector);
              }

            } else if (!p.isInsideVehicle()) {
              ParticleLib18 ench2 =
                  new ParticleLib18(
                      com.lightcraftmc.particles18.ParticleLib18.ParticleType.ENCHANTMENT_TABLE,
                      0.1000000014901161D,
                      4,
                      0.300000011920929D);
              ench2.sendToLocation(p.getLocation().add(0.0D, 1.0D, 0.0D));
            }
          }
        }
      }
    }
  }
示例#4
0
  private void launch() {
    origin = player.getEyeLocation();
    for (int i = -arc; i <= arc; i += stepsize) {
      double angle = Math.toRadians((double) i);
      Vector direction = player.getEyeLocation().getDirection().clone();

      double x, z, vx, vz;
      x = direction.getX();
      z = direction.getZ();

      vx = x * Math.cos(angle) - z * Math.sin(angle);
      vz = x * Math.sin(angle) + z * Math.cos(angle);

      direction.setX(vx);
      direction.setZ(vz);

      elements.put(direction, origin);
    }
  }
示例#5
0
 @Override
 public boolean onCommand(CommandSender cs, Command cmd, String label, String[] args) {
   if (cmd.getName().equalsIgnoreCase("slap")) {
     if (!plugin.isAuthorized(cs, "rcmds.slap")) {
       RUtils.dispNoPerms(cs);
       return true;
     }
     if (args.length < 1) {
       cs.sendMessage(cmd.getDescription());
       return false;
     }
     Player victim;
     victim = plugin.getServer().getPlayer(args[0]);
     if (victim == null || plugin.isVanished(victim)) {
       cs.sendMessage(ChatColor.RED + "That person is not online!");
       return true;
     }
     if (plugin.isAuthorized(victim, "rcmds.exempt.slap")) {
       cs.sendMessage(ChatColor.RED + "You may not slap that player.");
       return true;
     }
     Vector push = victim.getVelocity();
     push.setY(push.getY() + .5);
     push.setX(push.getX() + .5);
     push.setZ(push.getZ() + .5);
     victim.setVelocity(push);
     plugin
         .getServer()
         .broadcastMessage(
             ChatColor.GOLD
                 + cs.getName()
                 + ChatColor.WHITE
                 + " slaps "
                 + ChatColor.RED
                 + victim.getName()
                 + ChatColor.WHITE
                 + "!");
     return true;
   }
   return false;
 }
  /**
   * Find a suitable location for a player to teleport to in the given world. This method uses
   * WorldBorder as the configuration source.
   *
   * @param world World to teleport to
   * @return Location to teleport to
   */
  private Location findSuitableLocationWB(World world) {
    BorderData borderData = WorldBorder.plugin.GetWorldBorder(world.getName());

    if (borderData == null) {
      // throw new IllegalStateException(String.format("World %1$s isn't configured in
      // WorldBorder.", world.getName()));
      return null;
    }

    for (int i = 0; i < 100; i++) {
      Vector position = new Vector(borderData.getX(), 0.0, borderData.getZ());

      // Get a uniform-area random position within the world border's geometry
      boolean isRound = (borderData.getShape() == null) ? true : borderData.getShape();
      if (isRound) {
        position.add(
            getRandomPointInEllipse(random, borderData.getRadiusX(), borderData.getRadiusZ()));
      } else {
        position.add(
            getRandomPointInRectangle(random, borderData.getRadiusX(), borderData.getRadiusZ()));
      }

      // Ensure there's a solid block to stand on
      Block highestBlock = world.getHighestBlockAt(position.getBlockX(), position.getBlockZ());
      if (highestBlock == null) continue;
      highestBlock = highestBlock.getRelative(0, -1, 0); // Because the javadocs are wrong.
      if (highestBlock == null) continue;
      if (highestBlock.getY() < 1 || highestBlock.getY() >= world.getMaxHeight() - 2) continue;
      if (highestBlock.isLiquid()) continue;

      position.setX((double) position.getBlockX() + 0.5);
      position.setY(highestBlock.getY() + 2);
      position.setZ((double) position.getBlockZ() + 0.5);

      return position.toLocation(world, getRandomYaw(), 0.0f);
    }

    return null;
  }
  @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
  public void onPlayerMove(PlayerMoveEvent event) {
    Player player = event.getPlayer();
    if (Concussion.getTarget(player) != null) {
      event.setCancelled(true);
      return;
    }
    if (WaterSpout.isBending(event.getPlayer())
        || AirSpout.getPlayers().contains(event.getPlayer())) {
      Vector vel = new Vector();
      vel.setX(event.getTo().getX() - event.getFrom().getX());
      vel.setY(event.getTo().getY() - event.getFrom().getY());
      vel.setZ(event.getTo().getZ() - event.getFrom().getZ());
      // You now know the old velocity. Set to match recommended velocity
      double currspeed = vel.length();
      double maxspeed = .15;
      if (currspeed > maxspeed) {
        vel = vel.normalize().multiply(maxspeed * 0.9);
        event.getPlayer().setVelocity(vel);
      }
    }
    if (Bloodbending.isBloodbended(player)) {
      double distance1, distance2;
      Location loc = Bloodbending.getBloodbendingLocation(player);
      distance1 = event.getFrom().distance(loc);
      distance2 = event.getTo().distance(loc);
      if (distance2 > distance1) {
        player.setVelocity(new Vector(0, 0, 0));
      }
    }

    if (Dash.isDashing(player)) {
      Vector dir = event.getTo().clone().subtract(event.getFrom()).toVector();
      Dash d = Dash.getDash(player);
      d.setDirection(dir);
    }
  }
示例#8
0
  public SearchParser(CommandSender player, List<String> args) throws IllegalArgumentException {
    this.player = player;

    String lastParam = "";
    boolean paramSet = false;
    boolean worldedit = false;

    for (int i = 0; i < args.size(); i++) {
      String arg = args.get(i);
      if (arg.isEmpty()) continue;

      if (!paramSet) {
        if (arg.length() < 2)
          throw new IllegalArgumentException("Invalid argument format: &7" + arg);
        if (!arg.substring(1, 2).equals(":")) {
          if (arg.contains(":"))
            throw new IllegalArgumentException("Invalid argument format: &7" + arg);

          // No arg specified, treat as player
          players.add(arg);
          continue;
        }

        lastParam = arg.substring(0, 1).toLowerCase();
        paramSet = true;

        if (arg.length() == 2) {
          if (i == (args.size() - 1)) // No values specified
          throw new IllegalArgumentException("Invalid argument format: &7" + arg);
          else // User put a space between the colon and value
          continue;
        }

        // Get values out of argument
        arg = arg.substring(2);
      }

      if (paramSet) {
        if (arg.isEmpty()) {
          throw new IllegalArgumentException("Invalid argument format: &7" + lastParam + ":");
        }

        String[] values = arg.split(",");

        // Players
        if (lastParam.equals("p")) for (String p : values) players.add(p);
        // Worlds
        else if (lastParam.equals("w")) worlds = values;
        // Filters
        else if (lastParam.equals("f")) {
          if (filters != null) filters = Util.concat(filters, values);
          else filters = values;
        }
        // Blocks
        else if (lastParam.equals("b")) {
          for (int j = 0; j < values.length; j++) {
            if (Material.getMaterial(values[j]) != null)
              values[j] = Integer.toString(Material.getMaterial(values[j]).getId());
          }
        }
        // Actions
        else if (lastParam.equals("a")) {
          for (String value : values) {
            DataType type = DataType.fromName(value);
            if (type == null)
              throw new IllegalArgumentException("Invalid action supplied: &7" + value);
            if (!Util.hasPerm(player, "search." + type.getConfigName().toLowerCase()))
              throw new IllegalArgumentException(
                  "You do not have permission to search for: &7" + type.getConfigName());
            actions.add(type);
          }
        }
        // Location
        else if (lastParam.equals("l") && player instanceof Player) {
          if (values[0].equalsIgnoreCase("here")) loc = ((Player) player).getLocation().toVector();
          else {
            loc = new Vector();
            loc.setX(Integer.parseInt(values[0]));
            loc.setY(Integer.parseInt(values[1]));
            loc.setZ(Integer.parseInt(values[2]));
          }
        }
        // Radius
        else if (lastParam.equals("r") && player instanceof Player) {
          if (!Util.isInteger(values[0])) {
            if ((values[0].equalsIgnoreCase("we") || values[0].equalsIgnoreCase("worldedit"))
                && HawkEye.worldEdit != null) {
              Selection sel = HawkEye.worldEdit.getSelection((Player) player);
              double lRadius = Math.ceil(sel.getLength() / 2);
              double wRadius = Math.ceil(sel.getWidth() / 2);
              double hRadius = Math.ceil(sel.getHeight() / 2);

              if (Config.MaxRadius != 0
                  && (lRadius > Config.MaxRadius
                      || wRadius > Config.MaxRadius
                      || hRadius > Config.MaxRadius))
                throw new IllegalArgumentException(
                    "Selection too large, max radius: &7" + Config.MaxRadius);

              worldedit = true;
              minLoc =
                  new Vector(
                      sel.getMinimumPoint().getX(),
                      sel.getMinimumPoint().getY(),
                      sel.getMinimumPoint().getZ());
              maxLoc =
                  new Vector(
                      sel.getMaximumPoint().getX(),
                      sel.getMaximumPoint().getY(),
                      sel.getMaximumPoint().getZ());
            } else {
              throw new IllegalArgumentException("Invalid radius supplied: &7" + values[0]);
            }
          } else {
            radius = Integer.parseInt(values[0]);
            if (Config.MaxRadius != 0 && radius > Config.MaxRadius)
              throw new IllegalArgumentException(
                  "Radius too large, max allowed: &7" + Config.MaxRadius);
          }
        }
        // Time
        else if (lastParam.equals("t")) {

          int type = 2;
          boolean isTo = false;
          for (int j = 0; j < arg.length(); j++) {
            String c = arg.substring(j, j + 1);
            if (!Util.isInteger(c)) {
              if (c.equals("m")
                  || c.equals("s")
                  || c.equals("h")
                  || c.equals("d")
                  || c.equals("w")) {
                type = 0;
              }
              if (c.equals("-") || c.equals(":")) type = 1;
            }
          }

          // If the time is in the format '0w0d0h0m0s'
          if (type == 0) {

            int weeks = 0;
            int days = 0;
            int hours = 0;
            int mins = 0;
            int secs = 0;

            String nums = "";
            for (int j = 0; j < values[0].length(); j++) {
              String c = values[0].substring(j, j + 1);
              if (c.equals("!")) { // If the number has a ! infront of it the time inverts
                c = values[0].substring(j, j + 2).replace("!", "");
                isTo = true;
              } else {
                if (Util.isInteger(c)) {
                  nums += c;
                  continue;
                }

                int num = Integer.parseInt(nums);
                if (c.equals("w")) weeks = num;
                else if (c.equals("d")) days = num;
                else if (c.equals("h")) hours = num;
                else if (c.equals("m")) mins = num;
                else if (c.equals("s")) secs = num;
                else throw new IllegalArgumentException("Invalid time measurement: &7" + c);
                nums = "";
              }
            }

            Calendar cal = Calendar.getInstance();
            cal.add(Calendar.WEEK_OF_YEAR, -1 * weeks);
            cal.add(Calendar.DAY_OF_MONTH, -1 * days);
            cal.add(Calendar.HOUR, -1 * hours);
            cal.add(Calendar.MINUTE, -1 * mins);
            cal.add(Calendar.SECOND, -1 * secs);
            SimpleDateFormat form = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            if (isTo) dateTo = form.format(cal.getTime());
            else dateFrom = form.format(cal.getTime());
          }

          // If the time is in the format 'yyyy-MM-dd HH:mm:ss'
          else if (type == 1) {
            if (values.length == 1) {
              SimpleDateFormat form = new SimpleDateFormat("yyyy-MM-dd");
              dateFrom = form.format(Calendar.getInstance().getTime()) + " " + values[0];
            }
            if (values.length >= 2) dateFrom = values[0] + " " + values[1];
            if (values.length == 4) dateTo = values[2] + " " + values[3];
          }
          // Invalid time format
          else if (type == 2) throw new IllegalArgumentException("Invalid time format!");

        } else throw new IllegalArgumentException("Invalid parameter supplied: &7" + lastParam);

        paramSet = false;
      }
    }

    // Sort out locations
    if (!worldedit) parseLocations();
  }
示例#9
0
  @EventHandler(priority = EventPriority.HIGHEST)
  private void onInteract(PlayerInteractEvent event) {
    final Player player = event.getPlayer();
    PlayerDataClass playerData = plugin.getPlayerHandler().findPlayer(player.getDisplayName());

    if (playerData.getType() != null) {
      if (player.getItemInHand().getType() == Material.BOW
          && event.getAction() == Action.RIGHT_CLICK_BLOCK
          && (inJump.get(player) == null || inJump.get(player).equals(Boolean.FALSE))
          && playerData.getType().equalsIgnoreCase("soldier")) {

        if (player.getInventory().contains(Material.ARROW)) {
          player.getInventory().removeItem(new ItemStack(Material.ARROW, 1));
          player.updateInventory();
          player
              .getLocation()
              .getWorld()
              .createExplosion(
                  player.getLocation().getX(),
                  player.getLocation().getY(),
                  player.getLocation().getZ(),
                  0);

          // double rotation = player.getLocation().getPitch();

          // double jumpFactor = -(rotation / 20);
          // double distanceFactor = -((90 - rotation) * 10);

          Vector newDirection = player.getVelocity();
          inJump.put(player, true);
          /*if (jumpFactor < -1) {
          	newDirection.setY(newDirection.getY() * jumpFactor);
          }
          if (distanceFactor < -1) {
          	newDirection.setX(newDirection.getX() * distanceFactor);
          	newDirection.setZ(newDirection.getZ() * distanceFactor);
          }

          player.setVelocity(newDirection);*/
          Vector jumpDirection = player.getLocation().getDirection().multiply(-1.5);
          jumpDirection.setX(jumpDirection.getX() * 1.4);
          jumpDirection.setZ(jumpDirection.getZ() * 1.4);
          newDirection.setX(newDirection.getX() * -jumpDirection.getX());
          newDirection.setY(newDirection.getY() * -jumpDirection.getY());
          newDirection.setZ(newDirection.getZ() * -jumpDirection.getZ());
          player.setVelocity(jumpDirection);
          player.damage(3);
          plugin
              .getServer()
              .getScheduler()
              .scheduleSyncDelayedTask(
                  plugin,
                  new Runnable() {
                    public void run() {
                      inJump.put(player, false);
                    }
                  },
                  10L);
          return;
        }
      }
      /* if (player.getItemInHand().getType() == Material.BOW &&
      		event.getAction() == Action.RIGHT_CLICK_AIR &&
      		playerData.getType().equalsIgnoreCase("soldier")) {

           		if (player.getInventory().contains(Material.ARROW)) {
           			player.getInventory().removeItem(new ItemStack (Material.ARROW, 1));
           			player.updateInventory();
           			//Location loc = player.getLocation(); // Get the player Location
           			//loc.add(0, 1, 0); //Add 1 to the Y, makes the arrow go at chest level instead of feet

           			Location arrowLocation = player.getEyeLocation();
        			arrowLocation.setY(arrowLocation.getY() + 0.1);
                 Arrow sniperArrow = player.getWorld().spawnArrow(arrowLocation,
                 player.getLocation().getDirection(), 0.6f, 1);
                 sniperArrow.setShooter(player);
                 sniperArrow.setBounce(false);
                 //sniperArrow.setVelocity(player.getLocation().getDirection().normalize().multiply(12));
        		}

            	return;
      }	*/

      /*if (player.getItemInHand().getType() == Material.BOW &&
      		(event.getAction() == Action.LEFT_CLICK_AIR ||
      		event.getAction() == Action.LEFT_CLICK_BLOCK) &&
      		playerData.getType().equalsIgnoreCase("soldier")) {
      	event.setCancelled(true);
      	return;
      }	*/
      if (player.getItemInHand().getType() == Material.IRON_SWORD
          && (event.getAction() == Action.RIGHT_CLICK_AIR
              || event.getAction() == Action.RIGHT_CLICK_BLOCK)
          && playerData.getType().equalsIgnoreCase("spy")) {

        plugin
            .getServer()
            .getWorld("world")
            .playEffect(player.getLocation(), Effect.EXTINGUISH, 40);

        if (playerData.getDisguised() == null) {
          if (playerData.getTeam() == "red") {
            if (plugin.getPlayerHandler().getBluePlayers().size() > 0) {
              plugin.getPlayerHandler().giveArmor(playerData.getName(), "blue");
              Random random = new Random();
              List<PlayerDataClass> temp = plugin.getPlayerHandler().getBluePlayers();
              int randomNumber = random.nextInt(temp.size());
              playerData.setDisguised(temp.get(randomNumber).getName());
              plugin.getPlayerLocationListener().getRedPlayersOnPoint().remove(playerData);
              TagAPI.refreshPlayer(plugin.getServer().getPlayer(playerData.getName()));
            } else {
              plugin.getPlayerHandler().giveArmor(playerData.getName(), "blue");
              playerData.setDisguised(playerData.getName());
              TagAPI.refreshPlayer(plugin.getServer().getPlayer(playerData.getName()));
            }
          }
          if (playerData.getTeam() == "blue") {
            if (plugin.getPlayerHandler().getRedPlayers().size() > 0) {
              plugin.getPlayerHandler().giveArmor(playerData.getName(), "red");
              Random random = new Random();
              List<PlayerDataClass> temp = plugin.getPlayerHandler().getRedPlayers();
              int randomNumber = random.nextInt(temp.size());
              playerData.setDisguised(temp.get(randomNumber).getName());
              TagAPI.refreshPlayer(plugin.getServer().getPlayer(playerData.getName()));
            } else {
              plugin.getPlayerHandler().giveArmor(playerData.getName(), "red");
              playerData.setDisguised(playerData.getName());
              TagAPI.refreshPlayer(plugin.getServer().getPlayer(playerData.getName()));
            }
          }
          return;
        } else {
          playerData.setDisguised(null);
          plugin.getPlayerHandler().giveArmor(playerData.getName(), playerData.getTeam());
          TagAPI.refreshPlayer(plugin.getServer().getPlayer(playerData.getName()));
          return;
        }
      }

      if ((event.getAction() == Action.LEFT_CLICK_AIR
              || event.getAction() == Action.LEFT_CLICK_BLOCK
              || event.getAction() == Action.RIGHT_CLICK_AIR
              || event.getAction() == Action.RIGHT_CLICK_BLOCK)
          && playerData.getType().equalsIgnoreCase("spy")
          && playerData.getDisguised() != null) {
        playerData.setDisguised(null);
        plugin.getPlayerHandler().giveArmor(playerData.getName(), playerData.getTeam());
        TagAPI.refreshPlayer(plugin.getServer().getPlayer(playerData.getName()));
        return;
      }

      if (player.getItemInHand().getType() == Material.BOW
          && event.getAction() == Action.LEFT_CLICK_AIR
          && playerData.getType().equalsIgnoreCase("sniper")) {
        if (playerData.isScoped() == true) {
          setUnscoped(player, playerData);
        } else {
          setScoped(player, playerData);
        }
      }

      if (player.getItemInHand().getType() == Material.getMaterial(356)
          && (event.getAction() == Action.LEFT_CLICK_AIR
              || event.getAction() == Action.LEFT_CLICK_BLOCK)
          && playerData.getType().equalsIgnoreCase("demo")) {
        plugin.getLogger().info("demo fired");

        Location stickyLocation = player.getEyeLocation();
        stickyLocation.setY(stickyLocation.getY() + 0.1);

        Item sticky;
        if (playerData.getTeam().equals("red")) {
          sticky =
              player
                  .getWorld()
                  .dropItemNaturally(
                      stickyLocation,
                      new ItemStack(
                          Material.INK_SACK, 1, (short) 0, (byte) (15 - DyeColor.RED.getData())));
          sticky.setMetadata("redsticky", new FixedMetadataValue(plugin, true));
        } else {
          sticky =
              player
                  .getWorld()
                  .dropItemNaturally(
                      stickyLocation,
                      new ItemStack(
                          Material.INK_SACK, 1, (short) 0, (byte) (15 - DyeColor.BLUE.getData())));
          sticky.setMetadata("bluesticky", new FixedMetadataValue(plugin, true));
        }

        // stickyBomb.setData(dye);
        // Item sticky = player.getWorld().dropItem(stickyLocation, stickyBomb);

        sticky.setVelocity(player.getEyeLocation().getDirection());

        StickyDataClass stickyData = new StickyDataClass();
        stickyData.setOwner(playerData.getName());
        stickyData.setSticky(sticky);
        stickyData.setTeam(playerData.getTeam());
        plugin.getStickysFired().add(stickyData);
      }

      if (player.getItemInHand().getType() == Material.getMaterial(356)
          && (event.getAction() == Action.RIGHT_CLICK_AIR
              || event.getAction() == Action.RIGHT_CLICK_BLOCK)
          && playerData.getType().equalsIgnoreCase("demo")) {
        plugin.getLogger().info("demo triggered");
        event.setCancelled(true);
        for (int i = 0; i < plugin.getStickysFired().size(); i++) {
          StickyDataClass temp = plugin.getStickysFired().get(i);
          plugin.getLogger().info(i + " Owner/Team " + temp.getOwner() + "/" + temp.getTeam());
          if (temp.getOwner() == playerData.getName()) {
            plugin
                .getServer()
                .getWorld("world")
                .createExplosion(
                    temp.getSticky().getLocation().getX(),
                    temp.getSticky().getLocation().getY(),
                    temp.getSticky().getLocation().getZ(),
                    5,
                    false,
                    false);

            for (Entity nearby : temp.getSticky().getNearbyEntities(3, 3, 3)) {
              if (nearby instanceof Player) {
                Player nearbyPlayer = (Player) nearby;
                nearbyPlayer.damage(8, player);
              }
            }
            temp.getSticky().remove();
            plugin.getStickysFired().remove(i);
          }
        }
      }

    } else {
      return;
    }
  }
示例#10
0
  /**
   * Teleports the passed in Entity through the portal.
   *
   * <p>Given an Entity object, attempts to teleport them through the portal. This involves many
   * steps. 1) Verify the portal on the other end still exists. If it doesn't, mark this as such. 2)
   * If there is no counterpart, figure out where it would be, and get it. This may involve
   * generating and placing a portal into the world. 3) Assuming we now have a counterpart, figure
   * out where to teleport the entity to. 3a) Figure out the entity's position relative to the entry
   * portal. 3b) Translate this to a position relative to the exit portal. 3c) Preserve the entity's
   * camera's orientation relative to the portal. 4) Teleport the entity. 4a) If the entity is a
   * Player in a vehicle, we do a dance. - Raise the destination by 1 (vehicles have to 'fall' into
   * the portal to avoid losing momentum, so they should be one higher). - Make the player leave the
   * vehicle. - Spawn a new minecart at the destination. - Teleport the player to the destination. -
   * Make the player a passenger of the minecart. - Give the new minecart the (properly translated)
   * velocity of the old vehicle. - Remove the old vehicle.
   *
   * @param e The entity to teleport.
   * @return The location the entity was teleported to, or null if the entity was not teleported.
   */
  public Location teleport(Entity e, Location interaction) {
    if (this.counterpart != null) {
      if (!this.counterpart.isValid()) {
        PortalUtil.removePortal(this.counterpart);
        this.counterpart = null;
        PortalUtil.getCounterpartPortalFor(this);
      } else {
        BlockData bd = this.getWorldBlockType();
        if (bd != null
            && !bd.m.equals(Material.AIR)
            && !bd.m.equals(Material.OBSIDIAN)
            && !this.counterpart
                .getKeyBlock()
                .getWorld()
                .equals(PortalUtil.getDestWorldFor(this))) {

          // Did my keyblock change, and if so, change my destination.
          this.counterpart = null;
          PortalUtil.getCounterpartPortalFor(this);
        }
      }
    } else {
      PortalUtil.getCounterpartPortalFor(this);
    }

    if (this.counterpart == null) {
      // Could not establish a link, for whatever reason.
      return null;
    }

    double destX, destY, destZ;
    float destPitch, destYaw;
    int rotateVehicleVelocity = 0;

    Vector offset = interaction.toVector().subtract(this.keyBlock.getLocation().toVector());

    Vector finalOffset;

    if (this.facingNorth) {
      if (offset.getX() < .5) {
        // Player moving south.
        offset.setX(offset.getX() + OFFSET);
      } else {
        // Player moving north.
        offset.setX(offset.getX() - OFFSET);
      }

      if (this.counterpart.isFacingNorth()) {
        destYaw = e.getLocation().getYaw();
        finalOffset = offset;
      } else {
        destYaw = e.getLocation().getYaw() - 90;
        finalOffset = new Vector(offset.getZ(), offset.getY(), -offset.getX() + OFFSET);
        rotateVehicleVelocity = 1;
      }
    } else {
      if (offset.getZ() < .5) {
        // Player moving west
        offset.setZ(offset.getZ() + OFFSET);
      } else {
        // Player moving east.
        offset.setZ(offset.getZ() - OFFSET);
      }
      if (this.counterpart.isFacingNorth()) {
        destYaw = e.getLocation().getYaw() + 90;
        finalOffset = new Vector(-offset.getZ() + OFFSET, offset.getY(), offset.getX());
        rotateVehicleVelocity = 2;
      } else {
        destYaw = e.getLocation().getYaw();
        finalOffset = offset;
      }
    }

    World destWorld = this.counterpart.getKeyBlock().getWorld();
    String permission = "nethrar.block." + destWorld.getName();

    if ((Nethrar.getPlugin().shouldUsePermissions())
        && ((e instanceof Player))
        && (((Player) e).hasPermission(permission))
        && !((Player) e).isOp()) {
      return null;
    }

    destX = this.counterpart.getKeyBlock().getX() + finalOffset.getX();
    destY = this.counterpart.getKeyBlock().getY() + finalOffset.getY();
    destZ = this.counterpart.getKeyBlock().getZ() + finalOffset.getZ();

    destPitch = e.getLocation().getPitch();

    // Jitter the location just a bit so the resulting minecart doesn't
    // end up underground, if there is a minecart being teleported.
    if ((e instanceof Player && ((Player) e).isInsideVehicle())
        || (e instanceof Vehicle && !(e instanceof Pig))) {
      // +.11 is necessary to get a minecart to spawn on top of, instead
      // of inside, rails on the same level on the other side. However,
      // if there are *not* rails on the other side, then the minecart
      // will fall into the block underneath, unless a +1 is added.
      destY += 1.0;
    }

    Location dest;
    dest = new Location(destWorld, destX, destY, destZ, destYaw, destPitch);

    // Bug: Player camera orientation not preserved when teleporting
    // in a vehicle. Probably because vehicle takes over player
    // camera.
    Vehicle oldV = null, newV = null;
    if (e instanceof Player) {
      if (((Player) e).isInsideVehicle()) {
        oldV = (Vehicle) ((Player) e).getVehicle();
        ((Player) e).leaveVehicle();
      }
    } else if (e instanceof StorageMinecart || e instanceof Minecart || e instanceof Boat) {

      oldV = ((Vehicle) e);
    }

    if (oldV != null) {
      if (oldV instanceof StorageMinecart) {
        newV = destWorld.spawn(dest, StorageMinecart.class);
        ((StorageMinecart) newV)
            .getInventory()
            .setContents(((StorageMinecart) oldV).getInventory().getContents());
      } else if (oldV instanceof Minecart) {
        newV = destWorld.spawn(dest, Minecart.class);
      } else if (oldV instanceof Boat) {
        newV = destWorld.spawn(dest, Boat.class);
      } else {
        log.warning("[NETHRAR] Unsupported vehicle hit a portal.");
      }

      Vector oldVelocity = oldV.getVelocity();
      Vector newVelocity;
      switch (rotateVehicleVelocity) {
          // Left-handed system - clockwise is positive.
        case 1:
          // In a north-facing portal, out a west-facing portal.
          // Rotate 90 degrees counterclockwise.
          newVelocity = new Vector(oldVelocity.getZ(), oldVelocity.getY(), oldVelocity.getX() * -1);
          break;
        case 2:
          // In a west-facing portal, out a north-facing portal.
          // Rotate 90 degrees clockwise.
          newVelocity = new Vector(oldVelocity.getZ() * -1, oldVelocity.getY(), oldVelocity.getX());
          break;
        default:
          newVelocity = oldVelocity;
          break;
      }

      PortalUtil.markTeleported(e);
      Bukkit.getServer()
          .getScheduler()
          .scheduleSyncDelayedTask(
              PortalUtil.getPlugin(), new NethrarTeleporter(e, dest, newV, newVelocity, oldV));
    } else {
      PortalUtil.markTeleported(e);
      // Regular player teleportation doesn't need to be delayed.
      NethrarTeleporter tp = new NethrarTeleporter(e, dest);
      tp.run();
    }
    return null;
  }
示例#11
0
 private void flipXZ(Vector a) {
   double tempX = a.getX();
   a.setX(a.getZ());
   a.setZ(tempX);
 }
示例#12
0
  @Override
  public void run() {
    for (Location l : Storage.blackholes.keySet()) {
      for (Entity e : Utilities.getNearbyEntities(l, 10, 10, 10)) {
        if (e instanceof Player) {
          if (((Player) e).getGameMode().equals(CREATIVE)) {
            continue;
          }
        }
        if (Storage.blackholes.get(l)) {
          Vector v = l.clone().subtract(e.getLocation()).toVector();
          v.setX(v.getX() + (-.5f + Storage.rnd.nextFloat()) * 10);
          v.setY(v.getY() + (-.5f + Storage.rnd.nextFloat()) * 10);
          v.setZ(v.getZ() + (-.5f + Storage.rnd.nextFloat()) * 10);
          e.setVelocity(v.multiply(.35f));
          e.setFallDistance(0);
        } else {
          Vector v = e.getLocation().subtract(l.clone()).toVector();
          v.setX(v.getX() + (-.5f + Storage.rnd.nextFloat()) * 2);
          v.setY(v.getY() + Storage.rnd.nextFloat());
          v.setZ(v.getZ() + (-.5f + Storage.rnd.nextFloat()) * 2);
          e.setVelocity(v.multiply(.35f));
        }
      }
    }
    // Arrows
    toRemove.clear();
    for (Set<CustomArrow> pro : Storage.advancedProjectiles.values()) {
      for (CustomArrow a : pro) {
        a.onFlight();
        a.tick++;
        if (a.entity.isDead() || a.tick > 600) {
          toRemove.add(a);
        }
      }
    }
    for (CustomArrow pro : toRemove) {
      Storage.advancedProjectiles.remove(pro.entity);
      pro.entity.remove();
    }
    for (Block block : Storage.webs) {
      if (Storage.rnd.nextInt(175) == 0 && block.getChunk().isLoaded()) {
        block.setType(AIR);
        websToRemove.add(block);
      }
    }
    for (Block block : websToRemove) {
      Storage.webs.remove(block);
    }
    websToRemove.clear();
    for (LivingEntity ent : Storage.derpingEntities) {
      Location loc = ent.getLocation();
      loc.setYaw(Storage.rnd.nextFloat() * 360F);
      loc.setPitch(Storage.rnd.nextFloat() * 180F - 90F);
      ent.teleport(loc);
    }
    tick++;
    // Other stuff
    for (FallingBlock b : Storage.anthMobs2) {
      if (!Storage.anthVortex.contains(Storage.anthMobs.get(b))) {
        for (Entity e : b.getNearbyEntities(7, 7, 7)) {
          if (e instanceof LivingEntity) {
            LivingEntity lE = (LivingEntity) e;
            if (!(lE instanceof Player) && lE instanceof Monster) {
              b.setVelocity(e.getLocation().subtract(b.getLocation()).toVector().multiply(.25));
              if (lE.getLocation().getWorld().equals(b.getLocation().getWorld())) {
                if (lE.getLocation().distance(b.getLocation()) < 1.2) {
                  EntityDamageEvent evt =
                      new EntityDamageEvent(lE, EntityDamageEvent.DamageCause.SUFFOCATION, 100);
                  Bukkit.getPluginManager().callEvent(evt);
                  lE.setLastDamageCause(evt);
                  if (!evt.isCancelled()) {
                    lE.damage(8f);
                  }
                }
              }
            }
          }
        }
      }
    }
    boolean r = Storage.fallBool;
    Storage.fallBool = !Storage.fallBool;
    for (FallingBlock b : Storage.anthMobs.keySet()) {
      if (Storage.anthVortex.contains(Storage.anthMobs.get(b))) {
        Location loc = Storage.anthMobs.get(b).getLocation();
        Vector v;
        if (b.getLocation().getWorld().equals(Storage.anthMobs.get(b).getLocation().getWorld())) {
          if (r && b.getLocation().distance(Storage.anthMobs.get(b).getLocation()) < 10) {
            v = b.getLocation().subtract(loc).toVector();
          } else {
            int x = Storage.rnd.nextInt(12) - 6;
            int z = Storage.rnd.nextInt(12) - 6;
            Location tLoc = loc.clone();
            tLoc.setX(tLoc.getX() + x);
            tLoc.setZ(tLoc.getZ() + z);
            v = tLoc.subtract(b.getLocation()).toVector();
          }
          v.multiply(.05);
          boolean close = false;
          for (int x = -3; x < 0; x++) {
            if (b.getLocation().getBlock().getRelative(0, x, 0).getType() != AIR) {
              close = true;
            }
          }
          if (close) {
            v.setY(5);
          } else {
            v.setY(-.1);
          }
          b.setVelocity(v);
        }
      }
    }

    for (Arrow e : Storage.tracer.keySet()) {
      Entity close = null;
      double distance = 100;
      int level = Storage.tracer.get(e);
      level = level + 2;
      for (Entity e1 : e.getNearbyEntities(level, level, level)) {
        if (e1.getLocation().getWorld().equals(e.getLocation().getWorld())) {
          double d = e1.getLocation().distance(e.getLocation());
          if (e.getLocation()
              .getWorld()
              .equals(((Entity) e.getShooter()).getLocation().getWorld())) {
            if (d < distance
                && e1 instanceof LivingEntity
                && !e1.equals(e.getShooter())
                && e.getLocation().distance(((Entity) e.getShooter()).getLocation()) > 15) {
              distance = d;
              close = e1;
            }
          }
        }
      }
      if (close != null) {
        Location location = close.getLocation();
        org.bukkit.util.Vector v = new org.bukkit.util.Vector(0D, 0D, 0D);
        Location pos = e.getLocation();
        double its =
            Math.sqrt(
                (location.getBlockX() - pos.getBlockX()) * (location.getBlockX() - pos.getBlockX())
                    + (location.getBlockY() - pos.getBlockY())
                        * (location.getBlockY() - pos.getBlockY())
                    + (location.getBlockZ() - pos.getBlockZ())
                        * (location.getBlockZ() - pos.getBlockZ()));
        if (its == 0) {
          its = (double) 1;
        }
        v.setX((location.getBlockX() - pos.getBlockX()) / its);
        v.setY((location.getBlockY() - pos.getBlockY()) / its);
        v.setZ((location.getBlockZ() - pos.getBlockZ()) / its);
        e.setVelocity(v.multiply(2));
      }
    }

    for (Guardian g : Storage.guardianMove.keySet()) {
      if (g.getLocation().distance(Storage.guardianMove.get(g).getLocation()) > 2
          && g.getTicksLived() < 160) {
        g.setVelocity(
            Storage.guardianMove
                .get(g)
                .getLocation()
                .toVector()
                .subtract(g.getLocation().toVector()));
      } else {
        Storage.guardianMove.remove(g);
      }
    }

    for (Player player : Bukkit.getOnlinePlayers()) {
      Config config = Config.get(player.getWorld());
      for (ItemStack stk : player.getInventory().getArmorContents()) {
        HashMap<CustomEnchantment, Integer> map = config.getEnchants(stk);
        for (CustomEnchantment ench : map.keySet()) {
          ench.onFastScan(player, map.get(ench));
        }
      }
      HashMap<CustomEnchantment, Integer> map = config.getEnchants(player.getItemInHand());
      for (CustomEnchantment ench : map.keySet()) {
        ench.onFastScanHand(player, map.get(ench));
      }
    }
    HashSet<Player> toDelete = new HashSet<>();
    for (Player player : Storage.hungerPlayers.keySet()) {
      if (Storage.hungerPlayers.get(player) < 1) {
        toDelete.add(player);
      } else {
        Storage.hungerPlayers.put(player, Storage.hungerPlayers.get(player) - 1);
      }
    }
    for (Player p : toDelete) {
      Storage.hungerPlayers.remove(p);
    }
    toDelete.clear();
    for (Player player : Storage.moverBlockDecay.keySet()) {
      Storage.moverBlockDecay.put(player, Storage.moverBlockDecay.get(player) + 1);
      if (Storage.moverBlockDecay.get(player) > 5) {
        Storage.moverBlocks.remove(player);
        toDelete.add(player);
      }
    }
    for (Player p : toDelete) {
      Storage.moverBlockDecay.remove(p);
    }
  }