Splits the blacksmith command into two commands, and much more

This commit is contained in:
2022-08-19 19:08:54 +02:00
parent 755db8c497
commit e1191dad7d
21 changed files with 1077 additions and 235 deletions

View File

@ -1,8 +1,10 @@
package net.knarcraft.blacksmith;
import net.citizensnpcs.api.CitizensAPI;
import net.knarcraft.blacksmith.command.BlackSmithCommand;
import net.knarcraft.blacksmith.command.BlackSmithTabCompleter;
import net.knarcraft.blacksmith.command.BlackSmithConfigCommand;
import net.knarcraft.blacksmith.command.BlackSmithConfigTabCompleter;
import net.knarcraft.blacksmith.command.BlackSmithEditCommand;
import net.knarcraft.blacksmith.command.BlackSmithEditTabCompleter;
import net.knarcraft.blacksmith.config.GlobalSettings;
import net.knarcraft.blacksmith.listener.NPCClickListener;
import net.knarcraft.blacksmith.listener.PlayerListener;
@ -57,6 +59,7 @@ public class BlacksmithPlugin extends JavaPlugin {
public void onEnable() {
instance = this;
//Copy default config to disk
FileConfiguration fileConfiguration = this.getConfig();
this.saveDefaultConfig();
fileConfiguration.options().copyDefaults(true);
@ -65,29 +68,65 @@ public class BlacksmithPlugin extends JavaPlugin {
config = new GlobalSettings(this);
config.load();
//Set up Vault integration
if (!setUpVault()) {
return;
}
//Register the blacksmith trait with Citizens
CitizensAPI.getTraitFactory().registerTrait(
net.citizensnpcs.api.trait.TraitInfo.create(BlacksmithTrait.class).withName("blacksmith"));
//Register all commands
registerCommands();
//Register all listeners
registerListeners();
getLogger().log(Level.INFO, " v" + getDescription().getVersion() + " enabled.");
}
/**
* Tries to set up Vault
*
* @return <p>True if Vault setup/integration succeeded</p>
*/
private boolean setUpVault() {
getLogger().log(Level.INFO, "Setting Up Vault now....");
boolean canLoad = EconomyManager.setUp(getServer().getServicesManager(), getLogger());
if (!canLoad) {
getLogger().log(Level.SEVERE, "Vault Integration Failed....");
getServer().getPluginManager().disablePlugin(this);
return;
}
//Register the blacksmith trait with Citizens
CitizensAPI.getTraitFactory().registerTrait(
net.citizensnpcs.api.trait.TraitInfo.create(BlacksmithTrait.class).withName("blacksmith"));
//Register the blacksmith main-command
PluginCommand blacksmithCommand = this.getCommand("blacksmith");
if (blacksmithCommand != null) {
blacksmithCommand.setExecutor(new BlackSmithCommand());
blacksmithCommand.setTabCompleter(new BlackSmithTabCompleter());
return false;
}
return true;
}
/**
* Registers all listeners used by this plugin
*/
private void registerListeners() {
PluginManager pluginManager = getServer().getPluginManager();
pluginManager.registerEvents(new PlayerListener(), this);
pluginManager.registerEvents(new NPCClickListener(), this);
}
getLogger().log(Level.INFO, " v" + getDescription().getVersion() + " enabled.");
/**
* Registers all commands used by this plugin
*/
private void registerCommands() {
//Register the blacksmith NPC edit main-command
PluginCommand blacksmithCommand = this.getCommand("blacksmith");
if (blacksmithCommand != null) {
blacksmithCommand.setExecutor(new BlackSmithEditCommand());
blacksmithCommand.setTabCompleter(new BlackSmithEditTabCompleter());
}
//Register the global config edit command
PluginCommand blacksmithConfigCommand = this.getCommand("blacksmithConfig");
if (blacksmithConfigCommand != null) {
blacksmithConfigCommand.setExecutor(new BlackSmithConfigCommand());
blacksmithConfigCommand.setTabCompleter(new BlackSmithConfigTabCompleter());
}
}
}