Exemplo n.º 1
0
 public static void main(String[] args) {
   MinecraftServer.main(args);
 }
Exemplo n.º 2
0
  public static void main(String[] args) {
    log = Logger.getLogger(Main.class.getName());
    try {
      // Setting up logging

      Logger packageLog = Logger.getLogger(ChatBot.class.getPackage().getName());
      File logFile = new File(LOGFILE + ".log");
      if (logFile.exists()) {
        Calendar cal = Calendar.getInstance();
        File backup =
            new File(
                String.format(
                    "%s_%d_%d_%d.log",
                    LOGFILE,
                    cal.get(Calendar.YEAR),
                    cal.get(Calendar.MONTH) + 1,
                    cal.get(Calendar.DAY_OF_MONTH)));
        if (backup.exists())
          try (BufferedReader reader = new BufferedReader(new FileReader(logFile));
              PrintWriter writer = new PrintWriter(new FileWriter(backup, true))) {
            char buff[] = new char[1024];
            int n;
            while ((n = reader.read(buff)) > 0) {
              writer.write(buff, 0, n);
            }
            log.info("Appened log to backup " + backup.getName());
          } catch (IOException e) {
            log.log(Level.SEVERE, "Couldn't append log to " + backup.getName(), e);
          }
        else {
          try {
            FileUtils.moveFile(logFile, backup);
            log.info("Moved log to backup " + backup.getName());
          } catch (IOException e) {
            log.log(Level.SEVERE, "Couldn't move log to " + backup.getName(), e);
          }
        }
      }

      //noinspection ResultOfMethodCallIgnored
      // logFile.delete();
      Handler handler = new FileHandler(LOGFILE + ".log");
      handler.setFormatter(new SimpleFormatter());
      packageLog.setLevel(Level.FINE);
      packageLog.addHandler(handler);

      // Starting up XMPPCraft
      Main main = new Main();
      PipeInputStream stdinPipe = new PipeInputStream(1048576);
      PipeOutputStream stdoutPipe = new PipeOutputStream();
      main.init(
          System.in, new PipeOutputStream(stdinPipe), new PipeInputStream(stdoutPipe, 1048576));
      System.setIn(stdinPipe);
      System.setOut(new PrintStream(new TeeOutputStream(System.out, stdoutPipe)));
      main.start();
      // Starting up Minecraft
      MinecraftServer.main(args);
      // DummyMinecraftServer.main(args);
    } catch (KeyManagementException
        | NoSuchAlgorithmException
        | SmackException
        | XMPPException
        | IOException e) {
      String filename =
          String.format(
              "crashreport_%s_%s.log",
              e.getClass().getSimpleName(), new SimpleDateFormat("MM_dd.HH_mm").format(new Date()));
      File f = new File(filename);
      try {
        if (f.createNewFile()) {
          PrintWriter out = new PrintWriter(f);
          out.println("Error on startup :");
          out.printf(
              "JVM: %s %s on %s\n",
              System.getProperty("java.vm.name"),
              System.getProperty("java.runtime.version"),
              System.getProperty("os.name"));
          e.printStackTrace(out);
          out.flush();
          out.close();
        }
      } catch (IOException ignore) {
      } // lol what can you do
      log.severe("Crash detected. Generating report.");
    }
  }
