Updates KnarLib
All checks were successful
EpicKnarvik97/Blacksmith/pipeline/head This commit looks good
All checks were successful
EpicKnarvik97/Blacksmith/pipeline/head This commit looks good
This commit is contained in:
@@ -13,49 +13,40 @@ import net.knarcraft.blacksmith.command.scrapper.ScrapperConfigCommand;
|
||||
import net.knarcraft.blacksmith.command.scrapper.ScrapperConfigTabCompleter;
|
||||
import net.knarcraft.blacksmith.command.scrapper.ScrapperEditCommand;
|
||||
import net.knarcraft.blacksmith.command.scrapper.ScrapperEditTabCompleter;
|
||||
import net.knarcraft.blacksmith.config.StargateYamlConfiguration;
|
||||
import net.knarcraft.blacksmith.config.blacksmith.GlobalBlacksmithSettings;
|
||||
import net.knarcraft.blacksmith.config.scrapper.GlobalScrapperSettings;
|
||||
import net.knarcraft.blacksmith.formatting.BlacksmithTranslatableMessage;
|
||||
import net.knarcraft.blacksmith.formatting.Translatable;
|
||||
import net.knarcraft.blacksmith.listener.NPCClickListener;
|
||||
import net.knarcraft.blacksmith.listener.PlayerListener;
|
||||
import net.knarcraft.blacksmith.manager.EconomyManager;
|
||||
import net.knarcraft.blacksmith.trait.BlacksmithTrait;
|
||||
import net.knarcraft.blacksmith.trait.ScrapperTrait;
|
||||
import net.knarcraft.blacksmith.util.ConfigHelper;
|
||||
import net.knarcraft.knarlib.formatting.FormatBuilder;
|
||||
import net.knarcraft.knarlib.formatting.StringFormatter;
|
||||
import net.knarcraft.knarlib.formatting.TranslatableTimeUnit;
|
||||
import net.knarcraft.knarlib.formatting.Translator;
|
||||
import net.knarcraft.knarlib.plugin.ConfigCommentPlugin;
|
||||
import net.knarcraft.knarlib.util.ConfigHelper;
|
||||
import net.knarcraft.knarlib.util.UpdateChecker;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.plugin.java.JavaPluginLoader;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* Blacksmith's main class
|
||||
*/
|
||||
public class BlacksmithPlugin extends JavaPlugin {
|
||||
public class BlacksmithPlugin extends ConfigCommentPlugin {
|
||||
|
||||
private static final String CONFIG_FILE_NAME = "config.yml";
|
||||
private static BlacksmithPlugin instance;
|
||||
private GlobalBlacksmithSettings blacksmithConfig;
|
||||
private GlobalScrapperSettings scrapperConfig;
|
||||
private static Translator translator;
|
||||
private static StringFormatter stringFormatter;
|
||||
private FileConfiguration configuration;
|
||||
|
||||
/**
|
||||
* Constructor required for MockBukkit
|
||||
@@ -108,29 +99,10 @@ public class BlacksmithPlugin extends JavaPlugin {
|
||||
this.reloadConfig();
|
||||
blacksmithConfig.load();
|
||||
scrapperConfig.load();
|
||||
translator.loadLanguages(this.getDataFolder(), "en", this.getConfiguration().getString(
|
||||
translator.loadLanguages(this.getDataFolder(), "en", this.getConfig().getString(
|
||||
"language", "en"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the raw configuration
|
||||
*
|
||||
* @return <p>The raw configuration</p>
|
||||
*/
|
||||
@NotNull
|
||||
public FileConfiguration getConfiguration() {
|
||||
return this.configuration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the string formatter to use for formatting
|
||||
*
|
||||
* @return <p>The string formatter to use</p>
|
||||
*/
|
||||
public static @NotNull StringFormatter getStringFormatter() {
|
||||
return BlacksmithPlugin.stringFormatter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the translator to use for translation
|
||||
*
|
||||
@@ -148,20 +120,13 @@ public class BlacksmithPlugin extends JavaPlugin {
|
||||
@Override
|
||||
public void onEnable() {
|
||||
instance = this;
|
||||
|
||||
//Copy default config to disk, and add missing configuration values
|
||||
this.saveDefaultConfig();
|
||||
this.getConfig().options().copyDefaults(true);
|
||||
this.reloadConfig();
|
||||
this.saveConfig();
|
||||
ConfigHelper.saveDefaults(this);
|
||||
|
||||
//Migrate from an earlier configuration file syntax if necessary
|
||||
if (getConfiguration().getString("scrapper.defaults.dropItem") == null) {
|
||||
ConfigHelper.migrateConfig(this.getDataFolder().getPath().replaceAll("\\\\", "/"),
|
||||
getConfiguration());
|
||||
this.reloadConfig();
|
||||
if (getConfig().getString("scrapper.defaults.dropItem") == null) {
|
||||
net.knarcraft.knarlib.util.ConfigHelper.migrateConfig(this);
|
||||
}
|
||||
initializeConfigurations(getConfiguration());
|
||||
initializeConfigurations(getConfig());
|
||||
|
||||
//Set up Vault integration
|
||||
if (!setUpVault()) {
|
||||
@@ -185,28 +150,6 @@ public class BlacksmithPlugin extends JavaPlugin {
|
||||
() -> this.getDescription().getVersion(), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reloadConfig() {
|
||||
super.reloadConfig();
|
||||
this.configuration = new StargateYamlConfiguration();
|
||||
this.configuration.options().copyDefaults(true);
|
||||
try {
|
||||
this.configuration.load(new File(getDataFolder(), CONFIG_FILE_NAME));
|
||||
} catch (IOException | InvalidConfigurationException exception) {
|
||||
error("Unable to load the configuration! Message: " + exception.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveConfig() {
|
||||
super.saveConfig();
|
||||
try {
|
||||
this.configuration.save(new File(getDataFolder(), CONFIG_FILE_NAME));
|
||||
} catch (IOException exception) {
|
||||
error("Unable to save the configuration! Message: " + exception.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls an event
|
||||
*
|
||||
@@ -267,7 +210,7 @@ public class BlacksmithPlugin extends JavaPlugin {
|
||||
//Prepare the translator
|
||||
translator = new Translator();
|
||||
translator.registerMessageCategory(TranslatableTimeUnit.UNIT_SECOND);
|
||||
translator.registerMessageCategory(BlacksmithTranslatableMessage.ITEM_TYPE_ENCHANTMENT);
|
||||
translator.registerMessageCategory(Translatable.ITEM_TYPE_ENCHANTMENT);
|
||||
translator.loadLanguages(this.getDataFolder(), "en",
|
||||
fileConfiguration.getString("language", "en"));
|
||||
PluginDescriptionFile description = this.getDescription();
|
||||
@@ -277,7 +220,7 @@ public class BlacksmithPlugin extends JavaPlugin {
|
||||
} else {
|
||||
prefix = description.getPrefix();
|
||||
}
|
||||
BlacksmithPlugin.stringFormatter = new StringFormatter(prefix, translator);
|
||||
FormatBuilder.setStringFormatter(new StringFormatter(prefix, translator));
|
||||
|
||||
// This reload is necessary to get values just added to the configuration for some reason
|
||||
this.reload();
|
||||
@@ -319,22 +262,4 @@ public class BlacksmithPlugin extends JavaPlugin {
|
||||
registerCommand("preset", new PresetCommand(), new PresetTabCompleter());
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a command
|
||||
*
|
||||
* @param commandName <p>The name of the command</p>
|
||||
* @param executor <p>The executor to bind to the command</p>
|
||||
* @param tabCompleter <p>The tab completer to bind to the command, or null</p>
|
||||
*/
|
||||
private void registerCommand(@NotNull String commandName, @NotNull CommandExecutor executor,
|
||||
@Nullable TabCompleter tabCompleter) {
|
||||
PluginCommand command = this.getCommand(commandName);
|
||||
if (command != null) {
|
||||
command.setExecutor(executor);
|
||||
if (tabCompleter != null) {
|
||||
command.setTabCompleter(tabCompleter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user