Initial commit
This commit is contained in:
147
src/main/java/net/knarcraft/paidsigns/PaidSigns.java
Normal file
147
src/main/java/net/knarcraft/paidsigns/PaidSigns.java
Normal file
@ -0,0 +1,147 @@
|
||||
package net.knarcraft.paidsigns;
|
||||
|
||||
import net.knarcraft.paidsigns.command.AddCommand;
|
||||
import net.knarcraft.paidsigns.command.AddTabCompleter;
|
||||
import net.knarcraft.paidsigns.command.ReloadTabCommand;
|
||||
import net.knarcraft.paidsigns.command.RemoveCommand;
|
||||
import net.knarcraft.paidsigns.command.RemoveTabCompleter;
|
||||
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 removeCommand = this.getCommand("removePaidSign");
|
||||
if (removeCommand != null) {
|
||||
removeCommand.setExecutor(new RemoveCommand());
|
||||
removeCommand.setTabCompleter(new RemoveTabCompleter());
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user