Adds customization and automatic movement to crafting stations
All checks were successful
KnarCraft/BlacksmithVisuals/pipeline/head This commit looks good
All checks were successful
KnarCraft/BlacksmithVisuals/pipeline/head This commit looks good
This commit is contained in:
@@ -1,6 +1,18 @@
|
||||
package net.knarcraft.blacksmithvisuals;
|
||||
|
||||
import net.knarcraft.blacksmithvisuals.command.ReloadCommand;
|
||||
import net.knarcraft.blacksmithvisuals.command.SetNPCPositionCommand;
|
||||
import net.knarcraft.blacksmithvisuals.listener.BlacksmithListener;
|
||||
import net.knarcraft.blacksmithvisuals.manager.ConfigurationManager;
|
||||
import net.knarcraft.blacksmithvisuals.manager.NPCDataManager;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* The blacksmith visual main class
|
||||
@@ -8,18 +20,102 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
@SuppressWarnings("unused")
|
||||
public final class BlacksmithVisuals extends JavaPlugin {
|
||||
|
||||
private static BlacksmithVisuals instance;
|
||||
private ConfigurationManager configurationManager;
|
||||
private NPCDataManager npcDataManager;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
// Plugin startup logic
|
||||
getServer().getPluginManager().registerEvents(new BlacksmithListener(), this);
|
||||
BlacksmithVisuals.instance = this;
|
||||
|
||||
//TODO: Allow customization of sounds, volumes and pitches
|
||||
// Allow setting an idle position and a working position, and move the NPC to the right position at the right time.
|
||||
// Use the distance between the two locations to decide how much sooner before the success/fail sounds are played the NPC should start walking
|
||||
//Copy default config to disk, and add missing configuration values
|
||||
this.saveDefaultConfig();
|
||||
this.getConfig().options().copyDefaults(true);
|
||||
this.reloadConfig();
|
||||
this.saveConfig();
|
||||
|
||||
try {
|
||||
this.configurationManager = new ConfigurationManager(this.getConfig());
|
||||
} catch (InvalidConfigurationException exception) {
|
||||
this.getLogger().log(Level.SEVERE, "Could not properly load the configuration file. " +
|
||||
"Please check it for errors!");
|
||||
this.onDisable();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
this.npcDataManager = NPCDataManager.load();
|
||||
} catch (IOException e) {
|
||||
this.getLogger().log(Level.SEVERE, "Could not properly load the data.yml file. " +
|
||||
"Please check it for errors!");
|
||||
this.onDisable();
|
||||
return;
|
||||
}
|
||||
getServer().getPluginManager().registerEvents(new BlacksmithListener(this.configurationManager), this);
|
||||
registerCommand("reload", new ReloadCommand());
|
||||
registerCommand("setNPCPosition", new SetNPCPositionCommand());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
// Plugin shutdown logic
|
||||
}
|
||||
|
||||
/**
|
||||
* Reloads the configuration file
|
||||
*/
|
||||
public void reload() {
|
||||
reloadConfig();
|
||||
saveConfig();
|
||||
try {
|
||||
this.configurationManager.load(getConfig());
|
||||
} catch (InvalidConfigurationException exception) {
|
||||
this.getLogger().log(Level.SEVERE, "Could not properly load the configuration file. " +
|
||||
"Please check it for errors!");
|
||||
this.onDisable();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a command
|
||||
*
|
||||
* @param commandName <p>The name of the command</p>
|
||||
* @param executor <p>The executor to bind to the command</p>
|
||||
*/
|
||||
private void registerCommand(@NotNull String commandName, @NotNull CommandExecutor executor) {
|
||||
PluginCommand command = this.getCommand(commandName);
|
||||
if (command != null) {
|
||||
command.setExecutor(executor);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the NPC data manager
|
||||
*
|
||||
* @return <p>The NPC data manager</p>
|
||||
*/
|
||||
@NotNull
|
||||
public NPCDataManager getNpcDataManager() {
|
||||
return this.npcDataManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the configuration manager
|
||||
*
|
||||
* @return <p>The configuration manager</p>
|
||||
*/
|
||||
@NotNull
|
||||
public ConfigurationManager getConfigurationManager() {
|
||||
return this.configurationManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an instance of this plugin
|
||||
*
|
||||
* @return <p>An instance of this plugin</p>
|
||||
*/
|
||||
@NotNull
|
||||
public static BlacksmithVisuals getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user