diff --git a/src/main/java/net/knarcraft/knarlib/formatting/StringFormatter.java b/src/main/java/net/knarcraft/knarlib/formatting/StringFormatter.java index c9daa01..48a9d32 100644 --- a/src/main/java/net/knarcraft/knarlib/formatting/StringFormatter.java +++ b/src/main/java/net/knarcraft/knarlib/formatting/StringFormatter.java @@ -28,7 +28,7 @@ public final class StringFormatter { * @param pluginName

The name of the using plugin (used for the message prefix)

* @param translator

The translator to use for translating messages

*/ - 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); - return coloredPrefix + " " + ChatColor.RESET + message; - } + String coloredPrefix = ColorHelper.translateColorCodes(namePrefix + this.pluginName + + nameSuffix, this.colorConversion); + return coloredPrefix + " " + ChatColor.RESET + message; } } diff --git a/src/main/java/net/knarcraft/knarlib/formatting/StringReplacer.java b/src/main/java/net/knarcraft/knarlib/formatting/StringReplacer.java index c858bb5..9898e9d 100644 --- a/src/main/java/net/knarcraft/knarlib/formatting/StringReplacer.java +++ b/src/main/java/net/knarcraft/knarlib/formatting/StringReplacer.java @@ -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

The input string to replace placeholders for

*/ - public StringReplacer(String replacementInput) { + public StringReplacer(@NotNull String replacementInput) { this.replacementInput = replacementInput; } @@ -35,7 +37,7 @@ public final class StringReplacer { * @param placeholder

The placeholder to replace

* @param value

The replacement value

*/ - 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

The placeholder to remove

*/ - public void remove(String placeholder) { + public void remove(@NotNull String placeholder) { this.replacements.remove(placeholder); } @@ -55,7 +57,7 @@ public final class StringReplacer { * * @return

The string with placeholders replaced

*/ - 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

The string to replace placeholders in

* @return

The string with placeholders replaced

*/ - 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])); } diff --git a/src/main/java/net/knarcraft/knarlib/formatting/TimeFormatter.java b/src/main/java/net/knarcraft/knarlib/formatting/TimeFormatter.java index 6689db0..237821d 100644 --- a/src/main/java/net/knarcraft/knarlib/formatting/TimeFormatter.java +++ b/src/main/java/net/knarcraft/knarlib/formatting/TimeFormatter.java @@ -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

The duration, in seconds, to display

* @return

The string used for displaying this sign's duration

*/ - 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

Whether to cast the duration to an int

* @return

The formatted duration string

*/ - 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

The translatable time unit to use for the plural form

* @return

True if the time unit was registered. False if a translation is missing

*/ - 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

The translator to check

- * @param translatableMessage

The translatable message to check

- * @return

True if a non-empty translation has been registered

- */ - private static boolean hasTranslation(Translator translator, TranslatableMessage translatableMessage) { - String translation = translator.getTranslatedMessage(translatableMessage); - return translation != null && !translation.isBlank(); - } - } diff --git a/src/main/java/net/knarcraft/knarlib/formatting/TranslatableMessage.java b/src/main/java/net/knarcraft/knarlib/formatting/TranslatableMessage.java index c35a1bc..803f492 100644 --- a/src/main/java/net/knarcraft/knarlib/formatting/TranslatableMessage.java +++ b/src/main/java/net/knarcraft/knarlib/formatting/TranslatableMessage.java @@ -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

The name of this translatable message

