Adds nullability annotations among other things

Adds nullability annotations for all methods
Fixes some nullability problems and inconsistencies
Gets rid of RelativeBlockVector's inner class
Changes RelativeBlockVector to a record
Simplifies FromTheEndTeleportation's storage, and makes it into a minimal record
Removes the putStringInList method
Gets rid of some primitive list usage
Fixes some incorrect method accessibility
Removes some redundancy in PortalOption
This commit is contained in:
2024-02-20 12:43:01 +01:00
parent 894a692e7b
commit b4a6ce1a77
78 changed files with 1025 additions and 639 deletions

View File

@@ -1,5 +1,8 @@
package net.knarcraft.stargate.config;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* A ConfigOption represents one of the available config options
*/
@@ -209,7 +212,7 @@ public enum ConfigOption {
* @param description <p>The description of what this config option does</p>
* @param defaultValue <p>The default value of this config option</p>
*/
ConfigOption(String configNode, String description, Object defaultValue) {
ConfigOption(@NotNull String configNode, @NotNull String description, @NotNull Object defaultValue) {
this.configNode = configNode;
this.description = description;
this.defaultValue = defaultValue;
@@ -235,7 +238,7 @@ public enum ConfigOption {
* @param name <p>The name of the config option to get</p>
* @return <p>The corresponding config option, or null if the name is invalid</p>
*/
public static ConfigOption getByName(String name) {
public static @Nullable ConfigOption getByName(@NotNull String name) {
for (ConfigOption option : ConfigOption.values()) {
if (option.getName().equalsIgnoreCase(name)) {
return option;
@@ -249,7 +252,7 @@ public enum ConfigOption {
*
* @return <p>The name of this config option</p>
*/
public String getName() {
public @NotNull String getName() {
if (!this.configNode.contains(".")) {
return this.configNode;
}
@@ -262,7 +265,7 @@ public enum ConfigOption {
*
* @return <p>The data type used</p>
*/
public OptionDataType getDataType() {
public @NotNull OptionDataType getDataType() {
return this.dataType;
}
@@ -271,7 +274,7 @@ public enum ConfigOption {
*
* @return <p>This config option's config node</p>
*/
public String getConfigNode() {
public @NotNull String getConfigNode() {
return this.configNode;
}
@@ -280,7 +283,7 @@ public enum ConfigOption {
*
* @return <p>The description of this config option</p>
*/
public String getDescription() {
public @NotNull String getDescription() {
return this.description;
}
@@ -289,7 +292,7 @@ public enum ConfigOption {
*
* @return <p>This config option's default value</p>
*/
public Object getDefaultValue() {
public @NotNull Object getDefaultValue() {
return this.defaultValue;
}

View File

@@ -1,25 +1,38 @@
package net.knarcraft.stargate.config;
import java.util.Arrays;
import org.jetbrains.annotations.NotNull;
import java.util.Set;
/**
* A config tag groups config values by a property
*/
public enum ConfigTag {
COLOR(new ConfigOption[]{ConfigOption.FREE_GATES_COLOR, ConfigOption.MAIN_SIGN_COLOR,
ConfigOption.HIGHLIGHT_SIGN_COLOR, ConfigOption.PER_SIGN_COLORS}),
FOLDER(new ConfigOption[]{ConfigOption.GATE_FOLDER, ConfigOption.PORTAL_FOLDER}),
DYNMAP(new ConfigOption[]{ConfigOption.ENABLE_DYNMAP, ConfigOption.DYNMAP_ICONS_DEFAULT_HIDDEN});
/**
* Color-related configuration options
*/
COLOR(Set.of(ConfigOption.FREE_GATES_COLOR, ConfigOption.MAIN_SIGN_COLOR, ConfigOption.HIGHLIGHT_SIGN_COLOR,
ConfigOption.PER_SIGN_COLORS)),
private final ConfigOption[] taggedOptions;
/**
* Folder-altering configuration options
*/
FOLDER(Set.of(ConfigOption.GATE_FOLDER, ConfigOption.PORTAL_FOLDER)),
/**
* Dynmap-related configuration options
*/
DYNMAP(Set.of(ConfigOption.ENABLE_DYNMAP, ConfigOption.DYNMAP_ICONS_DEFAULT_HIDDEN));
private final Set<ConfigOption> taggedOptions;
/**
* Instantiates a new config tag
*
* @param taggedOptions <p>The config options included in this tag</p>
*/
ConfigTag(ConfigOption[] taggedOptions) {
ConfigTag(@NotNull Set<ConfigOption> taggedOptions) {
this.taggedOptions = taggedOptions;
}
@@ -29,8 +42,8 @@ public enum ConfigTag {
* @param option <p>The config option to check</p>
* @return <p>True of the config option is tagged</p>
*/
public boolean isTagged(ConfigOption option) {
return Arrays.stream(taggedOptions).anyMatch((item) -> item == option);
public boolean isTagged(@NotNull ConfigOption option) {
return taggedOptions.contains(option);
}
/**
@@ -39,7 +52,7 @@ public enum ConfigTag {
* @param configOption <p>The config option to check</p>
* @return <p>True if changing the config option requires a "reload of colors" to take effect</p>
*/
public static boolean requiresColorReload(ConfigOption configOption) {
public static boolean requiresColorReload(@NotNull ConfigOption configOption) {
return (COLOR.isTagged(configOption) && configOption != ConfigOption.FREE_GATES_COLOR);
}
@@ -49,7 +62,7 @@ public enum ConfigTag {
* @param option <p>The config option to check</p>
* @return <p>True if changing the config option requires a full reload to take effect</p>
*/
public static boolean requiresFullReload(ConfigOption option) {
public static boolean requiresFullReload(@NotNull ConfigOption option) {
return FOLDER.isTagged(option);
}
@@ -59,7 +72,7 @@ public enum ConfigTag {
* @param configOption <p>The config option to check</p>
* @return <p>True if changing the config option requires a reload of all dynmap markers</p>
*/
public static boolean requiresDynmapReload(ConfigOption configOption) {
public static boolean requiresDynmapReload(@NotNull ConfigOption configOption) {
return DYNMAP.isTagged(configOption);
}
@@ -69,7 +82,7 @@ public enum ConfigTag {
* @param option <p>The config option to check</p>
* @return <p>True if changing the config option requires a portal reload to take effect</p>
*/
public static boolean requiresPortalReload(ConfigOption option) {
public static boolean requiresPortalReload(@NotNull ConfigOption option) {
return COLOR.isTagged(option) || FOLDER.isTagged(option) || option == ConfigOption.VERIFY_PORTALS;
}
@@ -79,7 +92,7 @@ public enum ConfigTag {
* @param option <p>The config option to check</p>
* @return <p>True if the language loader requires a reload</p>
*/
public static boolean requiresLanguageReload(ConfigOption option) {
public static boolean requiresLanguageReload(@NotNull ConfigOption option) {
return option == ConfigOption.LANGUAGE;
}
@@ -89,7 +102,7 @@ public enum ConfigTag {
* @param option <p>The config option to check</p>
* @return <p>True if economy requires a reload</p>
*/
public static boolean requiresEconomyReload(ConfigOption option) {
public static boolean requiresEconomyReload(@NotNull ConfigOption option) {
return option == ConfigOption.USE_ECONOMY;
}

View File

@@ -1,6 +1,7 @@
package net.knarcraft.stargate.config;
import net.knarcraft.stargate.Stargate;
import net.knarcraft.stargate.container.RelativeBlockVector;
import net.knarcraft.stargate.portal.Portal;
import net.knarcraft.stargate.portal.PortalRegistry;
import org.bukkit.Location;
@@ -10,6 +11,8 @@ import org.dynmap.markers.GenericMarker;
import org.dynmap.markers.Marker;
import org.dynmap.markers.MarkerIcon;
import org.dynmap.markers.MarkerSet;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* A manager for dealing with everything Dynmap
@@ -29,7 +32,7 @@ public final class DynmapManager {
* @param dynmapAPI <p>A reference</p>
* @throws NullPointerException <p>If dynmap has an invalid state</p>
*/
public static void initialize(DynmapAPI dynmapAPI) throws NullPointerException {
public static void initialize(@Nullable DynmapAPI dynmapAPI) throws NullPointerException {
if (dynmapAPI == null || !dynmapAPI.markerAPIInitialized() || dynmapAPI.getMarkerAPI() == null) {
markerSet = null;
portalIcon = null;
@@ -67,7 +70,7 @@ public final class DynmapManager {
*
* @param portal <p>The portal to add a marker for</p>
*/
public static void addPortalMarker(Portal portal) {
public static void addPortalMarker(@NotNull Portal portal) {
if (markerSet == null || Stargate.getStargateConfig().isDynmapDisabled()) {
return;
}
@@ -76,7 +79,13 @@ public final class DynmapManager {
return;
}
Location location = portal.getBlockAt(portal.getGate().getLayout().getExit());
Location location;
@Nullable RelativeBlockVector exit = portal.getGate().getLayout().getExit();
if (exit == null) {
location = portal.getTopLeft();
} else {
location = portal.getBlockAt(exit);
}
Marker marker = markerSet.createMarker(getPortalMarkerId(portal), portal.getName(), world.getName(),
location.getX(), location.getY(), location.getZ(), portalIcon, false);
if (marker == null) {
@@ -112,7 +121,7 @@ public final class DynmapManager {
*
* @param portal <p>The portal to remove the marker for</p>
*/
public static void removePortalMarker(Portal portal) {
public static void removePortalMarker(@NotNull Portal portal) {
if (markerSet == null || Stargate.getStargateConfig().isDynmapDisabled()) {
return;
}
@@ -128,7 +137,7 @@ public final class DynmapManager {
* @param portal <p>The portal to get a marker id for</p>
* @return <p></p>
*/
private static String getPortalMarkerId(Portal portal) {
private static String getPortalMarkerId(@NotNull Portal portal) {
return portal.getNetwork() + "-:-" + portal.getName();
}

View File

@@ -11,6 +11,8 @@ import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.ServicesManager;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Map;
@@ -29,7 +31,7 @@ public final class EconomyConfig {
*
* @param configOptions <p>The loaded config options to read</p>
*/
public EconomyConfig(Map<ConfigOption, Object> configOptions) {
public EconomyConfig(@NotNull Map<ConfigOption, Object> configOptions) {
this.configOptions = configOptions;
try {
String freeColor = (String) configOptions.get(ConfigOption.FREE_GATES_COLOR);
@@ -62,6 +64,7 @@ public final class EconomyConfig {
*
* @return <p>An economy object, or null if economy is disabled or not initialized</p>
*/
@Nullable
public Economy getEconomy() {
return economy;
}
@@ -71,6 +74,7 @@ public final class EconomyConfig {
*
* @return <p>An instance of the Vault plugin, or null if Vault is not loaded</p>
*/
@Nullable
public Plugin getVault() {
return vault;
}
@@ -137,6 +141,7 @@ public final class EconomyConfig {
*
* @return <p>The account all taxes are paid to</p>
*/
@Nullable
public String getTaxAccount() {
return (String) configOptions.get(ConfigOption.TAX_ACCOUNT);
}
@@ -158,6 +163,7 @@ public final class EconomyConfig {
* @param amount <p>The amount to display</p>
* @return <p>A formatted text string describing the amount</p>
*/
@NotNull
public String format(int amount) {
if (isEconomyEnabled()) {
return economy.format(amount);
@@ -172,7 +178,7 @@ public final class EconomyConfig {
* @param pluginManager <p>The plugin manager to get plugins from</p>
* @return <p>True if economy was enabled</p>
*/
public boolean setupEconomy(PluginManager pluginManager) {
public boolean setupEconomy(@NotNull PluginManager pluginManager) {
if (!isEconomyEnabled()) {
return false;
}
@@ -211,7 +217,7 @@ public final class EconomyConfig {
* @param gate <p>The gate type used</p>
* @return <p>The cost of creating the gate</p>
*/
public int getCreateCost(Player player, Gate gate) {
public int getCreateCost(@NotNull Player player, @NotNull Gate gate) {
if (isFree(player, "create")) {
return 0;
} else {
@@ -226,7 +232,7 @@ public final class EconomyConfig {
* @param gate <p>The gate type used</p>
* @return <p>The cost of destroying the gate</p>
*/
public int getDestroyCost(Player player, Gate gate) {
public int getDestroyCost(@NotNull Player player, @NotNull Gate gate) {
if (isFree(player, "destroy")) {
return 0;
} else {
@@ -241,7 +247,7 @@ public final class EconomyConfig {
* @param permissionNode <p>The free.permissionNode necessary to allow free gate {action}</p>
* @return <p></p>
*/
private boolean isFree(Player player, String permissionNode) {
private boolean isFree(@NotNull Player player, @NotNull String permissionNode) {
return !useEconomy() || PermissionHelper.hasPermission(player, "stargate.free." + permissionNode);
}

View File

@@ -3,6 +3,8 @@ package net.knarcraft.stargate.config;
import net.knarcraft.knarlib.property.ColorConversion;
import net.knarcraft.knarlib.util.FileHelper;
import net.knarcraft.stargate.Stargate;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.BufferedReader;
import java.io.BufferedWriter;
@@ -30,7 +32,7 @@ public final class LanguageLoader {
*
* @param languageFolder <p>The folder containing the language files</p>
*/
public LanguageLoader(String languageFolder) {
public LanguageLoader(@NotNull String languageFolder) {
this.languageFolder = languageFolder;
File testFile = new File(languageFolder, "en.txt");
if (!testFile.exists()) {
@@ -65,7 +67,8 @@ public final class LanguageLoader {
* @param name <p>The name/key of the string to display</p>
* @return <p>The string in the user's preferred language</p>
*/
public String getString(String name) {
@NotNull
public String getString(@NotNull String name) {
String value = null;
if (loadedStringTranslations != null) {
value = loadedStringTranslations.get(name);
@@ -82,7 +85,8 @@ public final class LanguageLoader {
* @param name <p>The name/key of the string to display</p>
* @return <p>The string in the backup language (English)</p>
*/
public String getBackupString(String name) {
@NotNull
public String getBackupString(@NotNull String name) {
String value = null;
if (loadedBackupStrings != null) {
value = loadedBackupStrings.get(name);
@@ -98,7 +102,7 @@ public final class LanguageLoader {
*
* @param chosenLanguage <p>The new plugin language</p>
*/
public void setChosenLanguage(String chosenLanguage) {
public void setChosenLanguage(@NotNull String chosenLanguage) {
this.chosenLanguage = chosenLanguage;
}
@@ -107,7 +111,7 @@ public final class LanguageLoader {
*
* @param language <p>The language to update</p>
*/
private void updateLanguage(String language) {
private void updateLanguage(@NotNull String language) {
Map<String, String> currentLanguageValues = load(language);
InputStream inputStream = getClass().getResourceAsStream("/lang/" + language + ".txt");
@@ -133,8 +137,8 @@ public final class LanguageLoader {
* @param currentLanguageValues <p>The current values of the loaded/processed language</p>
* @throws IOException <p>if unable to read a language file</p>
*/
private void readChangedLanguageStrings(InputStream inputStream, String language, Map<String,
String> currentLanguageValues) throws IOException {
private void readChangedLanguageStrings(@NotNull InputStream inputStream, @NotNull String language,
@Nullable Map<String, String> currentLanguageValues) throws IOException {
//Get language values
BufferedReader bufferedReader = FileHelper.getBufferedReaderFromInputStream(inputStream);
Map<String, String> internalLanguageValues = FileHelper.readKeyValuePairs(bufferedReader, "=",
@@ -177,8 +181,8 @@ public final class LanguageLoader {
* @param customLanguageStrings <p>Any custom language strings not recognized</p>
* @throws IOException <p>If unable to write to the language file</p>
*/
private void updateLanguageFile(String language, Map<String, String> languageStrings,
Map<String, String> customLanguageStrings) throws IOException {
private void updateLanguageFile(@NotNull String language, @NotNull Map<String, String> languageStrings,
@Nullable Map<String, String> customLanguageStrings) throws IOException {
BufferedWriter bufferedWriter = FileHelper.getBufferedWriterFromString(languageFolder + language + ".txt");
//Output normal Language data
@@ -203,7 +207,8 @@ public final class LanguageLoader {
* @param lang <p>The language to load</p>
* @return <p>A mapping between loaded string indexes and the strings to display</p>
*/
private Map<String, String> load(String lang) {
@Nullable
private Map<String, String> load(@NotNull String lang) {
return load(lang, null);
}
@@ -214,7 +219,8 @@ public final class LanguageLoader {
* @param inputStream <p>An optional input stream to use. Defaults to using a file input stream</p>
* @return <p>A mapping between loaded string indexes and the strings to display</p>
*/
private Map<String, String> load(String lang, InputStream inputStream) {
@Nullable
private Map<String, String> load(@NotNull String lang, @Nullable InputStream inputStream) {
Map<String, String> strings;
BufferedReader bufferedReader;
try {
@@ -224,7 +230,7 @@ public final class LanguageLoader {
bufferedReader = FileHelper.getBufferedReaderFromInputStream(inputStream);
}
strings = FileHelper.readKeyValuePairs(bufferedReader, "=", ColorConversion.NORMAL);
} catch (Exception e) {
} catch (Exception exception) {
if (Stargate.getStargateConfig().isDebuggingEnabled()) {
Stargate.logInfo("Unable to load language " + lang);
}

View File

@@ -2,6 +2,7 @@ package net.knarcraft.stargate.config;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
/**
* The message sender is responsible sending messages to players with correct coloring and formatting
@@ -15,7 +16,7 @@ public final class MessageSender {
*
* @param languageLoader <p>The language loader to get translated strings from</p>
*/
public MessageSender(LanguageLoader languageLoader) {
public MessageSender(@NotNull LanguageLoader languageLoader) {
this.languageLoader = languageLoader;
}
@@ -25,7 +26,7 @@ public final class MessageSender {
* @param player <p>The player to send the message to</p>
* @param message <p>The message to send</p>
*/
public void sendErrorMessage(CommandSender player, String message) {
public void sendErrorMessage(@NotNull CommandSender player, @NotNull String message) {
sendMessage(player, message, true);
}
@@ -35,7 +36,7 @@ public final class MessageSender {
* @param player <p>The player to send the message to</p>
* @param message <p>The message to send</p>
*/
public void sendSuccessMessage(CommandSender player, String message) {
public void sendSuccessMessage(@NotNull CommandSender player, @NotNull String message) {
sendMessage(player, message, false);
}
@@ -46,7 +47,7 @@ public final class MessageSender {
* @param message <p>The message to send</p>
* @param error <p>Whether the message sent is an error</p>
*/
private void sendMessage(CommandSender sender, String message, boolean error) {
private void sendMessage(@NotNull CommandSender sender, @NotNull String message, boolean error) {
if (message.isEmpty()) {
return;
}

View File

@@ -19,6 +19,7 @@ import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.messaging.Messenger;
import org.dynmap.DynmapAPI;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.io.IOException;
@@ -58,7 +59,7 @@ public final class StargateConfig {
*
* @param logger <p>The logger to use for logging errors</p>
*/
public StargateConfig(Logger logger) {
public StargateConfig(@NotNull Logger logger) {
this.logger = logger;
configOptions = new HashMap<>();
@@ -76,6 +77,7 @@ public final class StargateConfig {
*
* @return <p>A reference to the config options map</p>
*/
@NotNull
public Map<ConfigOption, Object> getConfigOptionsReference() {
return configOptions;
}
@@ -136,6 +138,7 @@ public final class StargateConfig {
*
* @return <p>The loaded config options</p>
*/
@NotNull
public Map<ConfigOption, Object> getConfigOptions() {
return new HashMap<>(configOptions);
}
@@ -147,6 +150,7 @@ public final class StargateConfig {
*
* @return <p>The open portals queue</p>
*/
@NotNull
public Queue<Portal> getOpenPortalsQueue() {
return openPortalsQueue;
}
@@ -158,6 +162,7 @@ public final class StargateConfig {
*
* @return <p>The active portals queue</p>
*/
@NotNull
public Queue<Portal> getActivePortalsQueue() {
return activePortalsQueue;
}
@@ -203,6 +208,7 @@ public final class StargateConfig {
*
* @return <p>The object containing economy config values</p>
*/
@NotNull
public EconomyConfig getEconomyConfig() {
return this.economyConfig;
}
@@ -212,7 +218,7 @@ public final class StargateConfig {
*
* @param sender <p>The sender of the reload request</p>
*/
public void reload(CommandSender sender) {
public void reload(@NotNull CommandSender sender) {
//Unload all saved data
unload();
@@ -285,6 +291,7 @@ public final class StargateConfig {
*
* @return <p>The managed worlds</p>
*/
@NotNull
public Set<String> getManagedWorlds() {
return new HashSet<>(managedWorlds);
}
@@ -294,7 +301,7 @@ public final class StargateConfig {
*
* @param worldName <p>The name of the world to manage</p>
*/
public void addManagedWorld(String worldName) {
public void addManagedWorld(@NotNull String worldName) {
managedWorlds.add(worldName);
}
@@ -303,7 +310,7 @@ public final class StargateConfig {
*
* @param worldName <p>The name of the world to stop managing</p>
*/
public void removeManagedWorld(String worldName) {
public void removeManagedWorld(@NotNull String worldName) {
managedWorlds.remove(worldName);
}
@@ -448,6 +455,7 @@ public final class StargateConfig {
*
* @return <p>Gets the gate config</p>
*/
@NotNull
public StargateGateConfig getStargateGateConfig() {
return stargateGateConfig;
}
@@ -465,13 +473,13 @@ public final class StargateConfig {
*
* @param currentConfiguration <p>The current config to back up</p>
*/
private void migrateConfig(FileConfiguration currentConfiguration) {
private void migrateConfig(@NotNull FileConfiguration currentConfiguration) {
String debugPath = "StargateConfig::migrateConfig";
//Save the old config just in case something goes wrong
try {
currentConfiguration.save(new File(dataFolderPath, "config.yml.old"));
} catch (IOException e) {
} catch (IOException exception) {
Stargate.debug(debugPath, "Unable to save old backup and do migration");
return;
}
@@ -489,7 +497,7 @@ public final class StargateConfig {
migrationFields = FileHelper.readKeyValuePairs(FileHelper.getBufferedReaderFromInputStream(
FileHelper.getInputStreamForInternalFile("/config-migrations.txt")), "=",
ColorConversion.NORMAL);
} catch (IOException e) {
} catch (IOException exception) {
Stargate.debug(debugPath, "Unable to load config migration file");
return;
}
@@ -530,9 +538,10 @@ public final class StargateConfig {
*/
private void setupVaultEconomy() {
EconomyConfig economyConfig = getEconomyConfig();
if (economyConfig.setupEconomy(Stargate.getPluginManager()) && economyConfig.getEconomy() != null) {
if (economyConfig.setupEconomy(Stargate.getPluginManager()) && economyConfig.getEconomy() != null &&
economyConfig.getVault() != null) {
String vaultVersion = economyConfig.getVault().getDescription().getVersion();
Stargate.logInfo(Stargate.replaceVars(Stargate.getString("vaultLoaded"), "%version%", vaultVersion));
Stargate.logInfo(Stargate.replacePlaceholders(Stargate.getString("vaultLoaded"), "%version%", vaultVersion));
}
}
@@ -578,6 +587,7 @@ public final class StargateConfig {
*
* @return <p>The portal folder</p>
*/
@NotNull
public String getPortalFolder() {
return portalFolder;
}
@@ -589,6 +599,7 @@ public final class StargateConfig {
*
* @return <p>The folder storing gate files</p>
*/
@NotNull
public String getGateFolder() {
return gateFolder;
}
@@ -598,6 +609,7 @@ public final class StargateConfig {
*
* @return <p>The sender for sending messages to players</p>
*/
@NotNull
public MessageSender getMessageSender() {
return messageSender;
}
@@ -607,6 +619,7 @@ public final class StargateConfig {
*
* @return <p>The language loader</p>
*/
@NotNull
public LanguageLoader getLanguageLoader() {
return languageLoader;
}

View File

@@ -6,6 +6,7 @@ import net.knarcraft.stargate.portal.PortalSignDrawer;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.Color;
import org.bukkit.Material;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.HashMap;
@@ -26,7 +27,7 @@ public final class StargateGateConfig {
*
* @param configOptions <p>The loaded config options to use</p>
*/
public StargateGateConfig(Map<ConfigOption, Object> configOptions) {
public StargateGateConfig(@NotNull Map<ConfigOption, Object> configOptions) {
this.configOptions = configOptions;
loadGateConfig();
}
@@ -248,8 +249,8 @@ public final class StargateGateConfig {
* @param defaultColors <p>The specified default colors</p>
* @param colorMaps <p>The list of color maps to save the resulting colors to</p>
*/
private void parsePerSignColors(Object signColorSpecification, ChatColor[] defaultColors,
List<Map<Material, ChatColor>> colorMaps) {
private void parsePerSignColors(@NotNull Object signColorSpecification, @NotNull ChatColor[] defaultColors,
@NotNull List<Map<Material, ChatColor>> colorMaps) {
String[] specificationData = String.valueOf(signColorSpecification).split(":");
Material[] signMaterials = new Material[]{Material.matchMaterial(specificationData[0] + "_SIGN"),
Material.matchMaterial(specificationData[0] + "_WALL_SIGN")};
@@ -280,8 +281,8 @@ public final class StargateGateConfig {
* @param signMaterials <p>The materials to load this color for</p>
* @param colorMaps <p>The list of color maps to save the resulting color to</p>
*/
private void loadPerSignColor(String[] colors, int colorIndex, ChatColor[] defaultColors, Material[] signMaterials,
List<Map<Material, ChatColor>> colorMaps) {
private void loadPerSignColor(@NotNull String[] colors, int colorIndex, @NotNull ChatColor[] defaultColors,
@NotNull Material[] signMaterials, @NotNull List<Map<Material, ChatColor>> colorMaps) {
ChatColor parsedColor;
if (colors[colorIndex].equalsIgnoreCase("inverted")) {
//Convert from ChatColor to awt.Color to Bukkit.Color then invert and convert to ChatColor
@@ -309,7 +310,7 @@ public final class StargateGateConfig {
*
* @param mainSignColor <p>A string representing the main sign color</p>
*/
private void loadPerSignColor(String mainSignColor, String highlightSignColor) {
private void loadPerSignColor(@NotNull String mainSignColor, @NotNull String highlightSignColor) {
try {
PortalSignDrawer.setMainColor(ChatColor.of(mainSignColor.toUpperCase()));
} catch (IllegalArgumentException | NullPointerException exception) {

View File

@@ -21,18 +21,20 @@ import java.util.List;
*/
public class StargateYamlConfiguration extends YamlConfiguration {
public static final String START_OF_COMMENT_LINE = "[HASHTAG]";
static public final String END_OF_COMMENT = "_endOfComment_";
static public final String START_OF_COMMENT = "comment_";
private static final String START_OF_COMMENT_LINE = "[HASHTAG]";
private static final String END_OF_COMMENT = "_endOfComment_";
private static final String START_OF_COMMENT = "comment_";
@Override
@NotNull
@SuppressWarnings("deprecation")
protected @NotNull String buildHeader() {
protected String buildHeader() {
return "";
}
@Override
public @NotNull String saveToString() {
@NotNull
public String saveToString() {
// Convert YAML comments to normal comments
return this.convertYAMLMappingsToComments(super.saveToString());
}
@@ -51,7 +53,8 @@ public class StargateYamlConfiguration extends YamlConfiguration {
* the {@link FileConfiguration#save(File)} method. The config
* needs to be saved if a config value has changed.</p>
*/
private String convertCommentsToYAMLMappings(String configString) {
@NotNull
private String convertCommentsToYAMLMappings(@NotNull String configString) {
StringBuilder yamlBuilder = new StringBuilder();
List<String> currentComment = new ArrayList<>();
int commentId = 0;
@@ -84,8 +87,8 @@ public class StargateYamlConfiguration extends YamlConfiguration {
* @param previousIndentation <p>The indentation of the current block comment</p>
* @param commentId <p>The id of the comment</p>
*/
private void addYamlString(StringBuilder yamlBuilder, List<String> currentComment, String line,
int previousIndentation, int commentId) {
private void addYamlString(@NotNull StringBuilder yamlBuilder, @NotNull List<String> currentComment,
@NotNull String line, int previousIndentation, int commentId) {
String trimmed = line.trim();
//Write the full formatted comment to the StringBuilder
if (!currentComment.isEmpty()) {
@@ -105,7 +108,7 @@ public class StargateYamlConfiguration extends YamlConfiguration {
* @param commentParts <p>The list to add to</p>
* @param comment <p>The comment to add</p>
*/
private void addComment(List<String> commentParts, String comment) {
private void addComment(@NotNull List<String> commentParts, @NotNull String comment) {
if (comment.startsWith("# ")) {
commentParts.add(comment.replaceFirst("# ", START_OF_COMMENT_LINE));
} else {
@@ -121,7 +124,8 @@ public class StargateYamlConfiguration extends YamlConfiguration {
* @param commentId <p>The unique id of the comment</p>
* @param indentation <p>The indentation to add to every line</p>
*/
private void generateCommentYAML(StringBuilder yamlBuilder, List<String> commentLines, int commentId, int indentation) {
private void generateCommentYAML(@NotNull StringBuilder yamlBuilder, @NotNull List<String> commentLines,
int commentId, int indentation) {
String subIndentation = this.addIndentation(indentation + 2);
//Add the comment start marker
yamlBuilder.append(this.addIndentation(indentation)).append(START_OF_COMMENT).append(commentId).append(": |\n");
@@ -143,7 +147,8 @@ public class StargateYamlConfiguration extends YamlConfiguration {
* @param yamlString <p>A string using the YAML format</p>
* @return <p>The corresponding comment string</p>
*/
private String convertYAMLMappingsToComments(String yamlString) {
@NotNull
private String convertYAMLMappingsToComments(@NotNull String yamlString) {
StringBuilder finalText = new StringBuilder();
String[] lines = yamlString.split("\n");
@@ -173,7 +178,8 @@ public class StargateYamlConfiguration extends YamlConfiguration {
* @param commentIndentation <p>The indentation of the read comment</p>
* @return <p>The index containing the next non-comment line</p>
*/
private int readComment(StringBuilder builder, String[] lines, int startIndex, int commentIndentation) {
private int readComment(@NotNull StringBuilder builder, @NotNull String[] lines, int startIndex,
int commentIndentation) {
for (int currentIndex = startIndex; currentIndex < lines.length; currentIndex++) {
String line = lines[currentIndex];
String possibleComment = line.trim();
@@ -194,6 +200,7 @@ public class StargateYamlConfiguration extends YamlConfiguration {
* @param indentationSpaces <p>The number spaces to use for indentation</p>
* @return <p>A string containing the number of spaces specified</p>
*/
@NotNull
private String addIndentation(int indentationSpaces) {
return " ".repeat(Math.max(0, indentationSpaces));
}
@@ -205,7 +212,7 @@ public class StargateYamlConfiguration extends YamlConfiguration {
* @param line <p>The line to get indentation of</p>
* @return <p>The number of spaces in the line's indentation</p>
*/
private int getIndentation(String line) {
private int getIndentation(@NotNull String line) {
int spacesFound = 0;
for (char aCharacter : line.toCharArray()) {
if (aCharacter == ' ') {