Files
src
build.gradle
PLACEHOLDERS.md
README.md
settings.gradle
Code
33 1,875
src/main/java/com/example/shop/ShopPlugin.java
package com.example.shop;
import com.example.shop.command.ShopCommand;
import com.example.shop.config.ConfigManager;
import com.example.shop.config.MessageService;
import com.example.shop.config.SoundService;
import com.example.shop.economy.EconomyService;
import com.example.shop.gui.main.GuiManager;
import com.example.shop.item.ItemFactory;
import com.example.shop.listener.ShopListener;
import com.example.shop.placeholder.PlaceholderService;
import com.example.shop.placeholder.ShopPlaceholderExpansion;
import com.example.shop.playerdata.saved.PlayerDataManager;
import com.example.shop.shop.repository.ShopRepository;
import com.example.shop.util.NumberFormatter;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
public class ShopPlugin extends JavaPlugin {
private ConfigManager config;
private ShopRepository repository;
private MessageService messages;
private SoundService sounds;
private NumberFormatter numbers;
private PlayerDataManager data;
private EconomyService economy;
private PlaceholderService placeholders;
private GuiManager gui;
@Override
public void onEnable() {
config = new ConfigManager(this);
numbers = new NumberFormatter();
numbers.load(config.config().getConfigurationSection("number-format"));
data = new PlayerDataManager(this);
economy = new EconomyService();
if (!economy.setup()) getLogger().warning("Vault economy provider was not found; purchases are disabled until one is available.");
messages = new MessageService(config);
sounds = new SoundService(config);
placeholders = new PlaceholderService(this, data, numbers);
repository = new ShopRepository(this, config);
repository.reload();
gui = new GuiManager(this, repository, new ItemFactory(placeholders), placeholders, messages, sounds, economy, data);
ShopCommand shopCommand = new ShopCommand(this, messages);
getCommand("shop").setExecutor(shopCommand);
getCommand("shop").setTabCompleter(shopCommand);
getCommand("soulshop").setExecutor(shopCommand);
getCommand("soulshop").setTabCompleter(shopCommand);
getCommand("shopadmin").setExecutor(shopCommand);
getCommand("shopadmin").setTabCompleter(shopCommand);
Bukkit.getPluginManager().registerEvents(new ShopListener(this), this);
if (placeholderApiAvailable()) new ShopPlaceholderExpansion(this).register();
getLogger().info("ShopPlugin " + getDescription().getVersion() + " enabled with " + repository.all().size() + " shop(s).");
}
@Override
public void onDisable() { if (data != null) data.saveAll(); }
public boolean reloadPluginConfiguration() {
try {
config.reload();
numbers.load(config.config().getConfigurationSection("number-format"));
placeholders.reload();
repository.reload();
return true;
} catch (RuntimeException ex) {
getLogger().severe("Configuration reload failed: " + ex.getMessage());
return false;
}
}
public boolean placeholderApiAvailable() { return Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI"); }
public void deposit(Player player, double amount) { economy.deposit(player, amount); }
public ConfigManager configManager() { return config; }
public ShopRepository repository() { return repository; }
public MessageService messages() { return messages; }
public NumberFormatter numbers() { return numbers; }
public PlayerDataManager data() { return data; }
public EconomyService economy() { return economy; }
public GuiManager gui() { return gui; }
}