Search in sources :

Example 1 with MarketServiceImpl

use of com.skelril.skree.service.internal.market.MarketServiceImpl in project Skree by Skelril.

the class MarketSystem method init.

@NModuleTrigger(trigger = "SERVER_STARTED")
public void init() {
    service = new MarketServiceImpl();
    loadState();
    // Register the service
    Sponge.getServiceManager().setProvider(SkreePlugin.inst(), MarketService.class, service);
    Sponge.getCommandManager().register(SkreePlugin.inst(), MarketCommand.aquireSpec(), "market", "mk");
    // Calculate delay
    long elapsedTime = System.currentTimeMillis() - state.getLastUpdate();
    long elapsedSeconds = elapsedTime / TimeUnit.SECONDS.toMillis(1);
    long waitDuration = WAIT_UNIT.toSeconds(WAIT_TIME);
    long remainingTime = Math.max(0, waitDuration - elapsedSeconds);
    // Schedule an update task for every two hours
    Task.builder().execute(() -> {
        service.updatePrices();
        state.setLastUpdate(System.currentTimeMillis());
        dumpState();
        MessageChannel.TO_ALL.send(Text.of(TextColors.GOLD, "The market has been updated"));
        GameChatterPlugin.inst().sendSystemMessage("The market has been updated");
    }).interval(WAIT_TIME, WAIT_UNIT).delay(remainingTime, TimeUnit.SECONDS).async().submit(SkreePlugin.inst());
}
Also used : MarketServiceImpl(com.skelril.skree.service.internal.market.MarketServiceImpl) NModuleTrigger(com.skelril.nitro.module.NModuleTrigger)

Aggregations

NModuleTrigger (com.skelril.nitro.module.NModuleTrigger)1 MarketServiceImpl (com.skelril.skree.service.internal.market.MarketServiceImpl)1