Java Code Examples for org.bukkit.Location#setPitch()

The following examples show how to use org.bukkit.Location#setPitch() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private String addSpawner(String type, Location loc, String customName, boolean hologramEnabled, double startLevel, org.screamingsandals.bedwars.api.Team team, int maxSpawnedResources) {
    if (game.getPos1() == null || game.getPos2() == null) {
        return i18n("admin_command_set_pos1_pos2_first");
    }
    if (game.getWorld() != loc.getWorld()) {
        return i18n("admin_command_must_be_in_same_world");
    }
    if (!isInArea(loc, game.getPos1(), game.getPos2())) {
        return i18n("admin_command_spawn_must_be_in_area");
    }
    loc.setYaw(0);
    loc.setPitch(0);
    ItemSpawnerType spawnerType = Main.getSpawnerType(type);
    if (spawnerType != null) {
        game.getSpawners().add(new ItemSpawner(loc, spawnerType, customName, hologramEnabled, startLevel, team, maxSpawnedResources));
        return i18n("admin_command_spawner_added").replace("%resource%", spawnerType.getItemName())
                .replace("%x%", Integer.toString(loc.getBlockX())).replace("%y%", Integer.toString(loc.getBlockY()))
                .replace("%z%", Integer.toString(loc.getBlockZ()));
    } else {
        return i18n("admin_command_invalid_spawner_type");
    }
}
 
Example 2
/**
 * Modify the to location of the given event to prevent the movement and move the player so they
 * are standing on the center of the block at the from location.
 */
private static void resetPosition(final PlayerMoveEvent event) {
  Location newLoc;
  double yValue = event.getFrom().getY();

  if (yValue <= 0 || event instanceof PlayerTeleportEvent) {
    newLoc = event.getFrom();
  } else {
    newLoc = BlockVectors.center(event.getFrom()).subtract(new Vector(0, 0.5, 0));
    if (newLoc.getBlock() != null) {
      switch (newLoc.getBlock().getType()) {
        case STEP:
        case WOOD_STEP:
          newLoc.add(new Vector(0, 0.5, 0));
          break;
        default:
          break;
      }
    }
  }

  newLoc.setPitch(event.getTo().getPitch());
  newLoc.setYaw(event.getTo().getYaw());
  event.setCancelled(false);
  event.setTo(newLoc);
}
 
Example 3
private String addSpawner(String type, Location loc, String customName, boolean hologramEnabled, double startLevel, org.screamingsandals.bedwars.api.Team team, int maxSpawnedResources) {
    if (game.getPos1() == null || game.getPos2() == null) {
        return i18n("admin_command_set_pos1_pos2_first");
    }
    if (game.getWorld() != loc.getWorld()) {
        return i18n("admin_command_must_be_in_same_world");
    }
    if (!isInArea(loc, game.getPos1(), game.getPos2())) {
        return i18n("admin_command_spawn_must_be_in_area");
    }
    loc.setYaw(0);
    loc.setPitch(0);
    ItemSpawnerType spawnerType = Main.getSpawnerType(type);
    if (spawnerType != null) {
        game.getSpawners().add(new ItemSpawner(loc, spawnerType, customName, hologramEnabled, startLevel, team, maxSpawnedResources));
        return i18n("admin_command_spawner_added").replace("%resource%", spawnerType.getItemName())
                .replace("%x%", Integer.toString(loc.getBlockX())).replace("%y%", Integer.toString(loc.getBlockY()))
                .replace("%z%", Integer.toString(loc.getBlockZ()));
    } else {
        return i18n("admin_command_invalid_spawner_type");
    }
}
 
Example 4
Source Project: CardinalPGM   File: Portal.java    License: MIT License 6 votes vote down vote up
private void tryTeleport(Player player, Location from, RegionModule destination, int dir) {
    if ((filter == null || filter.evaluate(player).equals(FilterState.ALLOW)) || ObserverModule.testObserver(player)) {
        if (destination != null) {
            from.setPosition(destination.getRandomPoint().getLocation().position());
        } else {
            from.setX(x.getLeft() ? from.getX() + (x.getRight() * dir) : x.getRight());
            from.setY(y.getLeft() ? from.getY() + (y.getRight() * dir) : y.getRight());
            from.setZ(z.getLeft() ? from.getZ() + (z.getRight() * dir) : z.getRight());
        }
        from.setYaw((float) (yaw.getLeft() ? from.getYaw() + (yaw.getRight() * dir) : yaw.getRight()));
        from.setPitch((float) (pitch.getLeft() ? from.getPitch() + (pitch.getRight() * dir) : pitch.getRight()));
        player.setFallDistance(0);
        player.teleport(from);
        if (sound) player.playSound(player.getLocation(), Sound.ENTITY_ENDERMEN_TELEPORT, 0.2F, 1);
    }
}
 
