Java tutorial
/* MapMarkers Minecraft Bukkit plugin for showing Essentials warps and warp events on maps generated by Minecraft Overviewer. Copyright (C) 2011 Brendan Johan Lee Email: brendan (at) vanntett.net This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ package is.brendan.WarpMarkers; import java.io.*; import java.util.TimerTask; import java.util.logging.*; import org.json.simple.JSONArray; /** * Periodic timer that outputs stuff to JSON. * @author Brendan Johan Lee - deadcyclo@vanntett.net */ public class WarpMarkersTimerTask extends TimerTask { private final WarpMarkers plugin; private String outputFile; private String updateFile; public WarpMarkersTimerTask(WarpMarkers instance, String file, String updateFile) { plugin = instance; outputFile = file; this.updateFile = updateFile; } public void run() { JSONArray jsonList = plugin.getJSON(); JSONArray jsonListUpdates = plugin.getUpdatesJSON(); if (jsonList != null) { try { PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(outputFile))); writer.print(jsonList); writer.close(); } catch (java.io.IOException e) { plugin.log(Level.SEVERE, "Unable to write to " + outputFile + ": " + e.getMessage(), e); e.printStackTrace(); } } if (jsonListUpdates != null) { try { PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(updateFile))); writer.print(jsonListUpdates); writer.close(); } catch (java.io.IOException e) { plugin.log(Level.SEVERE, "Unable to write to " + updateFile + ": " + e.getMessage(), e); e.printStackTrace(); } } } }