mirror of
https://github.com/EpicEricEE/ShopChest.git
synced 2024-11-08 11:50:14 +01:00
Use consumers as callback functions
This commit is contained in:
parent
70f9ff3914
commit
5c2f3022b5
@ -2,14 +2,13 @@ package de.epiceric.shopchest.api;
|
|||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
|
||||||
import de.epiceric.shopchest.api.event.ShopReloadEvent;
|
import de.epiceric.shopchest.api.event.ShopReloadEvent;
|
||||||
import de.epiceric.shopchest.api.exceptions.ChestNotFoundException;
|
|
||||||
import de.epiceric.shopchest.api.exceptions.NoSpaceAboveChestException;
|
|
||||||
import de.epiceric.shopchest.api.shop.Shop;
|
import de.epiceric.shopchest.api.shop.Shop;
|
||||||
import de.epiceric.shopchest.api.shop.ShopProduct;
|
import de.epiceric.shopchest.api.shop.ShopProduct;
|
||||||
|
|
||||||
@ -76,14 +75,12 @@ public interface ShopManager {
|
|||||||
* Can be either chest if it's on a double chest
|
* Can be either chest if it's on a double chest
|
||||||
* @param buyPrice the price a player can buy the product for.
|
* @param buyPrice the price a player can buy the product for.
|
||||||
* @param sellPrice the price a player can sell the product for.
|
* @param sellPrice the price a player can sell the product for.
|
||||||
* @throws ChestNotFoundException when there is no chest at the given location
|
* @param callback the callback returning the created shop on success
|
||||||
* @throws NoSpaceAboveChestException when there is no empty space above the chest
|
* @param errorCallback the callback returning the error if one occurred
|
||||||
* @return the shop if created successfully or an empty optional if not
|
|
||||||
* @since 1.13
|
* @since 1.13
|
||||||
* @see ShopManager#addAdminShop(ShopProduct, Location, double, double)
|
* @see ShopManager#addAdminShop(ShopProduct, Location, double, double, Consumer, Consumer)
|
||||||
*/
|
*/
|
||||||
Shop addShop(OfflinePlayer vendor, ShopProduct product, Location location, double buyPrice, double sellPrice)
|
void addShop(OfflinePlayer vendor, ShopProduct product, Location location, double buyPrice, double sellPrice, Consumer<Shop> callback, Consumer<Throwable> errorCallback);
|
||||||
throws ChestNotFoundException, NoSpaceAboveChestException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an admin shop and adds it to the database
|
* Creates an admin shop and adds it to the database
|
||||||
@ -97,38 +94,42 @@ public interface ShopManager {
|
|||||||
* Can be either chest if it's on a double chest
|
* Can be either chest if it's on a double chest
|
||||||
* @param buyPrice the price a player can buy the product for.
|
* @param buyPrice the price a player can buy the product for.
|
||||||
* @param sellPrice the price a player can sell the product for.
|
* @param sellPrice the price a player can sell the product for.
|
||||||
* @throws ChestNotFoundException when there is no chest at the given location
|
* @param callback the callback returning the created shop on success
|
||||||
* @throws NoSpaceAboveChestException when there is no empty space above the chest
|
* @param errorCallback the callback returning the error if one occurred
|
||||||
* @return the created admin shop
|
|
||||||
* @since 1.13
|
* @since 1.13
|
||||||
* @see ShopManager#addShop(OfflinePlayer, ShopProduct, Location, double, double)
|
* @see ShopManager#addShop(OfflinePlayer, ShopProduct, Location, double, double, Consumer, Consumer)
|
||||||
*/
|
*/
|
||||||
Shop addAdminShop(ShopProduct product, Location location, double buyPrice, double sellPrice)
|
void addAdminShop(ShopProduct product, Location location, double buyPrice, double sellPrice, Consumer<Shop> callback, Consumer<Throwable> errorCallback);
|
||||||
throws ChestNotFoundException, NoSpaceAboveChestException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes a shop from the database
|
* Removes a shop from the database
|
||||||
*
|
*
|
||||||
* @param shop the shop to remove
|
* @param shop the shop to remove
|
||||||
|
* @param callback the callback returning nothing on success
|
||||||
|
* @param errorCallback the callback returning the error if one occurred
|
||||||
* @since 1.13
|
* @since 1.13
|
||||||
*/
|
*/
|
||||||
void removeShop(Shop shop);
|
void removeShop(Shop shop, Consumer<Void> callback, Consumer<Throwable> errorCallback);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes a shop from the database by its ID
|
* Removes a shop from the database by its ID
|
||||||
*
|
*
|
||||||
* @param shopId the id of the shop to remove
|
* @param shopId the id of the shop to remove
|
||||||
|
* @param callback the callback returning nothing on success
|
||||||
|
* @param errorCallback the callback returning the error if one occurred
|
||||||
* @since 1.13
|
* @since 1.13
|
||||||
*/
|
*/
|
||||||
void removeShop(int shopId);
|
void removeShop(int shopId, Consumer<Void> callback, Consumer<Throwable> errorCallback);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asynchronously reloads all shops from the database
|
* Asynchronously reloads all shops from the database
|
||||||
* <p>
|
* <p>
|
||||||
* This does not trigger the {@link ShopReloadEvent}.
|
* This does not trigger the {@link ShopReloadEvent}.
|
||||||
*
|
*
|
||||||
|
* @param callback the callback returning the amount of shops on success
|
||||||
|
* @param errorCallback the callback returning the error if one occurred
|
||||||
* @since 1.13
|
* @since 1.13
|
||||||
*/
|
*/
|
||||||
void reloadShops();
|
void reloadShops(Consumer<Integer> callback, Consumer<Throwable> errorCallback);
|
||||||
|
|
||||||
}
|
}
|
@ -1,5 +1,7 @@
|
|||||||
package de.epiceric.shopchest.api.shop;
|
package de.epiceric.shopchest.api.shop;
|
||||||
|
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
@ -12,8 +14,8 @@ import de.epiceric.shopchest.api.exceptions.ChestNotFoundException;
|
|||||||
* Represents a shop
|
* Represents a shop
|
||||||
*
|
*
|
||||||
* @since 1.13
|
* @since 1.13
|
||||||
* @see ShopManager#addShop(OfflinePlayer, ShopProduct, Location, double, double)
|
* @see ShopManager#addShop(OfflinePlayer, ShopProduct, Location, double, double, Consumer, Consumer)
|
||||||
* @see ShopManager#addAdminShop(ShopProduct, Location, double, double)
|
* @see ShopManager#addAdminShop(ShopProduct, Location, double, double, Consumer, Consumer)
|
||||||
*/
|
*/
|
||||||
public interface Shop {
|
public interface Shop {
|
||||||
|
|
||||||
@ -21,6 +23,7 @@ public interface Shop {
|
|||||||
* Gets this shop's ID
|
* Gets this shop's ID
|
||||||
*
|
*
|
||||||
* @return the ID
|
* @return the ID
|
||||||
|
* @throws IllegalStateException if the shop has not been added to the database yet
|
||||||
* @since 1.13
|
* @since 1.13
|
||||||
*/
|
*/
|
||||||
int getId();
|
int getId();
|
||||||
|
Loading…
Reference in New Issue
Block a user