Example 5
@Override
protected final void arrow(final SnipeData v)
{
    Player player = v.owner().getPlayer();
    Location location = this.getLastBlock().getLocation();
    Location playerLocation = player.getLocation();
    location.setPitch(playerLocation.getPitch());
    location.setYaw(playerLocation.getYaw());
    location.setWorld(Bukkit.getWorld(location.getWorld().getName()));
    TaskManager.IMP.sync(new RunnableVal<Object>() {
        @Override
        public void run(Object value) {
            player.teleport(location);
        }
    });
}
 
Example 6
/**
 * Modify the to location of the given event to prevent the movement and
 * move the player so they are standing on the center of the block at the
 * from location.
 */
private static void resetPosition(final PlayerMoveEvent event) {
    Location newLoc;
    double yValue = event.getFrom().getY();

    if(yValue <= 0 || event instanceof PlayerTeleportEvent) {
        newLoc = event.getFrom();
    } else {
        newLoc = BlockUtils.center(event.getFrom()).subtract(new Vector(0, 0.5, 0));
        if(newLoc.getBlock() != null) {
            switch(newLoc.getBlock().getType()) {
            case STEP:
            case WOOD_STEP:
                newLoc.add(new Vector(0, 0.5, 0));
                break;
            default: break;
            }
        }
    }

    newLoc.setPitch(event.getTo().getPitch());
    newLoc.setYaw(event.getTo().getYaw());
    event.setCancelled(false);
    event.setTo(newLoc);
}
 
Example 7
/**
 * Moves the player back a few blocks in the conversation's center
 * direction.
 *
 * @param event PlayerMoveEvent event, for extracting the necessary data
 */
private void moveBack(PlayerMoveEvent event) {
    // if the player is in other world (he teleported himself), teleport him
    // back to the center of the conversation
    if (!event.getTo().getWorld().equals(conv.getLocation().getWorld()) || event.getTo()
            .distance(conv.getLocation()) > Integer.valueOf(Config.getString("config.max_npc_distance")) * 2) {
        event.getPlayer().teleport(conv.getLocation());
        return;
    }
    // if not, then calculate the vector
    float yaw = event.getTo().getYaw();
    float pitch = event.getTo().getPitch();
    Vector vector = new Vector(conv.getLocation().getX() - event.getTo().getX(),
            conv.getLocation().getY() - event.getTo().getY(), conv.getLocation().getZ() - event.getTo().getZ());
    vector = vector.multiply(1 / vector.length());
    // and teleport him back using this vector
    Location newLocation = event.getTo().clone();
    newLocation.add(vector);
    newLocation.setPitch(pitch);
    newLocation.setYaw(yaw);
    event.getPlayer().teleport(newLocation);
    if (Config.getString("config.notify_pullback").equalsIgnoreCase("true")) {
        conv.sendMessage(Config.getMessage(Config.getLanguage(), "pullback"));
    }
}
 
Example 8
Source Project: AreaShop   File: Utils.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Create a location from a map, reconstruction from the config values.
 * @param config The config section to reconstruct from
 * @return The location
 */
public static Location configToLocation(ConfigurationSection config) {
	if(config == null
			|| !config.isString("world")
			|| !config.isDouble("x")
			|| !config.isDouble("y")
			|| !config.isDouble("z")
			|| Bukkit.getWorld(config.getString("world")) == null) {
		return null;
	}
	Location result = new Location(
			Bukkit.getWorld(config.getString("world")),
			config.getDouble("x"),
			config.getDouble("y"),
			config.getDouble("z"));
	if(config.isString("yaw") && config.isString("pitch")) {
		result.setPitch(Float.parseFloat(config.getString("pitch")));
		result.setYaw(Float.parseFloat(config.getString("yaw")));
	}
	return result;
}
 
