private void refreshActiveTradeStations(World world) { activeTradeStations = new LinkedHashMap<>(); File worldSave = world.getSaveHandler().getMapFileFromName("dummy"); File file = worldSave.getParentFile(); if (!file.exists() || !file.isDirectory()) { return; } String[] list = file.list(); if (list == null) { return; } for (String str : list) { if (!str.startsWith(TradeStation.SAVE_NAME)) { continue; } if (!str.endsWith(".dat")) { continue; } MailAddress address = new MailAddress(str.replace(TradeStation.SAVE_NAME, "").replace(".dat", "")); ITradeStation trade = PostManager.postRegistry.getTradeStation(world, address); if (trade == null) { continue; } registerTradeStation(trade); } }
@Override public void deleteTradeStation(World world, IMailAddress address) { TradeStation trade = getTradeStation(world, address); if (trade == null) { return; } // Need to be marked as invalid since WorldSavedData seems to do some caching of its own. trade.invalidate(); cachedTradeStations.remove(address); getPostOffice(world).deregisterTradeStation(trade); File file = world.getSaveHandler().getMapFileFromName(trade.mapName); boolean delete = file.delete(); if (!delete) { Log.error("Failed to delete trade station file. {}", file); } }
public static void addWorldNames(World world) { final ISaveHandler saveHandler = world.getSaveHandler(); final File worldDirectory = saveHandler.getWorldDirectory(); if (worldDirectory != null) { final String worldDir = worldDirectory.getName(); mainSanitizer.addPre(PRIORITY_SAVE_DIR_NAME, replaceNoDuplicates(worldDir, "[save dir]")); } try { File dummy = saveHandler.getMapFileFromName("dummy"); if (dummy != null) { String parent = dummy.getParentFile().getParent(); if (parent != null) mainSanitizer.addPre(PRIORITY_SAVE_DIR, pathNoDuplicate(parent, "[save dir]")); } } catch (Throwable t) { Log.warn(t, "Failed to get sanitizer name for world"); } String worldName = world.getWorldInfo().getWorldName(); mainSanitizer.addPre(PRIORITY_WORLD_NAME, replaceNoDuplicates(worldName, "[world name]")); }