Search in sources :

Example 1 with AsyncPurseUpdateEvent

use of com.nextplugins.economy.api.event.operations.AsyncPurseUpdateEvent in project NextEconomy by NextPlugins.

the class PurseAPI method updatePurse.

/**
 * Change purse value with messages and calling event (Better way)
 *
 * @param newValue to purse
 */
public void updatePurse(int newValue) {
    val lastNextUpdate = nextUpdate;
    val duration = PurseValue.get(PurseValue::nextUpdate);
    setNextUpdate(System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(duration));
    Bukkit.getScheduler().runTaskAsynchronously(NextEconomy.getInstance(), () -> {
        val asyncPurseUpdateEvent = new AsyncPurseUpdateEvent(newValue, purse, lastNextUpdate);
        PluginManager pluginManager = Bukkit.getPluginManager();
        pluginManager.callEvent(asyncPurseUpdateEvent);
    });
}
Also used : PluginManager(org.bukkit.plugin.PluginManager) AsyncPurseUpdateEvent(com.nextplugins.economy.api.event.operations.AsyncPurseUpdateEvent) PurseValue(com.nextplugins.economy.configuration.PurseValue)

Aggregations

AsyncPurseUpdateEvent (com.nextplugins.economy.api.event.operations.AsyncPurseUpdateEvent)1 PurseValue (com.nextplugins.economy.configuration.PurseValue)1 PluginManager (org.bukkit.plugin.PluginManager)1