1
0
Fork 0
mirror of https://github.com/xHyroM/lighteco.git synced 2024-11-23 07:21:04 +01:00

refactor: sonarqube

This commit is contained in:
Jozef Steinhübl 2023-08-29 09:13:25 +02:00
parent 0e3af38d55
commit c52e9da63d
30 changed files with 49 additions and 135 deletions

View file

@ -1,11 +0,0 @@
package dev.xhyrom.lighteco.api.event;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.function.Consumer;
public interface EventBus {
<T extends LightEcoEvent> @NonNull EventSubscription<T> subscribe(@NonNull Class<T> eventClass, @NonNull Consumer<? super T> subscriber);
<T extends LightEcoEvent> @NonNull EventSubscription<T> subscribe(Object plugin, @NonNull Class<T> eventClass, @NonNull Consumer<? super T> subscriber);
}

View file

@ -1,13 +0,0 @@
package dev.xhyrom.lighteco.api.event;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.function.Consumer;
public interface EventSubscription<T extends LightEcoEvent> extends AutoCloseable {
@NonNull Class<T> getEventClass();
boolean isActive();
@NonNull Consumer<? super T> getHandler();
}

View file

@ -1,10 +0,0 @@
package dev.xhyrom.lighteco.api.event;
import dev.xhyrom.lighteco.api.LightEco;
import org.checkerframework.checker.nullness.qual.NonNull;
public interface LightEcoEvent {
@NonNull LightEco getLightEco();
@NonNull Class<? extends LightEcoEvent> getEventClass();
}

View file

@ -1,11 +0,0 @@
package dev.xhyrom.lighteco.api.event.currency;
import dev.xhyrom.lighteco.api.event.LightEcoEvent;
import dev.xhyrom.lighteco.api.event.util.Position;
import dev.xhyrom.lighteco.api.model.currency.Currency;
import org.checkerframework.checker.nullness.qual.NonNull;
public interface CurrencyRegisterEvent extends LightEcoEvent {
@Position(0)
@NonNull Currency getCurrency();
}

View file

@ -1,21 +0,0 @@
package dev.xhyrom.lighteco.api.event.util;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Represents the position (index) of a parameter within an event.
* Used for information purposes only.
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.SOURCE)
public @interface Position {
/**
* Represents the position (index) of a parameter.
*
* @return the position (index)
*/
int value();
}

View file

