static Location jitter(final Location teamSpawn, int index) {
    if (index == 0) return teamSpawn;
    index = index % 6;
    Location loc = teamSpawn.clone();

    switch (index) {
      case 0:
        break;
      case 1:
        loc.setX(loc.getX() - 1);
        break;
      case 2:
        loc.setX(loc.getX() + 1);
        break;
      case 3:
        loc.setZ(loc.getZ() - 1);
        break;
      case 4:
        loc.setZ(loc.getZ() + 1);
        break;
      case 5:
        loc.setX(loc.getX() + rand.nextDouble() - 0.5);
        loc.setZ(loc.getZ() + rand.nextDouble() - 0.5);
    }
    return loc;
  }
  @Test
  public void testAlignToDistance1024x1024() throws Exception {
    Location loc = new Location(null, 1024, 0, 1024);
    assertThat(
        LocationUtil.alignToDistance(loc, 1024),
        is(new Location(null, 1024, Settings.island_height, 1024)));

    loc.setX(511.9);
    loc.setZ(512.5);
    assertThat(
        LocationUtil.alignToDistance(loc, 1024),
        is(new Location(null, 0, Settings.island_height, 1024)));

    loc.setX(1535.9);
    loc.setZ(512.5);
    assertThat(
        LocationUtil.alignToDistance(loc, 1024),
        is(new Location(null, 1024, Settings.island_height, 1024)));

    loc.setX(-511.99);
    loc.setZ(-511.99);
    assertThat(
        LocationUtil.alignToDistance(loc, 1024),
        is(new Location(null, 0, Settings.island_height, 0)));

    loc.setX(-512.01);
    loc.setZ(-512.01);
    assertThat(
        LocationUtil.alignToDistance(loc, 1024),
        is(new Location(null, -1024, Settings.island_height, -1024)));
  }
Beispiel #3
0
  /**
   * Finds a teleport location for a spectator NEAR to another location
   *
   * <p>If possible, they will be placed 5 blocks away, facing towards the destination player.
   *
   * @param l the location they are to be teleported near to
   */
  public static Location getSpectatorTeleportLocation(Location l) {
    Location lp = new Location(l.getWorld(), l.getX(), l.getY(), l.getZ());
    Location lxp = new Location(l.getWorld(), l.getX(), l.getY(), l.getZ());
    Location lxn = new Location(l.getWorld(), l.getX(), l.getY(), l.getZ());
    Location lzp = new Location(l.getWorld(), l.getX(), l.getY(), l.getZ());
    Location lzn = new Location(l.getWorld(), l.getX(), l.getY(), l.getZ());
    Location tpl = new Location(l.getWorld(), l.getX(), l.getY(), l.getZ());
    boolean xp = true, xn = true, zp = true, zn = true;

    for (int i = 0; i < 5; i++) {
      if (xp) {
        lxp.setX(lxp.getX() + 1);
        if (!TeleportUtils.isSpaceForPlayer(lxp)) xp = false;
      }
      if (xn) {
        lxn.setX(lxn.getX() - 1);
        if (!TeleportUtils.isSpaceForPlayer(lxn)) xn = false;
      }
      if (zp) {
        lzp.setZ(lzp.getZ() + 1);
        if (!TeleportUtils.isSpaceForPlayer(lzp)) zp = false;
      }
      if (zn) {
        lzn.setZ(lzn.getZ() - 1);
        if (!TeleportUtils.isSpaceForPlayer(lzn)) zn = false;
      }
    }

    if (!xp) lxp.setX(lxp.getX() - 1);
    if (!xn) lxn.setX(lxn.getX() + 1);
    if (!zp) lzp.setZ(lzp.getZ() - 1);
    if (!zn) lzn.setZ(lzn.getZ() + 1);

    tpl.setYaw(90);
    tpl.setPitch(0);

    if (lxp.distanceSquared(lp) > tpl.distanceSquared(lp)) {
      tpl = lxp;
      tpl.setYaw(90);
    }
    if (lxn.distanceSquared(lp) > tpl.distanceSquared(lp)) {
      tpl = lxn;
      tpl.setYaw(270);
    }
    if (lzp.distanceSquared(lp) > tpl.distanceSquared(lp)) {
      tpl = lzp;
      tpl.setYaw(180);
    }
    if (lzn.distanceSquared(lp) > tpl.distanceSquared(lp)) {
      tpl = lzn;
      tpl.setYaw(0);
    }
    return tpl;
  }
