mirror of
https://github.com/xHyroM/lighteco.git
synced 2024-12-25 21:51:07 +01:00
feat: add currency interface
This commit is contained in:
parent
cefa84404b
commit
7757558442
5 changed files with 60 additions and 6 deletions
|
@ -0,0 +1,40 @@
|
|||
package dev.xhyrom.lighteco.api.model.currency;
|
||||
|
||||
public interface Currency<T> {
|
||||
String getIdentifier();
|
||||
|
||||
/**
|
||||
* Get the type of the currency, either {@link Type#EXCLUSIVE} or {@link Type#GLOBAL}
|
||||
*
|
||||
* @see Type
|
||||
* @return The type of the currency
|
||||
*/
|
||||
Type getType();
|
||||
|
||||
boolean isPayable();
|
||||
|
||||
/**
|
||||
* Calculate the tax for the given amount
|
||||
* Used for payables
|
||||
*
|
||||
* @param amount The amount to calculate the tax for
|
||||
* @return The tax
|
||||
*/
|
||||
default double calculateTax(T amount) {
|
||||
return 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* Represents the type of currency
|
||||
*/
|
||||
enum Type {
|
||||
/**
|
||||
* A currency that is only available on a single server
|
||||
*/
|
||||
EXCLUSIVE,
|
||||
/**
|
||||
* A currency that is available on all servers (proxy)
|
||||
*/
|
||||
GLOBAL;
|
||||
}
|
||||
}
|
|
@ -6,5 +6,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
|||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public interface PlayerAdapter<T> {
|
||||
@NonNull CompletableFuture<User> getUser(@NonNull T player);
|
||||
@NonNull User getUser(@NonNull T player);
|
||||
|
||||
@NonNull CompletableFuture<User> loadUser(@NonNull T player);
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import java.util.UUID;
|
|||
public interface StorageProvider {
|
||||
@NonNull String[] getIdentifiers();
|
||||
|
||||
@NonNull User loadUser(@NonNull UUID uniqueId) throws Exception;
|
||||
@NonNull User loadUser(@NonNull UUID uniqueId);
|
||||
// todo: look at this
|
||||
void saveUser(@NonNull User user) /*throws Exception;*/;
|
||||
void saveUser(@NonNull User user);
|
||||
}
|
||||
|
|
|
@ -19,7 +19,19 @@ public class ApiPlayerAdapter<T> implements PlayerAdapter<T> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public @NonNull CompletableFuture<User> getUser(@NonNull T player) {
|
||||
public @NonNull User getUser(@NonNull T player) {
|
||||
UUID uniqueId = contextManager.getPlayerUniqueId(player);
|
||||
User user = userManager.getUser(uniqueId);
|
||||
|
||||
if (user == null) {
|
||||
throw new IllegalStateException("User is not loaded");
|
||||
}
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull CompletableFuture<User> loadUser(@NonNull T player) {
|
||||
UUID uniqueId = contextManager.getPlayerUniqueId(player);
|
||||
boolean loaded = userManager.isLoaded(uniqueId);
|
||||
|
||||
|
|
|
@ -16,12 +16,12 @@ public class MemoryStorageProvider implements StorageProvider {
|
|||
}
|
||||
|
||||
@Override
|
||||
public @NonNull User loadUser(@NonNull UUID uniqueId) throws Exception {
|
||||
public @NonNull User loadUser(@NonNull UUID uniqueId) {
|
||||
return users.get(uniqueId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveUser(@NonNull User user) throws Exception {
|
||||
public void saveUser(@NonNull User user) {
|
||||
users.put(user.getUniqueId(), user);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue