diff options
author | Dinnerbone <dinnerbone@dinnerbone.com> | 2011-01-04 00:43:23 +0000 |
---|---|---|
committer | Dinnerbone <dinnerbone@dinnerbone.com> | 2011-01-04 00:43:23 +0000 |
commit | 7b08efd9d975a353cc93329998635db1fea3e402 (patch) | |
tree | d5e09bc4b2a84704ee856820b01d64914d75c90e | |
parent | b7f7c3ffb575725127f0cac602357fa7d81b1e4a (diff) | |
download | craftbukkit-7b08efd9d975a353cc93329998635db1fea3e402.tar craftbukkit-7b08efd9d975a353cc93329998635db1fea3e402.tar.gz craftbukkit-7b08efd9d975a353cc93329998635db1fea3e402.tar.lz craftbukkit-7b08efd9d975a353cc93329998635db1fea3e402.tar.xz craftbukkit-7b08efd9d975a353cc93329998635db1fea3e402.zip |
Added command-line arguments, forced nogui
-rw-r--r-- | pom.xml | 5 | ||||
-rw-r--r-- | src/main/java/net/minecraft/server/MinecraftServer.java | 18 | ||||
-rw-r--r-- | src/main/java/net/minecraft/server/PropertyManager.java | 92 | ||||
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/CraftServer.java | 2 | ||||
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/Main.java | 71 |
5 files changed, 177 insertions, 11 deletions
@@ -27,6 +27,11 @@ <type>jar</type> <scope>compile</scope> </dependency> + <dependency> + <groupId>net.sf.jopt-simple</groupId> + <artifactId>jopt-simple</artifactId> + <version>3.2</version> + </dependency> </dependencies> <!-- This builds a completely 'ready to start' jar with all dependencies inside --> <build> diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java index 333e0090..c3b2568c 100644 --- a/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java @@ -11,6 +11,7 @@ import java.util.Iterator; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; +import joptsimple.OptionSet; import org.bukkit.craftbukkit.CraftServer; @@ -37,14 +38,18 @@ implements ICommandListener, Runnable { public boolean n; public CraftServer server; // CraftBukkit + public OptionSet options; // CraftBukkit - public MinecraftServer() { + // CraftBukkit: Added arg "OptionSet options" + public MinecraftServer(final OptionSet options) { o = true; g = false; h = 0; p = new ArrayList<IUpdatePlayerListBox>(); q = Collections.synchronizedList(new ArrayList<ServerCommand>()); new ThreadSleepForever(this); + + this.options = options; // CraftBukkit } // CraftBukkit: added throws UnknownHostException @@ -60,7 +65,7 @@ implements ICommandListener, Runnable { a.warning("To start the server with more ram, launch it as \"java -Xmx1024M -Xms1024M -jar minecraft_server.jar\""); } a.info("Loading properties"); - d = new PropertyManager(new File("server.properties")); + d = new PropertyManager(options); // Craftbukkit String s = d.a("server-ip", ""); l = d.a("online-mode", true); @@ -450,18 +455,17 @@ implements ICommandListener, Runnable { p.add(iupdateplayerlistbox); } - public static void main(String args[]) { + // Craftbukkit start - replaces main(String args[]) + public static void main(final OptionSet options) { try { - MinecraftServer minecraftserver = new MinecraftServer(); + MinecraftServer minecraftserver = new MinecraftServer(options); - if (!java.awt.GraphicsEnvironment.isHeadless() && (args.length <= 0 || !args[0].equals("nogui"))) { - ServerGUI.a(minecraftserver); - } (new ThreadServerApplication("Server thread", minecraftserver)).start(); } catch (Exception exception) { a.log(Level.SEVERE, "Failed to start the minecraft server", exception); } } + // Craftbukkit end public File a(String s) { return new File(s); diff --git a/src/main/java/net/minecraft/server/PropertyManager.java b/src/main/java/net/minecraft/server/PropertyManager.java new file mode 100644 index 00000000..4be80a80 --- /dev/null +++ b/src/main/java/net/minecraft/server/PropertyManager.java @@ -0,0 +1,92 @@ +package net.minecraft.server; + + +import java.io.*; +import java.util.Properties; +import java.util.logging.Level; +import java.util.logging.Logger; +import joptsimple.OptionSet; + + +public class PropertyManager { + + public static Logger a = Logger.getLogger("Minecraft"); + private Properties b; + private File c; + + private OptionSet options = null; // Craftbukkit + + public PropertyManager(File file) { + b = new Properties(); + c = file; + if (file.exists()) { + try { + b.load(new FileInputStream(file)); + } catch (Exception exception) { + a.log(Level.WARNING, (new StringBuilder()).append("Failed to load ").append(file).toString(), exception); + a(); + } + } else { + a.log(Level.WARNING, (new StringBuilder()).append(file).append(" does not exist").toString()); + a(); + } + } + + // Craftbukkit start + public PropertyManager(final OptionSet options) { + this((File)options.valueOf("config")); + + this.options = options; + } + + private <T> T getOverride(String name, T value) { + if ((options != null) && (options.has(name))) { + return (T)options.valueOf(name); + } + + return value; + } + // Craftbukkit end + + public void a() { + a.log(Level.INFO, "Generating new properties file"); + b(); + } + + public void b() { + try { + b.store(new FileOutputStream(c), "Minecraft server properties"); + } catch (Exception exception) { + a.log(Level.WARNING, (new StringBuilder()).append("Failed to save ").append(c).toString(), exception); + a(); + } + } + + public String a(String s, String s1) { + if (!b.containsKey(s)) { + b.setProperty(s, getOverride(s, s1)); // Craftbukkit + b(); + } + return getOverride(s, b.getProperty(s, s1)); // Craftbukkit + } + + public int a(String s, int i) { + try { + return getOverride(s, Integer.parseInt(a(s, String.valueOf(i)))); // Craftbukkit + } catch (Exception exception) { + b.setProperty(s, getOverride(s, i).toString()); // Craftbukkit + } + return getOverride(s, i); // Craftbukkit + } + + public boolean a(String s, boolean flag) { + try { + return getOverride(s, Boolean.parseBoolean(a(s, String.valueOf(flag)))); // Craftbukkit + } catch (Exception exception) { + b.setProperty(s, getOverride(s, flag).toString()); // Craftbukkit + } + return getOverride(s, flag); // Craftbukkit + } + +} + diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java index e5758051..216a26b6 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -27,7 +27,7 @@ public final class CraftServer implements Server { pluginManager.RegisterInterface(JavaPluginLoader.class); - File pluginFolder = new File("plugins"); + File pluginFolder = (File)console.options.valueOf("plugins"); if (pluginFolder.exists()) { try { diff --git a/src/main/java/org/bukkit/craftbukkit/Main.java b/src/main/java/org/bukkit/craftbukkit/Main.java index 786e56d8..0f89768e 100644 --- a/src/main/java/org/bukkit/craftbukkit/Main.java +++ b/src/main/java/org/bukkit/craftbukkit/Main.java @@ -1,16 +1,81 @@ package org.bukkit.craftbukkit; +import java.io.File; +import java.io.IOException; +import java.util.Arrays; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; +import joptsimple.OptionParser; +import joptsimple.OptionSet; import net.minecraft.server.MinecraftServer; public class Main { public static void main(String[] args) { // Todo: Installation script + OptionParser parser = new OptionParser() { + { + acceptsAll(asList("?", "help"), "Show the help"); + + acceptsAll(asList("c", "config"), "Properties file to use") + .withRequiredArg() + .ofType(File.class) + .defaultsTo(new File("server.properties")) + .describedAs("Properties file"); + + acceptsAll(asList("P", "plugins"), "Plugin directory to use") + .withRequiredArg() + .ofType(File.class) + .defaultsTo(new File("plugins")) + .describedAs("Plugin directory"); + + acceptsAll(asList("h", "host", "server-ip"), "Host to listen on") + .withRequiredArg() + .ofType(String.class) + .describedAs("Hostname or IP"); + + acceptsAll(asList("p", "port", "server-port"), "Port to listen on") + .withRequiredArg() + .ofType(Integer.class) + .describedAs("Port"); + + acceptsAll(asList("o", "online-mode"), "Whether to use online authentication") + .withRequiredArg() + .ofType(Boolean.class) + .describedAs("Authentication"); + + acceptsAll(asList("s", "size", "max-players"), "Maximum amount of players") + .withRequiredArg() + .ofType(Integer.class) + .describedAs("Server size"); + } + }; + + OptionSet options = null; try { - MinecraftServer.main(args); - } catch (Throwable t) { - t.printStackTrace(); + options = parser.parse(args); + } catch (joptsimple.OptionException ex) { + Logger.getLogger(Main.class.getName()).log(Level.SEVERE, ex.getLocalizedMessage()); + } + + if ((options == null) || (options.has("?"))) { + try { + parser.printHelpOn(System.out); + } catch (IOException ex) { + Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); + } + } else { + try { + MinecraftServer.main(options); + } catch (Throwable t) { + t.printStackTrace(); + } } } + + private static List<String> asList(String... params) { + return Arrays.asList(params); + } } |