1
0
Fork 0
mirror of https://github.com/xHyroM/lighteco.git synced 2024-11-24 15:51:06 +01:00

feat: add currency interface

This commit is contained in:
xHyroM 2023-07-31 21:48:45 +02:00
parent cefa84404b
commit 7757558442
No known key found for this signature in database
GPG key ID: BE0423F386C436AA
5 changed files with 60 additions and 6 deletions

View file

@ -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;
}
}

View file

@ -6,5 +6,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
public interface PlayerAdapter<T> { public interface PlayerAdapter<T> {
@NonNull CompletableFuture<User> getUser(@NonNull T player); @NonNull User getUser(@NonNull T player);
@NonNull CompletableFuture<User> loadUser(@NonNull T player);
} }

View file

@ -8,7 +8,7 @@ import java.util.UUID;
public interface StorageProvider { public interface StorageProvider {
@NonNull String[] getIdentifiers(); @NonNull String[] getIdentifiers();
@NonNull User loadUser(@NonNull UUID uniqueId) throws Exception; @NonNull User loadUser(@NonNull UUID uniqueId);
// todo: look at this // todo: look at this
void saveUser(@NonNull User user) /*throws Exception;*/; void saveUser(@NonNull User user);
} }

View file

@ -19,7 +19,19 @@ public class ApiPlayerAdapter<T> implements PlayerAdapter<T> {
} }
@Override @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); UUID uniqueId = contextManager.getPlayerUniqueId(player);
boolean loaded = userManager.isLoaded(uniqueId); boolean loaded = userManager.isLoaded(uniqueId);

View file

@ -16,12 +16,12 @@ public class MemoryStorageProvider implements StorageProvider {
} }
@Override @Override
public @NonNull User loadUser(@NonNull UUID uniqueId) throws Exception { public @NonNull User loadUser(@NonNull UUID uniqueId) {
return users.get(uniqueId); return users.get(uniqueId);
} }
@Override @Override
public void saveUser(@NonNull User user) throws Exception { public void saveUser(@NonNull User user) {
users.put(user.getUniqueId(), user); users.put(user.getUniqueId(), user);
} }
} }