Пример #1
0
  /** Plays the Error sound at given location depending on the machine TEMPORARY SOLUTION~~~ */
  public void playErrorSound(Location machineLocation, MachineType machineType) {
    Manager manager;
    switch (machineType) {
      case OREGIN:
        manager = getManager(OreGinManager.class);
        break;
      case CLOAKER:
        manager = getManager(CloakerManager.class);
        break;
      default:
        manager = null;
        break;
    }

    if (manager != null) {
      Machine machine = manager.getMachine(machineLocation);

      if (machine != null) {
        switch (machineType) {
          case OREGIN:
            OreGinSoundCollection.getErrorSound().playSound(machineLocation);
            break;
          case CLOAKER:
            CloakerSoundCollection.getErrorSound().playSound(machineLocation);
            break;
          case SMELTER:
            break;
        }
      }
    }
  }
Пример #2
0
 /** Returns whether a machine exists at given location in any manager */
 public boolean machineExistsAt(Location location) {
   for (Manager manager : managers) {
     if (manager.machineExistsAt(location)) {
       return true;
     }
   }
   return false;
 }
Пример #3
0
  /** Load file */
  private static void load(Manager managerInterface, File file) {
    try {
      managerInterface.load(file);
    } catch (FileNotFoundException exception) {
      Bukkit.getServer().getLogger().info(file.getName() + " does not exist! Creating file!");
    } catch (IOException exception) {
      throw new RuntimeException("Failed to load " + file.getPath(), exception);
    }

    try {
      managerInterface.save(file);
    } catch (IOException exception) {
      throw new RuntimeException("Failed to create " + file.getPath(), exception);
    }
  }
Пример #4
0
  /** Save file */
  private static void save(Manager manager, File file) {
    try {
      File newFile = new File(file.getAbsolutePath() + ".new");
      File bakFile = new File(file.getAbsolutePath() + ".bak");

      manager.save(newFile);

      if (bakFile.exists()) {
        bakFile.delete();
      }

      if (file.exists() && !file.renameTo(bakFile)) {
        throw new IOException(
            "Failed to rename " + file.getAbsolutePath() + " to " + bakFile.getAbsolutePath());
      }

      if (!newFile.renameTo(file)) {
        throw new IOException(
            "Failed to rename " + newFile.getAbsolutePath() + " to " + file.getAbsolutePath());
      }
    } catch (IOException exception) {
      throw new RuntimeException("Failed to save to " + file.getAbsolutePath(), exception);
    }
  }
Пример #5
0
 /** Loads all managers */
 private void loadManagers() {
   for (Manager manager : managers) {
     load(manager, getSavesFile(manager.getSavesFileName()));
   }
 }
Пример #6
0
 /** Saves all managers */
 private void saveManagers() {
   for (Manager manager : managers) {
     save(manager, getSavesFile(manager.getSavesFileName()));
   }
 }