Example #1
0
 /** Test of main method, of class MainClass. */
 @Test
 public void testMain() {
   System.out.println("main");
   String[] Args = null;
   MainClass.main(Args);
   // TODO review the generated test code and remove the default call to fail.
   // fail("The test case is a prototype.");
 }
Example #2
0
 @Override
 public boolean keyDown(int keyCode) {
   if (keyCode == Input.Keys.BACK) {
     if (pause) {
       pause = false;
       pauseButton.setChecked(false);
       exitButton.setVisible(false);
     } else {
       MainClass.setCurrentStage(new Stage_Menu(getViewport()));
     }
   }
   return super.keyDown(keyCode);
 }
Example #3
0
  @Override
  public void run() {

    // 1-65535
    try {
      ServerSocket serverSocket = new ServerSocket(1995);
      while (true) {
        // accept()会阻塞主线程,故要开一个新的线程处理
        Socket socket = serverSocket.accept();
        // 建立连接
        MainClass.print("有客户端链接到了本机的1995端口");
        Client_num++;
        MainClass.print(socket.getInetAddress().toString());
        // 将socket传递给新的线程
        ChatSocket cs = new ChatSocket(socket);
        cs.start();
        ChatManager.getChatManager().add(cs);
      }

    } catch (IOException e) {
      e.printStackTrace();
    }
  }
  @Override
  public void visit(MainClass main) {
    System.out.print("class ");
    if (main.getClassId() != null) main.getClassId().accept(this);
    System.out.println(" {");

    System.out.print("\tpublic static void main(String[] ");
    if (main.getArgId() != null) main.getArgId().accept(this);
    System.out.println(") {");

    System.out.print("\t\t");
    if (main.getStm() != null) main.getStm().accept(this);
    System.out.println();
    System.out.println("\t}");
    System.out.println("}");
  }
  /**
   * Starting point
   *
   * @param args
   */
  public static void main(String args[]) {
    System.out.println("Program initialisation");

    // Initializing Logs
    final long startTime = System.currentTimeMillis();

    System.out.println("Initializing logs");

    String logDirectory = "./log";
    String allLogFileName = "all.log";
    String infoLogFileName = "info.log";
    String warningLogFileName = "warning.log";
    String errorLogFileName = "error.log";
    String debugLogFileName = "debug.log";
    String harvesterLogFileName = "log/harvester.log";

    File logdir = new File(logDirectory);
    logdir.mkdir();
    File allFile = new File(logDirectory + "/" + allLogFileName);
    File infoFile = new File(logDirectory + "/" + infoLogFileName);
    File warningFile = new File(logDirectory + "/" + warningLogFileName);
    File errorFile = new File(logDirectory + "/" + errorLogFileName);
    File debugFile = new File(logDirectory + "/" + debugLogFileName);
    File harvesterFile = new File(harvesterLogFileName);

    allFile.delete();
    infoFile.delete();
    warningFile.delete();
    errorFile.delete();
    debugFile.delete();

    // Set loggers outputs
    try {
      FileOutputStream allFileOutputStream = new FileOutputStream(allFile, true);
      FileOutputStream harvesterFileOutputStream = new FileOutputStream(harvesterFile, true);
      FileOutputStream infoFileOutputStream = new FileOutputStream(infoFile, true);
      FileOutputStream warningFileOutputStream = new FileOutputStream(warningFile, true);
      FileOutputStream errorFileOutputStream = new FileOutputStream(errorFile, true);
      FileOutputStream debugFileOutputStream = new FileOutputStream(debugFile, true);
      RFHarvesterLogger.setInfoLog(
          new TeeOutputStream(
              System.out,
              new TeeOutputStream(
                  harvesterFileOutputStream,
                  new TeeOutputStream(allFileOutputStream, infoFileOutputStream))));
      RFHarvesterLogger.setWarningLog(
          new TeeOutputStream(
              System.out,
              new TeeOutputStream(
                  harvesterFileOutputStream,
                  new TeeOutputStream(allFileOutputStream, warningFileOutputStream))));
      RFHarvesterLogger.setErrorLog(
          new TeeOutputStream(
              System.out,
              new TeeOutputStream(
                  harvesterFileOutputStream,
                  new TeeOutputStream(allFileOutputStream, errorFileOutputStream))));
      RFHarvesterLogger.setDebugLog(
          new TeeOutputStream(
              System.out,
              new TeeOutputStream(
                  harvesterFileOutputStream,
                  new TeeOutputStream(allFileOutputStream, debugFileOutputStream))));
    } catch (FileNotFoundException e) {
      e.printStackTrace();
      System.exit(
          ExitCodes.EX_CANTCREAT.value()); // Program won't run without correctly set loggers.
    }

    RFHarvesterLogger.setDatation(true);
    RFHarvesterLogger.info("Logs correctly initialized");

    RFHarvesterState.begin();

    Runtime.getRuntime()
        .addShutdownHook(
            new Thread() {
              @Override
              public void run() {
                if (RFHarvesterState.checkRunningStatus() > 0) {
                  RFHarvesterState.updateStatus("Interrompue");
                  RFHarvesterState.updateMessage("Moisson interrompue.");
                }
                RFHarvesterState.endStatus();
                long endTime = System.currentTimeMillis();
                RFHarvesterLogger.info(
                    "Program ended at:   " + RFHarvesterDatation.getDateHour(endTime));
                RFHarvesterLogger.info(
                    "Program Total duration : "
                        + RFHarvesterDatation.duration(endTime - startTime));
                RFHarvesterLogger.info(
                    "------------------------------------------------------------------------------------------------------------------------");
                RFHarvesterLogger.debug(
                    "------------------------------------------------------------------------------------------------------------------------");
                RFHarvesterLogger.warning(
                    "------------------------------------------------------------------------------------------------------------------------");
                RFHarvesterLogger.error(
                    "------------------------------------------------------------------------------------------------------------------------");
              }
            });

    RFHarvesterLogger.info("Program started at: " + RFHarvesterDatation.getDateHour(startTime));

    MainClass program = new MainClass();
    ArrayList<String> arguments = new ArrayList<String>(Arrays.asList(args));

    int flags = 0b00000000000000000000000000000000;
    final int harvestFlag = 0b00000000000000000000000000000001;
    final int harvestParameter = 0b00000000000000000000000000000100;

    for (String arg : arguments) {
      RFHarvesterLogger.debug(arg);
      String[] argWithValues = arg.split("=");
      switch (argWithValues[0]) {
        case "--harvest":
          flags |= harvestFlag;
          if (argWithValues.length > 1) flags |= harvestParameter;
          break;
          // NEW WAY TO RUN CONFIGURATION, OTHER ONES ARE DEPRECATED
        case "--configuration":
          int exitCode = ExitCodes.EX_OK.value();
          if (argWithValues.length <= 1) {
            RFHarvesterLogger.error("ERROR: Missing configuration value.");
            RFHarvesterState.updateStatus("ERREUR!!!");
            RFHarvesterState.updateMessage("Missing configuration value.");
            exitCode = ExitCodes.EX_USAGE.value();
          } else {
            try {
              RFHarvesterState.updateConfiguration("ID: " + argWithValues[1]);
              program.runConfiguration(argWithValues[1]);
              RFHarvesterState.updateStatus("Terminée");
            } catch (Exception e) {
              String exceptionMessage = RFHarvesterLogger.exceptionToString(e);
              RFHarvesterLogger.error("FATAL ERROR!!!" + exceptionMessage);
              RFHarvesterState.updateStatus("ERREUR!!!");
              RFHarvesterState.updateMessage(exceptionMessage.split("\n")[1].trim());
              exitCode = ExitCodes.EX_SOFTWARE.value();
            }
          }
          System.exit(exitCode);
          break;

        case "--info":
        case "--list-properties":
        case "--version":
          break;
        default:
          System.out.println("Unknown property: " + argWithValues[0]);
          System.exit(ExitCodes.EX_USAGE.value());
          break;
      }
    }
    if (((flags & harvestFlag) != harvestFlag)) {
      System.out.println("Missing mandatory property --harvest");
      System.exit(ExitCodes.EX_USAGE.value());
    } else if ((flags & harvestParameter) != harvestParameter) {
      System.out.println("Property --harvest have no defined value");
      System.exit(ExitCodes.EX_USAGE.value());
    }

    String harvest = null;
    for (String arg : arguments) {
      String[] argWithValues = arg.split("=");
      switch (argWithValues[0]) {
        case "--list-properties":
          System.getProperties().list(System.out);
          break;
        case "--restore":
          if (argWithValues.length > 2) {
            System.out.println("Property --harvest wrongly defined: " + arg.substring(10));
            System.exit(ExitCodes.EX_USAGE.value());
          }
          harvest = argWithValues[1];
          break;
        case "--harvest":
          if (argWithValues.length > 2) {
            System.out.println("Property --harvest wrongly defined: " + arg.substring(10));
            System.exit(ExitCodes.EX_USAGE.value());
          }
          harvest = argWithValues[1];
          break;
        default:
          break;
      }
    }

    if (((flags & harvestFlag) == harvestFlag)) {
      switch (harvest) {
        case "portfolio":
          program.harvestPortfolio();
          RFHarvesterState.updateStatus("Terminée");
          break;
        case "authorities":
          program.harvestAuthorities();
          RFHarvesterState.updateStatus("Terminée");
          break;
        default:
          RFHarvesterLogger.error("Unrecognized harvesting value: " + harvest);
          break;
      }
    }
  }
  @Override
  public boolean onCommand(CommandSender cs, Command command, String string, String[] args) {
    Player player = (Player) cs;
    World w = Bukkit.getServer().getWorld("World");
    if (string.equalsIgnoreCase("fexplode")) {
      if (player.hasPermission("explosionman.fexplode") || player.isOp()) {
        @SuppressWarnings("unused")
        boolean canexplode = true;
        @SuppressWarnings("deprecation")
        Block lookBlock = player.getTargetBlock(null, 200);
        Location plocation = lookBlock.getLocation();
        if (args.length == 0) {
          if (MainClass.getConfig().getBoolean("fexplodemsg")) {
            String fexplodemsg =
                MainClass.getConfig()
                    .getString("fexplodetext")
                    .replaceAll("(&([a-f0-9]))", "\u00A7$2");
            player.sendMessage(fexplodemsg);
          }
          w.createExplosion(plocation, MainClass.getConfig().getInt("fexplodepower"));
          if (player.hasPermission("explosionman.fexplodelightning")) {
            w.strikeLightningEffect(plocation);
          }
        } else if (args.length == 1) {
          try {
            @SuppressWarnings("unused")
            float explosionPower = Float.parseFloat(args[0]);
          } catch (NumberFormatException e) {
            player.sendMessage(ChatColor.RED + "That is not a number!");
            return false;
          }
          float explosionPower = Float.parseFloat(args[0]);
          if (explosionPower > MainClass.getConfig().getInt("fexplodebigpower")) {
            if (player.hasPermission("explosionman.fexplodebig") || player.isOp()) {
              canexplode = true;
            } else {
              player.sendMessage(
                  ChatColor.RED + "You do not have permission to create such a large explosion!");
              canexplode = false;
              return false;
            }
          }
          if (canexplode = true) {
            if (MainClass.getConfig().getBoolean("fexplodemsg")) {
              String fexplodemsg =
                  MainClass.getConfig()
                      .getString("fexplodetext")
                      .replaceAll("(&([a-f0-9]))", "\u00A7$2");
              player.sendMessage(fexplodemsg);
            }
            w.createExplosion(plocation, explosionPower);
            if (player.hasPermission("explosionman.fexplodelightning")) {
              w.strikeLightningEffect(plocation);
            }
          }
        } else if (args.length > 1) {
          player.sendMessage(
              ChatColor.RED + "The proper use is " + ChatColor.AQUA + "/fexplode [number]");
        }

      } else {
        player.sendMessage(ChatColor.RED + "You cannot make an explosion over there!");
      }
    }
    return false;
  }