001/* 002 * Trident - A Multithreaded Server Alternative 003 * Copyright 2014 The TridentSDK Team 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018package net.tridentsdk.world; 019 020import net.tridentsdk.registry.Registered; 021import net.tridentsdk.world.gen.ChunkGenerator; 022import net.tridentsdk.world.gen.FeatureGenerator; 023import net.tridentsdk.world.settings.WorldCreateOptions; 024 025import javax.annotation.concurrent.ThreadSafe; 026import java.util.List; 027 028/** 029 * Manages the worlds for the server 030 * 031 * @author The TridentSDK Team 032 * @since 0.3-alpha-DP 033 */ 034@ThreadSafe 035public interface WorldLoader { 036 /** 037 * Creates a new world loader using the default generator 038 * 039 * @return the new world loader 040 */ 041 static WorldLoader newLoader() { 042 return Registered.impl().newLoader(null); 043 } 044 045 /** 046 * Creates a new world loader using the generator specified 047 * 048 * @param clas the class of the generator to use 049 * @return the new world loaer 050 */ 051 static WorldLoader newLoader(Class<? extends ChunkGenerator> clas) { 052 return Registered.impl().newLoader(clas); 053 } 054 055 /** 056 * Checks if the world has been loaded yet 057 * 058 * @param world the name of the folder to check 059 * @return {@code true} if the world has been loaded 060 */ 061 static boolean worldExists(String world) { 062 return Registered.worlds().containsKey(world); 063 } 064 065 /** 066 * Load an existing world inside the server's file container 067 * 068 * @param world the name of the folder containing a world 069 * @return the world loaded 070 */ 071 World load(String world); 072 073 /** 074 * Creates a new world 075 * 076 * @param name the name of the new world 077 * @return the world which was created 078 */ 079 World createWorld(String name); 080 081 /** 082 * Writes the changes made to the world to the world folder 083 */ 084 void save(); 085 086 /** 087 * Checks the existence of a chunk in a world, based on the world directory 088 * 089 * @param x the X coordinate of the chunk 090 * @param z the Z coordinate of the chunk 091 * @return {@code true} if the chunk is not present within the world directory 092 */ 093 boolean chunkExists(int x, int z); 094 095 /** 096 * Checks the existence of a chunk in a world, based on the world directory 097 * 098 * @param position the position which the chunk should be checked for existence 099 * @return {@code true} if the chunk is not present within the world directory 100 */ 101 boolean chunkExists(ChunkLocation position); 102 103 /** 104 * Loads the chunk into the world 105 * 106 * @param x the X of the chunk 107 * @param z the Z of the chunk 108 * @return the chunk which was loaded 109 */ 110 Chunk loadChunk(int x, int z); 111 112 /** 113 * Loads the chunk into the world 114 * 115 * @param position the position of the chunk to load 116 * @return the chunk which was loaded 117 */ 118 Chunk loadChunk(ChunkLocation position); 119 120 /** 121 * Writes the changes in the chunk to the world file 122 * 123 * @param chunk the chunk which to write the changes 124 */ 125 void saveChunk(Chunk chunk); 126 127 /** 128 * Options used for creating the world 129 * 130 * @return the world creation options 131 */ 132 WorldCreateOptions options(); 133 134 /** 135 * The generator used to load new chunks used by this world loader 136 * 137 * @return the generation abstraction to generated chunks 138 */ 139 ChunkGenerator generator(); 140 141 /** 142 * Obtains a mutable collection of the overlay brushes used to generate the world 143 * 144 * @return the overlay brushes 145 */ 146 List<FeatureGenerator> brushes(); 147}