Java Code Examples for org.bukkit.Location#setY()
The following examples show how to use
org.bukkit.Location#setY() .
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: Holograms.java From HubBasics with GNU Lesser General Public License v3.0 | 6 votes |
private JSONArray spawnLines(Location loc, String[] lines) { int lineIndex = 0; JSONArray array = new JSONArray(); for (String str : lines) { ArmorStand armorStand = (ArmorStand) loc.getWorld().spawnEntity(loc, EntityType.ARMOR_STAND); armorStand.setGravity(false); armorStand.setVisible(false); armorStand.setCustomName(ChatColor.translateAlternateColorCodes('&', str)); armorStand.setCustomNameVisible(true); armorStand.setRemoveWhenFarAway(false); loc.setY(loc.getY() - 0.25); JSONObject object = new JSONObject(); object.put(ARMORSTAND_LINE, lineIndex); object.put(ARMORSTAND_TEXT, str); object.put(ARMORSTAND_UUID, armorStand.getUniqueId().toString()); array.put(lineIndex, object); lineIndex++; } return array; }
Example 2
Source File: SignGUIImpl.java From NovaGuilds with GNU General Public License v3.0 | 6 votes |
@Override public void open(Player player, String[] defaultText, SignGUIListener response) { try { final List<Packet> packets = new ArrayList<>(); Location location = player.getLocation().clone(); location.setY(0); if(defaultText != null) { packets.add(new PacketPlayOutBlockChange(location, CompatibilityUtils.Mat.SIGN.get(), 0)); packets.add(new PacketPlayOutUpdateSign(location, defaultText)); } packets.add(new PacketPlayOutOpenSignEditor(location)); if(defaultText != null) { packets.add(new PacketPlayOutBlockChange(location, null, 0)); } signLocations.put(player.getUniqueId(), location); listeners.put(player.getUniqueId(), response); PacketSender.sendPacket(player, packets.toArray(new Packet[packets.size()])); } catch(NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException e) { LoggerUtils.exception(e); } }
Example 3
Source File: SpleefTracker.java From CardinalPGM with MIT License | 6 votes |
@EventHandler(priority = EventPriority.MONITOR) public void onBlockBreak(BlockBreakEvent event) { if (event.isCancelled() || GameHandler.getGameHandler().getMatch().getModules().getModule(TitleRespawn.class).isDeadUUID(event.getPlayer().getUniqueId())) return; for (Player player : Bukkit.getOnlinePlayers()) { Location location = event.getBlock().getLocation(); location.setY(location.getY() + 1); Location playerLoc = player.getLocation(); if (playerLoc.getBlockX() == location.getBlockX() && playerLoc.getBlockY() == location.getBlockY() && playerLoc.getBlockZ() == location.getBlockZ()) { Description description = null; if (player.getLocation().add(new Vector(0, 1, 0)).getBlock().getType().equals(Material.LADDER)) { description = Description.OFF_A_LADDER; } else if (player.getLocation().add(new Vector(0, 1, 0)).getBlock().getType().equals(Material.VINE)) { description = Description.OFF_A_VINE; } else if (player.getLocation().getBlock().getType().equals(Material.WATER) || player.getLocation().getBlock().getType().equals(Material.STATIONARY_WATER)) { description = Description.OUT_OF_THE_WATER; } else if (player.getLocation().getBlock().getType().equals(Material.LAVA) || player.getLocation().getBlock().getType().equals(Material.STATIONARY_LAVA)) { description = Description.OUT_OF_THE_LAVA; } Bukkit.getServer().getPluginManager().callEvent(new TrackerDamageEvent(player, event.getPlayer(), event.getPlayer().getItemInHand(), Cause.PLAYER, description, Type.SPLEEFED)); } } }
Example 4
Source File: CommandParticle.java From Carbon with GNU Lesser General Public License v3.0 | 6 votes |
private Location getLocation(CommandSender sender, boolean color, Location location, String x, String y, String z) { boolean xRelative = x.startsWith("~"); boolean yRelative = y.startsWith("~"); boolean zRelative = z.startsWith("~"); double dX = parseDouble(sender, color, x.replaceAll("~", "")); double dY = parseDouble(sender, color, y.replaceAll("~", "")); double dZ = parseDouble(sender, color, z.replaceAll("~", "")); Location finalloc = location; if (xRelative) { finalloc = finalloc.add(dX, 0D, 0D); } else { finalloc.setX(dX); } if (yRelative) { finalloc = finalloc.add(0D, dY, 0D); } else { finalloc.setY(dY); } if (zRelative) { finalloc = finalloc.add(0D, 0D, dZ); } else { finalloc.setZ(dZ); } return finalloc; }
Example 5
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 6
Source File: HeightValidator.java From RandomTeleport with GNU General Public License v3.0 | 6 votes |
@Override public boolean validate(RandomSearcher searcher, Location location) { Block block = location.getWorld().getHighestBlockAt(location); if (block.getY() > searcher.getMaxY()) { block = location.getWorld().getBlockAt( block.getX(), searcher.getMinY() + searcher.getRandom().nextInt(searcher.getMaxY() - searcher.getMinY()), block.getZ() ); } while (block.isEmpty()) { block = block.getRelative(BlockFace.DOWN); if (block == null || block.getY() < searcher.getMinY()) { return false; } } location.setY(block.getY()); return !block.getRelative(BlockFace.UP).getType().isSolid() && !block.getRelative(BlockFace.UP, 2).getType().isSolid(); }
Example 7
Source File: SpleefTracker.java From CardinalPGM with MIT License | 6 votes |
@EventHandler(priority = EventPriority.MONITOR) public void onEntityExplode(EntityExplodeEvent event) { if (event.isCancelled() || GameHandler.getGameHandler().getMatch().getModules().getModule(TitleRespawn.class).isDeadUUID(event.getEntity().getUniqueId())) return; for (Block block : event.blockList()) { for (Player player : Bukkit.getOnlinePlayers()) { Location location = block.getLocation(); location.setY(location.getY() + 1); Location playerLoc = player.getLocation(); if (playerLoc.getBlockX() == location.getBlockX() && playerLoc.getBlockY() == location.getBlockY() && playerLoc.getBlockZ() == location.getBlockZ()) { Description description = null; if (player.getLocation().add(new Vector(0, 1, 0)).getBlock().getType().equals(Material.LADDER)) { description = Description.OFF_A_LADDER; } else if (player.getLocation().add(new Vector(0, 1, 0)).getBlock().getType().equals(Material.VINE)) { description = Description.OFF_A_VINE; } else if (player.getLocation().getBlock().getType().equals(Material.WATER) || player.getLocation().getBlock().getType().equals(Material.STATIONARY_WATER)) { description = Description.OUT_OF_THE_WATER; } else if (player.getLocation().getBlock().getType().equals(Material.LAVA) || player.getLocation().getBlock().getType().equals(Material.STATIONARY_LAVA)) { description = Description.OUT_OF_THE_LAVA; } OfflinePlayer damager = (TntTracker.getWhoPlaced(event.getEntity()) != null ? Bukkit.getOfflinePlayer(TntTracker.getWhoPlaced(event.getEntity())) : null); Bukkit.getServer().getPluginManager().callEvent(new TrackerDamageEvent(player, damager, damager != null && damager.getPlayer() != null ? ((Player) damager).getInventory().getItemInMainHand() : new ItemStack(Material.AIR), Cause.TNT, description, Type.SPLEEFED)); } } } }
Example 8
Source File: Scout.java From AnnihilationPro with MIT License | 6 votes |
private void pullEntityToLocation(Entity e, Location loc) { Location entityLoc = e.getLocation(); entityLoc.setY(entityLoc.getY() + 0.5D); e.teleport(entityLoc); double g = -0.08D; double d = loc.distance(entityLoc); double t = d; double v_x = (1.0D + 0.07000000000000001D * t) * (loc.getX() - entityLoc.getX()) / t; double v_y = (1.0D + 0.03D * t) * (loc.getY() - entityLoc.getY()) / t - 0.5D * g * t; double v_z = (1.0D + 0.07000000000000001D * t) * (loc.getZ() - entityLoc.getZ()) / t; Vector v = e.getVelocity(); v.setX(v_x); v.setY(v_y); v.setZ(v_z); e.setVelocity(v); //addNoFall(e, 100); }
Example 9
Source File: FireworkMatchModule.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
public static Location getOpenSpaceAbove(Location location) { Preconditions.checkNotNull(location, "location"); Location result = location.clone(); while (true) { Block block = result.getBlock(); if (block == null || block.getType() == Material.AIR) break; result.setY(result.getY() + 1); } return result; }
Example 10
Source File: Signs.java From TabooLib with MIT License | 5 votes |
/** * 向玩家发送虚拟牌子,并返回编辑内容 * * @param player 玩家 * @param origin 原始内容 * @param catcher 编辑内容 */ public static void fakeSign(Player player, String[] origin, Consumer<String[]> catcher) { Validate.isTrue(Version.isAfter(Version.v1_8), "Unsupported Version: " + Version.getCurrentVersion()); Location location = player.getLocation(); location.setY(0); try { player.sendBlockChange(location, Materials.OAK_WALL_SIGN.parseMaterial(), (byte) 0); player.sendSignChange(location, format(origin)); } catch (Throwable t) { t.printStackTrace(); } NMS.handle().openSignEditor(player, location.getBlock()); signs.add(new Data(player.getName(), catcher, location.getBlockX(), location.getBlockY(), location.getBlockZ())); }
Example 11
Source File: IndicatorListener.java From HoloAPI with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onEntityRegainHealth(EntityRegainHealthEvent event) { if (Settings.INDICATOR_ENABLE.getValue("gainHealth")) { if ((event.getEntity() instanceof Player && Settings.INDICATOR_SHOW_FOR_PLAYERS.getValue("gainHealth")) || Settings.INDICATOR_SHOW_FOR_MOBS.getValue("gainHealth")) { Location l = event.getEntity().getLocation().clone(); l.setY(l.getY() + Settings.INDICATOR_Y_OFFSET.getValue("gainHealth")); HoloAPI.getManager().createSimpleHologram(l, Settings.INDICATOR_TIME_VISIBLE.getValue("gainHealth"), true, Settings.INDICATOR_FORMAT.getValue("gainHealth", "default") + "+" + event.getAmount() + " " + HEART_CHARACTER); } } }
Example 12
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 13
Source File: FireworkUtil.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
public static @Nonnull Location getOpenSpaceAbove(@Nonnull Location location) { Preconditions.checkNotNull(location, "location"); Location result = location.clone(); while(true) { Block block = result.getBlock(); if(block == null || block.getType() == Material.AIR) break; result.setY(result.getY() + 1); } return result; }
Example 14
Source File: Post.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
private Location roundToBlock(Location loc) { Location newLoc = loc.clone(); newLoc.setX(Math.floor(loc.getX()) + 0.5); newLoc.setY(Math.floor(loc.getY())); newLoc.setZ(Math.floor(loc.getZ()) + 0.5); return newLoc; }
Example 15
Source File: BossBar_legacy.java From TAB with Apache License 2.0 | 4 votes |
public Location getWitherLocation(ITabPlayer p) { Location loc = p.getBukkitEntity().getEyeLocation().add(p.getBukkitEntity().getEyeLocation().getDirection().normalize().multiply(WITHER_DISTANCE)); if (loc.getY() < 1) loc.setY(1); return loc; }
Example 16
Source File: RescuePlatform.java From BedWars with GNU Lesser General Public License v3.0 | 4 votes |
public void createPlatform(boolean bre, int time, int dist, Material bMat) { canBreak = bre; breakingTime = time; buildingMaterial = bMat; platformBlocks = new ArrayList<>(); Location center = player.getLocation().clone(); center.setY(center.getY() - dist); for (BlockFace blockFace : BlockFace.values()) { if (blockFace.equals(BlockFace.DOWN) || blockFace.equals(BlockFace.UP)) { continue; } Block placedBlock = center.getBlock().getRelative(blockFace); if (placedBlock.getType() != Material.AIR) { continue; } ItemStack coloredStack = Main.applyColor( TeamColor.fromApiColor(team.getColor()), new ItemStack(buildingMaterial)); if (Main.isLegacy()) { placedBlock.setType(coloredStack.getType()); try { // The method is no longer in API, but in legacy versions exists Block.class.getMethod("setData", byte.class).invoke(placedBlock, (byte) coloredStack.getDurability()); } catch (Exception e) { } } else { placedBlock.setType(coloredStack.getType()); } addBlockToList(placedBlock); } if (breakingTime > 0) { game.registerSpecialItem(this); runTask(); MiscUtils.sendActionBarMessage(player, i18nonly("specials_rescue_platform_created").replace("%time%", Integer.toString(breakingTime))); item.setAmount(item.getAmount() - 1); if (item.getAmount() > 1) { item.setAmount(item.getAmount() - 1); } else { player.getInventory().remove(item); } player.updateInventory(); } else { game.registerSpecialItem(this); MiscUtils.sendActionBarMessage(player, i18nonly("specials_rescue_platform_created_unbreakable")); item.setAmount(item.getAmount() - 1); if (item.getAmount() > 1) { item.setAmount(item.getAmount() - 1); } else { player.getInventory().remove(item); } player.updateInventory(); } }
Example 17
Source File: IslandLogic.java From uSkyBlock with GNU General Public License v3.0 | 4 votes |
private Location getNetherLocation(Location loc) { Location netherIsland = loc.clone(); netherIsland.setWorld(plugin.getWorldManager().getNetherWorld()); netherIsland.setY(loc.getY()/2); return netherIsland; }
Example 18
Source File: CommonLevelLogic.java From uSkyBlock with GNU General Public License v3.0 | 4 votes |
Location getNetherLocation(Location l) { Location netherLoc = l.clone(); netherLoc.setWorld(plugin.getWorldManager().getNetherWorld()); netherLoc.setY(Settings.nether_height); return netherLoc; }
Example 19
Source File: Pet.java From SonarPet with GNU General Public License v3.0 | 4 votes |
@Override public void setAsHat(boolean flag) { if (this.isHat == flag) { return; } if (this.ownerRiding) { this.ownerRidePet(false); } this.teleportToOwner(); //Entity craftPet = ((Entity) this.getCraftPet().getHandle()); if (!flag) { if (this.getRider() != null) { //Entity rider = ((Entity) this.getRider().getCraftPet().getHandle()); //rider.mount(null); INMS.getInstance().mount(this.getRider().getEntityPet().getBukkitEntity(), null); //craftPet.mount(null); INMS.getInstance().mount(this.getEntityPet().getBukkitEntity(), null); //rider.mount(craftPet); INMS.getInstance().mount(this.getRider().getEntityPet().getBukkitEntity(), this.getEntityPet().getBukkitEntity()); } else { //craftPet.mount(null); INMS.getInstance().mount(this.getEntityPet().getBukkitEntity(), null); } } else { if (this.getRider() != null && this.getRider().isSpawned()) { //Entity rider = ((Entity) this.getRider().getCraftPet().getHandle()); //rider.mount(null); INMS.getInstance().mount(this.getRider().getEntityPet().getBukkitEntity(), null); //craftPet.mount(((CraftPlayer) this.getOwner()).getHandle()); INMS.getInstance().mount(this.getEntityPet().getBukkitEntity(), this.getOwner()); //this.getCraftPet().setPassenger(this.getRider().getCraftPet()); INMS.getInstance().mount(this.getRider().getEntityPet().getBukkitEntity(), this.getEntityPet().getBukkitEntity()); } else { //craftPet.mount(((CraftPlayer) this.getOwner()).getHandle()); INMS.getInstance().mount(this.getEntityPet().getBukkitEntity(), this.getOwner()); } } this.getEntityPet().resizeBoundingBox(flag); this.isHat = flag; Particle.PORTAL.show(getLocation()); Location l = this.getLocation().clone(); l.setY(l.getY() - 1D); Particle.PORTAL.show(getLocation()); checkState(this.isRegistered(), "%s is no longer registered!", this); }
Example 20
Source File: AxcMove.java From FunnyGuilds with Apache License 2.0 | 4 votes |
@Override public void execute(CommandSender sender, String[] args) { MessageConfiguration messages = FunnyGuilds.getInstance().getMessageConfiguration(); PluginConfiguration config = FunnyGuilds.getInstance().getPluginConfiguration(); Player player = (Player) sender; if (!config.regionsEnabled) { player.sendMessage(messages.regionsDisabled); return; } if (args.length < 1) { player.sendMessage(messages.generalNoTagGiven); return; } Guild guild = GuildUtils.getByTag(args[0]); if (guild == null) { player.sendMessage(messages.generalNoGuildFound); return; } Location location = player.getLocation(); if (config.createCenterY != 0) { location.setY(config.createCenterY); } int distance = config.regionSize + config.createDistance; if (config.enlargeItems != null) { distance = config.enlargeItems.size() * config.enlargeSize + distance; } if (distance > player.getWorld().getSpawnLocation().distance(location)) { player.sendMessage(messages.createSpawn.replace("{DISTANCE}", Integer.toString(distance))); return; } if (RegionUtils.isNear(location)) { player.sendMessage(messages.createIsNear); return; } User admin = User.get(player); if (!SimpleEventHandler.handle(new GuildMoveEvent(EventCause.ADMIN, admin, guild, location))) { return; } Region region = guild.getRegion(); if (region == null) { region = new Region(guild, location, config.regionSize); } else { if (config.createEntityType != null) { GuildEntityHelper.despawnGuildHeart(guild); } else if (config.createMaterial != null && config.createMaterial.getLeft() != Material.AIR) { Block block = region.getCenter().getBlock().getRelative(BlockFace.DOWN); Bukkit.getScheduler().runTask(FunnyGuilds.getInstance(), () -> { if (block.getLocation().getBlockY() > 1) { block.setType(Material.AIR); } }); } region.setCenter(location); } if (config.createCenterSphere) { List<Location> sphere = SpaceUtils.sphere(location, 3, 3, false, true, 0); for (Location locationInSphere : sphere) { if (locationInSphere.getBlock().getType() != Material.BEDROCK) { locationInSphere.getBlock().setType(Material.AIR); } } } GuildUtils.spawnHeart(guild); player.sendMessage(messages.adminGuildRelocated.replace("{GUILD}", guild.getName()).replace("{REGION}", region.getName())); }