Example #1
0
  /**
   * File copier from xZise
   *
   * @param fromFile
   * @param toFile
   */
  private void copyFile(File fromFile, File toFile) {
    FileInputStream from = null;
    FileOutputStream to = null;
    try {
      from = new FileInputStream(fromFile);
      to = new FileOutputStream(toFile);
      byte[] buffer = new byte[4096];
      int bytesRead;

      while ((bytesRead = from.read(buffer)) != -1) {
        to.write(buffer, 0, bytesRead);
      }
    } catch (IOException ex) {
      WarpLogger.severe(
          "Failed to rename " + fromFile.getName() + "to " + toFile.getName() + ": ", ex);
    } finally {

      try {
        if (from != null) {
          from.close();
        }
        if (to != null) {
          to.close();
        }
      } catch (IOException e) {
      }
    }
  }
Example #2
0
 private void updateFiles(File oldDatabase, File newDatabase) {
   if (!getDataFolder().exists()) {
     getDataFolder().mkdirs();
   }
   if (newDatabase.exists()) {
     newDatabase.delete();
   }
   try {
     newDatabase.createNewFile();
   } catch (IOException ex) {
     WarpLogger.severe("Could not create new database file", ex);
   }
   copyFile(oldDatabase, newDatabase);
 }
Example #3
0
  @Override
  public void onEnable() {
    name = this.getDescription().getName();
    version = this.getDescription().getVersion();
    pm = getServer().getPluginManager();

    WarpSettings.initialize(this);
    LanguageManager.initialize(this);

    try {
      connectionManager = new ConnectionManager(WarpSettings.usemySQL, true, true, this);
    } catch (DataConnectionException e) {
      WarpLogger.severe("Could not establish database connection. Disabling MyWarp.");
      getServer().getPluginManager().disablePlugin(this);
      return;
    }

    File newDatabase = new File(getDataFolder(), "warps.db");
    File oldDatabase = new File("homes-warps.db");
    if (!newDatabase.exists() && oldDatabase.exists()) {
      updateFiles(oldDatabase, newDatabase);
    }

    warpList = new WarpList(getServer());
    warpPermissions = new WarpPermissions(this);
    blockListener = new MWBlockListener(this);
    entityListener = new MWEntityListener();
    playerListener = new MWPlayerListener(this);

    pm.registerEvents(blockListener, this);
    pm.registerEvents(entityListener, this);
    pm.registerEvents(playerListener, this);

    if (WarpSettings.useDynmap) {
      if (!pm.isPluginEnabled("dynmap")) {
        WarpLogger.severe("Failed to hook into Dynmap. Disabeling Dynmap support.");
      } else {
        markers = new DynmapMarkers(this);
      }
    }

    commandHandler = new CommandHandler(this);
    new CommandUtils(this);

    // basic commands
    commandHandler.addCommand(new CreateCommand(this));
    commandHandler.addCommand(new CreatePrivateCommand(this));
    commandHandler.addCommand(new DeleteCommand(this));
    commandHandler.addCommand(new ListCommand(this));
    commandHandler.addCommand(new ListAllCommand(this));
    commandHandler.addCommand(new PointCommand(this));
    commandHandler.addCommand(new SearchCommand(this));
    commandHandler.addCommand(new UpdateCommand(this));
    commandHandler.addCommand(new WelcomeCommand(this));
    commandHandler.addCommand(new WarpToCommand(this));

    // social commands
    commandHandler.addCommand(new GiveCommand(this));
    commandHandler.addCommand(new InviteCommand(this));
    commandHandler.addCommand(new PrivateCommand(this));
    commandHandler.addCommand(new PublicCommand(this));
    commandHandler.addCommand(new UninviteCommand(this));

    // help command
    commandHandler.addCommand(new HelpCommand(this));

    // admin commands
    commandHandler.addCommand(new AdminWarpToCommand(this));
    commandHandler.addCommand(new ReloadCommand(this));
    commandHandler.addCommand(new ImportCommand(this));

    WarpLogger.info(name + " " + version + " enabled");
  }