本文整理汇总了Java中org.bukkit.World.Environment.THE_END属性的典型用法代码示例。如果您正苦于以下问题:Java Environment.THE_END属性的具体用法?Java Environment.THE_END怎么用?Java Environment.THE_END使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.bukkit.World.Environment
的用法示例。
在下文中一共展示了Environment.THE_END属性的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onPlayerSwitchWorlds
@EventHandler
public void onPlayerSwitchWorlds(PlayerChangedWorldEvent event) {
World world = event.getPlayer().getWorld();
if (world.getEnvironment() != Environment.THE_END) return;
EndWorldWrapper worldWrapper = manager.getWorldWrapper(world);
// Start the respawn countdown if joining an empty world
if (plugin.getConfig().getBoolean("respawn-on-join", false)) {
if (world.getPlayers().size() > 1 || worldWrapper.isRespawnInProgress()
|| world.getEntitiesByClass(EnderDragon.class).size() == 0)
return;
manager.getWorldWrapper(world).startRespawn(RespawnType.JOIN);
}
// Reset end crystal states just in case something went awry
if (!worldWrapper.isRespawnInProgress()) {
world.getEntitiesByClass(EnderCrystal.class).forEach(e -> {
e.setInvulnerable(false);
e.setBeamTarget(null);
});
}
}
示例2: onClickEndPortalFrame
@EventHandler
public void onClickEndPortalFrame(PlayerInteractEvent event) {
Player player = event.getPlayer();
World world = player.getWorld();
Block clickedBlock = event.getClickedBlock();
if (event.getAction() != Action.RIGHT_CLICK_BLOCK || world.getEnvironment() != Environment.THE_END
|| clickedBlock.getType() != Material.BEDROCK || event.getHand() != EquipmentSlot.HAND
|| (player.getInventory().getItemInMainHand() != null || player.getInventory().getItemInOffHand() != null)) return;
NMSAbstract nmsAbstract = plugin.getNMSAbstract();
DragonBattle dragonBattle = nmsAbstract.getEnderDragonBattleFromWorld(world);
Location portalLocation = dragonBattle.getEndPortalLocation();
if (event.getClickedBlock().getLocation().distanceSquared(portalLocation) > 36) return; // 5 blocks
EndWorldWrapper endWorld = plugin.getDEDManager().getWorldWrapper(world);
int secondsRemaining = endWorld.getTimeUntilRespawn();
if (secondsRemaining <= 0) return;
plugin.sendMessage(player, "Dragon will respawn in " + ChatColor.YELLOW + secondsRemaining);
}
示例3: getEnvironment
/**
* Determines the environment of the given world based on its folder
* structure.
*
* @param world the name of the world to determine the environment of
* @return the environment of the given world
* @since 0.3.0
*/
public static Environment getEnvironment(String world) {
File worldFolder = new File(Bukkit.getWorldContainer(), world);
if (worldFolder.exists()) {
for (File f : worldFolder.listFiles()) {
if (f.getName().equals("region")) {
return Environment.NORMAL;
}
else if (f.getName().equals("DIM1")) {
return Environment.THE_END;
}
else if (f.getName().equals("DIM-1")) {
return Environment.NETHER;
}
}
}
return null;
}
示例4: AdditionalSubWorld
public AdditionalSubWorld(final NWorld instance, final AdditionalWorld parentWorld, final NLocation spawnLocation, final String requiredPermission, final boolean enabled, final boolean hidden, final Environment type) {
super(instance);
this.parentWorld = parentWorld;
String worldName = parentWorld.getWorldName();
if (type == Environment.NETHER) {
worldName += "_nether";
this.setType(WorldType.ADDITIONAL_SUB_NETHER);
parentWorld.setNetherWorld(this);
} else if (type == Environment.THE_END) {
worldName += "_the_end";
this.setType(WorldType.ADDITIONAL_SUB_END);
parentWorld.setEndWorld(this);
} else {
throw new IllegalArgumentException("Invalid sub-world type: " + type);
}
this.setWorldName(worldName);
this.setSpawnLocation(spawnLocation);
this.setRequiredPermission(requiredPermission);
this.setEnabled(enabled);
this.setHidden(hidden);
if (!this.plugin.getWorlds().containsKey(worldName)) {
this.plugin.getWorlds().put(worldName, this);
}
}
示例5: onEndChunkUnload
/**
* Remove the unloaded EnderDragons from the loaded set
*
* @param event a Chunk Unload Event
*/
@EventHandler(priority = EventPriority.NORMAL)
public void onEndChunkUnload(final ChunkUnloadEvent event) {
if (event.getWorld().getEnvironment() == Environment.THE_END) {
final String worldName = event.getWorld().getName();
final EndWorldHandler handler = this.plugin.getHandler(StringUtil.toLowerCamelCase(worldName));
if (handler != null) {
EndChunk chunk = handler.getChunks().getChunk(event.getChunk());
if (chunk == null) {
chunk = handler.getChunks().addChunk(event.getChunk());
}
for (final Entity e : event.getChunk().getEntities()) {
if (e.getType() == EntityType.ENDER_DRAGON) {
final EnderDragon ed = (EnderDragon)e;
handler.getLoadedDragons().remove(ed.getUniqueId());
chunk.incrementSavedDragons();
}
}
}
}
}
示例6: onWorldLoad
/**
* Creates an EndWorldHandler if the loaded world is an End world
*
* @param event a World Load Event
*/
@EventHandler(priority = EventPriority.NORMAL)
public void onWorldLoad(final WorldLoadEvent event) {
if (event.getWorld().getEnvironment() == Environment.THE_END) {
this.plugin.getLogger().info("Additional End world detected: handling " + event.getWorld().getName());
final EndWorldHandler handler = new EndWorldHandler(this.plugin, event.getWorld());
try {
handler.loadConfig();
handler.loadChunks();
this.plugin.getWorldHandlers().put(handler.getCamelCaseWorldName(), handler);
handler.init();
} catch (final IOException | InvalidConfigurationException e) {
this.plugin.getLogger().severe("An error occured, stacktrace follows:");
e.printStackTrace();
}
}
}
示例7: onWorldUnload
/**
* Creates an EndWorldHandler if the loaded world is an End world
*
* @param event a World Unload Event
*/
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onWorldUnload(final WorldUnloadEvent event) {
if (event.getWorld().getEnvironment() == Environment.THE_END) {
this.plugin.getLogger().info("Handling " + event.getWorld().getName() + " unload");
final EndWorldHandler handler = this.plugin.getHandler(StringUtil.toLowerCamelCase(event.getWorld().getName()));
if (handler != null) {
try {
handler.unload(false);
} catch (final InvalidConfigurationException e) {
this.plugin.getLogger().severe("An error occured, stacktrace follows:");
e.printStackTrace();
}
}
}
}
示例8: getID
private int getID(Environment env)
{
if (env == Environment.NETHER)
return -1;
else if (env == Environment.NORMAL)
return 0;
else if (env == Environment.THE_END)
return 1;
else
return -1;
}
示例9: onPlayerPortal
@EventHandler(ignoreCancelled=true, priority=EventPriority.HIGHEST)
public void onPlayerPortal(PlayerPortalEvent event)
{
if (event.getCause() == TeleportCause.END_PORTAL) {
if (event.getTo().getWorld().getEnvironment() == Environment.THE_END) {
event.setTo(event.getTo().getWorld().getSpawnLocation().clone().add(0.5D, 0.0D, 0.5D));
} else if (event.getFrom().getWorld().getEnvironment() == Environment.THE_END) {
event.setTo(this.endExitLocation);
}
}
}
示例10: EndWorldWrapper
/**
* Construct a new EndWorldWrapper around an existing world
*
* @param plugin the plugin instance
* @param world the world to wrap
*/
protected EndWorldWrapper(DragonEggDrop plugin, World world) {
this.plugin = plugin;
this.world = world.getUID();
if (world.getEnvironment() != Environment.THE_END)
throw new IllegalArgumentException("EndWorldWrapper worlds must be of environment \"THE_END\"");
}
示例11: onPlayerJoin
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
// Version notification
Player player = event.getPlayer();
if (player.isOp() && plugin.isNewVersionAvailable()) {
this.plugin.sendMessage(player, ChatColor.GRAY + "A new version is available for download (Version " + this.plugin.getNewVersion() + "). " + RESOURCE_PAGE);
}
World world = player.getWorld();
if (world.getEnvironment() != Environment.THE_END) return;
EndWorldWrapper worldWrapper = manager.getWorldWrapper(world);
// Reset end crystal states just in case something went awry
if (!worldWrapper.isRespawnInProgress()) {
world.getEntitiesByClass(EnderCrystal.class).forEach(e -> {
e.setInvulnerable(false);
e.setBeamTarget(null);
});
}
// Dragon respawn logic
if (!plugin.getConfig().getBoolean("respawn-on-join", false)) return;
if (!world.getPlayers().isEmpty() || manager.getWorldWrapper(world).isRespawnInProgress()
|| world.getEntitiesByClass(EnderDragon.class).size() == 0)
return;
manager.getWorldWrapper(world).startRespawn(RespawnType.JOIN);
}
示例12: onItemSpawn
@EventHandler
public void onItemSpawn(ItemSpawnEvent event) {
Item item = event.getEntity();
ItemStack stack = item.getItemStack();
World world = item.getWorld();
if (world.getEnvironment() != Environment.THE_END || stack.getType() != Material.DRAGON_EGG
|| stack.hasItemMeta()) return;
DragonTemplate dragon = plugin.getDEDManager().getWorldWrapper(world).getActiveBattle();
DragonLoot loot = dragon.getLoot();
String eggName = loot.getEggName().replace("%dragon%", dragon.getName());
List<String> eggLore = loot.getEggLore().stream()
.map(s -> s.replace("%dragon%", dragon.getName()))
.collect(Collectors.toList());
ItemMeta eggMeta = stack.getItemMeta();
if (eggName != null && !eggName.isEmpty()) {
eggMeta.setDisplayName(eggName);
}
if (eggLore != null && !eggLore.isEmpty()) {
eggMeta.setLore(eggLore);
}
stack.setItemMeta(eggMeta);
}
示例13: onEntityDamageByEntity
@EventHandler
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
Entity entity = event.getEntity();
if (!(entity instanceof EnderCrystal) || event.getEntity().getWorld().getEnvironment() != Environment.THE_END
|| !entity.isInvulnerable()) return;
event.setCancelled(true);
}
示例14: onCreatureSpawn
@EventHandler
public void onCreatureSpawn(CreatureSpawnEvent event) {
if (!(event.getEntity() instanceof EnderDragon)) return;
EnderDragon dragon = (EnderDragon) event.getEntity();
if (dragon.getWorld().getEnvironment() != Environment.THE_END) return;
DragonBattle dragonBattle = plugin.getNMSAbstract().getEnderDragonBattleFromDragon(dragon);
EndWorldWrapper world = plugin.getDEDManager().getWorldWrapper(dragon.getWorld());
if (plugin.getConfig().getBoolean("strict-countdown") && world.isRespawnInProgress()) {
world.stopRespawn();
}
DragonTemplate template = plugin.getDEDManager().getRandomTemplate();
if (template != null) {
template.applyToBattle(plugin.getNMSAbstract(), dragon, dragonBattle);
world.setActiveBattle(template);
if (template.shouldAnnounceRespawn()) {
Bukkit.getOnlinePlayers().forEach(p -> p.sendMessage(
ChatColor.DARK_GRAY + "[" + ChatColor.RED.toString() + ChatColor.BOLD + "!!!" + ChatColor.DARK_GRAY + "] "
+ template.getName() + ChatColor.DARK_GRAY + " has respawned in the end!")
);
}
}
BattleStateChangeEvent bscEventCrystals = new BattleStateChangeEvent(dragonBattle, dragon, BattleState.DRAGON_RESPAWNING, BattleState.BATTLE_COMMENCED);
Bukkit.getPluginManager().callEvent(bscEventCrystals);
}