Skip to content

Commit

Permalink
Suppress warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
srnyx committed Jun 26, 2024
1 parent 72b6689 commit a4188d8
Show file tree
Hide file tree
Showing 15 changed files with 44 additions and 53 deletions.
2 changes: 2 additions & 0 deletions src/main/java/xyz/srnyx/annoyingapi/AnnoyingPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
/**
* Represents a plugin using Annoying API
*/
@SuppressWarnings("EmptyMethod")
public class AnnoyingPlugin extends JavaPlugin {
/**
* The {@link Logger} for the plugin
Expand Down Expand Up @@ -530,6 +531,7 @@ private DataManager attemptDatabaseMigration(@NotNull DataManager oldManager) {
*
* @return {@code true} if the task was run asynchronously, {@code false} if it was run synchronously
*/
@SuppressWarnings("UnusedReturnValue")
public boolean attemptAsync(@NotNull Runnable runnable) {
try {
Bukkit.getScheduler().runTaskAsynchronously(this, runnable);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/xyz/srnyx/annoyingapi/AnnoyingUpdate.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public AnnoyingPlugin getAnnoyingPlugin() {
*
* @return {@code true} if an update is available, {@code false} otherwise
*/
@SuppressWarnings("UnusedReturnValue")
public boolean checkUpdate() {
final boolean update = isUpdateAvailable();
if (update && latestVersion != null) new AnnoyingMessage(annoyingPlugin, annoyingPlugin.options.messagesOptions.keys.updateAvailable)
Expand Down
20 changes: 11 additions & 9 deletions src/main/java/xyz/srnyx/annoyingapi/PluginPlatform.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public enum Platform {
* <p>Project ID <i>or</i> slug
* <p><b>Example:</b> {@code gzktm9GG} <i>or</i> {@code annoying-api}
*/
MODRINTH,
MODRINTH(false),
/**
* <a href="https://hangar.papermc.io/">{@code https://hangar.papermc.io/}</a>
* <p>Slug
Expand All @@ -239,33 +239,34 @@ public enum Platform {
* <p>Project ID
* <p><b>Example:</b> {@code 106637}
*/
SPIGOT,
SPIGOT(false),
/**
* <a href="https://dev.bukkit.org/projects">{@code https://dev.bukkit.org/projects}</a>
* <p>Project ID <i>or</i> slug
* <p><b>Example:</b> {@code 728930} <i>or</i> {@code annoying-api}
*/
BUKKIT,
BUKKIT(false),
/**
* An external direct-download URL
* <p><b>Example:</b> {@code https://ci.dmulloy2.net/job/ProtocolLib/lastSuccessfulBuild/artifact/target/ProtocolLib.jar}
*/
EXTERNAL,
EXTERNAL(false),
/**
* A URL that the user can manually download the plugin from
* <p><b>Example:</b> {@code https://github.com/srnyx/annoying-api/releases/latest}
*/
MANUAL;
MANUAL(false);

/**
* Whether this {@link Platform} requires an author
*/
public final boolean requiresAuthor;

Platform() {
requiresAuthor = false;
}

/**
* Creates a new {@link Platform}
*
* @param requiresAuthor {@link #requiresAuthor}
*/
Platform(boolean requiresAuthor) {
this.requiresAuthor = requiresAuthor;
}
Expand All @@ -274,6 +275,7 @@ public enum Platform {
/**
* A collection of {@link PluginPlatform}s
*/
@SuppressWarnings("UnusedReturnValue")
public static class Multi extends Stringable {
/**
* The {@link PluginPlatform PluginPlatforms} in this {@link Multi Multi}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
/**
* Represents a command that can be executed by a player or the console
*/
@SuppressWarnings("SameReturnValue")
public abstract class AnnoyingCommand extends Registrable implements TabExecutor {
/**
* Constructs a new command instance for registration
Expand Down
1 change: 1 addition & 0 deletions src/main/java/xyz/srnyx/annoyingapi/data/Data.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public String get(@NotNull String key, @NotNull String def) {
*
* @return {@code true} if the data value was set successfully, {@code false} otherwise
*/
@SuppressWarnings("UnusedReturnValue")
public boolean set(@NotNull String key, @Nullable Object value) {
return value == null ? remove(key) : set(key, value.toString());
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/xyz/srnyx/annoyingapi/data/EntityData.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public EntityData(@NotNull AnnoyingPlugin plugin, @NotNull Entity entity) {
*
* @return a map of keys that failed to convert (key, value) or {@code null} if an error occurred (only returns {@code null} if 1.14+ fails)
*/
@Nullable
@Nullable @SuppressWarnings("deprecation")
public Map<String, String> convertOldData(boolean onlyTryOnce, @Nullable Collection<String> keys) {
// 1.14+ (persistent data container)
if (NAMESPACED_KEY_CONSTRUCTOR != null && PERSISTENT_DATA_HOLDER_GET_PERSISTENT_DATA_CONTAINER_METHOD != null && PERSISTENT_DATA_CONTAINER_GET_METHOD != null && PERSISTENT_DATA_CONTAINER_SET_METHOD != null && PERSISTENT_DATA_CONTAINER_REMOVE_METHOD != null && PERSISTENT_DATA_TYPE_STRING != null && PERSISTENT_DATA_TYPE_BYTE != null) {
Expand Down
48 changes: 13 additions & 35 deletions src/main/java/xyz/srnyx/annoyingapi/data/StorageConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,25 +220,25 @@ public Cache() {
*/
public enum Method {
/**
* H2 storage method
* H2's storage method
*/
H2(H2Dialect::new, "h2{}Driver", dataFolder -> "jdbc:h2:file:.\\" + dataFolder + "\\data\\h2\\data", RuntimeLibrary.H2),
H2(H2Dialect::new, "h2{}Driver", dataFolder -> "jdbc:h2:file:.\\" + dataFolder + "\\data\\h2\\data", null, RuntimeLibrary.H2),
/**
* SQLite storage method
* SQLite's storage method
*/
SQLITE(SQLiteDialect::new, "org{}sqlite{}JDBC", dataFolder -> "jdbc:sqlite:" + dataFolder + "\\data\\sqlite\\data.db"),
SQLITE(SQLiteDialect::new, "org{}sqlite{}JDBC", dataFolder -> "jdbc:sqlite:" + dataFolder + "\\data\\sqlite\\data.db", null, null),
/**
* MySQL storage method
* MySQL's storage method
*/
MYSQL(MySQLDialect::new, MYSQL_MARIADB_DRIVER, dataFolder -> "jdbc:mysql://", 3306),
MYSQL(MySQLDialect::new, MYSQL_MARIADB_DRIVER, "jdbc:mysql://", 3306, null),
/**
* MariaDB storage method
* MariaDB's storage method
*/
MARIADB(MariaDBDialect::new, MYSQL_MARIADB_DRIVER, dataFolder -> "jdbc:mysql://", 3306),
MARIADB(MariaDBDialect::new, MYSQL_MARIADB_DRIVER, "jdbc:mysql://", 3306, null),
/**
* PostgreSQL storage method
* PostgreSQL's storage method
*/
POSTGRESQL(PostgreSQLDialect::new, "postgresql{}Driver", dataFolder -> "jdbc:postgresql://", 5432, RuntimeLibrary.POSTGRESQL);
POSTGRESQL(PostgreSQLDialect::new, "postgresql{}Driver", "jdbc:postgresql://", 5432, RuntimeLibrary.POSTGRESQL);

/**
* The {@link SQLDialect SQL dialect} constructor for the method
Expand Down Expand Up @@ -286,32 +286,10 @@ public enum Method {
* @param driver {@link #driver}
* @param url {@link #url}
* @param defaultPort {@link #defaultPort}
* @param library {@link #library}
*/
Method(@NotNull Function<DataManager, SQLDialect> dialect, @NotNull String driver, @NotNull Function<File, String> url, int defaultPort) {
this(dialect, driver, url, defaultPort, null);
}

/**
* Construct a new {@link Method} with the given parameters
*
* @param dialect {@link #dialect}
* @param driver {@link #driver}
* @param url {@link #url}
* @param library {@link #library}
*/
Method(@NotNull Function<DataManager, SQLDialect> dialect, @NotNull String driver, @NotNull Function<File, String> url, @NotNull RuntimeLibrary library) {
this(dialect, driver, url, null, library);
}

/**
* Construct a new {@link Method} with the given parameters
*
* @param dialect {@link #dialect}
* @param driver {@link #driver}
* @param url {@link #url}
*/
Method(@NotNull Function<DataManager, SQLDialect> dialect, @NotNull String driver, @NotNull Function<File, String> url) {
this(dialect, driver, url, null, null);
Method(@NotNull Function<DataManager, SQLDialect> dialect, @NotNull String driver, @NotNull String url, @Nullable Integer defaultPort, @Nullable RuntimeLibrary library) {
this(dialect, driver, dataFolder -> url, defaultPort, library);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public PreparedStatement getValueImpl(@NotNull String table, @NotNull String tar
return statement;
}

@Override @NotNull
@Override @NotNull @SuppressWarnings("DuplicatedCode")
public PreparedStatement setValueImpl(@NotNull String table, @NotNull String target, @NotNull String column, @NotNull String value) throws SQLException {
final PreparedStatement statement = dataManager.connection.prepareStatement("INSERT INTO `" + table + "` (`" + StringData.TARGET_COLUMN + "`, `" + column + "`) VALUES (?, ?) ON DUPLICATE KEY UPDATE `" + column + "` = ?");
statement.setString(1, target);
Expand All @@ -56,7 +56,7 @@ public PreparedStatement setValueImpl(@NotNull String table, @NotNull String tar
return statement;
}

@Override @NotNull
@Override @NotNull @SuppressWarnings("DuplicatedCode")
public PreparedStatement setValuesImpl(@NotNull String table, @NotNull String target, @NotNull Map<String, String> data) throws SQLException {
// Get builders
final StringBuilder insertBuilder = new StringBuilder("INSERT INTO `" + table + "` (`" + StringData.TARGET_COLUMN + "`");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public PreparedStatement getValueImpl(@NotNull String table, @NotNull String tar
return statement;
}

@Override @NotNull
@Override @NotNull @SuppressWarnings("DuplicatedCode")
public PreparedStatement setValueImpl(@NotNull String table, @NotNull String target, @NotNull String column, @NotNull String value) throws SQLException {
final PreparedStatement statement = dataManager.connection.prepareStatement("INSERT INTO `" + table + "` (`" + StringData.TARGET_COLUMN + "`, `" + column + "`) VALUES (?, ?) ON DUPLICATE KEY UPDATE `" + column + "` = ?");
statement.setString(1, target);
Expand All @@ -65,7 +65,7 @@ public PreparedStatement setValueImpl(@NotNull String table, @NotNull String tar
return statement;
}

@Override @NotNull
@Override @NotNull @SuppressWarnings("DuplicatedCode")
public PreparedStatement setValuesImpl(@NotNull String table, @NotNull String target, @NotNull Map<String, String> data) throws SQLException {
// Get builders
final StringBuilder insertBuilder = new StringBuilder("INSERT INTO `" + table + "` (`" + StringData.TARGET_COLUMN + "`");
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/xyz/srnyx/annoyingapi/file/AnnoyingFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
* @see AnnoyingResource
* @see AnnoyingData
*/
@SuppressWarnings("unchecked")
public class AnnoyingFile<T extends AnnoyingFile<T>> extends YamlConfiguration {
/**
* The {@link AnnoyingPlugin} instance
Expand Down Expand Up @@ -178,6 +179,7 @@ public boolean delete(boolean silentFail) {
*
* @see #delete(boolean)
*/
@SuppressWarnings("UnusedReturnValue")
public boolean delete() {
return delete(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ public AnnoyingMessage replace(@NotNull String before, @Nullable Object after) {
*/
@NotNull
public BaseComponent[] getComponents(@Nullable AnnoyingSender sender) {
if (components != null) return components; // Use cached components
if (components != null) { //noinspection NullableProblems
return components; // Use cached components
}
final AnnoyingJSON json = new AnnoyingJSON();

// Get messages file
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/xyz/srnyx/annoyingapi/options/DataOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class DataOptions extends Stringable {
* <br><b>All tables will be made with the primary key {@code target}</b>
* <br><i>Removing {@link EntityData#TABLE_NAME} will break {@link EntityData}</i>
*/
@NotNull public Map<String, Set<String>> tables = new HashMap<>(MapUtility.mapOf(EntityData.TABLE_NAME, new HashSet<>(Collections.singleton(StringData.TARGET_COLUMN))));
@NotNull @SuppressWarnings("CanBeFinal") public Map<String, Set<String>> tables = new HashMap<>(MapUtility.mapOf(EntityData.TABLE_NAME, new HashSet<>(Collections.singleton(StringData.TARGET_COLUMN))));
/**
* Whether to use the cache by default for {@link StringData}
*/
Expand Down Expand Up @@ -199,6 +199,7 @@ public static DataOptions load(@NotNull ConfigurationSection section) {
/**
* Options for {@link EntityData entity data management}
*/
@SuppressWarnings("DeprecatedIsStillUsed")
public static class Entities extends Stringable {
/**
* The path to the folder (inside {@code plugins/PLUGIN/data/}) where the entity data files will be stored
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class PluginOptions extends Stringable {
* <p>If you add a dependency to this OUTSIDE the constructor, it will not be checked
* <p><i>This is <b>NOT</b> meant for optional dependencies, all of these dependencies will be downloaded/installed (even if {@link AnnoyingDependency#required} is {@code false})</i>
*/
@NotNull public List<AnnoyingDependency> dependencies = new ArrayList<>();
@NotNull @SuppressWarnings("CanBeFinal") public List<AnnoyingDependency> dependencies = new ArrayList<>();
/**
* <i>{@code RECOMMENDED}</i> The different {@link PluginPlatform platforms} the plugin is available on
* <p>If not specified, the plugin will not be able to check for updates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class RegistrationOptions extends Stringable {
/**
* <i>{@code OPTIONAL}</i> The {@link Registrable}s to register when the plugin {@link AnnoyingPlugin#onEnable() enables}
*/
@NotNull public Set<Registrable> toRegister = new HashSet<>();
@NotNull @SuppressWarnings("CanBeFinal") public Set<Registrable> toRegister = new HashSet<>();
/**
* <i>{@code OPTIONAL}</i> The {@link PlaceholderExpansion PAPI expansion} to register when the plugin {@link AnnoyingPlugin#onEnable() enables}
* <p><i>Can also be a {@link AnnoyingPAPIExpansion}</i>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public static String stripUntranslatedColor(@Nullable String string) {
public static boolean toggleScoreboardTag(@NotNull Entity entity, @NotNull String scoreboardTag) {
if (ENTITY_GET_SCOREBOARD_TAGS_METHOD == null || ENTITY_REMOVE_SCOREBOARD_TAG_METHOD == null || ENTITY_ADD_SCOREBOARD_TAG_METHOD == null) return false;
try {
//noinspection unchecked
if (((Set<String>) ENTITY_GET_SCOREBOARD_TAGS_METHOD.invoke(entity)).contains(scoreboardTag)) {
ENTITY_REMOVE_SCOREBOARD_TAG_METHOD.invoke(entity, scoreboardTag);
return false;
Expand Down

0 comments on commit a4188d8

Please sign in to comment.