Beispiel #4
0
 public static Region regionfromString(String str, String str2) {
   String[] Splits = str.split("\\:");
   Location loc = new Location(PiritaProtect.Plugin.getServer().getWorld(Splits[0]), 0, 0, 0);
   loc.setX(Double.parseDouble(Splits[1]));
   loc.setY(Double.parseDouble(Splits[2]));
   loc.setZ(Double.parseDouble(Splits[3]));
   Splits = str2.split("\\:");
   Location loc2 = new Location(PiritaProtect.Plugin.getServer().getWorld(Splits[0]), 0, 0, 0);
   loc2.setX(Double.parseDouble(Splits[1]));
   loc2.setY(Double.parseDouble(Splits[2]));
   loc2.setZ(Double.parseDouble(Splits[3]));
   Region cube = new Region(loc, loc2);
   return cube;
 }
 @EventHandler(priority = EventPriority.HIGHEST)
 public void onPlayerMove(PlayerMoveEvent event) {
   if (region.contains(event.getTo().toVector()) && !region.contains(event.getFrom().toVector())) {
     if ((filter == null || filter.evaluate(event.getPlayer()).equals(FilterState.ALLOW))
         || (TeamUtils.getTeamByPlayer(event.getPlayer()) != null
             && TeamUtils.getTeamByPlayer(event.getPlayer()).isObserver())
         || !GameHandler.getGameHandler().getMatch().isRunning()) {
       if (destination != null) {
         event.getPlayer().teleport(destination.getRandomPoint().getLocation());
         if (sound)
           event
               .getPlayer()
               .playSound(event.getPlayer().getLocation(), Sound.ENDERMAN_TELEPORT, 0.2F, 1);
       } else {
         Location newLocation = event.getTo();
         if (xRelative) newLocation.setX(newLocation.getX() + location.getX());
         else newLocation.setX(location.getX());
         if (yRelative) newLocation.setY(newLocation.getY() + location.getY());
         else newLocation.setY(location.getY());
         if (zRelative) newLocation.setZ(newLocation.getZ() + location.getZ());
         else newLocation.setZ(location.getZ());
         if (yawRelative) newLocation.setYaw(newLocation.getYaw() + yaw);
         else newLocation.setYaw(yaw);
         if (pitchRelative) newLocation.setPitch(newLocation.getPitch() + pitch);
         else newLocation.setPitch(pitch);
         event.getPlayer().teleport(newLocation);
         if (sound)
           event
               .getPlayer()
               .playSound(event.getPlayer().getLocation(), Sound.ENDERMAN_TELEPORT, 0.2F, 1);
       }
     }
   }
   if (destination != null
       && destination.contains(event.getTo().toVector())
       && !destination.contains(event.getFrom().toVector())
       && this.bidirectional) {
     if (filter == null
         || filter.evaluate(event.getPlayer()).equals(FilterState.ALLOW)
         || (TeamUtils.getTeamByPlayer(event.getPlayer()) != null
             && TeamUtils.getTeamByPlayer(event.getPlayer()).isObserver())
         || !GameHandler.getGameHandler().getMatch().isRunning()) {
       event.getPlayer().teleport(region.getRandomPoint().getLocation());
       if (sound)
         event
             .getPlayer()
             .playSound(event.getPlayer().getLocation(), Sound.ENDERMAN_TELEPORT, 0.2F, 1);
     }
   }
 }
Beispiel #6
0
  @Override
  public void run(Player player, String[] args) {
    try {
      Material block = player.getTargetBlock(null, 7).getType();
      if (block == Material.COBBLESTONE) {
        player.getTargetBlock(null, 7).setType(Material.STONE);
        player.getWorld().playSound(player.getLocation(), Sound.FIRE_IGNITE, 1, 1);
        Location loc = player.getTargetBlock(null, 7).getLocation();
        loc.setX(loc.getX() + 0.5);
        loc.setZ(loc.getZ() + 0.5);
        loc.setY(loc.getY() + 0.5);
        ParticleEffects.sendToLocation(ParticleEffects.FLAME, loc, 1, 1, 1, 0, 10);
      } else if (block == Material.SAND) {
        player.getTargetBlock(null, 7).setType(Material.GLASS);
        player.getWorld().playSound(player.getLocation(), Sound.FIRE_IGNITE, 1, 1);
        Location loc = player.getTargetBlock(null, 7).getLocation();
        loc.setX(loc.getX() + 0.5);
        loc.setZ(loc.getZ() + 0.5);
        loc.setY(loc.getY() + 0.5);
        ParticleEffects.sendToLocation(ParticleEffects.FLAME, loc, 1, 1, 1, 0, 10);
      } else if (block == Material.IRON_ORE) {
        Block b = player.getTargetBlock(null, 7);
        b.setType(Material.AIR);
        b.getWorld().dropItem(b.getLocation(), new ItemStack(Material.IRON_INGOT));
        player.getWorld().playSound(player.getLocation(), Sound.FIRE_IGNITE, 1, 1);
        Location loc = player.getTargetBlock(null, 7).getLocation();
        loc.setX(loc.getX() + 0.5);
        loc.setZ(loc.getZ() + 0.5);
        loc.setY(loc.getY() + 0.5);
        ParticleEffects.sendToLocation(ParticleEffects.FLAME, loc, 1, 1, 1, 0, 10);
      } else if (block == Material.GOLD_ORE) {
        Block b = player.getTargetBlock(null, 7);
        b.setType(Material.AIR);
        b.getWorld().dropItem(b.getLocation(), new ItemStack(Material.GOLD_INGOT));
        player.getWorld().playSound(player.getLocation(), Sound.FIRE_IGNITE, 1, 1);
        Location loc = player.getTargetBlock(null, 7).getLocation();
        loc.setX(loc.getX() + 0.5);
        loc.setZ(loc.getZ() + 0.5);
        loc.setY(loc.getY() + 0.5);
        ParticleEffects.sendToLocation(ParticleEffects.FLAME, loc, 1, 1, 1, 0, 30);
      } else {
        LivingEntity en = (LivingEntity) getTarget(player);
        player.getWorld().playSound(player.getLocation(), Sound.FIRE_IGNITE, 1, 1);
        en.setFireTicks(160);
      }
    } catch (Exception e) {

    }
  }