Example 9
Source Project: Kettle   File: CraftEntity.java    License: GNU General Public License v3.0 5 votes vote down vote up
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.getBukkitYaw());
        loc.setPitch(entity.rotationPitch);
    }

    return loc;
}
 
Example 10
public Location getLocation(Location loc) {
    if (loc != null) {
        loc.setWorld(world);
        loc.setX(x);
        loc.setY(y);
        loc.setZ(z);
        loc.setYaw(0);
        loc.setPitch(0);
    }

    return loc;
}
 
Example 11
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlayerMove(final PlayerMoveEvent event) {
    if(freeze.isFrozen(event.getPlayer())) {
        Location old = event.getFrom();
        old.setPitch(event.getTo().getPitch());
        old.setYaw(event.getTo().getYaw());
        event.setTo(old);
    }
}
 
Example 12
Source Project: Skript   File: EffTeleport.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void execute(final Event e) {
	Location to = location.getSingle(e);
	if (to == null)
		return;
	if (Math.abs(to.getX() - to.getBlockX() - 0.5) < Skript.EPSILON && Math.abs(to.getZ() - to.getBlockZ() - 0.5) < Skript.EPSILON) {
		final Block on = to.getBlock().getRelative(BlockFace.DOWN);
		if (on.getType() != Material.AIR) {
			to = to.clone();
			// TODO 1.13 block height stuff
			//to.setY(on.getY() + Utils.getBlockHeight(on.getTypeId(), on.getData()));
		}
	}
	for (final Entity entity : entities.getArray(e)) {
		final Location loc;
		if (ignoreDirection(to.getYaw(), to.getPitch())) {
			loc = to.clone();
			loc.setPitch(entity.getLocation().getPitch());
			loc.setYaw(entity.getLocation().getYaw());
		} else {
			loc = to;
		}
		loc.getChunk().load();
		if (e instanceof PlayerRespawnEvent && entity.equals(((PlayerRespawnEvent) e).getPlayer()) && !Delay.isDelayed(e)) {
			((PlayerRespawnEvent) e).setRespawnLocation(loc);
		} else {
			entity.teleport(loc);
		}
	}
}
 
Example 13
@Nullable
@Override
public Location getLocation(final @Nullable Location loc) {
	if (loc != null) {
		loc.setWorld(getWorld());
		loc.setX(getX());
		loc.setY(getY());
		loc.setZ(getZ());
		loc.setPitch(0);
		loc.setYaw(0);
	}
	return loc;
}
 
Example 14
@Nullable
@Override
public Location getLocation(final @Nullable Location loc) {
	if (loc != null) {
		loc.setWorld(getWorld());
		loc.setX(getX());
		loc.setY(getY());
		loc.setZ(getZ());
		loc.setPitch(0);
		loc.setYaw(0);
	}
	return loc;
}
 
Example 15
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerClickEvent(PlayerInteractEvent event) {
    Player player = event.getPlayer();
    try{
        if(GameManager.getInstance().isSpectator(player) && player.isSneaking() && (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_AIR)||
                GameManager.getInstance().isSpectator(player) && player.isSneaking() && (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_AIR)){
            Player[]players = GameManager.getInstance().getGame(GameManager.getInstance().getPlayerSpectateId(player)).getPlayers()[0];
            Game g = GameManager.getInstance().getGame(GameManager.getInstance().getPlayerSpectateId(player));

            int i = g.getNextSpec().get(player);
            if((event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_AIR)){
                i++;
            }
            else if(event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_AIR){
                i--;
            }
            if(i>players.length-1){
                i = 0;
            }
            if(i<0){
                i = players.length-1;
            }
            g.getNextSpec().put(player, i);
            Player tpto = players[i];
            Location l = tpto.getLocation();
            l.setYaw(0);
            l.setPitch(0);
            player.teleport(l);
            player.sendMessage(ChatColor.AQUA+"You are now spectating "+tpto.getName());
        }
        else if (GameManager.getInstance().isSpectator(player)) {
            event.setCancelled(true);
        }
    }
    catch(Exception e){e.printStackTrace();}
}
 