@ -4,24 +4,24 @@ import dev.xhyrom.lighteco.api.model.user.User;
import java.math.BigDecimal;
public abstract class Currency {
public abstract String getIdentifier();
public interface Currency {
String getIdentifier();
/**
* Get the type of the currency, either {@link Type#LOCAL} or {@link Type#GLOBAL}
*
* @see Type
* @return The type of the currency
*/
public abstract Type getType();
Type getType();
public abstract boolean isPayable();
boolean isPayable();
/**
* Get the number of fractional digits this currency has
*
* @return The number of fractional digits
*/
public int fractionalDigits() {
default int fractionalDigits() {
return 0;
};
@ -30,7 +30,7 @@ public abstract class Currency {
*
* @return The users
*/
public abstract BigDecimal getDefaultBalance();
BigDecimal getDefaultBalance();
/**
* Calculate the tax for the given amount
@ -39,7 +39,7 @@ public abstract class Currency {
* @param amount The amount to calculate the tax for
* @return Amount that should be taxed
*/
public BigDecimal calculateTax(User user, BigDecimal amount) {
default BigDecimal calculateTax(User user, BigDecimal amount) {
return BigDecimal.ZERO;
};

View file

@ -2,6 +2,7 @@ import java.io.ByteArrayOutputStream
plugins {
id("java")
id("org.sonarqube") version "4.2.1.3168"
}
val majorVersion = 0

View file

@ -25,8 +25,8 @@ public class BukkitCommandSender extends AbstractCommandSender<CommandSender> {
@Override
public UUID getUniqueId() {
if (super.delegate instanceof Player) {
return ((Player) super.delegate).getUniqueId();
if (super.delegate instanceof Player player) {
return player.getUniqueId();
}
return null;

View file

@ -46,8 +46,12 @@ public class BalanceCommand implements Command {
this.manager.plugin.getUserManager().loadUser(target.getUniqueId())
.thenAcceptAsync(result -> {
String name = target.getName() != null ? target.getName() : args.getRaw("target");
result.setUsername(name);
String username = result.getUsername() == null ?
target.getName() != null
? target.getName()
: args.getRaw("target")
: result.getUsername();
result.setUsername(username);
this.manager.onBalance(sender, currency, result);
});

View file

@ -2,13 +2,12 @@ package dev.xhyrom.lighteco.bukkit.commands;
import dev.jorel.commandapi.CommandAPICommand;
import java.util.List;
public interface Command {
default CommandAPICommand build() {
return null;
};
}
default CommandAPICommand[] multipleBuild() {
return null;
};
return new CommandAPICommand[0];
}
}

View file

@ -44,12 +44,12 @@ public class PayCommand implements Command {
this.manager.plugin.getUserManager().loadUser(target.getUniqueId())
.thenAcceptAsync(result -> {
String name = result.getUsername() == null ?
String username = result.getUsername() == null ?
target.getName() != null
? target.getName()
: args.getRaw("target")
: result.getUsername();
result.setUsername(name);
result.setUsername(username);
this.manager.onPay(sender, currency, result, amount);
});

View file

@ -4,7 +4,7 @@ import dev.xhyrom.lighteco.api.model.currency.Currency;
import java.math.BigDecimal;
public class TestCurrency extends Currency {
public class TestCurrency implements Currency {
@Override
public String getIdentifier() {
return "test";

View file

@ -5,7 +5,7 @@ import dev.xhyrom.lighteco.api.model.user.User;
import java.math.BigDecimal;
public class TestCurrency2 extends Currency {
public class TestCurrency2 implements Currency {
@Override
public String getIdentifier() {
return "test2";

View file

@ -18,9 +18,7 @@ public class TestPlugin extends JavaPlugin {
getLogger().info("TestCurrency registered!");
currencyManager.getRegisteredCurrencies().forEach(currency -> {
getLogger().info("Currency: " + currency.getIdentifier() + " (" + currency.getType() + ", " + currency.fractionalDigits() + ", " + currency.isPayable() + ")");
});
currencyManager.getRegisteredCurrencies().forEach(currency -> getLogger().info("Currency: " + currency.getIdentifier() + " (" + currency.getType() + ", " + currency.fractionalDigits() + ", " + currency.isPayable() + ")"));
provider.getCommandManager().registerCurrencyCommand(currencyManager.getCurrency("test"));
provider.getCommandManager().registerCurrencyCommand(currencyManager.getCurrency("test2"));

View file

@ -23,7 +23,7 @@ public class ApiCurrencyManager extends ApiAbstractManager<dev.xhyrom.lighteco.c
public @NonNull Collection<Currency> getRegisteredCurrencies() {
return this.handler.values()
.stream().map(this::wrap)
.collect(Collectors.toList());
.toList();
}
@Override

View file

@ -21,7 +21,7 @@ public abstract class AbstractCommandManager implements CommandManager {
private final Map<String, CurrencyMessageConfig> config;
private final ArrayList<UUID> mustWait = new ArrayList<>();
public AbstractCommandManager(LightEcoPlugin plugin) {
protected AbstractCommandManager(LightEcoPlugin plugin) {
this.plugin = plugin;
this.config = this.plugin.getConfig().messages.currency;
}
@ -59,13 +59,13 @@ public abstract class AbstractCommandManager implements CommandManager {
}
private CurrencyMessageConfig getConfig(Currency currency) {
CurrencyMessageConfig config = this.config.get(currency.getIdentifier());
CurrencyMessageConfig currencyMessageConfig = this.config.get(currency.getIdentifier());
if (config == null) {
if (currencyMessageConfig == null) {
return this.config.get("default");
}
return config;
return currencyMessageConfig;
}
@Override

View file

@ -6,13 +6,9 @@ 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;
import static dev.xhyrom.lighteco.api.model.currency.Currency.Type;
public class StandardCurrencyManager extends AbstractManager<String, Currency> implements CurrencyManager {
private final LightEcoPlugin plugin;

View file

@ -3,7 +3,7 @@ package dev.xhyrom.lighteco.common.model.chat;
public abstract class AbstractCommandSender<T> implements CommandSender {
protected final T delegate;
public AbstractCommandSender(T delegate) {
protected AbstractCommandSender(T delegate) {
this.delegate = delegate;
}
}

View file

@ -12,10 +12,8 @@ import eu.okaeri.configs.ConfigManager;
import eu.okaeri.configs.yaml.snakeyaml.YamlSnakeYamlConfigurer;
import lombok.Getter;
import java.io.File;
@Getter
public abstract class AbstractLightEcoPlugin implements LightEcoPlugin {
@Getter
private DependencyManager dependencyManager;
@Getter
private Config config;
@ -27,7 +25,7 @@ public abstract class AbstractLightEcoPlugin implements LightEcoPlugin {
public final void load() {
this.dependencyManager = new DependencyManagerImpl(this);
this.config = ConfigManager.create(Config.class, (it) -> {
this.config = ConfigManager.create(Config.class, it -> {
it.withConfigurer(new YamlSnakeYamlConfigurer());
it.withBindFile(this.getBootstrap().getDataDirectory().resolve("config.yml"));
it.withRemoveOrphans(true);

View file

@ -24,8 +24,8 @@ public class Storage {
try {
return callable.call();
} catch (Exception e) {
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
if (e instanceof RuntimeException r) {
throw r;
}
throw new CompletionException(e);
@ -38,8 +38,8 @@ public class Storage {
try {
runnable.run();
} catch (Exception e) {
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
if (e instanceof RuntimeException r) {
throw r;
}
throw new CompletionException(e);

View file

@ -10,7 +10,7 @@ import java.util.HashMap;
import java.util.UUID;
public class MemoryStorageProvider implements StorageProvider {
private final HashMap<UUID, User> userDatabase = new HashMap<>();
private HashMap<UUID, User> userDatabase;
private final LightEcoPlugin plugin;
public MemoryStorageProvider(LightEcoPlugin plugin) {
@ -18,10 +18,14 @@ public class MemoryStorageProvider implements StorageProvider {
}
@Override
public void init() {}
public void init() {
userDatabase = new HashMap<>();
}
@Override
public void shutdown() {}
public void shutdown() {
userDatabase = null;
}
@Override
public @NonNull User loadUser(@NonNull UUID uniqueId, @Nullable String username) {

View file

@ -48,9 +48,8 @@ public enum SqlStatements {
case POSTGRESQL -> {
return this.postgresql;
}
default -> throw new IllegalArgumentException("Unknown implementation: " + implementationName);
}
throw new IllegalArgumentException("Unknown implementation: " + implementationName);
}
public static boolean mustDuplicateParameters(StorageType implementationName) {

View file

@ -14,7 +14,6 @@ import java.io.InputStream;
import java.math.BigDecimal;
import java.sql.*;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.function.Function;

View file

@ -2,7 +2,6 @@ package dev.xhyrom.lighteco.common.storage.provider.sql.connection.file;
import dev.xhyrom.lighteco.common.storage.provider.sql.connection.ConnectionFactory;
import java.io.File;
import java.nio.file.Path;
import java.sql.Connection;
import java.sql.SQLException;
@ -12,7 +11,7 @@ abstract class FileConnectionFactory implements ConnectionFactory {
private Connection connection;
private final Path file;
public FileConnectionFactory(Path file) {
protected FileConnectionFactory(Path file) {
this.file = file;
}

View file

@ -17,7 +17,7 @@ public abstract class HikariConnectionFactory implements ConnectionFactory {
private final StorageDataConfig configuration;
private HikariDataSource hikari;
public HikariConnectionFactory(StorageDataConfig configuration) {
protected HikariConnectionFactory(StorageDataConfig configuration) {
this.configuration = configuration;
}

View file

@ -3,8 +3,6 @@ package dev.xhyrom.lighteco.common.storage.provider.sql.connection.hikari;
import dev.xhyrom.lighteco.common.config.storage.StorageDataConfig;
import dev.xhyrom.lighteco.common.storage.StorageType;
import java.util.Map;
public class MariaDBConnectionFactory extends DriverBasedHikariConnectionFactory {
public MariaDBConnectionFactory(StorageDataConfig configuration) {
super(configuration);

View file

@ -227,7 +227,7 @@ public class Vault extends AbstractEconomy {
private double bigDecimalToDouble(final BigDecimal value) {
double amount = value.doubleValue();
if (new BigDecimal(amount).compareTo(value) > 0) {
if (BigDecimal.valueOf(amount).compareTo(value) > 0) {
amount = Math.nextAfter(amount, Double.NEGATIVE_INFINITY);
}

View file

@ -1,15 +0,0 @@
package dev.xhyrom.lighteco.currency.money.bukkit.listener;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.server.ServiceRegisterEvent;
public class BukkitServiceListener implements Listener {
@EventHandler
public void onServiceRegister(ServiceRegisterEvent event) {
if (!(event.getProvider().getProvider() instanceof Economy)) return;
}
}

View file

@ -4,7 +4,7 @@ import dev.xhyrom.lighteco.api.model.currency.Currency;
import java.math.BigDecimal;
public class MoneyCurrency extends Currency {
public class MoneyCurrency implements Currency {
@Override
public String getIdentifier() {
return "money";

0
gradlew vendored Normal file → Executable file
View file