Beispiel #7
0
  private void playOutExplosion(GlowPlayer player, Iterable<BlockVector> blocks) {
    Collection<ExplosionMessage.Record> records = new ArrayList<>();

    Location clientLoc = location.clone();
    clientLoc.setX((int) clientLoc.getX());
    clientLoc.setY((int) clientLoc.getY());
    clientLoc.setZ((int) clientLoc.getZ());

    for (BlockVector block : blocks) {
      byte x = (byte) (block.getBlockX() - clientLoc.getBlockX());
      byte y = (byte) (block.getBlockY() - clientLoc.getBlockY());
      byte z = (byte) (block.getBlockZ() - clientLoc.getBlockZ());
      records.add(new ExplosionMessage.Record(x, y, z));
    }

    Vector velocity = player.getVelocity();
    ExplosionMessage message =
        new ExplosionMessage(
            (float) location.getX(),
            (float) location.getY(),
            (float) location.getZ(),
            5,
            (float) velocity.getX(),
            (float) velocity.getY(),
            (float) velocity.getZ(),
            records);

    player.getSession().send(message);
  }
  @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);
      }
    }
  }
 private List<Sign> checkZoneForSigns(Block topper, Block bottomer) {
   Location looking = new Location(topper.getWorld(), 0, 0, 0);
   List<Sign> signs = new ArrayList<Sign>();
   for (int x = topper.getX(); x <= bottomer.getX(); x++) {
     looking.setX(x);
     for (int y = bottomer.getY(); y <= topper.getY(); y++) {
       looking.setY(y);
       for (int z = topper.getZ(); z <= bottomer.getZ(); z++) {
         looking.setZ(z);
         this.plugin.log(
             Level.FINEST,
             "Looking for sign at "
                 + this.plugin.getCore().getLocationManipulation().strCoordsRaw(looking));
         Material isASign = topper.getWorld().getBlockAt(looking).getType();
         if (isASign == Material.WALL_SIGN || isASign == Material.SIGN_POST) {
           this.plugin.log(
               Level.FINER,
               "WOO Found one! "
                   + this.plugin.getCore().getLocationManipulation().strCoordsRaw(looking));
           signs.add((Sign) topper.getWorld().getBlockAt(looking).getState());
         }
       }
     }
   }
   return signs;
 }
  /**
   * Find a position for the player to stand that is not inside a block. Blocks above the player
   * will be iteratively tested until there is a series of two free blocks. The player will be
   * teleported to that free position.
   *
   * @param player
   */
  public static void findFreePosition(Player player) {
    Location loc = player.getLocation();
    int x = loc.getBlockX();
    int y = Math.max(0, loc.getBlockY());
    int origY = y;
    int z = loc.getBlockZ();
    World world = player.getWorld();

    byte free = 0;

    while (y <= world.getMaxHeight() + 1) {
      if (BlockType.canPassThrough(world.getBlockTypeIdAt(x, y, z))) {
        free++;
      } else {
        free = 0;
      }

      if (free == 2) {
        if (y - 1 != origY || y == 1) {
          loc.setX(x + 0.5);
          loc.setY(y);
          loc.setZ(z + 0.5);
          if (y <= 2 && world.getBlockAt(x, 0, z).getTypeId() == BlockID.AIR) {
            world.getBlockAt(x, 0, z).setTypeId(20);
            loc.setY(2);
          }
          player.setFallDistance(0F);
          player.teleport(loc);
        }
        return;
      }

      y++;
    }
  }
	@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
	public void onPlayerMove(final PlayerMoveEvent event)
	{
		final IUser user = userMap.getUser(event.getPlayer());

		final ISettings settings = ess.getSettings();

		if (user.getData().isAfk() && settings.getData().getCommands().getAfk().isFreezeAFKPlayers())
		{
			final Location from = event.getFrom();
			final Location to = event.getTo().clone();
			to.setX(from.getX());
			to.setY(from.getY());
			to.setZ(from.getZ());
			try
			{
				event.setTo(LocationUtil.getSafeDestination(to));
			}
			catch (Exception ex)
			{
				event.setTo(to);
			}
			return;
		}

		final Location afk = user.getAfkPosition();
		if (afk == null || !event.getTo().getWorld().equals(afk.getWorld()) || afk.distanceSquared(event.getTo()) > 9)
		{
			user.updateActivity(true);
		}
	}
  /**
   * Find a position for the player to stand that is not inside a block. Blocks above the player
   * will be iteratively tested until there is a series of two free blocks. The player will be
   * teleported to that free position.
   *
   * @param player
   */
  public void findFreePosition(Player player) {
    Location loc = player.getLocation();
    int x = loc.getBlockX();
    int y = Math.max(0, loc.getBlockY());
    int origY = y;
    int z = loc.getBlockZ();
    World world = player.getWorld();

    byte free = 0;

    while (y <= 129) {
      if (BlockType.canPassThrough(world.getBlockTypeIdAt(x, y, z))) {
        free++;
      } else {
        free = 0;
      }

      if (free == 2) {
        if (y - 1 != origY) {
          loc.setX(x + 0.5);
          loc.setY(y);
          loc.setZ(z + 0.5);
          player.teleportTo(loc);
        }

        return;
      }

      y++;
    }
  }
