Bunch of things:

- IntelliJ Inspection fixes.
- Removed some unused code
- Added ConfigNode#getStringMap
- Removed usages of ConfigNode#getChildren
This commit is contained in:
Rsl1122 2018-12-20 13:50:40 +02:00
parent f39e1cd95c
commit a64336803f
14 changed files with 45 additions and 85 deletions

View File

@ -85,6 +85,7 @@ public class PlanBungeeMocker extends Mocker {
return this;
}
@SuppressWarnings("deprecation")
public PlanBungeeMocker withProxy() {
ProxyServer proxyMock = Mockito.mock(ProxyServer.class);
doReturn("1.12.2").when(proxyMock).getVersion();

View File

@ -95,9 +95,6 @@ public class ManageConDebugCommand extends CommandNode {
try {
connectionSystem.sendInfoRequest(infoRequestFactory.checkConnectionRequest(address), server);
sender.sendMessage(getMsgFor(address, usingHttps, local, true, true));
} catch (ForbiddenException | BadRequestException | InternalErrorException e) {
sender.sendMessage(getMsgFor(address, usingHttps, local, false, false));
sender.sendMessage(locale.getString(ManageLang.CON_EXCEPTION, e.getClass().getSimpleName()));
} catch (UnauthorizedServerException e) {
sender.sendMessage(getMsgFor(address, usingHttps, local, true, false));
sender.sendMessage(locale.getString(ManageLang.CON_UNAUTHORIZED));

View File

@ -60,13 +60,11 @@ public class ManageDisableCommand extends CommandNode {
Verify.isTrue(args.length >= 1,
() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ONE_ARG, Arrays.toString(this.getArguments()))));
switch (args[0].toLowerCase()) {
case "kickcount":
status.setCountKicks(false);
sender.sendMessage(locale.getString(CommandLang.FEATURE_DISABLED, "Kick Counting"));
break;
default:
sender.sendMessage(locale.getString(CommandLang.FAIL_NO_SUCH_FEATURE, "'kickcount'"));
if ("kickcount".equals(args[0].toLowerCase())) {
status.setCountKicks(false);
sender.sendMessage(locale.getString(CommandLang.FEATURE_DISABLED, "Kick Counting"));
} else {
sender.sendMessage(locale.getString(CommandLang.FAIL_NO_SUCH_FEATURE, "'kickcount'"));
}
}
}

View File

@ -110,20 +110,14 @@ public class ManageRestoreCommand extends CommandNode {
private void runRestoreTask(String backupDbName, Sender sender, Database database) {
processing.submitCritical(() -> {
try {
String backupDBName = backupDbName;
boolean containsDBFileExtension = backupDBName.endsWith(".db");
File backupDBFile = files.getFileFromPluginFolder(backupDBName + (containsDBFileExtension ? "" : ".db"));
boolean containsDBFileExtension = backupDbName.endsWith(".db");
File backupDBFile = files.getFileFromPluginFolder(backupDbName + (containsDBFileExtension ? "" : ".db"));
if (!backupDBFile.exists()) {
sender.sendMessage(locale.getString(ManageLang.FAIL_FILE_NOT_FOUND, backupDBFile.getAbsolutePath()));
return;
}
if (containsDBFileExtension) {
backupDBName = backupDBName.substring(0, backupDBName.length() - 3);
}
SQLiteDB backupDB = sqliteFactory.usingFile(backupDBFile);
backupDB.init();

View File

@ -26,7 +26,6 @@ import com.djrapitops.pluginbridge.plan.Bridge;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.*;
import java.util.stream.Collectors;
/**
* Class responsible for hooking to other plugins and managing the %plugins%
@ -115,13 +114,6 @@ public class HookHandler implements SubSystem {
return additionalDataSources;
}
public List<BanData> getBanDataSources() {
return additionalDataSources.stream()
.filter(p -> p instanceof BanData)
.map(p -> (BanData) p)
.collect(Collectors.toList());
}
public Map<PluginData, InspectContainer> getInspectContainersFor(UUID uuid) {
List<PluginData> plugins = getAdditionalDataSources();
Map<PluginData, InspectContainer> containers = new HashMap<>();

View File

@ -246,6 +246,6 @@ public class PlanSystem implements SubSystem {
}
public boolean isEnabled() {
return false;
return enabled;
}
}

View File

@ -24,7 +24,6 @@ import com.djrapitops.plan.system.database.DBSystem;
import com.djrapitops.plan.system.file.PlanFiles;
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.settings.config.PlanConfig;
import com.djrapitops.plan.system.settings.paths.ExportSettings;
import com.djrapitops.plan.system.settings.theme.Theme;
@ -55,7 +54,6 @@ public class HtmlExport extends SpecificExport {
private final PlanPlugin plugin;
private final PlanConfig config;
private final Theme theme;
private final Processing processing;
private final PlanFiles files;
private final DBSystem dbSystem;
private final PageFactory pageFactory;
@ -68,7 +66,6 @@ public class HtmlExport extends SpecificExport {
PlanFiles files,
PlanConfig config,
Theme theme,
Processing processing,
DBSystem dbSystem,
PageFactory pageFactory,
ServerInfo serverInfo,
@ -79,7 +76,6 @@ public class HtmlExport extends SpecificExport {
this.plugin = plugin;
this.config = config;
this.theme = theme;
this.processing = processing;
this.files = files;
this.dbSystem = dbSystem;
this.pageFactory = pageFactory;

View File

@ -71,10 +71,11 @@ public class ConnectionOut {
/**
* Constructor.
* @param toServer Full address to another Plan webserver. (http://something:port)
* @param serverUUID UUID of server this outbound connection.
* @param infoRequest Type of the action this connection wants to be performed.
* @param connectionLog
*
* @param toServer Full address to another Plan webserver. (http://something:port)
* @param serverUUID UUID of server this outbound connection.
* @param infoRequest Type of the action this connection wants to be performed.
* @param connectionLog Where the connection should be logged.
*/
public ConnectionOut(
Server toServer, UUID serverUUID, InfoRequest infoRequest,

View File

@ -25,6 +25,7 @@ package com.djrapitops.plan.system.settings.config;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;
/**
* Represents a single node in a configuration file
@ -245,6 +246,17 @@ public class ConfigNode {
return getNode(path).map(ConfigNode::getStringList).orElse(Collections.emptyList());
}
/**
* Return values in a Map.
*
* @param fullKeys Should the key be full keys of the Config node.
* @return Map with Config key - ConfigNode#getString.
*/
public Map<String, String> getStringMap(boolean fullKeys) {
return childNodes.values().stream()
.collect(Collectors.toMap(node -> node.getKey(fullKeys), ConfigNode::getString));
}
public Integer getInteger(String path) {
return getNode(path).map(ConfigNode::getInteger).orElse(null);
}
@ -300,11 +312,6 @@ public class ConfigNode {
return parent != null ? parent.getNodeDepth() + 1 : -1; // Root node is -1
}
@Deprecated // Make protected
public Map<String, ConfigNode> getChildren() {
return childNodes;
}
public ConfigNode getParent() {
return parent;
}

View File

@ -59,7 +59,7 @@ public class ConfigWriter {
}
private void dfsTreeTraverseLineResolve(ConfigNode writing, Collection<String> lines) {
Map<String, ConfigNode> children = writing.getChildren();
Map<String, ConfigNode> children = writing.childNodes;
for (String key : writing.getNodeOrder()) {
ConfigNode node = children.get(key);
if (node.value == null && node.nodeOrder.isEmpty()) {

View File

@ -74,13 +74,7 @@ public class WorldAliasSettings {
* @return Map: Original name, Alias
*/
public Map<String, String> getAliases() {
ConfigNode aliasSect = getAliasSection();
Map<String, String> aliasMap = new HashMap<>();
for (Map.Entry<String, ConfigNode> world : aliasSect.getChildren().entrySet()) {
aliasMap.put(world.getKey(), world.getValue().getString());
}
return aliasMap;
return getAliasSection().getStringMap(false);
}
/**

View File

@ -152,9 +152,8 @@ public class InspectPage implements Page {
String playerName = player.getValue(PlayerKeys.NAME).orElse("Unknown");
int timesKicked = player.getValue(PlayerKeys.KICK_COUNT).orElse(0);
replacer.addAllPlaceholdersFrom(player, yearLongFormatter,
PlayerKeys.REGISTERED, PlayerKeys.LAST_SEEN
);
replacer.addPlaceholderFrom(player, yearLongFormatter, PlayerKeys.REGISTERED);
replacer.addPlaceholderFrom(player, yearLongFormatter, PlayerKeys.LAST_SEEN);
replacer.put("playerName", playerName);
replacer.put("kickCount", timesKicked);

View File

@ -40,9 +40,6 @@ public class BungeeBukkitConnectionTest {
private PlanSystem bukkitSystem;
private PlanSystem bungeeSystem;
private UUID bukkitUUID;
private UUID bungeeUUID;
@After
public void tearDown() {
System.out.println("------------------------------");
@ -69,8 +66,8 @@ public class BungeeBukkitConnectionTest {
bukkitSystem.enable();
bungeeSystem.enable();
bukkitUUID = bukkitSystem.getServerInfo().getServerUUID();
bungeeUUID = bungeeSystem.getServerInfo().getServerUUID();
UUID bukkitUUID = bukkitSystem.getServerInfo().getServerUUID();
UUID bungeeUUID = bungeeSystem.getServerInfo().getServerUUID();
System.out.println("------------------------------");
System.out.println("Enable Complete");

View File

@ -42,6 +42,7 @@ import org.junit.rules.TemporaryFolder;
import org.junit.rules.Timeout;
import rules.BukkitComponentMocker;
import rules.ComponentMocker;
import utilities.FieldFetcher;
import utilities.OptionalAssert;
import utilities.RandomData;
import utilities.TestConstants;
@ -49,8 +50,6 @@ import utilities.TestConstants;
import java.io.File;
import java.lang.management.ManagementFactory;
import java.lang.management.OperatingSystemMXBean;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.security.NoSuchAlgorithmException;
import java.util.*;
import java.util.concurrent.TimeUnit;
@ -916,14 +915,10 @@ public abstract class CommonDBTest {
playerContainer.putRawData(PlayerKeys.ACTIVE_SESSION, RandomData.randomSession());
List<String> unsupported = new ArrayList<>();
for (Field field : PlayerKeys.class.getDeclaredFields()) {
if (!Modifier.isPublic(field.getModifiers())) {
continue;
}
// the field is static and no object is needed for access.
Key key = (Key) field.get(null);
List<Key> keys = FieldFetcher.getPublicStaticFields(PlayerKeys.class, Key.class);
for (Key key : keys) {
if (!playerContainer.supports(key)) {
unsupported.add(field.getName());
unsupported.add(key.getKeyName());
}
}
@ -937,14 +932,10 @@ public abstract class CommonDBTest {
ServerContainer serverContainer = db.fetch().getServerContainer(serverUUID);
List<String> unsupported = new ArrayList<>();
for (Field field : ServerKeys.class.getDeclaredFields()) {
if (!Modifier.isPublic(field.getModifiers())) {
continue;
}
// the field is static and no object is needed for access.
Key key = (Key) field.get(null);
List<Key> keys = FieldFetcher.getPublicStaticFields(ServerKeys.class, Key.class);
for (Key key : keys) {
if (!serverContainer.supports(key)) {
unsupported.add(field.getName());
unsupported.add(key.getKeyName());
}
}
@ -959,14 +950,10 @@ public abstract class CommonDBTest {
db.fetch().getServerContainer(serverUUID)
);
Collection<String> unsupported = new ArrayList<>();
for (Field field : AnalysisKeys.class.getDeclaredFields()) {
if (!Modifier.isPublic(field.getModifiers())) {
continue;
}
// the field is static and no object is needed for access.
Key key = (Key) field.get(null);
List<Key> keys = FieldFetcher.getPublicStaticFields(AnalysisKeys.class, Key.class);
for (Key key : keys) {
if (!analysisContainer.supports(key)) {
unsupported.add(field.getName());
unsupported.add(key.getKeyName());
}
}
@ -995,13 +982,10 @@ public abstract class CommonDBTest {
NetworkContainer networkContainer = db.fetch().getNetworkContainer();
List<String> unsupported = new ArrayList<>();
for (Field field : NetworkKeys.class.getDeclaredFields()) {
if (!Modifier.isPublic(field.getModifiers())) {
continue;
}
Key key = (Key) field.get(null);
List<Key> keys = FieldFetcher.getPublicStaticFields(NetworkKeys.class, Key.class);
for (Key key : keys) {
if (!networkContainer.supports(key)) {
unsupported.add(field.getName());
unsupported.add(key.getKeyName());
}
}