sender.sendMessage("You can only perform this command as a player"); return true; Location location = player.getLocation(); x = location.getBlockX(); y = location.getBlockY(); z = location.getBlockZ(); } else if (args.length == 3) { try { x = getInteger(sender, args[0], MIN_COORD, MAX_COORD, true); y = getInteger(sender, args[1], 0, world.getMaxHeight(), true); z = getInteger(sender, args[2], MIN_COORD, MAX_COORD, true); } catch (NumberFormatException ex) { sender.sendMessage(ex.getMessage()); return true; sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage); return false; world.setSpawnLocation(x, y, z); Command.broadcastCommandMessage(sender, "Set world " + world.getName() + "'s spawnpoint to (" + x + ", " + y + ", " + z + ")"); return true;
@Override public void populate(World world, Random random, Chunk source) { int sourceX = (source.getX() << 4) + random.nextInt(16); int sourceZ = (source.getZ() << 4) + random.nextInt(16); int sourceY = random.nextInt(world.getSeaLevel() << 1); for (int i = 0; i < 64; i++) { int x = sourceX + random.nextInt(8) - random.nextInt(8); int z = sourceZ + random.nextInt(8) - random.nextInt(8); int y = sourceY + random.nextInt(4) - random.nextInt(4); if (world.getBlockAt(x, y, z).getType() == Material.AIR && world.getBlockAt(x, y - 1, z).getType() == Material.GRASS) { BlockState state = world.getBlockAt(x, y, z).getState(); state.setType(Material.MELON_BLOCK); state.setData(new MaterialData(Material.MELON_BLOCK)); state.update(true); } } } }
private void setType(Block block, int type, int data) { World world = block.getWorld(); int x = block.getX(); int y = block.getY(); int z = block.getZ(); GlowChunk chunk = (GlowChunk) world.getChunkAt(block); chunk.setType(x & 0xf, z & 0xf, y, type); chunk.setMetaData(x & 0xf, z & 0xf, y, data); } }
/** * Copies the options from the specified world * * @param world World to copy options from * @return This object, for chaining */ public WorldCreator copy(World world) { if (world == null) { throw new IllegalArgumentException("World cannot be null"); } seed = world.getSeed(); environment = world.getEnvironment(); generator = world.getGenerator(); return this; }
/** * Tests if the specified location is valid for a natural spawn position * * @param world The world we're testing on * @param x X-coordinate of the block to test * @param z Z-coordinate of the block to test * @return true if the location is valid, otherwise false */ public boolean canSpawn(World world, int x, int z) { Block highest = world.getBlockAt(x, world.getHighestBlockYAt(x, z), z); switch (world.getEnvironment()) { case NETHER: return true; case THE_END: return highest.getType() != Material.AIR && highest.getType() != Material.WATER && highest.getType() != Material.LAVA; case NORMAL: default: return highest.getType() == Material.SAND || highest.getType() == Material.GRAVEL; } }
@Override public boolean execute(CommandSender sender, String currentAlias, String[] args) { if (!testPermission(sender)) return true; World world = null; if (args.length == 1) { world = Bukkit.getWorld(args[0]); if (world == null) { sender.sendMessage(ChatColor.RED + "No world exists with the name '" + args[0] + "'"); return true; } } else if (sender instanceof Player) { world = ((Player) sender).getWorld(); } else { world = Bukkit.getWorlds().get(0); } Command.broadcastCommandMessage(sender, "Toggling downfall " + (world.hasStorm() ? "off" : "on") + " for world '" + world.getName() + "'"); world.setStorm(!world.hasStorm()); return true; }
@Override public void populate(World world, Random random, Chunk chunk) { GlowServer server = (GlowServer) Bukkit.getServer(); boolean allowAnimals = world.getAllowAnimals() && server.getAnimalsSpawnEnabled(); boolean allowMonsters = world.getAllowMonsters() && server.getMonstersSpawnEnabled(); if (entityTypes.length == 0) { return; if (random.nextFloat() >= rarity) { return; EntityType type = entityTypes[random.nextInt(entityTypes.length)]; if ((!allowAnimals && Animals.class.isAssignableFrom(type.getEntityClass())) || !allowMonsters && Monster.class.isAssignableFrom(type.getEntityClass())) { return; int centerX = sourceX + random.nextInt(16); int centerZ = sourceZ + random.nextInt(16); int count = minGroup == maxGroup ? minGroup double x = radius * Math.sin(angle) + centerX; double z = radius * Math.cos(angle) + centerZ; Block block = world.getHighestBlockAt(new Location(world, x, 0, z)); if (block.getType() == Material.WATER || block.getType() == Material.STATIONARY_WATER || block.getType() == Material.LAVA || block.getType() == Material.STATIONARY_LAVA) { i--; world.spawnEntity(location, type);
@Override public void decorate(World world, Random random, Chunk source) { int sourceX = (source.getX() << 4) + random.nextInt(16); int sourceZ = (source.getZ() << 4) + random.nextInt(16); Block sourceBlock = world .getBlockAt(sourceX, world.getHighestBlockYAt(sourceX, sourceZ), sourceZ); BiFunction<Random, BlockStateDelegate, ? extends GenericTree> ctor = getRandomTree(random, trees); if (ctor != null) { BlockStateDelegate delegate = new BlockStateDelegate(); GenericTree tree; try { tree = ctor.apply(random, delegate); } catch (Exception ex) { tree = new GenericTree(random, delegate); } if (tree.generate(sourceBlock.getLocation())) { delegate.updateBlockStates(); } } }
@Override public boolean generate(World world, Random random, int sourceX, int sourceY, int sourceZ) { if (!world.getBlockAt(sourceX, sourceY, sourceZ).isEmpty() || world.getBlockAt(sourceX, sourceY - 1, sourceZ).getType() != Material.ENDER_STONE) { return false; int height = random.nextInt(32) + 6; int radius = random.nextInt(4) + 1; for (int j = -radius; j <= radius; j++) { if (i * i + j * j <= radius * radius + 1 && world.getBlockAt(sourceX + i, sourceY - 1, sourceZ + j).getType() != Material.ENDER_STONE) { return false; for (int j = -radius; j <= radius; j++) { if (i * i + j * j <= radius * radius + 1) { Block block = world.getBlockAt(sourceX + i, sourceY + k, sourceZ + j); block.setType(Material.OBSIDIAN); final Location loc = new Location(world, sourceX + 0.5D, sourceY + height + 1, sourceZ + 0.5D, random.nextFloat() * 360, 0); world.spawnEntity(loc, EntityType.ENDER_CRYSTAL); Block block = world.getBlockAt(sourceX, sourceY + height, sourceZ); block.setType(Material.BEDROCK); return true;
@Override public Location getFixedSpawnLocation(World world, Random random) { while (true) { int x = random.nextInt(128) - 64; int y = 128 * 3 / 4; int z = random.nextInt(128) - 64; if (world.getBlockAt(x, y, z).isEmpty()) { while (world.getBlockAt(x, y - 1, z).isEmpty() && y > 0) { y--; } return new Location(world, x, y, z); } } }
@Override public void populate(World world, Random random, Chunk chunk) { int sourceX = chunk.getX() << 4; int sourceZ = chunk.getZ() << 4; for (int i = 0; i < random.nextInt(6) + 3; i++) { int x = sourceX + random.nextInt(16); int z = sourceZ + random.nextInt(16); int y = random.nextInt(28) + 4; if (world.getBlockAt(x, y, z).getType() == Material.STONE) { world.getBlockAt(x, y, z).setType(Material.EMERALD_ORE); } } } }
@Override public void decorate(World world, Random random, Chunk source) { int sourceX = (source.getX() << 4) + random.nextInt(16); int sourceZ = (source.getZ() << 4) + random.nextInt(16); int sourceY = world.getHighestBlockYAt(sourceX, sourceZ) - 1; while ( world.getBlockAt(sourceX, sourceY - 1, sourceZ).getType() == Material.STATIONARY_WATER || world.getBlockAt(sourceX, sourceY - 1, sourceZ).getType() == Material.WATER && sourceY > 1) { sourceY--; } Material material = world.getBlockAt(sourceX, sourceY, sourceZ).getType(); if (material == Material.STATIONARY_WATER || material == Material.WATER) { new BlockPatch(type, horizRadius, vertRadius, overridables) .generate(world, random, sourceX, sourceY, sourceZ); } } }
@Override public void populate(World world, Random random, Chunk source) { if (world.canGenerateStructures()) { random.setSeed(world.getSeed()); long randX = random.nextLong(); long randZ = random.nextLong(); if (!world.getChunkAt(x, z).isLoaded() && !world.getChunkAt(x, z).load(true)) { continue; random.setSeed(x * randX + z * randZ ^ world.getSeed()); Map<Integer, GlowStructure> structures = ((GlowWorld) world) .getStructures();
@Override public void populate(World world, Random random, Chunk chunk) { obsidianPillarDecorator.populate(world, random, chunk); // spawn the enderdragon if (chunk.getX() == 0 && chunk.getZ() == 0) { final Location loc = new Location(world, (chunk.getX() << 4) + 8, 128, (chunk.getZ() << 4) + 8, random.nextFloat() * 360, 0); world.spawnEntity(loc, EntityType.ENDER_DRAGON); } } }
: ((BlockCommandSender) sender).getBlock().getLocation(); final Entity[] entities = new CommandTarget(sender, args[0]).getMatched(location); targets = new ArrayList<>(); final Player player = Bukkit.getPlayerExact(playerPattern); .sendMessage( ChatColor.RED + "Player '" + playerPattern + "' cannot be found"); return false; currentLocation = new Location(world, 0, 0, 0); if (spawnLocation.getY() < 0) { sender.sendMessage(ChatColor.RED + "The y coordinate (" + spawnLocation.getY() + ") is too small, it must be at least 0."); return false; } else if (spawnLocation.getBlockY() > world.getMaxHeight()) { + world.getMaxHeight() + "'."); return false; if (CommandUtils.isPhysical(sender)) { spawnLocation = sender instanceof Entity ? ((Entity) sender).getLocation() : ((BlockCommandSender) sender).getBlock().getLocation(); target.setBedSpawnLocation(spawnLocation, true); sender.sendMessage("Set " + target.getName() + "'s spawn point to "
player = (Player) sender; } else { sender.sendMessage("Please provide a player!"); return true; player = Bukkit.getPlayerExact(args[0]); if (player == null) { sender.sendMessage("Can't find player " + args[0]); return true; World world = player.getWorld(); try { x = getInteger(sender, args[pos++], MIN_COORD, MAX_COORD, true); y = getInteger(sender, args[pos++], 0, world.getMaxHeight()); z = getInteger(sender, args[pos], MIN_COORD, MAX_COORD, true); } catch(NumberFormatException ex) { sender.sendMessage(ex.getMessage()); return true; player.setBedSpawnLocation(new Location(world, x, y, z), true); Command.broadcastCommandMessage(sender, "Set " + player.getDisplayName() + "'s spawnpoint to " + x + ", " + y + ", " + z); Location location = player.getLocation(); player.setBedSpawnLocation(location, true); Command.broadcastCommandMessage(sender, "Set " + player.getDisplayName() + "'s spawnpoint to " + location.getX() + ", " + location.getY() + ", " + location.getZ()); } else { sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
private Location getSafeLocation(Location loc) { int blockY = loc.getBlockY(); World world = loc.getWorld(); if (blockY > world.getHighestBlockYAt(loc)) { blockY = world.getHighestBlockYAt(loc) + 1; Block current = world.getBlockAt(loc.getBlockX(), blockY, loc.getBlockZ()); if (current.isEmpty() && current.getRelative(BlockFace.UP).isEmpty()) { hadSpace = true; } else if (hadSpace) {
/** * Find a a Location obove or below the specified Location, which is on ground. * * <p>The returned Location will be at the center of the block, X and Y wise. * * @param spawn The Location a safe spawn position should be found at. * @return The location to spawn the player at. */ private static Location findSafeSpawnLocation(Location spawn) { World world = spawn.getWorld(); int blockX = spawn.getBlockX(); int blockY = spawn.getBlockY(); int blockZ = spawn.getBlockZ(); int highestY = world.getHighestBlockYAt(blockX, blockZ); int y = blockY; boolean wasPreviousSafe = false; for (; y <= highestY; y++) { Material type = world.getBlockAt(blockX, y, blockZ).getType(); boolean safe = Material.AIR.equals(type); if (wasPreviousSafe && safe) { y--; break; } wasPreviousSafe = safe; } return new Location(world, blockX + 0.5, y, blockZ + 0.5); }
public static void chimaeraExecuteTeleport() { Player player = mcMMOPlayer.getPlayer(); if (Config.getInstance().getChimaeraUseBedSpawn() && player.getBedSpawnLocation() != null) { player.teleport(player.getBedSpawnLocation()); } else { Location spawnLocation = player.getWorld().getSpawnLocation(); if (spawnLocation.getBlock().getType() == Material.AIR) { player.teleport(spawnLocation); } else { player.teleport(player.getWorld().getHighestBlockAt(spawnLocation).getLocation()); } } player.getInventory().setItemInMainHand(new ItemStack(getChimaeraWing(player.getInventory().getItemInMainHand().getAmount() - Config.getInstance().getChimaeraUseCost()))); player.updateInventory(); mcMMOPlayer.actualizeChimeraWingLastUse(); mcMMOPlayer.setTeleportCommenceLocation(null); if (Config.getInstance().getChimaeraSoundEnabled()) { SoundManager.sendSound(player, location, SoundType.CHIMAERA_WING); } NotificationManager.sendPlayerInformation(player, NotificationType.ITEM_MESSAGE, "Item.ChimaeraWing.Pass"); }
@SuppressWarnings("deprecation") @EventHandler public void onPlayerMove(PlayerMoveEvent event) { Block block, control; if (event.getTo().getY() > event.getFrom().getY()) { block = event.getPlayer().getWorld().getBlockAt(new Location(event.getPlayer().getWorld(), event.getTo().getX(), event.getTo().getY() + 2, event.getTo().getZ())); control = event.getPlayer().getWorld().getBlockAt(new Location(event.getPlayer().getWorld(), event.getTo().getX(), event.getTo().getY() - 2, event.getTo().getZ())); if (!(block.getTypeId() != 0 || control.getTypeId() == 0)) { EvtJump custom = new EvtJump(event.getPlayer()); Bukkit.getServer().getPluginManager().callEvent(custom); if (custom.isCancelled()) { event.setCancelled(true); } } } }