Beispiel #13
0
  public static void drop(Player p) {
    Location loc = new Location(Bukkit.getWorld("world"), 0, 0, 0);
    Random rand = new Random();
    loc.setX(rand.nextInt(8000));
    loc.setY(100);
    loc.setZ(rand.nextInt(8000));
    loc.setY(Bukkit.getWorld("world").getHighestBlockAt(loc.getBlockX(), loc.getBlockZ()).getY());
    loc.getBlock().setType(Material.CHEST);
    Block bb = loc.getBlock();
    bb.setType(Material.CHEST);
    Chest chest = (Chest) bb.getState();

    Inventory inv = chest.getInventory();

    for (ItemStack stack : items) {
      inv.addItem(stack);
    }

    Bukkit.broadcastMessage(
        ChatColor.RED + "A tornado has appeared in the world, and left valuble supplies!");
    Bukkit.broadcastMessage(
        ChatColor.translateAlternateColorCodes(
            '&',
            "&7Coords: X: &c"
                + loc.getBlockX()
                + "&7 Y:&c "
                + loc.getBlockY()
                + "&7 Z: &c"
                + loc.getBlockZ()));
  }
Beispiel #14
0
 /**
  * just like: from=to; except the pitch/yal is not reset; ie. keep the pitch/yaw of "from"
  *
  * @param from
  * @param to
  * @return from (unneeded but hey)
  */
 public static final Location setLocationExceptEye(Location from, Location to) {
   assert Q.nn(from);
   assert Q.nn(to);
   from.setWorld(to.getWorld());
   from.setX(to.getX());
   from.setY(to.getY());
   from.setZ(to.getZ());
   return from;
 }
Beispiel #15
0
  public Location getLocation(Location loc) {
    if (loc != null) {
      loc.setWorld(getWorld());
      loc.setX(entity.posX);
      loc.setY(entity.posY);
      loc.setZ(entity.posZ);
      loc.setYaw(entity.rotationYaw);
      loc.setPitch(entity.rotationPitch);
    }

    return loc;
  }
  public Location getLocation(Location loc) {
    if (loc != null) {
      loc.setWorld(getWorld());
      loc.setX(entity.locX);
      loc.setY(entity.locY);
      loc.setZ(entity.locZ);
      loc.setYaw(entity.yaw);
      loc.setPitch(entity.pitch);
    }

    return loc;
  }
Beispiel #17
0
  /**
   * Gets the Location of the given world's new player spawn.
   *
   * @param world The world to get the new player spawn for.
   * @return The Location of the new player spawn.
   */
  public Location getNewPlayerSpawn(String world) {
    Location spawn = this.getServer().getWorld(world).getSpawnLocation();

    if (deathSpawnExists(world)) {
      spawn.setX(spawns.getDouble("new-player-spawn." + world + ".x", spawn.getX()));
      spawn.setY(spawns.getDouble("new-player-spawn." + world + ".y", spawn.getY()));
      spawn.setZ(spawns.getDouble("new-player-spawn." + world + ".z", spawn.getZ()));
      spawn.setYaw(Float.parseFloat(spawns.getString("new-player-spawn." + world + ".yaw")));
      spawn.setPitch(Float.parseFloat(spawns.getString("new-player-spawn." + world + ".pitch")));
    }

    return spawn;
  }
 // All magic in this function happens cause vanilla minecraft
 // offset doesn't work properly by some reason
 private void sendToPlayer(Player p) {
   final float offset = 1f, mcoffset = 0.2f;
   Location loc = p.getLocation();
   int i = 0;
   double x = loc.getX(), y = loc.getY(), z = loc.getZ();
   Set<AbstractPacket> packets = new HashSet<>();
   do {
     loc.setY(y += (1 + R.nextInt(5)) * 0.15f);
     loc.setX(x + ((100 - R.nextInt(200)) / 100f * offset));
     loc.setZ(z + ((100 - R.nextInt(200)) / 100f * offset));
     packets.add(constructPacketForLocation(effect, loc, mcoffset, mcoffset, mcoffset, 0.75f, 6));
     ++i;
   } while (i < 4);
   sendPacketsToLocationInRadius(packets, loc, 48);
 }
 /** {@inheritDoc} */
 @Override
 public Location getSafeLocation(Location l, int tolerance, int radius) {
   // Check around the player first in a configurable radius:
   // TODO: Make this configurable
   Location safe = checkAboveAndBelowLocation(l, tolerance, radius);
   if (safe != null) {
     safe.setX(safe.getBlockX() + .5); // SUPPRESS CHECKSTYLE: MagicNumberCheck
     safe.setZ(safe.getBlockZ() + .5); // SUPPRESS CHECKSTYLE: MagicNumberCheck
     this.plugin.log(
         Level.FINE, "Hey! I found one: " + plugin.getLocationManipulation().strCoordsRaw(safe));
   } else {
     this.plugin.log(Level.FINE, "Uh oh! No safe place found!");
   }
   return safe;
 }
