164 lines
5.2 KiB
Java
164 lines
5.2 KiB
Java
package net.knarcraft.paidsigns;
|
|
|
|
import net.knarcraft.paidsigns.command.AddCommand;
|
|
import net.knarcraft.paidsigns.command.AddConditionCommand;
|
|
import net.knarcraft.paidsigns.command.AddConditionTabCompleter;
|
|
import net.knarcraft.paidsigns.command.AddTabCompleter;
|
|
import net.knarcraft.paidsigns.command.ReloadTabCommand;
|
|
import net.knarcraft.paidsigns.command.RemoveConditionCommand;
|
|
import net.knarcraft.paidsigns.command.RemoveConditionTabCompleter;
|
|
import net.knarcraft.paidsigns.command.RemoveTabCommand;
|
|
import net.knarcraft.paidsigns.listener.SignListener;
|
|
import net.knarcraft.paidsigns.manager.EconomyManager;
|
|
import net.knarcraft.paidsigns.manager.PaidSignManager;
|
|
import net.milkbowl.vault.economy.Economy;
|
|
import org.bukkit.command.PluginCommand;
|
|
import org.bukkit.command.TabExecutor;
|
|
import org.bukkit.configuration.file.FileConfiguration;
|
|
import org.bukkit.plugin.PluginManager;
|
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
|
import org.bukkit.plugin.ServicesManager;
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
|
|
/**
|
|
* The PaidSigns plugin's main class
|
|
*/
|
|
public final class PaidSigns extends JavaPlugin {
|
|
|
|
private static PaidSigns paidSigns;
|
|
private PaidSignManager signManager;
|
|
private boolean ignoreCase;
|
|
private boolean ignoreColor;
|
|
|
|
/**
|
|
* Instantiates a new paid signs object
|
|
*/
|
|
@SuppressWarnings("unused")
|
|
public PaidSigns() {
|
|
paidSigns = this;
|
|
}
|
|
|
|
/**
|
|
* Gets an instance of this plugin
|
|
*
|
|
* @return <p>An instance of this plugin</p>
|
|
*/
|
|
public static PaidSigns getInstance() {
|
|
return paidSigns;
|
|
}
|
|
|
|
@Override
|
|
public void onEnable() {
|
|
setupVault();
|
|
signManager = new PaidSignManager(PaidSignManager.loadSigns());
|
|
loadConfig();
|
|
|
|
PluginManager pluginManager = getServer().getPluginManager();
|
|
pluginManager.registerEvents(new SignListener(), this);
|
|
|
|
registerCommands();
|
|
}
|
|
|
|
@Override
|
|
public void onDisable() {
|
|
}
|
|
|
|
/**
|
|
* Reloads this plugin
|
|
*/
|
|
public void reload() {
|
|
this.reloadConfig();
|
|
loadConfig();
|
|
signManager = new PaidSignManager(PaidSignManager.loadSigns());
|
|
}
|
|
|
|
/**
|
|
* Gets the paid sign manager used to manage paid signs
|
|
*
|
|
* @return <p>The paid sign manager</p>
|
|
*/
|
|
public PaidSignManager getSignManager() {
|
|
return signManager;
|
|
}
|
|
|
|
/**
|
|
* Gets the default setting for whether to ignore the case of paid sign ids
|
|
*
|
|
* @return <p>The default ignore case value</p>
|
|
*/
|
|
public boolean ignoreCase() {
|
|
return this.ignoreCase;
|
|
}
|
|
|
|
/**
|
|
* Gets the default setting for whether to ignore the color of paid sign ids
|
|
*
|
|
* @return <p>The default ignore color value</p>
|
|
*/
|
|
public boolean ignoreColor() {
|
|
return this.ignoreColor;
|
|
}
|
|
|
|
/**
|
|
* Registers the commands used by this plugin
|
|
*/
|
|
private void registerCommands() {
|
|
PluginCommand addCommand = this.getCommand("addPaidSign");
|
|
if (addCommand != null) {
|
|
addCommand.setExecutor(new AddCommand());
|
|
addCommand.setTabCompleter(new AddTabCompleter());
|
|
}
|
|
|
|
PluginCommand addConditionCommand = this.getCommand("addPaidSignCondition");
|
|
if (addConditionCommand != null) {
|
|
addConditionCommand.setExecutor(new AddConditionCommand());
|
|
addConditionCommand.setTabCompleter(new AddConditionTabCompleter());
|
|
}
|
|
|
|
PluginCommand removeConditionCommand = this.getCommand("removePaidSignCondition");
|
|
if (removeConditionCommand != null) {
|
|
removeConditionCommand.setExecutor(new RemoveConditionCommand());
|
|
removeConditionCommand.setTabCompleter(new RemoveConditionTabCompleter());
|
|
}
|
|
|
|
PluginCommand removeCommand = this.getCommand("removePaidSign");
|
|
if (removeCommand != null) {
|
|
TabExecutor removeTabExecutor = new RemoveTabCommand();
|
|
removeCommand.setExecutor(removeTabExecutor);
|
|
removeCommand.setTabCompleter(removeTabExecutor);
|
|
}
|
|
|
|
PluginCommand reloadCommand = this.getCommand("reload");
|
|
if (reloadCommand != null) {
|
|
TabExecutor reloadTabExecutor = new ReloadTabCommand();
|
|
reloadCommand.setExecutor(reloadTabExecutor);
|
|
reloadCommand.setTabCompleter(reloadTabExecutor);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Loads the configuration file
|
|
*/
|
|
private void loadConfig() {
|
|
FileConfiguration config = this.getConfig();
|
|
config.options().copyDefaults(true);
|
|
this.saveDefaultConfig();
|
|
ignoreCase = config.getBoolean("ignoreCase", true);
|
|
ignoreColor = config.getBoolean("ignoreColor", false);
|
|
}
|
|
|
|
/**
|
|
* Sets up Vault by getting plugins from their providers
|
|
*/
|
|
private void setupVault() {
|
|
ServicesManager servicesManager = this.getServer().getServicesManager();
|
|
RegisteredServiceProvider<Economy> economyProvider = servicesManager.getRegistration(Economy.class);
|
|
if (economyProvider != null) {
|
|
EconomyManager.initialize(economyProvider.getProvider());
|
|
} else {
|
|
throw new IllegalStateException("[PaidSigns] Error: Vault could not be loaded");
|
|
}
|
|
}
|
|
|
|
}
|