Files
src
build.gradle
Code
28 2,305
src/main/java/com/example/petsystempro/PetSystemPro.java
package com.example.petsystempro;
import com.example.petsystempro.command.PetCommand;
import com.example.petsystempro.config.ConfigManager;
import com.example.petsystempro.config.MessagesConfig;
import com.example.petsystempro.inventory.gui.GUIListener;
import com.example.petsystempro.inventory.gui.GUIManager;
import com.example.petsystempro.listener.ChatInputListener;
import com.example.petsystempro.listener.PetEquipListener;
import com.example.petsystempro.listener.PetExpListener;
import com.example.petsystempro.listener.PlayerDeathListener;
import com.example.petsystempro.manager.BoostManager;
import com.example.petsystempro.manager.MoneyRewardManager;
import com.example.petsystempro.manager.PetDataManager;
import com.example.petsystempro.manager.PetManager;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
public class PetSystemPro extends JavaPlugin {
private ConfigManager configManager;
private MessagesConfig messagesConfig;
private PetDataManager petDataManager;
private PetManager petManager;
private BoostManager boostManager;
private MoneyRewardManager moneyRewardManager;
private GUIManager guiManager;
private Economy economy;
@Override
public void onEnable() {
getLogger().info("[1/10] Starting PetSystemPro initialization...");
try {
getLogger().info("[2/10] Saving default config...");
saveDefaultConfig();
getLogger().info("[3/10] Setting up economy (Vault)...");
if (!setupEconomy()) {
getLogger().warning("Vault not found! Money rewards will be disabled.");
}
getLogger().info("[4/10] Loading config manager...");
this.configManager = new ConfigManager(this);
getLogger().info("[5/10] Loading messages config...");
this.messagesConfig = new MessagesConfig(this);
getLogger().info("[6/10] Initializing managers...");
this.petDataManager = new PetDataManager(this);
this.petManager = new PetManager(this);
this.boostManager = new BoostManager(this);
this.moneyRewardManager = new MoneyRewardManager(this);
this.guiManager = new GUIManager();
getLogger().info("[7/10] Registering listeners...");
registerListeners();
getLogger().info("[8/10] Registering commands...");
registerCommands();
getLogger().info("[9/10] Starting background tasks...");
this.moneyRewardManager.start();
this.petManager.startFollowerTask();
getLogger().info("[10/10] PetSystemPro enabled successfully!");
} catch (Throwable t) {
getLogger().severe("");
getLogger().severe("============================================");
getLogger().severe(" CRITICAL ERROR DURING PLUGIN STARTUP");
getLogger().severe(" Plugin FAILED to initialize properly!");
getLogger().severe(" Error: " + t.getClass().getSimpleName());
getLogger().severe(" Message: " + t.getMessage());
getLogger().severe("============================================");
t.printStackTrace();
getLogger().severe("============================================");
getLogger().severe(" Initializing SAFE MODE...");
getLogger().severe("============================================");
if (this.configManager == null) {
try {
this.configManager = new ConfigManager(this);
getLogger().info("[SAFE] ConfigManager initialized");
} catch (Throwable t2) {
getLogger().severe("[FAIL] ConfigManager failed!");
}
}
if (this.messagesConfig == null) {
try {
this.messagesConfig = new MessagesConfig(this);
getLogger().info("[SAFE] MessagesConfig initialized");
} catch (Throwable t2) {
getLogger().severe("[FAIL] MessagesConfig failed!");
}
}
if (this.guiManager == null) {
this.guiManager = new GUIManager();
getLogger().info("[SAFE] GUIManager initialized");
}
if (this.petDataManager == null) {
try {
this.petDataManager = new PetDataManager(this);
getLogger().info("[SAFE] PetDataManager initialized");
} catch (Throwable t2) {
getLogger().severe("[FAIL] PetDataManager failed!");
}
}
if (this.petManager == null) {
this.petManager = new PetManager(this);
getLogger().info("[SAFE] PetManager initialized");
}
if (this.boostManager == null) {
this.boostManager = new BoostManager(this);
getLogger().info("[SAFE] BoostManager initialized");
}
if (this.moneyRewardManager == null) {
this.moneyRewardManager = new MoneyRewardManager(this);
getLogger().info("[SAFE] MoneyRewardManager initialized");
}
try {
registerListeners();
getLogger().info("[SAFE] Listeners registered");
} catch (Throwable t2) {
getLogger().severe("[FAIL] Failed to register listeners!");
t2.printStackTrace();
}
try {
registerCommands();
getLogger().info("[SAFE] Commands registered");
} catch (Throwable t2) {
getLogger().severe("[FAIL] Failed to register commands!");
t2.printStackTrace();
}
getLogger().warning("");
getLogger().warning("SAFE MODE ACTIVE - Plugin may not work correctly!");
getLogger().warning("Please fix the errors above and restart the server.");
getLogger().warning("");
}
}
@Override
public void onDisable() {
try {
if (this.moneyRewardManager != null) {
this.moneyRewardManager.stop();
}
if (this.petManager != null) {
this.petManager.stopFollowerTask();
this.petManager.removeAllFollowers();
}
getLogger().info("PetSystemPro disabled.");
} catch (Exception e) {
getLogger().severe("Error during plugin shutdown:");
e.printStackTrace();
}
}
private void registerListeners() {
Bukkit.getPluginManager().registerEvents(new GUIListener(guiManager), this);
Bukkit.getPluginManager().registerEvents(new PetEquipListener(this), this);
Bukkit.getPluginManager().registerEvents(new PetExpListener(this), this);
Bukkit.getPluginManager().registerEvents(new PlayerDeathListener(this), this);
Bukkit.getPluginManager().registerEvents(new ChatInputListener(this), this);
}
private void registerCommands() {
try {
if (getCommand("pet") != null) {
getCommand("pet").setExecutor(new PetCommand(this));
} else {
getLogger().severe("Failed to register /pet command - not found in plugin.yml!");
}
if (getCommand("petadmin") != null) {
getCommand("petadmin").setExecutor(new PetCommand(this));
} else {
getLogger().severe("Failed to register /petadmin command - not found in plugin.yml!");
}
} catch (Exception e) {
getLogger().severe("Failed to register commands:");
e.printStackTrace();
}
}
private boolean setupEconomy() {
if (getServer().getPluginManager().getPlugin("Vault") == null) {
return false;
}