Beispiel #20
0
 @Override
 public Set<Player> selectPlayers(String param) {
   Set<Player> players = new HashSet<Player>();
   if (param.isEmpty()) return players;
   Param params = new Param(param, "loc");
   String locStr = params.getParam("loc");
   if (locStr.isEmpty()) return players;
   Location loc = Locator.parseLocation(locStr, null);
   if (loc == null) return players;
   loc.setX(loc.getBlockX() + 0.5);
   loc.setY(loc.getBlockY() + 0.5);
   loc.setZ(loc.getBlockZ() + 0.5);
   double radius = params.getParam("radius", 1.0);
   for (Player player : loc.getWorld().getPlayers())
     if (player.getLocation().distance(loc) <= radius) players.add(player);
   return players;
 }
	private void fixBlockGlitch(Player p, Block b) {
		Location bLoc = b.getLocation();
		Location pLoc = p.getLocation();

		if (shouldFix(pLoc, bLoc)) {
			if (!SimpleBlockData.isSolid(b.getTypeId()))
				return;

			bLoc.setY(bLoc.getY() + 1);
			bLoc.setX(pLoc.getX());
			bLoc.setZ(pLoc.getZ());
			bLoc.setPitch(pLoc.getPitch());
			bLoc.setYaw(pLoc.getYaw());

			p.teleport(bLoc);
		}
	}
Beispiel #22
0
  public static void createNuke(World world, Player player, String nukePlayerName) {
    List<Player> worldPlayers = world.getPlayers();
    Player nukedPlayer = null;
    Location nukedPlayerLocation = null;
    TNTPrimed tnt = null;
    int fuseTicks = 13;

    for (Player worldPlayer : worldPlayers) {
      if (worldPlayer.getDisplayName().equals(nukePlayerName)) {
        nukedPlayer = worldPlayer;
        nukedPlayerLocation = nukedPlayer.getLocation();
        break;
      }
    }

    if (nukedPlayerLocation != null) {
      double origX = nukedPlayerLocation.getX();
      double origY = nukedPlayerLocation.getY();
      double origZ = nukedPlayerLocation.getZ();

      // Height Loop
      for (double yIndex = origY + 5; yIndex <= origY + 10; yIndex += 2) {
        nukedPlayerLocation.setY(yIndex);
        tnt = world.spawn(nukedPlayerLocation, TNTPrimed.class);
        ((TNTPrimed) tnt).setFuseTicks(fuseTicks);

        // Forward/Backward Loop
        for (double zIndex = origZ - 1; zIndex <= origZ + 1; zIndex += 1) {
          nukedPlayerLocation.setZ(zIndex);
          tnt = world.spawn(nukedPlayerLocation, TNTPrimed.class);
          ((TNTPrimed) tnt).setFuseTicks(fuseTicks);

          // Left/Right Loop
          for (double xIndex = origX - 1; xIndex <= origX + 1; xIndex += 1) {
            nukedPlayerLocation.setX(xIndex);
            tnt = world.spawn(nukedPlayerLocation, TNTPrimed.class);
            ((TNTPrimed) tnt).setFuseTicks(fuseTicks);
          }
        }
      }

      Bukkit.broadcastMessage(
          nukedPlayer.getDisplayName() + " was nuked by " + player.getDisplayName() + ".");
    } else player.sendMessage("Player could not be found.");
  }
Beispiel #23
0
  /**
   * Called on player movement.
   *
   * @param event Relevant event details
   */
  @EventHandler
  public void onPlayerMove(PlayerMoveEvent event) {
    Player player = event.getPlayer();

    if (player.getVehicle() != null) return; // handled in vehicle listener
    if (event.getFrom().getBlockX() != event.getTo().getBlockX()
        || event.getFrom().getBlockY() != event.getTo().getBlockY()
        || event.getFrom().getBlockZ() != event.getTo().getBlockZ()) {

      if (sessions.getAdminSession(player).isFrozen()) {

        player.sendMessage(ChatColor.RED + "You are frozen.");

        Location newLoc = event.getFrom();
        newLoc.setX(newLoc.getBlockX() + 0.5);
        newLoc.setY(newLoc.getBlockY());
        newLoc.setZ(newLoc.getBlockZ() + 0.5);
        event.setTo(newLoc);
      }
    }
  }
  private void Murus(String[] components, PlayerChatEvent ev) {
    boolean overwrite = IsForceful(components, ev);
    Material component = GetMaterial(components[(this.n + 1)]);
    int length = 5 + 15 * this.size / 2;
    Vector vector = ev.getPlayer().getEyeLocation().getDirection().normalize();
    Location location;
    if (IsFlying(components, ev))
      location = ev.getPlayer().getTargetBlock(null, 10 + 5 * this.size).getLocation();
    else location = ev.getPlayer().getTargetBlock(null, 500).getLocation();
    int xorg = location.getBlockX();
    int yorg = location.getBlockY();
    int zorg = location.getBlockZ();
    double vx = vector.getX();
    double vz = vector.getZ();
    double ox = -vz;
    double oz = vx;
    for (int i = -length / 2; i <= length / 2 + 1; i++) {
      location.setX(xorg + i * ox);
      location.setZ(zorg + i * oz);
      for (int y = Math.max(yorg, 1); y <= Math.min(yorg + length / 2, 120); y++) {
        location.setY(y);
        Block block = location.getBlock();
        Material type = block.getType();
        if ((overwrite) && (type != Material.BEDROCK)) {
          block.setType(component);
        } else {
          if (type != Material.AIR) continue;
          block.setType(component);
        }
      }
    }

    if (IsMotion(components, ev))
      ev.getPlayer()
          .teleport(
              new Vector(xorg, yorg + length / 2 + 1, zorg).toLocation(ev.getPlayer().getWorld()));
  }
