public NamedLocation create(String id, Location loc, Player player) { id = id.trim(); NamedLocation warp = new NamedLocation(id, loc); locs.put(id.toLowerCase(), warp); if (player != null) { warp.setCreatorName(player.getName()); } else { warp.setCreatorName(""); } return warp; }
public void load() throws IOException { FileInputStream input = null; Map<String, NamedLocation> locs = new HashMap<String, NamedLocation>(); file.getParentFile().mkdirs(); if (!file.exists()) { file.createNewFile(); } try { input = new FileInputStream(file); InputStreamReader streamReader = new InputStreamReader(input, "utf-8"); BufferedReader reader = new BufferedReader(streamReader); CSVReader csv = new CSVReader(reader); String[] line; while ((line = csv.readNext()) != null) { if (line.length < 7) { logger.warning("CommandBook: " + type + " data file has an invalid line with < 7 fields"); } else { try { String name = line[0].trim().replace(" ", ""); String worldName = line[1]; // Set to null if the world exists String creator = line[2]; double x = Double.parseDouble(line[3]); double y = Double.parseDouble(line[4]); double z = Double.parseDouble(line[5]); float pitch = Float.parseFloat(line[6]); float yaw = Float.parseFloat(line[7]); World world = CommandBook.server().getWorld(worldName); if (world != null) { // We shouldn't have this warp if (castWorld != null && !castWorld.equals(world)) { continue; } } Location loc = new Location(world, x, y, z, yaw, pitch); NamedLocation warp = new NamedLocation(name, loc); warp.setWorldName(worldName); warp.setCreatorName(creator); if (world == null) { getNestedList(unloadedLocs, worldName).add(warp); } else { locs.put(name.toLowerCase(), warp); } } catch (NumberFormatException e) { logger.warning( "CommandBook: " + type + " data file has an invalid line with non-numeric numeric fields"); } } } this.locs = locs; if (castWorld != null) { logger.info( "CommandBook: " + locs.size() + " " + type + "(s) loaded for " + castWorld.getName()); } else { logger.info("CommandBook: " + locs.size() + " " + type + "(s) loaded"); } } finally { if (input != null) { try { input.close(); } catch (IOException e) { } } } }