Exemplo n.º 3
0
  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("W", "world-dir", "universe", "world-container"), "World container")
                .withRequiredArg()
                .ofType(File.class)
                .describedAs("Directory containing worlds");

            acceptsAll(asList("w", "world", "level-name"), "World name")
                .withRequiredArg()
                .ofType(String.class)
                .describedAs("World name");

            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");

            acceptsAll(
                    asList("d", "date-format"),
                    "Format of the date to display in the console (for log entries)")
                .withRequiredArg()
                .ofType(SimpleDateFormat.class)
                .describedAs("Log date format");

            acceptsAll(asList("log-pattern"), "Specfies the log filename pattern")
                .withRequiredArg()
                .ofType(String.class)
                .defaultsTo("server.log")
                .describedAs("Log filename");

            acceptsAll(
                    asList("log-limit"), "Limits the maximum size of the log file (0 = unlimited)")
                .withRequiredArg()
                .ofType(Integer.class)
                .defaultsTo(0)
                .describedAs("Max log size");

            acceptsAll(asList("log-count"), "Specified how many log files to cycle through")
                .withRequiredArg()
                .ofType(Integer.class)
                .defaultsTo(1)
                .describedAs("Log count");

            acceptsAll(asList("log-append"), "Whether to append to the log file")
                .withRequiredArg()
                .ofType(Boolean.class)
                .defaultsTo(true)
                .describedAs("Log append");

            acceptsAll(asList("log-strip-color"), "Strips color codes from log file");

            acceptsAll(asList("b", "bukkit-settings"), "File for bukkit settings")
                .withRequiredArg()
                .ofType(File.class)
                .defaultsTo(new File("bukkit.yml"))
                .describedAs("Yml file");

            acceptsAll(asList("C", "commands-settings"), "File for command settings")
                .withRequiredArg()
                .ofType(File.class)
                .defaultsTo(new File("commands.yml"))
                .describedAs("Yml file");

            acceptsAll(asList("nojline"), "Disables jline and emulates the vanilla console");

            acceptsAll(asList("noconsole"), "Disables the console");

            acceptsAll(asList("v", "version"), "Show the CraftBukkit Version");

            acceptsAll(asList("demo"), "Demo mode");
          }
        };

    OptionSet options = null;

    try {
      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 if (options.has("v")) {
      System.out.println(CraftServer.class.getPackage().getImplementationVersion());
    } else {
      try {
        // This trick bypasses Maven Shade's clever rewriting of our getProperty call when using
        // String literals
        String jline_UnsupportedTerminal =
            new String(
                new char[] {
                  'j', 'l', 'i', 'n', 'e', '.', 'U', 'n', 's', 'u', 'p', 'p', 'o', 'r', 't', 'e',
                  'd', 'T', 'e', 'r', 'm', 'i', 'n', 'a', 'l'
                });
        String jline_terminal =
            new String(
                new char[] {'j', 'l', 'i', 'n', 'e', '.', 't', 'e', 'r', 'm', 'i', 'n', 'a', 'l'});

        useJline = !(jline_UnsupportedTerminal).equals(System.getProperty(jline_terminal));

        if (options.has("nojline")) {
          System.setProperty("user.language", "en");
          useJline = false;
        }

        if (!useJline) {
          // This ensures the terminal literal will always match the jline implementation
          System.setProperty(
              jline.TerminalFactory.JLINE_TERMINAL, jline.UnsupportedTerminal.class.getName());
        }

        if (options.has("noconsole")) {
          useConsole = false;
        }

        // Spigot Start
        int maxPermGen = 0; // In kb
        for (String s :
            java.lang.management.ManagementFactory.getRuntimeMXBean().getInputArguments()) {
          if (s.startsWith("-XX:MaxPermSize")) {
            maxPermGen = Integer.parseInt(s.replaceAll("[^\\d]", ""));
            maxPermGen <<= 10 * ("kmg".indexOf(Character.toLowerCase(s.charAt(s.length() - 1))));
          }
        }
        if (maxPermGen < (128 << 10)) // 128mb
        {
          System.out.println(
              "Warning, your max perm gen size is not set or less than 128mb. It is recommended you restart Java with the following argument: -XX:MaxPermSize=128M");
          System.out.println(
              "Please see http://www.spigotmc.org/wiki/changing-permgen-size/ for more details and more in-depth instructions.");
        }
        // Spigot End
        System.out.println("Loading libraries, please wait...");
        MinecraftServer.main(options);
      } catch (Throwable t) {
        t.printStackTrace();
      }
    }
  }