Beispiel #25
0
  public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {

    Player player = null;

    switch (cmd.getName()) {
      case "stp":
        if (args[0].equals("time")) {
          int r_time = 0;

          if (args.length == 1) {
            sender.sendMessage(ChatColor.RED + "時間(分)を入力してください");
            return false;
          }

          try {
            r_time = Integer.parseInt(args[1]);
          } catch (NumberFormatException nfex) {
            sender.sendMessage(ChatColor.RED + "時間を正しく入力してください");
            doError(sender, nfex);
            return false;
          }

          if (r_time < 0 || r_time > 60) {
            sender.sendMessage(ChatColor.RED + "時間(分)は0~60の間で設定してください");
            return false;
          }

          getConfig().set("reload_time", r_time);
          saveConfig();

          sender.sendMessage(ChatColor.AQUA + "更新時間を" + args[1] + "分に設定しました");

        } else {
          int tp_number;

          player = (Player) sender; // get player of do command

          try {
            tp_number = Integer.parseInt(args[0]);
          } catch (NumberFormatException nfex) {
            sender.sendMessage(ChatColor.RED + "TPナンバーを正しく入力してください");
            doError(sender, nfex);
            return false;
          }

          if (tp_number < 0 || tp_number > 9) {
            sender.sendMessage(ChatColor.RED + "TPナンバーは0〜9で入力してください");
            return true;
          }

          Location tplocset = player.getLocation();
          getConfig().set("at.X" + tp_number, tplocset.getX());
          getConfig().set("at.Y" + tp_number, tplocset.getY());
          getConfig().set("at.Z" + tp_number, tplocset.getZ());
          saveConfig();

          sender.sendMessage(ChatColor.AQUA + "TP" + args[0] + "を設定しました");
        }
        break;
      case "ctp":
        if ((sender instanceof Player) == false && args.length == 0) {
          sender.sendMessage(ChatColor.RED + "ゲーム内から実行するか、TP対象のプレイヤーを指定してください");
          return false;
        }

        Calendar now = Calendar.getInstance();

        if (args.length != 0) {
          try {
            player = getPlayer(args[0]);
          } catch (Exception e) {
            doError(sender, e);
            return false;
          }

          if (player == null) {
            sender.sendMessage(ChatColor.RED + args[0] + "さんはオフラインです");
            return true;
          }
        } else if ((sender instanceof Player)) {
          player = (Player) sender; // get player of do command
        }

        // Init
        if (tp_number_ctp == -1) {
          tp_number_ctp = 0;
          minute = now.get(now.MINUTE);
        }

        if (now.get(now.MINUTE) - minute > getConfig().getInt("reload_time") - 1
            || now.get(now.MINUTE) - minute < 0) {
          minute = now.get(now.MINUTE);
          tp_number_ctp++;
        }

        if (tp_number_ctp < 0) tp_number_ctp = 9;
        else if (tp_number_ctp > 9) tp_number_ctp = 0;

        Location tplocset1 = player.getLocation();
        tplocset1.setX(getConfig().getDouble("at.X" + tp_number_ctp));
        tplocset1.setY(getConfig().getDouble("at.Y" + tp_number_ctp));
        tplocset1.setZ(getConfig().getDouble("at.Z" + tp_number_ctp));

        if (tplocset1 == null) {
          sender.sendMessage(ChatColor.RED + "TP" + tp_number_ctp + "が設定されていません");
          return true;
        }

        player.teleport(tplocset1);

        getLogger().info(player.toString() + "をTP" + tp_number_ctp + "にTPしました");

        break;
    }
    return true;
  }
Beispiel #26
0
  private void makeItSo(Player player) {
    // start with the block shifted vertically from the player
    // to the destination sign's height (plus one).
    // check if this looks at all like something we're interested in first

    double toX = 0;
    double toY = 0;
    double toZ = 0;

    if (trigger.getState() instanceof Sign) {
      Sign s = (Sign) trigger.getState();
      String[] pos = s.getLine(2).split(":");
      if (pos.length > 2) {
        try {
          toX = Double.parseDouble(pos[0]);
          toY = Double.parseDouble(pos[1]);
          toZ = Double.parseDouble(pos[2]);
        } catch (Exception e) {
          return;
        }
      } else return;
    }

    Block floor =
        trigger
            .getWorld()
            .getBlockAt((int) Math.floor(toX), (int) (Math.floor(toY) + 1), (int) Math.floor(toZ));
    // well, unless that's already a ceiling.
    if (!occupiable(floor)) floor = floor.getRelative(BlockFace.DOWN);

    // now iterate down until we find enough open space to stand in
    // or until we're 5 blocks away, which we consider too far.
    int foundFree = 0;
    for (int i = 0; i < 5; i++) {
      if (occupiable(floor)) {
        foundFree++;
      } else {
        break;
      }
      if (floor.getY() == 0x0) // hit the bottom of the world
      break;
      floor = floor.getRelative(BlockFace.DOWN);
    }
    if (foundFree < 2) {
      player.sendMessage("mech.lift.obstruct");
      return;
    }

    // Teleport!
    Location subspaceRift = player.getLocation().clone();
    subspaceRift.setY(floor.getY() + 1);
    subspaceRift.setX(floor.getX());
    subspaceRift.setZ(floor.getZ());
    if (player.isInsideVehicle()) {
      subspaceRift = player.getVehicle().getLocation().clone();
      subspaceRift.setY(floor.getY() + 2);
      subspaceRift.setX(floor.getX());
      subspaceRift.setZ(floor.getZ());
      player.getVehicle().teleport(subspaceRift);
    }
    player.teleport(subspaceRift);

    player.sendMessage("mech.teleport.alert");
  }
