Uses KnarLib implementation for some methods
All checks were successful
EpicKnarvik97/Books-Without-Borders/pipeline/head This commit looks good

This commit is contained in:
2025-09-06 04:46:15 +02:00
parent 1437739fe3
commit e9e4836a16
2 changed files with 4 additions and 44 deletions

View File

@@ -125,7 +125,7 @@
<dependency> <dependency>
<groupId>net.knarcraft</groupId> <groupId>net.knarcraft</groupId>
<artifactId>knarlib</artifactId> <artifactId>knarlib</artifactId>
<version>1.2.12</version> <version>1.2.14</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@@ -47,23 +47,19 @@ import net.knarcraft.bookswithoutborders.listener.PlayerEventListener;
import net.knarcraft.bookswithoutborders.listener.SignEventListener; import net.knarcraft.bookswithoutborders.listener.SignEventListener;
import net.knarcraft.bookswithoutborders.utility.BookFileUtil; import net.knarcraft.bookswithoutborders.utility.BookFileUtil;
import net.knarcraft.bookswithoutborders.utility.InputCleaningUtil; import net.knarcraft.bookswithoutborders.utility.InputCleaningUtil;
import net.knarcraft.knarlib.config.StargateYamlConfiguration;
import net.knarcraft.knarlib.formatting.FormatBuilder; import net.knarcraft.knarlib.formatting.FormatBuilder;
import net.knarcraft.knarlib.formatting.StringFormatter; import net.knarcraft.knarlib.formatting.StringFormatter;
import net.knarcraft.knarlib.formatting.Translator; import net.knarcraft.knarlib.formatting.Translator;
import net.knarcraft.knarlib.plugin.ConfigCommentPlugin;
import net.knarcraft.knarlib.property.ColorConversion; import net.knarcraft.knarlib.property.ColorConversion;
import net.knarcraft.knarlib.util.ConfigHelper; import net.knarcraft.knarlib.util.ConfigHelper;
import net.knarcraft.knarlib.util.UpdateChecker; import net.knarcraft.knarlib.util.UpdateChecker;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginCommand;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemFactory; import org.bukkit.inventory.ItemFactory;
import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@@ -81,7 +77,7 @@ import java.util.logging.Level;
/** /**
* The main Books Without Borders class * The main Books Without Borders class
*/ */
public class BooksWithoutBorders extends JavaPlugin { public class BooksWithoutBorders extends ConfigCommentPlugin {
private static BooksWithoutBorders booksWithoutBorders; private static BooksWithoutBorders booksWithoutBorders;
@@ -93,7 +89,6 @@ public class BooksWithoutBorders extends JavaPlugin {
private BookshelfHandler bookshelfHandler; private BookshelfHandler bookshelfHandler;
private BwBConfig booksWithoutBordersConfig; private BwBConfig booksWithoutBordersConfig;
private final Queue<MigrationRequest> migrationQueue = new LinkedList<>(); private final Queue<MigrationRequest> migrationQueue = new LinkedList<>();
private FileConfiguration configuration = null;
/** /**
* Logs a message to the console * Logs a message to the console
@@ -198,32 +193,13 @@ public class BooksWithoutBorders extends JavaPlugin {
getInstance().playerLetterIndex = new HashMap<>(); getInstance().playerLetterIndex = new HashMap<>();
} }
@Override
public void reloadConfig() {
this.configuration = StargateYamlConfiguration.loadConfiguration(this, true);
}
@Override
public void saveConfig() {
StargateYamlConfiguration.saveConfiguration(this, this.configuration);
}
@Override
@NotNull
public FileConfiguration getConfig() {
if (this.configuration == null) {
this.reloadConfig();
}
return this.configuration;
}
@Override @Override
public void onEnable() { public void onEnable() {
booksWithoutBorders = this; booksWithoutBorders = this;
ConfigHelper.saveDefaults(this); ConfigHelper.saveDefaults(this);
//Migrate from an earlier configuration file syntax if necessary //Migrate from an earlier configuration file syntax if necessary
if (this.configuration.getString("Options.Save_Books_in_Yaml_Format") != null) { if (getConfig().getString("Options.Save_Books_in_Yaml_Format") != null) {
ConfigHelper.migrateConfig(this); ConfigHelper.migrateConfig(this);
} }
@@ -320,22 +296,6 @@ public class BooksWithoutBorders extends JavaPlugin {
registerCommand(BwBCommand.CREATE_BWB_SIGN.toString(), new CommandCreateBwBSign()); registerCommand(BwBCommand.CREATE_BWB_SIGN.toString(), new CommandCreateBwBSign());
} }
/**
* Registers a command
*
* @param commandName <p>The name of the command to register</p>
* @param executor <p>The executor to register for the command</p>
*/
private void registerCommand(@NotNull String commandName, @NotNull CommandExecutor executor) {
PluginCommand pluginCommand = this.getCommand(commandName);
if (pluginCommand != null) {
pluginCommand.setExecutor(executor);
} else {
getLogger().log(Level.SEVERE, new FormatBuilder(StaticMessage.EXCEPTION_COMMAND_REGISTRATION_FAILED.toString()).
replace(Placeholder.COMMAND, commandName).toString());
}
}
/** /**
* Initializes the plugin, loading and fixing the config file * Initializes the plugin, loading and fixing the config file
* *