Fix some CodeClimate issues

- Mostly missing Javadoc on methods & line length violations
This commit is contained in:
ljacqu 2019-11-03 10:54:43 +01:00
parent 2673eb0f8e
commit e31cb5bb9e
9 changed files with 83 additions and 71 deletions

View File

@ -13,6 +13,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
/**
* AuthMe player data.
*/
@SuppressWarnings("checkstyle:FinalClass") // Justification: class is mocked in multiple tests
public class PlayerAuth {
/** Default email used in the database if the email column is defined to be NOT NULL. */

View File

@ -170,6 +170,7 @@ public class MySQL extends AbstractSqlDataSource {
/**
* Creates the table or any of its required columns if they don't exist.
*/
@SuppressWarnings({"checkstyle:CyclomaticComplexity", "checkstyle:JavaNCSS"})
private void checkTablesAndColumns() throws SQLException {
try (Connection con = getConnection(); Statement st = con.createStatement()) {
// Create table with ID column if it doesn't exist

View File

@ -98,6 +98,7 @@ public class SQLite extends AbstractSqlDataSource {
* @throws SQLException when an SQL error occurs while initializing the database
*/
@VisibleForTesting
@SuppressWarnings("checkstyle:CyclomaticComplexity")
protected void setup() throws SQLException {
try (Statement st = con.createStatement()) {
// Note: cannot add unique fields later on in SQLite, so we add it on initialization

View File

@ -30,73 +30,55 @@ class WordpressExtension extends MySqlExtension {
}
}
/**
* Saves the required data to Wordpress tables.
*
* @param auth the player data
* @param id the player id
* @param con the sql connection
* @throws SQLException .
*/
private void saveSpecifics(PlayerAuth auth, int id, Connection con) throws SQLException {
String sql = "INSERT INTO " + wordpressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?)";
try (PreparedStatement pst = con.prepareStatement(sql)) {
// First Name
pst.setInt(1, id);
pst.setString(2, "first_name");
pst.setString(3, "");
pst.addBatch();
// Last Name
pst.setInt(1, id);
pst.setString(2, "last_name");
pst.setString(3, "");
pst.addBatch();
// Nick Name
pst.setInt(1, id);
pst.setString(2, "nickname");
pst.setString(3, auth.getNickname());
pst.addBatch();
// Description
pst.setInt(1, id);
pst.setString(2, "description");
pst.setString(3, "");
pst.addBatch();
// Rich_Editing
pst.setInt(1, id);
pst.setString(2, "rich_editing");
pst.setString(3, "true");
pst.addBatch();
// Comments_Shortcuts
pst.setInt(1, id);
pst.setString(2, "comment_shortcuts");
pst.setString(3, "false");
pst.addBatch();
// admin_color
pst.setInt(1, id);
pst.setString(2, "admin_color");
pst.setString(3, "fresh");
pst.addBatch();
// use_ssl
pst.setInt(1, id);
pst.setString(2, "use_ssl");
pst.setString(3, "0");
pst.addBatch();
// show_admin_bar_front
pst.setInt(1, id);
pst.setString(2, "show_admin_bar_front");
pst.setString(3, "true");
pst.addBatch();
// wp_capabilities
pst.setInt(1, id);
pst.setString(2, wordpressPrefix + "capabilities");
pst.setString(3, "a:1:{s:10:\"subscriber\";b:1;}");
pst.addBatch();
// wp_user_level
pst.setInt(1, id);
pst.setString(2, wordpressPrefix + "user_level");
pst.setString(3, "0");
pst.addBatch();
// default_password_nag
pst.setInt(1, id);
pst.setString(2, "default_password_nag");
pst.setString(3, "");
pst.addBatch();
new UserMetaBatchAdder(pst, id)
.addMetaRow("first_name", "")
.addMetaRow("last_name", "")
.addMetaRow("nickname", auth.getNickname())
.addMetaRow("description", "")
.addMetaRow("rich_editing", "true")
.addMetaRow("comment_shortcuts", "false")
.addMetaRow("admin_color", "fresh")
.addMetaRow("use_ssl", "0")
.addMetaRow("show_admin_bar_front", "true")
.addMetaRow(wordpressPrefix + "capabilities", "a:1:{s:10:\"subscriber\";b:1;}")
.addMetaRow(wordpressPrefix + "user_level", "0")
.addMetaRow("default_password_nag", "");
// Execute queries
pst.executeBatch();
pst.clearBatch();
}
}
/** Helper to add batch entries to the wrapped prepared statement. */
private static final class UserMetaBatchAdder {
private final PreparedStatement pst;
private final int userId;
UserMetaBatchAdder(PreparedStatement pst, int userId) {
this.pst = pst;
this.userId = userId;
}
UserMetaBatchAdder addMetaRow(String metaKey, String metaValue) throws SQLException {
pst.setInt(1, userId);
pst.setString(2, metaKey);
pst.setString(3, metaValue);
pst.addBatch();
return this;
}
}
}

View File

@ -69,6 +69,11 @@ class InventoryPacketAdapter extends PacketAdapter {
}
}
/**
* Registers itself to ProtocolLib and blanks out the inventory packet to any applicable players.
*
* @param bukkitService the bukkit service (for retrieval of online players)
*/
public void register(BukkitService bukkitService) {
ProtocolLibrary.getProtocolManager().addPacketListener(this);
@ -85,6 +90,11 @@ class InventoryPacketAdapter extends PacketAdapter {
ProtocolLibrary.getProtocolManager().removePacketListener(this);
}
/**
* Sends a blanked out packet to the given player in order to hide the inventory.
*
* @param player the player to send the blank inventory packet to
*/
public void sendBlankInventoryPacket(Player player) {
ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
PacketContainer inventoryPacket = protocolManager.createPacket(PacketType.Play.Server.WINDOW_ITEMS);

View File

@ -30,8 +30,8 @@ public class BungeeReceiver implements PluginMessageListener, SettingsDependent
private boolean isEnabled;
@Inject
BungeeReceiver(final AuthMe plugin, final BukkitService bukkitService, final Management management,
final DataSource dataSource, final Settings settings) {
BungeeReceiver(AuthMe plugin, BukkitService bukkitService, Management management,
DataSource dataSource, Settings settings) {
this.plugin = plugin;
this.bukkitService = bukkitService;
this.management = management;
@ -51,6 +51,11 @@ public class BungeeReceiver implements PluginMessageListener, SettingsDependent
}
}
/**
* Processes the given data input and attempts to translate it to a message for the "AuthMe.v2.Broadcast" channel.
*
* @param in the input to handle
*/
private void handleBroadcast(final ByteArrayDataInput in) {
// Read data byte array
final short dataLength = in.readShort();
@ -91,7 +96,12 @@ public class BungeeReceiver implements PluginMessageListener, SettingsDependent
}
}
private void handle(final ByteArrayDataInput in) {
/**
* Processes the given data input and attempts to translate it to a message for the "AuthMe.v2" channel.
*
* @param in the input to handle
*/
private void handle(ByteArrayDataInput in) {
// Parse type
final String typeId = in.readUTF();
final Optional<MessageType> type = MessageType.fromId(typeId);

View File

@ -2,9 +2,8 @@ package tools.docs.translations;
import ch.jalu.configme.resource.PropertyReader;
import ch.jalu.configme.resource.YamlFileReader;
import fr.xephi.authme.message.MessagePathHelper;
import fr.xephi.authme.message.MessageKey;
import tools.utils.ToolsConstants;
import fr.xephi.authme.message.MessagePathHelper;
import java.io.File;
import java.util.ArrayList;
@ -12,13 +11,14 @@ import java.util.Comparator;
import java.util.List;
import static tools.utils.FileIoUtils.listFilesOrThrow;
import static tools.utils.ToolsConstants.MAIN_RESOURCES_ROOT;
/**
* Gathers all available translations of AuthMe.
*/
public class TranslationsGatherer {
private static final String MESSAGES_FOLDER = ToolsConstants.MAIN_RESOURCES_ROOT + MessagePathHelper.MESSAGES_FOLDER;
private static final String MESSAGES_FOLDER = MAIN_RESOURCES_ROOT + MessagePathHelper.MESSAGES_FOLDER;
private List<TranslationInfo> translationInfo = new ArrayList<>();

View File

@ -109,6 +109,12 @@ public class HelpTranslationVerifier {
return commandPaths;
}
/**
* Creates all paths of the properties that are used to define the help translation of the given command definition.
*
* @param command the command to create the paths for
* @return all yaml paths that can be used to translate the command
*/
private List<String> getYamlPaths(CommandDescription command) {
// e.g. commands.authme.register
String commandPath = "commands." + CommandUtils.constructParentList(command).stream()

View File

@ -1,13 +1,12 @@
package tools.messages;
import com.google.common.collect.Multimap;
import fr.xephi.authme.message.MessagePathHelper;
import fr.xephi.authme.message.MessageKey;
import fr.xephi.authme.message.MessagePathHelper;
import fr.xephi.authme.util.StringUtils;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import tools.utils.ToolTask;
import tools.utils.ToolsConstants;
import java.io.File;
import java.util.ArrayList;
@ -19,6 +18,7 @@ import java.util.Set;
import static fr.xephi.authme.message.MessagePathHelper.DEFAULT_MESSAGES_FILE;
import static tools.utils.FileIoUtils.listFilesOrThrow;
import static tools.utils.ToolsConstants.MAIN_RESOURCES_ROOT;
/**
* Task to verify the keys in the messages files.
@ -26,7 +26,7 @@ import static tools.utils.FileIoUtils.listFilesOrThrow;
public final class VerifyMessagesTask implements ToolTask {
/** The folder containing the message files. */
private static final String MESSAGES_FOLDER = ToolsConstants.MAIN_RESOURCES_ROOT + MessagePathHelper.MESSAGES_FOLDER;
private static final String MESSAGES_FOLDER = MAIN_RESOURCES_ROOT + MessagePathHelper.MESSAGES_FOLDER;
@Override
public String getTaskName() {
@ -47,13 +47,14 @@ public final class VerifyMessagesTask implements ToolTask {
if (StringUtils.isEmpty(inputFile)) {
messageFiles = getMessagesFiles();
} else {
File customFile = new File(ToolsConstants.MAIN_RESOURCES_ROOT, MessagePathHelper.createMessageFilePath(inputFile));
File customFile = new File(MAIN_RESOURCES_ROOT, MessagePathHelper.createMessageFilePath(inputFile));
messageFiles = Collections.singletonList(customFile);
}
FileConfiguration defaultFileConfiguration = null;
if (addMissingKeys) {
defaultFileConfiguration = YamlConfiguration.loadConfiguration(new File(ToolsConstants.MAIN_RESOURCES_ROOT, DEFAULT_MESSAGES_FILE));
defaultFileConfiguration = YamlConfiguration.loadConfiguration(
new File(MAIN_RESOURCES_ROOT, DEFAULT_MESSAGES_FILE));
}
// Verify the given files