2022-06-06 16:30:35 +00:00
|
|
|
package com.alttd.playershops;
|
|
|
|
|
|
2022-08-21 15:36:01 +00:00
|
|
|
import com.alttd.playershops.commands.ShopCommand;
|
2022-08-07 15:28:38 +00:00
|
|
|
import com.alttd.playershops.config.Config;
|
2022-08-13 13:22:00 +00:00
|
|
|
import com.alttd.playershops.config.DatabaseConfig;
|
2022-07-10 19:00:12 +00:00
|
|
|
import com.alttd.playershops.config.MessageConfig;
|
2022-08-21 15:36:01 +00:00
|
|
|
import com.alttd.playershops.gui.GuiIcon;
|
2022-08-07 15:28:38 +00:00
|
|
|
import com.alttd.playershops.handler.ShopHandler;
|
2022-08-13 13:22:00 +00:00
|
|
|
import com.alttd.playershops.listener.BlockListener;
|
2022-07-05 09:06:39 +00:00
|
|
|
import com.alttd.playershops.listener.PlayerListener;
|
|
|
|
|
import com.alttd.playershops.listener.ShopListener;
|
2022-08-13 13:22:00 +00:00
|
|
|
import com.alttd.playershops.shop.ShopType;
|
2022-08-13 14:10:23 +00:00
|
|
|
import com.alttd.playershops.storage.DatabaseManager;
|
2022-07-04 09:04:13 +00:00
|
|
|
import lombok.Getter;
|
2022-06-06 16:30:35 +00:00
|
|
|
import net.milkbowl.vault.economy.Economy;
|
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
|
|
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
|
|
|
|
|
|
|
|
public class PlayerShops extends JavaPlugin {
|
|
|
|
|
|
2022-07-04 09:04:13 +00:00
|
|
|
@Getter
|
2022-06-06 16:30:35 +00:00
|
|
|
private static PlayerShops instance;
|
2022-07-04 09:04:13 +00:00
|
|
|
@Getter
|
2022-07-10 18:32:49 +00:00
|
|
|
private Economy econ = null;
|
2022-07-04 09:04:13 +00:00
|
|
|
@Getter
|
|
|
|
|
private ShopHandler shopHandler;
|
2022-08-13 14:10:23 +00:00
|
|
|
@Getter
|
|
|
|
|
private DatabaseManager databaseManager;
|
2022-06-06 16:30:35 +00:00
|
|
|
|
2022-07-05 09:06:39 +00:00
|
|
|
private ShopListener shopListener;
|
|
|
|
|
private PlayerListener playerListener;
|
2022-08-13 13:22:00 +00:00
|
|
|
private BlockListener blockListener;
|
2022-07-05 09:06:39 +00:00
|
|
|
|
2022-06-06 16:30:35 +00:00
|
|
|
public void onEnable() {
|
|
|
|
|
instance = this;
|
|
|
|
|
if(!setupEconomy()) {
|
|
|
|
|
Bukkit.getLogger().warning("Error loading Vault and economy.\n Disabling plugin");
|
|
|
|
|
this.setEnabled(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Bukkit.getLogger().info("Hooked into Vault economy provided by " + econ.getName());
|
|
|
|
|
reloadConfigs();
|
2022-08-13 14:10:23 +00:00
|
|
|
databaseManager = new DatabaseManager(instance);
|
2022-08-13 13:22:00 +00:00
|
|
|
shopHandler = new ShopHandler(instance);
|
|
|
|
|
|
2022-06-06 16:30:35 +00:00
|
|
|
registerListeners();
|
|
|
|
|
registerCommands();
|
2022-08-13 13:22:00 +00:00
|
|
|
}
|
2022-07-04 09:04:13 +00:00
|
|
|
|
2022-08-13 13:22:00 +00:00
|
|
|
public void onDisable() {
|
|
|
|
|
unRegisterListeners();
|
|
|
|
|
Bukkit.getScheduler().cancelTasks(this);
|
2022-08-13 14:10:23 +00:00
|
|
|
|
|
|
|
|
databaseManager.unload();
|
2022-06-06 16:30:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean setupEconomy() {
|
|
|
|
|
if (getServer().getPluginManager().getPlugin("Vault") == null) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
|
|
|
|
|
if (rsp == null) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2022-07-10 18:32:49 +00:00
|
|
|
econ = rsp.getProvider();
|
2022-06-06 16:30:35 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Economy getEconomy() {
|
|
|
|
|
if(econ == null)
|
|
|
|
|
setupEconomy();
|
|
|
|
|
return econ;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void registerListeners() {
|
2022-07-08 08:59:45 +00:00
|
|
|
shopListener = new ShopListener(this);
|
|
|
|
|
playerListener = new PlayerListener(this);
|
2022-08-13 13:22:00 +00:00
|
|
|
blockListener = new BlockListener(this);
|
2022-07-05 09:06:39 +00:00
|
|
|
}
|
2022-06-06 16:30:35 +00:00
|
|
|
|
2022-08-13 13:22:00 +00:00
|
|
|
private void unRegisterListeners() {
|
2022-07-05 09:06:39 +00:00
|
|
|
shopListener.unregister();
|
|
|
|
|
playerListener.unregister();
|
2022-08-13 13:22:00 +00:00
|
|
|
blockListener.unregister();
|
2022-06-06 16:30:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void registerCommands() {
|
2022-08-21 15:36:01 +00:00
|
|
|
getCommand("playershop").setExecutor(new ShopCommand());
|
2022-06-06 16:30:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void reloadConfigs() {
|
|
|
|
|
Config.reload();
|
2022-07-10 19:00:12 +00:00
|
|
|
MessageConfig.reload();
|
2022-08-13 13:22:00 +00:00
|
|
|
DatabaseConfig.reload();
|
|
|
|
|
|
|
|
|
|
for (ShopType shopType : ShopType.values()) {
|
|
|
|
|
// preload ShopType to get the configs active
|
|
|
|
|
}
|
2022-08-21 15:36:01 +00:00
|
|
|
for (GuiIcon guiIcon : GuiIcon.values()) {
|
|
|
|
|
// preload to get config values generated
|
|
|
|
|
}
|
2022-06-06 16:30:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|