Files
src
build.gradle
manifest.kod
Code
21 2,103
src/main/java/com/soullifesmp/SoulLifeSMP.java
package com.soullifesmp;
import com.soullifesmp.commands.*;
import com.soullifesmp.data.DatabaseHandler;
import com.soullifesmp.hooks.LuckPermsHook;
import com.soullifesmp.hooks.PlaceholderAPIHook;
import com.soullifesmp.hooks.VaultHook;
import com.soullifesmp.inventory.gui.GUIListener;
import com.soullifesmp.inventory.gui.GUIManager;
import com.soullifesmp.listeners.*;
import com.soullifesmp.managers.*;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.util.logging.Level;
@Getter
public class SoulLifeSMP extends JavaPlugin {
private DatabaseHandler databaseHandler;
private DataManager dataManager;
private LifeManager lifeManager;
private SoulLifeManager soulLifeManager;
private TokenManager tokenManager;
private BountyManager bountyManager;
private KillStreakManager killStreakManager;
private EventManager eventManager;
private SpinManager spinManager;
private GUIManager guiManager;
private VaultHook vaultHook;
private PlaceholderAPIHook placeholderAPIHook;
private LuckPermsHook luckPermsHook;
private FileConfiguration messagesConfig;
private FileConfiguration databaseConfig;
@Override
public void onEnable() {
long startTime = System.currentTimeMillis();
getLogger().info("§4========================================");
getLogger().info("§cStarting SoulLife SMP...");
getLogger().info("§4========================================");
saveDefaultConfig();
loadConfigs();
initializeDatabase();
initializeManagers();
initializeHooks();
registerCommands();
registerListeners();
startTasks();
long loadTime = System.currentTimeMillis() - startTime;
getLogger().info("§4========================================");
getLogger().info("§aSoulLife SMP enabled! §7(" + loadTime + "ms)");
getLogger().info("§4========================================");
}
@Override
public void onDisable() {
getLogger().info("§4========================================");
getLogger().info("§cShutting down SoulLife SMP...");
getLogger().info("§4========================================");
if (eventManager != null) {
eventManager.shutdown();
}
if (dataManager != null) {
dataManager.saveAllData();
}
if (databaseHandler != null) {
databaseHandler.close();
}
getLogger().info("§cSoulLife SMP disabled!");
}
private void loadConfigs() {
File messagesFile = new File(getDataFolder(), "messages.yml");
if (!messagesFile.exists()) {
saveResource("messages.yml", false);
}
messagesConfig = YamlConfiguration.loadConfiguration(messagesFile);
File databaseFile = new File(getDataFolder(), "database.yml");
if (!databaseFile.exists()) {
saveResource("database.yml", false);
}
databaseConfig = YamlConfiguration.loadConfiguration(databaseFile);
}
private void initializeDatabase() {
try {
databaseHandler = new DatabaseHandler(this);
databaseHandler.initialize();
getLogger().info("§aDatabase initialized successfully!");
} catch (Exception e) {
getLogger().log(Level.SEVERE, "Failed to initialize database!", e);
Bukkit.getPluginManager().disablePlugin(this);
}
}
private void initializeManagers() {
guiManager = new GUIManager();
dataManager = new DataManager(this);
lifeManager = new LifeManager(this);
soulLifeManager = new SoulLifeManager(this);
tokenManager = new TokenManager(this);
bountyManager = new BountyManager(this);
killStreakManager = new KillStreakManager(this);
eventManager = new EventManager(this);
spinManager = new SpinManager(this);
getLogger().info("§aAll managers initialized!");
}
private void initializeHooks() {
if (Bukkit.getPluginManager().isPluginEnabled("Vault")) {
vaultHook = new VaultHook(this);
if (vaultHook.hook()) {
getLogger().info("§aHooked into Vault!");
}
}
if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) {
placeholderAPIHook = new PlaceholderAPIHook(this);
if (placeholderAPIHook.register()) {
getLogger().info("§aHooked into PlaceholderAPI!");
}
}
if (Bukkit.getPluginManager().isPluginEnabled("LuckPerms")) {
luckPermsHook = new LuckPermsHook();
getLogger().info("§aHooked into LuckPerms!");
}
}
private void registerCommands() {
getCommand("lives").setExecutor(new LivesCommand(this));
getCommand("tokens").setExecutor(new TokensCommand(this));
getCommand("spin").setExecutor(new SpinCommand(this));
getCommand("souls").setExecutor(new SoulsCommand(this));
getCommand("protect").setExecutor(new ProtectCommand(this));
getCommand("stats").setExecutor(new StatsCommand(this));
getCommand("soullife").setExecutor(new SoulLifeCommand(this));
getLogger().info("§aCommands registered!");
}
private void registerListeners() {
PluginManager pm = Bukkit.getPluginManager();
pm.registerEvents(new GUIListener(guiManager), this);
pm.registerEvents(new PlayerDeathListener(this), this);
pm.registerEvents(new PlayerJoinListener(this), this);
pm.registerEvents(new PlayerInteractListener(this), this);
pm.registerEvents(new PlayerDamageListener(this), this);
getLogger().info("§aListeners registered!");
}
private void startTasks() {
Bukkit.getScheduler().runTaskTimerAsynchronously(this, () -> {
if (dataManager != null) {
dataManager.saveAllData();
}
}, 6000L, 6000L);
getLogger().info("§aBackground tasks started!");
}
public void reloadConfigs() {
reloadConfig();
loadConfigs();
if (eventManager != null) {
eventManager.reload();
}
if (bountyManager != null) {
bountyManager.reload();
}
}
public String getMessage(String path) {
String message = messagesConfig.getString(path, "");
String prefix = messagesConfig.getString("prefix", "");
return message.replace("{prefix}", prefix)
.replace("&", "§");
}