gt: 		if (useCost < 0) return iConomyHandler.useCost;
context: package net.TheDgtl.Stargate;
  
  import java.io.BufferedWriter;
  import java.io.File;
  import java.io.FileWriter;
  import java.io.FilenameFilter;
  import java.io.IOException;
  import java.util.ArrayList;
  import java.util.HashMap;
  import java.util.HashSet;
  import java.util.Scanner;
  import java.util.logging.Level;
  
  import org.bukkit.Material;
  import org.bukkit.block.Block;
  
  /**
   * Stargate - A portal plugin for Bukkit
   * Copyright (C) 2011 Shaun (sturmeh)
   * Copyright (C) 2011 Dinnerbone
   * Copyright (C) 2011, 2012 Steven "Drakia" Scott <Contact@TheDgtl.net>
   * 
   * This program is free software: you can redistribute it and/or modify
   * it under the terms of the GNU Lesser General Public License as published by
   * the Free Software Foundation, either version 3 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 Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public License
   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
   */
   
  public class Gate {
  	public static final int ANYTHING = -1;
  	public static final int ENTRANCE = -2;
  	public static final int CONTROL = -3;
  	public static final int EXIT = -4;
  	private static HashMap<String, Gate> gates = new HashMap<String, Gate>();
  	private static HashMap<Integer, ArrayList<Gate>> controlBlocks = new HashMap<Integer, ArrayList<Gate>>();
  	private static HashSet<Integer> frameBlocks = new HashSet<Integer>();
  
  	private String filename;
  	private Character[][] layout;
  	private HashMap<Character, Integer> types;
  	private HashMap<Character, Integer> metadata;
  	private RelativeBlockVector[] entrances = new RelativeBlockVector[0];
  	private RelativeBlockVector[] border = new RelativeBlockVector[0];
  	private RelativeBlockVector[] controls = new RelativeBlockVector[0];
  	private RelativeBlockVector exitBlock = null;
  	private HashMap<RelativeBlockVector, Integer> exits = new HashMap<RelativeBlockVector, Integer>();
  	private int portalBlockOpen = Material.PORTAL.getId();
  	private int portalBlockClosed = Material.AIR.getId();
  	
  	// iConomy information
  	private int useCost = -1;
  	private int createCost = -1;
  	private int destroyCost = -1;
  	private boolean toOwner = false;
  
  	public Gate(String filename, Character[][] layout, HashMap<Character, Integer> types, HashMap<Character, Integer> metadata) {
  		this.filename = filename;
  		this.layout = layout;
  		this.metadata = metadata;
  		this.types = types;
  
  		populateCoordinates();
  	}
  
  	private void populateCoordinates() {
  		ArrayList<RelativeBlockVector> entranceList = new ArrayList<RelativeBlockVector>();
  		ArrayList<RelativeBlockVector> borderList = new ArrayList<RelativeBlockVector>();
  		ArrayList<RelativeBlockVector> controlList = new ArrayList<RelativeBlockVector>();
  		RelativeBlockVector[] relativeExits = new RelativeBlockVector[layout[0].length];
  		int[] exitDepths = new int[layout[0].length];
  		RelativeBlockVector lastExit = null;
  
  		for (int y = 0; y < layout.length; y++) {
  			for (int x = 0; x < layout[y].length; x++) {
  				Integer id = types.get(layout[y][x]);
  				if (layout[y][x] == '-') {
  					controlList.add(new RelativeBlockVector(x, y, 0));
  				}
  
  				if (id == ENTRANCE || id == EXIT) {
  					entranceList.add(new RelativeBlockVector(x, y, 0));
  					exitDepths[x] = y;
  					if (id == EXIT)
  						this.exitBlock = new RelativeBlockVector(x, y, 0);
  				} else if (id != ANYTHING) {
  					borderList.add(new RelativeBlockVector(x, y, 0));
  				}
  			}
  		}
  
  		for (int x = 0; x < exitDepths.length; x++) {
  			relativeExits[x] = new RelativeBlockVector(x, exitDepths[x], 0);
  		}
  
  		for (int x = relativeExits.length - 1; x >= 0; x--) {
  			if (relativeExits[x] != null) {
  				lastExit = relativeExits[x];
  			} else {
  				relativeExits[x] = lastExit;
  			}
  
  			if (exitDepths[x] > 0) this.exits.put(relativeExits[x], x);
  		}
  
  		this.entrances = entranceList.toArray(this.entrances);
  		this.border = borderList.toArray(this.border);
  		this.controls = controlList.toArray(this.controls);
  	}
  	
  	public void save(String gateFolder) {
  		try {
  			BufferedWriter bw = new BufferedWriter(new FileWriter(gateFolder + filename));
  			
  			writeConfig(bw, "portal-open", portalBlockOpen);
  			writeConfig(bw, "portal-closed", portalBlockClosed);
  			if (useCost != -1)
  				writeConfig(bw, "usecost", useCost);
  			if (createCost != -1)
  				writeConfig(bw, "createcost", createCost);
  			if (destroyCost != -1)
  				writeConfig(bw, "destroycost", destroyCost);
  			writeConfig(bw, "toowner", toOwner);
  
  			for (Character type : types.keySet()) {
  				Integer value = types.get(type);
  				// Skip control values
  				if (value < 0) continue;
  
  				bw.append(type);
  				bw.append('=');
  				bw.append(value.toString());
  				Integer mData = metadata.get(type);
  				// Append metadata
  				if (mData != null) {
  					bw.append(':');
  					bw.append(mData.toString());
  				}
  				bw.newLine();
  			}
  
  			bw.newLine();
  
  			for (int y = 0; y < layout.length; y++) {
  				for (int x = 0; x < layout[y].length; x++) {
  					Character symbol = layout[y][x];
  					bw.append(symbol);
  				}
  				bw.newLine();
  			}
  
  			bw.close();
  		} catch (IOException ex) {
  			Stargate.log.log(Level.SEVERE, "Could not save Gate " + filename + " - " + ex.getMessage());
  		}
  	}
  
  	private void writeConfig(BufferedWriter bw, String key, int value) throws IOException {
  		bw.append(String.format("%s=%d", key, value));
  		bw.newLine();
  	}
  	
  	private void writeConfig(BufferedWriter bw, String key, boolean value) throws IOException {
  		bw.append(String.format("%s=%b", key, value));
  		bw.newLine();
  	}
  
  	public Character[][] getLayout() {
  		return layout;
  	}
  	
  	public HashMap<Character, Integer> getTypes() {
  		return types;
  	}
  	
  	public HashMap<Character, Integer> getMetaData() {
  		return metadata;
  	}
  
  	public RelativeBlockVector[] getEntrances() {
  		return entrances;
  	}
  
  	public RelativeBlockVector[] getBorder() {
  		return border;
  	}
  
  	public RelativeBlockVector[] getControls() {
  		return controls;
  	}
  
  	public HashMap<RelativeBlockVector, Integer> getExits() {
  		return exits;
  	}
  	public RelativeBlockVector getExit() {
  		return exitBlock;
  	}
  
  	public int getControlBlock() {
  		return types.get('-');
  	}
  
  	public String getFilename() {
  		return filename;
  	}
  
  	public int getPortalBlockOpen() {
  		return portalBlockOpen;
  	}
  	
  	public void setPortalBlockOpen(int type) {
  		portalBlockOpen = type;
  	}
  
  	public int getPortalBlockClosed() {
  		return portalBlockClosed;
  	}
  	
  	public void setPortalBlockClosed(int type) {
  		portalBlockClosed = type;
  	}
  	
  	public int getUseCost() {
  