Permalink
Browse files

New initialization system

  • Loading branch information...
1 parent 2e2e04b commit 3848274d3eda0757c249e79f8623d47190c8adbe @aumgn aumgn committed Sep 13, 2013
@@ -9,26 +9,22 @@
* Represents the Glydar API
*/
public final class ParaGlydar {
- private static Server s;
- private static ModelCreator mc;
- private static DataCreator dc;
- private static PluginLoader pl;
+
+ private static Server server;
/**
* Static class cannot be initialized.
*/
private ParaGlydar() {
}
- ;
-
/**
* Gets the current {@link Server} singleton
*
* @return Server instance being ran
*/
public static Server getServer() {
- return s;
+ return server;
}
/**
@@ -39,8 +35,8 @@ public static Server getServer() {
* @param server Server instance
*/
public static void setServer(Server server) {
- if (s == null) {
- s = server;
+ if (ParaGlydar.server == null) {
+ ParaGlydar.server = server;
} else {
getLogger().severe("Can't change the server instance!");
}
@@ -52,7 +48,7 @@ public static void setServer(Server server) {
* @return DataCreator instance
*/
public static DataCreator getDataCreator() {
- return dc;
+ return server.getDataCreator();
}
/**
@@ -61,30 +57,16 @@ public static DataCreator getDataCreator() {
* @return ModelCreator instance
*/
public static ModelCreator getModelCreator() {
- return mc;
- }
-
- /**
- * Sets the plugin loader for this runtime.
- * Should not be used by plugins.
- *
- * @param pluginLoader PluginLoader to be set to
- */
- public static void setPluginLoader(PluginLoader pluginLoader) {
- if (pl == null) {
- pl = pluginLoader;
- } else {
- getLogger().severe("Can't change the plugin loader instance!");
- }
+ return server.getModelCreator();
}
-
+
/**
* Gets the plugin loader for this runtime.
*
* @return The plugin loader
*/
public static PluginLoader getPluginLoader(){
- return pl;
+ return server.getPluginLoader();
}
/**
@@ -93,18 +75,6 @@ public static PluginLoader getPluginLoader(){
* @return
*/
public static GlydarLogger getLogger() {
- return s.getLogger();
- }
-
- /**
- * Sets the creator API for this runtime
- * Should not be used by plugins.
- *
- * @param m ModelCreator to be set to
- * @param d DataCreator to be set to
- */
- public static void setCreatorAPI(ModelCreator m, DataCreator d) {
- mc = m;
- dc = d;
+ return server.getLogger();
}
}
@@ -5,48 +5,59 @@
import java.util.List;
import org.glydar.paraglydar.command.manager.CommandManager;
+import org.glydar.paraglydar.data.DataCreator;
import org.glydar.paraglydar.event.manager.EventManager;
import org.glydar.paraglydar.logging.GlydarLogger;
import org.glydar.paraglydar.models.Entity;
+import org.glydar.paraglydar.models.ModelCreator;
import org.glydar.paraglydar.models.Player;
import org.glydar.paraglydar.models.World;
import org.glydar.paraglydar.permissions.Permission;
+import org.glydar.paraglydar.plugin.PluginLoader;
public interface Server {
/**
- * Gets the base folder this server use for
+ * Gets the server's name
+ * @return Name of the server
*/
- Path getBaseFolder();
+ public String getName();
/**
- * Gets the base folder this server use for
+ * Gets the server's implementation version
+ * @return Version of the server
*/
- Path getConfigFolder();
+ public String getVersion();
+
+ public Path getBaseFolder();
+
+ public Path getConfigFolder();
+
+ /**
+ * Gets the logger for this runtime
+ * @return This runtime's logger
+ */
+ public GlydarLogger getLogger();
+
+ public ServerConfig getConfig();
+
+ public PluginLoader getPluginLoader();
/**
* Gets the event manager currently used
* @return The EventManager that Glydar is currently using
*/
public EventManager getEventManager();
-
+
/**
* Gets the command manager currently used
* @return The CommandManager that Glydar is currently using
*/
public CommandManager getCommandManager();
- /**
- * Gets the server's name
- * @return Name of the server
- */
- public String getName();
+ public DataCreator getDataCreator();
- /**
- * Gets the server's implementation version
- * @return Version of the server
- */
- public String getVersion();
+ public ModelCreator getModelCreator();
/**
* Gets all currently connected players
@@ -87,12 +98,6 @@
public List<World> getWorlds();
/**
- * Gets the logger for this runtime
- * @return This runtime's logger
- */
- public GlydarLogger getLogger();
-
- /**
* Returns true if the server is currently running.
* @return Whether or not the server is currently running.
*/
@@ -122,35 +127,10 @@
* @param permission The permission to be matched against
*/
public void broadcast(String message, Permission permission);
-
- /**
- * Returns true if the server is currently in debug mode
- * @return Whether or not the server is currently in debug mode
- */
- public boolean isDebugging();
-
+
/**
* If debugging is enabled, then the specified message is printed to the console
* @param message The debug message to be sent
*/
public void debug(String message);
-
- /**
- * Returns the maximum amount of players that are allowed on the server at any one point in time
- * @return Maximum amount of players
- */
- public int getMaxPlayers();
-
- /**
- * Cheaty way to set the maximum amount of players
- * @param maxPlayers Maximum amount of players
- */
- public void setMaxPlayers(int maxPlayers);
-
- /**
- * Returns the port that the server is currently running on
- * @return The port
- */
- public int getPort();
-
}
@@ -0,0 +1,42 @@
+package org.glydar.paraglydar;
+
+import java.util.List;
+import java.util.Set;
+
+import org.glydar.paraglydar.models.World;
+
+public interface ServerConfig {
+
+ boolean isDebug();
+
+ int getPort();
+
+ int getFPS();
+
+ int getMaxPlayers();
+
+ void setMaxPlayers(int maxPlayers);
+
+ Set<String> getAdmins();
+
+ boolean addAdmin(String name);
+
+ boolean removeAdmin(String name);
+
+ WorldConfig getDefaultWorldConfig();
+
+ List<WorldConfig> getAllWorldsConfigs();
+
+ List<WorldConfig> getOtherWorldsConfigs();
+
+ void persistWorld(World world);
+
+ interface WorldConfig {
+
+ String getName();
+
+ int getSeed();
+
+ boolean isPvpAllowed();
+ }
+}
@@ -16,11 +16,8 @@
import java.util.Map.Entry;
import java.util.ServiceLoader;
import java.util.Set;
-import java.util.logging.Level;
import java.util.regex.Pattern;
-import org.glydar.paraglydar.ParaGlydar;
-
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
@@ -93,7 +90,6 @@ private void actuallyLoad(Map<String, Object> map, I18nFormatLoader loader, Loca
putAll(map, loader.load(reader), locale);
}
catch (IOException exc) {
- ParaGlydar.getLogger().log(Level.SEVERE, "Unable to read localization data for location : " + location, exc);
}
}
@@ -39,7 +39,7 @@ public void setParent(GlydarLogger logger) {
public void log(Level level, Throwable thrown, String message, Object... parameters) {
GlydarLogRecord record = new GlydarLogRecord(level, message, prefix);
record.setThrown(thrown);
- if (parameters.length > 1) {
+ if (parameters.length > 0) {
record.setParameters(parameters);
}

0 comments on commit 3848274

Please sign in to comment.