mirror of
https://github.com/xHyroM/lighteco.git
synced 2024-11-21 22:41:06 +01:00
fix(common): check if currency's value type is allowed
This commit is contained in:
parent
aa2a48e462
commit
2b274497a7
1 changed files with 12 additions and 0 deletions
|
@ -6,6 +6,8 @@ import dev.xhyrom.lighteco.common.model.user.User;
|
|||
import dev.xhyrom.lighteco.common.plugin.LightEcoPlugin;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -41,12 +43,22 @@ public class StandardCurrencyManager extends AbstractManager<String, Currency<?>
|
|||
if (currency.getType() == Type.LOCAL && this.plugin.getPlatformType().isProxy())
|
||||
throw new IllegalArgumentException("Cannot register local currency on proxy platform");
|
||||
|
||||
if (!isValidValueType(currency.getValueType()))
|
||||
throw new IllegalArgumentException("Invalid value type " + currency.getValueType().getName() + " for currency " + currency.getIdentifier());
|
||||
|
||||
if (this.isLoaded(currency.getIdentifier()))
|
||||
throw new IllegalArgumentException("Currency with identifier " + currency.getIdentifier() + " already registered");
|
||||
|
||||
this.map.put(currency.getIdentifier(), currency);
|
||||
}
|
||||
|
||||
private boolean isValidValueType(Class<?> clazz) {
|
||||
return clazz == Integer.class || clazz == Long.class ||
|
||||
clazz == Double.class || clazz == Float.class ||
|
||||
clazz == Short.class || clazz == BigInteger.class ||
|
||||
clazz == BigDecimal.class;
|
||||
}
|
||||
|
||||
// TODO: finish
|
||||
@Override
|
||||
public List<User> getTopUsers(@NonNull Currency<?> currency, int length) {
|
||||
|
|
Loading…
Reference in a new issue