org.bukkit.World#getEnvironment ( )源码实例Demo

下面列出了org.bukkit.World#getEnvironment ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Kettle   文件: ChunkGenerator.java
/**
 * 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;
    }
}
 
源代码2 项目: DungeonsXL   文件: ImportCommand.java
@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]));
}
 
源代码3 项目: RedProtect   文件: ConfigManager.java
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();
}
 
源代码4 项目: UHC   文件: EndModule.java
@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);
        }
    }
}
 
源代码5 项目: uSkyBlock   文件: WorldManager.java
/**
 * 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);
}
 
源代码6 项目: Slimefun4   文件: ArmorTask.java
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;
}
 
源代码7 项目: FastAsyncWorldedit   文件: BukkitQueue_0.java
@Override
public boolean hasSky() {
    World world = getWorld();
    return world == null || world.getEnvironment() == World.Environment.NORMAL;
}
 
源代码8 项目: UHC   文件: LocationUtil.java
/**
 * 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;
}