Beispiel #27
0
    /** Starts the initial animation, and removes itself when it is finished. */
    public void run() {
      Location tempLoc;
      if (target != null) {
        tempLoc = target.getEyeLocation();
        tempLoc.setY(tempLoc.getY() - 0.5);
      } else {
        tempLoc = startLoc.clone();
      }

      if (type == SpiralType.HORIZONTAL1) {
        loc.setX(
            tempLoc.getX()
                + radius * Math.cos(Math.toRadians((double) i / (double) totalSteps * 360)));
        loc.setY(tempLoc.getY() + dy * i);
        loc.setZ(
            tempLoc.getZ()
                + radius * Math.sin(Math.toRadians((double) i / (double) totalSteps * 360)));
      } else if (type == SpiralType.HORIZONTAL2) {
        loc.setX(
            tempLoc.getX()
                + radius * -Math.cos(Math.toRadians((double) i / (double) totalSteps * 360)));
        loc.setY(tempLoc.getY() + dy * i);
        loc.setZ(
            tempLoc.getZ()
                + radius * -Math.sin(Math.toRadians((double) i / (double) totalSteps * 360)));
      } else if (type == SpiralType.VERTICAL1) {
        loc.setX(
            tempLoc.getX()
                + radius * Math.sin(Math.toRadians((double) i / (double) totalSteps * 360)));
        loc.setY(
            tempLoc.getY()
                + radius * Math.cos(Math.toRadians((double) i / (double) totalSteps * 360)));
        loc.setZ(tempLoc.getZ() + dz * i);
      } else if (type == SpiralType.VERTICAL2) {
        loc.setX(tempLoc.getX() + dx * i);
        loc.setY(
            tempLoc.getY()
                + radius * Math.sin(Math.toRadians((double) i / (double) totalSteps * 360)));
        loc.setZ(
            tempLoc.getZ()
                + radius * Math.cos(Math.toRadians((double) i / (double) totalSteps * 360)));
      } else if (type == SpiralType.DIAGONAL1) {
        loc.setX(
            tempLoc.getX()
                + radius * Math.cos(Math.toRadians((double) i / (double) totalSteps * 360)));
        loc.setY(
            tempLoc.getY()
                + radius * Math.sin(Math.toRadians((double) i / (double) totalSteps * 360)));
        loc.setZ(
            tempLoc.getZ()
                + radius * -Math.cos(Math.toRadians((double) i / (double) totalSteps * 360)));
      } else if (type == SpiralType.DIAGONAL2) {
        loc.setX(
            tempLoc.getX()
                + radius * Math.cos(Math.toRadians((double) i / (double) totalSteps * 360)));
        loc.setY(
            tempLoc.getY()
                + radius * Math.sin(Math.toRadians((double) i / (double) totalSteps * 360)));
        loc.setZ(
            tempLoc.getZ()
                + radius * Math.cos(Math.toRadians((double) i / (double) totalSteps * 360)));
      }

      AirMethods.getAirbendingParticles().display(loc, (float) 0, (float) 0, (float) 0, 0, 1);
      if (i == totalSteps + 1) this.cancel();
      i++;
    }
