Adds missing @NotNull annotations
All checks were successful
EpicKnarvik97/KnarLib/pipeline/head This commit looks good
All checks were successful
EpicKnarvik97/KnarLib/pipeline/head This commit looks good
This commit is contained in:
parent
2c8182e552
commit
94d74e7794
@ -28,7 +28,7 @@ public final class StringFormatter {
|
|||||||
* @param pluginName <p>The name of the using plugin (used for the message prefix)</p>
|
* @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>
|
* @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.pluginName = pluginName;
|
||||||
this.translator = translator;
|
this.translator = translator;
|
||||||
}
|
}
|
||||||
@ -201,13 +201,9 @@ public final class StringFormatter {
|
|||||||
*/
|
*/
|
||||||
private String getFormattedMessage(@NotNull String message) {
|
private String getFormattedMessage(@NotNull String message) {
|
||||||
message = ColorHelper.translateColorCodes(message, this.colorConversion);
|
message = ColorHelper.translateColorCodes(message, this.colorConversion);
|
||||||
if (this.pluginName == null) {
|
String coloredPrefix = ColorHelper.translateColorCodes(namePrefix + this.pluginName +
|
||||||
return message;
|
nameSuffix, this.colorConversion);
|
||||||
} else {
|
return coloredPrefix + " " + ChatColor.RESET + message;
|
||||||
String coloredPrefix = ColorHelper.translateColorCodes(namePrefix + ChatColor.RESET +
|
|
||||||
this.pluginName + ChatColor.RESET + nameSuffix, this.colorConversion);
|
|
||||||
return coloredPrefix + " " + ChatColor.RESET + message;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package net.knarcraft.knarlib.formatting;
|
package net.knarcraft.knarlib.formatting;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -25,7 +27,7 @@ public final class StringReplacer {
|
|||||||
*
|
*
|
||||||
* @param replacementInput <p>The input string to replace placeholders for</p>
|
* @param replacementInput <p>The input string to replace placeholders for</p>
|
||||||
*/
|
*/
|
||||||
public StringReplacer(String replacementInput) {
|
public StringReplacer(@NotNull String replacementInput) {
|
||||||
this.replacementInput = replacementInput;
|
this.replacementInput = replacementInput;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,7 +37,7 @@ public final class StringReplacer {
|
|||||||
* @param placeholder <p>The placeholder to replace</p>
|
* @param placeholder <p>The placeholder to replace</p>
|
||||||
* @param value <p>The replacement value</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);
|
this.replacements.put(placeholder, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,7 +46,7 @@ public final class StringReplacer {
|
|||||||
*
|
*
|
||||||
* @param placeholder <p>The placeholder to remove</p>
|
* @param placeholder <p>The placeholder to remove</p>
|
||||||
*/
|
*/
|
||||||
public void remove(String placeholder) {
|
public void remove(@NotNull String placeholder) {
|
||||||
this.replacements.remove(placeholder);
|
this.replacements.remove(placeholder);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,7 +57,7 @@ public final class StringReplacer {
|
|||||||
*
|
*
|
||||||
* @return <p>The string with placeholders replaced</p>
|
* @return <p>The string with placeholders replaced</p>
|
||||||
*/
|
*/
|
||||||
public String replace() {
|
public @NotNull String replace() {
|
||||||
if (replacementInput == null) {
|
if (replacementInput == null) {
|
||||||
throw new IllegalStateException("This method cannot be run without a defined string");
|
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>
|
* @param input <p>The string to replace placeholders in</p>
|
||||||
* @return <p>The string with placeholders replaced</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]),
|
return StringFormatter.replacePlaceholders(input, replacements.keySet().toArray(new String[0]),
|
||||||
replacements.values().toArray(new String[0]));
|
replacements.values().toArray(new String[0]));
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package net.knarcraft.knarlib.formatting;
|
package net.knarcraft.knarlib.formatting;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -28,7 +30,7 @@ public final class TimeFormatter {
|
|||||||
* @param duration <p>The duration, in seconds, to display</p>
|
* @param duration <p>The duration, in seconds, to display</p>
|
||||||
* @return <p>The string used for displaying this sign's duration</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
|
//Initialize time units once, and only if this method is actually used
|
||||||
if (sortedUnits == null) {
|
if (sortedUnits == null) {
|
||||||
initializeUnits(translator);
|
initializeUnits(translator);
|
||||||
@ -76,8 +78,8 @@ public final class TimeFormatter {
|
|||||||
* @param castToInt <p>Whether to cast the duration to an int</p>
|
* @param castToInt <p>Whether to cast the duration to an int</p>
|
||||||
* @return <p>The formatted duration string</p>
|
* @return <p>The formatted duration string</p>
|
||||||
*/
|
*/
|
||||||
private static String formatDurationString(double duration, Translator translator,
|
private static String formatDurationString(double duration, @NotNull Translator translator,
|
||||||
TranslatableMessage translatableMessage, boolean castToInt) {
|
@NotNull TranslatableMessage translatableMessage, boolean castToInt) {
|
||||||
String durationFormat = translator.getTranslatedMessage(TranslatableTimeUnit.DURATION_FORMAT);
|
String durationFormat = translator.getTranslatedMessage(TranslatableTimeUnit.DURATION_FORMAT);
|
||||||
durationFormat = replacePlaceholder(durationFormat, "{unit}",
|
durationFormat = replacePlaceholder(durationFormat, "{unit}",
|
||||||
translator.getTranslatedMessage(translatableMessage));
|
translator.getTranslatedMessage(translatableMessage));
|
||||||
@ -88,7 +90,7 @@ public final class TimeFormatter {
|
|||||||
/**
|
/**
|
||||||
* Initializes the mapping of available time units for formatting permission sign duration
|
* 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
|
//Register each time unit with a registered singular and plural translation
|
||||||
timeUnits = new HashMap<>();
|
timeUnits = new HashMap<>();
|
||||||
registerTimeUnit(translator, 315360000, TranslatableTimeUnit.UNIT_DECADE, TranslatableTimeUnit.UNIT_DECADES);
|
registerTimeUnit(translator, 315360000, TranslatableTimeUnit.UNIT_DECADE, TranslatableTimeUnit.UNIT_DECADES);
|
||||||
@ -102,7 +104,7 @@ public final class TimeFormatter {
|
|||||||
TranslatableTimeUnit.UNIT_SECONDS);
|
TranslatableTimeUnit.UNIT_SECONDS);
|
||||||
|
|
||||||
//As now and seconds are the base units, those must be registered to use getDurationString
|
//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");
|
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>
|
* @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>
|
* @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,
|
private static boolean registerTimeUnit(@NotNull Translator translator, double seconds,
|
||||||
TranslatableTimeUnit plural) {
|
@NotNull TranslatableTimeUnit singular,
|
||||||
|
@NotNull TranslatableTimeUnit plural) {
|
||||||
String singularTranslation = translator.getTranslatedMessage(singular);
|
String singularTranslation = translator.getTranslatedMessage(singular);
|
||||||
String pluralTranslation = translator.getTranslatedMessage(plural);
|
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});
|
timeUnits.put(seconds, new TranslatableTimeUnit[]{singular, plural});
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} 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();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package net.knarcraft.knarlib.formatting;
|
package net.knarcraft.knarlib.formatting;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A message which can be translated
|
* A message which can be translated
|
||||||
*/
|
*/
|
||||||
@ -13,7 +15,7 @@ public interface TranslatableMessage {
|
|||||||
*
|
*
|
||||||
* @return <p>The name of this translatable message</p>
|
* @return <p>The name of this translatable message</p>
|
||||||
*/
|
*/
|
||||||
String name();
|
@NotNull String name();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets all translatable messages
|
* Gets all translatable messages
|
||||||
@ -22,6 +24,6 @@ public interface TranslatableMessage {
|
|||||||
*
|
*
|
||||||
* @return <p>All translatable messages</p>
|
* @return <p>All translatable messages</p>
|
||||||
*/
|
*/
|
||||||
TranslatableMessage[] getAllMessages();
|
@NotNull TranslatableMessage[] getAllMessages();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package net.knarcraft.knarlib.formatting;
|
package net.knarcraft.knarlib.formatting;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An enum containing all translatable time units
|
* An enum containing all translatable time units
|
||||||
*
|
*
|
||||||
@ -101,7 +103,7 @@ public enum TranslatableTimeUnit implements TranslatableMessage {
|
|||||||
;
|
;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TranslatableMessage[] getAllMessages() {
|
public @NotNull TranslatableMessage[] getAllMessages() {
|
||||||
return TranslatableTimeUnit.values();
|
return TranslatableTimeUnit.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,12 +5,12 @@ import net.knarcraft.knarlib.util.ColorHelper;
|
|||||||
import net.knarcraft.knarlib.util.FileHelper;
|
import net.knarcraft.knarlib.util.FileHelper;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -41,7 +41,7 @@ public final class Translator {
|
|||||||
*
|
*
|
||||||
* @param translatableMessage <p>A translatable message in the category to register</p>
|
* @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);
|
messageCategories.add(translatableMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,12 +54,8 @@ public final class Translator {
|
|||||||
*
|
*
|
||||||
* @param colorConversion <p>The color conversion to be used</p>
|
* @param colorConversion <p>The color conversion to be used</p>
|
||||||
*/
|
*/
|
||||||
public void setColorConversion(ColorConversion colorConversion) {
|
public void setColorConversion(@NotNull ColorConversion colorConversion) {
|
||||||
if (colorConversion != null) {
|
this.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 fallbackLanguage <p>The default language to fall back on in the case of missing translations</p>
|
||||||
* @param selectedLanguage <p>The currently selected language</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);
|
backupTranslatedMessages = loadTranslatedMessages(fallbackLanguage);
|
||||||
translatedMessages = loadCustomTranslatedMessages(dataFolder, selectedLanguage);
|
translatedMessages = loadCustomTranslatedMessages(dataFolder, selectedLanguage);
|
||||||
if (translatedMessages == null) {
|
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
|
* Gets a translated version of the given translatable message
|
||||||
*
|
*
|
||||||
* @param translatableMessage <p>The message to translate</p>
|
* @param translatableMessage <p>The message to translate</p>
|
||||||
* @return <p>The translated message</p>
|
* @return <p>The translated message</p>
|
||||||
*/
|
*/
|
||||||
public String getTranslatedMessage(TranslatableMessage translatableMessage) {
|
public @NotNull String getTranslatedMessage(@NotNull TranslatableMessage translatableMessage) {
|
||||||
if (translatedMessages == null) {
|
if (translatedMessages == null) {
|
||||||
return "Translated strings not loaded";
|
return "Translated strings not loaded";
|
||||||
}
|
}
|
||||||
@ -104,7 +112,7 @@ public final class Translator {
|
|||||||
* @param language <p>The language chosen by the user</p>
|
* @param language <p>The language chosen by the user</p>
|
||||||
* @return <p>A mapping of all strings for the given language</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 {
|
try {
|
||||||
BufferedReader reader = FileHelper.getBufferedReaderForInternalFile("/strings.yml");
|
BufferedReader reader = FileHelper.getBufferedReaderForInternalFile("/strings.yml");
|
||||||
return loadTranslatableMessages(language, reader);
|
return loadTranslatableMessages(language, reader);
|
||||||
@ -121,10 +129,8 @@ public final class Translator {
|
|||||||
* @param language <p>The selected language</p>
|
* @param language <p>The selected language</p>
|
||||||
* @return <p>The loaded translated strings, or null if no custom language file exists</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) {
|
public @Nullable Map<TranslatableMessage, String> loadCustomTranslatedMessages(@NotNull File dataFolder,
|
||||||
if (dataFolder == null) {
|
@NotNull String language) {
|
||||||
return null;
|
|
||||||
}
|
|
||||||
File strings = new File(dataFolder, "strings.yml");
|
File strings = new File(dataFolder, "strings.yml");
|
||||||
if (!strings.exists()) {
|
if (!strings.exists()) {
|
||||||
Bukkit.getLogger().log(Level.FINEST, "Strings file not found");
|
Bukkit.getLogger().log(Level.FINEST, "Strings file not found");
|
||||||
@ -133,9 +139,9 @@ public final class Translator {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
Bukkit.getLogger().log(Level.INFO, "Loading custom strings...");
|
Bukkit.getLogger().log(Level.INFO, "Loading custom strings...");
|
||||||
return loadTranslatableMessages(language, new BufferedReader(new InputStreamReader(
|
return loadTranslatableMessages(language,
|
||||||
new FileInputStream(strings))));
|
FileHelper.getBufferedReaderFromString(strings.toPath().toString()));
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException exception) {
|
||||||
Bukkit.getLogger().log(Level.WARNING, "Unable to load custom messages");
|
Bukkit.getLogger().log(Level.WARNING, "Unable to load custom messages");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -148,7 +154,8 @@ public final class Translator {
|
|||||||
* @param reader <p>The buffered reader to read from</p>
|
* @param reader <p>The buffered reader to read from</p>
|
||||||
* @return <p>The loaded translated strings</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<>();
|
Map<TranslatableMessage, String> translatedMessages = new HashMap<>();
|
||||||
YamlConfiguration configuration = YamlConfiguration.loadConfiguration(reader);
|
YamlConfiguration configuration = YamlConfiguration.loadConfiguration(reader);
|
||||||
|
|
||||||
|
@ -70,8 +70,9 @@ public final class ParticleConfig {
|
|||||||
* @param offsetZ <p>The z-offset/spread of the spawned particles</p>
|
* @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>
|
* @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,
|
public ParticleConfig(@NotNull ParticleMode particleMode, @NotNull Particle particleType, int particleAmount,
|
||||||
double heightOffset, double offsetX, double offsetY, double offsetZ, double extra) {
|
double particleDensity, double heightOffset, double offsetX, double offsetY, double offsetZ,
|
||||||
|
double extra) {
|
||||||
this.particleMode = particleMode;
|
this.particleMode = particleMode;
|
||||||
this.particleType = particleType;
|
this.particleType = particleType;
|
||||||
this.particleAmount = particleAmount;
|
this.particleAmount = particleAmount;
|
||||||
@ -88,7 +89,7 @@ public final class ParticleConfig {
|
|||||||
*
|
*
|
||||||
* @return <p>The particle mode</p>
|
* @return <p>The particle mode</p>
|
||||||
*/
|
*/
|
||||||
public ParticleMode getParticleMode() {
|
public @NotNull ParticleMode getParticleMode() {
|
||||||
return particleMode;
|
return particleMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,7 +98,7 @@ public final class ParticleConfig {
|
|||||||
*
|
*
|
||||||
* @return <p>The particle type</p>
|
* @return <p>The particle type</p>
|
||||||
*/
|
*/
|
||||||
public Particle getParticleType() {
|
public @NotNull Particle getParticleType() {
|
||||||
return particleType;
|
return particleType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ public final class ParticleSpawner implements Runnable {
|
|||||||
*
|
*
|
||||||
* @return <p>The id used for stored calculations</p>
|
* @return <p>The id used for stored calculations</p>
|
||||||
*/
|
*/
|
||||||
public UUID getStoredCalculationId() {
|
public @NotNull UUID getStoredCalculationId() {
|
||||||
return this.storedCalculationId;
|
return this.storedCalculationId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,7 +131,7 @@ public final class ParticleSpawner implements Runnable {
|
|||||||
*
|
*
|
||||||
* @return <p>The particle config to use</p>
|
* @return <p>The particle config to use</p>
|
||||||
*/
|
*/
|
||||||
private ParticleConfig getParticleConfig() {
|
private @NotNull ParticleConfig getParticleConfig() {
|
||||||
ParticleConfig materialConfig = this.materialConfigs.get(processingBlock.getType());
|
ParticleConfig materialConfig = this.materialConfigs.get(processingBlock.getType());
|
||||||
if (materialConfig != null) {
|
if (materialConfig != null) {
|
||||||
return materialConfig;
|
return materialConfig;
|
||||||
|
@ -85,7 +85,7 @@ public final class ParticleTrailSpawner implements Runnable {
|
|||||||
*
|
*
|
||||||
* @param playerId <p>The id of the player to remove the trail for</p>
|
* @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.playersWithTrails.remove(playerId);
|
||||||
this.playerParticles.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>
|
* @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.playerParticles.put(playerId, randomParticle());
|
||||||
this.playersWithTrails.add(playerId);
|
this.playersWithTrails.add(playerId);
|
||||||
}
|
}
|
||||||
@ -105,7 +105,7 @@ public final class ParticleTrailSpawner implements Runnable {
|
|||||||
*
|
*
|
||||||
* @return <p>A random particle</p>
|
* @return <p>A random particle</p>
|
||||||
*/
|
*/
|
||||||
private Particle randomParticle() {
|
private @NotNull Particle randomParticle() {
|
||||||
Particle spawnParticle = null;
|
Particle spawnParticle = null;
|
||||||
while (spawnParticle == null || spawnParticle.getDataType() != Void.class) {
|
while (spawnParticle == null || spawnParticle.getDataType() != Void.class) {
|
||||||
spawnParticle = randomTrailTypes.get(random.nextInt(randomTrailTypes.size()));
|
spawnParticle = randomTrailTypes.get(random.nextInt(randomTrailTypes.size()));
|
||||||
|
@ -3,6 +3,7 @@ package net.knarcraft.knarlib.util;
|
|||||||
import net.knarcraft.knarlib.property.ColorConversion;
|
import net.knarcraft.knarlib.property.ColorConversion;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
import org.bukkit.Color;
|
import org.bukkit.Color;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
@ -25,7 +26,7 @@ public final class ColorHelper {
|
|||||||
* @param color <p>The color to invert</p>
|
* @param color <p>The color to invert</p>
|
||||||
* @return <p>The inverted color</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());
|
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>
|
* @param color <p>The color to convert into a chat color</p>
|
||||||
* @return <p>The resulting 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()));
|
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>
|
* @param colorConversion <p>The type of color conversion to apply before stripping</p>
|
||||||
* @return <p>The message without color codes</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));
|
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>
|
* @param colorConversion <p>The type of color conversion to apply</p>
|
||||||
* @return <p>The string with color codes applied</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) {
|
return switch (colorConversion) {
|
||||||
case NONE -> message;
|
case NONE -> message;
|
||||||
case NORMAL -> ChatColor.translateAlternateColorCodes('&', 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>
|
* @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>
|
* @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) {
|
if (!onlyRGB) {
|
||||||
message = ChatColor.translateAlternateColorCodes('&', message);
|
message = ChatColor.translateAlternateColorCodes('&', message);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package net.knarcraft.knarlib.util;
|
package net.knarcraft.knarlib.util;
|
||||||
|
|
||||||
import net.knarcraft.knarlib.property.ColorConversion;
|
import net.knarcraft.knarlib.property.ColorConversion;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
@ -33,7 +35,7 @@ public final class FileHelper {
|
|||||||
* @return <p>A buffered read for reading the file</p>
|
* @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>
|
* @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);
|
InputStream inputStream = getInputStreamForInternalFile(file);
|
||||||
if (inputStream == null) {
|
if (inputStream == null) {
|
||||||
throw new FileNotFoundException("Unable to read the given file");
|
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>
|
* @param file <p>The file to read</p>
|
||||||
* @return <p>An input stream for the file</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);
|
return FileHelper.class.getResourceAsStream(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,7 +63,7 @@ public final class FileHelper {
|
|||||||
* @return <p>A buffered reader reading the file</p>
|
* @return <p>A buffered reader reading the file</p>
|
||||||
* @throws FileNotFoundException <p>If the given file does not exist</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);
|
FileInputStream fileInputStream = new FileInputStream(file);
|
||||||
return getBufferedReaderFromInputStream(fileInputStream);
|
return getBufferedReaderFromInputStream(fileInputStream);
|
||||||
}
|
}
|
||||||
@ -72,7 +74,7 @@ public final class FileHelper {
|
|||||||
* @param inputStream <p>The input stream to read</p>
|
* @param inputStream <p>The input stream to read</p>
|
||||||
* @return <p>A buffered reader reading the input stream</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);
|
InputStreamReader inputStreamReader = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
|
||||||
return new BufferedReader(inputStreamReader);
|
return new BufferedReader(inputStreamReader);
|
||||||
}
|
}
|
||||||
@ -84,7 +86,7 @@ public final class FileHelper {
|
|||||||
* @return <p>A buffered writer writing to the file</p>
|
* @return <p>A buffered writer writing to the file</p>
|
||||||
* @throws FileNotFoundException <p>If the file does not exist</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);
|
FileOutputStream fileOutputStream = new FileOutputStream(file);
|
||||||
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fileOutputStream, StandardCharsets.UTF_8);
|
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fileOutputStream, StandardCharsets.UTF_8);
|
||||||
return new BufferedWriter(outputStreamWriter);
|
return new BufferedWriter(outputStreamWriter);
|
||||||
@ -99,8 +101,9 @@ public final class FileHelper {
|
|||||||
* @return <p>A map containing the read pairs</p>
|
* @return <p>A map containing the read pairs</p>
|
||||||
* @throws IOException <p>If unable to read from the stream</p>
|
* @throws IOException <p>If unable to read from the stream</p>
|
||||||
*/
|
*/
|
||||||
public static Map<String, String> readKeyValuePairs(BufferedReader bufferedReader, String separator,
|
public static Map<String, String> readKeyValuePairs(@NotNull BufferedReader bufferedReader,
|
||||||
ColorConversion colorConversion) throws IOException {
|
@NotNull String separator,
|
||||||
|
@NotNull ColorConversion colorConversion) throws IOException {
|
||||||
Map<String, String> readPairs = new HashMap<>();
|
Map<String, String> readPairs = new HashMap<>();
|
||||||
|
|
||||||
String line = bufferedReader.readLine();
|
String line = bufferedReader.readLine();
|
||||||
@ -136,7 +139,7 @@ public final class FileHelper {
|
|||||||
* @param string <p>The string to remove the BOM from</p>
|
* @param string <p>The string to remove the BOM from</p>
|
||||||
* @return <p>A string guaranteed without a BOM</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";
|
String UTF8_BOM = "\uFEFF";
|
||||||
if (string.startsWith(UTF8_BOM)) {
|
if (string.startsWith(UTF8_BOM)) {
|
||||||
string = string.substring(1);
|
string = string.substring(1);
|
||||||
|
@ -229,7 +229,7 @@ public final class ParticleHelper {
|
|||||||
* @param block <p>The block to check</p>
|
* @param block <p>The block to check</p>
|
||||||
* @return <p>The height of the block</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;
|
double maxY = 0;
|
||||||
for (BoundingBox boundingBox : block.getCollisionShape().getBoundingBoxes()) {
|
for (BoundingBox boundingBox : block.getCollisionShape().getBoundingBoxes()) {
|
||||||
if (boundingBox.getMaxY() > maxY) {
|
if (boundingBox.getMaxY() > maxY) {
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package net.knarcraft.knarlib.util;
|
package net.knarcraft.knarlib.util;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -19,7 +21,7 @@ public final class TabCompletionHelper {
|
|||||||
* @param typedText <p>The text the player has started typing</p>
|
* @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>
|
* @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<>();
|
List<String> configValues = new ArrayList<>();
|
||||||
for (String value : values) {
|
for (String value : values) {
|
||||||
if (value.toLowerCase().contains(typedText.toLowerCase())) {
|
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>
|
* @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>
|
* @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<>();
|
List<String> configValues = new ArrayList<>();
|
||||||
for (String value : values) {
|
for (String value : values) {
|
||||||
if (value.toLowerCase().startsWith(typedText.toLowerCase())) {
|
if (value.toLowerCase().startsWith(typedText.toLowerCase())) {
|
||||||
|
@ -2,6 +2,8 @@ package net.knarcraft.knarlib.util;
|
|||||||
|
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.scheduler.BukkitScheduler;
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
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 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>
|
* @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,
|
public static void checkForUpdate(@NotNull Plugin plugin, @NotNull String apiResourceURL,
|
||||||
Consumer<String> setVersionMethod) {
|
@NotNull Supplier<String> getVersionSupplier,
|
||||||
|
@NotNull Consumer<String> setVersionMethod) {
|
||||||
BukkitScheduler scheduler = plugin.getServer().getScheduler();
|
BukkitScheduler scheduler = plugin.getServer().getScheduler();
|
||||||
scheduler.runTaskAsynchronously(plugin, () -> UpdateChecker.queryAPI(plugin, apiResourceURL, getVersionSupplier,
|
scheduler.runTaskAsynchronously(plugin, () -> UpdateChecker.queryAPI(plugin, apiResourceURL, getVersionSupplier,
|
||||||
setVersionMethod));
|
setVersionMethod));
|
||||||
@ -48,8 +51,9 @@ public final class UpdateChecker {
|
|||||||
* @param getVersionMethod <p>The supplier used to get the current plugin version</p>
|
* @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>
|
* @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,
|
private static void queryAPI(@NotNull Plugin plugin, @NotNull String APIResourceURL,
|
||||||
Consumer<String> setVersionMethod) {
|
@NotNull Supplier<String> getVersionMethod,
|
||||||
|
@Nullable Consumer<String> setVersionMethod) {
|
||||||
try {
|
try {
|
||||||
InputStream inputStream = new URL(APIResourceURL).openStream();
|
InputStream inputStream = new URL(APIResourceURL).openStream();
|
||||||
BufferedReader reader = FileHelper.getBufferedReaderFromInputStream(inputStream);
|
BufferedReader reader = FileHelper.getBufferedReaderFromInputStream(inputStream);
|
||||||
@ -77,7 +81,7 @@ public final class UpdateChecker {
|
|||||||
* @param oldVersion <p>The old (current) plugin version</p>
|
* @param oldVersion <p>The old (current) plugin version</p>
|
||||||
* @return <p>The string to display</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);
|
return String.format(updateNotice, newVersion, oldVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,7 +92,7 @@ public final class UpdateChecker {
|
|||||||
* @param newVersion <p>The new version to check</p>
|
* @param newVersion <p>The new version to check</p>
|
||||||
* @return <p>True if the new version is higher than the old one</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);
|
oldVersion = removeNonNumericCharacters(oldVersion);
|
||||||
newVersion = removeNonNumericCharacters(newVersion);
|
newVersion = removeNonNumericCharacters(newVersion);
|
||||||
String[] oldVersionParts = oldVersion.split("\\.");
|
String[] oldVersionParts = oldVersion.split("\\.");
|
||||||
@ -110,7 +114,7 @@ public final class UpdateChecker {
|
|||||||
* @param versionString <p>The version string to clean</p>
|
* @param versionString <p>The version string to clean</p>
|
||||||
* @return <p>The string with non-numeric characters replaced</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.]", "");
|
return versionString.replaceAll("[^0-9.]", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user