Example 16
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;
}
 
Example 17
@Override
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
	Player player = CommandValidator.getPlayerSender(sender);
	NamedHologram hologram = CommandValidator.getNamedHologram(args[0]);
	
	Location loc = hologram.getLocation();
	loc.setPitch(90);
	player.teleport(loc, TeleportCause.PLUGIN);
	player.sendMessage(Colors.PRIMARY + "You were teleported to the hologram named '" + hologram.getName() + "'.");

}
 
Example 18
public Location getLocation(Location loc) {
    if (loc != null) {
        loc.setWorld(world);
        loc.setX(x);
        loc.setY(y);
        loc.setZ(z);
        loc.setYaw(0);
        loc.setPitch(0);
    }

    return loc;
}
 
Example 19
private void activateEffects() {

        // display effects for all players
        for (Player player : Bukkit.getOnlinePlayers()) {

            // get NPC-effect assignments for this player
            Map<Integer, Effect> assignments = players.get(player.getUniqueId());

            // skip if there are no assignments for this player
            if (assignments == null) {
                continue;
            }

            // display effects on all NPCs
            for (Entry<Integer, Effect> entry : assignments.entrySet()) {
                Integer id = entry.getKey();
                Effect effect = entry.getValue();

                // skip this effect if it's not its time
                if (tick % effect.interval != 0) {
                    continue;
                }

                // get the NPC from its ID
                NPC npc = CitizensAPI.getNPCRegistry().getById(id);

                // skip if there are no such NPC or it's not spawned or not visible
                if (npc == null || !npc.isSpawned() || npc.getEntity().getWorld() != player.getWorld() ||
                        (NPCHider.getInstance() != null && NPCHider.getInstance().isInvisible(player, npc))) {
                    continue;
                }

                // prepare effect location
                Location loc = npc.getStoredLocation().clone();
                loc.setPitch(-90);

                // fire the effect
                EffectLibIntegrator.getEffectManager().start(
                        effect.name, 
                        effect.settings, 
                        new DynamicLocation(loc, null), 
                        new DynamicLocation(null, null), 
                        (ConfigurationSection) null, 
                        player);
            }
        }
    }
 
Example 20
@SuppressWarnings("deprecation")
@Override
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
	Player player = CommandValidator.getPlayerSender(sender);
	String hologramName = args[0];

	if (!hologramName.matches("[a-zA-Z0-9_\\-]+")) {
		throw new CommandException("The name must contain only alphanumeric chars, underscores and hyphens.");
	}

	CommandValidator.isTrue(!NamedHologramManager.isExistingHologram(hologramName), "A hologram with that name already exists.");

	Location spawnLoc = player.getLocation();
	boolean moveUp = player.isOnGround();

	if (moveUp) {
		spawnLoc.add(0.0, 1.2, 0.0);
	}

	NamedHologram hologram = new NamedHologram(spawnLoc, hologramName);

	if (args.length > 1) {
		String text = Utils.join(args, " ", 1, args.length);
		CommandValidator.isTrue(!text.equalsIgnoreCase("{empty}"), "The first line should not be empty.");
		
		CraftHologramLine line = CommandValidator.parseHologramLine(hologram, text, true);
		hologram.getLinesUnsafe().add(line);
		player.sendMessage(Colors.SECONDARY_SHADOW + "(Change the lines with /" + label + " edit " + hologram.getName() + ")");
	} else {
		hologram.appendTextLine("Default hologram. Change it with " + Colors.PRIMARY + "/" + label + " edit " + hologram.getName());
	}

	NamedHologramManager.addHologram(hologram);
	hologram.refreshAll();

	HologramDatabase.saveHologram(hologram);
	HologramDatabase.trySaveToDisk();
	Location look = player.getLocation();
	look.setPitch(90);
	player.teleport(look, TeleportCause.PLUGIN);
	player.sendMessage(Colors.PRIMARY + "You created a hologram named '" + hologram.getName() + "'.");

	if (moveUp) {
		player.sendMessage(Colors.SECONDARY_SHADOW + "(You were on the ground, the hologram was automatically moved up. If you use /" + label + " movehere " + hologram.getName() + ", the hologram will be moved to your feet)");
	}
}