Fix some CodeClimate issues
- Mostly missing Javadoc on methods & line length violations
This commit is contained in:
parent
2673eb0f8e
commit
e31cb5bb9e
@ -13,6 +13,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||||||
/**
|
/**
|
||||||
* AuthMe player data.
|
* AuthMe player data.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("checkstyle:FinalClass") // Justification: class is mocked in multiple tests
|
||||||
public class PlayerAuth {
|
public class PlayerAuth {
|
||||||
|
|
||||||
/** Default email used in the database if the email column is defined to be NOT NULL. */
|
/** Default email used in the database if the email column is defined to be NOT NULL. */
|
||||||
|
|||||||
@ -170,6 +170,7 @@ public class MySQL extends AbstractSqlDataSource {
|
|||||||
/**
|
/**
|
||||||
* Creates the table or any of its required columns if they don't exist.
|
* Creates the table or any of its required columns if they don't exist.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings({"checkstyle:CyclomaticComplexity", "checkstyle:JavaNCSS"})
|
||||||
private void checkTablesAndColumns() throws SQLException {
|
private void checkTablesAndColumns() throws SQLException {
|
||||||
try (Connection con = getConnection(); Statement st = con.createStatement()) {
|
try (Connection con = getConnection(); Statement st = con.createStatement()) {
|
||||||
// Create table with ID column if it doesn't exist
|
// Create table with ID column if it doesn't exist
|
||||||
|
|||||||
@ -98,6 +98,7 @@ public class SQLite extends AbstractSqlDataSource {
|
|||||||
* @throws SQLException when an SQL error occurs while initializing the database
|
* @throws SQLException when an SQL error occurs while initializing the database
|
||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
|
@SuppressWarnings("checkstyle:CyclomaticComplexity")
|
||||||
protected void setup() throws SQLException {
|
protected void setup() throws SQLException {
|
||||||
try (Statement st = con.createStatement()) {
|
try (Statement st = con.createStatement()) {
|
||||||
// Note: cannot add unique fields later on in SQLite, so we add it on initialization
|
// Note: cannot add unique fields later on in SQLite, so we add it on initialization
|
||||||
|
|||||||
@ -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 {
|
private void saveSpecifics(PlayerAuth auth, int id, Connection con) throws SQLException {
|
||||||
String sql = "INSERT INTO " + wordpressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?)";
|
String sql = "INSERT INTO " + wordpressPrefix + "usermeta (user_id, meta_key, meta_value) VALUES (?,?,?)";
|
||||||
try (PreparedStatement pst = con.prepareStatement(sql)) {
|
try (PreparedStatement pst = con.prepareStatement(sql)) {
|
||||||
// First Name
|
|
||||||
pst.setInt(1, id);
|
new UserMetaBatchAdder(pst, id)
|
||||||
pst.setString(2, "first_name");
|
.addMetaRow("first_name", "")
|
||||||
pst.setString(3, "");
|
.addMetaRow("last_name", "")
|
||||||
pst.addBatch();
|
.addMetaRow("nickname", auth.getNickname())
|
||||||
// Last Name
|
.addMetaRow("description", "")
|
||||||
pst.setInt(1, id);
|
.addMetaRow("rich_editing", "true")
|
||||||
pst.setString(2, "last_name");
|
.addMetaRow("comment_shortcuts", "false")
|
||||||
pst.setString(3, "");
|
.addMetaRow("admin_color", "fresh")
|
||||||
pst.addBatch();
|
.addMetaRow("use_ssl", "0")
|
||||||
// Nick Name
|
.addMetaRow("show_admin_bar_front", "true")
|
||||||
pst.setInt(1, id);
|
.addMetaRow(wordpressPrefix + "capabilities", "a:1:{s:10:\"subscriber\";b:1;}")
|
||||||
pst.setString(2, "nickname");
|
.addMetaRow(wordpressPrefix + "user_level", "0")
|
||||||
pst.setString(3, auth.getNickname());
|
.addMetaRow("default_password_nag", "");
|
||||||
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();
|
|
||||||
|
|
||||||
// Execute queries
|
// Execute queries
|
||||||
pst.executeBatch();
|
pst.executeBatch();
|
||||||
pst.clearBatch();
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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) {
|
public void register(BukkitService bukkitService) {
|
||||||
ProtocolLibrary.getProtocolManager().addPacketListener(this);
|
ProtocolLibrary.getProtocolManager().addPacketListener(this);
|
||||||
|
|
||||||
@ -85,6 +90,11 @@ class InventoryPacketAdapter extends PacketAdapter {
|
|||||||
ProtocolLibrary.getProtocolManager().removePacketListener(this);
|
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) {
|
public void sendBlankInventoryPacket(Player player) {
|
||||||
ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
|
ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
|
||||||
PacketContainer inventoryPacket = protocolManager.createPacket(PacketType.Play.Server.WINDOW_ITEMS);
|
PacketContainer inventoryPacket = protocolManager.createPacket(PacketType.Play.Server.WINDOW_ITEMS);
|
||||||
|
|||||||
@ -30,8 +30,8 @@ public class BungeeReceiver implements PluginMessageListener, SettingsDependent
|
|||||||
private boolean isEnabled;
|
private boolean isEnabled;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
BungeeReceiver(final AuthMe plugin, final BukkitService bukkitService, final Management management,
|
BungeeReceiver(AuthMe plugin, BukkitService bukkitService, Management management,
|
||||||
final DataSource dataSource, final Settings settings) {
|
DataSource dataSource, Settings settings) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.bukkitService = bukkitService;
|
this.bukkitService = bukkitService;
|
||||||
this.management = management;
|
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) {
|
private void handleBroadcast(final ByteArrayDataInput in) {
|
||||||
// Read data byte array
|
// Read data byte array
|
||||||
final short dataLength = in.readShort();
|
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
|
// Parse type
|
||||||
final String typeId = in.readUTF();
|
final String typeId = in.readUTF();
|
||||||
final Optional<MessageType> type = MessageType.fromId(typeId);
|
final Optional<MessageType> type = MessageType.fromId(typeId);
|
||||||
|
|||||||
@ -2,9 +2,8 @@ package tools.docs.translations;
|
|||||||
|
|
||||||
import ch.jalu.configme.resource.PropertyReader;
|
import ch.jalu.configme.resource.PropertyReader;
|
||||||
import ch.jalu.configme.resource.YamlFileReader;
|
import ch.jalu.configme.resource.YamlFileReader;
|
||||||
import fr.xephi.authme.message.MessagePathHelper;
|
|
||||||
import fr.xephi.authme.message.MessageKey;
|
import fr.xephi.authme.message.MessageKey;
|
||||||
import tools.utils.ToolsConstants;
|
import fr.xephi.authme.message.MessagePathHelper;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -12,13 +11,14 @@ import java.util.Comparator;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static tools.utils.FileIoUtils.listFilesOrThrow;
|
import static tools.utils.FileIoUtils.listFilesOrThrow;
|
||||||
|
import static tools.utils.ToolsConstants.MAIN_RESOURCES_ROOT;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gathers all available translations of AuthMe.
|
* Gathers all available translations of AuthMe.
|
||||||
*/
|
*/
|
||||||
public class TranslationsGatherer {
|
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<>();
|
private List<TranslationInfo> translationInfo = new ArrayList<>();
|
||||||
|
|
||||||
|
|||||||
@ -109,6 +109,12 @@ public class HelpTranslationVerifier {
|
|||||||
return commandPaths;
|
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) {
|
private List<String> getYamlPaths(CommandDescription command) {
|
||||||
// e.g. commands.authme.register
|
// e.g. commands.authme.register
|
||||||
String commandPath = "commands." + CommandUtils.constructParentList(command).stream()
|
String commandPath = "commands." + CommandUtils.constructParentList(command).stream()
|
||||||
|
|||||||
@ -1,13 +1,12 @@
|
|||||||
package tools.messages;
|
package tools.messages;
|
||||||
|
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
import fr.xephi.authme.message.MessagePathHelper;
|
|
||||||
import fr.xephi.authme.message.MessageKey;
|
import fr.xephi.authme.message.MessageKey;
|
||||||
|
import fr.xephi.authme.message.MessagePathHelper;
|
||||||
import fr.xephi.authme.util.StringUtils;
|
import fr.xephi.authme.util.StringUtils;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import tools.utils.ToolTask;
|
import tools.utils.ToolTask;
|
||||||
import tools.utils.ToolsConstants;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -19,6 +18,7 @@ import java.util.Set;
|
|||||||
|
|
||||||
import static fr.xephi.authme.message.MessagePathHelper.DEFAULT_MESSAGES_FILE;
|
import static fr.xephi.authme.message.MessagePathHelper.DEFAULT_MESSAGES_FILE;
|
||||||
import static tools.utils.FileIoUtils.listFilesOrThrow;
|
import static tools.utils.FileIoUtils.listFilesOrThrow;
|
||||||
|
import static tools.utils.ToolsConstants.MAIN_RESOURCES_ROOT;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Task to verify the keys in the messages files.
|
* 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 {
|
public final class VerifyMessagesTask implements ToolTask {
|
||||||
|
|
||||||
/** The folder containing the message files. */
|
/** 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
|
@Override
|
||||||
public String getTaskName() {
|
public String getTaskName() {
|
||||||
@ -47,13 +47,14 @@ public final class VerifyMessagesTask implements ToolTask {
|
|||||||
if (StringUtils.isEmpty(inputFile)) {
|
if (StringUtils.isEmpty(inputFile)) {
|
||||||
messageFiles = getMessagesFiles();
|
messageFiles = getMessagesFiles();
|
||||||
} else {
|
} 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);
|
messageFiles = Collections.singletonList(customFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
FileConfiguration defaultFileConfiguration = null;
|
FileConfiguration defaultFileConfiguration = null;
|
||||||
if (addMissingKeys) {
|
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
|
// Verify the given files
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user