Beispiel #28
0
  // Command
  public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    // Check for player
    if (sender instanceof Player) {
      // Store player and command
      Player player = (Player) sender;
      String command = cmd.getName().toUpperCase();

      // Check command
      if (command.equals("IPARKOUR")) {
        // Check for perms
        if (player.hasPermission("iParkour.iparkour")) {
          // Check args
          if (args.length == 0) {
            // Display a list of commands
            for (String str : helpMsgs) {
              player.sendMessage(str);
            }
            return true;

          } else if (args.length == 1) {
            // See which sub command
            String subCMD = args[0].toUpperCase();

            // EDIT
            if (subCMD.equals("EDIT")) {
              // Check for perms
              if (player.hasPermission("iParkour.iparkour.edit")) {
                // Check player's gamemode
                if (player.getGameMode().equals(GameMode.CREATIVE)) {
                  try {
                    new WorldInventory(plugin);
                    MenuManager mm = new MenuManager();
                    player.openInventory(mm.getMenu("World List"));
                  } catch (NullPointerException npe) {
                    player.sendMessage(
                        ChatColor.GREEN
                            + ""
                            + ChatColor.BOLD
                            + "[iParkour] "
                            + ChatColor.RED
                            + "There are not any points registered on this server.");
                  }
                  return true;
                } else {
                  player.sendMessage(
                      ChatColor.GREEN
                          + ""
                          + ChatColor.BOLD
                          + "[iParkour] "
                          + ChatColor.RED
                          + "You must be in CREATIVE mode to use this command.");
                }

              } else { // No perms
                player.sendMessage(
                    ChatColor.GREEN
                        + ""
                        + ChatColor.BOLD
                        + "[iParkour] "
                        + ChatColor.RED
                        + "You do not have permission to use this command.");
                return true;
              }
              // CHECKPOINT
            } else if (subCMD.equals("CHECKPOINT")) {
              // Check for perms
              if (player.hasPermission("iParkour.iparkour.checkpoint")) {
                // Check if the player has started
                PlayerInfo pInfo = new PlayerInfo(player, plugin);
                if (pInfo.getHasStarted()) {
                  String lastCP = pInfo.getLastCP();
                  if (lastCP.equals("null")) {
                    player.sendMessage(
                        ChatColor.GREEN
                            + ""
                            + ChatColor.BOLD
                            + "[iParkour] "
                            + ChatColor.GOLD
                            + "You have not reached a Checkpoint yet!");
                    return true;
                  } else {
                    Point pointInfo = new Point(plugin, player.getWorld(), pInfo.getLastCP());
                    Location cpLoc = pointInfo.getLocation();
                    cpLoc.setX(cpLoc.getX() + .5);
                    cpLoc.setY(cpLoc.getY() + .5);
                    cpLoc.setZ(cpLoc.getZ() + .5);
                    cpLoc.setYaw(player.getLocation().getYaw());
                    player.teleport(cpLoc);
                    player.sendMessage(
                        ChatColor.GREEN
                            + ""
                            + ChatColor.BOLD
                            + "[iParkour] "
                            + ChatColor.GOLD
                            + "You were teleported to "
                            + ChatColor.GREEN
                            + ""
                            + ChatColor.BOLD
                            + lastCP
                            + ChatColor.GOLD
                            + "!");
                    return true;
                  }
                } else {
                  player.sendMessage(
                      ChatColor.GREEN
                          + ""
                          + ChatColor.BOLD
                          + "[iParkour] "
                          + ChatColor.GOLD
                          + "You have to start before you can use a Checkpoint!");
                  return true;
                }
              } else { // No perms
                player.sendMessage(
                    ChatColor.GREEN
                        + ""
                        + ChatColor.BOLD
                        + "[iParkour] "
                        + ChatColor.RED
                        + "You do not have permission to use this command.");
                return true;
              }
            }
            return true;
          }
        } else { // No perms
          player.sendMessage(
              ChatColor.GREEN
                  + ""
                  + ChatColor.BOLD
                  + "[iParkour] "
                  + ChatColor.RED
                  + "You do not have permission to use this command.");
          return true;
        }
      } // Else do nothing

      // Else give sender error
    } else {
      sender.sendMessage("[iParkour] This command is only for players!");
    }
    return true;
  }
  @Command(
      aliases = {"vteleport", "vtp"},
      bounds = {1, 2},
      help =
          "Teleport to other people with /vtp [player]\n"
              + "Teleport to other people at an offset with /vtp [player] [x,y,z][num]\n"
              + "Teleport others to you with /vtp [player] me",
      playerOnly = true)
  @CommandPermission(permission = "voxelguest.miscellaneous.vtp")
  public void vteleport(CommandSender cs, String[] args) {
    if (args != null && args.length > 0) {
      Player p = (Player) cs;

      List<Player> l = Bukkit.matchPlayer(args[0]);
      if (l.size() > 1) {
        p.sendMessage(ChatColor.RED + "Partial match");
      } else if (l.isEmpty()) {
        p.sendMessage(ChatColor.RED + "No player to match");
      } else {
        Player pl = l.get(0);
        Location loc = pl.getLocation();

        p.sendMessage(ChatColor.AQUA + "Woosh!");

        if (args.length < 2) {
          p.teleport(loc);
        } else {
          if (args[1].matches("me")) {
            insertHistoryEntry(pl, pl.getLocation());
            pl.sendMessage(ChatColor.DARK_AQUA + "Woosh!");
            pl.teleport(p.getLocation());
            return;
          }

          for (int i = 1; i < args.length; i++) {
            try {
              if (args[i].startsWith("x")) {
                loc.setX(loc.getX() + Double.parseDouble(args[i].replace("x", "")));
                continue;
              } else if (args[i].startsWith("y")) {
                loc.setY(loc.getY() + Double.parseDouble(args[i].replace("y", "")));
                continue;
              } else if (args[i].startsWith("z")) {
                loc.setZ(loc.getZ() + Double.parseDouble(args[i].replace("z", "")));
                continue;
              }
            } catch (NumberFormatException e) {
              p.sendMessage(ChatColor.RED + "Error parsing argument \"" + args[i] + "\"");
              return;
            }
          }

          insertHistoryEntry(p, p.getLocation());
          p.teleport(loc);
        }
      }
      return;
    } else {
      cs.sendMessage(ChatColor.RED + "Please specify the target player.");
      return;
    }
  }
Beispiel #30
0
 void setX(double x) {
   bukkitLocation.setX(x);
 }