public void loadCarpets() { File carpetDat = carpetsFile(); if (!carpetDat.exists()) { return; } log.info("Loading carpets..."); try { FileInputStream file = new FileInputStream(carpetDat); ObjectInputStream in = new ObjectInputStream(file); carpets = (CarpetStorage) in.readObject(); carpets.attach(this); in.close(); } catch (IOException e) { log.warning("Error loading carpets.dat; carpets data has not been loaded."); } catch (ClassNotFoundException e) { log.severe("CarpetStorage class not found! This should never happen!"); } carpets.checkCarpets(); }
public void saveCarpets() { File carpetDat = carpetsFile(); log.info("Saving carpets..."); if (!carpetDat.exists()) { try { carpetDat.createNewFile(); } catch (IOException e) { log.severe("Unable to create carpets.dat; IOException"); } } try { FileOutputStream file = new FileOutputStream(carpetDat); ObjectOutputStream out = new ObjectOutputStream(file); out.writeObject(carpets); out.close(); } catch (IOException e) { log.warning("Error writing to carpets.dat; carpets data has not been saved!"); } carpets.clear(); }
@SuppressWarnings("incomplete-switch") @Override public synchronized void run() { final List<WorldEditorException> errorList = new ArrayList<WorldEditorException>(); int counter = 0; while (!edits.isEmpty() && counter < 100) { try { switch (edits.poll().perform()) { case SUCCESS: successes++; break; case BLACKLISTED: blacklistCollisions++; break; } } catch (final WorldEditorException ex) { errorList.add(ex); } catch (final Exception ex) { getLogger().log(Level.WARNING, "[LogBlock WorldEditor] Exeption: ", ex); } counter++; } if (edits.isEmpty()) { logblock.getServer().getScheduler().cancelTask(taskID); if (errorList.size() > 0) try { final File file = new File( "plugins/LogBlock/error/WorldEditor-" + new SimpleDateFormat("yy-MM-dd-HH-mm-ss").format(System.currentTimeMillis()) + ".log"); file.getParentFile().mkdirs(); final PrintWriter writer = new PrintWriter(file); for (final LookupCacheElement err : errorList) writer.println(err.getMessage()); writer.close(); } catch (final Exception ex) { } errors = errorList.toArray(new WorldEditorException[errorList.size()]); notify(); } }
@Override public void onEnable() { log = getLogger(); if (!getDataFolder().exists()) { getDataFolder().mkdirs(); } config = getConfig(); configFile = new File(getDataFolder(), "config.yml"); if (configFile.exists()) { loadSettings(); } else { saveSettings(); } if (saveCarpets) { loadCarpets(); } registerEvents(magicListener); registerCommands(); getWorldGuard(); getVault(); startStats(); log.info("is now enabled!"); }