Files
src
pom.xml
Code
17 1,542
src/main/java/com/celestialteams/CelestialTeams.java
package com.celestialteams;
import com.celestialteams.command.AdminCommand;
import com.celestialteams.command.TeamCommand;
import com.celestialteams.listener.TeleportListener;
import com.celestialteams.manager.ConfigManager;
import com.celestialteams.manager.TeamManager;
import com.celestialteams.placeholder.CelestialExpansion;
import org.bukkit.command.PluginCommand;
import org.bukkit.plugin.java.JavaPlugin;
public class CelestialTeams extends JavaPlugin {
private ConfigManager configManager;
private TeamManager teamManager;
private CelestialExpansion placeholderExpansion; // Track expansion instance for clean unregistration
@Override
public void onEnable() {
// Initialize MessageUtil FIRST so other managers can use it safely during startup
com.celestialteams.util.MessageUtil.init(this);
configManager = new ConfigManager(this);
configManager.loadAll();
teamManager = new TeamManager(this);
teamManager.loadTeams();
// FIX: Safe registration checks for commands to prevent server boot failure if plugin.yml is edited incorrectly
TeamCommand teamCmd = new TeamCommand(this);
PluginCommand teamCommandObj = getCommand("team");
if (teamCommandObj != null) {
teamCommandObj.setExecutor(teamCmd);
teamCommandObj.setTabCompleter(teamCmd);
} else {
getLogger().warning("Command '/team' is missing from plugin.yml!");
}
AdminCommand adminCmd = new AdminCommand(this);
PluginCommand adminCommandObj = getCommand("celestialteams");
if (adminCommandObj != null) {
adminCommandObj.setExecutor(adminCmd);
adminCommandObj.setTabCompleter(adminCmd);
} else {
getLogger().warning("Command '/celestialteams' is missing from plugin.yml!");
}
getServer().getPluginManager().registerEvents(new TeleportListener(this), this);
if (getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) {
placeholderExpansion = new CelestialExpansion(this);
placeholderExpansion.register();
getLogger().info("PlaceholderAPI hooked successfully.");
}
getLogger().info("CelestialTeams enabled.");
}
@Override
public void onDisable() {
if (teamManager != null) {
teamManager.saveTeams();
}
// FIX: Cleanly unregister expansion to avoid memory leak states upon reloads
if (placeholderExpansion != null) {
try {
placeholderExpansion.unregister();
} catch (Exception e) {
// Catch quietly in case PAPI is disabling at the same exact frame
}
}
getLogger().info("CelestialTeams disabled.");
}
public ConfigManager getConfigManager() {
return configManager;
}
public TeamManager getTeamManager() {
return teamManager;
}
}