下面列出了org.bukkit.Bukkit#getWorlds ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Update the global score for all worlds
*/
private void updateGlobalScores() {
for (World world : Bukkit.getWorlds()) {
//Do not update worlds with disabled climate-engines:
WorldClimateEngine climateEngine = ClimateEngine.getInstance().getClimateEngine(world.getUID());
if (climateEngine != null && climateEngine.isEnabled()) {
//Get the scoreboard for this world:
Scoreboard scoreboard = getScoreboard(world.getUID(), false);
//Get its objective (scoreboard title / group):
Objective objective = null;
if (scoreboard != null) {
objective = scoreboard.getObjective(GLOBAL_WARMING);
}
//Update the title to show this world's temperature:
if (objective != null) {
double temperature = climateEngine.getTemperature();
objective.setDisplayName(climateEngine.formatTemp(temperature));
}
}
}
}
private boolean loadPlayerData(String name) {
try {
this.player = name;
for(World w : Bukkit.getWorlds()) {
this.file = new File(w.getWorldFolder(), "players" + File.separator + this.player + ".dat");
if(this.file.exists()){
this.compound = NBTCompressedStreamTools.a(new FileInputStream(this.file));
this.player = this.file.getCanonicalFile().getName().replace(".dat", "");
return true;
}
}
}
catch(Exception e) {
e.printStackTrace();
}
return false;
}
@Override
public void run() {
worlds.clear();
for (World world : Bukkit.getWorlds()) {
List<Player> players = world.getPlayers();
int count = 0;
for (Player player : players) {
if (!player.hasMetadata("NPC")) {
count++;
}
}
worlds.put(world.getName(), count);
}
}
/**
* Get all npc's from all worlds.
*
* @return A list of all npc's
*/
public List<NPC> getNPCs() {
List<NPC> npcList = new ArrayList<NPC>();
for(World world : Bukkit.getWorlds()) {
npcList.addAll(getNPCs(world));
}
return npcList;
}
@Override
public void run() {
runnable.run();
// Load all items
PostSetup.loadItems();
// Load all worlds
SlimefunPlugin.getWorldSettingsService().load(Bukkit.getWorlds());
for (World world : Bukkit.getWorlds()) {
try {
new BlockStorage(world);
}
catch (Exception x) {
Slimefun.getLogger().log(Level.SEVERE, x, () -> "An Error occured while trying to load World \"" + world.getName() + "\" for Slimefun v" + SlimefunPlugin.getVersion());
}
}
// Load all listeners that depend on items to be enabled
if (isEnabled("ELEVATOR_PLATE", "GPS_ACTIVATION_DEVICE_SHARED", "GPS_ACTIVATION_DEVICE_PERSONAL")) {
new TeleporterListener(plugin);
}
if (isEnabled("PROGRAMMABLE_ANDROID_BUTCHER", "PROGRAMMABLE_ANDROID_2_BUTCHER", "PROGRAMMABLE_ANDROID_3_BUTCHER")) {
new ButcherAndroidListener(plugin);
}
if (isEnabled("ENERGY_REGULATOR", "CARGO_MANAGER")) {
new NetworkListener(plugin, SlimefunPlugin.getNetworkManager());
}
}
@Override
public void run() {
for (World world : Bukkit.getWorlds()) {
WorldClimateEngine climateEngine = ClimateEngine.getInstance().getClimateEngine(world.getUID());
if (climateEngine != null && climateEngine.isEffectEnabled(ClimateEffectType.PERMANENT_SLOWNESS)) {
for (Player player : world.getPlayers()) {
updatePlayerSlowness(player, climateEngine.getTemperature());
}
}
}
}
@Override
public void onDisable() {
for (final World world : Bukkit.getWorlds()) {
if (worlds.worldMatches(world)) {
world.setPVP(false);
}
}
}
public long getCanPurgePlayer(String player, String world) {
if (RedProtect.get().config.configRoot().purge.purge_limit_perworld) {
return regionManagers.get(world).getCanPurgeCount(player, false);
} else {
long total = 0;
for (World wr : Bukkit.getWorlds()) {
total += regionManagers.get(wr.getName()).getCanPurgeCount(player, false);
}
return total;
}
}
/**
* does the same as tickDuctSpawnAndDespawn(Duct duct) but for all ducts in all worlds
*/
private void tickDuctSpawnAndDespawn() {
synchronized (globalDuctManager.getDucts()) {
for (World world : Bukkit.getWorlds()) {
Map<BlockLocation, Duct> ductMap = globalDuctManager.getDucts(world);
if (ductMap != null) {
for (Duct duct : ductMap.values()) {
tickDuctSpawnAndDespawn(duct);
}
}
}
}
}
@EventHandler
public void onServerLoad(ServerLoadEvent event) {
List<World> worlds = Bukkit.getWorlds();
for (int i = 0; i < worlds.size(); i++) {
int period = (int) Math.round(sm.getCustomConfig().getDouble("task-delay") / worlds.size()) * (i == 0 ? 1 : i);
new StackTask(sm, worlds.get(i)).runTaskTimer(sm, 100, period);
}
}
/**
* Returns online players.
*
* @return players
*/
public static List<Player> getOnlinePlayers() {
final List<Player> players = new ArrayList<>();
for (final World world : Bukkit.getWorlds()) {
players.addAll(world.getPlayers());
}
return players;
}
public static void init() {
entityUIDs = new ConcurrentHashMap<Integer, UUID>();
playerNames = Maps.synchronizedBiMap(HashBiMap.<UUID, String>create());
entityTypes = new ConcurrentHashMap<UUID, EntityType>();
for(World world : Bukkit.getWorlds()) {
for(LivingEntity livingEntity : world.getLivingEntities()) {
addEntity(livingEntity);
}
}
}
private void displayWorldInfo(CommandSender sender) {
int entities = 0;
int chunks = 0;
int livingEntities = 0;
int tileEntities = 0;
long usedWorldSize = 0;
List<World> worlds = Bukkit.getWorlds();
for (World world : worlds) {
for (Chunk loadedChunk : world.getLoadedChunks()) {
tileEntities += loadedChunk.getTileEntities().length;
}
livingEntities += world.getLivingEntities().size();
entities += world.getEntities().size();
chunks += world.getLoadedChunks().length;
File worldFolder = Bukkit.getWorld(world.getUID()).getWorldFolder();
usedWorldSize += LagUtils.getFolderSize(plugin.getLogger(), worldFolder.toPath());
}
sendMessage(sender, "Entities", String.format("%d/%d", livingEntities, entities));
sendMessage(sender, "Tile Entities", String.valueOf(tileEntities));
sendMessage(sender, "Loaded Chunks", String.valueOf(chunks));
sendMessage(sender, "Worlds", String.valueOf(worlds.size()));
sendMessage(sender, "World Size", readableBytes(usedWorldSize));
}
/**
* Prints the timings and extra data to the given stream.
*
* @param printStream
*/
public static void printTimings(PrintStream printStream)
{
printStream.println( "Minecraft" );
for ( CustomTimingsHandler timings : HANDLERS )
{
long time = timings.totalTime;
long count = timings.count;
if ( count == 0 )
{
continue;
}
long avg = time / count;
printStream.println( " " + timings.name + " Time: " + time + " Count: " + count + " Avg: " + avg + " Violations: " + timings.violations );
}
printStream.println( "# Version " + Bukkit.getVersion() );
int entities = 0;
int livingEntities = 0;
for ( World world : Bukkit.getWorlds() )
{
entities += world.getEntities().size();
livingEntities += world.getLivingEntities().size();
}
printStream.println( "# Entities " + entities );
printStream.println( "# LivingEntities " + livingEntities );
}
@SuppressWarnings({"unchecked", "rawtypes"})
@Override
public void run() {
if (this.economy == null) {
this.economy = GriefDefenderPlugin.getInstance().getVaultProvider().getApi();
}
for (World world : Bukkit.getWorlds()) {
if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(world.getUID())) {
continue;
}
GDClaimManager claimManager = GriefDefenderPlugin.getInstance().dataStore.getClaimWorldManager(world.getUID());
ArrayList<Claim> claimList = (ArrayList<Claim>) new ArrayList<>(claimManager.getWorldClaims());
if (claimList.size() == 0) {
return;
}
Iterator<GDClaim> iterator = ((ArrayList) claimList.clone()).iterator();
while (iterator.hasNext()) {
GDClaim claim = iterator.next();
final GDPlayerData playerData = claim.getOwnerPlayerData();
if (claim.isWilderness()) {
continue;
}
if (playerData == null) {
continue;
}
if (!playerData.dataInitialized) {
continue;
}
if (claim.isAdminClaim()) {
// search for town
final Set<Claim> children = claim.getChildren(false);
for (Claim child : children) {
if (child.isTown()) {
handleTownTax((GDClaim) child, playerData);
} else if (child.isBasicClaim()) {
handleClaimTax((GDClaim) child, playerData, false);
}
}
} else {
if (claim.isTown()) {
handleTownTax(claim, playerData);
} else if (claim.isBasicClaim()){
handleClaimTax(claim, playerData, false);
}
}
}
}
}
@Override
public void execute(CommandSender sender, String label, String[] args) throws CommandException {
boolean foundAnyHologram = false;
for (World world : Bukkit.getWorlds()) {
Map<Hologram, HologramDebugInfo> hologramsDebugInfo = new HashMap<>();
for (Chunk chunk : world.getLoadedChunks()) {
for (Entity entity : chunk.getEntities()) {
NMSEntityBase nmsEntity = HolographicDisplays.getNMSManager().getNMSEntityBase(entity);
if (nmsEntity == null) {
continue;
}
Hologram ownerHologram = nmsEntity.getHologramLine().getParent();
HologramDebugInfo hologramDebugInfo = hologramsDebugInfo.computeIfAbsent(ownerHologram, mapKey -> new HologramDebugInfo());
if (nmsEntity.isDeadNMS()) {
hologramDebugInfo.deadEntities++;
} else {
hologramDebugInfo.aliveEntities++;
}
}
}
if (!hologramsDebugInfo.isEmpty()) {
foundAnyHologram = true;
sender.sendMessage(Colors.PRIMARY + "Holograms in world '" + world.getName() + "':");
for (Entry<Hologram, HologramDebugInfo> entry : hologramsDebugInfo.entrySet()) {
Hologram hologram = entry.getKey();
String displayName = getHologramDisplayName(hologram);
HologramDebugInfo debugInfo = entry.getValue();
sender.sendMessage(Colors.PRIMARY_SHADOW + "- '" + displayName + "': " + hologram.size() + " lines, "
+ debugInfo.getTotalEntities() + " entities (" + debugInfo.aliveEntities + " alive, " + debugInfo.deadEntities + " dead)");
}
}
}
if (!foundAnyHologram) {
sender.sendMessage(Colors.ERROR + "Couldn't find any loaded hologram (holograms may be in unloaded chunks).");
}
}
public void list_cmd() {
CivMessage.sendHeading(sender, "Worlds");
for (World world : Bukkit.getWorlds()) {
CivMessage.send(sender, world.getName());
}
}
/**
* Despawn all npc's on all worlds.
*/
public void despawnAll() {
for(World world : Bukkit.getWorlds()) {
despawnAll(world);
}
}
public void loadAll() throws Exception {
for (World w : Bukkit.getWorlds()) {
load(w.getName());
}
}
public static void buildWorldList() {
for (World world : Bukkit.getWorlds()) {
worlds.put(world.getName(), world);
}
}