下面列出了org.bukkit.World#getEnvironment ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 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 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]));
}
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();
}
@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);
}
}
}
/**
* 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);
}
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;
}
@Override
public boolean hasSky() {
World world = getWorld();
return world == null || world.getEnvironment() == World.Environment.NORMAL;
}
/**
* 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;
}