Skip to content

Commit

Permalink
Optimize imports
Browse files Browse the repository at this point in the history
  • Loading branch information
ChromMob committed Feb 7, 2023
1 parent bf75141 commit 4e8e755
Show file tree
Hide file tree
Showing 30 changed files with 288 additions and 270 deletions.
4 changes: 2 additions & 2 deletions .deepsource.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ version = 1
[[analyzers]]
name = "java"

[analyzers.meta]
runtime_version = "8"
[analyzers.meta]
runtime_version = "8"
302 changes: 151 additions & 151 deletions LICENSE.md

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions src/main/java/me/chrommob/minestore/common/MineStoreCommon.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import co.aikar.commands.CommandManager;
import me.chrommob.minestore.common.authHolder.AuthHolder;
import me.chrommob.minestore.common.command.AuthCommand;
import me.chrommob.minestore.common.command.types.AbstractUser;
import me.chrommob.minestore.common.command.ReloadCommand;
import me.chrommob.minestore.common.command.types.AbstractUser;
import me.chrommob.minestore.common.commandGetters.WebListener;
import me.chrommob.minestore.common.commandHolder.CommandDumper;
import me.chrommob.minestore.common.commandHolder.CommandStorage;
Expand All @@ -18,46 +18,50 @@

public class MineStoreCommon {
private static MineStoreCommon instance;
private ConfigReader configReader;
private File configFile;
private CommandExecuterCommon commandExecuterCommon;
private LoggerCommon logger;
private PlayerJoinListener playerJoinListener;
private CommandManager commandManager;
private UserGetter userGetter;
private CommandGetter commandGetter;
private CommandStorage commandStorage;
private CommandDumper commandDumper;
private AuthHolder authHolder;

public MineStoreCommon() {
instance = this;
}

private ConfigReader configReader;
private File configFile;
public static MineStoreCommon getInstance() {
return instance;
}

public void setConfigLocation(File configFile) {
this.configFile = configFile;
}

private CommandExecuterCommon commandExecuterCommon;
public void registerCommandExecuter(CommandExecuterCommon commandExecuter) {
this.commandExecuterCommon = commandExecuter;
}

private LoggerCommon logger;
public void registerLogger(LoggerCommon logger) {
this.logger = logger;
}

private PlayerJoinListener playerJoinListener;
public void registerPlayerJoinListener(PlayerJoinListener playerJoinListener) {
this.playerJoinListener = playerJoinListener;
}

private CommandManager commandManager;
public void registerCommandManager(CommandManager commandManager) {
this.commandManager = commandManager;
}

private UserGetter userGetter;
public void registerUserGetter(UserGetter userGetter) {
this.userGetter = userGetter;
}

private CommandGetter commandGetter;
private CommandStorage commandStorage;
private CommandDumper commandDumper;
private AuthHolder authHolder;
public void init() {
configReader = new ConfigReader(configFile);
commandDumper = new CommandDumper();
Expand Down Expand Up @@ -127,10 +131,6 @@ private boolean verify() {
return true;
}

public static MineStoreCommon getInstance() {
return instance;
}

public ConfigReader configReader() {
return configReader;
}
Expand Down Expand Up @@ -167,7 +167,7 @@ public void debug(Exception e) {
if (e.getStackTrace() != null) {
debug(Arrays.toString(e.getStackTrace()));
}
if (e.getCause() != null){
if (e.getCause() != null) {
debug(e.getCause().toString());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,6 @@ public class AuthHolder {
private Map<String, AuthUser> authUsers = new ConcurrentHashMap<>();
private Map<String, ParsedResponse> toPost = new ConcurrentHashMap<>();
private String url;

public AuthHolder(MineStoreCommon plugin) {
authTimeout = (int) plugin.configReader().get(ConfigKey.AUTH_TIMEOUT);
new Thread(removeAndPost).start();
String storeUrl = (String) MineStoreCommon.getInstance().configReader().get(ConfigKey.STORE_URL);
if (storeUrl.endsWith("/")) {
storeUrl = storeUrl.substring(0, storeUrl.length() - 1);
}
url = storeUrl + "/api/game_auth/confirm/";
}

private Runnable removeAndPost = () -> {
while (true) {
if (authUsers.isEmpty() && toPost.isEmpty()) {
Expand Down Expand Up @@ -61,6 +50,16 @@ public AuthHolder(MineStoreCommon plugin) {
}
};

public AuthHolder(MineStoreCommon plugin) {
authTimeout = (int) plugin.configReader().get(ConfigKey.AUTH_TIMEOUT);
new Thread(removeAndPost).start();
String storeUrl = (String) MineStoreCommon.getInstance().configReader().get(ConfigKey.STORE_URL);
if (storeUrl.endsWith("/")) {
storeUrl = storeUrl.substring(0, storeUrl.length() - 1);
}
url = storeUrl + "/api/game_auth/confirm/";
}

private void postAuthCompleted(ParsedResponse parsedResponse) {
MineStoreCommon.getInstance().debug("Posting auth completed for " + parsedResponse.username() + " with id " + parsedResponse.authId());
try {
Expand All @@ -77,7 +76,7 @@ private void postAuthCompleted(ParsedResponse parsedResponse) {
os.write(5);
}
urlConnection.getInputStream();
} catch (Exception e){
} catch (Exception e) {
e.printStackTrace();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class AuthUser {
private final CommonUser user;
private final ParsedResponse parsedResponse;
private long time;

public AuthUser(CommonUser user, ParsedResponse parsedResponse, long time) {
this.user = user;
this.parsedResponse = parsedResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import me.chrommob.minestore.common.MineStoreCommon;
import me.chrommob.minestore.common.interfaces.CommonUser;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;

public class CommonConsoleUser implements CommonUser {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import me.chrommob.minestore.common.config.ConfigKey;
import me.chrommob.minestore.common.config.ConfigReader;
import me.chrommob.minestore.common.interfaces.CommandGetter;
import me.chrommob.minestore.common.interfaces.ConfigReaderCommon;

import javax.net.ssl.HttpsURLConnection;
import java.io.BufferedReader;
Expand All @@ -18,52 +17,13 @@
import java.net.URL;

public class WebListener implements CommandGetter {
private boolean running;
private final MineStoreCommon mineStoreCommon;
private final ConfigReader configReader;
private boolean wasEmpty = false;
private final Gson gson = new Gson();
public WebListener(MineStoreCommon mineStoreCommon) {
running = false;
this.mineStoreCommon = mineStoreCommon;
configReader = mineStoreCommon.configReader();
}

private boolean running;
private boolean wasEmpty = false;
private URL queueUrl;
private URL executedUrl;
@Override
public boolean load() {
running = false;
String finalQueueUrl;
String finalExecutedUrl;
String storeUrl = (String) configReader.get(ConfigKey.STORE_URL);
if (storeUrl.endsWith("/")) {
storeUrl = storeUrl.substring(0, storeUrl.length() - 1);
}
if ((boolean) configReader.get(ConfigKey.SECRET_ENABLED)) {
finalQueueUrl = storeUrl + "/api/servers/" + configReader.get(ConfigKey.SECRET_KEY) + "/commands/queue";
finalExecutedUrl = storeUrl + "/api/servers/" + configReader.get(ConfigKey.SECRET_KEY) + "/commands/executed/";
} else {
finalQueueUrl = storeUrl + "/api/servers/commands/queue";
finalExecutedUrl = storeUrl + "/api/servers/commands/executed/";
}
try {
queueUrl = new URL(finalQueueUrl);
executedUrl = new URL(finalExecutedUrl);
} catch (Exception e) {
mineStoreCommon.log("Store URL is not a URL!");
MineStoreCommon.getInstance().debug(e);
return false;
}
running = true;
return true;
}

@Override
public void start() {
new Thread(runnable).start();
}

public Runnable runnable = new Runnable() {
@Override
public void run() {
Expand Down Expand Up @@ -130,6 +90,45 @@ public void run() {
}
};

public WebListener(MineStoreCommon mineStoreCommon) {
running = false;
this.mineStoreCommon = mineStoreCommon;
configReader = mineStoreCommon.configReader();
}

@Override
public boolean load() {
running = false;
String finalQueueUrl;
String finalExecutedUrl;
String storeUrl = (String) configReader.get(ConfigKey.STORE_URL);
if (storeUrl.endsWith("/")) {
storeUrl = storeUrl.substring(0, storeUrl.length() - 1);
}
if ((boolean) configReader.get(ConfigKey.SECRET_ENABLED)) {
finalQueueUrl = storeUrl + "/api/servers/" + configReader.get(ConfigKey.SECRET_KEY) + "/commands/queue";
finalExecutedUrl = storeUrl + "/api/servers/" + configReader.get(ConfigKey.SECRET_KEY) + "/commands/executed/";
} else {
finalQueueUrl = storeUrl + "/api/servers/commands/queue";
finalExecutedUrl = storeUrl + "/api/servers/commands/executed/";
}
try {
queueUrl = new URL(finalQueueUrl);
executedUrl = new URL(finalExecutedUrl);
} catch (Exception e) {
mineStoreCommon.log("Store URL is not a URL!");
MineStoreCommon.getInstance().debug(e);
return false;
}
running = true;
return true;
}

@Override
public void start() {
new Thread(runnable).start();
}

private void post(ParsedResponse response) {
try {
String id = String.valueOf(response.commandId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,6 @@ public ParsedResponse(TYPE type, String username, String authId, int requestId)
this.authId = authId;
}

public enum TYPE {
AUTH,
COMMAND
}

public enum COMMAND_TYPE {
ONLINE,
OFFLINE
}

public TYPE type() {
return type;
}
Expand All @@ -60,4 +50,14 @@ public int commandId() {
public String authId() {
return authId;
}

public enum TYPE {
AUTH,
COMMAND
}

public enum COMMAND_TYPE {
ONLINE,
OFFLINE
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import me.chrommob.minestore.common.MineStoreCommon;
import me.chrommob.minestore.common.commandGetters.dataTypes.ParsedResponse;

import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public class CommandStorage {
private Map<String, List<String>> commands;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public enum ConfigKey {
AUTH_FAILURE_MESSAGE(new Configuration("auth.failure-message", "<dark_red>You have failed to log in to our store!</dark_red>"));

private final Configuration configuration;

ConfigKey(Configuration configuration) {
this.configuration = configuration;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;

public class ConfigReader {
private Yaml yaml;
private final File configFile;
private Yaml yaml;
private Map<String, Object> configYaml = new LinkedHashMap<>();

public ConfigReader(File configFile) {
this.configFile = configFile;
init();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
public class Configuration {
private String location;
private Object defaultValue;

public Configuration(String location, Object defaultValue) {
this.location = location;
this.defaultValue = defaultValue;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package me.chrommob.minestore.platforms.bukkit;

import co.aikar.commands.PaperCommandManager;
import me.chrommob.minestore.common.MineStoreCommon;
import me.chrommob.minestore.platforms.bukkit.events.BukkitPlayerJoin;
import me.chrommob.minestore.platforms.bukkit.logger.BukkitLogger;
import me.chrommob.minestore.platforms.bukkit.user.BukkitUserGetter;
import me.chrommob.minestore.platforms.bukkit.webCommand.CommandExecuterBukkit;
import me.chrommob.minestore.common.MineStoreCommon;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import org.bukkit.plugin.java.JavaPlugin;
import org.checkerframework.checker.nullness.qual.NonNull;
Expand All @@ -14,12 +14,17 @@ public final class MineStoreBukkit extends JavaPlugin {
private static MineStoreBukkit instance;
private BukkitAudiences adventure;

public static MineStoreBukkit getInstance() {
return instance;
}

public @NonNull BukkitAudiences adventure() {
if(this.adventure == null) {
if (this.adventure == null) {
throw new IllegalStateException("Tried to access Adventure when the plugin was disabled!");
}
return this.adventure;
}

@Override
public void onEnable() {
this.adventure = BukkitAudiences.create(this);
Expand All @@ -36,13 +41,9 @@ public void onEnable() {

@Override
public void onDisable() {
if(this.adventure != null) {
if (this.adventure != null) {
this.adventure.close();
this.adventure = null;
}
}

public static MineStoreBukkit getInstance() {
return instance;
}
}
Loading

0 comments on commit 4e8e755

Please sign in to comment.