*/ - String name(); + @NotNull String name(); /** * Gets all translatable messages @@ -22,6 +24,6 @@ public interface TranslatableMessage { * * @return

All translatable messages

*/ - TranslatableMessage[] getAllMessages(); + @NotNull TranslatableMessage[] getAllMessages(); } diff --git a/src/main/java/net/knarcraft/knarlib/formatting/TranslatableTimeUnit.java b/src/main/java/net/knarcraft/knarlib/formatting/TranslatableTimeUnit.java index 2e4151d..49a9dd8 100644 --- a/src/main/java/net/knarcraft/knarlib/formatting/TranslatableTimeUnit.java +++ b/src/main/java/net/knarcraft/knarlib/formatting/TranslatableTimeUnit.java @@ -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(); } diff --git a/src/main/java/net/knarcraft/knarlib/formatting/Translator.java b/src/main/java/net/knarcraft/knarlib/formatting/Translator.java index 858910d..3d23c08 100644 --- a/src/main/java/net/knarcraft/knarlib/formatting/Translator.java +++ b/src/main/java/net/knarcraft/knarlib/formatting/Translator.java @@ -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

A translatable message in the category to register

*/ - public void registerMessageCategory(TranslatableMessage translatableMessage) { + public void registerMessageCategory(@NotNull TranslatableMessage translatableMessage) { messageCategories.add(translatableMessage); } @@ -54,12 +54,8 @@ public final class Translator { * * @param colorConversion

The color conversion to be used

*/ - public void setColorConversion(ColorConversion colorConversion) { - if (colorConversion != null) { - this.colorConversion = colorConversion; - } else { - throw new IllegalArgumentException("Color conversion cannot be null"); - } + public void setColorConversion(@NotNull ColorConversion colorConversion) { + this.colorConversion = colorConversion; } /** @@ -69,7 +65,8 @@ public final class Translator { * @param fallbackLanguage

The default language to fall back on in the case of missing translations

* @param selectedLanguage

The currently selected language

*/ - 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

The translatable message to check

+ * @return

True if the message has a translation

+ */ + 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

The message to translate

* @return

The translated message

*/ - 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

The language chosen by the user

* @return

A mapping of all strings for the given language

*/ - public Map loadTranslatedMessages(String language) { + public @Nullable Map 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

The selected language

* @return

The loaded translated strings, or null if no custom language file exists

*/ - public Map loadCustomTranslatedMessages(File dataFolder, String language) { - if (dataFolder == null) { - return null; - } + public @Nullable Map 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

The buffered reader to read from

* @return

The loaded translated strings

*/ - private Map loadTranslatableMessages(String language, BufferedReader reader) { + private @NotNull Map loadTranslatableMessages(@NotNull String language, + @NotNull BufferedReader reader) { Map translatedMessages = new HashMap<>(); YamlConfiguration configuration = YamlConfiguration.loadConfiguration(reader); diff --git a/src/main/java/net/knarcraft/knarlib/particle/ParticleConfig.java b/src/main/java/net/knarcraft/knarlib/particle/ParticleConfig.java index 29a1cf3..c522dd2 100644 --- a/src/main/java/net/knarcraft/knarlib/particle/ParticleConfig.java +++ b/src/main/java/net/knarcraft/knarlib/particle/ParticleConfig.java @@ -70,8 +70,9 @@ public final class ParticleConfig { * @param offsetZ

The z-offset/spread of the spawned particles

* @param extra

Extra data for the particle. Usage depends on the particle type.

*/ - 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

The particle mode

*/ - public ParticleMode getParticleMode() { + public @NotNull ParticleMode getParticleMode() { return particleMode; } @@ -97,7 +98,7 @@ public final class ParticleConfig { * * @return

The particle type

*/ - public Particle getParticleType() { + public @NotNull Particle getParticleType() { return particleType; } diff --git a/src/main/java/net/knarcraft/knarlib/particle/ParticleSpawner.java b/src/main/java/net/knarcraft/knarlib/particle/ParticleSpawner.java index 5775df9..8faa133 100644 --- a/src/main/java/net/knarcraft/knarlib/particle/ParticleSpawner.java +++ b/src/main/java/net/knarcraft/knarlib/particle/ParticleSpawner.java @@ -69,7 +69,7 @@ public final class ParticleSpawner implements Runnable { * * @return

The id used for stored calculations

*/ - public UUID getStoredCalculationId() { + public @NotNull UUID getStoredCalculationId() { return this.storedCalculationId; } @@ -131,7 +131,7 @@ public final class ParticleSpawner implements Runnable { * * @return

The particle config to use

*/ - private ParticleConfig getParticleConfig() { + private @NotNull ParticleConfig getParticleConfig() { ParticleConfig materialConfig = this.materialConfigs.get(processingBlock.getType()); if (materialConfig != null) { return materialConfig; diff --git a/src/main/java/net/knarcraft/knarlib/particle/ParticleTrailSpawner.java b/src/main/java/net/knarcraft/knarlib/particle/ParticleTrailSpawner.java index d36eead..19c2275 100644 --- a/src/main/java/net/knarcraft/knarlib/particle/ParticleTrailSpawner.java +++ b/src/main/java/net/knarcraft/knarlib/particle/ParticleTrailSpawner.java @@ -85,7 +85,7 @@ public final class ParticleTrailSpawner implements Runnable { * * @param playerId

The id of the player to remove the trail for

*/ - 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

The id of the player to add the trail to

*/ - 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

A random particle

*/ - private Particle randomParticle() { + private @NotNull Particle randomParticle() { Particle spawnParticle = null; while (spawnParticle == null || spawnParticle.getDataType() != Void.class) { spawnParticle = randomTrailTypes.get(random.nextInt(randomTrailTypes.size())); diff --git a/src/main/java/net/knarcraft/knarlib/util/ColorHelper.java b/src/main/java/net/knarcraft/knarlib/util/ColorHelper.java index 0c8cf7e..f5793bd 100644 --- a/src/main/java/net/knarcraft/knarlib/util/ColorHelper.java +++ b/src/main/java/net/knarcraft/knarlib/util/ColorHelper.java @@ -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

The color to invert

* @return

The inverted color

*/ - 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

The color to convert into a chat color

* @return

The resulting chat color

*/ - 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

The type of color conversion to apply before stripping

* @return

The message without color codes

*/ - 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

The type of color conversion to apply

* @return

The string with color codes applied

*/ - 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

Whether to only convert RGB (hexadecimal) color codes. If false, &[a-f0-9] will be converted as well.

* @return

The message with color codes translated

*/ - private static String translateAllColorCodes(String message, boolean onlyRGB) { + private static @NotNull String translateAllColorCodes(@NotNull String message, boolean onlyRGB) { if (!onlyRGB) { message = ChatColor.translateAlternateColorCodes('&', message); } diff --git a/src/main/java/net/knarcraft/knarlib/util/FileHelper.java b/src/main/java/net/knarcraft/knarlib/util/FileHelper.java index 89556d8..481eed2 100644 --- a/src/main/java/net/knarcraft/knarlib/util/FileHelper.java +++ b/src/main/java/net/knarcraft/knarlib/util/FileHelper.java @@ -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

A buffered read for reading the file

* @throws FileNotFoundException

If unable to get an input stream for the given file

*/ - 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

The file to read

* @return

An input stream for the file

*/ - 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

A buffered reader reading the file

* @throws FileNotFoundException

If the given file does not exist

*/ - 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

The input stream to read

* @return

A buffered reader reading the input stream

*/ - 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

A buffered writer writing to the file

* @throws FileNotFoundException

If the file does not exist

*/ - 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

A map containing the read pairs

* @throws IOException

If unable to read from the stream

*/ - public static Map readKeyValuePairs(BufferedReader bufferedReader, String separator, - ColorConversion colorConversion) throws IOException { + public static Map readKeyValuePairs(@NotNull BufferedReader bufferedReader, + @NotNull String separator, + @NotNull ColorConversion colorConversion) throws IOException { Map readPairs = new HashMap<>(); String line = bufferedReader.readLine(); @@ -136,7 +139,7 @@ public final class FileHelper { * @param string

The string to remove the BOM from

* @return

A string guaranteed without a BOM

*/ - 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); diff --git a/src/main/java/net/knarcraft/knarlib/util/ParticleHelper.java b/src/main/java/net/knarcraft/knarlib/util/ParticleHelper.java index 0ad6dc6..3763060 100644 --- a/src/main/java/net/knarcraft/knarlib/util/ParticleHelper.java +++ b/src/main/java/net/knarcraft/knarlib/util/ParticleHelper.java @@ -229,7 +229,7 @@ public final class ParticleHelper { * @param block

The block to check

* @return

The height of the block

*/ - 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) { diff --git a/src/main/java/net/knarcraft/knarlib/util/TabCompletionHelper.java b/src/main/java/net/knarcraft/knarlib/util/TabCompletionHelper.java index 69b3988..795910d 100644 --- a/src/main/java/net/knarcraft/knarlib/util/TabCompletionHelper.java +++ b/src/main/java/net/knarcraft/knarlib/util/TabCompletionHelper.java @@ -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

The text the player has started typing

* @return

The given string values that contain the player's typed text

*/ - public static List filterMatchingContains(List values, String typedText) { + public static @NotNull List filterMatchingContains(@NotNull List values, @NotNull String typedText) { List configValues = new ArrayList<>(); for (String value : values) { if (value.toLowerCase().contains(typedText.toLowerCase())) { @@ -36,7 +38,7 @@ public final class TabCompletionHelper { * @param typedText

The text the player has started typing

* @return

The given string values that start with the player's typed text

*/ - public static List filterMatchingStartsWith(List values, String typedText) { + public static @NotNull List filterMatchingStartsWith(@NotNull List values, @NotNull String typedText) { List configValues = new ArrayList<>(); for (String value : values) { if (value.toLowerCase().startsWith(typedText.toLowerCase())) { diff --git a/src/main/java/net/knarcraft/knarlib/util/UpdateChecker.java b/src/main/java/net/knarcraft/knarlib/util/UpdateChecker.java index edc1698..8bf43e7 100644 --- a/src/main/java/net/knarcraft/knarlib/util/UpdateChecker.java +++ b/src/main/java/net/knarcraft/knarlib/util/UpdateChecker.java @@ -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

The supplier used to get the current plugin version

* @param setVersionMethod

A method to call with the new version as an argument. Can be used to alert admins about an available update or similar.

*/ - public static void checkForUpdate(Plugin plugin, String apiResourceURL, Supplier getVersionSupplier, - Consumer setVersionMethod) { + public static void checkForUpdate(@NotNull Plugin plugin, @NotNull String apiResourceURL, + @NotNull Supplier getVersionSupplier, + @NotNull Consumer 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

The supplier used to get the current plugin version

* @param setVersionMethod

A method to call with the new version as an argument. Can be used to alert admins about an available update or similar.

*/ - private static void queryAPI(Plugin plugin, String APIResourceURL, Supplier getVersionMethod, - Consumer setVersionMethod) { + private static void queryAPI(@NotNull Plugin plugin, @NotNull String APIResourceURL, + @NotNull Supplier getVersionMethod, + @Nullable Consumer setVersionMethod) { try { InputStream inputStream = new URL(APIResourceURL).openStream(); BufferedReader reader = FileHelper.getBufferedReaderFromInputStream(inputStream); @@ -77,7 +81,7 @@ public final class UpdateChecker { * @param oldVersion

The old (current) plugin version

* @return

The string to display

*/ - 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

The new version to check

* @return

True if the new version is higher than the old one

*/ - 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

The version string to clean

* @return

The string with non-numeric characters replaced

*/ - private static String removeNonNumericCharacters(String versionString) { + private static @NotNull String removeNonNumericCharacters(@NotNull String versionString) { return versionString.replaceAll("[^0-9.]", ""); }