Java Code Examples for org.bukkit.World#getEnvironment()

The following examples show how to use org.bukkit.World#getEnvironment() . 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: ChunkGenerator.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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;
    }
}
 
Example 2
Source File: ImportCommand.java    From DungeonsXL with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onExecute(String[] args, CommandSender sender) {
    File target = new File(DungeonsXL.MAPS, args[1]);
    File source = new File(Bukkit.getWorldContainer(), args[1]);

    if (!source.exists()) {
        MessageUtil.sendMessage(sender, DMessage.ERROR_NO_SUCH_MAP.getMessage(args[1]));
        return;
    }

    if (target.exists()) {
        MessageUtil.sendMessage(sender, DMessage.ERROR_NAME_IN_USE.getMessage(args[1]));
        return;
    }

    World world = Bukkit.getWorld(args[1]);
    if (world != null) {
        world.save();
    }

    MessageUtil.log(plugin, "&6Creating new map.");
    MessageUtil.log(plugin, "&6Importing world...");

    FileUtil.copyDir(source, target, "playerdata", "stats");

    DResourceWorld resource = new DResourceWorld(plugin, args[1]);
    plugin.getDungeonRegistry().add(args[1], new DDungeon(plugin, resource));
    if (world.getEnvironment() != Environment.NORMAL) {
        WorldConfig config = resource.getConfig(true);
        config.setWorldEnvironment(world.getEnvironment());
        config.save();
    }
    plugin.getMapRegistry().add(resource.getName(), resource);
    MessageUtil.sendMessage(sender, DMessage.CMD_IMPORT_SUCCESS.getMessage(args[1]));
}
 
Example 3
Source File: ConfigManager.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
public void addWorldProperties(World w) {
    try {
        //add worlds to claim types list
        if (!root.region_settings.claim.world_types.containsKey(w.getName())) {
            root.region_settings.claim.world_types.put(w.getName(), "BLOCK");
            RedProtect.get().logger.warning("Added world to claim types list " + w.getName());
        }
        //add world to globalflags
        if (!globalFlagsRoot.worlds.containsKey(w.getName())) {
            globalFlagsRoot.worlds.put(w.getName(), new GlobalFlagsCategory.WorldProperties());
        }
        //add worlds to color list
        if (!root.region_settings.world_colors.containsKey(w.getName()) && w.getEnvironment() != null) {
            switch (w.getEnvironment()) {
                case NORMAL:
                    root.region_settings.world_colors.put(w.getName(), "&a&l");
                case NETHER:
                    root.region_settings.world_colors.put(w.getName(), "&c&l");
                case THE_END:
                    root.region_settings.world_colors.put(w.getName(), "&5&l");
                default:
                    root.region_settings.world_colors.put(w.getName(), "&a&l");
            }
            RedProtect.get().logger.warning("Added world to colors list " + w.getName());
        }
    } catch (Exception ex) {
        RedProtect.get().logger.warning("Error on add config properties for world " + w.getName() + ": " + ex.getMessage());
        ex.printStackTrace();
    }
    saveGFlags();
}
 
Example 4
Source File: EndModule.java    From UHC with MIT License 5 votes vote down vote up
@Override
public void onDisable() {
    final Set<OfflinePlayer> players = Sets.newHashSet();
    final Set<String> worlds = Sets.newHashSet();

    for (final World world : Bukkit.getWorlds()) {
        if (world.getEnvironment() == World.Environment.THE_END) {
            worlds.add(world.getName());
            players.addAll(world.getPlayers());
        }
    }

    if (players.size() == 0) return;

    final Joiner joiner = Joiner.on(", ");
    final String playerNames = joiner.join(Iterables.transform(players, FunctionalUtil.PLAYER_NAME_FETCHER));
    final String worldNames = joiner.join(worlds);

    final String message = messages.evalTemplate(
            "notification",
            ImmutableMap.of("players", playerNames, "worlds", worldNames)
    );
    Bukkit.getConsoleSender().sendMessage(message);

    for (final Player player : Bukkit.getOnlinePlayers()) {
        if (player.hasPermission("uhc.broadcast.enddisable")) {
            player.sendMessage(message);
        }
    }
}
 
Example 5
Source File: WorldManager.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Checks if the given {@link World} is associated with Ultimate Skyblock.
 * @param world World to check.
 * @return True if the given world is associated with the plugin, false otherwise.
 */
public boolean isSkyAssociatedWorld(@Nullable World world) {
    if (world == null) {
        return false;
    }

    return world.getName().startsWith(WorldManager.skyBlockWorld.getName())
            && !(world.getEnvironment() == World.Environment.NETHER && !Settings.nether_enabled)
            && !(world.getEnvironment() == World.Environment.THE_END);
}
 
Example 6
Source File: ArmorTask.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
private boolean hasSunlight(Player p) {
    World world = p.getWorld();

    if (world.getEnvironment() != Environment.NORMAL) {
        // The End and Nether have no sunlight
        return false;
    }

    return (world.getTime() < 12300 || world.getTime() > 23850) && p.getEyeLocation().getBlock().getLightFromSky() == 15;
}
 
Example 7
Source File: BukkitQueue_0.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean hasSky() {
    World world = getWorld();
    return world == null || world.getEnvironment() == World.Environment.NORMAL;
}
 
Example 8
Source File: LocationUtil.java    From UHC with MIT License 4 votes vote down vote up
/**
 * Checks for the highest safe to stand on block with 2 un-solid blocks above it (excluding above world height).
 *
 * <p>Does not teleport on to non-solid blocks or blocks that can damage the player.</p>
 * <p>Only teleports into water if it is not at head height (feet only)</p>
 * <p>
 *     If the world type is NETHER then searching will start at 128 instead of the world max height to avoid the
 *     bedrock roof.
 * </p>
 *
 * @param world world to check within
 * @param xcoord the x coord to check at
 * @param zcoord the z coord to check at
 * @return -1 if no valid location found, otherwise coordinate with non-air Y coord with 2 air blocks above it
 */
public static int findHighestTeleportableY(World world, int xcoord, int zcoord) {
    final Location startingLocation = new Location(
            world,
            xcoord,
            world.getEnvironment() == World.Environment.NETHER ? NETHER_MAX_HEIGHT : world.getMaxHeight(),
            zcoord
    );

    boolean above2WasSafe = false;
    boolean aboveWasSafe = false;
    boolean above2WasWater = false;
    boolean aboveWasWater = false;

    Block currentBlock = startingLocation.getBlock();

    Material type;
    boolean damagesPlayer;
    boolean canStandOn;
    boolean aboveAreSafe;
    while (currentBlock.getY() >= 0) {
        type = currentBlock.getType();

        // get info about the current block
        damagesPlayer = damagesPlayer(type);
        canStandOn = canStandOn(type);

        aboveAreSafe = aboveWasSafe && above2WasSafe && !above2WasWater;

        // valid block if it has 2 safe blocks above it, it doesn't damage the player,
        // is safe to stand on and there isn't any water in the head space
        if (aboveAreSafe && !damagesPlayer && canStandOn) {
            return currentBlock.getY();
        }

        // move safe blocks
        above2WasSafe = aboveWasSafe;
        aboveWasSafe = !canStandOn && !damagesPlayer;

        // move water blocks
        above2WasWater = aboveWasWater;
        aboveWasWater = type == Material.WATER || type == Material.STATIONARY_WATER;

        // move down a block and run again
        currentBlock = currentBlock.getRelative(BlockFace.DOWN);
    }

    return -1;
}