Adds missing @NotNull annotations
All checks were successful
EpicKnarvik97/KnarLib/pipeline/head This commit looks good

This commit is contained in:
Kristian Knarvik 2023-07-08 17:22:56 +02:00
parent 2c8182e552
commit 94d74e7794
14 changed files with 99 additions and 88 deletions

View File

@ -28,7 +28,7 @@ public final class StringFormatter {
* @param pluginName <p>The name of the using plugin (used for the message prefix)</p>
* @param translator <p>The translator to use for translating messages</p>
*/
public StringFormatter(String pluginName, Translator translator) {
public StringFormatter(@NotNull String pluginName, @NotNull Translator translator) {
this.pluginName = pluginName;
this.translator = translator;
}
@ -201,13 +201,9 @@ public final class StringFormatter {
*/
private String getFormattedMessage(@NotNull String message) {
message = ColorHelper.translateColorCodes(message, this.colorConversion);
if (this.pluginName == null) {
return message;
} else {
String coloredPrefix = ColorHelper.translateColorCodes(namePrefix + ChatColor.RESET +
this.pluginName + ChatColor.RESET + nameSuffix, this.colorConversion);
String coloredPrefix = ColorHelper.translateColorCodes(namePrefix + this.pluginName +
nameSuffix, this.colorConversion);
return coloredPrefix + " " + ChatColor.RESET + message;
}
}
}

View File

@ -1,5 +1,7 @@
package net.knarcraft.knarlib.formatting;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
import java.util.Map;
@ -25,7 +27,7 @@ public final class StringReplacer {
*
* @param replacementInput <p>The input string to replace placeholders for</p>
*/
public StringReplacer(String replacementInput) {
public StringReplacer(@NotNull String replacementInput) {
this.replacementInput = replacementInput;
}
@ -35,7 +37,7 @@ public final class StringReplacer {
* @param placeholder <p>The placeholder to replace</p>
* @param value <p>The replacement value</p>
*/
public void add(String placeholder, String value) {
public void add(@NotNull String placeholder, @NotNull String value) {
this.replacements.put(placeholder, value);
}
@ -44,7 +46,7 @@ public final class StringReplacer {
*
* @param placeholder <p>The placeholder to remove</p>
*/
public void remove(String placeholder) {
public void remove(@NotNull String placeholder) {
this.replacements.remove(placeholder);
}
@ -55,7 +57,7 @@ public final class StringReplacer {
*
* @return <p>The string with placeholders replaced</p>
*/
public String replace() {
public @NotNull String replace() {
if (replacementInput == null) {
throw new IllegalStateException("This method cannot be run without a defined string");
}
@ -68,7 +70,7 @@ public final class StringReplacer {
* @param input <p>The string to replace placeholders in</p>
* @return <p>The string with placeholders replaced</p>
*/
public String replace(String input) {
public @NotNull String replace(@NotNull String input) {
return StringFormatter.replacePlaceholders(input, replacements.keySet().toArray(new String[0]),
replacements.values().toArray(new String[0]));
}

View File

@ -1,5 +1,7 @@
package net.knarcraft.knarlib.formatting;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@ -28,7 +30,7 @@ public final class TimeFormatter {
* @param duration <p>The duration, in seconds, to display</p>
* @return <p>The string used for displaying this sign's duration</p>
*/
public static String getDurationString(Translator translator, long duration) {
public static String getDurationString(@NotNull Translator translator, long duration) {
//Initialize time units once, and only if this method is actually used
if (sortedUnits == null) {
initializeUnits(translator);
@ -76,8 +78,8 @@ public final class TimeFormatter {
* @param castToInt <p>Whether to cast the duration to an int</p>
* @return <p>The formatted duration string</p>
*/
private static String formatDurationString(double duration, Translator translator,
TranslatableMessage translatableMessage, boolean castToInt) {
private static String formatDurationString(double duration, @NotNull Translator translator,
@NotNull TranslatableMessage translatableMessage, boolean castToInt) {
String durationFormat = translator.getTranslatedMessage(TranslatableTimeUnit.DURATION_FORMAT);
durationFormat = replacePlaceholder(durationFormat, "{unit}",
translator.getTranslatedMessage(translatableMessage));
@ -88,7 +90,7 @@ public final class TimeFormatter {
/**
* Initializes the mapping of available time units for formatting permission sign duration
*/
private static void initializeUnits(Translator translator) {
private static void initializeUnits(@NotNull Translator translator) {
//Register each time unit with a registered singular and plural translation
timeUnits = new HashMap<>();
registerTimeUnit(translator, 315360000, TranslatableTimeUnit.UNIT_DECADE, TranslatableTimeUnit.UNIT_DECADES);
@ -102,7 +104,7 @@ public final class TimeFormatter {
TranslatableTimeUnit.UNIT_SECONDS);
//As now and seconds are the base units, those must be registered to use getDurationString
if (!registeredSeconds || !hasTranslation(translator, TranslatableTimeUnit.UNIT_NOW)) {
if (!registeredSeconds || !translator.hasTranslation(TranslatableTimeUnit.UNIT_NOW)) {
throw new IllegalStateException("A translation is missing for UNIT_SECOND, UNIT_SECONDS or UNIT_NOW");
}
@ -121,11 +123,12 @@ public final class TimeFormatter {
* @param plural <p>The translatable time unit to use for the plural form</p>
* @return <p>True if the time unit was registered. False if a translation is missing</p>
*/
private static boolean registerTimeUnit(Translator translator, double seconds, TranslatableTimeUnit singular,
TranslatableTimeUnit plural) {
private static boolean registerTimeUnit(@NotNull Translator translator, double seconds,
@NotNull TranslatableTimeUnit singular,
@NotNull TranslatableTimeUnit plural) {
String singularTranslation = translator.getTranslatedMessage(singular);
String pluralTranslation = translator.getTranslatedMessage(plural);
if (hasTranslation(translator, singular) && hasTranslation(translator, plural)) {
if (translator.hasTranslation(singular) && translator.hasTranslation(plural)) {
timeUnits.put(seconds, new TranslatableTimeUnit[]{singular, plural});
return true;
} else {
@ -133,16 +136,4 @@ public final class TimeFormatter {
}
}
/**
* Checks whether the given translatable message has a registered translation
*
* @param translator <p>The translator to check</p>
* @param translatableMessage <p>The translatable message to check</p>
* @return <p>True if a non-empty translation has been registered</p>
*/
private static boolean hasTranslation(Translator translator, TranslatableMessage translatableMessage) {
String translation = translator.getTranslatedMessage(translatableMessage);
return translation != null && !translation.isBlank();
}
}

View File

@ -1,5 +1,7 @@
package net.knarcraft.knarlib.formatting;
import org.jetbrains.annotations.NotNull;
/**
* A message which can be translated
*/
@ -13,7 +15,7 @@ public interface TranslatableMessage {
*
* @return <p>The name of this translatable message</p>
*/
String name();
@NotNull String name();
/**
* Gets all translatable messages
@ -22,6 +24,6 @@ public interface TranslatableMessage {
*
* @return <p>All translatable messages</p>
*/
TranslatableMessage[] getAllMessages();
@NotNull TranslatableMessage[] getAllMessages();
}

View File

@ -1,5 +1,7 @@
package net.knarcraft.knarlib.formatting;
import org.jetbrains.annotations.NotNull;
/**
* An enum containing all translatable time units
*
@ -101,7 +103,7 @@ public enum TranslatableTimeUnit implements TranslatableMessage {
;
@Override
public TranslatableMessage[] getAllMessages() {
public @NotNull TranslatableMessage[] getAllMessages() {
return TranslatableTimeUnit.values();
}

View File

@ -5,12 +5,12 @@ import net.knarcraft.knarlib.util.ColorHelper;
import net.knarcraft.knarlib.util.FileHelper;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.YamlConfiguration;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -41,7 +41,7 @@ public final class Translator {
*
* @param translatableMessage <p>A translatable message in the category to register</p>
*/
public void registerMessageCategory(TranslatableMessage translatableMessage) {
public void registerMessageCategory(@NotNull TranslatableMessage translatableMessage) {
messageCategories.add(translatableMessage);
}
@ -54,12 +54,8 @@ public final class Translator {
*
* @param colorConversion <p>The color conversion to be used</p>
*/
public void setColorConversion(ColorConversion colorConversion) {
if (colorConversion != null) {
public void setColorConversion(@NotNull ColorConversion colorConversion) {
this.colorConversion = colorConversion;
} else {
throw new IllegalArgumentException("Color conversion cannot be null");
}
}
/**
@ -69,7 +65,8 @@ public final class Translator {
* @param fallbackLanguage <p>The default language to fall back on in the case of missing translations</p>
* @param selectedLanguage <p>The currently selected language</p>
*/
public void loadLanguages(File dataFolder, String fallbackLanguage, String selectedLanguage) {
public void loadLanguages(@NotNull File dataFolder, @NotNull String fallbackLanguage,
@NotNull String selectedLanguage) {
backupTranslatedMessages = loadTranslatedMessages(fallbackLanguage);
translatedMessages = loadCustomTranslatedMessages(dataFolder, selectedLanguage);
if (translatedMessages == null) {
@ -77,13 +74,24 @@ public final class Translator {
}
}
/**
* Checks whether the given translatable message has a translation
*
* @param translatableMessage <p>The translatable message to check</p>
* @return <p>True if the message has a translation</p>
*/
public boolean hasTranslation(@NotNull TranslatableMessage translatableMessage) {
return backupTranslatedMessages.containsKey(translatableMessage) &&
!backupTranslatedMessages.get(translatableMessage).isBlank();
}
/**
* Gets a translated version of the given translatable message
*
* @param translatableMessage <p>The message to translate</p>
* @return <p>The translated message</p>
*/
public String getTranslatedMessage(TranslatableMessage translatableMessage) {
public @NotNull String getTranslatedMessage(@NotNull TranslatableMessage translatableMessage) {
if (translatedMessages == null) {
return "Translated strings not loaded";
}
@ -104,7 +112,7 @@ public final class Translator {
* @param language <p>The language chosen by the user</p>
* @return <p>A mapping of all strings for the given language</p>
*/
public Map<TranslatableMessage, String> loadTranslatedMessages(String language) {
public @Nullable Map<TranslatableMessage, String> loadTranslatedMessages(@NotNull String language) {
try {
BufferedReader reader = FileHelper.getBufferedReaderForInternalFile("/strings.yml");
return loadTranslatableMessages(language, reader);
@ -121,10 +129,8 @@ public final class Translator {
* @param language <p>The selected language</p>
* @return <p>The loaded translated strings, or null if no custom language file exists</p>
*/
public Map<TranslatableMessage, String> loadCustomTranslatedMessages(File dataFolder, String language) {
if (dataFolder == null) {
return null;
}
public @Nullable Map<TranslatableMessage, String> loadCustomTranslatedMessages(@NotNull File dataFolder,
@NotNull String language) {
File strings = new File(dataFolder, "strings.yml");
if (!strings.exists()) {
Bukkit.getLogger().log(Level.FINEST, "Strings file not found");
@ -133,9 +139,9 @@ public final class Translator {
try {
Bukkit.getLogger().log(Level.INFO, "Loading custom strings...");
return loadTranslatableMessages(language, new BufferedReader(new InputStreamReader(
new FileInputStream(strings))));
} catch (FileNotFoundException e) {
return loadTranslatableMessages(language,
FileHelper.getBufferedReaderFromString(strings.toPath().toString()));
} catch (FileNotFoundException exception) {
Bukkit.getLogger().log(Level.WARNING, "Unable to load custom messages");
return null;
}
@ -148,7 +154,8 @@ public final class Translator {
* @param reader <p>The buffered reader to read from</p>
* @return <p>The loaded translated strings</p>
*/
private Map<TranslatableMessage, String> loadTranslatableMessages(String language, BufferedReader reader) {
private @NotNull Map<TranslatableMessage, String> loadTranslatableMessages(@NotNull String language,
@NotNull BufferedReader reader) {
Map<TranslatableMessage, String> translatedMessages = new HashMap<>();
YamlConfiguration configuration = YamlConfiguration.loadConfiguration(reader);

View File

@ -70,8 +70,9 @@ public final class ParticleConfig {
* @param offsetZ <p>The z-offset/spread of the spawned particles</p>
* @param extra <p>Extra data for the particle. Usage depends on the particle type.</p>
*/
public ParticleConfig(ParticleMode particleMode, Particle particleType, int particleAmount, double particleDensity,
double heightOffset, double offsetX, double offsetY, double offsetZ, double extra) {
public ParticleConfig(@NotNull ParticleMode particleMode, @NotNull Particle particleType, int particleAmount,
double particleDensity, double heightOffset, double offsetX, double offsetY, double offsetZ,
double extra) {
this.particleMode = particleMode;
this.particleType = particleType;
this.particleAmount = particleAmount;
@ -88,7 +89,7 @@ public final class ParticleConfig {
*
* @return <p>The particle mode</p>
*/
public ParticleMode getParticleMode() {
public @NotNull ParticleMode getParticleMode() {
return particleMode;
}
@ -97,7 +98,7 @@ public final class ParticleConfig {
*
* @return <p>The particle type</p>
*/
public Particle getParticleType() {
public @NotNull Particle getParticleType() {
return particleType;
}

View File

@ -69,7 +69,7 @@ public final class ParticleSpawner implements Runnable {
*
* @return <p>The id used for stored calculations</p>
*/
public UUID getStoredCalculationId() {
public @NotNull UUID getStoredCalculationId() {
return this.storedCalculationId;
}
@ -131,7 +131,7 @@ public final class ParticleSpawner implements Runnable {
*
* @return <p>The particle config to use</p>
*/
private ParticleConfig getParticleConfig() {
private @NotNull ParticleConfig getParticleConfig() {
ParticleConfig materialConfig = this.materialConfigs.get(processingBlock.getType());
if (materialConfig != null) {
return materialConfig;

View File

@ -85,7 +85,7 @@ public final class ParticleTrailSpawner implements Runnable {
*
* @param playerId <p>The id of the player to remove the trail for</p>
*/
public void removeTrail(UUID playerId) {
public void removeTrail(@NotNull UUID playerId) {
this.playersWithTrails.remove(playerId);
this.playerParticles.remove(playerId);
}
@ -95,7 +95,7 @@ public final class ParticleTrailSpawner implements Runnable {
*
* @param playerId <p>The id of the player to add the trail to</p>
*/
public void startTrail(UUID playerId) {
public void startTrail(@NotNull UUID playerId) {
this.playerParticles.put(playerId, randomParticle());
this.playersWithTrails.add(playerId);
}
@ -105,7 +105,7 @@ public final class ParticleTrailSpawner implements Runnable {
*
* @return <p>A random particle</p>
*/
private Particle randomParticle() {
private @NotNull Particle randomParticle() {
Particle spawnParticle = null;
while (spawnParticle == null || spawnParticle.getDataType() != Void.class) {
spawnParticle = randomTrailTypes.get(random.nextInt(randomTrailTypes.size()));

View File

@ -3,6 +3,7 @@ package net.knarcraft.knarlib.util;
import net.knarcraft.knarlib.property.ColorConversion;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.Color;
import org.jetbrains.annotations.NotNull;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -25,7 +26,7 @@ public final class ColorHelper {
* @param color <p>The color to invert</p>
* @return <p>The inverted color</p>
*/
public static Color invert(Color color) {
public static @NotNull Color invert(@NotNull Color color) {
return color.setRed(255 - color.getRed()).setGreen(255 - color.getGreen()).setBlue(255 - color.getBlue());
}
@ -35,7 +36,7 @@ public final class ColorHelper {
* @param color <p>The color to convert into a chat color</p>
* @return <p>The resulting chat color</p>
*/
public static ChatColor fromColor(Color color) {
public static @NotNull ChatColor fromColor(@NotNull Color color) {
return ChatColor.of(String.format("#%02X%02X%02X", color.getRed(), color.getGreen(), color.getBlue()));
}
@ -58,7 +59,7 @@ public final class ColorHelper {
* @param colorConversion <p>The type of color conversion to apply before stripping</p>
* @return <p>The message without color codes</p>
*/
public static String stripColorCodes(String message, ColorConversion colorConversion) {
public static @NotNull String stripColorCodes(@NotNull String message, @NotNull ColorConversion colorConversion) {
return ChatColor.stripColor(translateColorCodes(message, colorConversion));
}
@ -69,7 +70,7 @@ public final class ColorHelper {
* @param colorConversion <p>The type of color conversion to apply</p>
* @return <p>The string with color codes applied</p>
*/
public static String translateColorCodes(String message, ColorConversion colorConversion) {
public static @NotNull String translateColorCodes(@NotNull String message, @NotNull ColorConversion colorConversion) {
return switch (colorConversion) {
case NONE -> message;
case NORMAL -> ChatColor.translateAlternateColorCodes('&', message);
@ -85,7 +86,7 @@ public final class ColorHelper {
* @param onlyRGB <p>Whether to only convert RGB (hexadecimal) color codes. If false, &[a-f0-9] will be converted as well.</p>
* @return <p>The message with color codes translated</p>
*/
private static String translateAllColorCodes(String message, boolean onlyRGB) {
private static @NotNull String translateAllColorCodes(@NotNull String message, boolean onlyRGB) {
if (!onlyRGB) {
message = ChatColor.translateAlternateColorCodes('&', message);
}

View File

@ -1,6 +1,8 @@
package net.knarcraft.knarlib.util;
import net.knarcraft.knarlib.property.ColorConversion;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.BufferedReader;
import java.io.BufferedWriter;
@ -33,7 +35,7 @@ public final class FileHelper {
* @return <p>A buffered read for reading the file</p>
* @throws FileNotFoundException <p>If unable to get an input stream for the given file</p>
*/
public static BufferedReader getBufferedReaderForInternalFile(String file) throws FileNotFoundException {
public static @NotNull BufferedReader getBufferedReaderForInternalFile(@NotNull String file) throws FileNotFoundException {
InputStream inputStream = getInputStreamForInternalFile(file);
if (inputStream == null) {
throw new FileNotFoundException("Unable to read the given file");
@ -50,7 +52,7 @@ public final class FileHelper {
* @param file <p>The file to read</p>
* @return <p>An input stream for the file</p>
*/
public static InputStream getInputStreamForInternalFile(String file) {
public static @Nullable InputStream getInputStreamForInternalFile(@NotNull String file) {
return FileHelper.class.getResourceAsStream(file);
}
@ -61,7 +63,7 @@ public final class FileHelper {
* @return <p>A buffered reader reading the file</p>
* @throws FileNotFoundException <p>If the given file does not exist</p>
*/
public static BufferedReader getBufferedReaderFromString(String file) throws FileNotFoundException {
public static @NotNull BufferedReader getBufferedReaderFromString(@NotNull String file) throws FileNotFoundException {
FileInputStream fileInputStream = new FileInputStream(file);
return getBufferedReaderFromInputStream(fileInputStream);
}
@ -72,7 +74,7 @@ public final class FileHelper {
* @param inputStream <p>The input stream to read</p>
* @return <p>A buffered reader reading the input stream</p>
*/
public static BufferedReader getBufferedReaderFromInputStream(InputStream inputStream) {
public static @NotNull BufferedReader getBufferedReaderFromInputStream(@NotNull InputStream inputStream) {
InputStreamReader inputStreamReader = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
return new BufferedReader(inputStreamReader);
}
@ -84,7 +86,7 @@ public final class FileHelper {
* @return <p>A buffered writer writing to the file</p>
* @throws FileNotFoundException <p>If the file does not exist</p>
*/
public static BufferedWriter getBufferedWriterFromString(String file) throws FileNotFoundException {
public static @NotNull BufferedWriter getBufferedWriterFromString(@NotNull String file) throws FileNotFoundException {
FileOutputStream fileOutputStream = new FileOutputStream(file);
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fileOutputStream, StandardCharsets.UTF_8);
return new BufferedWriter(outputStreamWriter);
@ -99,8 +101,9 @@ public final class FileHelper {
* @return <p>A map containing the read pairs</p>
* @throws IOException <p>If unable to read from the stream</p>
*/
public static Map<String, String> readKeyValuePairs(BufferedReader bufferedReader, String separator,
ColorConversion colorConversion) throws IOException {
public static Map<String, String> readKeyValuePairs(@NotNull BufferedReader bufferedReader,
@NotNull String separator,
@NotNull ColorConversion colorConversion) throws IOException {
Map<String, String> readPairs = new HashMap<>();
String line = bufferedReader.readLine();
@ -136,7 +139,7 @@ public final class FileHelper {
* @param string <p>The string to remove the BOM from</p>
* @return <p>A string guaranteed without a BOM</p>
*/
private static String removeUTF8BOM(String string) {
private static @NotNull String removeUTF8BOM(@NotNull String string) {
String UTF8_BOM = "\uFEFF";
if (string.startsWith(UTF8_BOM)) {
string = string.substring(1);

View File

@ -229,7 +229,7 @@ public final class ParticleHelper {
* @param block <p>The block to check</p>
* @return <p>The height of the block</p>
*/
public static double getBlockHeight(Block block) {
public static double getBlockHeight(@NotNull Block block) {
double maxY = 0;
for (BoundingBox boundingBox : block.getCollisionShape().getBoundingBoxes()) {
if (boundingBox.getMaxY() > maxY) {

View File

@ -1,5 +1,7 @@
package net.knarcraft.knarlib.util;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
@ -19,7 +21,7 @@ public final class TabCompletionHelper {
* @param typedText <p>The text the player has started typing</p>
* @return <p>The given string values that contain the player's typed text</p>
*/
public static List<String> filterMatchingContains(List<String> values, String typedText) {
public static @NotNull List<String> filterMatchingContains(@NotNull List<String> values, @NotNull String typedText) {
List<String> configValues = new ArrayList<>();
for (String value : values) {
if (value.toLowerCase().contains(typedText.toLowerCase())) {
@ -36,7 +38,7 @@ public final class TabCompletionHelper {
* @param typedText <p>The text the player has started typing</p>
* @return <p>The given string values that start with the player's typed text</p>
*/
public static List<String> filterMatchingStartsWith(List<String> values, String typedText) {
public static @NotNull List<String> filterMatchingStartsWith(@NotNull List<String> values, @NotNull String typedText) {
List<String> configValues = new ArrayList<>();
for (String value : values) {
if (value.toLowerCase().startsWith(typedText.toLowerCase())) {

View File

@ -2,6 +2,8 @@ package net.knarcraft.knarlib.util;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitScheduler;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.BufferedReader;
import java.io.IOException;
@ -33,8 +35,9 @@ public final class UpdateChecker {
* @param getVersionSupplier <p>The supplier used to get the current plugin version</p>
* @param setVersionMethod <p>A method to call with the new version as an argument. Can be used to alert admins about an available update or similar.</p>
*/
public static void checkForUpdate(Plugin plugin, String apiResourceURL, Supplier<String> getVersionSupplier,
Consumer<String> setVersionMethod) {
public static void checkForUpdate(@NotNull Plugin plugin, @NotNull String apiResourceURL,
@NotNull Supplier<String> getVersionSupplier,
@NotNull Consumer<String> setVersionMethod) {
BukkitScheduler scheduler = plugin.getServer().getScheduler();
scheduler.runTaskAsynchronously(plugin, () -> UpdateChecker.queryAPI(plugin, apiResourceURL, getVersionSupplier,
setVersionMethod));
@ -48,8 +51,9 @@ public final class UpdateChecker {
* @param getVersionMethod <p>The supplier used to get the current plugin version</p>
* @param setVersionMethod <p>A method to call with the new version as an argument. Can be used to alert admins about an available update or similar.</p>
*/
private static void queryAPI(Plugin plugin, String APIResourceURL, Supplier<String> getVersionMethod,
Consumer<String> setVersionMethod) {
private static void queryAPI(@NotNull Plugin plugin, @NotNull String APIResourceURL,
@NotNull Supplier<String> getVersionMethod,
@Nullable Consumer<String> setVersionMethod) {
try {
InputStream inputStream = new URL(APIResourceURL).openStream();
BufferedReader reader = FileHelper.getBufferedReaderFromInputStream(inputStream);
@ -77,7 +81,7 @@ public final class UpdateChecker {
* @param oldVersion <p>The old (current) plugin version</p>
* @return <p>The string to display</p>
*/
public static String getUpdateAvailableString(String newVersion, String oldVersion) {
public static @NotNull String getUpdateAvailableString(@NotNull String newVersion, @NotNull String oldVersion) {
return String.format(updateNotice, newVersion, oldVersion);
}
@ -88,7 +92,7 @@ public final class UpdateChecker {
* @param newVersion <p>The new version to check</p>
* @return <p>True if the new version is higher than the old one</p>
*/
public static boolean isVersionHigher(String oldVersion, String newVersion) {
public static boolean isVersionHigher(@NotNull String oldVersion, @NotNull String newVersion) {
oldVersion = removeNonNumericCharacters(oldVersion);
newVersion = removeNonNumericCharacters(newVersion);
String[] oldVersionParts = oldVersion.split("\\.");
@ -110,7 +114,7 @@ public final class UpdateChecker {
* @param versionString <p>The version string to clean</p>
* @return <p>The string with non-numeric characters replaced</p>
*/
private static String removeNonNumericCharacters(String versionString) {
private static @NotNull String removeNonNumericCharacters(@NotNull String versionString) {
return versionString.replaceAll("[^0-9.]", "");
}