Java Code Examples for org.bukkit.Location#setYaw()
The following examples show how to use
org.bukkit.Location#setYaw() .
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
Source File: Portal.java From CardinalPGM with MIT License | 6 votes |
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 2
Source File: GeneralizingListener.java From PGM with GNU Affero General Public License v3.0 | 6 votes |
/** * 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
Source File: Utils.java From AreaShop with GNU General Public License v3.0 | 6 votes |
/** * 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 4
Source File: GameCreator.java From BedWars with GNU Lesser General Public License v3.0 | 6 votes |
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 5
Source File: SpawnModuleBuilder.java From CardinalPGM with MIT License | 6 votes |
private List<Pair<RegionModule, Vector>> getRegions(Element element){ List<Pair<RegionModule, Vector>> regions = new ArrayList<>(); for (Element region : element.getChildren()) { RegionModule current = RegionModuleBuilder.getRegion(region); Location location = new Location(GameHandler.getGameHandler().getMatchWorld(), 0, 0, 0); if (region.getParentElement().getParentElement().getParentElement().getAttributeValue("yaw") != null) location.setYaw(Float.parseFloat(region.getParentElement().getParentElement().getParentElement().getAttributeValue("yaw"))); if (region.getParentElement().getParentElement().getAttributeValue("yaw") != null) location.setYaw(Float.parseFloat(region.getParentElement().getParentElement().getAttributeValue("yaw"))); if (region.getParentElement().getAttributeValue("yaw") != null) location.setYaw(Float.parseFloat(region.getParentElement().getAttributeValue("yaw"))); if (region.getAttributeValue("yaw") != null) location.setYaw(Float.parseFloat(region.getAttributeValue("yaw"))); if (region.getParentElement().getParentElement().getParentElement().getAttributeValue("angle") != null) location.setDirection(parseAngle(region.getParentElement().getParentElement().getParentElement().getAttributeValue("angle")).subtract(current.getCenterBlock().getVector())); if (region.getParentElement().getParentElement().getAttributeValue("angle") != null) location.setDirection(parseAngle(region.getParentElement().getParentElement().getAttributeValue("angle")).subtract(current.getCenterBlock().getVector())); if (region.getParentElement().getAttributeValue("angle") != null) location.setDirection(parseAngle(region.getParentElement().getAttributeValue("angle")).subtract(current.getCenterBlock().getVector())); regions.add(new ImmutablePair<>(current, location.getDirection())); } return regions; }
Example 6
Source File: IslandGenerator.java From uSkyBlock with GNU General Public License v3.0 | 6 votes |
/** * Generate an island at the given {@link Location}. * @param playerPerk PlayerPerk object for the island owner. * @param next Location to generate an island. * @param cSchem New island schematic. * @return True if the island was generated, false otherwise. */ public boolean createIsland(@NotNull PlayerPerk playerPerk, @NotNull Location next, @Nullable String cSchem) { // Hacky, but clear the Orphan info next.setYaw(0); next.setPitch(0); next.setY((double) Settings.island_height); File schemFile = getSchematicFile(cSchem != null ? cSchem : "default"); File netherFile = getSchematicFile(cSchem != null ? cSchem + "Nether" : "uSkyBlockNether"); if (netherFile == null) { netherFile = netherSchematic; } if (schemFile.exists() && Bukkit.getServer().getPluginManager().isPluginEnabled("WorldEdit")) { AsyncWorldEditHandler.loadIslandSchematic(schemFile, next, playerPerk); World skyBlockNetherWorld = uSkyBlock.getInstance().getWorldManager().getNetherWorld(); if (skyBlockNetherWorld != null) { Location netherHome = new Location(skyBlockNetherWorld, next.getBlockX(), Settings.nether_height, next.getBlockZ()); AsyncWorldEditHandler.loadIslandSchematic(netherFile, netherHome, playerPerk); } return true; } else { return false; } }
Example 7
Source File: ChatConvIO.java From BetonQuest with GNU General Public License v3.0 | 6 votes |
/** * 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 File: DelayedChangeBlock.java From Skript with GNU General Public License v3.0 | 5 votes |
@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 9
Source File: TurnEffect.java From EffectLib with MIT License | 5 votes |
@Override public void onRun() { Entity entity = getEntity(); if (entity == null) { cancel(); return; } Location loc = entity.getLocation(); loc.setYaw(loc.getYaw() + step); entity.teleport(loc); }
Example 10
Source File: EffTeleport.java From Skript with GNU General Public License v3.0 | 5 votes |
@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 11
Source File: BlockStateBlock.java From Skript with GNU General Public License v3.0 | 5 votes |
@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 12
Source File: MoveEvent.java From Survival-Games with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void frozenSpawnHandler(PlayerMoveEvent e) { /* Optimization for single game world. No longer works since support for multiple worlds was added *if(e.getPlayer().getWorld()!=SettingsManager.getGameWorld()) return;*/ if(GameManager.getInstance().getPlayerGameId(e.getPlayer()) == -1){ playerpos.remove(e.getPlayer()); return; } if(GameManager.getInstance().getGame(GameManager.getInstance().getPlayerGameId(e.getPlayer())).getMode() == Game.GameMode.INGAME) return; GameMode mo3 = GameManager.getInstance().getGameMode(GameManager.getInstance().getPlayerGameId(e.getPlayer())); if(GameManager.getInstance().isPlayerActive(e.getPlayer()) && mo3 != Game.GameMode.INGAME){ if(playerpos.get(e.getPlayer()) == null){ playerpos.put(e.getPlayer(), e.getPlayer().getLocation().toVector()); return; } Location l = e.getPlayer().getLocation(); Vector v = playerpos.get(e.getPlayer()); if(l.getBlockX() != v.getBlockX() || l.getBlockZ() != v.getBlockZ()){ l.setX(v.getBlockX() + .5); l.setZ(v.getBlockZ() + .5); l.setYaw(e.getPlayer().getLocation().getYaw()); l.setPitch(e.getPlayer().getLocation().getPitch()); e.getPlayer().teleport(l); } } }
Example 13
Source File: FreezeListener.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@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 14
Source File: CraftBlockState.java From Kettle with GNU General Public License v3.0 | 5 votes |
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 15
Source File: CraftBlock.java From Thermos with GNU General Public License v3.0 | 5 votes |
public Location getLocation(Location loc) { if (loc != null) { loc.setWorld(getWorld()); loc.setX(x); loc.setY(y); loc.setZ(z); loc.setYaw(0); loc.setPitch(0); } return loc; }
Example 16
Source File: Post.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
public Location getReturnPoint(Flag flag, AngleProvider yawProvider) { Location location = getReturnPoint(flag); if (location instanceof PointProviderLocation && !((PointProviderLocation) location).hasYaw()) { location.setYaw(yawProvider.getAngle(location.toVector())); } return location; }
Example 17
Source File: FreezeMatchModule.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
@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 18
Source File: Banners.java From ProjectAres with GNU Affero General Public License v3.0 | 4 votes |
public static Location getLocationWithYaw(Banner block) { Location location = block.getLocation(); location.setYaw(BlockFaces.faceToYaw(((org.bukkit.material.Banner) block.getData()).getFacing())); return location; }
Example 19
Source File: PortalTransform.java From ProjectAres with GNU Affero General Public License v3.0 | 4 votes |
private Location mutate(Location v) { mutate(v.position()); v.setYaw((float) yaw.applyAsDouble(v.getYaw())); v.setPitch((float) pitch.applyAsDouble(v.getPitch())); return v; }
Example 20
Source File: SelectionHolder.java From AstralEdit with Apache License 2.0 | 4 votes |
/** * Rotates the selection unSecure * * @param yaw yaw */ void unSecureRotate(double yaw) { final Location location = this.getLocation(); location.setYaw((float) yaw); this.rotate(location); }