Search in sources :

Example 1 with ITradeStation

use of forestry.api.mail.ITradeStation in project ForestryMC by ForestryMC.

the class ContainerCatalogue method rebuildStationsList.

private void rebuildStationsList() {
    stations.clear();
    IPostOffice postOffice = PostManager.postRegistry.getPostOffice(player.world);
    Map<IMailAddress, ITradeStation> tradeStations = postOffice.getActiveTradeStations(player.world);
    for (ITradeStation station : tradeStations.values()) {
        ITradeStationInfo info = station.getTradeInfo();
        // Filter out any trade stations which do not actually offer anything.
        if (FILTERS.get(currentFilter).contains(info.getState())) {
            stations.add(station);
        }
    }
    stationIndex = 0;
    updateTradeInfo();
}
Also used : ITradeStation(forestry.api.mail.ITradeStation) IMailAddress(forestry.api.mail.IMailAddress) IPostOffice(forestry.api.mail.IPostOffice) ITradeStationInfo(forestry.api.mail.ITradeStationInfo)

Example 2 with ITradeStation

use of forestry.api.mail.ITradeStation in project ForestryMC by ForestryMC.

the class PostOffice method refreshActiveTradeStations.

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);
    }
}
Also used : ITradeStation(forestry.api.mail.ITradeStation) IMailAddress(forestry.api.mail.IMailAddress) File(java.io.File)

Example 3 with ITradeStation

use of forestry.api.mail.ITradeStation in project ForestryMC by ForestryMC.

the class ContainerCatalogue method updateTradeInfo.

/* Managing Trade info */
private void updateTradeInfo() {
    // Updating is done by the server.
    if (player.world.isRemote) {
        return;
    }
    if (!stations.isEmpty()) {
        ITradeStation station = stations.get(stationIndex);
        setTradeInfo(station.getTradeInfo());
    } else {
        setTradeInfo(null);
    }
    needsSync = true;
}
Also used : ITradeStation(forestry.api.mail.ITradeStation)

Example 4 with ITradeStation

use of forestry.api.mail.ITradeStation in project ForestryMC by ForestryMC.

the class ContainerLetter method updateTradeInfo.

/* Managing Trade info */
private void updateTradeInfo(World world, @Nullable IMailAddress address) {
    // Updating is done by the server.
    if (world.isRemote) {
        return;
    }
    if (address == null) {
        setTradeInfo(null);
        return;
    }
    ITradeStation station = PostManager.postRegistry.getTradeStation(world, address);
    if (station == null) {
        setTradeInfo(null);
        return;
    }
    setTradeInfo(station.getTradeInfo());
}
Also used : ITradeStation(forestry.api.mail.ITradeStation)

Aggregations

ITradeStation (forestry.api.mail.ITradeStation)4 IMailAddress (forestry.api.mail.IMailAddress)2 IPostOffice (forestry.api.mail.IPostOffice)1 ITradeStationInfo (forestry.api.mail.ITradeStationInfo)1 File (java.io.File)1